From 9f8fabbe07a70dff2b0f424b539fd94e40e29d00 Mon Sep 17 00:00:00 2001 From: Alec Berg Date: Mon, 7 Jul 2014 12:00:31 -0700 Subject: [PATCH] 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 Reviewed-on: https://chromium-review.googlesource.com/206878 Reviewed-by: Vincent Palatin --- test/motion_sense.c | 24 +++++++++++++++++++----- 1 file 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 #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;