summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2018-04-01 07:01:19 +0200
committerRichard Braun <rbraun@sceen.net>2018-04-01 07:01:19 +0200
commitcb86e4abaa7f3419ea0e096e5ca80ede5505a696 (patch)
treefe16a41d98641b45bc35177806fd16a4a09f6001 /test
parent076476fe6c0f4b947d4441afcfc97561bb23711c (diff)
kern/bulletin: new module
Diffstat (limited to 'test')
-rw-r--r--test/Kconfig3
-rw-r--r--test/Makefile1
-rw-r--r--test/test_bulletin.c83
3 files changed, 87 insertions, 0 deletions
diff --git a/test/Kconfig b/test/Kconfig
index 5c3072dc..80679ef9 100644
--- a/test/Kconfig
+++ b/test/Kconfig
@@ -9,6 +9,9 @@ if TEST_MODULE
choice
prompt "Select test module"
+config TEST_MODULE_BULLETIN
+ bool "bulletin"
+
config TEST_MODULE_MUTEX
bool "mutex"
select MUTEX_DEBUG
diff --git a/test/Makefile b/test/Makefile
index 96541af4..c98d6fb4 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -1,3 +1,4 @@
+x15_SOURCES-$(CONFIG_TEST_MODULE_BULLETIN) += test/test_bulletin.c
x15_SOURCES-$(CONFIG_TEST_MODULE_MUTEX) += test/test_mutex.c
x15_SOURCES-$(CONFIG_TEST_MODULE_MUTEX_PI) += test/test_mutex_pi.c
x15_SOURCES-$(CONFIG_TEST_MODULE_PMAP_UPDATE_MP) += test/test_pmap_update_mp.c
diff --git a/test/test_bulletin.c b/test/test_bulletin.c
new file mode 100644
index 00000000..4a2fdb53
--- /dev/null
+++ b/test/test_bulletin.c
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2018 Richard Braun.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ *
+ * This test makes a bulletin subscriber subscribe to a bulletin, and uses
+ * a timer to periodically publish, unsubscribe, and resubscribe to the
+ * bulletin. A counter is used to test passing values to the notification
+ * callback function.
+ */
+
+#include <assert.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdio.h>
+
+#include <kern/bulletin.h>
+#include <kern/clock.h>
+#include <kern/error.h>
+#include <kern/log.h>
+#include <kern/timer.h>
+#include <test/test.h>
+
+#define TEST_INTERVAL 1
+#define TEST_NR_LOOPS 4
+
+static struct bulletin test_bulletin;
+static struct bulletin_sub test_bulletin_sub;
+static struct timer test_timer;
+static unsigned int test_counter;
+
+static void
+test_notify(uintptr_t value, void *arg)
+{
+ log_info("test: notify: value:%lu arg:%p", value, arg);
+}
+
+static void
+test_tick(struct timer *timer)
+{
+ uint64_t ticks;
+
+ test_counter++;
+ bulletin_publish(&test_bulletin, test_counter);
+ bulletin_unsubscribe(&test_bulletin, &test_bulletin_sub);
+
+ if (test_counter == TEST_NR_LOOPS) {
+ log_info("test: done");
+ return;
+ }
+
+ bulletin_subscribe(&test_bulletin, &test_bulletin_sub,
+ test_notify, (void *)0x123);
+
+ ticks = timer_get_time(timer) + clock_ticks_from_ms(TEST_INTERVAL * 1000);
+ timer_schedule(&test_timer, ticks);
+}
+
+void __init
+test_setup(void)
+{
+ uint64_t ticks;
+
+ bulletin_init(&test_bulletin);
+ bulletin_subscribe(&test_bulletin, &test_bulletin_sub,
+ test_notify, (void *)0x123);
+
+ timer_init(&test_timer, test_tick, TIMER_DETACHED);
+ ticks = clock_get_time() + clock_ticks_from_ms(TEST_INTERVAL * 1000);
+ timer_schedule(&test_timer, ticks);
+}