blob: 0da7548fd24bd93ad7d0d848b0931bdc57bfa87f [file] [log] [blame]
Simon Glass9b306e52021-01-16 14:52:22 -07001// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright 2021 Google LLC
4 */
5
6#include <common.h>
7#include <cros_ec.h>
8#include <dm.h>
9#include <asm/test.h>
10#include <dm/test.h>
11#include <test/ut.h>
12
13static int dm_test_cros_ec_hello(struct unit_test_state *uts)
14{
15 struct udevice *dev;
16 uint val;
17
18 ut_assertok(uclass_first_device_err(UCLASS_CROS_EC, &dev));
19
20 ut_assertok(cros_ec_hello(dev, NULL));
21
22 val = 0xdead1357;
23 ut_assertok(cros_ec_hello(dev, &val));
24 ut_asserteq(0xdead1357, val);
25
26 sandbox_cros_ec_set_test_flags(dev, CROSECT_BREAK_HELLO);
27 ut_asserteq(-ENOTSYNC, cros_ec_hello(dev, &val));
28 ut_asserteq(0x12345678, val);
29
30 return 0;
31}
32DM_TEST(dm_test_cros_ec_hello, UT_TESTF_SCAN_FDT);
Simon Glass33909b52021-01-16 14:52:25 -070033
34static int dm_test_cros_ec_sku_id(struct unit_test_state *uts)
35{
36 struct udevice *dev;
37
38 ut_assertok(uclass_first_device_err(UCLASS_CROS_EC, &dev));
39 ut_asserteq(1234, cros_ec_get_sku_id(dev));
40
41 /* try the command */
42 console_record_reset();
43 ut_assertok(run_command("crosec sku", 0));
44 ut_assert_nextline("1234");
45 ut_assert_console_end();
46
47 return 0;
48}
49DM_TEST(dm_test_cros_ec_sku_id, UT_TESTF_SCAN_FDT);
Simon Glass959e1ce2021-01-16 14:52:26 -070050
51static int dm_test_cros_ec_features(struct unit_test_state *uts)
52{
53 struct udevice *dev;
54 u64 feat;
55
56 ut_assertok(uclass_first_device_err(UCLASS_CROS_EC, &dev));
57 ut_assertok(cros_ec_get_features(dev, &feat));
58 ut_asserteq_64(1U << EC_FEATURE_FLASH | 1U << EC_FEATURE_I2C |
59 1ULL << EC_FEATURE_UNIFIED_WAKE_MASKS | 1ULL << EC_FEATURE_ISH,
60 feat);
61
62 ut_asserteq(true, cros_ec_check_feature(dev, EC_FEATURE_I2C));
63 ut_asserteq(false, cros_ec_check_feature(dev, EC_FEATURE_MOTION_SENSE));
64 ut_asserteq(true, cros_ec_check_feature(dev, EC_FEATURE_ISH));
65
66 /* try the command */
67 console_record_reset();
68 ut_assertok(run_command("crosec features", 0));
69 ut_assert_nextline("flash");
70 ut_assert_nextline("i2c");
71 ut_assert_nextline("unified_wake_masks");
72 ut_assert_nextline("ish");
73 ut_assert_console_end();
74
75 return 0;
76}
77DM_TEST(dm_test_cros_ec_features, UT_TESTF_SCAN_FDT);
Simon Glass9d702522021-01-16 14:52:28 -070078
79static int dm_test_cros_ec_switches(struct unit_test_state *uts)
80{
81 struct udevice *dev;
82
83 ut_assertok(uclass_first_device_err(UCLASS_CROS_EC, &dev));
84 ut_asserteq(0, cros_ec_get_switches(dev));
85
86 /* try the command */
87 console_record_reset();
88 ut_assertok(run_command("crosec switches", 0));
89 ut_assert_console_end();
90
91 /* Open the lid and check the switch changes */
92 sandbox_cros_ec_set_test_flags(dev, CROSECT_LID_OPEN);
93 ut_asserteq(EC_SWITCH_LID_OPEN, cros_ec_get_switches(dev));
94
95 /* try the command */
96 console_record_reset();
97 ut_assertok(run_command("crosec switches", 0));
98 ut_assert_nextline("lid open");
99 ut_assert_console_end();
100
101 return 0;
102}
103DM_TEST(dm_test_cros_ec_switches, UT_TESTF_SCAN_FDT);
Simon Glass03161302021-01-16 14:52:29 -0700104
105static int dm_test_cros_ec_events(struct unit_test_state *uts)
106{
107 struct udevice *dev;
108 u32 events;
109
110 ut_assertok(uclass_first_device_err(UCLASS_CROS_EC, &dev));
111 ut_assertok(cros_ec_get_host_events(dev, &events));
112 ut_asserteq(0, events);
113
114 /* try the command */
115 console_record_reset();
116 ut_assertok(run_command("crosec events", 0));
117 ut_assert_nextline("00000000");
118 ut_assert_console_end();
119
120 /* Open the lid and check the event appears */
121 sandbox_cros_ec_set_test_flags(dev, CROSECT_LID_OPEN);
122 ut_assertok(cros_ec_get_host_events(dev, &events));
123 ut_asserteq(EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN), events);
124
125 /* try the command */
126 console_record_reset();
127 ut_assertok(run_command("crosec events", 0));
128 ut_assert_nextline("00000002");
129 ut_assert_nextline("lid_open");
130 ut_assert_console_end();
131
132 /* Clear the event */
133 ut_assertok(cros_ec_clear_host_events(dev,
134 EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN)));
135 ut_assertok(cros_ec_get_host_events(dev, &events));
136 ut_asserteq(0, events);
137
138 return 0;
139}
140DM_TEST(dm_test_cros_ec_events, UT_TESTF_SCAN_FDT);