From 679190c41a25592103e711718c93d2655d344713 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Mon, 4 Apr 2022 14:17:59 -0400 Subject: test: serial: Add test for putc/puts This adds a test to ensure that puts is equivalent to putc called in a loop. We don't verify the contents of the message to avoid having to record console output a second time (though that could be added in the future). The globals are initialized to non-zero values to avoid a warning; in particular, the character count is off-by-one (but we always make relative measurements). Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- test/dm/serial.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/dm/serial.c') diff --git a/test/dm/serial.c b/test/dm/serial.c index 0662b5f09b8..37d17a65f16 100644 --- a/test/dm/serial.c +++ b/test/dm/serial.c @@ -7,14 +7,22 @@ #include #include #include +#include #include #include #include +static const char test_message[] = + "This is a test message\n" + "consisting of multiple lines\n"; + static int dm_test_serial(struct unit_test_state *uts) { + int i; struct serial_device_info info_serial = {0}; struct udevice *dev_serial; + size_t start, putc_written; + uint value_serial; ut_assertok(uclass_get_device_by_name(UCLASS_SERIAL, "serial", @@ -66,6 +74,17 @@ static int dm_test_serial(struct unit_test_state *uts) SERIAL_8_BITS, SERIAL_TWO_STOP))); + /* 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); + return 0; } -- cgit v1.2.3