summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Peress <peress@google.com>2022-04-26 10:53:54 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-04-29 18:57:48 +0000
commit2dd94c6b793eaec5ed36b2d3f645f23c9837566c (patch)
treeeb51bb50ccecd1b765d30ee0c1dc4833225b1b6b
parent6ca603504d2e5b466e8f8236dcd11ede8e693fc3 (diff)
downloadchrome-ec-2dd94c6b793eaec5ed36b2d3f645f23c9837566c.tar.gz
test: refactor fixtures
Some clean-up from my previous mistakes of having the fixture as a global static. BRANCH=none BUG=none TEST=zmake test test-drivers Signed-off-by: Yuval Peress <peress@google.com> Change-Id: I81645a538eda5ebe8419fdd0b060cfea1836d6cb Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3608481 Reviewed-by: Aaron Massey <aaronmassey@google.com>
-rw-r--r--zephyr/test/drivers/src/console_cmd/accelinit.c22
-rw-r--r--zephyr/test/drivers/src/console_cmd/accelread.c39
-rw-r--r--zephyr/test/drivers/src/console_cmd/accelres.c23
-rw-r--r--zephyr/test/drivers/src/host_cmd/motion_sense.c33
4 files changed, 61 insertions, 56 deletions
diff --git a/zephyr/test/drivers/src/console_cmd/accelinit.c b/zephyr/test/drivers/src/console_cmd/accelinit.c
index 39e1bd732e..22c7556558 100644
--- a/zephyr/test/drivers/src/console_cmd/accelinit.c
+++ b/zephyr/test/drivers/src/console_cmd/accelinit.c
@@ -20,29 +20,29 @@ struct console_cmd_accelinit_fixture {
struct accelgyro_drv mock_drv;
};
-static struct console_cmd_accelinit_fixture fixture = {
- .mock_drv = {
- .init = mock_init,
- },
-};
-
static void *console_cmd_accelinit_setup(void)
{
+ static struct console_cmd_accelinit_fixture fixture = {
+ .mock_drv = {
+ .init = mock_init,
+ },
+ };
fixture.sensor_0_drv = motion_sensors[0].drv;
return &fixture;
}
-static void console_cmd_accelinit_before(void *state)
+static void console_cmd_accelinit_before(void *fixture)
{
- ARG_UNUSED(state);
+ ARG_UNUSED(fixture);
RESET_FAKE(mock_init);
FFF_RESET_HISTORY();
}
-static void console_cmd_accelinit_after(void *state)
+static void console_cmd_accelinit_after(void *fixture)
{
- ARG_UNUSED(state);
- motion_sensors[0].drv = fixture.sensor_0_drv;
+ struct console_cmd_accelinit_fixture *this = fixture;
+
+ motion_sensors[0].drv = this->sensor_0_drv;
motion_sensors[0].drv->init(&motion_sensors[0]);
}
diff --git a/zephyr/test/drivers/src/console_cmd/accelread.c b/zephyr/test/drivers/src/console_cmd/accelread.c
index 4c3f880e01..d1bc24aa45 100644
--- a/zephyr/test/drivers/src/console_cmd/accelread.c
+++ b/zephyr/test/drivers/src/console_cmd/accelread.c
@@ -24,38 +24,38 @@ struct console_cmd_accelread_fixture {
struct accelgyro_drv mock_drv;
};
-static struct console_cmd_accelread_fixture fixture = {
- .mock_drv = {
- .read = mock_read,
- /*
- * Data rate functions are required so that motion_sense task
- * doesn't segfault.
- */
- .set_data_rate = mock_set_data_rate,
- .get_data_rate = mock_get_data_rate,
- },
-};
-
static void *console_cmd_accelread_setup(void)
{
+ static struct console_cmd_accelread_fixture fixture = {
+ .mock_drv = {
+ .read = mock_read,
+ /*
+ * Data rate functions are required so that motion_sense
+ * task doesn't segfault.
+ */
+ .set_data_rate = mock_set_data_rate,
+ .get_data_rate = mock_get_data_rate,
+ },
+ };
fixture.sensor_0_drv = motion_sensors[0].drv;
return &fixture;
}
-static void console_cmd_accelread_before(void *state)
+static void console_cmd_accelread_before(void *fixture)
{
- ARG_UNUSED(state);
+ ARG_UNUSED(fixture);
RESET_FAKE(mock_read);
RESET_FAKE(mock_set_data_rate);
RESET_FAKE(mock_get_data_rate);
FFF_RESET_HISTORY();
}
-static void console_cmd_accelread_after(void *state)
+static void console_cmd_accelread_after(void *fixture)
{
- ARG_UNUSED(state);
- motion_sensors[0].drv = fixture.sensor_0_drv;
+ struct console_cmd_accelread_fixture *this = fixture;
+
+ motion_sensors[0].drv = this->sensor_0_drv;
}
ZTEST_SUITE(console_cmd_accelread, drivers_predicate_post_main,
@@ -87,13 +87,16 @@ ZTEST_USER(console_cmd_accelread, test_invalid_sensor_num)
EC_ERROR_PARAM1, rv);
}
+static struct console_cmd_accelread_fixture *current_fixture;
+
int mock_read_call_super(const struct motion_sensor_t *s, int *v)
{
- return fixture.sensor_0_drv->read(s, v);
+ return current_fixture->sensor_0_drv->read(s, v);
}
ZTEST_USER_F(console_cmd_accelread, test_read)
{
+ current_fixture = this;
mock_read_fake.custom_fake = mock_read_call_super;
motion_sensors[0].drv = &this->mock_drv;
diff --git a/zephyr/test/drivers/src/console_cmd/accelres.c b/zephyr/test/drivers/src/console_cmd/accelres.c
index 64b3545e27..f466a0e28e 100644
--- a/zephyr/test/drivers/src/console_cmd/accelres.c
+++ b/zephyr/test/drivers/src/console_cmd/accelres.c
@@ -21,30 +21,31 @@ struct console_cmd_accelres_fixture {
struct accelgyro_drv mock_drv;
};
-static struct console_cmd_accelres_fixture fixture = {
- .mock_drv = {
- .set_resolution = set_resolution,
- },
-};
-
void *console_cmd_accelres_setup(void)
{
+ static struct console_cmd_accelres_fixture fixture = {
+ .mock_drv = {
+ .set_resolution = set_resolution,
+ },
+ };
+
fixture.sensor_0_drv = motion_sensors[0].drv;
return &fixture;
}
-void console_cmd_accelres_before(void *state)
+void console_cmd_accelres_before(void *fixture)
{
- ARG_UNUSED(state);
+ ARG_UNUSED(fixture);
RESET_FAKE(set_resolution);
FFF_RESET_HISTORY();
}
-void console_cmd_accelres_after(void *state)
+void console_cmd_accelres_after(void *fixture)
{
- ARG_UNUSED(state);
- motion_sensors[0].drv = fixture.sensor_0_drv;
+ struct console_cmd_accelres_fixture *this = fixture;
+
+ motion_sensors[0].drv = this->sensor_0_drv;
}
ZTEST_SUITE(console_cmd_accelres, drivers_predicate_post_main,
diff --git a/zephyr/test/drivers/src/host_cmd/motion_sense.c b/zephyr/test/drivers/src/host_cmd/motion_sense.c
index 08e794c5d4..5a76c41f24 100644
--- a/zephyr/test/drivers/src/host_cmd/motion_sense.c
+++ b/zephyr/test/drivers/src/host_cmd/motion_sense.c
@@ -34,27 +34,27 @@ struct host_cmd_motion_sense_fixture {
struct accelgyro_drv mock_drv;
};
-static struct host_cmd_motion_sense_fixture fixture = {
- .mock_drv = {
- .set_range = mock_set_range,
- .set_offset = mock_set_offset,
- .get_offset = mock_get_offset,
- .set_scale = mock_set_scale,
- .get_scale = mock_get_scale,
- .perform_calib = mock_perform_calib,
- },
-};
-
static void *host_cmd_motion_sense_setup(void)
{
+ static struct host_cmd_motion_sense_fixture fixture = {
+ .mock_drv = {
+ .set_range = mock_set_range,
+ .set_offset = mock_set_offset,
+ .get_offset = mock_get_offset,
+ .set_scale = mock_set_scale,
+ .get_scale = mock_get_scale,
+ .perform_calib = mock_perform_calib,
+ },
+ };
+
fixture.sensor_0_drv = motion_sensors[0].drv;
return &fixture;
}
-static void host_cmd_motion_sense_before(void *state)
+static void host_cmd_motion_sense_before(void *fixture)
{
- ARG_UNUSED(state);
+ ARG_UNUSED(fixture);
RESET_FAKE(mock_set_range);
RESET_FAKE(mock_set_offset);
RESET_FAKE(mock_get_offset);
@@ -67,10 +67,11 @@ static void host_cmd_motion_sense_before(void *state)
motion_sensors[0].config[SENSOR_CONFIG_AP].ec_rate = 1000 * MSEC;
}
-static void host_cmd_motion_sense_after(void *state)
+static void host_cmd_motion_sense_after(void *fixture)
{
- ARG_UNUSED(state);
- motion_sensors[0].drv = fixture.sensor_0_drv;
+ struct host_cmd_motion_sense_fixture *this = fixture;
+
+ motion_sensors[0].drv = this->sensor_0_drv;
}
ZTEST_SUITE(host_cmd_motion_sense, drivers_predicate_post_main,