Skip to content

Commit 3a0d26d

Browse files
committed
Don't run landlock tests when landlock isn't available
1 parent 27d2924 commit 3a0d26d

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

β€Žrats/core/30_sandbox_test.rugoβ€Ž

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,39 @@ use "eval"
44
use "os"
55
use "str"
66

7+
def detect_landlock()
8+
uname = test.run("uname -s")
9+
if uname["status"] != 0 || uname["output"] != "Linux"
10+
return "non-linux"
11+
end
12+
# Probe: run a sandboxed program that should be denied access to /etc.
13+
# If landlock is actually enforced, os.read_file fails and "LANDLOCK_DENIED"
14+
# is printed. If the kernel lacks landlock support, BestEffort() silently
15+
# degrades and the read succeeds.
16+
probe = <<~RUGO
17+
sandbox rox: ["/usr"]
18+
import "os"
19+
data = try os.read_file("/etc/os-release") or e
20+
"LANDLOCK_DENIED"
21+
end
22+
puts(data)
23+
RUGO
24+
r = eval.run(probe)
25+
if str.contains(r["output"], "LANDLOCK_DENIED")
26+
return "available"
27+
end
28+
return "unsupported-kernel"
29+
end
30+
31+
LANDLOCK_STATE = detect_landlock()
32+
733
def skip_if_no_landlock()
8-
result = test.run("uname -s")
9-
if result["status"] != 0 || result["output"] != "Linux"
34+
if LANDLOCK_STATE == "non-linux"
1035
test.skip("Landlock requires Linux")
1136
end
37+
if LANDLOCK_STATE != "available"
38+
test.skip("Landlock not enforced on this kernel")
39+
end
1240
end
1341

1442
# ── Codegen / emit tests ────────────────────────────────────────────

0 commit comments

Comments
Β (0)