From 0c08abd19a11c64e2e5349e508e7c53da90add99 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Fri, 15 Nov 2019 14:43:19 +0100 Subject: [PATCH] tests/periph_uart_nonblocking: add simple test application MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The application is mainly to compile-test non-blocking UART functionality, but some functional testing is also possible. With non-blocking UART the total runtime of the program is 2100735 µs on same54-xpro. With blocking UART the total runtime is 2152407 µs. --- tests/periph_uart_nonblocking/Makefile | 6 ++ tests/periph_uart_nonblocking/main.c | 69 +++++++++++++++++++ tests/periph_uart_nonblocking/tests/01-run.py | 24 +++++++ 3 files changed, 99 insertions(+) create mode 100644 tests/periph_uart_nonblocking/Makefile create mode 100644 tests/periph_uart_nonblocking/main.c create mode 100755 tests/periph_uart_nonblocking/tests/01-run.py diff --git a/tests/periph_uart_nonblocking/Makefile b/tests/periph_uart_nonblocking/Makefile new file mode 100644 index 0000000000..dd5a14dadc --- /dev/null +++ b/tests/periph_uart_nonblocking/Makefile @@ -0,0 +1,6 @@ +include ../Makefile.tests_common + +FEATURES_REQUIRED += periph_uart_nonblocking +USEMODULE += xtimer + +include $(RIOTBASE)/Makefile.include diff --git a/tests/periph_uart_nonblocking/main.c b/tests/periph_uart_nonblocking/main.c new file mode 100644 index 0000000000..62e2f6fabb --- /dev/null +++ b/tests/periph_uart_nonblocking/main.c @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2019 Benjamin Valentin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief Simple test application for non-blocking UART functionality + * + * @author Benjamin Valentin + * + * @} + */ + +#include +#include + +#define LINE_DELAY_MS 100 + +static inline uint32_t puts_delay(const char* str) +{ + puts(str); + xtimer_usleep(LINE_DELAY_MS * 1000); + return LINE_DELAY_MS * 1000; +} + +int main(void) +{ + uint32_t total_us = 0; + xtimer_ticks32_t counter = xtimer_now(); + + /* Richard Stallman and the Free Software Foundation + claim no copyright on this song. */ + total_us += puts_delay(""); + total_us += puts_delay("Join us now and share the software;"); + total_us += puts_delay("You'll be free, hackers, you'll be free."); + total_us += puts_delay("Join us now and share the software;"); + total_us += puts_delay("You'll be free, hackers, you'll be free."); + total_us += puts_delay(""); + total_us += puts_delay("Hoarders can get piles of money,"); + total_us += puts_delay("That is true, hackers, that is true."); + total_us += puts_delay("But they cannot help their neighbors;"); + total_us += puts_delay("That's not good, hackers, that's not good."); + total_us += puts_delay(""); + total_us += puts_delay("When we have enough free software"); + total_us += puts_delay("At our call, hackers, at our call,"); + total_us += puts_delay("We'll kick out those dirty licenses"); + total_us += puts_delay("Ever more, hackers, ever more."); + total_us += puts_delay(""); + total_us += puts_delay("Join us now and share the software;"); + total_us += puts_delay("You'll be free, hackers, you'll be free."); + total_us += puts_delay("Join us now and share the software;"); + total_us += puts_delay("You'll be free, hackers, you'll be free."); + total_us += puts_delay(""); + + counter.ticks32 = xtimer_now().ticks32 - counter.ticks32; + + printf("== printed in %" PRIu32 "/%" PRIu32 " µs ==\n", xtimer_usec_from_ticks(counter), total_us); + + puts("[SUCCESS]"); + + return 0; +} diff --git a/tests/periph_uart_nonblocking/tests/01-run.py b/tests/periph_uart_nonblocking/tests/01-run.py new file mode 100755 index 0000000000..11f5abbc9a --- /dev/null +++ b/tests/periph_uart_nonblocking/tests/01-run.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2019 Benjamin Valentin +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. + +import sys +from testrunner import run + + +def testfunc(child): + child.expect(r'== printed in (\d+)/(\d+) µs ==') + time_actual = int(child.match.group(1)) + time_expect = int(child.match.group(2)) + + assert time_actual / time_expect < 1.0015 + + child.expect_exact("[SUCCESS]") + + +if __name__ == "__main__": + sys.exit(run(testfunc))