Skip to content
Snippets Groups Projects
Commit 72b524cf authored by Simon Glass's avatar Simon Glass Committed by Tom Rini
Browse files

test: Handle driver model reinit in test_pre_run()


For driver model tests we want to reinit the data structures so that
everything is in a known state before the test runs. This avoids one test
changing something that breaks a subsequent tests.

Move the call for this into test_pre_run().

Signed-off-by: Simon Glass's avatarSimon Glass <sjg@chromium.org>
parent 47ec3ede
No related branches found
No related tags found
No related merge requests found
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
* @fail_count: Number of tests that failed * @fail_count: Number of tests that failed
* @start: Store the starting mallinfo when doing leak test * @start: Store the starting mallinfo when doing leak test
* @priv: A pointer to some other info some suites want to track * @priv: A pointer to some other info some suites want to track
* @of_live: true to use livetree if available, false to use flattree
* @of_root: Record of the livetree root node (used for setting up tests) * @of_root: Record of the livetree root node (used for setting up tests)
* @expect_str: Temporary string used to hold expected string value * @expect_str: Temporary string used to hold expected string value
* @actual_str: Temporary string used to hold actual string value * @actual_str: Temporary string used to hold actual string value
...@@ -24,6 +25,7 @@ struct unit_test_state { ...@@ -24,6 +25,7 @@ struct unit_test_state {
struct mallinfo start; struct mallinfo start;
void *priv; void *priv;
struct device_node *of_root; struct device_node *of_root;
bool of_live;
char expect_str[256]; char expect_str[256];
char actual_str[256]; char actual_str[256];
}; };
......
...@@ -387,6 +387,16 @@ int test_pre_run(struct unit_test_state *uts, struct unit_test *test); ...@@ -387,6 +387,16 @@ int test_pre_run(struct unit_test_state *uts, struct unit_test *test);
*/ */
int test_post_run(struct unit_test_state *uts, struct unit_test *test); int test_post_run(struct unit_test_state *uts, struct unit_test *test);
/**
* dm_test_init() - Get ready to run a driver model test
*
* This clears out the driver model data structures. For sandbox it resets the
* state structure.
*
* @uts: Test state
*/
int dm_test_init(struct unit_test_state *uts);
/** /**
* ut_run_tests() - Run a set of tests * ut_run_tests() - Run a set of tests
* *
......
...@@ -24,10 +24,10 @@ DECLARE_GLOBAL_DATA_PTR; ...@@ -24,10 +24,10 @@ DECLARE_GLOBAL_DATA_PTR;
struct unit_test_state global_dm_test_state; struct unit_test_state global_dm_test_state;
static struct dm_test_state _global_priv_dm_test_state; static struct dm_test_state _global_priv_dm_test_state;
/* Get ready for testing */ int dm_test_init(struct unit_test_state *uts)
static int dm_test_init(struct unit_test_state *uts, bool of_live)
{ {
struct dm_test_state *dms = uts->priv; struct dm_test_state *dms = uts->priv;
bool of_live = uts->of_live;
memset(dms, '\0', sizeof(*dms)); memset(dms, '\0', sizeof(*dms));
gd->dm_root = NULL; gd->dm_root = NULL;
...@@ -70,7 +70,7 @@ static int dm_do_test(struct unit_test_state *uts, struct unit_test *test, ...@@ -70,7 +70,7 @@ static int dm_do_test(struct unit_test_state *uts, struct unit_test *test,
printf("Test: %s: %s%s\n", test->name, fname, printf("Test: %s: %s%s\n", test->name, fname,
!of_live ? " (flat tree)" : ""); !of_live ? " (flat tree)" : "");
ut_assertok(dm_test_init(uts, of_live)); uts->of_live = of_live;
ut_assertok(test_pre_run(uts, test)); ut_assertok(test_pre_run(uts, test));
......
...@@ -30,6 +30,9 @@ static int do_autoprobe(struct unit_test_state *uts) ...@@ -30,6 +30,9 @@ static int do_autoprobe(struct unit_test_state *uts)
int test_pre_run(struct unit_test_state *uts, struct unit_test *test) int test_pre_run(struct unit_test_state *uts, struct unit_test *test)
{ {
if (test->flags & UT_TESTF_DM)
ut_assertok(dm_test_init(uts));
ut_set_skip_delays(uts, false); ut_set_skip_delays(uts, false);
uts->start = mallinfo(); uts->start = mallinfo();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment