/* SPDX-License-Identifier: LicenseRef-Starship-1.0 * Copyright (c) 2023-2026 Robert A. James */ /* test_sk_v4_stop.c -- kernel/src/v4/sk_v4_stop.c on the host (#177): the v4 kernel's fatal stops * halt -- interrupts off, then arch_halt() in a loop -- instead of spinning a core at 100%. * arch_halt() and arch_disable_interrupts() are faked: the fake halt counts, and after a few calls * jumps back out of the loop. A stop that spins never calls it: an alarm ends the test as failed. */ #define _POSIX_C_SOURCE 200809L #include "harness.h" #include "starkernel/v4/sk_v4_stop.h" #include #include #include static jmp_buf out; static int halts, irq_off, irq_off_before_first_halt = -1; void arch_disable_interrupts(void) { irq_off = 1; } void arch_enable_interrupts(void) { irq_off = 0; } void arch_halt(void) { if (irq_off_before_first_halt < 0) irq_off_before_first_halt = irq_off; if (++halts >= 3) longjmp(out, 1); /* it is halting, again and again: enough */ } static void spun(int sig) { (void)sig; static const char msg[] = "FAIL sk_v4_stop spun for 2 s without halting (#177)\n 1 checks, 1 failures\n"; (void)!write(1, msg, sizeof msg - 1); /* not printf: _exit would not flush it */ _exit(1); } int main(void) { signal(SIGALRM, spun); alarm(2); if (setjmp(out) == 0) sk_v4_stop(); alarm(0); CHECK(halts == 3, "#177: the stop halts in a loop (arch_halt called %d times before the test stopped it)", halts); CHECK(irq_off_before_first_halt == 1, "#177: interrupts off before the first halt, so nothing wakes it to spin again"); return DONE(); }