summaryrefslogtreecommitdiff
path: root/zephyr/test/drivers/host_cmd/src/keyboard_mkbp.c
blob: 4c74a48ab46c7ef92a762803427d587bd391a466 (plain)
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
/* 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 <zephyr/ztest.h>
#include "include/keyboard_mkbp.h"
#include "test/drivers/test_state.h"
#include "test/drivers/utils.h"

struct keyboard_mkbp_commands_fixture {
	struct ec_mkbp_config config;
};

static void *keyboard_mkbp_setup(void)
{
	static struct keyboard_mkbp_commands_fixture fixture = { 0 };

	return &fixture;
}

static void keyboard_mkbp_before(void *fixture)
{
	struct keyboard_mkbp_commands_fixture *f = fixture;

	get_keyscan_config(&f->config);
}

static void keyboard_mkbp_after(void *fixture)
{
	struct keyboard_mkbp_commands_fixture *f = fixture;
	struct ec_params_mkbp_set_config req = { 0 };
	struct host_cmd_handler_args args =
		BUILD_HOST_COMMAND_PARAMS(EC_CMD_MKBP_SET_CONFIG, 0, req);

	req.config = f->config;
	host_command_process(&args);
}

ZTEST_SUITE(keyboard_mkbp_commands, drivers_predicate_post_main,
	    keyboard_mkbp_setup, keyboard_mkbp_before, keyboard_mkbp_after,
	    NULL);

/**
 * @brief TestPurpose: Verify EC_CMD_MKBP_GET_CONFIG host command.
 */
ZTEST_USER(keyboard_mkbp_commands, test_mkbp_get_config_cmd)
{
	enum ec_status ret_val;
	struct ec_response_mkbp_get_config resp;

	struct host_cmd_handler_args args =
		BUILD_HOST_COMMAND_RESPONSE(EC_CMD_MKBP_GET_CONFIG, 0, resp);

	ret_val = host_command_process(&args);

	zassert_ok(ret_val, "Expected=%d, returned=%d", EC_SUCCESS, ret_val);
}

/**
 * @brief TestPurpose: Verify EC_CMD_MKBP_SET_CONFIG host command.
 */
ZTEST_USER(keyboard_mkbp_commands, test_mkbp_set_config_cmd)
{
	enum ec_status ret_val;
	struct ec_params_mkbp_set_config req = { 0 };
	struct host_cmd_handler_args args =
		BUILD_HOST_COMMAND_PARAMS(EC_CMD_MKBP_SET_CONFIG, 0, req);

	get_keyscan_config(&req.config);

	req.config.valid_mask =
		EC_MKBP_VALID_SCAN_PERIOD | EC_MKBP_VALID_POLL_TIMEOUT |
		EC_MKBP_VALID_MIN_POST_SCAN_DELAY |
		EC_MKBP_VALID_OUTPUT_SETTLE | EC_MKBP_VALID_DEBOUNCE_DOWN |
		EC_MKBP_VALID_DEBOUNCE_UP | EC_MKBP_VALID_FIFO_MAX_DEPTH;

	ret_val = host_command_process(&args);

	zassert_ok(ret_val, "Expected=%d, returned=%d", EC_SUCCESS, ret_val);
}