blob: 3d741a8c363cd38d37046582bcb66876e9e50602 [file] [log] [blame]
Patrice Chotardd7c09682018-08-03 15:07:41 +02001// 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
12static int dm_test_serial(struct unit_test_state *uts)
13{
Andy Shevchenkod5bb4f82018-11-20 23:52:33 +020014 struct serial_device_info info_serial = {0};
Patrice Chotardd7c09682018-08-03 15:07:41 +020015 struct udevice *dev_serial;
Andy Shevchenkoac7f5db2018-11-20 23:52:32 +020016 uint value_serial;
Patrice Chotardd7c09682018-08-03 15:07:41 +020017
18 ut_assertok(uclass_get_device_by_name(UCLASS_SERIAL, "serial",
19 &dev_serial));
20
21 ut_assertok(serial_tstc());
22 /*
23 * test with default config which is the only one supported by
24 * sandbox_serial driver
25 */
Simon Glass3de04e72018-12-28 14:23:09 -070026 ut_assertok(serial_setconfig(dev_serial, SERIAL_DEFAULT_CONFIG));
Simon Glass67d1b052018-12-28 14:23:08 -070027 ut_assertok(serial_getconfig(dev_serial, &value_serial));
Andy Shevchenkoac7f5db2018-11-20 23:52:32 +020028 ut_assert(value_serial == SERIAL_DEFAULT_CONFIG);
Simon Glassa61cbad2018-12-28 14:23:10 -070029 ut_assertok(serial_getinfo(dev_serial, &info_serial));
Andy Shevchenkod5bb4f82018-11-20 23:52:33 +020030 ut_assert(info_serial.type == SERIAL_CHIP_UNKNOWN);
31 ut_assert(info_serial.addr == SERIAL_DEFAULT_ADDRESS);
Andy Shevchenkoac7f5db2018-11-20 23:52:32 +020032 /*
33 * test with a parameter which is NULL pointer
34 */
Simon Glass67d1b052018-12-28 14:23:08 -070035 ut_asserteq(-EINVAL, serial_getconfig(dev_serial, NULL));
Simon Glassa61cbad2018-12-28 14:23:10 -070036 ut_asserteq(-EINVAL, serial_getinfo(dev_serial, NULL));
Patrice Chotardd7c09682018-08-03 15:07:41 +020037 /*
38 * test with a serial config which is not supported by
39 * sandbox_serial driver: test with wrong parity
40 */
41 ut_asserteq(-ENOTSUPP,
Simon Glass3de04e72018-12-28 14:23:09 -070042 serial_setconfig(dev_serial,
43 SERIAL_CONFIG(SERIAL_PAR_ODD,
Patrice Chotardd7c09682018-08-03 15:07:41 +020044 SERIAL_8_BITS,
45 SERIAL_ONE_STOP)));
46 /*
47 * test with a serial config which is not supported by
48 * sandbox_serial driver: test with wrong bits number
49 */
50 ut_asserteq(-ENOTSUPP,
Simon Glass3de04e72018-12-28 14:23:09 -070051 serial_setconfig(dev_serial,
52 SERIAL_CONFIG(SERIAL_PAR_NONE,
Patrice Chotardd7c09682018-08-03 15:07:41 +020053 SERIAL_6_BITS,
54 SERIAL_ONE_STOP)));
55
56 /*
57 * test with a serial config which is not supported by
58 * sandbox_serial driver: test with wrong stop bits number
59 */
60 ut_asserteq(-ENOTSUPP,
Simon Glass3de04e72018-12-28 14:23:09 -070061 serial_setconfig(dev_serial,
62 SERIAL_CONFIG(SERIAL_PAR_NONE,
Patrice Chotardd7c09682018-08-03 15:07:41 +020063 SERIAL_8_BITS,
64 SERIAL_TWO_STOP)));
65
66 return 0;
67}
68
69DM_TEST(dm_test_serial, DM_TESTF_SCAN_FDT);