mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 14:13:58 +08:00
8f1b4d4a6f
This is a better place as cgroups itself is using these.
Should help with moving more stuff common in between fs and fs2 to
fscommon.
Looks big, but this is just moving the code around:
fscommon/{fscommon,open}.go -> cgroups/file.go
fscommon/fscommon_test.go -> cgroups/file_test.go
and fixes for TestMode moved to a different package.
There's no functional change.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
43 lines
972 B
Go
43 lines
972 B
Go
// +build linux
|
|
|
|
package cgroups
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strconv"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestWriteCgroupFileHandlesInterrupt(t *testing.T) {
|
|
const (
|
|
memoryCgroupMount = "/sys/fs/cgroup/memory"
|
|
memoryLimit = "memory.limit_in_bytes"
|
|
)
|
|
if _, err := os.Stat(memoryCgroupMount); err != nil {
|
|
// most probably cgroupv2
|
|
t.Skip(err)
|
|
}
|
|
|
|
cgroupName := fmt.Sprintf("test-eint-%d", time.Now().Nanosecond())
|
|
cgroupPath := filepath.Join(memoryCgroupMount, cgroupName)
|
|
if err := os.MkdirAll(cgroupPath, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer os.RemoveAll(cgroupPath)
|
|
|
|
if _, err := os.Stat(filepath.Join(cgroupPath, memoryLimit)); err != nil {
|
|
// either cgroupv2, or memory controller is not available
|
|
t.Skip(err)
|
|
}
|
|
|
|
for i := 0; i < 100000; i++ {
|
|
limit := 1024*1024 + i
|
|
if err := WriteFile(cgroupPath, memoryLimit, strconv.Itoa(limit)); err != nil {
|
|
t.Fatalf("Failed to write %d on attempt %d: %+v", limit, i, err)
|
|
}
|
|
}
|
|
}
|