summaryrefslogtreecommitdiff
path: root/test/usb_ppc.c
blob: d08ae47946337b63c5c191ac5ea12049eeb66b92 (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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/* Copyright 2019 The ChromiumOS Authors
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 *
 * Test USB PD module.
 */
#include "common.h"
#include "console.h"
#include "crc.h"
#include "task.h"
#include "test_util.h"
#include "timer.h"
#include "usbc_ppc.h"
#include "util.h"

const struct ppc_drv null_drv = {
	.init = NULL,
	.is_sourcing_vbus = NULL,
	.vbus_sink_enable = NULL,
	.vbus_source_enable = NULL,
	.set_polarity = NULL,
	.set_vbus_source_current_limit = NULL,
	.discharge_vbus = NULL,
	.set_sbu = NULL,
	.set_vconn = NULL,
	.is_vbus_present = NULL,
	.enter_low_power_mode = NULL,
};

struct ppc_config_t ppc_chips[] = {
	[0] = { .drv = &null_drv },
};
unsigned int ppc_cnt = ARRAY_SIZE(ppc_chips);

const struct tcpc_config_t tcpc_config[] = {
	[0] = {},
};

static int test_ppc_init(void)
{
	int rv;

	rv = ppc_init(1);
	TEST_ASSERT(rv == EC_ERROR_INVAL);
	rv = ppc_init(0);
	TEST_ASSERT(rv == EC_ERROR_UNIMPLEMENTED);

	return EC_SUCCESS;
}

static int test_ppc_is_sourcing_vbus(void)
{
	int rv;

	rv = ppc_is_sourcing_vbus(1);
	TEST_ASSERT(rv == 0);
	rv = ppc_is_sourcing_vbus(0);
	TEST_ASSERT(rv == 0);

	return EC_SUCCESS;
}

static int test_ppc_set_polarity(void)
{
	int rv;

	rv = ppc_set_polarity(1, 0);
	TEST_ASSERT(rv == EC_ERROR_INVAL);
	rv = ppc_set_polarity(0, 0);
	TEST_ASSERT(rv == EC_ERROR_UNIMPLEMENTED);

	return EC_SUCCESS;
}

static int test_ppc_set_vbus_source_current_limit(void)
{
	int rv;

	rv = ppc_set_vbus_source_current_limit(1, 0);
	TEST_ASSERT(rv == EC_ERROR_INVAL);
	rv = ppc_set_vbus_source_current_limit(0, 0);
	TEST_ASSERT(rv == EC_ERROR_UNIMPLEMENTED);

	return EC_SUCCESS;
}

static int test_ppc_set_sbu(void)
{
	int rv;

	rv = ppc_set_sbu(1, 0);
	TEST_ASSERT(rv == EC_ERROR_INVAL);
	rv = ppc_set_sbu(0, 0);
	TEST_ASSERT(rv == EC_ERROR_UNIMPLEMENTED);

	return EC_SUCCESS;
}

static int test_ppc_set_vconn(void)
{
	int rv;

	rv = ppc_set_vconn(1, 0);
	TEST_ASSERT(rv == EC_ERROR_INVAL);
	rv = ppc_set_vconn(0, 0);
	TEST_ASSERT(rv == EC_ERROR_UNIMPLEMENTED);

	return EC_SUCCESS;
}

static int test_ppc_discharge_vbus(void)
{
	int rv;

	rv = ppc_discharge_vbus(1, 0);
	TEST_ASSERT(rv == EC_ERROR_INVAL);
	rv = ppc_discharge_vbus(0, 0);
	TEST_ASSERT(rv == EC_ERROR_UNIMPLEMENTED);

	return EC_SUCCESS;
}

static int test_ppc_vbus_sink_enable(void)
{
	int rv;

	rv = ppc_vbus_sink_enable(1, 0);
	TEST_ASSERT(rv == EC_ERROR_INVAL);
	rv = ppc_vbus_sink_enable(0, 0);
	TEST_ASSERT(rv == EC_ERROR_UNIMPLEMENTED);

	return EC_SUCCESS;
}

static int test_ppc_enter_low_power_mode(void)
{
	int rv;

	rv = ppc_enter_low_power_mode(1);
	TEST_ASSERT(rv == EC_ERROR_INVAL);
	rv = ppc_enter_low_power_mode(0);
	TEST_ASSERT(rv == EC_ERROR_UNIMPLEMENTED);

	return EC_SUCCESS;
}

static int test_ppc_vbus_source_enable(void)
{
	int rv;

	rv = ppc_vbus_source_enable(1, 0);
	TEST_ASSERT(rv == EC_ERROR_INVAL);
	rv = ppc_vbus_source_enable(0, 0);
	TEST_ASSERT(rv == EC_ERROR_UNIMPLEMENTED);

	return EC_SUCCESS;
}

static int test_ppc_is_vbus_present(void)
{
	int rv;

	rv = ppc_is_vbus_present(1);
	TEST_ASSERT(rv == 0);
	rv = ppc_is_vbus_present(0);
	TEST_ASSERT(rv == 0);

	return EC_SUCCESS;
}

void run_test(int argc, const char **argv)
{
	test_reset();

	RUN_TEST(test_ppc_init);
	RUN_TEST(test_ppc_is_sourcing_vbus);
	RUN_TEST(test_ppc_set_polarity);
	RUN_TEST(test_ppc_set_vbus_source_current_limit);
	RUN_TEST(test_ppc_set_sbu);
	RUN_TEST(test_ppc_set_vconn);
	RUN_TEST(test_ppc_discharge_vbus);
	RUN_TEST(test_ppc_vbus_sink_enable);
	RUN_TEST(test_ppc_enter_low_power_mode);
	RUN_TEST(test_ppc_vbus_source_enable);
	RUN_TEST(test_ppc_is_vbus_present);

	test_print_result();
}