[PATCH v2 18/45] test: Detect a change in the device tree

Simon Glass sjg at chromium.org
Wed Sep 7 04:27:06 CEST 2022


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 at chromium.org>
---

(no changes since v1)

 include/asm-generic/global_data.h |  4 ++++
 test/test-main.c                  | 19 ++++++++++++++++---
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h
index 805a6fd6797..57e6959ace1 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -635,6 +635,10 @@ enum gd_flags {
 	 * @GD_FLG_SMP_READY: SMP initialization is complete
 	 */
 	GD_FLG_SMP_READY = 0x80000,
+	/**
+	 * @GD_FLG_FDT_CHANGED: Device tree change has been detected by tests
+	 */
+	GD_FLG_FDT_CHANGED = 0x100000,
 };
 
 #endif /* __ASSEMBLY__ */
diff --git a/test/test-main.c b/test/test-main.c
index 8a9439eec4a..7ab0d6ba53b 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -78,6 +78,10 @@ static int dm_test_pre_run(struct unit_test_state *uts)
 {
 	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;
@@ -112,9 +116,17 @@ static int dm_test_post_run(struct unit_test_state *uts)
 			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:
@@ -412,7 +424,8 @@ static int ut_run_test_live_flat(struct unit_test_state *uts,
 	 * 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++;
-- 
2.37.2.789.g6183377224-goog



More information about the U-Boot mailing list