. "$BST_LIB"
require ps procps/present

# procps is entirely /proc-driven. On wasm32-hwjs, /proc reads intermittently
# return EINTR and are not restarted (brintos/linux#9 — the kernel's view of the
# signal mask is stale-empty, so a masked signal is delivered mid-read and the read
# returns EINTR instead of restarting). Tools that poll many /proc files per run
# (top, vmstat, pgrep, sysctl, and the full-scan `ps -e`) therefore hang; tools that
# read only one or two /proc files work. Assert the working ones; record the
# many-read tools as skip against #9 WITHOUT executing them, so a hung tool cannot
# wedge the whole selftest runner.
#
# Do NOT wrap the asserted tools in `timeout`: coreutils timeout arms a SIGALRM and
# wait()s for the child, and on this runtime that signal/wait path itself hangs (the
# same #9 signal breakage) — wrapping wedges even the working tools. Run them bare;
# they are reliable (verified on-target).

# --- reliably working (few /proc reads) ---
# ps -p <pid> reads a single pid's /proc entry; PID 1 is busybox init.
check_out procps/ps-pid1 "init" ps -p 1
# free reads /proc/meminfo.
check_out procps/free-memtotal "Mem" free
# uptime reads /proc/uptime + /proc/loadavg.
check_out procps/uptime-load "load average" uptime
# pkill --version does not scan /proc (proves the pkill/pgrep binary is present).
check_out procps/pkill-version "procps-ng" pkill --version

# --- present but runtime-blocked by brintos/linux#9 (NOT executed: they hang) ---
for t in top vmstat pgrep sysctl; do
  if command -v "$t" >/dev/null 2>&1; then
    bst_skip "procps/$t" "present; hangs on wasm32-hwjs /proc EINTR (brintos/linux#9) — not run to avoid wedging the runner"
  else
    bst_skip "procps/$t" "$t not installed on this image"
  fi
done
# ps -e (full-process scan) is intermittently hit by the same #9 EINTR.
bst_skip "procps/ps-scan" "ps -e full scan intermittently hangs on /proc EINTR (brintos/linux#9)"
