...
1
16
17 package v2
18
19 import (
20 "os"
21 "path/filepath"
22 "strings"
23 "syscall"
24 "testing"
25
26 "github.com/stretchr/testify/assert"
27 "golang.org/x/sys/unix"
28 )
29
30 func checkCgroupMode(t *testing.T) {
31 var st syscall.Statfs_t
32 if err := syscall.Statfs(defaultCgroup2Path, &st); err != nil {
33 t.Fatal("cannot statfs cgroup root")
34 }
35 isUnified := st.Type == unix.CGROUP2_SUPER_MAGIC
36 if !isUnified {
37 t.Skip("System running in hybrid or cgroupv1 mode")
38 }
39 }
40
41 func checkCgroupControllerSupported(t *testing.T, controller string) {
42 b, err := os.ReadFile(filepath.Join(defaultCgroup2Path, controllersFile))
43 if err != nil || !strings.Contains(string(b), controller) {
44 t.Skipf("Controller: %s is not supported on that system", controller)
45 }
46 }
47
48 func checkFileContent(t *testing.T, path, filename, value string) {
49 out, err := os.ReadFile(filepath.Join(path, filename))
50 if err != nil {
51 t.Fatalf("failed to read %s file", filename)
52 }
53 assert.Equal(t, value, strings.TrimSpace(string(out)))
54 }
55
View as plain text