mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-30 10:31:02 +00:00
This tests power button notification and debouncing. BUG=chrome-os-partner:19236 TEST=Pass all tests BRANCH=None Change-Id: Ief8bc24a8725e01734d84e76ab4b6ae0506b811f Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/50524 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
105 lines
2.3 KiB
C
105 lines
2.3 KiB
C
/* Copyright (c) 2013 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.
|
|
*
|
|
* Test lid switch.
|
|
*/
|
|
|
|
#include "common.h"
|
|
#include "console.h"
|
|
#include "hooks.h"
|
|
#include "host_command.h"
|
|
#include "power_button.h"
|
|
#include "test_util.h"
|
|
#include "timer.h"
|
|
#include "util.h"
|
|
|
|
static int mock_power_button = 1;
|
|
static int mock_lid = 1;
|
|
static int pb_hook_count;
|
|
|
|
int gpio_get_level(enum gpio_signal signal)
|
|
{
|
|
if (signal == GPIO_POWER_BUTTON_L)
|
|
return mock_power_button;
|
|
return 0;
|
|
}
|
|
|
|
int lid_is_open(void)
|
|
{
|
|
return mock_lid;
|
|
}
|
|
|
|
static void pb_change_hook(void)
|
|
{
|
|
pb_hook_count++;
|
|
}
|
|
DECLARE_HOOK(HOOK_POWER_BUTTON_CHANGE, pb_change_hook, HOOK_PRIO_DEFAULT);
|
|
|
|
static int test_hook(void)
|
|
{
|
|
/* Release power button for testing */
|
|
mock_power_button = 1;
|
|
power_button_interrupt(GPIO_POWER_BUTTON_L);
|
|
msleep(100);
|
|
pb_hook_count = 0;
|
|
host_clear_events(0xffffffff);
|
|
|
|
mock_power_button = 0;
|
|
power_button_interrupt(GPIO_POWER_BUTTON_L);
|
|
msleep(50);
|
|
TEST_ASSERT(pb_hook_count == 1);
|
|
TEST_ASSERT(power_button_is_pressed());
|
|
TEST_ASSERT(host_get_events() &
|
|
EC_HOST_EVENT_MASK(EC_HOST_EVENT_POWER_BUTTON));
|
|
host_clear_events(0xffffffff);
|
|
|
|
mock_power_button = 1;
|
|
power_button_interrupt(GPIO_POWER_BUTTON_L);
|
|
msleep(50);
|
|
TEST_ASSERT(pb_hook_count == 2);
|
|
TEST_ASSERT(!power_button_is_pressed());
|
|
TEST_ASSERT(!(host_get_events() &
|
|
EC_HOST_EVENT_MASK(EC_HOST_EVENT_POWER_BUTTON)));
|
|
|
|
return EC_SUCCESS;
|
|
}
|
|
|
|
static int test_debounce(void)
|
|
{
|
|
/* Release power button for testing */
|
|
mock_power_button = 1;
|
|
power_button_interrupt(GPIO_POWER_BUTTON_L);
|
|
msleep(100);
|
|
pb_hook_count = 0;
|
|
host_clear_events(0xffffffff);
|
|
|
|
mock_power_button = 0;
|
|
power_button_interrupt(GPIO_POWER_BUTTON_L);
|
|
msleep(20);
|
|
TEST_ASSERT(pb_hook_count == 0);
|
|
TEST_ASSERT(!power_button_is_pressed());
|
|
TEST_ASSERT(!(host_get_events() &
|
|
EC_HOST_EVENT_MASK(EC_HOST_EVENT_POWER_BUTTON)));
|
|
|
|
mock_power_button = 1;
|
|
power_button_interrupt(GPIO_POWER_BUTTON_L);
|
|
msleep(50);
|
|
TEST_ASSERT(pb_hook_count == 0);
|
|
TEST_ASSERT(!power_button_is_pressed());
|
|
TEST_ASSERT(!(host_get_events() &
|
|
EC_HOST_EVENT_MASK(EC_HOST_EVENT_POWER_BUTTON)));
|
|
|
|
return EC_SUCCESS;
|
|
}
|
|
|
|
void run_test(void)
|
|
{
|
|
test_reset();
|
|
|
|
RUN_TEST(test_hook);
|
|
RUN_TEST(test_debounce);
|
|
|
|
test_print_result();
|
|
}
|