blob: 6237693cb804df563f041610231546dc0d80948b [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>
Simon Glass0f2af882020-05-10 11:40:05 -06007#include <log.h>
Patrice Chotard70ed0ea2018-08-03 15:07:41 +02008#include <serial.h>
9#include <dm.h>
10#include <dm/test.h>
11#include <test/ut.h>
12
13static int dm_test_serial(struct unit_test_state *uts)
14{
Andy Shevchenko44f21da2018-11-20 23:52:33 +020015 struct serial_device_info info_serial = {0};
Patrice Chotard70ed0ea2018-08-03 15:07:41 +020016 struct udevice *dev_serial;
Andy Shevchenko08e98792018-11-20 23:52:32 +020017 uint value_serial;
Patrice Chotard70ed0ea2018-08-03 15:07:41 +020018
19 ut_assertok(uclass_get_device_by_name(UCLASS_SERIAL, "serial",
20 &dev_serial));
21
22 ut_assertok(serial_tstc());
23 /*
24 * test with default config which is the only one supported by
25 * sandbox_serial driver
26 */
Simon Glassde62d482018-12-28 14:23:09 -070027 ut_assertok(serial_setconfig(dev_serial, SERIAL_DEFAULT_CONFIG));
Simon Glassdaaff932018-12-28 14:23:08 -070028 ut_assertok(serial_getconfig(dev_serial, &value_serial));
Andy Shevchenko08e98792018-11-20 23:52:32 +020029 ut_assert(value_serial == SERIAL_DEFAULT_CONFIG);
Simon Glass896c1642018-12-28 14:23:10 -070030 ut_assertok(serial_getinfo(dev_serial, &info_serial));
Andy Shevchenko44f21da2018-11-20 23:52:33 +020031 ut_assert(info_serial.type == SERIAL_CHIP_UNKNOWN);
32 ut_assert(info_serial.addr == SERIAL_DEFAULT_ADDRESS);
Andy Shevchenko106930e2020-02-27 17:21:54 +020033 ut_assert(info_serial.clock == SERIAL_DEFAULT_CLOCK);
Andy Shevchenko08e98792018-11-20 23:52:32 +020034 /*
35 * test with a parameter which is NULL pointer
36 */
Simon Glassdaaff932018-12-28 14:23:08 -070037 ut_asserteq(-EINVAL, serial_getconfig(dev_serial, NULL));
Simon Glass896c1642018-12-28 14:23:10 -070038 ut_asserteq(-EINVAL, serial_getinfo(dev_serial, NULL));
Patrice Chotard70ed0ea2018-08-03 15:07:41 +020039 /*
40 * test with a serial config which is not supported by
41 * sandbox_serial driver: test with wrong parity
42 */
43 ut_asserteq(-ENOTSUPP,
Simon Glassde62d482018-12-28 14:23:09 -070044 serial_setconfig(dev_serial,
45 SERIAL_CONFIG(SERIAL_PAR_ODD,
Patrice Chotard70ed0ea2018-08-03 15:07:41 +020046 SERIAL_8_BITS,
47 SERIAL_ONE_STOP)));
48 /*
49 * test with a serial config which is not supported by
50 * sandbox_serial driver: test with wrong bits number
51 */
52 ut_asserteq(-ENOTSUPP,
Simon Glassde62d482018-12-28 14:23:09 -070053 serial_setconfig(dev_serial,
54 SERIAL_CONFIG(SERIAL_PAR_NONE,
Patrice Chotard70ed0ea2018-08-03 15:07:41 +020055 SERIAL_6_BITS,
56 SERIAL_ONE_STOP)));
57
58 /*
59 * test with a serial config which is not supported by
60 * sandbox_serial driver: test with wrong stop bits number
61 */
62 ut_asserteq(-ENOTSUPP,
Simon Glassde62d482018-12-28 14:23:09 -070063 serial_setconfig(dev_serial,
64 SERIAL_CONFIG(SERIAL_PAR_NONE,
Patrice Chotard70ed0ea2018-08-03 15:07:41 +020065 SERIAL_8_BITS,
66 SERIAL_TWO_STOP)));
67
68 return 0;
69}
70
71DM_TEST(dm_test_serial, DM_TESTF_SCAN_FDT);