summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMocramis <mocramis@gmail.com>2018-01-08 21:21:13 +0100
committerMocramis <mocramis@gmail.com>2018-01-08 21:21:13 +0100
commitbf5c783d4cad55ba41210ba71b3c8e28ce63cfa8 (patch)
tree63ad90bbc798f6cca9b8cf3d11614b480fc76c1b /test
parent1ec3d3f143a201984d51f1cff91b0fe29cde2b71 (diff)
parent65f71c221037e468caa5921d23a86da34f3bd0a5 (diff)
Merge branch 'master' into perfmon
Diffstat (limited to 'test')
-rw-r--r--test/Kconfig1
-rw-r--r--test/test_mutex.c3
-rw-r--r--test/test_xcall.c85
3 files changed, 64 insertions, 25 deletions
diff --git a/test/Kconfig b/test/Kconfig
index 1881d2a..6f3dbb4 100644
--- a/test/Kconfig
+++ b/test/Kconfig
@@ -14,6 +14,7 @@ config TEST_MODULE_LLSYNC_DEFER
config TEST_MODULE_MUTEX
bool "mutex"
+ select MUTEX_DEBUG
config TEST_MODULE_MUTEX_PI
bool "mutex_pi"
diff --git a/test/test_mutex.c b/test/test_mutex.c
index d5cc5d1..029e2fe 100644
--- a/test/test_mutex.c
+++ b/test/test_mutex.c
@@ -178,7 +178,4 @@ test_setup(void)
timer_init(&test_timer, test_report_syscnt, TIMER_DETACHED);
time = clock_get_time() + clock_ticks_from_ms(TEST_REPORT_INTERVAL);
timer_schedule(&test_timer, time);
-
- log_info("test: enable mutex debugging for the selected implementation");
- log_info("test: and check the relevant system counters");
}
diff --git a/test/test_xcall.c b/test/test_xcall.c
index f516401..cd33594 100644
--- a/test/test_xcall.c
+++ b/test/test_xcall.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014 Richard Braun.
+ * Copyright (c) 2014-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
@@ -15,41 +15,50 @@
* 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.
+ * This test creates a thread that tests cross-calls for all combinations
+ * of processors. This thread sequentially creates other threads that are
+ * bound to a single processor, and perform cross-calls to all processors,
+ * including the local one.
*/
+#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <kern/error.h>
#include <kern/cpumap.h>
+#include <kern/log.h>
#include <kern/panic.h>
#include <kern/thread.h>
#include <kern/xcall.h>
#include <test/test.h>
-static int test_done;
+static bool test_done;
static void
test_fn(void *arg)
{
- (void)arg;
+ uintptr_t cpu;
assert(thread_interrupted());
- printf("function called, running on cpu%u\n", cpu_id());
- test_done = 1;
+ cpu = (uintptr_t)arg;
+
+ if (cpu != cpu_id()) {
+ panic("invalid cpu");
+ }
+
+ log_info("function called, running on cpu%u\n", cpu_id());
+ test_done = true;
}
static void
test_once(unsigned int cpu)
{
- test_done = 0;
+ test_done = false;
- printf("cross-call on cpu%u:\n", cpu);
- xcall_call(test_fn, NULL, cpu);
+ log_info("cross-call: cpu%u -> cpu%u:\n", cpu_id(), cpu);
+ xcall_call(test_fn, (void *)(uintptr_t)cpu, cpu);
if (!test_done) {
panic("test_done false");
@@ -57,33 +66,65 @@ test_once(unsigned int cpu)
}
static void
-test_run(void *arg)
+test_run_cpu(void *arg)
{
(void)arg;
- test_once(0);
- test_once(1);
- printf("done\n");
+ for (unsigned int i = (cpu_count() - 1); i < cpu_count(); i++) {
+ test_once(i);
+ }
}
-void
-test_setup(void)
+static void
+test_run(void *arg)
{
+ char name[THREAD_NAME_SIZE];
struct thread_attr attr;
struct thread *thread;
struct cpumap *cpumap;
+ unsigned int cpu;
int error;
+ (void)arg;
+
error = cpumap_create(&cpumap);
error_check(error, "cpumap_create");
- cpumap_zero(cpumap);
- cpumap_set(cpumap, 0);
+
+ for (unsigned int i = 0; i < cpu_count(); i++) {
+ /*
+ * Send IPIs from CPU 1 first, in order to better trigger any
+ * initialization race that may prevent correct IPI transmission.
+ * This assumes CPUs are initialized sequentially, and that CPU 1
+ * may have finished initialization much earlier than the last CPU.
+ * CPU 0 isn't used since it's the one normally initializing remote
+ * CPUs.
+ */
+ cpu = (1 + i) % cpu_count();
+
+ cpumap_zero(cpumap);
+ cpumap_set(cpumap, cpu);
+ snprintf(name, sizeof(name), THREAD_KERNEL_PREFIX "test_run/%u", cpu);
+ thread_attr_init(&attr, name);
+ thread_attr_set_cpumap(&attr, cpumap);
+ error = thread_create(&thread, &attr, test_run_cpu, NULL);
+ error_check(error, "thread_create");
+ thread_join(thread);
+ }
+
+ cpumap_destroy(cpumap);
+
+ log_info("done\n");
+}
+
+void
+test_setup(void)
+{
+ struct thread_attr attr;
+ struct thread *thread;
+ int error;
thread_attr_init(&attr, THREAD_KERNEL_PREFIX "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);
}