summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Peress <peress@google.com>2022-04-06 21:44:14 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-09-16 18:42:02 +0000
commitbac21aa7ab72bf27e76ec1dfb6ae207974c943b3 (patch)
tree5e5aa2448ef50a7f9cf639363076ced6ab9414ba
parent3707156f639a3c9ebd6415446ca6753f7cd5922c (diff)
downloadchrome-ec-bac21aa7ab72bf27e76ec1dfb6ae207974c943b3.tar.gz
test: add test for fifo pop
Test the case where the entry being removed has fewer than 2 entries in the fifo. This would trigger us to look at other sensors to see if timestamp spreading is still needed. The test verifies that the correct sample is at the head of the sensor data and that the timestamps were spread. BRANCH=trogdor BUG=b:224614211, b:243492849 TEST=make run-motion_sense_fifo -j Signed-off-by: Yuval Peress <peress@google.com> (cherry picked from commit 39ac0322e2b2772615f8a73ae7a6cae5ac185b4c) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3575698 Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Keith Short <keithshort@chromium.org> Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Change-Id: I5771247722d0e2cc4b1765d9da2b6d66e649303d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3881926 Reviewed-by: Chao Gui <chaogui@google.com> Reviewed-by: Bob Moragues <moragues@chromium.org> Commit-Queue: Bob Moragues <moragues@chromium.org> Tested-by: Chao Gui <chaogui@google.com>
-rw-r--r--test/motion_sense_fifo.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/test/motion_sense_fifo.c b/test/motion_sense_fifo.c
index b20eb9a36f..bdac86d942 100644
--- a/test/motion_sense_fifo.c
+++ b/test/motion_sense_fifo.c
@@ -269,6 +269,58 @@ static int test_spread_data_in_window(void)
return EC_SUCCESS;
}
+static int test_spread_data_on_overflow(void)
+{
+ const uint32_t now = __hw_clock_source_read();
+ const int fill_count = (CONFIG_ACCEL_FIFO_SIZE / 2) - 1;
+ int i, read_count;
+
+ /* Set up the sensors */
+ motion_sensors[0].collection_rate = 20; /* us */
+ motion_sensors[0].oversampling_ratio = 1;
+ motion_sensors[1].oversampling_ratio = 1;
+
+ /* Add 1 sample for sensor [1]. This will be evicted. */
+ data->sensor_num = 1;
+ motion_sense_fifo_stage_data(data, motion_sensors + 1, 3, 0);
+
+ /*
+ * Fill the rest of the fifo, every 2 entries will have the same
+ * timestamp simulating have 2 entries on the hardware FIFO per read.
+ */
+ data->sensor_num = 0;
+ for (i = 0; i < fill_count; i++) {
+ int ts = now - ((fill_count - i) / 2) * 10;
+
+ motion_sense_fifo_stage_data(data, motion_sensors, 3, ts);
+ }
+
+ /* Insert an async event which also causes a commit */
+ motion_sense_fifo_insert_async_event(motion_sensors, ASYNC_EVENT_FLUSH);
+
+ read_count =
+ motion_sense_fifo_read(sizeof(data), 4, data, &data_bytes_read);
+
+ /* Verify that we read 4 entries */
+ TEST_EQ(read_count, 4, "%d");
+
+ /* Verify that entries 0 and 2 are timestamps (1 and 3 are data) */
+ TEST_BITS_SET(data[0].flags, MOTIONSENSE_SENSOR_FLAG_TIMESTAMP);
+ TEST_BITS_SET(data[2].flags, MOTIONSENSE_SENSOR_FLAG_TIMESTAMP);
+
+ /*
+ * Verify that the first read entry is the first one added in the for
+ * loop above.
+ */
+ TEST_EQ(data[0].sensor_num, 0, "%u");
+ TEST_EQ(data[0].timestamp, now - ((fill_count - 1) / 2) * 10, "%u");
+
+ /* Verify that the timestamp was spread */
+ TEST_NE(data[0].timestamp, data[2].timestamp, "%u");
+
+ return EC_SUCCESS;
+}
+
static int test_spread_data_by_collection_rate(void)
{
const uint32_t now = __hw_clock_source_read();
@@ -374,6 +426,7 @@ void run_test(int argc, char **argv)
RUN_TEST(test_add_data_no_spreading_when_different_sensors);
RUN_TEST(test_add_data_no_spreading_different_timestamps);
RUN_TEST(test_spread_data_in_window);
+ RUN_TEST(test_spread_data_on_overflow);
RUN_TEST(test_spread_data_by_collection_rate);
RUN_TEST(test_spread_double_commit_same_timestamp);
RUN_TEST(test_commit_non_data_or_timestamp_entries);