summaryrefslogtreecommitdiff
path: root/test/test_xcall.c
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2014-10-09 21:01:25 +0200
committerRichard Braun <rbraun@sceen.net>2014-10-09 21:01:25 +0200
commit11f78e61b3f7a00ba35933ce94ba4db1f213ebe0 (patch)
tree57fced19e7a4d86ef899fa166b51264fa358ce86 /test/test_xcall.c
parent1839368a4f2bdfb0e1cd784f22bf0a70d868ff13 (diff)
kern/xcall: new module
Provide cross-processor function calls.
Diffstat (limited to 'test/test_xcall.c')
-rw-r--r--test/test_xcall.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/test/test_xcall.c b/test/test_xcall.c
new file mode 100644
index 00000000..9da6a151
--- /dev/null
+++ b/test/test_xcall.c
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2014 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 is a simple test of the cross-call functionality. One thread is
+ * created and bound to CPU 0. It makes two cross-calls, one on its local
+ * processor, and another on a remote processor.
+ */
+
+#include <kern/error.h>
+#include <kern/cpumap.h>
+#include <kern/printk.h>
+#include <kern/stddef.h>
+#include <kern/thread.h>
+#include <kern/xcall.h>
+#include <test/test.h>
+
+static int test_done;
+
+static void
+test_fn(void *arg)
+{
+ (void)arg;
+
+ printk("function called, running on cpu%u\n", cpu_id());
+ test_done = 1;
+}
+
+static void
+test_once(unsigned int cpu)
+{
+ test_done = 0;
+
+ printk("cross-call on cpu%u:\n", cpu);
+ xcall_call(test_fn, NULL, cpu);
+
+ if (!test_done)
+ panic("test_done false");
+}
+
+static void
+test_run(void *arg)
+{
+ (void)arg;
+
+ test_once(0);
+ test_once(1);
+ printk("done\n");
+}
+
+void
+test_setup(void)
+{
+ struct thread_attr attr;
+ struct thread *thread;
+ struct cpumap *cpumap;
+ int error;
+
+ error = cpumap_create(&cpumap);
+ error_check(error, "cpumap_create");
+ cpumap_zero(cpumap);
+ cpumap_set(cpumap, 0);
+
+ thread_attr_init(&attr, "x15_test_run");
+ thread_attr_set_detached(&attr);
+ thread_attr_set_cpumap(&attr, cpumap);
+ error = thread_create(&thread, &attr, test_run, NULL);
+ error_check(error, "thread_create");
+
+ cpumap_destroy(cpumap);
+}