AtlatestRepositorysigil-ui
1
#!/usr/bin/env sigil2
;;; Native protocol fixture and Sigil tests, with private sockets and no renderer.3
;;; Requires a C compiler (CC), wayland-scanner and Wayland server development files.4
;;; WAYLAND_CFLAGS/WAYLAND_LIBS can override their include/link flags.5
;;; SIGIL_UI_TEST_ROOT selects the persistent evidence directory.6
(import (sigil shell prelude))7
(requires (tools env mktemp chmod wayland-scanner))8
(define root (realpath (path (script-dir) "..")))9
(define base (or (getenv "SIGIL_UI_TEST_ROOT") (path (getenv "HOME") "tmp/sigil-ui-configure")))10
(ensure-directory base)11
(define work (out mktemp -d ,(path base "configure.XXXXXX")))12
($ chmod 700 ,work)13
(setenv! "TMPDIR" work)14
(define compiler (or (getenv "CC") "cc"))15
(define (flags name) (filter (lambda (s) (not (string-empty? s))) (split (or (getenv name) "") " ")))16
(define xml (path root "native/wayland/protocols/xdg-shell.xml"))17
(define server (path work "configure-server"))18
($ wayland-scanner server-header ,xml ,(path work "configure-xdg-server.h"))19
($ wayland-scanner private-code ,xml ,(path work "configure-xdg-protocol.c"))20
($ ,compiler -std=c11 -D_POSIX_C_SOURCE=200809L -Wall -Wextra -Werror -Wno-unused-parameter21
,@(flags "WAYLAND_CFLAGS") ,(str "-I" work)22
,(path root "test/wayland/configure-server.c") ,(path work "configure-xdg-protocol.c")23
-o ,server ,@(if (getenv "WAYLAND_LIBS") (flags "WAYLAND_LIBS") (list "-lwayland-server"))24
timeout: 60)25
(println "Configure fixture: ~a" work)27
;;; Compile the real wait body against deterministic I/O and clock faults.28
(define source (read-text (path root "native/wayland.c")))29
(define parts (split source "static int wait_initial_configure"))30
(unless (= (length parts) 2) (error "Expected exactly one configure wait"))31
(define wait-body (str "static int wait_initial_configure"32
(car (split (cadr parts) "\n/* (%wl-open"))))33
(define reset-body34
(string-replace35
(string-replace wait-body "int64_t deadline = now_ms() + timeout_ms;" "int64_t deadline;")36
"while ((!w->configured || (w->decoration && !w->decoration_mode)) && !w->closed) {"37
"while ((!w->configured || (w->decoration && !w->decoration_mode)) && !w->closed) {\n deadline = now_ms() + timeout_ms;"))38
(when (equal? wait-body reset-body) (error "Deadline mutation did not apply"))39
(define (build-wait-test name body)40
(define directory (path work name))41
(ensure-directory directory)42
(write-text (path directory "configure-wait-under-test.h") body)43
(define binary (path directory "configure-wait-test"))44
($ ,compiler -std=c11 -Wall -Wextra -Werror -Wno-unused-parameter45
,(str "-I" directory) ,(path root "test/wayland/configure-wait-test.c")46
-o ,binary timeout: 60)47
binary)48
(define wait-test (build-wait-test "actual" wait-body))49
(define wait-log (path work "wait.log"))50
($ ,wait-test out: ,wait-log err: 'merge timeout: 20)51
(println "~a" (read-text wait-log))52
(define mutant (build-wait-test "reset-mutant" reset-body))53
(define mutant-log (path work "reset-mutant.log"))54
(define mutation ($? ,mutant out: ,mutant-log err: 'merge timeout: 20))55
(define mutant-output (read-text mutant-log))56
(println "~a" mutant-output)57
(unless (and (not (ok? mutation))58
(contains? mutant-output "FAIL: traffic total deadline")59
(contains? mutant-output "FAIL: interrupted total deadline"))60
(error "Reset-per-loop mutant was not rejected by both deadline cases"))61
(println "PASS: reset-per-loop mutant rejected")63
(define test-log (path work "test.log"))64
(println "Test output: ~a" test-log)65
(define result66
($? env ,(str "SIGIL_UI_CONFIGURE_SERVER=" server) ,(str "SIGIL_UI_CONFIGURE_ROOT=" work)67
sigil test --backend bytecode test/wayland/configure.sgl test/wayland/services.sgl cwd: ,root68
out: ,test-log err: 'merge timeout: 600))69
(println "~a" (read-text test-log))70
(unless (ok? result) (error (format-outcome result)))