summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlec Berg <alecaberg@chromium.org>2014-07-07 12:00:31 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-07-08 02:18:28 +0000
commit9f8fabbe07a70dff2b0f424b539fd94e40e29d00 (patch)
tree8865a52e6cb465d9ffc626a7199638dda2ff220a
parent8291fd38415d1a81aa0b12d11264c6f966ba110a (diff)
downloadchrome-ec-9f8fabbe07a70dff2b0f424b539fd94e40e29d00.tar.gz
motion_sense: make unit test more reliable
Fix motion_sense unit test flakiness by making sure that the lid angle calculations ran by checking LPC sample id number instead of relying on a fixed time delay. BUG=chromium:391625 BRANCH=none TEST=make -j runtests Change-Id: I6e879ef28837e62e0c9d4e5f05e0165fa9f9a966 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/206878 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--test/motion_sense.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/test/motion_sense.c b/test/motion_sense.c
index 1ec3d4ad60..1836a524fe 100644
--- a/test/motion_sense.c
+++ b/test/motion_sense.c
@@ -8,6 +8,7 @@
#include <math.h>
#include "common.h"
+#include "host_command.h"
#include "motion_sense.h"
#include "task.h"
#include "test_util.h"
@@ -64,6 +65,9 @@ int accel_get_datarate(const enum accel_id id, int * const rate)
/* Test utilities */
static int test_lid_angle(void)
{
+ uint8_t *lpc_status = host_get_memmap(EC_MEMMAP_ACC_STATUS);
+ uint8_t sample;
+
/*
* Set the base accelerometer as if it were sitting flat on a desk
* and set the lid to closed.
@@ -74,24 +78,30 @@ static int test_lid_angle(void)
mock_x_acc[ACCEL_LID] = 0;
mock_y_acc[ACCEL_LID] = 0;
mock_z_acc[ACCEL_LID] = 1000;
+ sample = *lpc_status & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK;
task_wake(TASK_ID_MOTIONSENSE);
- msleep(5);
+ while ((*lpc_status & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK) == sample)
+ msleep(5);
TEST_ASSERT(motion_get_lid_angle() == 0);
/* Set lid open to 90 degrees. */
mock_x_acc[ACCEL_LID] = -1000;
mock_y_acc[ACCEL_LID] = 0;
mock_z_acc[ACCEL_LID] = 0;
+ sample = *lpc_status & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK;
task_wake(TASK_ID_MOTIONSENSE);
- msleep(5);
+ while ((*lpc_status & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK) == sample)
+ msleep(5);
TEST_ASSERT(motion_get_lid_angle() == 90);
/* Set lid open to 225. */
mock_x_acc[ACCEL_LID] = 500;
mock_y_acc[ACCEL_LID] = 0;
mock_z_acc[ACCEL_LID] = -500;
+ sample = *lpc_status & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK;
task_wake(TASK_ID_MOTIONSENSE);
- msleep(5);
+ while ((*lpc_status & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK) == sample)
+ msleep(5);
TEST_ASSERT(motion_get_lid_angle() == 225);
/*
@@ -101,8 +111,10 @@ static int test_lid_angle(void)
mock_x_acc[ACCEL_BASE] = 0;
mock_y_acc[ACCEL_BASE] = 1000;
mock_z_acc[ACCEL_BASE] = 0;
+ sample = *lpc_status & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK;
task_wake(TASK_ID_MOTIONSENSE);
- msleep(5);
+ while ((*lpc_status & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK) == sample)
+ msleep(5);
TEST_ASSERT(motion_get_lid_angle() == LID_ANGLE_UNRELIABLE);
/*
@@ -115,8 +127,10 @@ static int test_lid_angle(void)
mock_x_acc[ACCEL_LID] = -500;
mock_y_acc[ACCEL_LID] = -400;
mock_z_acc[ACCEL_LID] = -300;
+ sample = *lpc_status & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK;
task_wake(TASK_ID_MOTIONSENSE);
- msleep(5);
+ while ((*lpc_status & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK) == sample)
+ msleep(5);
TEST_ASSERT(motion_get_lid_angle() == 180);
return EC_SUCCESS;