]> Git Repo - u-boot.git/blob - test/dm/serial.c
Merge branch 'master' of https://source.denx.de/u-boot/custodians/u-boot-sh
[u-boot.git] / test / dm / serial.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2018, STMicroelectronics
4  */
5
6 #include <log.h>
7 #include <serial.h>
8 #include <dm.h>
9 #include <asm/serial.h>
10 #include <dm/test.h>
11 #include <test/test.h>
12 #include <test/ut.h>
13
14 static const char test_message[] =
15         "This is a test message\n"
16         "consisting of multiple lines\n";
17
18 static int dm_test_serial(struct unit_test_state *uts)
19 {
20         int i;
21         struct serial_device_info info_serial = {0};
22         struct udevice *dev_serial;
23         size_t start, putc_written;
24
25         uint value_serial;
26
27         ut_assertok(uclass_get_device_by_name(UCLASS_SERIAL, "serial",
28                                               &dev_serial));
29
30         ut_assertok(serial_tstc());
31         ut_asserteq(115200, fetch_baud_from_dtb());
32         /*
33          * test with default config which is the only one supported by
34          * sandbox_serial driver
35          */
36         ut_assertok(serial_setconfig(dev_serial, SERIAL_DEFAULT_CONFIG));
37         ut_assertok(serial_getconfig(dev_serial, &value_serial));
38         ut_assert(value_serial == SERIAL_DEFAULT_CONFIG);
39         ut_assertok(serial_getinfo(dev_serial, &info_serial));
40         ut_assert(info_serial.type == SERIAL_CHIP_UNKNOWN);
41         ut_assert(info_serial.addr == SERIAL_DEFAULT_ADDRESS);
42         ut_assert(info_serial.clock == SERIAL_DEFAULT_CLOCK);
43         /*
44          * test with a parameter which is NULL pointer
45          */
46         ut_asserteq(-EINVAL, serial_getconfig(dev_serial, NULL));
47         ut_asserteq(-EINVAL, serial_getinfo(dev_serial, NULL));
48         /*
49          * test with a serial config which is not supported by
50          * sandbox_serial driver: test with wrong parity
51          */
52         ut_asserteq(-ENOTSUPP,
53                     serial_setconfig(dev_serial,
54                                      SERIAL_CONFIG(SERIAL_PAR_ODD,
55                                                    SERIAL_8_BITS,
56                                                    SERIAL_ONE_STOP)));
57         /*
58          * test with a serial config which is not supported by
59          * sandbox_serial driver: test with wrong bits number
60          */
61         ut_asserteq(-ENOTSUPP,
62                     serial_setconfig(dev_serial,
63                                      SERIAL_CONFIG(SERIAL_PAR_NONE,
64                                                    SERIAL_6_BITS,
65                                                    SERIAL_ONE_STOP)));
66
67         /*
68          * test with a serial config which is not supported by
69          * sandbox_serial driver: test with wrong stop bits number
70          */
71         ut_asserteq(-ENOTSUPP,
72                     serial_setconfig(dev_serial,
73                                      SERIAL_CONFIG(SERIAL_PAR_NONE,
74                                                    SERIAL_8_BITS,
75                                                    SERIAL_TWO_STOP)));
76
77         /* Verify that putc and puts print the same number of characters */
78         sandbox_serial_endisable(false);
79         start = sandbox_serial_written();
80         for (i = 0; i < sizeof(test_message) - 1; i++)
81                 serial_putc(test_message[i]);
82         putc_written = sandbox_serial_written();
83         serial_puts(test_message);
84         sandbox_serial_endisable(true);
85         ut_asserteq(putc_written - start,
86                     sandbox_serial_written() - putc_written);
87
88         return 0;
89 }
90 DM_TEST(dm_test_serial, UTF_SCAN_FDT);
This page took 0.030163 seconds and 4 git commands to generate.