...

Source file src/github.com/containerd/cgroups/v2/testutils_test.go

Documentation: github.com/containerd/cgroups/v2

     1  /*
     2     Copyright The containerd Authors.
     3  
     4     Licensed under the Apache License, Version 2.0 (the "License");
     5     you may not use this file except in compliance with the License.
     6     You may obtain a copy of the License at
     7  
     8         http://www.apache.org/licenses/LICENSE-2.0
     9  
    10     Unless required by applicable law or agreed to in writing, software
    11     distributed under the License is distributed on an "AS IS" BASIS,
    12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13     See the License for the specific language governing permissions and
    14     limitations under the License.
    15  */
    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