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
|
/* 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 "ec_commands.h"
#include "host_command.h"
#include "test/drivers/test_state.h"
#include <zephyr/fff.h>
#include <zephyr/ztest.h>
#ifndef CONFIG_PLATFORM_EC_SWITCH
FAKE_VOID_FUNC(switch_interrupt, int);
#endif
ZTEST(ec_cmd_read_memmap, id)
{
struct ec_params_read_memmap params = {
.offset = EC_MEMMAP_ID,
.size = 2,
};
uint8_t response[2];
int rv;
struct host_cmd_handler_args args =
BUILD_HOST_COMMAND(EC_CMD_READ_MEMMAP, 0, response, params);
rv = host_command_process(&args);
if (IS_ENABLED(CONFIG_HOSTCMD_X86)) {
zassert_equal(rv, EC_RES_INVALID_COMMAND, "Got %d", rv);
return;
}
zassert_ok(rv, "Got %d", rv);
/* Response should be 'E' 'C' */
zassert_equal('E', response[0]);
zassert_equal('C', response[1]);
}
ZTEST(ec_cmd_read_memmap, switches)
{
struct ec_params_read_memmap params = {
.offset = EC_MEMMAP_SWITCHES,
.size = 1,
};
uint8_t response[1];
int rv;
struct host_cmd_handler_args args =
BUILD_HOST_COMMAND(EC_CMD_READ_MEMMAP, 0, response, params);
rv = host_command_process(&args);
if (IS_ENABLED(CONFIG_HOSTCMD_X86)) {
zassert_equal(rv, EC_RES_INVALID_COMMAND, "Got %d", rv);
return;
}
/* This test suite is run with CONFIG_PLATFORM_EC_SWITCH enabled
* and disabled.
*/
if (IS_ENABLED(CONFIG_PLATFORM_EC_SWITCH)) {
zassert_ok(rv, "Got %d", rv);
} else {
zassert_equal(rv, EC_RES_UNAVAILABLE, "Got %d", rv);
}
}
ZTEST(ec_cmd_read_memmap, invalid)
{
struct ec_params_read_memmap params = {
.offset = EC_MEMMAP_ID,
.size = UINT8_MAX,
};
uint8_t response[2];
int rv;
struct host_cmd_handler_args args =
BUILD_HOST_COMMAND(EC_CMD_READ_MEMMAP, 0, response, params);
rv = host_command_process(&args);
if (IS_ENABLED(CONFIG_HOSTCMD_X86)) {
zassert_equal(rv, EC_RES_INVALID_COMMAND, "Got %d", rv);
return;
}
/* Verify offset+size exceeding max fails */
zassert_equal(rv, EC_RES_INVALID_PARAM, "Got %d", rv);
/* Verify params.size > response_max fails */
params.size = 4;
zassert_equal(host_command_process(&args), EC_RES_INVALID_PARAM);
}
ZTEST_SUITE(ec_cmd_read_memmap, drivers_predicate_post_main, NULL, NULL, NULL,
NULL);
|