test: log: Give tests names instead of numbers
[platform/kernel/u-boot.git] / 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 <log.h>
8 #include <serial.h>
9 #include <dm.h>
10 #include <dm/test.h>
11 #include <test/test.h>
12 #include <test/ut.h>
13
14 static int dm_test_serial(struct unit_test_state *uts)
15 {
16         struct serial_device_info info_serial = {0};
17         struct udevice *dev_serial;
18         uint value_serial;
19
20         ut_assertok(uclass_get_device_by_name(UCLASS_SERIAL, "serial",
21                                               &dev_serial));
22
23         ut_assertok(serial_tstc());
24         /*
25          * test with default config which is the only one supported by
26          * sandbox_serial driver
27          */
28         ut_assertok(serial_setconfig(dev_serial, SERIAL_DEFAULT_CONFIG));
29         ut_assertok(serial_getconfig(dev_serial, &value_serial));
30         ut_assert(value_serial == SERIAL_DEFAULT_CONFIG);
31         ut_assertok(serial_getinfo(dev_serial, &info_serial));
32         ut_assert(info_serial.type == SERIAL_CHIP_UNKNOWN);
33         ut_assert(info_serial.addr == SERIAL_DEFAULT_ADDRESS);
34         ut_assert(info_serial.clock == SERIAL_DEFAULT_CLOCK);
35         /*
36          * test with a parameter which is NULL pointer
37          */
38         ut_asserteq(-EINVAL, serial_getconfig(dev_serial, NULL));
39         ut_asserteq(-EINVAL, serial_getinfo(dev_serial, NULL));
40         /*
41          * test with a serial config which is not supported by
42          * sandbox_serial driver: test with wrong parity
43          */
44         ut_asserteq(-ENOTSUPP,
45                     serial_setconfig(dev_serial,
46                                      SERIAL_CONFIG(SERIAL_PAR_ODD,
47                                                    SERIAL_8_BITS,
48                                                    SERIAL_ONE_STOP)));
49         /*
50          * test with a serial config which is not supported by
51          * sandbox_serial driver: test with wrong bits number
52          */
53         ut_asserteq(-ENOTSUPP,
54                     serial_setconfig(dev_serial,
55                                      SERIAL_CONFIG(SERIAL_PAR_NONE,
56                                                    SERIAL_6_BITS,
57                                                    SERIAL_ONE_STOP)));
58
59         /*
60          * test with a serial config which is not supported by
61          * sandbox_serial driver: test with wrong stop bits number
62          */
63         ut_asserteq(-ENOTSUPP,
64                     serial_setconfig(dev_serial,
65                                      SERIAL_CONFIG(SERIAL_PAR_NONE,
66                                                    SERIAL_8_BITS,
67                                                    SERIAL_TWO_STOP)));
68
69         return 0;
70 }
71
72 DM_TEST(dm_test_serial, UT_TESTF_SCAN_FDT);