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
106
107
108
109
110
111
|
/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "emul/emul_common_i2c.h"
#include "emul/emul_smart_battery.h"
#include "hooks.h"
#include "host_command.h"
#include "tablet_mode.h"
#include "test/drivers/test_state.h"
#include "test/drivers/utils.h"
#include <zephyr/drivers/emul.h>
#include <zephyr/ztest.h>
struct host_cmd_tablet_mode_fixture {
const struct emul *emul;
struct i2c_common_emul_data *i2c_emul;
};
static void host_cmd_tablet_mode_before(void *f)
{
ARG_UNUSED(f);
tablet_reset();
}
static void host_cmd_tablet_mode_after(void *f)
{
ARG_UNUSED(f);
tablet_reset();
}
ZTEST_SUITE(host_cmd_tablet_mode, drivers_predicate_post_main, NULL,
host_cmd_tablet_mode_before, host_cmd_tablet_mode_after, NULL);
/* Test tablet mode can be enabled with a host command. */
ZTEST_USER_F(host_cmd_tablet_mode, test_tablet_mode_on)
{
int rv;
struct ec_params_set_tablet_mode params = {
.tablet_mode = TABLET_MODE_FORCE_TABLET
};
struct host_cmd_handler_args args = BUILD_HOST_COMMAND_PARAMS(
EC_CMD_SET_TABLET_MODE, UINT8_C(0), params);
rv = host_command_process(&args);
zassert_equal(EC_RES_SUCCESS, rv, "Expected EC_RES_SUCCESS, but got %d",
rv);
/* Return 1 if in tablet mode, 0 otherwise */
rv = tablet_get_mode();
zassert_equal(rv, 1, "unexpected tablet mode: %d", rv);
}
/* Test tablet mode can be disabled with a host command. */
ZTEST_USER_F(host_cmd_tablet_mode, test_tablet_mode_off)
{
int rv;
struct ec_params_set_tablet_mode params = {
.tablet_mode = TABLET_MODE_FORCE_CLAMSHELL
};
struct host_cmd_handler_args args = BUILD_HOST_COMMAND_PARAMS(
EC_CMD_SET_TABLET_MODE, UINT8_C(0), params);
rv = host_command_process(&args);
zassert_equal(EC_RES_SUCCESS, rv, "Expected EC_RES_SUCCESS, but got %d",
rv);
/* Return 1 if in tablet mode, 0 otherwise */
rv = tablet_get_mode();
zassert_equal(rv, 0, "unexpected tablet mode: %d", rv);
}
/* Test tablet mode can be reset with a host command. */
ZTEST_USER_F(host_cmd_tablet_mode, test_tablet_mode_reset)
{
int rv;
struct ec_params_set_tablet_mode params = {
.tablet_mode = TABLET_MODE_DEFAULT
};
struct host_cmd_handler_args args = BUILD_HOST_COMMAND_PARAMS(
EC_CMD_SET_TABLET_MODE, UINT8_C(0), params);
rv = host_command_process(&args);
zassert_equal(EC_RES_SUCCESS, rv, "Expected EC_RES_SUCCESS, but got %d",
rv);
/* Return 1 if in tablet mode, 0 otherwise */
rv = tablet_get_mode();
zassert_equal(rv, 0, "unexpected tablet mode: %d", rv);
}
/* Test tablet mode can handle invalid host command parameters. */
ZTEST_USER_F(host_cmd_tablet_mode, test_tablet_mode_invalid_parameter)
{
int rv;
struct ec_params_set_tablet_mode params = {
.tablet_mode = 0xEE /* Sufficiently random, bad value.*/
};
struct host_cmd_handler_args args = BUILD_HOST_COMMAND_PARAMS(
EC_CMD_SET_TABLET_MODE, UINT8_C(0), params);
rv = host_command_process(&args);
zassert_equal(EC_RES_INVALID_PARAM, rv,
"Expected EC_RES_INVALID_PARAM, but got %d", rv);
/* Return 1 if in tablet mode, 0 otherwise */
rv = tablet_get_mode();
zassert_equal(rv, 0, "unexpected tablet mode: %d", rv);
}
|