1d7c09684SPatrice Chotard // SPDX-License-Identifier: GPL-2.0 2d7c09684SPatrice Chotard /* 3d7c09684SPatrice Chotard * Copyright (c) 2018, STMicroelectronics 4d7c09684SPatrice Chotard */ 5d7c09684SPatrice Chotard 6d7c09684SPatrice Chotard #include <common.h> 7d7c09684SPatrice Chotard #include <serial.h> 8d7c09684SPatrice Chotard #include <dm.h> 9d7c09684SPatrice Chotard #include <dm/test.h> 10d7c09684SPatrice Chotard #include <test/ut.h> 11d7c09684SPatrice Chotard 12d7c09684SPatrice Chotard static int dm_test_serial(struct unit_test_state *uts) 13d7c09684SPatrice Chotard { 14d5bb4f86SAndy Shevchenko struct serial_device_info info_serial = {0}; 15d7c09684SPatrice Chotard struct udevice *dev_serial; 16ac7f5db9SAndy Shevchenko uint value_serial; 17d7c09684SPatrice Chotard 18d7c09684SPatrice Chotard ut_assertok(uclass_get_device_by_name(UCLASS_SERIAL, "serial", 19d7c09684SPatrice Chotard &dev_serial)); 20d7c09684SPatrice Chotard 21d7c09684SPatrice Chotard ut_assertok(serial_tstc()); 22d7c09684SPatrice Chotard /* 23d7c09684SPatrice Chotard * test with default config which is the only one supported by 24d7c09684SPatrice Chotard * sandbox_serial driver 25d7c09684SPatrice Chotard */ 26d7c09684SPatrice Chotard ut_assertok(serial_setconfig(SERIAL_DEFAULT_CONFIG)); 27*67d1b051SSimon Glass ut_assertok(serial_getconfig(dev_serial, &value_serial)); 28ac7f5db9SAndy Shevchenko ut_assert(value_serial == SERIAL_DEFAULT_CONFIG); 29d5bb4f86SAndy Shevchenko ut_assertok(serial_getinfo(&info_serial)); 30d5bb4f86SAndy Shevchenko ut_assert(info_serial.type == SERIAL_CHIP_UNKNOWN); 31d5bb4f86SAndy Shevchenko ut_assert(info_serial.addr == SERIAL_DEFAULT_ADDRESS); 32ac7f5db9SAndy Shevchenko /* 33ac7f5db9SAndy Shevchenko * test with a parameter which is NULL pointer 34ac7f5db9SAndy Shevchenko */ 35*67d1b051SSimon Glass ut_asserteq(-EINVAL, serial_getconfig(dev_serial, NULL)); 36d5bb4f86SAndy Shevchenko ut_asserteq(-EINVAL, serial_getinfo(NULL)); 37d7c09684SPatrice Chotard /* 38d7c09684SPatrice Chotard * test with a serial config which is not supported by 39d7c09684SPatrice Chotard * sandbox_serial driver: test with wrong parity 40d7c09684SPatrice Chotard */ 41d7c09684SPatrice Chotard ut_asserteq(-ENOTSUPP, 42d7c09684SPatrice Chotard serial_setconfig(SERIAL_CONFIG(SERIAL_PAR_ODD, 43d7c09684SPatrice Chotard SERIAL_8_BITS, 44d7c09684SPatrice Chotard SERIAL_ONE_STOP))); 45d7c09684SPatrice Chotard /* 46d7c09684SPatrice Chotard * test with a serial config which is not supported by 47d7c09684SPatrice Chotard * sandbox_serial driver: test with wrong bits number 48d7c09684SPatrice Chotard */ 49d7c09684SPatrice Chotard ut_asserteq(-ENOTSUPP, 50d7c09684SPatrice Chotard serial_setconfig(SERIAL_CONFIG(SERIAL_PAR_NONE, 51d7c09684SPatrice Chotard SERIAL_6_BITS, 52d7c09684SPatrice Chotard SERIAL_ONE_STOP))); 53d7c09684SPatrice Chotard 54d7c09684SPatrice Chotard /* 55d7c09684SPatrice Chotard * test with a serial config which is not supported by 56d7c09684SPatrice Chotard * sandbox_serial driver: test with wrong stop bits number 57d7c09684SPatrice Chotard */ 58d7c09684SPatrice Chotard ut_asserteq(-ENOTSUPP, 59d7c09684SPatrice Chotard serial_setconfig(SERIAL_CONFIG(SERIAL_PAR_NONE, 60d7c09684SPatrice Chotard SERIAL_8_BITS, 61d7c09684SPatrice Chotard SERIAL_TWO_STOP))); 62d7c09684SPatrice Chotard 63d7c09684SPatrice Chotard return 0; 64d7c09684SPatrice Chotard } 65d7c09684SPatrice Chotard 66d7c09684SPatrice Chotard DM_TEST(dm_test_serial, DM_TESTF_SCAN_FDT); 67