diff options
author | Yuval Peress <peress@chromium.org> | 2020-01-14 11:02:34 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-02-14 01:06:36 +0000 |
commit | e8b5147f37bdb347ba25780bc4b969b37fd6b239 (patch) | |
tree | e6098efccad4da3009a0b9ac738f6a3d7014d7b5 /test/motion_sense_fifo.c | |
parent | 73abf0fc5fe3c55c6374a5c779569136e675cf0a (diff) | |
download | chrome-ec-e8b5147f37bdb347ba25780bc4b969b37fd6b239.tar.gz |
common: motion_sense_fifo: fix iteration bug
Fix potential bug when iterating over FIFO entries for commit.
This bug can manifest when non-timestamp/non-data entries are
inserted into the FIFO.
TEST=Added unit tests
BRANCH=None
BUG=b:138303429,chromium:1023858
Change-Id: I64855db2141f7ad6aafb3f3a84632a1dabef11f4
Signed-off-by: Yuval Peress <peress@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2012846
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Diffstat (limited to 'test/motion_sense_fifo.c')
-rw-r--r-- | test/motion_sense_fifo.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/motion_sense_fifo.c b/test/motion_sense_fifo.c index 9762fa61c9..bc678b00cb 100644 --- a/test/motion_sense_fifo.c +++ b/test/motion_sense_fifo.c @@ -314,6 +314,35 @@ static int test_spread_double_commit_same_timestamp(void) return EC_SUCCESS; } +static int test_commit_non_data_or_timestamp_entries(void) +{ + const uint32_t now = __hw_clock_source_read(); + int read_count; + + motion_sensors[0].oversampling_ratio = 1; + motion_sensors[0].collection_rate = 20000; /* ns */ + + /* Insert non-data entry */ + data[0].flags = MOTIONSENSE_SENSOR_FLAG_ODR; + motion_sense_fifo_stage_data(data, motion_sensors, 3, now - 20500); + + /* Insert data entry */ + data[0].flags = 0; + motion_sense_fifo_stage_data(data, motion_sensors, 3, now - 20500); + + motion_sense_fifo_commit_data(); + read_count = motion_sense_fifo_read( + sizeof(data), CONFIG_ACCEL_FIFO_SIZE, data, &data_bytes_read); + TEST_EQ(read_count, 4, "%d"); + TEST_BITS_SET(data[0].flags, MOTIONSENSE_SENSOR_FLAG_TIMESTAMP); + TEST_EQ(data[0].timestamp, now - 20500, "%u"); + TEST_BITS_SET(data[1].flags, MOTIONSENSE_SENSOR_FLAG_ODR); + TEST_BITS_SET(data[2].flags, MOTIONSENSE_SENSOR_FLAG_TIMESTAMP); + TEST_EQ(data[2].timestamp, now - 20500, "%u"); + + return EC_SUCCESS; +} + void before_test(void) { motion_sense_fifo_commit_data(); @@ -342,6 +371,7 @@ void run_test(void) RUN_TEST(test_spread_data_in_window); 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); test_print_result(); } |