[PATCH 02/15] test: Allow saving and restoring the bloblist

Simon Glass sjg at chromium.org
Mon Oct 28 13:47:53 CET 2024


Tests which create a new bloblist overwrite the existing one in sandbox.
Provide a flag for tests to declare this behaviour. Save and restore the
bloblist pointer so that other tests remain unaffected.

Note that when sandbox is running normally, the bloblist has been
relocated to high in memory. The existing bloblist tests create a new
bloblist low in memory, so they do not conflict.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 include/test/test.h |  3 +++
 test/test-main.c    | 13 +++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/include/test/test.h b/include/test/test.h
index 92eec2eb6f9..21c0478befe 100644
--- a/include/test/test.h
+++ b/include/test/test.h
@@ -29,6 +29,7 @@
  * @of_other: Live tree for the other FDT
  * @runs_per_test: Number of times to run each test (typically 1)
  * @force_run: true to run tests marked with the UTF_MANUAL flag
+ * @old_bloblist: stores the old gd->bloblist pointer
  * @expect_str: Temporary string used to hold expected string value
  * @actual_str: Temporary string used to hold actual string value
  */
@@ -50,6 +51,7 @@ struct unit_test_state {
 	struct device_node *of_other;
 	int runs_per_test;
 	bool force_run;
+	void *old_bloblist;
 	char expect_str[512];
 	char actual_str[512];
 };
@@ -73,6 +75,7 @@ enum ut_flags {
 	UTF_MANUAL	= BIT(8),
 	UTF_ETH_BOOTDEV	= BIT(9),	/* enable Ethernet bootdevs */
 	UTF_SF_BOOTDEV	= BIT(10),	/* enable SPI flash bootdevs */
+	UFT_BLOBLIST	= BIT(11),	/* test changes gd->bloblist */
 };
 
 /**
diff --git a/test/test-main.c b/test/test-main.c
index c825f9c7797..e1e8c6cde4b 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -4,6 +4,8 @@
  * Written by Simon Glass <sjg at chromium.org>
  */
 
+#define LOG_CATEGORY	LOGC_TEST
+
 #include <blk.h>
 #include <console.h>
 #include <cyclic.h>
@@ -379,6 +381,12 @@ static int test_pre_run(struct unit_test_state *uts, struct unit_test *test)
 			return -EAGAIN;
 		}
 	}
+	if (test->flags & UFT_BLOBLIST) {
+		log_debug("save bloblist %p\n", gd->bloblist);
+		uts->old_bloblist = gd->bloblist;
+		gd->bloblist = NULL;
+	}
+
 	ut_silence_console(uts);
 
 	return 0;
@@ -402,6 +410,11 @@ static int test_post_run(struct unit_test_state *uts, struct unit_test *test)
 	free(uts->of_other);
 	uts->of_other = NULL;
 
+	if (test->flags & UFT_BLOBLIST) {
+		gd->bloblist = uts->old_bloblist;
+		log_debug("restore bloblist %p\n", gd->bloblist);
+	}
+
 	blkcache_free();
 
 	return 0;
-- 
2.43.0



More information about the U-Boot mailing list