From fdba8be7772b4e5d6dfd6ed15529ab4f834fcf9e Mon Sep 17 00:00:00 2001 From: Andy Ross Date: Tue, 7 Jul 2020 08:10:36 -0700 Subject: [PATCH] tests/kernel/smp: Fixup IPI test This test was written to assume that the only IPI handled would be the one generated by the test, but the scheduler also generates an IPI any time a thread becomes runnable, and there's no way to lock that out in an SMP system where the other CPU is going to be doing its own thing (we can't use "1cpu" because that locks interrupts on the other CPU and obviously this is a test of an interrupt). Change the logic to detect that "at least one IPI was received", which is fine for coverage. Really a better place for a test like this would have been tests/kernel/mp, which is a test of the lower level APIs and runs the other CPU deterministically (i.e. not under the control of the Zephyr scheduler). Also some misc fixes: * Don't busy wait at the start, that's needless. * Sleep instead of busywaiting after sending the IPI, spinning isn't needed here and acts to increase CI load needlessly. * Declare the cross thread signal variable volatile for correctness (though this error seems to have been benign in practice). Signed-off-by: Andy Ross --- tests/kernel/smp/src/main.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/tests/kernel/smp/src/main.c b/tests/kernel/smp/src/main.c index c3c4171d6ee..cd48c9a7862 100644 --- a/tests/kernel/smp/src/main.c +++ b/tests/kernel/smp/src/main.c @@ -498,7 +498,7 @@ void test_get_cpu(void) #ifdef CONFIG_TRACE_SCHED_IPI /* global variable for testing send IPI */ -static int sched_ipi_has_called = -1; +static volatile int sched_ipi_has_called; void z_trace_sched_ipi(void) { @@ -524,23 +524,19 @@ void test_smp_ipi(void) { TC_PRINT("cpu num=%d", CONFIG_MP_NUM_CPUS); - sched_ipi_has_called = 0; - - k_busy_wait(DELAY_US); - - /* It shouldn't enter our IPI interrupt handler at this moment */ - zassert_true(sched_ipi_has_called == 0, "shouldn't receive IPI,(%d)", - sched_ipi_has_called); - - for (int i = 1; i <= 3 ; i++) { + for (int i = 0; i < 3 ; i++) { /* issue a sched ipi to tell other CPU to run thread */ + sched_ipi_has_called = 0; arch_sched_ipi(); - /* do busy wait here until get IPI */ - k_busy_wait(DELAY_US); + /* Need to wait longer than we think, loaded CI + * systems need to wait for host scheduling to run the + * other CPU's thread. + */ + k_msleep(100); /**TESTPOINT: check if enter our IPI interrupt handler */ - zassert_true(sched_ipi_has_called == i, + zassert_true(sched_ipi_has_called != 0, "did not receive IPI.(%d)", sched_ipi_has_called); }