Patrice Chotard | d7c0968 | 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> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 7 | #include <log.h> |
Patrice Chotard | d7c0968 | 2018-08-03 15:07:41 +0200 | [diff] [blame] | 8 | #include <serial.h> |
| 9 | #include <dm.h> |
| 10 | #include <dm/test.h> |
| 11 | #include <test/ut.h> |
| 12 | |
| 13 | static int dm_test_serial(struct unit_test_state *uts) |
| 14 | { |
Andy Shevchenko | d5bb4f8 | 2018-11-20 23:52:33 +0200 | [diff] [blame] | 15 | struct serial_device_info info_serial = {0}; |
Patrice Chotard | d7c0968 | 2018-08-03 15:07:41 +0200 | [diff] [blame] | 16 | struct udevice *dev_serial; |
Andy Shevchenko | ac7f5db | 2018-11-20 23:52:32 +0200 | [diff] [blame] | 17 | uint value_serial; |
Patrice Chotard | d7c0968 | 2018-08-03 15:07:41 +0200 | [diff] [blame] | 18 | |
| 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 Glass | 3de04e7 | 2018-12-28 14:23:09 -0700 | [diff] [blame] | 27 | ut_assertok(serial_setconfig(dev_serial, SERIAL_DEFAULT_CONFIG)); |
Simon Glass | 67d1b05 | 2018-12-28 14:23:08 -0700 | [diff] [blame] | 28 | ut_assertok(serial_getconfig(dev_serial, &value_serial)); |
Andy Shevchenko | ac7f5db | 2018-11-20 23:52:32 +0200 | [diff] [blame] | 29 | ut_assert(value_serial == SERIAL_DEFAULT_CONFIG); |
Simon Glass | a61cbad | 2018-12-28 14:23:10 -0700 | [diff] [blame] | 30 | ut_assertok(serial_getinfo(dev_serial, &info_serial)); |
Andy Shevchenko | d5bb4f8 | 2018-11-20 23:52:33 +0200 | [diff] [blame] | 31 | ut_assert(info_serial.type == SERIAL_CHIP_UNKNOWN); |
| 32 | ut_assert(info_serial.addr == SERIAL_DEFAULT_ADDRESS); |
Andy Shevchenko | bf4661bc | 2020-02-27 17:21:54 +0200 | [diff] [blame] | 33 | ut_assert(info_serial.clock == SERIAL_DEFAULT_CLOCK); |
Andy Shevchenko | ac7f5db | 2018-11-20 23:52:32 +0200 | [diff] [blame] | 34 | /* |
| 35 | * test with a parameter which is NULL pointer |
| 36 | */ |
Simon Glass | 67d1b05 | 2018-12-28 14:23:08 -0700 | [diff] [blame] | 37 | ut_asserteq(-EINVAL, serial_getconfig(dev_serial, NULL)); |
Simon Glass | a61cbad | 2018-12-28 14:23:10 -0700 | [diff] [blame] | 38 | ut_asserteq(-EINVAL, serial_getinfo(dev_serial, NULL)); |
Patrice Chotard | d7c0968 | 2018-08-03 15:07:41 +0200 | [diff] [blame] | 39 | /* |
| 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 Glass | 3de04e7 | 2018-12-28 14:23:09 -0700 | [diff] [blame] | 44 | serial_setconfig(dev_serial, |
| 45 | SERIAL_CONFIG(SERIAL_PAR_ODD, |
Patrice Chotard | d7c0968 | 2018-08-03 15:07:41 +0200 | [diff] [blame] | 46 | 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 Glass | 3de04e7 | 2018-12-28 14:23:09 -0700 | [diff] [blame] | 53 | serial_setconfig(dev_serial, |
| 54 | SERIAL_CONFIG(SERIAL_PAR_NONE, |
Patrice Chotard | d7c0968 | 2018-08-03 15:07:41 +0200 | [diff] [blame] | 55 | 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 Glass | 3de04e7 | 2018-12-28 14:23:09 -0700 | [diff] [blame] | 63 | serial_setconfig(dev_serial, |
| 64 | SERIAL_CONFIG(SERIAL_PAR_NONE, |
Patrice Chotard | d7c0968 | 2018-08-03 15:07:41 +0200 | [diff] [blame] | 65 | SERIAL_8_BITS, |
| 66 | SERIAL_TWO_STOP))); |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | DM_TEST(dm_test_serial, DM_TESTF_SCAN_FDT); |