AtlatestRepositorysigil-ui

sigil-ui / tree / scriptscheck-dmabuf-import.sgl

1#!/usr/bin/env sigil
2(import (sigil shell prelude))
3(define root (realpath (path (script-dir) "..")))
4(define headers (arg 1))
5(define archive (arg 2))
6(define evidence (arg 3))
7(define compiler (or (getenv "CC") "cc"))
8(unless (and (file? (path headers "sigil/sigil.h")) (file? archive))
9 (error "Expected matching Sigil runtime headers and static archive"))
10(ensure-directory evidence)
11(define cases '("created" "failed" "delayed" "cancel-pending" "cancel-ready"
12 "unref-pending" "unref-ready" "close-pending" "close-ready" "child-close"
13 "factory-pending" "factory-ready" "disconnect" "four-planes" "invalid"
14 "limit" "late-created" "missing" "legacy" "close-unflushed" "large-span"))
15(each variant '("plain" "sanitized")
16 (define executable (path evidence (str "import-" variant)))
17 (define flags
18 (append '("-std=c11" "-D_GNU_SOURCE" "-O1" "-g" "-Wall" "-Wextra" "-Werror" "-Wno-unused-parameter")
19 (if (equal? variant "sanitized") '("-fsanitize=address,undefined" "-fno-omit-frame-pointer") '())
20 (list (str "-I" headers) (str "-I" (path root "native"))
21 (str "-I" (path root "native/wayland")) (str "-I" (path root "native/wayland/include")))))
22 (define compiled ($? ,compiler ,@flags ,(path root "test/wayland/dmabuf-import-peer.c")
23 ,archive -lm -ldl -lpthread -o ,executable
24 out: ,(path evidence (str variant "-compile.log")) err: 'merge timeout: 40))
25 (unless (ok? compiled)
26 (display (read-text (path evidence (str variant "-compile.log"))))
27 (error "Import fixture did not compile" variant))
28 (each case cases
29 (define log (path evidence (str variant "-" case ".log")))
30 (define result ($? ,executable ,case
31 env: '(("ASAN_OPTIONS" . "detect_leaks=1:abort_on_error=1")
32 ("UBSAN_OPTIONS" . "halt_on_error=1:print_stacktrace=1"))
33 out: ,log err: 'merge timeout: 10))
34 (display (read-text log))
35 (unless (and (ok? result) (contains? (read-text log) (str "PASS: import wire " case ",")))
36 (error "Import wire check failed" variant case (format-outcome result)))))
37(println "PASS: 21 import wire cases in plain and ASan/UBSan builds")