all: optionally forbid degrading in tests
All checks were successful
Test / Create distribution (push) Successful in 1m28s
Test / Sandbox (push) Successful in 3m27s
Test / Hakurei (push) Successful in 4m41s
Test / ShareFS (push) Successful in 4m47s
Test / Sandbox (race detector) (push) Successful in 5m57s
Test / Hakurei (race detector) (push) Successful in 7m3s
Test / Flake checks (push) Successful in 1m29s
All checks were successful
Test / Create distribution (push) Successful in 1m28s
Test / Sandbox (push) Successful in 3m27s
Test / Hakurei (push) Successful in 4m41s
Test / ShareFS (push) Successful in 4m47s
Test / Sandbox (race detector) (push) Successful in 5m57s
Test / Hakurei (race detector) (push) Successful in 7m3s
Test / Flake checks (push) Successful in 1m29s
This enables transparently degradable tests to be forced on in environments known to support them. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -25,6 +25,7 @@ import (
|
|||||||
"hakurei.app/ext"
|
"hakurei.app/ext"
|
||||||
"hakurei.app/fhs"
|
"hakurei.app/fhs"
|
||||||
"hakurei.app/hst"
|
"hakurei.app/hst"
|
||||||
|
"hakurei.app/internal/info"
|
||||||
"hakurei.app/ldd"
|
"hakurei.app/ldd"
|
||||||
"hakurei.app/message"
|
"hakurei.app/message"
|
||||||
"hakurei.app/vfs"
|
"hakurei.app/vfs"
|
||||||
@@ -453,7 +454,7 @@ func TestContainer(t *testing.T) {
|
|||||||
c.SeccompDisable = !tc.filter
|
c.SeccompDisable = !tc.filter
|
||||||
c.RetainSession = tc.session
|
c.RetainSession = tc.session
|
||||||
c.HostNet = tc.net
|
c.HostNet = tc.net
|
||||||
if !c.HostNet {
|
if info.CanDegrade {
|
||||||
if _, err := container.LandlockGetABI(); err != nil {
|
if _, err := container.LandlockGetABI(); err != nil {
|
||||||
if !errors.Is(err, syscall.ENOSYS) {
|
if !errors.Is(err, syscall.ENOSYS) {
|
||||||
t.Fatalf("LandlockGetABI: error = %v", err)
|
t.Fatalf("LandlockGetABI: error = %v", err)
|
||||||
|
|||||||
@@ -137,7 +137,6 @@
|
|||||||
|
|
||||||
CC="musl-clang -O3 -Werror -Qunused-arguments" \
|
CC="musl-clang -O3 -Werror -Qunused-arguments" \
|
||||||
GOCACHE="$(mktemp -d)" \
|
GOCACHE="$(mktemp -d)" \
|
||||||
HAKUREI_TEST_SKIP_ACL=1 \
|
|
||||||
PATH="${pkgs.pkgsStatic.musl.bin}/bin:$PATH" \
|
PATH="${pkgs.pkgsStatic.musl.bin}/bin:$PATH" \
|
||||||
DESTDIR="$out" \
|
DESTDIR="$out" \
|
||||||
HAKUREI_VERSION="v${hakurei.version}" \
|
HAKUREI_VERSION="v${hakurei.version}" \
|
||||||
|
|||||||
@@ -11,9 +11,11 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"hakurei.app/internal/acl"
|
"hakurei.app/internal/acl"
|
||||||
|
"hakurei.app/internal/info"
|
||||||
)
|
)
|
||||||
|
|
||||||
const testFileName = "acl.test"
|
const testFileName = "acl.test"
|
||||||
@@ -24,8 +26,14 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestUpdate(t *testing.T) {
|
func TestUpdate(t *testing.T) {
|
||||||
if os.Getenv("HAKUREI_TEST_SKIP_ACL") == "1" {
|
if info.CanDegrade {
|
||||||
t.Skip("acl test skipped")
|
name := filepath.Join(t.TempDir(), "check-degrade")
|
||||||
|
if err := os.WriteFile(name, nil, 0); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := acl.Update(name, os.Geteuid()); errors.Is(err, syscall.ENOTSUP) {
|
||||||
|
t.Skip(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
testFilePath := filepath.Join(t.TempDir(), testFileName)
|
testFilePath := filepath.Join(t.TempDir(), testFileName)
|
||||||
|
|||||||
7
internal/info/optional_skip.go
Normal file
7
internal/info/optional_skip.go
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
//go:build !noskip
|
||||||
|
|
||||||
|
package info
|
||||||
|
|
||||||
|
// CanDegrade is whether tests are allowed to transparently degrade or skip due
|
||||||
|
// to required system features being denied or unavailable.
|
||||||
|
const CanDegrade = true
|
||||||
5
internal/info/optional_strict.go
Normal file
5
internal/info/optional_strict.go
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
//go:build noskip
|
||||||
|
|
||||||
|
package info
|
||||||
|
|
||||||
|
const CanDegrade = false
|
||||||
@@ -24,6 +24,7 @@ import (
|
|||||||
"hakurei.app/check"
|
"hakurei.app/check"
|
||||||
"hakurei.app/container"
|
"hakurei.app/container"
|
||||||
"hakurei.app/fhs"
|
"hakurei.app/fhs"
|
||||||
|
"hakurei.app/internal/info"
|
||||||
"hakurei.app/internal/pkg"
|
"hakurei.app/internal/pkg"
|
||||||
"hakurei.app/internal/stub"
|
"hakurei.app/internal/stub"
|
||||||
"hakurei.app/message"
|
"hakurei.app/message"
|
||||||
@@ -290,6 +291,8 @@ func checkWithCache(t *testing.T, testCases []cacheTestCase) {
|
|||||||
msg.SwapVerbose(testing.Verbose())
|
msg.SwapVerbose(testing.Verbose())
|
||||||
|
|
||||||
flags := tc.flags
|
flags := tc.flags
|
||||||
|
|
||||||
|
if info.CanDegrade {
|
||||||
if _, err := container.LandlockGetABI(); err != nil {
|
if _, err := container.LandlockGetABI(); err != nil {
|
||||||
if !errors.Is(err, syscall.ENOSYS) {
|
if !errors.Is(err, syscall.ENOSYS) {
|
||||||
t.Fatalf("LandlockGetABI: error = %v", err)
|
t.Fatalf("LandlockGetABI: error = %v", err)
|
||||||
@@ -297,6 +300,7 @@ func checkWithCache(t *testing.T, testCases []cacheTestCase) {
|
|||||||
flags |= pkg.CHostAbstract
|
flags |= pkg.CHostAbstract
|
||||||
t.Log("Landlock LSM is unavailable, setting CHostAbstract")
|
t.Log("Landlock LSM is unavailable, setting CHostAbstract")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var scrubFunc func() error // scrub after hashing
|
var scrubFunc func() error // scrub after hashing
|
||||||
if c, err := pkg.Open(t.Context(), msg, flags, 1<<4, base); err != nil {
|
if c, err := pkg.Open(t.Context(), msg, flags, 1<<4, base); err != nil {
|
||||||
|
|||||||
@@ -82,9 +82,6 @@ buildGo126Module rec {
|
|||||||
env = {
|
env = {
|
||||||
# use clang instead of gcc
|
# use clang instead of gcc
|
||||||
CC = "clang -O3 -Werror";
|
CC = "clang -O3 -Werror";
|
||||||
|
|
||||||
# nix build environment does not allow acls
|
|
||||||
HAKUREI_TEST_SKIP_ACL = 1;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ testers.nixosTest {
|
|||||||
|
|
||||||
cd ${self.packages.${system}.hakurei.src}
|
cd ${self.packages.${system}.hakurei.src}
|
||||||
${fhs}/bin/hakurei-fhs -c \
|
${fhs}/bin/hakurei-fhs -c \
|
||||||
'CC="clang -O3 -Werror" go test ${if withRace then "-race" else "-count 16"} ./...' \
|
'CC="clang -O3 -Werror" go test --tags=noskip ${if withRace then "-race" else "-count 16"} ./...' \
|
||||||
&> /tmp/hakurei-test.log && \
|
&> /tmp/hakurei-test.log && \
|
||||||
touch /tmp/hakurei-test-ok
|
touch /tmp/hakurei-test-ok
|
||||||
touch /tmp/hakurei-test-done
|
touch /tmp/hakurei-test-done
|
||||||
|
|||||||
Reference in New Issue
Block a user