mirror of
https://github.com/dgibson/dtc.git
synced 2025-10-13 16:27:39 -04:00
dtc: Add valgrind support to testsuite
This patch adds some options to the run_tests.sh script allowing it to run all the testcases under valgrind to check for pointer corruption bugs and memory leaks. Invoking "make checkm" will run the testsuite with valgrind. It include a mechanism for specifying valgrind errors to be suppressed on a per-testcase basis, and adds a couple of such suppression files for the mangle-layout and open_pack testcases which dump for use by other testcases a buffer which may contain uninitialized sections. We use suppressions rather than initializing the buffer so that valgrind will catch any internal access s to the uninitialized data, which would be a bug. The patch also fixes one genuine bug caught by valgrind - _packblocks() in fdt_rw.c was using memcpy() where it should have been using memmove(). At present the valgrinding won't do anything useful for testcases invoked via a shell script - which includes all the dtc testcases. I plan to fix that later. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
3ce5363387
commit
67b6b33b9b
5 changed files with 41 additions and 6 deletions
|
@ -358,12 +358,12 @@ static void _packblocks(const void *fdt, void *buf,
|
||||||
memmove(buf + mem_rsv_off, fdt + fdt_off_mem_rsvmap(fdt), mem_rsv_size);
|
memmove(buf + mem_rsv_off, fdt + fdt_off_mem_rsvmap(fdt), mem_rsv_size);
|
||||||
fdt_set_off_mem_rsvmap(buf, mem_rsv_off);
|
fdt_set_off_mem_rsvmap(buf, mem_rsv_off);
|
||||||
|
|
||||||
memcpy(buf + struct_off, fdt + fdt_off_dt_struct(fdt), struct_size);
|
memmove(buf + struct_off, fdt + fdt_off_dt_struct(fdt), struct_size);
|
||||||
fdt_set_off_dt_struct(buf, struct_off);
|
fdt_set_off_dt_struct(buf, struct_off);
|
||||||
fdt_set_size_dt_struct(buf, struct_size);
|
fdt_set_size_dt_struct(buf, struct_size);
|
||||||
|
|
||||||
memcpy(buf + strings_off, fdt + fdt_off_dt_strings(fdt),
|
memmove(buf + strings_off, fdt + fdt_off_dt_strings(fdt),
|
||||||
fdt_size_dt_strings(fdt));
|
fdt_size_dt_strings(fdt));
|
||||||
fdt_set_off_dt_strings(buf, strings_off);
|
fdt_set_off_dt_strings(buf, strings_off);
|
||||||
fdt_set_size_dt_strings(buf, fdt_size_dt_strings(fdt));
|
fdt_set_size_dt_strings(buf, fdt_size_dt_strings(fdt));
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ TESTS_TARGETS = $(TESTS) $(TESTS_TREES)
|
||||||
TESTS_DEPFILES = $(TESTS:%=%.d) \
|
TESTS_DEPFILES = $(TESTS:%=%.d) \
|
||||||
$(addprefix $(TESTS_PREFIX),testutils.d trees.d dumptrees.d)
|
$(addprefix $(TESTS_PREFIX),testutils.d trees.d dumptrees.d)
|
||||||
|
|
||||||
TESTS_CLEANFILES_L = *.output vgcore.* *.dtb *.test.dts
|
TESTS_CLEANFILES_L = *.output vglog.* vgcore.* *.dtb *.test.dts
|
||||||
TESTS_CLEANFILES = $(TESTS_CLEANFILES_L:%=$(TESTS_PREFIX)%)
|
TESTS_CLEANFILES = $(TESTS_CLEANFILES_L:%=$(TESTS_PREFIX)%)
|
||||||
|
|
||||||
BIN += $(TESTS) $(TESTS_PREFIX)dumptrees
|
BIN += $(TESTS) $(TESTS_PREFIX)dumptrees
|
||||||
|
@ -52,6 +52,9 @@ tests_clean:
|
||||||
check: tests dtc
|
check: tests dtc
|
||||||
cd $(TESTS_PREFIX); ./run_tests.sh
|
cd $(TESTS_PREFIX); ./run_tests.sh
|
||||||
|
|
||||||
|
checkm: tests dtc
|
||||||
|
cd $(TESTS_PREFIX); ./run_tests.sh -m 2>&1 | tee vglog.$$$$
|
||||||
|
|
||||||
checkv: tests dtc
|
checkv: tests dtc
|
||||||
cd $(TESTS_PREFIX); ./run_tests.sh -v
|
cd $(TESTS_PREFIX); ./run_tests.sh -v
|
||||||
|
|
||||||
|
|
7
tests/mangle-layout.supp
Normal file
7
tests/mangle-layout.supp
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
uninitialized alignment gaps can be dumped to output
|
||||||
|
Memcheck:Param
|
||||||
|
write(buf)
|
||||||
|
obj:/lib/ld-2.6.1.so
|
||||||
|
fun:main
|
||||||
|
}
|
7
tests/open_pack.supp
Normal file
7
tests/open_pack.supp
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
opened blob dumps uninitialized data
|
||||||
|
Memcheck:Param
|
||||||
|
write(buf)
|
||||||
|
obj:/lib/ld-2.6.1.so
|
||||||
|
fun:main
|
||||||
|
}
|
|
@ -2,16 +2,26 @@
|
||||||
|
|
||||||
export QUIET_TEST=1
|
export QUIET_TEST=1
|
||||||
|
|
||||||
|
export VALGRIND=
|
||||||
|
VGCODE=126
|
||||||
|
|
||||||
tot_tests=0
|
tot_tests=0
|
||||||
tot_pass=0
|
tot_pass=0
|
||||||
tot_fail=0
|
tot_fail=0
|
||||||
tot_config=0
|
tot_config=0
|
||||||
|
tot_vg=0
|
||||||
tot_strange=0
|
tot_strange=0
|
||||||
|
|
||||||
run_test () {
|
run_test () {
|
||||||
tot_tests=$[tot_tests + 1]
|
tot_tests=$[tot_tests + 1]
|
||||||
echo -n "$@: "
|
echo -n "$@: "
|
||||||
if "./$@"; then
|
VGLOCAL="$VALGRIND"
|
||||||
|
if [ -n "$VALGRIND" ]; then
|
||||||
|
if [ -f $1.supp ]; then
|
||||||
|
VGLOCAL="$VGLOCAL --suppressions=$1.supp"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if $VGLOCAL "./$@"; then
|
||||||
tot_pass=$[tot_pass + 1]
|
tot_pass=$[tot_pass + 1]
|
||||||
else
|
else
|
||||||
ret="$?"
|
ret="$?"
|
||||||
|
@ -19,6 +29,8 @@ run_test () {
|
||||||
tot_config=$[tot_config + 1]
|
tot_config=$[tot_config + 1]
|
||||||
elif [ "$ret" == "2" ]; then
|
elif [ "$ret" == "2" ]; then
|
||||||
tot_fail=$[tot_fail + 1]
|
tot_fail=$[tot_fail + 1]
|
||||||
|
elif [ "$ret" == "$VGCODE" ]; then
|
||||||
|
tot_vg=$[tot_vg + 1]
|
||||||
else
|
else
|
||||||
tot_strange=$[tot_strange + 1]
|
tot_strange=$[tot_strange + 1]
|
||||||
fi
|
fi
|
||||||
|
@ -147,7 +159,7 @@ dtc_tests () {
|
||||||
run_test dtc-checkfails.sh -I dts -O dtb minusone-phandle.dts
|
run_test dtc-checkfails.sh -I dts -O dtb minusone-phandle.dts
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts "vdt:" ARG ; do
|
while getopts "vt:m" ARG ; do
|
||||||
case $ARG in
|
case $ARG in
|
||||||
"v")
|
"v")
|
||||||
unset QUIET_TEST
|
unset QUIET_TEST
|
||||||
|
@ -155,6 +167,9 @@ while getopts "vdt:" ARG ; do
|
||||||
"t")
|
"t")
|
||||||
TESTSETS=$OPTARG
|
TESTSETS=$OPTARG
|
||||||
;;
|
;;
|
||||||
|
"m")
|
||||||
|
VALGRIND="valgrind --tool=memcheck -q --error-exitcode=$VGCODE"
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -181,6 +196,9 @@ echo -e "* Total testcases: $tot_tests"
|
||||||
echo -e "* PASS: $tot_pass"
|
echo -e "* PASS: $tot_pass"
|
||||||
echo -e "* FAIL: $tot_fail"
|
echo -e "* FAIL: $tot_fail"
|
||||||
echo -e "* Bad configuration: $tot_config"
|
echo -e "* Bad configuration: $tot_config"
|
||||||
|
if [ -n "$VALGRIND" ]; then
|
||||||
|
echo -e "* valgrind errors: $tot_vg"
|
||||||
|
fi
|
||||||
echo -e "* Strange test result: $tot_strange"
|
echo -e "* Strange test result: $tot_strange"
|
||||||
echo -e "**********"
|
echo -e "**********"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue