[U-Boot] [PATCH v2 23/71] sandbox: Add a way to reset sandbox state for tests
Simon Glass
sjg at chromium.org
Wed May 10 14:21:02 UTC 2017
Running a new test should reset the sandbox state to avoid tests
interferring with each other. Move the existing state-reset code into a
function so it can be used from tests.
Also update the code to reset the SPI devices and adjust the test code to
call it.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
Changes in v2: None
arch/sandbox/cpu/state.c | 14 ++++++++++----
arch/sandbox/include/asm/state.h | 7 +++++++
test/dm/test-main.c | 1 +
3 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/arch/sandbox/cpu/state.c b/arch/sandbox/cpu/state.c
index 2b4dbd341f..b58bf39cce 100644
--- a/arch/sandbox/cpu/state.c
+++ b/arch/sandbox/cpu/state.c
@@ -351,6 +351,15 @@ bool state_get_skip_delays(void)
return state->skip_delays;
}
+void state_reset_for_test(struct sandbox_state *state)
+{
+ /* No reset yet, so mark it as such. Always allow power reset */
+ state->last_sysreset = SYSRESET_COUNT;
+ state->sysreset_allowed[SYSRESET_POWER] = true;
+
+ memset(state->spi, '\0', sizeof(state->spi));
+}
+
int state_init(void)
{
state = &main_state;
@@ -359,10 +368,7 @@ int state_init(void)
state->ram_buf = os_malloc(state->ram_size);
assert(state->ram_buf);
- /* No reset yet, so mark it as such. Always allow power reset */
- state->last_sysreset = SYSRESET_COUNT;
- state->sysreset_allowed[SYSRESET_POWER] = true;
-
+ state_reset_for_test(state);
/*
* Example of how to use GPIOs:
*
diff --git a/arch/sandbox/include/asm/state.h b/arch/sandbox/include/asm/state.h
index 149f28d873..3fa8b01dfa 100644
--- a/arch/sandbox/include/asm/state.h
+++ b/arch/sandbox/include/asm/state.h
@@ -204,6 +204,13 @@ void state_set_skip_delays(bool skip_delays);
*/
bool state_get_skip_delays(void);
+/**
+ * state_reset_for_test() - Reset ready to re-run tests
+ *
+ * This clears out any test state ready for another test run.
+ */
+void state_reset_for_test(struct sandbox_state *state);
+
/**
* Initialize the test system state
*/
diff --git a/test/dm/test-main.c b/test/dm/test-main.c
index 67c0082fb8..9aa9d3a953 100644
--- a/test/dm/test-main.c
+++ b/test/dm/test-main.c
@@ -29,6 +29,7 @@ static int dm_test_init(struct unit_test_state *uts)
memset(dms, '\0', sizeof(*dms));
gd->dm_root = NULL;
memset(dm_testdrv_op_count, '\0', sizeof(dm_testdrv_op_count));
+ state_reset_for_test(state_get_current());
ut_assertok(dm_init(false));
dms->root = dm_root();
--
2.13.0.rc2.291.g57267f2277-goog
More information about the U-Boot
mailing list