Patrice Chotard | 70ed0ea | 2018-08-03 15:07:41 +0200 | [diff] [blame] | 1 | // 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 | |
| 12 | static int dm_test_serial(struct unit_test_state *uts) |
| 13 | { |
Andy Shevchenko | 44f21da | 2018-11-20 23:52:33 +0200 | [diff] [blame] | 14 | struct serial_device_info info_serial = {0}; |
Patrice Chotard | 70ed0ea | 2018-08-03 15:07:41 +0200 | [diff] [blame] | 15 | struct udevice *dev_serial; |
Andy Shevchenko | 08e9879 | 2018-11-20 23:52:32 +0200 | [diff] [blame] | 16 | uint value_serial; |
Patrice Chotard | 70ed0ea | 2018-08-03 15:07:41 +0200 | [diff] [blame] | 17 | |
| 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 Glass | de62d48 | 2018-12-28 14:23:09 -0700 | [diff] [blame] | 26 | ut_assertok(serial_setconfig(dev_serial, SERIAL_DEFAULT_CONFIG)); |
Simon Glass | daaff93 | 2018-12-28 14:23:08 -0700 | [diff] [blame] | 27 | ut_assertok(serial_getconfig(dev_serial, &value_serial)); |
Andy Shevchenko | 08e9879 | 2018-11-20 23:52:32 +0200 | [diff] [blame] | 28 | ut_assert(value_serial == SERIAL_DEFAULT_CONFIG); |
Simon Glass | 896c164 | 2018-12-28 14:23:10 -0700 | [diff] [blame] | 29 | ut_assertok(serial_getinfo(dev_serial, &info_serial)); |
Andy Shevchenko | 44f21da | 2018-11-20 23:52:33 +0200 | [diff] [blame] | 30 | ut_assert(info_serial.type == SERIAL_CHIP_UNKNOWN); |
| 31 | ut_assert(info_serial.addr == SERIAL_DEFAULT_ADDRESS); |
Andy Shevchenko | 106930e | 2020-02-27 17:21:54 +0200 | [diff] [blame] | 32 | ut_assert(info_serial.clock == SERIAL_DEFAULT_CLOCK); |
Andy Shevchenko | 08e9879 | 2018-11-20 23:52:32 +0200 | [diff] [blame] | 33 | /* |
| 34 | * test with a parameter which is NULL pointer |
| 35 | */ |
Simon Glass | daaff93 | 2018-12-28 14:23:08 -0700 | [diff] [blame] | 36 | ut_asserteq(-EINVAL, serial_getconfig(dev_serial, NULL)); |
Simon Glass | 896c164 | 2018-12-28 14:23:10 -0700 | [diff] [blame] | 37 | ut_asserteq(-EINVAL, serial_getinfo(dev_serial, NULL)); |
Patrice Chotard | 70ed0ea | 2018-08-03 15:07:41 +0200 | [diff] [blame] | 38 | /* |
| 39 | * test with a serial config which is not supported by |
| 40 | * sandbox_serial driver: test with wrong parity |
| 41 | */ |
| 42 | ut_asserteq(-ENOTSUPP, |
Simon Glass | de62d48 | 2018-12-28 14:23:09 -0700 | [diff] [blame] | 43 | serial_setconfig(dev_serial, |
| 44 | SERIAL_CONFIG(SERIAL_PAR_ODD, |
Patrice Chotard | 70ed0ea | 2018-08-03 15:07:41 +0200 | [diff] [blame] | 45 | SERIAL_8_BITS, |
| 46 | SERIAL_ONE_STOP))); |
| 47 | /* |
| 48 | * test with a serial config which is not supported by |
| 49 | * sandbox_serial driver: test with wrong bits number |
| 50 | */ |
| 51 | ut_asserteq(-ENOTSUPP, |
Simon Glass | de62d48 | 2018-12-28 14:23:09 -0700 | [diff] [blame] | 52 | serial_setconfig(dev_serial, |
| 53 | SERIAL_CONFIG(SERIAL_PAR_NONE, |
Patrice Chotard | 70ed0ea | 2018-08-03 15:07:41 +0200 | [diff] [blame] | 54 | SERIAL_6_BITS, |
| 55 | SERIAL_ONE_STOP))); |
| 56 | |
| 57 | /* |
| 58 | * test with a serial config which is not supported by |
| 59 | * sandbox_serial driver: test with wrong stop bits number |
| 60 | */ |
| 61 | ut_asserteq(-ENOTSUPP, |
Simon Glass | de62d48 | 2018-12-28 14:23:09 -0700 | [diff] [blame] | 62 | serial_setconfig(dev_serial, |
| 63 | SERIAL_CONFIG(SERIAL_PAR_NONE, |
Patrice Chotard | 70ed0ea | 2018-08-03 15:07:41 +0200 | [diff] [blame] | 64 | SERIAL_8_BITS, |
| 65 | SERIAL_TWO_STOP))); |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | DM_TEST(dm_test_serial, DM_TESTF_SCAN_FDT); |