// Runtime check 4: the fault report. Stores to address 0 after 2 s; the
// runtime's handler should write game:/crash.txt (exception, address,
// registers, stack) and go back to the dashboard.
#include <cstdio>
#include "xex_runtime.h"

static void __attribute__((noinline)) crashHere(volatile int *p) {
    *p = 42;
}

static void __attribute__((noinline)) caller(volatile int *p) {
    crashHere(p);
    printf("fault: still alive after the store\n");
}

int main(int, char **) {
    remove("game:/crash.txt");
    xex_notify("fault test: crashing in 2 s");
    xex_sleep_ms(2000);
    caller((volatile int *)nullptr);
    xex_notify("fault test: NOT caught");
    xex_sleep_ms(4000);
    return 0;
}
