test: Detect a change in the device tree

If the device tree changes during a test and we cannot restore it, mark
it as such so that future tests which need the live tree are skipped.

Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/test/test-main.c b/test/test-main.c
index 082821e..c12027c 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -79,6 +79,10 @@
 {
 	bool of_live = uts->of_live;
 
+	if (of_live && (gd->flags & GD_FLG_FDT_CHANGED)) {
+		printf("Cannot run live tree test as device tree changed\n");
+		return -EFAULT;
+	}
 	uts->root = NULL;
 	uts->testdev = NULL;
 	uts->force_fail_alloc = false;
@@ -113,9 +117,17 @@
 			uint chksum;
 
 			chksum = crc8(0, gd->fdt_blob, fdt_totalsize(gd->fdt_blob));
-
-			if (chksum != uts->fdt_chksum)
+			if (chksum != uts->fdt_chksum) {
+				/*
+				 * We cannot run any more tests that need the
+				 * live tree, since its strings point into the
+				 * flat tree, which has changed. This likely
+				 * means that at least some of the pointers from
+				 * the live tree point to different things
+				 */
 				printf("Device tree changed: cannot run live tree tests\n");
+				gd->flags |= GD_FLG_FDT_CHANGED;
+			}
 			break;
 		}
 		case FDTCHK_NONE:
@@ -415,7 +427,8 @@
 	 * or it is a core test.
 	 */
 	if (!(test->flags & UT_TESTF_LIVE_TREE) &&
-	    (!runs || ut_test_run_on_flattree(test))) {
+	    (!runs || ut_test_run_on_flattree(test)) &&
+	    !(gd->flags & GD_FLG_FDT_CHANGED)) {
 		uts->of_live = false;
 		ut_assertok(ut_run_test(uts, test, test->name));
 		runs++;