summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorYuval Peress <peress@chromium.org>2019-10-29 15:02:37 -0600
committerCommit Bot <commit-bot@chromium.org>2020-02-13 00:56:05 +0000
commit88808c3dda819f9da22272850d2b56ab1e538c9f (patch)
tree614c8f28cb17c232ac74ac252b615fcecd554ba6 /test
parent4acc29890130946ad574ea0f314b65497efb7ce2 (diff)
downloadchrome-ec-88808c3dda819f9da22272850d2b56ab1e538c9f.tar.gz
common: Migrate online calibration to own module
This change moves the code that handles caching the temperature (which is the first step in online calibration) into a new compilational unit. TEST=None BRANCH=None BUG=b:138303429,chromium:1023858 Change-Id: Ib1fe3d2234dc2436e2bbfd4febd22196e5cdafef Signed-off-by: Yuval Peress <peress@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1906340 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/build.mk2
-rw-r--r--test/motion_sense_fifo.c99
-rw-r--r--test/online_calibration.c134
-rw-r--r--test/online_calibration.tasklist11
-rw-r--r--test/test_config.h20
5 files changed, 166 insertions, 100 deletions
diff --git a/test/build.mk b/test/build.mk
index 2b84ffe907..4235274312 100644
--- a/test/build.mk
+++ b/test/build.mk
@@ -56,6 +56,7 @@ test-list-host += motion_lid
test-list-host += motion_sense_fifo
test-list-host += mutex
test-list-host += newton_fit
+test-list-host += online_calibration
test-list-host += pingpong
test-list-host += pinweaver
test-list-host += power_button
@@ -136,6 +137,7 @@ motion_angle-y=motion_angle.o motion_angle_data_literals.o motion_common.o
motion_angle_tablet-y=motion_angle_tablet.o motion_angle_data_literals_tablet.o motion_common.o
motion_lid-y=motion_lid.o
motion_sense_fifo-y=motion_sense_fifo.o
+online_calibration-y=online_calibration.o
kasa-y=kasa.o
mutex-y=mutex.o
newton_fit-y=newton_fit.o
diff --git a/test/motion_sense_fifo.c b/test/motion_sense_fifo.c
index 7e436bd404..9762fa61c9 100644
--- a/test/motion_sense_fifo.c
+++ b/test/motion_sense_fifo.c
@@ -14,46 +14,9 @@
#include "accelgyro.h"
#include <sys/types.h>
-struct mock_read_temp_result {
- void *s;
- int temp;
- int ret;
- int used_count;
- struct mock_read_temp_result *next;
-};
-
-static struct mock_read_temp_result *mock_read_temp_results;
-
-static int mock_read_temp(const struct motion_sensor_t *s, int *temp)
-{
- struct mock_read_temp_result *ptr = mock_read_temp_results;
-
- while (ptr) {
- if (ptr->s == s) {
- if (ptr->ret == EC_SUCCESS)
- *temp = ptr->temp;
- ptr->used_count++;
- return ptr->ret;
- }
- ptr = ptr->next;
- }
-
- return EC_ERROR_UNKNOWN;
-}
-
-static struct accelgyro_drv mock_sensor_driver = {
- .read_temp = mock_read_temp,
-};
-
-static struct accelgyro_drv empty_sensor_driver = {};
-
struct motion_sensor_t motion_sensors[] = {
- [BASE] = {
- .drv = &mock_sensor_driver,
- },
- [LID] = {
- .drv = &empty_sensor_driver,
- },
+ [BASE] = {},
+ [LID] = {},
};
const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
@@ -351,59 +314,6 @@ static int test_spread_double_commit_same_timestamp(void)
return EC_SUCCESS;
}
-static int test_read_temp_on_stage(void)
-{
- struct mock_read_temp_result expected = { &motion_sensors[BASE], 200,
- EC_SUCCESS, 0, NULL };
-
- mock_read_temp_results = &expected;
- motion_sensors[0].oversampling_ratio = 1;
- motion_sensors[0].collection_rate = 20000; /* ns */
- motion_sense_fifo_stage_data(data, motion_sensors, 3,
- __hw_clock_source_read() - 10000);
-
- TEST_EQ(expected.used_count, 1, "%d");
-
- return EC_SUCCESS;
-}
-
-static int test_read_temp_from_cache_on_stage(void)
-{
- struct mock_read_temp_result expected = { &motion_sensors[BASE], 200,
- EC_SUCCESS, 0, NULL };
-
- mock_read_temp_results = &expected;
- motion_sensors[0].oversampling_ratio = 1;
- motion_sensors[0].collection_rate = 20000; /* ns */
- motion_sense_fifo_stage_data(data, motion_sensors, 3,
- __hw_clock_source_read() - 10000);
- motion_sense_fifo_stage_data(data, motion_sensors, 3,
- __hw_clock_source_read() - 5000);
-
- TEST_EQ(expected.used_count, 1, "%d");
-
- return EC_SUCCESS;
-}
-
-static int test_read_temp_twice_after_cache_stale(void)
-{
- struct mock_read_temp_result expected = { &motion_sensors[BASE], 200,
- EC_SUCCESS, 0, NULL };
-
- mock_read_temp_results = &expected;
- motion_sensors[0].oversampling_ratio = 1;
- motion_sensors[0].collection_rate = 20000; /* ns */
- motion_sense_fifo_stage_data(data, motion_sensors, 3,
- __hw_clock_source_read() - 10000);
- sleep(2);
- motion_sense_fifo_stage_data(data, motion_sensors, 3,
- __hw_clock_source_read() - 5000);
-
- TEST_EQ(expected.used_count, 2, "%d");
-
- return EC_SUCCESS;
-}
-
void before_test(void)
{
motion_sense_fifo_commit_data();
@@ -412,13 +322,13 @@ void before_test(void)
motion_sense_fifo_reset_wake_up_needed();
memset(data, 0, sizeof(data));
motion_sense_fifo_reset();
- mock_read_temp_results = NULL;
}
void run_test(void)
{
test_reset();
motion_sense_fifo_init();
+
RUN_TEST(test_insert_async_event);
RUN_TEST(test_wake_up_needed);
RUN_TEST(test_wake_up_needed_overflow);
@@ -432,9 +342,6 @@ 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_read_temp_on_stage);
- RUN_TEST(test_read_temp_from_cache_on_stage);
- RUN_TEST(test_read_temp_twice_after_cache_stale);
test_print_result();
}
diff --git a/test/online_calibration.c b/test/online_calibration.c
new file mode 100644
index 0000000000..f9fe0ee068
--- /dev/null
+++ b/test/online_calibration.c
@@ -0,0 +1,134 @@
+/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "online_calibration.h"
+#include "test_util.h"
+#include "hwtimer.h"
+#include "timer.h"
+#include "accelgyro.h"
+
+struct mock_read_temp_result {
+ void *s;
+ int temp;
+ int ret;
+ int used_count;
+ struct mock_read_temp_result *next;
+};
+
+static struct mock_read_temp_result *mock_read_temp_results;
+
+static int mock_read_temp(const struct motion_sensor_t *s, int *temp)
+{
+ struct mock_read_temp_result *ptr = mock_read_temp_results;
+
+ while (ptr) {
+ if (ptr->s == s) {
+ if (ptr->ret == EC_SUCCESS)
+ *temp = ptr->temp;
+ ptr->used_count++;
+ return ptr->ret;
+ }
+ ptr = ptr->next;
+ }
+
+ return EC_ERROR_UNKNOWN;
+}
+
+static struct accelgyro_drv mock_sensor_driver = {
+ .read_temp = mock_read_temp,
+};
+
+static struct accelgyro_drv empty_sensor_driver = {};
+
+struct motion_sensor_t motion_sensors[] = {
+ [BASE] = {
+ .drv = &mock_sensor_driver,
+ },
+ [LID] = {
+ .drv = &empty_sensor_driver,
+ },
+};
+
+const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+
+static int test_read_temp_on_stage(void)
+{
+ struct mock_read_temp_result expected = { &motion_sensors[BASE], 200,
+ EC_SUCCESS, 0, NULL };
+ struct ec_response_motion_sensor_data data;
+ int rc;
+
+ mock_read_temp_results = &expected;
+ data.sensor_num = 0;
+ rc = online_calibration_process_data(
+ &data, &motion_sensors[0], __hw_clock_source_read());
+
+ TEST_EQ(rc, EC_SUCCESS, "%d");
+ TEST_EQ(expected.used_count, 1, "%d");
+
+ return EC_SUCCESS;
+}
+
+static int test_read_temp_from_cache_on_stage(void)
+{
+ struct mock_read_temp_result expected = { &motion_sensors[BASE], 200,
+ EC_SUCCESS, 0, NULL };
+ struct ec_response_motion_sensor_data data;
+ int rc;
+
+ mock_read_temp_results = &expected;
+ data.sensor_num = 0;
+ rc = online_calibration_process_data(
+ &data, &motion_sensors[0], __hw_clock_source_read());
+ TEST_EQ(rc, EC_SUCCESS, "%d");
+
+ rc = online_calibration_process_data(
+ &data, &motion_sensors[0], __hw_clock_source_read());
+ TEST_EQ(rc, EC_SUCCESS, "%d");
+
+ TEST_EQ(expected.used_count, 1, "%d");
+
+ return EC_SUCCESS;
+}
+
+static int test_read_temp_twice_after_cache_stale(void)
+{
+ struct mock_read_temp_result expected = { &motion_sensors[BASE], 200,
+ EC_SUCCESS, 0, NULL };
+ struct ec_response_motion_sensor_data data;
+ int rc;
+
+ mock_read_temp_results = &expected;
+ data.sensor_num = 0;
+ rc = online_calibration_process_data(
+ &data, &motion_sensors[0], __hw_clock_source_read());
+ TEST_EQ(rc, EC_SUCCESS, "%d");
+
+ sleep(2);
+ rc = online_calibration_process_data(
+ &data, &motion_sensors[0], __hw_clock_source_read());
+ TEST_EQ(rc, EC_SUCCESS, "%d");
+
+ TEST_EQ(expected.used_count, 2, "%d");
+
+ return EC_SUCCESS;
+}
+
+void before_test(void)
+{
+ mock_read_temp_results = NULL;
+ online_calibration_init();
+}
+
+void run_test(void)
+{
+ test_reset();
+
+ RUN_TEST(test_read_temp_on_stage);
+ RUN_TEST(test_read_temp_from_cache_on_stage);
+ RUN_TEST(test_read_temp_twice_after_cache_stale);
+
+ test_print_result();
+}
diff --git a/test/online_calibration.tasklist b/test/online_calibration.tasklist
new file mode 100644
index 0000000000..5b67239ff8
--- /dev/null
+++ b/test/online_calibration.tasklist
@@ -0,0 +1,11 @@
+/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**
+ * See CONFIG_TASK_LIST in config.h for details.
+ */
+#define CONFIG_TEST_TASK_LIST \
+ TASK_TEST(MOTIONSENSE, motion_sense_task, NULL, TASK_STACK_SIZE)
+
diff --git a/test/test_config.h b/test/test_config.h
index 51275afb30..b0dac3deeb 100644
--- a/test/test_config.h
+++ b/test/test_config.h
@@ -72,6 +72,7 @@
#ifdef TEST_STILLNESS_DETECTOR
#define CONFIG_FPU
#define CONFIG_ONLINE_CALIB
+#define CONFIG_TEMP_CACHE_STALE_THRES (5 * SECOND)
#endif
#ifdef TEST_FLOAT
@@ -96,8 +97,6 @@
#define CONFIG_ACCEL_FIFO
#define CONFIG_ACCEL_FIFO_SIZE 256
#define CONFIG_ACCEL_FIFO_THRES 10
-#define CONFIG_ONLINE_CALIB
-#define CONFIG_TEMP_CACHE_STALE_THRES (1 * SECOND)
#endif
#ifdef TEST_KASA
@@ -119,8 +118,21 @@
#define CONFIG_ONLINE_CALIB
#endif
-#if defined(TEST_MOTION_LID) || defined(TEST_MOTION_ANGLE) || \
- defined(TEST_MOTION_ANGLE_TABLET) || defined(TEST_MOTION_SENSE_FIFO)
+#ifdef TEST_ONLINE_CALIBRATION
+#define CONFIG_GPU
+#define CONFIG_ONLINE_CALIB
+#endif
+
+#if defined(CONFIG_ONLINE_CALIB) && \
+ !defined(CONFIG_TEMP_CACHE_STALE_THRES)
+#define CONFIG_TEMP_CACHE_STALE_THRES (1 * SECOND)
+#endif /* CONFIG_ONLINE_CALIB && !CONFIG_TEMP_CACHE_STALE_THRES */
+
+#if defined(TEST_MOTION_LID) || \
+ defined(TEST_MOTION_ANGLE) || \
+ defined(TEST_MOTION_ANGLE_TABLET) || \
+ defined(TEST_MOTION_SENSE_FIFO) || \
+ defined(CONFIG_ONLINE_CALIB)
enum sensor_id {
BASE,
LID,