diff options
author | Aseda Aboagye <aaboagye@google.com> | 2017-01-20 11:26:26 -0800 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2017-01-20 21:07:47 +0000 |
commit | 742e93b17ecced926cd0b0c6a32e4b296fbe605b (patch) | |
tree | 19e35d11b15809e95e2902e0b4d400d06fc08e93 | |
parent | bdfce24666671e5dfe24b8561aa7b5c1f191b1b8 (diff) | |
download | chrome-ec-742e93b17ecced926cd0b0c6a32e4b296fbe605b.tar.gz |
test: Fix motion_lid unit test.
My recent motion lid reliability changes failed to account for the
motion lid unit test. This commit fixes the test and adds a few cases.
BUG=None
BRANCH=glados
TEST=make -j runtests
Change-Id: If7dd914c46ef3a4be029773d7541848ebcfdcf6c
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Reviewed-on: https://chromium-review.googlesource.com/430960
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Alexandru Stan <amstan@chromium.org>
Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
-rw-r--r-- | test/motion_lid.c | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/test/motion_lid.c b/test/motion_lid.c index f610250e9c..dfea3ecf91 100644 --- a/test/motion_lid.c +++ b/test/motion_lid.c @@ -10,6 +10,7 @@ #include "accelgyro.h" #include "common.h" +#include "gpio.h" #include "hooks.h" #include "host_command.h" #include "motion_lid.h" @@ -206,6 +207,7 @@ static int test_lid_angle(void) lid->xyz[X] = 0; lid->xyz[Y] = 0; lid->xyz[Z] = -1000; + gpio_set_level(GPIO_LID_OPEN, 0); /* Initial wake up, like init does */ task_wake(TASK_ID_MOTIONSENSE); @@ -220,7 +222,10 @@ static int test_lid_angle(void) lid->xyz[X] = 0; lid->xyz[Y] = 1000; lid->xyz[Z] = 0; + gpio_set_level(GPIO_LID_OPEN, 1); + msleep(100); wait_for_valid_sample(); + TEST_ASSERT(motion_lid_get_angle() == 90); /* Set lid open to 225. */ @@ -237,12 +242,15 @@ static int test_lid_angle(void) wait_for_valid_sample(); TEST_ASSERT(motion_lid_get_angle() == 350); - /* Set lid open to 10, check rotation did not change. */ + /* + * Set lid open to 10. Since the lid switch still indicates that it's + * open, we should be getting an unreliable reading. + */ lid->xyz[X] = 0; lid->xyz[Y] = 173; lid->xyz[Z] = -984; wait_for_valid_sample(); - TEST_ASSERT(motion_lid_get_angle() == 350); + TEST_ASSERT(motion_lid_get_angle() == LID_ANGLE_UNRELIABLE); /* Rotate back to 180 and then 10 */ lid->xyz[X] = 0; @@ -251,11 +259,15 @@ static int test_lid_angle(void) wait_for_valid_sample(); TEST_ASSERT(motion_lid_get_angle() == 180); + /* + * Again, since the lid isn't closed, the angle should be unreliable. + * See SMALL_LID_ANGLE_RANGE. + */ lid->xyz[X] = 0; lid->xyz[Y] = 173; lid->xyz[Z] = -984; wait_for_valid_sample(); - TEST_ASSERT(motion_lid_get_angle() == 10); + TEST_ASSERT(motion_lid_get_angle() == LID_ANGLE_UNRELIABLE); /* * Align base with hinge and make sure it returns unreliable for angle. @@ -280,6 +292,30 @@ static int test_lid_angle(void) wait_for_valid_sample(); TEST_ASSERT(motion_lid_get_angle() == 180); + /* + * Close the lid and set the angle to 0. + */ + base->xyz[X] = 0; + base->xyz[Y] = 0; + base->xyz[Z] = 1000; + lid->xyz[X] = 0; + lid->xyz[Y] = 0; + lid->xyz[Z] = -1000; + gpio_set_level(GPIO_LID_OPEN, 0); + msleep(100); + wait_for_valid_sample(); + TEST_ASSERT(motion_lid_get_angle() == 0); + + /* + * Make the angle large, but since the lid is closed, the angle should + * be regarded as unreliable. + */ + lid->xyz[X] = 0; + lid->xyz[Y] = -173; + lid->xyz[Z] = -984; + wait_for_valid_sample(); + TEST_ASSERT(motion_lid_get_angle() == LID_ANGLE_UNRELIABLE); + return EC_SUCCESS; } |