tests: Better handling of valgrind errors saving blobs
Currently we have 3 valgrind suppression files in the tests, all of which
are to handle memcheck errors that originate from saving entire buffers
containing blobs where the gaps between sub-blocks might not be
initialized.
We can more simply suppress those errors by having the save_blob() helper
use valgrind's client interface to mark the data as initialized before we
write it out.
Signed-off-by: David Gibson <[email protected]>
Tested-by: Alexey Kardashevskiy <[email protected]>
Reviewed-by: Alexey Kardashevskiy <[email protected]>
Reviewed-by: Simon Glass <[email protected]>
diff --git a/tests/testutils.c b/tests/testutils.c
index 101b00b..d6d6818 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -30,6 +30,8 @@
#include <unistd.h>
#include <fcntl.h>
+#include <valgrind/memcheck.h>
+
#include <libfdt.h>
#include "tests.h"
@@ -179,11 +181,20 @@
void save_blob(const char *filename, void *fdt)
{
- int ret = utilfdt_write_err(filename, fdt);
+ size_t size = fdt_totalsize(fdt);
+ void *tmp;
+ int ret;
+ /* Make a temp copy of the blob so that valgrind won't check
+ * about uninitialized bits in the pieces between blocks */
+ tmp = xmalloc(size);
+ fdt_move(fdt, tmp, size);
+ VALGRIND_MAKE_MEM_DEFINED(tmp, size);
+ ret = utilfdt_write_err(filename, tmp);
if (ret)
CONFIG("Couldn't write blob to \"%s\": %s", filename,
strerror(ret));
+ free(tmp);
}
void *open_blob_rw(void *blob)