blob: 19a15d5d95235d21f82cbbae3cf796dba7bcdc91 [file] [log] [blame]
Patrice Chotard70ed0ea2018-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 Shevchenko44f21da2018-11-20 23:52:33 +020014 struct serial_device_info info_serial = {0};
Patrice Chotard70ed0ea2018-08-03 15:07:41 +020015 struct udevice *dev_serial;
Andy Shevchenko08e98792018-11-20 23:52:32 +020016 uint value_serial;
Patrice Chotard70ed0ea2018-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 */
26 ut_assertok(serial_setconfig(SERIAL_DEFAULT_CONFIG));
Andy Shevchenko08e98792018-11-20 23:52:32 +020027 ut_assertok(serial_getconfig(&value_serial));
28 ut_assert(value_serial == SERIAL_DEFAULT_CONFIG);
Andy Shevchenko44f21da2018-11-20 23:52:33 +020029 ut_assertok(serial_getinfo(&info_serial));
30 ut_assert(info_serial.type == SERIAL_CHIP_UNKNOWN);
31 ut_assert(info_serial.addr == SERIAL_DEFAULT_ADDRESS);
Andy Shevchenko08e98792018-11-20 23:52:32 +020032 /*
33 * test with a parameter which is NULL pointer
34 */
35 ut_asserteq(-EINVAL, serial_getconfig(NULL));
Andy Shevchenko44f21da2018-11-20 23:52:33 +020036 ut_asserteq(-EINVAL, serial_getinfo(NULL));
Patrice Chotard70ed0ea2018-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,
42 serial_setconfig(SERIAL_CONFIG(SERIAL_PAR_ODD,
43 SERIAL_8_BITS,
44 SERIAL_ONE_STOP)));
45 /*
46 * test with a serial config which is not supported by
47 * sandbox_serial driver: test with wrong bits number
48 */
49 ut_asserteq(-ENOTSUPP,
50 serial_setconfig(SERIAL_CONFIG(SERIAL_PAR_NONE,
51 SERIAL_6_BITS,
52 SERIAL_ONE_STOP)));
53
54 /*
55 * test with a serial config which is not supported by
56 * sandbox_serial driver: test with wrong stop bits number
57 */
58 ut_asserteq(-ENOTSUPP,
59 serial_setconfig(SERIAL_CONFIG(SERIAL_PAR_NONE,
60 SERIAL_8_BITS,
61 SERIAL_TWO_STOP)));
62
63 return 0;
64}
65
66DM_TEST(dm_test_serial, DM_TESTF_SCAN_FDT);