#!/usr/bin/env bash # Validate the Red Bear OS Phase 1 desktop substrate (CONSOLE-TO-KDE-DESKTOP-PLAN v2.0). # # Modes: # --guest Run inside a Red Bear OS guest # --qemu [CONFIG] Boot CONFIG in QEMU and run the same checks automatically set -euo pipefail find_uefi_firmware() { local candidates=( "/usr/share/ovmf/x64/OVMF.4m.fd" "/usr/share/OVMF/x64/OVMF.4m.fd" "/usr/share/ovmf/x64/OVMF_CODE.4m.fd" "/usr/share/OVMF/x64/OVMF_CODE.4m.fd" "/usr/share/ovmf/OVMF.fd" "/usr/share/OVMF/OVMF_CODE.fd" "/usr/share/qemu/edk2-x86_64-code.fd" ) local path for path in "${candidates[@]}"; do if [[ -f "$path" ]]; then printf '%s\n' "$path" return 0 fi done return 1 } run_guest_checks() { echo "=== Red Bear OS Phase 1 Desktop Substrate Test ===" echo local failures=0 require_path() { local path="$1" local message="$2" if [ -e "$path" ]; then echo " PASS $message" else echo " FAIL $message" failures=$((failures + 1)) fi } require_command() { local cmd="$1" local message="$2" if which "$cmd" >/dev/null 2>&1; then echo " PASS $message" else echo " FAIL $message" failures=$((failures + 1)) fi } supported_drm_gpu_present() { if ! command -v lspci >/dev/null 2>&1; then return 1 fi lspci 2>/dev/null | grep -E '(VGA compatible controller|3D controller)' | grep -E '(8086:|1002:)' >/dev/null 2>&1 } echo "--- relibc POSIX API surface ---" require_path /usr/include/sys/signalfd.h "sys/signalfd.h header present" require_path /usr/include/sys/timerfd.h "sys/timerfd.h header present" require_path /usr/include/sys/eventfd.h "sys/eventfd.h header present" require_path /usr/lib/libwayland-client.so "libwayland-client.so present (relibc consumer)" require_command wayland-scanner "wayland-scanner is installed" echo echo "--- evdevd input path ---" require_command evdevd "evdevd command is installed" require_path /scheme/evdev "/scheme/evdev exists" if command -v redbear-phase3-input-check >/dev/null 2>&1; then echo " NOTE redbear-phase3-input-check available (run manually for full input validation)" fi echo echo "--- udev-shim device enumeration ---" require_command udev-shim "udev-shim command is installed" require_path /scheme/udev "/scheme/udev exists" local libinput_found=false for lib in /usr/lib/libinput.so /usr/lib/libinput.so.10 /usr/lib/libinput.so.*; do if [ -e "$lib" ]; then libinput_found=true break fi done if $libinput_found; then echo " PASS libinput shared library present" else echo " FAIL libinput shared library not found" failures=$((failures + 1)) fi echo echo "--- firmware-loader ---" require_path /scheme/firmware "/scheme/firmware exists" require_path /lib/firmware "/lib/firmware directory exists" echo echo "--- DRM/KMS ---" local drm_found=false if [ -e /usr/bin/redox-drm ] || which redox-drm >/dev/null 2>&1; then drm_found=true fi if $drm_found; then echo " PASS redox-drm is installed" else echo " FAIL redox-drm not found" failures=$((failures + 1)) fi if [ -e /scheme/drm ]; then echo " PASS /scheme/drm exists" elif supported_drm_gpu_present; then echo " FAIL /scheme/drm does not exist despite supported AMD/Intel GPU presence" failures=$((failures + 1)) else echo " NOTE /scheme/drm missing, but no supported AMD/Intel GPU detected for redox-drm in this runtime" fi if which redbear-drm-display-check >/dev/null 2>&1; then echo " NOTE redbear-drm-display-check available (run manually for bounded display validation)" fi echo echo "--- health check summary ---" if which redbear-info >/dev/null 2>&1; then local report report="$(redbear-info --json 2>/dev/null || true)" if [ -n "$report" ]; then local net_ok=false case "$report" in *'"networking"'*|*'"virtio_net_present"'*|*'"ip"'*) net_ok=true ;; esac if $net_ok; then echo " PASS networking state reported in redbear-info" else echo " FAIL networking state not reported in redbear-info" failures=$((failures + 1)) fi local drm_reported=false case "$report" in *'scheme drm'*|*'/scheme/drm'*|*'"drm"'*) drm_reported=true ;; esac if $drm_reported; then echo " PASS DRM scheme reported in redbear-info" else echo " FAIL DRM scheme not reported in redbear-info" failures=$((failures + 1)) fi local fw_reported=false case "$report" in *'scheme firmware'*|*'/scheme/firmware'*|*'"firmware"'*) fw_reported=true ;; esac if $fw_reported; then echo " PASS firmware scheme reported in redbear-info" else echo " FAIL firmware scheme not reported in redbear-info" failures=$((failures + 1)) fi else echo " FAIL redbear-info --json returned empty" failures=$((failures + 1)) fi else echo " FAIL redbear-info is not installed" failures=$((failures + 1)) fi echo echo "=== Phase 1 Desktop Substrate Test Complete ===" if [ "$failures" -gt 0 ]; then echo " $failures check(s) FAILED" return 1 fi echo " All checks PASSED" return 0 } run_qemu_checks() { local config="$1" local firmware firmware="$(find_uefi_firmware)" || { echo "ERROR: no usable x86_64 UEFI firmware found" >&2 exit 1 } local arch image extra iso boot_media boot_args arch="${ARCH:-$(uname -m)}" image="build/$arch/$config/harddrive.img" extra="build/$arch/$config/extra.img" iso="build/$arch/$config.iso" boot_media="" if [[ -f "$iso" ]]; then boot_media="iso" elif [[ -f "$image" ]]; then boot_media="harddrive" else echo "ERROR: no bootable image found ($iso or $image)" >&2 echo "Build it first with: ./local/scripts/build-redbear.sh $config" >&2 exit 1 fi if [[ ! -f "$extra" ]]; then truncate -s 1g "$extra" fi if [[ "$boot_media" == "iso" ]]; then boot_args=(-cdrom "$iso") else boot_args=(-drive file="$image",format=raw,if=none,id=drv0 -device nvme,drive=drv0,serial=NVME_SERIAL) fi pkill -f "qemu-system-x86_64.*$config" 2>/dev/null || true sleep 1 attempt=1 while true; do rc=0 python3 local/scripts/qemu-login-expect.py \ --timeout 300 \ --log "build/$arch/$config/phase1-desktop-check.log" \ --step "expect:login:" \ --step "send:root" \ --step "expect:assword:" \ --step "send:password" \ --step "expect:Type 'help' for available commands." \ --step "send:echo __READY__" \ --step "expect:__READY__" \ --step "send:test -e /usr/include/sys/signalfd.h && echo __SIGNAFD_OK__ || echo __SIGNAFD_FAIL__" \ --step "expect:__SIGNAFD_OK__" \ --step "send:test -e /usr/include/sys/timerfd.h && echo __TIMERFD_OK__ || echo __TIMERFD_FAIL__" \ --step "expect:__TIMERFD_OK__" \ --step "send:test -e /usr/include/sys/eventfd.h && echo __EVENTFD_OK__ || echo __EVENTFD_FAIL__" \ --step "expect:__EVENTFD_OK__" \ --step "send:test -e /usr/lib/libwayland-client.so && echo __WAYLAND_LIB_OK__ || echo __WAYLAND_LIB_FAIL__" \ --step "expect:__WAYLAND_LIB_OK__" \ --step "send:which evdevd >/scheme/null && echo __EVDVD_OK__ || echo __EVDVD_FAIL__" \ --step "expect:__EVDVD_OK__" \ --step "send:test -e /scheme/evdev && echo __EVDEV_SCH_OK__ || echo __EVDEV_SCH_FAIL__" \ --step "expect:__EVDEV_SCH_OK__" \ --step "send:which udev-shim >/scheme/null && echo __UDEV_OK__ || echo __UDEV_FAIL__" \ --step "expect:__UDEV_OK__" \ --step "send:test -e /scheme/udev && echo __UDEV_SCH_OK__ || echo __UDEV_SCH_FAIL__" \ --step "expect:__UDEV_SCH_OK__" \ --step "send:test -e /lib/firmware && echo __FW_DIR_OK__ || echo __FW_DIR_FAIL__" \ --step "expect:__FW_DIR_OK__" \ --step "send:test -e /usr/bin/redox-drm && echo __DRM_OK__ || echo __DRM_FAIL__" \ --step "expect:__DRM_OK__" \ --step "send:test -e /scheme/drm && echo __DRM_SCH_OK__ || echo __DRM_SCH_FAIL__" \ --step "expect:__DRM_SCH_" \ --step "send:if lspci 2>/dev/null | grep -E '(VGA compatible controller|3D controller)' | grep -E '(8086:|1002:)' >/dev/null 2>&1; then echo __DRM_GPU_EXPECTED__; else echo __DRM_GPU_SKIP__; fi" \ --step "expect:__DRM_GPU_" \ --step "send:redbear-info --json" \ --step 'expect:"virtio_net_present": true' \ --step "expect:scheme firmware is registered" \ --step "expect:scheme udev is registered" \ --step "send:echo __PHASE1_DONE__" \ --step "expect:__PHASE1_DONE__" \ --step "send:shutdown" \ --pass_marker "__PHASE1_DONE__" \ --fail_marker "__SIGNAFD_FAIL__" \ --fail_marker "__TIMERFD_FAIL__" \ --fail_marker "__EVENTFD_FAIL__" \ --fail_marker "__WAYLAND_LIB_FAIL__" \ --fail_marker "__EVDVD_FAIL__" \ --fail_marker "__EVDEV_SCH_FAIL__" \ --fail_marker "__UDEV_FAIL__" \ --fail_marker "__UDEV_SCH_FAIL__" \ --fail_marker "__FW_DIR_FAIL__" \ --fail_marker "__DRM_FAIL__" \ --fail_marker "__DRM_GPU_EXPECTED__" \ -- \ qemu-system-x86_64 -name "Red Bear OS x86_64" -device qemu-xhci -smp 4 -m 2048 -bios "$firmware" -chardev stdio,id=debug,signal=off,mux=on -serial chardev:debug -mon chardev:debug -machine q35 -device ich9-intel-hda -device hda-output -device virtio-net,netdev=net0 -netdev user,id=net0 -object filter-dump,id=f1,netdev=net0,file="build/$arch/$config/network.pcap" -display none -vga none "${boot_args[@]}" -drive file="$extra",format=raw,if=none,id=drv1 -device nvme,drive=drv1,serial=NVME_EXTRA -enable-kvm -cpu host || rc=$? if [[ $rc -eq 0 ]]; then break fi if [[ ( $rc -eq 3 || $rc -eq 137 ) && $attempt -lt 5 ]]; then attempt=$((attempt + 1)) echo "QEMU exited before completing the check; retrying (attempt $attempt/5)" sleep 2 continue fi exit "$rc" done pkill -f "qemu-system-x86_64.*$image" 2>/dev/null || true echo "Phase 1 desktop substrate runtime validation completed via guest runtime check" } usage() { cat <<'USAGE' Usage: ./local/scripts/test-phase1-desktop-substrate.sh --guest ./local/scripts/test-phase1-desktop-substrate.sh --qemu [redbear-full] USAGE } case "${1:-}" in --guest) run_guest_checks ;; --qemu) run_qemu_checks "${2:-redbear-full}" ;; *) usage exit 1 ;; esac