test: Make a copy of the device tree before running a test

When the flat device tree changes it can mess up the live tree since that
uses the flat tree for its strings. This affects only a few sandbox tests
which modify the device tree, but the number will grow as ofnode support
for writing improves.

While the control FDT is not intended to change while U-Boot is running,
some tests do so. For example, the ofnode interface only supports
modifying properties in the control FDT, so tests must use that.

To solve this problem, keep a copy of the FDT and restore it as needed
when the test is finished. The copy only happens on sandbox (except SPL
builds), to reduce memory usage and because these tests are not useful on
other boards. For other boards, a checksum is taken to ensure that nothing
changes.

It would be possible to always checksum the FDT on sandbox and only
restore it if needed, but this is slightly slower than restoring it every
time, at least with crc8.

Move the code which checks for success to the very end, for clarity.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2022-09-06 20:27:05 -06:00
committed by Tom Rini
parent 9830698765
commit 0e4b697f88
3 changed files with 83 additions and 14 deletions

View File

@@ -20,6 +20,9 @@
* @testdev: Test device
* @force_fail_alloc: Force all memory allocs to fail
* @skip_post_probe: Skip uclass post-probe processing
* @fdt_chksum: crc8 of the device tree contents
* @fdt_copy: Copy of the device tree
* @fdt_size: Size of the device-tree copy
* @runs_per_test: Number of times to run each test (typically 1)
* @expect_str: Temporary string used to hold expected string value
* @actual_str: Temporary string used to hold actual string value
@@ -33,6 +36,9 @@ struct unit_test_state {
struct udevice *testdev;
int force_fail_alloc;
int skip_post_probe;
uint fdt_chksum;
void *fdt_copy;
uint fdt_size;
int runs_per_test;
char expect_str[512];
char actual_str[512];