Commit d7c09684d73c4831a0240ce1fcbe7644bc3ab6e7
Committed by
Tom Rini
1 parent
ad060c052b
Exists in
smarc_8mq_lf_v2020.04
and in
11 other branches
sandbox: Add serial test
Signed-off-by: Patrice Chotard <patrice.chotard@st.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Showing 5 changed files with 75 additions and 0 deletions Side-by-side Diff
drivers/serial/sandbox.c
... | ... | @@ -143,6 +143,19 @@ |
143 | 143 | return result; |
144 | 144 | } |
145 | 145 | |
146 | +static int sandbox_serial_setconfig(struct udevice *dev, uint serial_config) | |
147 | +{ | |
148 | + u8 parity = SERIAL_GET_PARITY(serial_config); | |
149 | + u8 bits = SERIAL_GET_BITS(serial_config); | |
150 | + u8 stop = SERIAL_GET_STOP(serial_config); | |
151 | + | |
152 | + if (bits != SERIAL_8_BITS || stop != SERIAL_ONE_STOP || | |
153 | + parity != SERIAL_PAR_NONE) | |
154 | + return -ENOTSUPP; /* not supported in driver*/ | |
155 | + | |
156 | + return 0; | |
157 | +} | |
158 | + | |
146 | 159 | static const char * const ansi_colour[] = { |
147 | 160 | "black", "red", "green", "yellow", "blue", "megenta", "cyan", |
148 | 161 | "white", |
... | ... | @@ -173,6 +186,7 @@ |
173 | 186 | .putc = sandbox_serial_putc, |
174 | 187 | .pending = sandbox_serial_pending, |
175 | 188 | .getc = sandbox_serial_getc, |
189 | + .setconfig = sandbox_serial_setconfig, | |
176 | 190 | }; |
177 | 191 | |
178 | 192 | static const struct udevice_id sandbox_serial_ids[] = { |
include/common.h
include/serial.h
... | ... | @@ -102,6 +102,11 @@ |
102 | 102 | #define SERIAL_GET_STOP(config) \ |
103 | 103 | ((config & SERIAL_STOP_MASK) >> SERIAL_STOP_SHIFT) |
104 | 104 | |
105 | +#define SERIAL_CONFIG(par, bits, stop) \ | |
106 | + (par << SERIAL_PAR_SHIFT | \ | |
107 | + bits << SERIAL_BITS_SHIFT | \ | |
108 | + stop << SERIAL_STOP_SHIFT) | |
109 | + | |
105 | 110 | #define SERIAL_DEFAULT_CONFIG SERIAL_PAR_NONE << SERIAL_PAR_SHIFT | \ |
106 | 111 | SERIAL_8_BITS << SERIAL_BITS_SHIFT | \ |
107 | 112 | SERIAL_ONE_STOP << SERIAL_STOP_SHIFT |
test/dm/Makefile
test/dm/serial.c
1 | +// SPDX-License-Identifier: GPL-2.0 | |
2 | +/* | |
3 | + * Copyright (c) 2018, STMicroelectronics | |
4 | + */ | |
5 | + | |
6 | +#include <common.h> | |
7 | +#include <serial.h> | |
8 | +#include <dm.h> | |
9 | +#include <dm/test.h> | |
10 | +#include <test/ut.h> | |
11 | + | |
12 | +static int dm_test_serial(struct unit_test_state *uts) | |
13 | +{ | |
14 | + struct udevice *dev_serial; | |
15 | + | |
16 | + ut_assertok(uclass_get_device_by_name(UCLASS_SERIAL, "serial", | |
17 | + &dev_serial)); | |
18 | + | |
19 | + ut_assertok(serial_tstc()); | |
20 | + /* | |
21 | + * test with default config which is the only one supported by | |
22 | + * sandbox_serial driver | |
23 | + */ | |
24 | + ut_assertok(serial_setconfig(SERIAL_DEFAULT_CONFIG)); | |
25 | + /* | |
26 | + * test with a serial config which is not supported by | |
27 | + * sandbox_serial driver: test with wrong parity | |
28 | + */ | |
29 | + ut_asserteq(-ENOTSUPP, | |
30 | + serial_setconfig(SERIAL_CONFIG(SERIAL_PAR_ODD, | |
31 | + SERIAL_8_BITS, | |
32 | + SERIAL_ONE_STOP))); | |
33 | + /* | |
34 | + * test with a serial config which is not supported by | |
35 | + * sandbox_serial driver: test with wrong bits number | |
36 | + */ | |
37 | + ut_asserteq(-ENOTSUPP, | |
38 | + serial_setconfig(SERIAL_CONFIG(SERIAL_PAR_NONE, | |
39 | + SERIAL_6_BITS, | |
40 | + SERIAL_ONE_STOP))); | |
41 | + | |
42 | + /* | |
43 | + * test with a serial config which is not supported by | |
44 | + * sandbox_serial driver: test with wrong stop bits number | |
45 | + */ | |
46 | + ut_asserteq(-ENOTSUPP, | |
47 | + serial_setconfig(SERIAL_CONFIG(SERIAL_PAR_NONE, | |
48 | + SERIAL_8_BITS, | |
49 | + SERIAL_TWO_STOP))); | |
50 | + | |
51 | + return 0; | |
52 | +} | |
53 | + | |
54 | +DM_TEST(dm_test_serial, DM_TESTF_SCAN_FDT); |