summaryrefslogtreecommitdiff
path: root/zephyr/test/drivers/host_cmd/src/get_pd_port_caps.c
blob: 907329f8a1f3689072aaa45c87a6afa7b54e55dc (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
/* 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/shell/shell.h>
#include <zephyr/ztest.h>

#include "console.h"
#include "ec_commands.h"
#include "test/drivers/test_state.h"
#include "test/drivers/utils.h"

ZTEST_USER(host_cmd_get_pd_port_caps, test_good_index)
{
	struct ec_params_get_pd_port_caps params = { .port = 0 };
	struct ec_response_get_pd_port_caps response;
	struct host_cmd_handler_args args = BUILD_HOST_COMMAND(
		EC_CMD_GET_PD_PORT_CAPS, 0, response, params);

	zassert_ok(host_command_process(&args),
		   "Failed to process get_pd_port_caps for port %d",
		   params.port);

	/* Verify standard Chromebook responses for these fields */
	zassert_equal(response.pd_power_role_cap, EC_PD_POWER_ROLE_DUAL,
		      "Bad dual role");
	zassert_equal(response.pd_try_power_role_cap,
		      EC_PD_TRY_POWER_ROLE_SOURCE, "Bad try role");
	zassert_equal(response.pd_data_role_cap, EC_PD_DATA_ROLE_DUAL,
		      "Bad data role");
	zassert_equal(response.pd_port_location, EC_PD_PORT_LOCATION_UNKNOWN,
		      "Unexpected port location");
}

ZTEST_USER(host_cmd_get_pd_port_caps, test_bad_index)
{
	struct ec_params_get_pd_port_caps params = { .port = 32 };
	struct ec_response_get_pd_port_caps response;
	struct host_cmd_handler_args args = BUILD_HOST_COMMAND(
		EC_CMD_GET_PD_PORT_CAPS, 0, response, params);

	zassert_equal(host_command_process(&args), EC_RES_INVALID_PARAM,
		      "Failed to fail get_pd_port_caps for port %d",
		      params.port);
}

static void host_cmd_get_pd_port_caps_begin(void *data)
{
	ARG_UNUSED(data);

	/* Assume we have at least one USB-C port */
	zassume_true(board_get_usb_pd_port_count() > 0,
		     "Insufficient TCPCs found");
}

ZTEST_SUITE(host_cmd_get_pd_port_caps, drivers_predicate_post_main, NULL,
	    host_cmd_get_pd_port_caps_begin, NULL, NULL);