#!/bin/sh
# Execute the synchronization boundary under deterministic hart interleaving.
set -eu
emulator=${RAD_EMULATOR:-emulator}
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT HUP INT TERM
for harts in 1 2 8; do
    printf '.constant HARTS %s;\n' "$harts" > "$work/sync.ras"
    cat test/sync/machine.ras kernel/kernel/sync.ras >> "$work/sync.ras"
    "$emulator" -run bin/sync.build.rv64 -- "$work/sync.ras" "$work/sync.rv64"
    "$emulator" -machine -harts="$harts" -run "$work/sync.rv64"
done
printf 'synchronization: code publication, locks, atomics, and MMIO passed on 1/2/8 harts\n'
