summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Peress <peress@google.com>2022-04-05 21:30:06 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-09-16 18:42:13 +0000
commitcdc98fc1e5eda898b704d17677d8fb091b33a3a6 (patch)
treef83f3bd6a7dbae9049184a06ad42cc713de8ef83
parent32ca95a8b0d435d2c1f1685d601ee6caef3c767a (diff)
downloadchrome-ec-cdc98fc1e5eda898b704d17677d8fb091b33a3a6.tar.gz
motion_sense_fifo: Add tests for the get_info function
Verify that all the fields returned by the get_info function are correctly filled per several different test scenarios. BRANCH=trogdor BUG=b:224614211, b:243492849 TEST=make run-motion_sense_fifo -j (cherry picked from commit 47e51bbb819b2966c2920bb47eb09bda70603843) Signed-off-by: Yuval Peress <peress@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3572852 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Commit-Queue: Jack Rosenthal <jrosenth@chromium.org> Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Change-Id: Ib544e3f1acbca21eb0d8a2bf7bf8ecf351a0a172 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3881928 Reviewed-by: Chao Gui <chaogui@google.com> Tested-by: Chao Gui <chaogui@google.com> Reviewed-by: Bob Moragues <moragues@chromium.org> Commit-Queue: Bob Moragues <moragues@chromium.org>
-rw-r--r--common/motion_sense_fifo.c3
-rw-r--r--test/motion_sense_fifo.c35
2 files changed, 37 insertions, 1 deletions
diff --git a/common/motion_sense_fifo.c b/common/motion_sense_fifo.c
index 45e42382bb..d3f0558c30 100644
--- a/common/motion_sense_fifo.c
+++ b/common/motion_sense_fifo.c
@@ -593,6 +593,7 @@ void motion_sense_fifo_get_info(
}
}
+/* 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 =
@@ -601,7 +602,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 f2524ff430..a2c94516c0 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");
@@ -371,14 +392,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)
@@ -400,6 +434,7 @@ void run_test(int argc, char **argv)
RUN_TEST(test_spread_data_on_overflow);
RUN_TEST(test_spread_data_by_collection_rate);
RUN_TEST(test_commit_non_data_or_timestamp_entries);
+ RUN_TEST(test_get_info_size);
test_print_result();
}