AtlatestRepositorysigil-ui
1
(import (sigil test) (sigil process) (sigil io) (sigil fs)2
(sigil path) (sigil string) (sigil time) (sigil ui wayland))3
(define server (or (getenv "SIGIL_UI_CONFIGURE_SERVER") (error "Run scripts/test-wayland-configure.sgl")))4
(define folder (or (getenv "SIGIL_UI_CONFIGURE_ROOT") (error "Private fixture root is required")))5
(define sequence 0)6
(define (now) (/ (current-jiffy) (jiffies-per-second)))7
(define (with-server mode thunk)8
(set! sequence (+ sequence 1))9
(let* ((work (path-join folder (string-append "case-" (number->string sequence))))10
(socket (path-join work "configure-test"))11
(log (path-join work "server.log"))12
(child #f))13
(make-directory work)14
(process-output->string "chmod" "700" work)15
(dynamic-wind16
(lambda () #f)17
(lambda ()18
(set! child (process-spawn "env" "-u" "WAYLAND_DISPLAY" "-u" "DISPLAY"19
(string-append "XDG_RUNTIME_DIR=" work) server mode20
die-with-parent: #t err: log))21
(unless (equal? "READY" (read-line (process-stdout child)))22
(error "Fake compositor did not become ready" log))23
(thunk socket))24
(lambda ()25
(when child26
(when (process-alive? child) (process-kill! child))27
(process-wait child))28
(println "Fixture evidence: ~a" log)))))29
(define (error-text thunk)30
(guard (e (#t (if (error-object? e) (error-object-message e) "?")))31
(thunk) #f))32
(define (assert-cleaned socket)33
(let ((receipt (path-join (path-dirname socket) "cleanup"))34
(deadline (+ (now) 2)))35
(let wait ()36
(cond ((file-exists? receipt)37
(assert-equal "0" (string-trim (read-file-string receipt))))38
((>= (now) deadline) (error "Compositor did not observe resource teardown"))39
(else (sleep 0.01) (wait))))))40
(test-group "asynchronous initial configure"41
(test "a configure delayed beyond four immediate roundtrips succeeds"42
(with-server "delay"43
(lambda (socket)44
(let* ((start (now))45
(surface (open-wayland-surface display: socket width: 320 height: 240)))46
(dynamic-wind (lambda () #f)47
(lambda ()48
(assert-equal 640 (wayland-surface-width surface))49
(assert-equal 480 (wayland-surface-height surface))50
(assert-true (>= (- (now) start) 0.45)))51
(lambda () (wayland-surface-close! surface)))))))52
(test "a compositor that never configures hits the deadline"53
(with-server "never"54
(lambda (socket)55
(let* ((start (now))56
(message (error-text (lambda () (open-wayland-surface display: socket)))))57
(assert-true (string-contains? message "did not configure the surface"))58
(assert-true (>= (- (now) start) 4.8))59
(assert-true (< (- (now) start) 8))))))60
(test "a close before configure retains its distinct error"61
(with-server "close"62
(lambda (socket)63
(assert-true (string-contains?64
(error-text (lambda () (open-wayland-surface display: socket)))65
"closed the surface before showing it")))))66
(test "a disconnected compositor retains its connection error"67
(with-server "disconnect"68
(lambda (socket)69
(assert-true (string-contains?70
(error-text (lambda () (open-wayland-surface display: socket)))71
"compositor connection failed")))))72
(test "close then configure in one batch tears down with an early-close error"73
(with-server "close-then-configure"74
(lambda (socket)75
(let ((unexpected #f))76
(let ((message (error-text (lambda ()77
(set! unexpected (open-wayland-surface display: socket))))))78
(when unexpected (wayland-surface-close! unexpected))79
(assert-true (and (string? message)80
(string-contains? message "closed the surface before showing it")))81
(assert-cleaned socket))))))82
(test "periodic ping traffic cannot restart the total deadline"83
(with-server "traffic"84
(lambda (socket)85
(let ((start (now)) (unexpected #f))86
(let ((message (error-text (lambda ()87
(set! unexpected (open-wayland-surface display: socket))))))88
(when unexpected (wayland-surface-close! unexpected))89
(assert-true (and (string? message)90
(string-contains? message "did not configure the surface")))91
(assert-true (>= (- (now) start) 4.8))92
(assert-true (< (- (now) start) 6.5))93
(assert-cleaned socket)))))))