From a414f5de92027992bdcc28058f89c75d1d93f60b Mon Sep 17 00:00:00 2001 From: Antoni Adaszkiewicz Date: Tue, 24 Jan 2023 17:29:47 +0100 Subject: [PATCH] Add tests for new drain and flush functions in UART api Change-Id: I7ec9d9b0893f1628c96e23c41b7119f3e01bd51b --- test/include/test_peripheral_uart.h | 4 ++ test/peripheral-io-test.c | 8 +++ test/src/test_peripheral_uart.c | 98 +++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+) diff --git a/test/include/test_peripheral_uart.h b/test/include/test_peripheral_uart.h index 89e2b33..389b8d2 100644 --- a/test/include/test_peripheral_uart.h +++ b/test/include/test_peripheral_uart.h @@ -78,5 +78,9 @@ int test_peripheral_io_uart_peripheral_uart_read_n2(void); int test_peripheral_io_uart_peripheral_uart_write_p(void); int test_peripheral_io_uart_peripheral_uart_write_n1(void); int test_peripheral_io_uart_peripheral_uart_write_n2(void); +int test_peripheral_io_uart_peripheral_uart_flush_p(void); +int test_peripheral_io_uart_peripheral_uart_flush_n(void); +int test_peripheral_io_uart_peripheral_uart_drain_p(void); +int test_peripheral_io_uart_peripheral_uart_drain_n(void); #endif /* __TEST_PERIPHERAL_UART_H__ */ \ No newline at end of file diff --git a/test/peripheral-io-test.c b/test/peripheral-io-test.c index 420445a..65dacb3 100644 --- a/test/peripheral-io-test.c +++ b/test/peripheral-io-test.c @@ -484,6 +484,14 @@ static void __test_peripheral_uart_run() __error_check(ret, "test_peripheral_io_uart_peripheral_uart_write_n1"); ret = test_peripheral_io_uart_peripheral_uart_write_n2(); __error_check(ret, "test_peripheral_io_uart_peripheral_uart_write_n2"); + ret = test_peripheral_io_uart_peripheral_uart_flush_p(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_flush_p"); + ret = test_peripheral_io_uart_peripheral_uart_flush_n(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_flush_n"); + ret = test_peripheral_io_uart_peripheral_uart_drain_p(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_drain_p"); + ret = test_peripheral_io_uart_peripheral_uart_drain_n(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_drain_n"); __test_performance_for_function("open/close", test_peripheral_io_uart_peripheral_uart_open_p); } diff --git a/test/src/test_peripheral_uart.c b/test/src/test_peripheral_uart.c index 0c7db85..c813fec 100644 --- a/test/src/test_peripheral_uart.c +++ b/test/src/test_peripheral_uart.c @@ -1695,3 +1695,101 @@ int test_peripheral_io_uart_peripheral_uart_write_n2(void) return PERIPHERAL_ERROR_NONE; } + +int test_peripheral_io_uart_peripheral_uart_flush_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + if (g_feature == false) { + ret = peripheral_uart_flush(uart_h); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) + return ret; + + ret = peripheral_uart_flush(uart_h); + if (ret != PERIPHERAL_ERROR_NONE && ret != PERIPHERAL_ERROR_TRY_AGAIN) { + peripheral_uart_close(uart_h); + return ret; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) + return ret; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_flush_n(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + if (g_feature == false) { + ret = peripheral_uart_flush(NULL); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; + + } else { + ret = peripheral_uart_flush(NULL); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { + return ret; + } + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_drain_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + if (g_feature == false) { + ret = peripheral_uart_drain(uart_h); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) + return ret; + + ret = peripheral_uart_drain(uart_h); + if (ret != PERIPHERAL_ERROR_NONE && ret != PERIPHERAL_ERROR_TRY_AGAIN) { + peripheral_uart_close(uart_h); + return ret; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) + return ret; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_drain_n(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + if (g_feature == false) { + ret = peripheral_uart_drain(NULL); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; + + } else { + ret = peripheral_uart_drain(NULL); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { + return ret; + } + } + + return PERIPHERAL_ERROR_NONE; +} -- 2.7.4