From 5b67d2b955a3ef6bc4ce6fec3b06c660539aa8ce Mon Sep 17 00:00:00 2001 From: David Gibson Date: Sat, 17 Mar 2018 20:05:24 +1100 Subject: [PATCH] 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 Tested-by: Alexey Kardashevskiy Reviewed-by: Alexey Kardashevskiy Reviewed-by: Simon Glass --- tests/mangle-layout.supp | 7 ------- tests/open_pack.supp | 7 ------- tests/sw_tree1.supp | 18 ------------------ tests/testutils.c | 13 ++++++++++++- 4 files changed, 12 insertions(+), 33 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 #include +#include + #include #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)