2018-08-03 13:07:41 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2018, STMicroelectronics
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2018-08-03 13:07:41 +00:00
|
|
|
#include <serial.h>
|
|
|
|
#include <dm.h>
|
2022-04-04 18:17:59 +00:00
|
|
|
#include <asm/serial.h>
|
2018-08-03 13:07:41 +00:00
|
|
|
#include <dm/test.h>
|
2020-07-19 16:15:37 +00:00
|
|
|
#include <test/test.h>
|
2018-08-03 13:07:41 +00:00
|
|
|
#include <test/ut.h>
|
|
|
|
|
2022-04-04 18:17:59 +00:00
|
|
|
static const char test_message[] =
|
|
|
|
"This is a test message\n"
|
|
|
|
"consisting of multiple lines\n";
|
|
|
|
|
2018-08-03 13:07:41 +00:00
|
|
|
static int dm_test_serial(struct unit_test_state *uts)
|
|
|
|
{
|
2022-04-04 18:17:59 +00:00
|
|
|
int i;
|
2018-11-20 21:52:33 +00:00
|
|
|
struct serial_device_info info_serial = {0};
|
2018-08-03 13:07:41 +00:00
|
|
|
struct udevice *dev_serial;
|
2022-04-04 18:17:59 +00:00
|
|
|
size_t start, putc_written;
|
|
|
|
|
2018-11-20 21:52:32 +00:00
|
|
|
uint value_serial;
|
2018-08-03 13:07:41 +00:00
|
|
|
|
|
|
|
ut_assertok(uclass_get_device_by_name(UCLASS_SERIAL, "serial",
|
|
|
|
&dev_serial));
|
|
|
|
|
|
|
|
ut_assertok(serial_tstc());
|
2023-09-21 11:20:43 +00:00
|
|
|
ut_asserteq(115200, fetch_baud_from_dtb());
|
2018-08-03 13:07:41 +00:00
|
|
|
/*
|
|
|
|
* test with default config which is the only one supported by
|
|
|
|
* sandbox_serial driver
|
|
|
|
*/
|
2018-12-28 21:23:09 +00:00
|
|
|
ut_assertok(serial_setconfig(dev_serial, SERIAL_DEFAULT_CONFIG));
|
2018-12-28 21:23:08 +00:00
|
|
|
ut_assertok(serial_getconfig(dev_serial, &value_serial));
|
2018-11-20 21:52:32 +00:00
|
|
|
ut_assert(value_serial == SERIAL_DEFAULT_CONFIG);
|
2018-12-28 21:23:10 +00:00
|
|
|
ut_assertok(serial_getinfo(dev_serial, &info_serial));
|
2018-11-20 21:52:33 +00:00
|
|
|
ut_assert(info_serial.type == SERIAL_CHIP_UNKNOWN);
|
|
|
|
ut_assert(info_serial.addr == SERIAL_DEFAULT_ADDRESS);
|
2020-02-27 15:21:54 +00:00
|
|
|
ut_assert(info_serial.clock == SERIAL_DEFAULT_CLOCK);
|
2018-11-20 21:52:32 +00:00
|
|
|
/*
|
|
|
|
* test with a parameter which is NULL pointer
|
|
|
|
*/
|
2018-12-28 21:23:08 +00:00
|
|
|
ut_asserteq(-EINVAL, serial_getconfig(dev_serial, NULL));
|
2018-12-28 21:23:10 +00:00
|
|
|
ut_asserteq(-EINVAL, serial_getinfo(dev_serial, NULL));
|
2018-08-03 13:07:41 +00:00
|
|
|
/*
|
|
|
|
* test with a serial config which is not supported by
|
|
|
|
* sandbox_serial driver: test with wrong parity
|
|
|
|
*/
|
|
|
|
ut_asserteq(-ENOTSUPP,
|
2018-12-28 21:23:09 +00:00
|
|
|
serial_setconfig(dev_serial,
|
|
|
|
SERIAL_CONFIG(SERIAL_PAR_ODD,
|
2018-08-03 13:07:41 +00:00
|
|
|
SERIAL_8_BITS,
|
|
|
|
SERIAL_ONE_STOP)));
|
|
|
|
/*
|
|
|
|
* test with a serial config which is not supported by
|
|
|
|
* sandbox_serial driver: test with wrong bits number
|
|
|
|
*/
|
|
|
|
ut_asserteq(-ENOTSUPP,
|
2018-12-28 21:23:09 +00:00
|
|
|
serial_setconfig(dev_serial,
|
|
|
|
SERIAL_CONFIG(SERIAL_PAR_NONE,
|
2018-08-03 13:07:41 +00:00
|
|
|
SERIAL_6_BITS,
|
|
|
|
SERIAL_ONE_STOP)));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* test with a serial config which is not supported by
|
|
|
|
* sandbox_serial driver: test with wrong stop bits number
|
|
|
|
*/
|
|
|
|
ut_asserteq(-ENOTSUPP,
|
2018-12-28 21:23:09 +00:00
|
|
|
serial_setconfig(dev_serial,
|
|
|
|
SERIAL_CONFIG(SERIAL_PAR_NONE,
|
2018-08-03 13:07:41 +00:00
|
|
|
SERIAL_8_BITS,
|
|
|
|
SERIAL_TWO_STOP)));
|
|
|
|
|
2022-04-04 18:17:59 +00:00
|
|
|
/* Verify that putc and puts print the same number of characters */
|
|
|
|
sandbox_serial_endisable(false);
|
|
|
|
start = sandbox_serial_written();
|
|
|
|
for (i = 0; i < sizeof(test_message) - 1; i++)
|
|
|
|
serial_putc(test_message[i]);
|
|
|
|
putc_written = sandbox_serial_written();
|
|
|
|
serial_puts(test_message);
|
|
|
|
sandbox_serial_endisable(true);
|
|
|
|
ut_asserteq(putc_written - start,
|
|
|
|
sandbox_serial_written() - putc_written);
|
|
|
|
|
2018-08-03 13:07:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_serial, UT_TESTF_SCAN_FDT);
|