[PATCHv2 11/13] tests: Better handling of valgrind errors saving blobs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



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 <david@xxxxxxxxxxxxxxxxxxxxx>
Reviewed-by: Simon Glass <sjg@xxxxxxxxxxxx>
---
 tests/mangle-layout.supp |  7 -------
 tests/open_pack.supp     |  7 -------
 tests/sw_tree1.supp      | 18 ------------------
 tests/testutils.c        | 15 +++++++++++++--
 4 files changed, 13 insertions(+), 34 deletions(-)
 delete mode 100644 tests/mangle-layout.supp
 delete mode 100644 tests/open_pack.supp
 delete mode 100644 tests/sw_tree1.supp

diff --git a/tests/mangle-layout.supp b/tests/mangle-layout.supp
deleted file mode 100644
index 2890420..0000000
--- a/tests/mangle-layout.supp
+++ /dev/null
@@ -1,7 +0,0 @@
-{
-   uninitialized alignment gaps can be dumped to output
-   Memcheck:Param
-   write(buf)
-   obj:/lib/ld-*.so
-   fun:main
-}
diff --git a/tests/open_pack.supp b/tests/open_pack.supp
deleted file mode 100644
index c954fe7..0000000
--- a/tests/open_pack.supp
+++ /dev/null
@@ -1,7 +0,0 @@
-{
-   opened blob dumps uninitialized data
-   Memcheck:Param
-   write(buf)
-   obj:/lib/ld-*.so
-   fun:main
-}
diff --git a/tests/sw_tree1.supp b/tests/sw_tree1.supp
deleted file mode 100644
index fcb1950..0000000
--- a/tests/sw_tree1.supp
+++ /dev/null
@@ -1,18 +0,0 @@
-{
-   allocation methods causes uninitialized data in alignment gap
-   Memcheck:Param
-   write(buf)
-   fun:__write_nocancel
-   fun:utilfdt_write_err
-   fun:save_blob
-   fun:main
-}
-{
-   allocation methods causes uninitialized data in alignment gap
-   Memcheck:Param
-   write(buf)
-   fun:write
-   fun:utilfdt_write_err
-   fun:save_blob
-   fun:main
-}
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 *load_blob_arg(int argc, char *argv[])
 
 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)
-- 
2.14.3

--
To unsubscribe from this list: send the line "unsubscribe devicetree-compiler" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Device Tree]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux