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 { 14d7c09684SPatrice Chotard struct udevice *dev_serial; 15*ac7f5db9SAndy Shevchenko uint value_serial; 16d7c09684SPatrice Chotard 17d7c09684SPatrice Chotard ut_assertok(uclass_get_device_by_name(UCLASS_SERIAL, "serial", 18d7c09684SPatrice Chotard &dev_serial)); 19d7c09684SPatrice Chotard 20d7c09684SPatrice Chotard ut_assertok(serial_tstc()); 21d7c09684SPatrice Chotard /* 22d7c09684SPatrice Chotard * test with default config which is the only one supported by 23d7c09684SPatrice Chotard * sandbox_serial driver 24d7c09684SPatrice Chotard */ 25d7c09684SPatrice Chotard ut_assertok(serial_setconfig(SERIAL_DEFAULT_CONFIG)); 26*ac7f5db9SAndy Shevchenko ut_assertok(serial_getconfig(&value_serial)); 27*ac7f5db9SAndy Shevchenko ut_assert(value_serial == SERIAL_DEFAULT_CONFIG); 28*ac7f5db9SAndy Shevchenko /* 29*ac7f5db9SAndy Shevchenko * test with a parameter which is NULL pointer 30*ac7f5db9SAndy Shevchenko */ 31*ac7f5db9SAndy Shevchenko ut_asserteq(-EINVAL, serial_getconfig(NULL)); 32d7c09684SPatrice Chotard /* 33d7c09684SPatrice Chotard * test with a serial config which is not supported by 34d7c09684SPatrice Chotard * sandbox_serial driver: test with wrong parity 35d7c09684SPatrice Chotard */ 36d7c09684SPatrice Chotard ut_asserteq(-ENOTSUPP, 37d7c09684SPatrice Chotard serial_setconfig(SERIAL_CONFIG(SERIAL_PAR_ODD, 38d7c09684SPatrice Chotard SERIAL_8_BITS, 39d7c09684SPatrice Chotard SERIAL_ONE_STOP))); 40d7c09684SPatrice Chotard /* 41d7c09684SPatrice Chotard * test with a serial config which is not supported by 42d7c09684SPatrice Chotard * sandbox_serial driver: test with wrong bits number 43d7c09684SPatrice Chotard */ 44d7c09684SPatrice Chotard ut_asserteq(-ENOTSUPP, 45d7c09684SPatrice Chotard serial_setconfig(SERIAL_CONFIG(SERIAL_PAR_NONE, 46d7c09684SPatrice Chotard SERIAL_6_BITS, 47d7c09684SPatrice Chotard SERIAL_ONE_STOP))); 48d7c09684SPatrice Chotard 49d7c09684SPatrice Chotard /* 50d7c09684SPatrice Chotard * test with a serial config which is not supported by 51d7c09684SPatrice Chotard * sandbox_serial driver: test with wrong stop bits number 52d7c09684SPatrice Chotard */ 53d7c09684SPatrice Chotard ut_asserteq(-ENOTSUPP, 54d7c09684SPatrice Chotard serial_setconfig(SERIAL_CONFIG(SERIAL_PAR_NONE, 55d7c09684SPatrice Chotard SERIAL_8_BITS, 56d7c09684SPatrice Chotard SERIAL_TWO_STOP))); 57d7c09684SPatrice Chotard 58d7c09684SPatrice Chotard return 0; 59d7c09684SPatrice Chotard } 60d7c09684SPatrice Chotard 61d7c09684SPatrice Chotard DM_TEST(dm_test_serial, DM_TESTF_SCAN_FDT); 62