From 3b38b29cd60e907cfa5bc347477ba08eee28fa94 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 17 Oct 2022 18:31:44 +0200 Subject: [PATCH] tests/event_source: add test for event sources --- tests/event_source/Makefile | 6 ++++ tests/event_source/Makefile.ci | 3 ++ tests/event_source/main.c | 56 ++++++++++++++++++++++++++++++ tests/event_source/tests/01-run.py | 16 +++++++++ 4 files changed, 81 insertions(+) create mode 100644 tests/event_source/Makefile create mode 100644 tests/event_source/Makefile.ci create mode 100644 tests/event_source/main.c create mode 100755 tests/event_source/tests/01-run.py diff --git a/tests/event_source/Makefile b/tests/event_source/Makefile new file mode 100644 index 0000000000..7b235ab750 --- /dev/null +++ b/tests/event_source/Makefile @@ -0,0 +1,6 @@ +include ../Makefile.tests_common + +USEMODULE += event_callback +USEMODULE += event_thread + +include $(RIOTBASE)/Makefile.include diff --git a/tests/event_source/Makefile.ci b/tests/event_source/Makefile.ci new file mode 100644 index 0000000000..b9ff275375 --- /dev/null +++ b/tests/event_source/Makefile.ci @@ -0,0 +1,3 @@ +BOARD_INSUFFICIENT_MEMORY := \ + nucleo-l011k4 \ + # diff --git a/tests/event_source/main.c b/tests/event_source/main.c new file mode 100644 index 0000000000..6a22449715 --- /dev/null +++ b/tests/event_source/main.c @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2022 ML!PA Consulting GmbH + * + * 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 Event Source test application + * + * @author Benjamin Valentin + * + * @} + */ + +#include + +#include "event/callback.h" +#include "event/source.h" +#include "event/thread.h" + +static void _event_cb(void *ctx) +{ + puts(ctx); +} + +int main(void) +{ + event_source_t source = EVENT_SOURCE_INIT; + event_callback_t a, b, c; + + event_source_subscriber_t ba = EVENT_SOURCE_SUBSCRIBER_INIT(&a, EVENT_PRIO_MEDIUM); + event_source_subscriber_t bb = EVENT_SOURCE_SUBSCRIBER_INIT(&b, EVENT_PRIO_MEDIUM); + event_source_subscriber_t bc = EVENT_SOURCE_SUBSCRIBER_INIT(&c, EVENT_PRIO_MEDIUM); + + event_callback_init(&a, _event_cb, "event A"); + event_callback_init(&b, _event_cb, "event B"); + event_callback_init(&c, _event_cb, "event C"); + + puts("empty event source"); + event_source_trigger(&source); + + event_source_attach(&source, &ba); + event_source_attach(&source, &bb); + event_source_attach(&source, &bc); + + puts("occupied event source"); + event_source_trigger(&source); + + return 0; +} diff --git a/tests/event_source/tests/01-run.py b/tests/event_source/tests/01-run.py new file mode 100755 index 0000000000..16803a028d --- /dev/null +++ b/tests/event_source/tests/01-run.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 + +import sys +from testrunner import run + + +def testfunc(child): + child.expect_exact("empty event source") + child.expect_exact("occupied event source") + child.expect_exact("event C") + child.expect_exact("event B") + child.expect_exact("event A") + + +if __name__ == "__main__": + sys.exit(run(testfunc))