diff options
-rw-r--r-- | common/motion_sense_fifo.c | 3 | ||||
-rw-r--r-- | test/motion_sense_fifo.c | 35 |
2 files changed, 37 insertions, 1 deletions
diff --git a/common/motion_sense_fifo.c b/common/motion_sense_fifo.c index 244032d10a..5743d0fdcb 100644 --- a/common/motion_sense_fifo.c +++ b/common/motion_sense_fifo.c @@ -575,6 +575,7 @@ void motion_sense_fifo_get_info( fifo_lost = 0; } +/* LCOV_EXCL_START - function cannot be tested due to limitations with mkbp */ static int motion_sense_get_next_event(uint8_t *out) { union ec_response_get_next_data *data = @@ -583,7 +584,7 @@ static int motion_sense_get_next_event(uint8_t *out) motion_sense_fifo_get_info(&data->sensor_fifo.info, 0); return sizeof(data->sensor_fifo); } - +/* LCOV_EXCL_STOP */ DECLARE_EVENT_SOURCE(EC_MKBP_EVENT_SENSOR_FIFO, motion_sense_get_next_event); inline int motion_sense_fifo_over_thres(void) diff --git a/test/motion_sense_fifo.c b/test/motion_sense_fifo.c index bdac86d942..ad333caa28 100644 --- a/test/motion_sense_fifo.c +++ b/test/motion_sense_fifo.c @@ -5,6 +5,7 @@ * Test motion_sense_fifo. */ +#include "ec_commands.h" #include "stdio.h" #include "motion_sense_fifo.h" #include "test_util.h" @@ -149,6 +150,7 @@ static int test_stage_data_removed_oversample(void) static int test_stage_data_remove_all_oversampling(void) { + struct ec_response_motion_sense_fifo_info fifo_info; int read_count; motion_sensors->oversampling_ratio = 0; @@ -162,6 +164,15 @@ static int test_stage_data_remove_all_oversampling(void) data->data[1] = 5; data->data[2] = 6; motion_sense_fifo_stage_data(data, motion_sensors, 3, 110); + + /* + * Check that count is 0 and total_lost is 0, oversampling should be + * removing the data before it touches the FIFO. + */ + motion_sense_fifo_get_info(&fifo_info, /*reset=*/false); + TEST_EQ(fifo_info.count, 0, "%d"); + TEST_EQ(fifo_info.total_lost, 0, "%d"); + motion_sense_fifo_commit_data(); read_count = motion_sense_fifo_read( @@ -177,6 +188,7 @@ static int test_stage_data_remove_all_oversampling(void) static int test_stage_data_evicts_data_with_timestamp(void) { + struct ec_response_motion_sense_fifo_info fifo_info; int i, read_count; /* Fill the fifo */ @@ -186,6 +198,15 @@ static int test_stage_data_evicts_data_with_timestamp(void) /* Add a single entry (should evict 2) */ motion_sense_fifo_add_timestamp(CONFIG_ACCEL_FIFO_SIZE * 100); + + /* + * Check that count is 1 smaller than the total size and total_lost is 2 + * because 2 entries were evicted together. + */ + motion_sense_fifo_get_info(&fifo_info, /*reset=*/false); + TEST_EQ(fifo_info.count, CONFIG_ACCEL_FIFO_SIZE - 1, "%d"); + TEST_EQ(fifo_info.total_lost, 2, "%d"); + read_count = motion_sense_fifo_read( sizeof(data), CONFIG_ACCEL_FIFO_SIZE, data, &data_bytes_read); TEST_EQ(read_count, CONFIG_ACCEL_FIFO_SIZE - 1, "%d"); @@ -400,14 +421,27 @@ static int test_commit_non_data_or_timestamp_entries(void) return EC_SUCCESS; } +static int test_get_info_size(void) +{ + struct ec_response_motion_sense_fifo_info fifo_info; + + motion_sense_fifo_get_info(&fifo_info, /*reset=*/false); + TEST_EQ(fifo_info.size, CONFIG_ACCEL_FIFO_SIZE, "%d"); + + return EC_SUCCESS; +} + void before_test(void) { + static struct ec_response_motion_sense_fifo_info fifo_info; + motion_sense_fifo_commit_data(); motion_sense_fifo_read(sizeof(data), CONFIG_ACCEL_FIFO_SIZE, &data, &data_bytes_read); motion_sense_fifo_reset_needed_flags(); memset(data, 0, sizeof(data)); motion_sense_fifo_reset(); + motion_sense_fifo_get_info(&fifo_info, /*reset=*/true); } void run_test(int argc, char **argv) @@ -430,6 +464,7 @@ void run_test(int argc, char **argv) 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); + RUN_TEST(test_get_info_size); test_print_result(); } |