summaryrefslogtreecommitdiff
path: root/tests/dtbs_equal_ordered.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2010-04-30 15:30:00 +1000
committerJon Loeliger <jdl@jdl.com>2010-04-30 08:36:54 -0500
commite3b32b75b54834bc4d55db22636b6504eabb788e (patch)
tree77deaf51fafdce9a41c344e1a37e2aa4b6b5e3e8 /tests/dtbs_equal_ordered.c
parent341df2bdc3f9664587a57f947249c3208da77c9b (diff)
downloaddevice-tree-compiler-e3b32b75b54834bc4d55db22636b6504eabb788e.tar.gz
dtc: Extend and better test dtbs_equal utility programs (resend)
The dtbs_equal_ordered test program is used to implement a number of testcases. However, the test program itself has never been particularly well tested. In addition there are testcases coming in future for which it would be useful to have a corresponding "dtbs_equal_unordered" which checks for equality of device trees, not considering the internal ordering of elements. Finally, for some tests we may want it would be useful to check trees for equality with the PASS case being when they are *not* equal. This patch addresses all of the above. A dtbs_equal_unordered is added, and both it and the existing dtbs_equal_ordered program now take a -n option to make the PASS case be where the trees are not equal. A number of example trees with slight modifications from test_tree1 are used to verify that both these programs correctly identify when the tree is altered, and a dtb_reverse program is used to verify that the unordered version does not depend on internal ordering. These new testcases for the equality testing programs are split out into a new test group in run_tests.sh. dtbs_equal_unordered uses the new property iteration functions, and so this also acts as further testing for those functions. dtbs_equal_unordered will be useful for further testing the recently added tree-merging code and its upcoming extensions. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'tests/dtbs_equal_ordered.c')
-rw-r--r--tests/dtbs_equal_ordered.c87
1 files changed, 56 insertions, 31 deletions
diff --git a/tests/dtbs_equal_ordered.c b/tests/dtbs_equal_ordered.c
index ed9278c..1db25f4 100644
--- a/tests/dtbs_equal_ordered.c
+++ b/tests/dtbs_equal_ordered.c
@@ -29,6 +29,31 @@
#include "tests.h"
#include "testdata.h"
+int notequal; /* = 0 */
+
+#define MISMATCH(fmt, ...) \
+ do { \
+ if (notequal) \
+ PASS(); \
+ else \
+ FAIL(fmt, ##__VA_ARGS__); \
+ } while (0)
+
+#define MATCH() \
+ do { \
+ if (!notequal) \
+ PASS(); \
+ else \
+ FAIL("Trees match which shouldn't"); \
+ } while (0)
+
+#define CHECK(code) \
+ { \
+ err = (code); \
+ if (err) \
+ FAIL(#code ": %s", fdt_strerror(err)); \
+ }
+
static void compare_mem_rsv(const void *fdt1, const void *fdt2)
{
int i;
@@ -36,23 +61,18 @@ static void compare_mem_rsv(const void *fdt1, const void *fdt2)
int err;
if (fdt_num_mem_rsv(fdt1) != fdt_num_mem_rsv(fdt2))
- FAIL("Trees have different number of reserve entries");
+ MISMATCH("Trees have different number of reserve entries");
for (i = 0; i < fdt_num_mem_rsv(fdt1); i++) {
- err = fdt_get_mem_rsv(fdt1, i, &addr1, &size1);
- if (err)
- FAIL("fdt_get_mem_rsv(fdt1, %d, ...): %s", i,
- fdt_strerror(err));
- err = fdt_get_mem_rsv(fdt2, i, &addr2, &size2);
- if (err)
- FAIL("fdt_get_mem_rsv(fdt2, %d, ...): %s", i,
- fdt_strerror(err));
+ CHECK(fdt_get_mem_rsv(fdt1, i, &addr1, &size1));
+ CHECK(fdt_get_mem_rsv(fdt2, i, &addr2, &size2));
+
if ((addr1 != addr2) || (size1 != size2))
- FAIL("Mismatch in reserve entry %d: "
- "(0x%llx, 0x%llx) != (0x%llx, 0x%llx)", i,
- (unsigned long long)addr1,
- (unsigned long long)size1,
- (unsigned long long)addr2,
- (unsigned long long)size2);
+ MISMATCH("Mismatch in reserve entry %d: "
+ "(0x%llx, 0x%llx) != (0x%llx, 0x%llx)", i,
+ (unsigned long long)addr1,
+ (unsigned long long)size1,
+ (unsigned long long)addr2,
+ (unsigned long long)size2);
}
}
@@ -77,7 +97,7 @@ static void compare_structure(const void *fdt1, const void *fdt2)
} while (tag2 == FDT_NOP);
if (tag1 != tag2)
- FAIL("Tag mismatch (%d != %d) at (%d, %d)",
+ MISMATCH("Tag mismatch (%d != %d) at (%d, %d)",
tag1, tag2, offset1, offset2);
switch (tag1) {
@@ -90,9 +110,10 @@ static void compare_structure(const void *fdt1, const void *fdt2)
if (!name2)
FAIL("fdt_get_name(fdt2, %d, ..): %s",
offset2, fdt_strerror(err));
+
if (!streq(name1, name2))
- FAIL("Name mismatch (\"%s\" != \"%s\") at (%d, %d)",
- name1, name2, offset1, offset2);
+ MISMATCH("Name mismatch (\"%s\" != \"%s\") at (%d, %d)",
+ name1, name2, offset1, offset2);
break;
case FDT_PROP:
@@ -106,17 +127,17 @@ static void compare_structure(const void *fdt1, const void *fdt2)
name1 = fdt_string(fdt1, fdt32_to_cpu(prop1->nameoff));
name2 = fdt_string(fdt2, fdt32_to_cpu(prop2->nameoff));
if (!streq(name1, name2))
- FAIL("Property name mismatch \"%s\" != \"%s\" "
- "at (%d, %d)", name1, name2, offset1, offset2);
+ MISMATCH("Property name mismatch \"%s\" != \"%s\" "
+ "at (%d, %d)", name1, name2, offset1, offset2);
len1 = fdt32_to_cpu(prop1->len);
len2 = fdt32_to_cpu(prop2->len);
if (len1 != len2)
- FAIL("Property length mismatch %u != %u "
- "at (%d, %d)", len1, len2, offset1, offset2);
+ MISMATCH("Property length mismatch %u != %u "
+ "at (%d, %d)", len1, len2, offset1, offset2);
if (memcmp(prop1->data, prop2->data, len1) != 0)
- FAIL("Property value mismatch at (%d, %d)",
- offset1, offset2);
+ MISMATCH("Property value mismatch at (%d, %d)",
+ offset1, offset2);
break;
case FDT_END:
@@ -131,10 +152,14 @@ int main(int argc, char *argv[])
uint32_t cpuid1, cpuid2;
test_init(argc, argv);
- if (argc != 3)
- CONFIG("Usage: %s <dtb file> <dtb file>", argv[0]);
- fdt1 = load_blob(argv[1]);
- fdt2 = load_blob(argv[2]);
+ if ((argc != 3)
+ && ((argc != 4) || !streq(argv[1], "-n")))
+ CONFIG("Usage: %s [-n] <dtb file> <dtb file>", argv[0]);
+ if (argc == 4)
+ notequal = 1;
+
+ fdt1 = load_blob(argv[argc-2]);
+ fdt2 = load_blob(argv[argc-1]);
compare_mem_rsv(fdt1, fdt2);
compare_structure(fdt1, fdt2);
@@ -142,8 +167,8 @@ int main(int argc, char *argv[])
cpuid1 = fdt_boot_cpuid_phys(fdt1);
cpuid2 = fdt_boot_cpuid_phys(fdt2);
if (cpuid1 != cpuid2)
- FAIL("boot_cpuid_phys mismatch 0x%x != 0x%x",
- cpuid1, cpuid2);
+ MISMATCH("boot_cpuid_phys mismatch 0x%x != 0x%x",
+ cpuid1, cpuid2);
- PASS();
+ MATCH();
}