1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
/* Copyright 2023 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
* Test clamshell/tablet when Only the GMR sensor is driving the tablet mode:
* In that mode, tablet mode is entered only when the lid angle is 360 degree.
*/
#include "common.h"
#include "console.h"
#include "gpio.h"
#include "hooks.h"
#include "host_command.h"
#include "tablet_mode.h"
#include "test_util.h"
#include "timer.h"
#include "util.h"
static int tablet_hook_count;
static void tablet_mode_change_hook(void)
{
tablet_hook_count++;
}
DECLARE_HOOK(HOOK_TABLET_MODE_CHANGE, tablet_mode_change_hook,
HOOK_PRIO_DEFAULT);
void before_test(void)
{
/* Make sure the device lid is in a consistent state (close). */
gpio_set_level(GPIO_TABLET_MODE_L, 1);
msleep(50);
gpio_set_level(GPIO_LID_OPEN, 0);
msleep(50);
tablet_hook_count = 1;
}
/*
* The device is in clamshell mode from before_test,
* Go through GPIO transitions and observe the table mode state.
*/
test_static int test_start_lid_close(void)
{
TEST_ASSERT(!tablet_get_mode());
/* Opening, No change. */
gpio_set_level(GPIO_LID_OPEN, 1);
msleep(50);
TEST_ASSERT(tablet_hook_count == 1);
TEST_ASSERT(!tablet_get_mode());
/* full 360, tablet mode. */
gpio_set_level(GPIO_TABLET_MODE_L, 0);
msleep(50);
TEST_ASSERT(tablet_hook_count == 2);
TEST_ASSERT(tablet_get_mode());
/* Get out of full 360 mode, Immediately back to clamshell mode. */
gpio_set_level(GPIO_TABLET_MODE_L, 1);
msleep(50);
TEST_ASSERT(tablet_hook_count == 3);
TEST_ASSERT(!tablet_get_mode());
/* Back to close, no change. */
gpio_set_level(GPIO_LID_OPEN, 0);
msleep(50);
TEST_ASSERT(tablet_hook_count == 3);
TEST_ASSERT(!tablet_get_mode());
return EC_SUCCESS;
}
/*
* Put the device in tablet mode first.
* Reset the EC, keep the existing GPIO level.
* Verify the state is not forgotten when the EC starts in tablet mode after
* reset.
*/
test_static int test_start_tablet_mode(void)
{
/* Go in tablet mode */
gpio_set_level(GPIO_LID_OPEN, 1);
gpio_set_level(GPIO_TABLET_MODE_L, 0);
msleep(50);
TEST_ASSERT(tablet_hook_count == 2);
/* Shutdown device */
hook_notify(HOOK_CHIPSET_SHUTDOWN);
/* Check we start in tablet mode */
msleep(50);
TEST_ASSERT(tablet_get_mode());
return EC_SUCCESS;
}
void run_test(int argc, const char **argv)
{
test_reset();
RUN_TEST(test_start_lid_close);
RUN_TEST(test_start_tablet_mode);
test_print_result();
}
|