summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAl Semjonovs <asemjonovs@google.com>2022-07-07 15:05:20 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-07-11 16:51:19 +0000
commit959e3100ec08be6ef5f78762e7d7e44347f91482 (patch)
tree836a7862c1498c20194cac6cf59acbe691030cd4
parentdbdfbfc45b2b07ad85d834d32375fb7e8bdaa2a8 (diff)
downloadchrome-ec-959e3100ec08be6ef5f78762e7d7e44347f91482.tar.gz
zephyr:test: Fix flaky tcs3400 test suite
TCS3400 driver data needs to be restored before and after each test BUG=b:236967124 BRANCH=none TEST=zmake test test-drivers (shuffled) Signed-off-by: Al Semjonovs <asemjonovs@google.com> Change-Id: I1b523a3d2552862db6fde1689adcdb9c27ad6c47 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3751768 Reviewed-by: Yuval Peress <peress@google.com>
-rw-r--r--zephyr/test/drivers/src/tcs3400.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/zephyr/test/drivers/src/tcs3400.c b/zephyr/test/drivers/src/tcs3400.c
index 33c476c4d1..d7fcface36 100644
--- a/zephyr/test/drivers/src/tcs3400.c
+++ b/zephyr/test/drivers/src/tcs3400.c
@@ -602,4 +602,35 @@ ZTEST_USER(tcs3400, test_tcs_set_range)
zassert_equal(0x10000, ms->current_range, NULL);
}
-ZTEST_SUITE(tcs3400, drivers_predicate_post_main, NULL, NULL, NULL, NULL);
+struct tcs3400_test_fixture {
+ struct als_drv_data_t drv_data;
+ struct tcs3400_rgb_drv_data_t rgb_drv_data;
+};
+
+static void tcs3400_before(void *state)
+{
+ struct tcs3400_test_fixture *f = state;
+
+ f->drv_data = *TCS3400_DRV_DATA(&motion_sensors[TCS_CLR_SENSOR_ID]);
+ f->rgb_drv_data =
+ *TCS3400_RGB_DRV_DATA(&motion_sensors[TCS_RGB_SENSOR_ID]);
+}
+
+static void tcs3400_after(void *state)
+{
+ struct tcs3400_test_fixture *f = state;
+
+ *TCS3400_DRV_DATA(&motion_sensors[TCS_CLR_SENSOR_ID]) = f->drv_data;
+ *TCS3400_RGB_DRV_DATA(&motion_sensors[TCS_RGB_SENSOR_ID]) =
+ f->rgb_drv_data;
+}
+
+static void *tcs3400_setup(void)
+{
+ static struct tcs3400_test_fixture tcs3400_fixture = { 0 };
+
+ return &tcs3400_fixture;
+}
+
+ZTEST_SUITE(tcs3400, drivers_predicate_post_main, tcs3400_setup, tcs3400_before,
+ tcs3400_after, NULL);