blob: 0662b5f09b8b9445cd29a9152d8b7981e5078cd7 [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>
Simon Glassf7ae49f2020-05-10 11:40:05 -06007#include <log.h>
Patrice Chotardd7c09682018-08-03 15:07:41 +02008#include <serial.h>
9#include <dm.h>
10#include <dm/test.h>
Simon Glass0e1fad42020-07-19 10:15:37 -060011#include <test/test.h>
Patrice Chotardd7c09682018-08-03 15:07:41 +020012#include <test/ut.h>
13
14static int dm_test_serial(struct unit_test_state *uts)
15{
Andy Shevchenkod5bb4f82018-11-20 23:52:33 +020016 struct serial_device_info info_serial = {0};
Patrice Chotardd7c09682018-08-03 15:07:41 +020017 struct udevice *dev_serial;
Andy Shevchenkoac7f5db2018-11-20 23:52:32 +020018 uint value_serial;
Patrice Chotardd7c09682018-08-03 15:07:41 +020019
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 */
Simon Glass3de04e72018-12-28 14:23:09 -070028 ut_assertok(serial_setconfig(dev_serial, SERIAL_DEFAULT_CONFIG));
Simon Glass67d1b052018-12-28 14:23:08 -070029 ut_assertok(serial_getconfig(dev_serial, &value_serial));
Andy Shevchenkoac7f5db2018-11-20 23:52:32 +020030 ut_assert(value_serial == SERIAL_DEFAULT_CONFIG);
Simon Glassa61cbad2018-12-28 14:23:10 -070031 ut_assertok(serial_getinfo(dev_serial, &info_serial));
Andy Shevchenkod5bb4f82018-11-20 23:52:33 +020032 ut_assert(info_serial.type == SERIAL_CHIP_UNKNOWN);
33 ut_assert(info_serial.addr == SERIAL_DEFAULT_ADDRESS);
Andy Shevchenkobf4661bc2020-02-27 17:21:54 +020034 ut_assert(info_serial.clock == SERIAL_DEFAULT_CLOCK);
Andy Shevchenkoac7f5db2018-11-20 23:52:32 +020035 /*
36 * test with a parameter which is NULL pointer
37 */
Simon Glass67d1b052018-12-28 14:23:08 -070038 ut_asserteq(-EINVAL, serial_getconfig(dev_serial, NULL));
Simon Glassa61cbad2018-12-28 14:23:10 -070039 ut_asserteq(-EINVAL, serial_getinfo(dev_serial, NULL));
Patrice Chotardd7c09682018-08-03 15:07:41 +020040 /*
41 * test with a serial config which is not supported by
42 * sandbox_serial driver: test with wrong parity
43 */
44 ut_asserteq(-ENOTSUPP,
Simon Glass3de04e72018-12-28 14:23:09 -070045 serial_setconfig(dev_serial,
46 SERIAL_CONFIG(SERIAL_PAR_ODD,
Patrice Chotardd7c09682018-08-03 15:07:41 +020047 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,
Simon Glass3de04e72018-12-28 14:23:09 -070054 serial_setconfig(dev_serial,
55 SERIAL_CONFIG(SERIAL_PAR_NONE,
Patrice Chotardd7c09682018-08-03 15:07:41 +020056 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,
Simon Glass3de04e72018-12-28 14:23:09 -070064 serial_setconfig(dev_serial,
65 SERIAL_CONFIG(SERIAL_PAR_NONE,
Patrice Chotardd7c09682018-08-03 15:07:41 +020066 SERIAL_8_BITS,
67 SERIAL_TWO_STOP)));
68
69 return 0;
70}
71
Simon Glasse180c2b2020-07-28 19:41:12 -060072DM_TEST(dm_test_serial, UT_TESTF_SCAN_FDT);