dtc: Add testcases for tree checks
This patch adds a group of testcases to check that dtc correctly rejects trees with various structural errors. To make things easier to test, we change dtc so that failing checks (as opposed to other errors) result in exit code 2. This patch also fixes an embarrasing bug uncovered by these new tests: check_phandles() worked out if the tree's phandles were valid, then throws that information away and returns success always. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>main
parent
2cf86939af
commit
0d6ade2547
2
checks.c
2
checks.c
|
@ -101,7 +101,7 @@ static int check_phandles(struct node *root, struct node *node)
|
||||||
for_each_child(node, child)
|
for_each_child(node, child)
|
||||||
ok = ok && check_phandles(root, child);
|
ok = ok && check_phandles(root, child);
|
||||||
|
|
||||||
return 1;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
int check_structure(struct node *dt)
|
int check_structure(struct node *dt)
|
||||||
|
|
2
dtc.c
2
dtc.c
|
@ -197,7 +197,7 @@ int main(int argc, char *argv[])
|
||||||
if (!structure_ok) {
|
if (!structure_ok) {
|
||||||
if (!force) {
|
if (!force) {
|
||||||
fprintf(stderr, "ERROR: Input tree has structural errors, aborting (use -f to force output)\n");
|
fprintf(stderr, "ERROR: Input tree has structural errors, aborting (use -f to force output)\n");
|
||||||
exit(1);
|
exit(2);
|
||||||
} else if (quiet < 3) {
|
} else if (quiet < 3) {
|
||||||
fprintf(stderr, "Warning: Input tree has structural errors, output forced\n");
|
fprintf(stderr, "Warning: Input tree has structural errors, output forced\n");
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
#! /bin/sh
|
||||||
|
|
||||||
|
. tests.sh
|
||||||
|
|
||||||
|
TMPFILE="tmp.out.$$"
|
||||||
|
|
||||||
|
rm -f $TMPFILE
|
||||||
|
|
||||||
|
verbose_run "$DTC" -o $TMPFILE "$@"
|
||||||
|
ret="$?"
|
||||||
|
|
||||||
|
if [ -f $TMPFILE ]; then
|
||||||
|
FAIL "output file was created despite bad input"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$ret" = "2" ]; then
|
||||||
|
PASS
|
||||||
|
else
|
||||||
|
FAIL "dtc returned error code $ret instead of 2 (check failed)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -f $TMPFILE
|
20
tests/dtc.sh
20
tests/dtc.sh
|
@ -1,24 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
|
|
||||||
PASS () {
|
. tests.sh
|
||||||
echo "PASS"
|
|
||||||
exit 0
|
|
||||||
}
|
|
||||||
|
|
||||||
FAIL () {
|
|
||||||
echo "FAIL" "$@"
|
|
||||||
exit 2
|
|
||||||
}
|
|
||||||
|
|
||||||
DTC=../dtc
|
|
||||||
|
|
||||||
verbose_run () {
|
|
||||||
if [ -z "$QUIET_TEST" ]; then
|
|
||||||
"$@"
|
|
||||||
else
|
|
||||||
"$@" > /dev/null 2> /dev/null
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
if verbose_run "$DTC" "$@"; then
|
if verbose_run "$DTC" "$@"; then
|
||||||
PASS
|
PASS
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
/dts-v1/;
|
||||||
|
|
||||||
|
/ {
|
||||||
|
node {
|
||||||
|
};
|
||||||
|
node {
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,10 @@
|
||||||
|
/dts-v1/;
|
||||||
|
|
||||||
|
/ {
|
||||||
|
node1 {
|
||||||
|
linux,phandle = <1>;
|
||||||
|
};
|
||||||
|
node2 {
|
||||||
|
linux,phandle = <1>;
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,6 @@
|
||||||
|
/dts-v1/;
|
||||||
|
|
||||||
|
/ {
|
||||||
|
prop;
|
||||||
|
prop;
|
||||||
|
};
|
|
@ -0,0 +1,7 @@
|
||||||
|
/dts-v1/;
|
||||||
|
|
||||||
|
/ {
|
||||||
|
node {
|
||||||
|
linux,phandle = <0xffffffff>;
|
||||||
|
};
|
||||||
|
};
|
|
@ -142,6 +142,12 @@ dtc_tests () {
|
||||||
run_test dtbs_equal_ordered $tree odts_$tree.test.dtb
|
run_test dtbs_equal_ordered $tree odts_$tree.test.dtb
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Check some checks
|
||||||
|
run_test dtc-checkfails.sh -I dts -O dtb dup-nodename.dts
|
||||||
|
run_test dtc-checkfails.sh -I dts -O dtb dup-propname.dts
|
||||||
|
run_test dtc-checkfails.sh -I dts -O dtb dup-phandle.dts
|
||||||
|
run_test dtc-checkfails.sh -I dts -O dtb zero-phandle.dts
|
||||||
|
run_test dtc-checkfails.sh -I dts -O dtb minusone-phandle.dts
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts "vdt:" ARG ; do
|
while getopts "vdt:" ARG ; do
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
# Common functions for shell testcases
|
||||||
|
|
||||||
|
PASS () {
|
||||||
|
echo "PASS"
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
FAIL () {
|
||||||
|
echo "FAIL" "$@"
|
||||||
|
exit 2
|
||||||
|
}
|
||||||
|
|
||||||
|
DTC=../dtc
|
||||||
|
|
||||||
|
verbose_run () {
|
||||||
|
if [ -z "$QUIET_TEST" ]; then
|
||||||
|
"$@"
|
||||||
|
else
|
||||||
|
"$@" > /dev/null 2> /dev/null
|
||||||
|
fi
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
/dts-v1/;
|
||||||
|
|
||||||
|
/ {
|
||||||
|
node {
|
||||||
|
linux,phandle = <0>;
|
||||||
|
};
|
||||||
|
};
|
Loading…
Reference in New Issue