aboutsummaryrefslogtreecommitdiffhomepage
path: root/container/syscall_test.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-03-11 20:03:08 +0900
committerOphestra <cat@gensokyo.uk>2026-03-11 20:03:08 +0900
commitfd515badffc159b62c5140b8340164ccd29e41f5 (patch)
treee4bfb24189960c360bd72e964d3f0acb3b28c4b7 /container/syscall_test.go
parent330a344845aa8653772a9be6c085f4fdb602a028 (diff)
container: move scheduler policy constants to std
This avoids depending on cgo. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container/syscall_test.go')
-rw-r--r--container/syscall_test.go100
1 files changed, 0 insertions, 100 deletions
diff --git a/container/syscall_test.go b/container/syscall_test.go
deleted file mode 100644
index 337d6450..00000000
--- a/container/syscall_test.go
+++ /dev/null
@@ -1,100 +0,0 @@
-package container_test
-
-import (
- "encoding/json"
- "errors"
- "math"
- "reflect"
- "syscall"
- "testing"
-
- "hakurei.app/container"
- "hakurei.app/container/std"
-)
-
-func TestSchedPolicyJSON(t *testing.T) {
- t.Parallel()
-
- testCases := []struct {
- policy container.SchedPolicy
- want string
- encodeErr error
- decodeErr error
- }{
- {container.SCHED_NORMAL, `""`, nil, nil},
- {container.SCHED_FIFO, `"fifo"`, nil, nil},
- {container.SCHED_RR, `"rr"`, nil, nil},
- {container.SCHED_BATCH, `"batch"`, nil, nil},
- {4, `"invalid policy 4"`, syscall.EINVAL, container.InvalidSchedPolicyError("invalid policy 4")},
- {container.SCHED_IDLE, `"idle"`, nil, nil},
- {container.SCHED_DEADLINE, `"deadline"`, nil, nil},
- {container.SCHED_EXT, `"ext"`, nil, nil},
- {math.MaxInt, `"iso"`, syscall.EINVAL, container.InvalidSchedPolicyError("iso")},
- }
- for _, tc := range testCases {
- name := tc.policy.String()
- if tc.policy == container.SCHED_NORMAL {
- name = "normal"
- }
-
- t.Run(name, func(t *testing.T) {
- t.Parallel()
-
- got, err := json.Marshal(tc.policy)
- if !errors.Is(err, tc.encodeErr) {
- t.Fatalf("Marshal: error = %v, want %v", err, tc.encodeErr)
- }
- if err == nil && string(got) != tc.want {
- t.Fatalf("Marshal: %s, want %s", string(got), tc.want)
- }
-
- var v container.SchedPolicy
- if err = json.Unmarshal([]byte(tc.want), &v); !reflect.DeepEqual(err, tc.decodeErr) {
- t.Fatalf("Unmarshal: error = %v, want %v", err, tc.decodeErr)
- }
- if err == nil && v != tc.policy {
- t.Fatalf("Unmarshal: %d, want %d", v, tc.policy)
- }
- })
- }
-}
-
-func TestSchedPolicyMinMax(t *testing.T) {
- t.Parallel()
-
- testCases := []struct {
- policy container.SchedPolicy
- min, max std.Int
- err error
- }{
- {container.SCHED_NORMAL, 0, 0, nil},
- {container.SCHED_FIFO, 1, 99, nil},
- {container.SCHED_RR, 1, 99, nil},
- {container.SCHED_BATCH, 0, 0, nil},
- {4, -1, -1, syscall.EINVAL},
- {container.SCHED_IDLE, 0, 0, nil},
- {container.SCHED_DEADLINE, 0, 0, nil},
- {container.SCHED_EXT, 0, 0, nil},
- }
- for _, tc := range testCases {
- name := tc.policy.String()
- if tc.policy == container.SCHED_NORMAL {
- name = "normal"
- }
-
- t.Run(name, func(t *testing.T) {
- t.Parallel()
-
- if priority, err := tc.policy.GetPriorityMax(); !reflect.DeepEqual(err, tc.err) {
- t.Fatalf("GetPriorityMax: error = %v, want %v", err, tc.err)
- } else if priority != tc.max {
- t.Fatalf("GetPriorityMax: %d, want %d", priority, tc.max)
- }
- if priority, err := tc.policy.GetPriorityMin(); !reflect.DeepEqual(err, tc.err) {
- t.Fatalf("GetPriorityMin: error = %v, want %v", err, tc.err)
- } else if priority != tc.min {
- t.Fatalf("GetPriorityMin: %d, want %d", priority, tc.min)
- }
- })
- }
-}