This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

spindle/engines/microvm: make cgroups tests compile on non-linux

Signed-off-by: dawn <dawn@tangled.org>

author
dawn
date (Aug 3, 2026, 11:20 AM +0300) commit 09db9a7c parent 25d3c23e change-id srpwomrq
+72 -15
+2
spindle/engines/microvm/cgroup.go
··· 1 + //go:build linux 2 + 1 3 package microvm 2 4 3 5 import (
+2
spindle/engines/microvm/cgroup_oom_test.go
··· 1 + //go:build linux 2 + 1 3 package microvm 2 4 3 5 import (
+46
spindle/engines/microvm/cgroup_other.go
··· 1 + //go:build !linux 2 + 3 + package microvm 4 + 5 + import ( 6 + "fmt" 7 + "log/slog" 8 + ) 9 + 10 + type CgroupLimits struct { 11 + Enabled bool 12 + Parent *CgroupParent 13 + Name string 14 + MemoryMaxMiB int64 15 + SwapMaxMiB *int64 16 + PidsMax int64 17 + CPUQuotaPercent int64 18 + IOWeight uint64 19 + } 20 + 21 + type CgroupParent struct{} 22 + 23 + type CgroupHandle struct{} 24 + 25 + func initCgroupParent(string, int64, *slog.Logger) (*CgroupParent, error) { 26 + return nil, fmt.Errorf("microVM cgroups are only supported on Linux") 27 + } 28 + 29 + func prepareCgroup(limits CgroupLimits, _ *slog.Logger) (*CgroupHandle, error) { 30 + if !limits.Enabled { 31 + return nil, nil 32 + } 33 + return nil, fmt.Errorf("microVM cgroups are only supported on Linux") 34 + } 35 + 36 + func (*CgroupHandle) AddProcess(int, *slog.Logger) error { 37 + return nil 38 + } 39 + 40 + func (*CgroupHandle) Close() error { 41 + return nil 42 + } 43 + 44 + func (*CgroupHandle) OOMKilled() bool { 45 + return false 46 + }
+20
spindle/engines/microvm/cgroup_resources_test.go
··· 1 + //go:build linux 2 + 3 + package microvm 4 + 5 + import "testing" 6 + 7 + func TestCgroupResourcesCPUQuota(t *testing.T) { 8 + r := cgroupResources(CgroupLimits{CPUQuotaPercent: 200}) 9 + if r.CPU == nil { 10 + t.Fatal("cpu quota should produce a cpu controller config") 11 + } 12 + if got := string(r.CPU.Max); got != "200000 100000" { 13 + t.Errorf("cpu.max = %q, want %q", got, "200000 100000") 14 + } 15 + 16 + r = cgroupResources(CgroupLimits{}) 17 + if r.CPU != nil { 18 + t.Errorf("no quota should leave cpu unlimited, got %v", r.CPU) 19 + } 20 + }
+2
spindle/engines/microvm/cgroup_test.go
··· 1 + //go:build linux 2 + 1 3 package microvm 2 4 3 5 import (
-15
spindle/engines/microvm/cid_test.go
··· 28 28 t.Errorf("key not deterministic: %q vs %q", a, again) 29 29 } 30 30 } 31 - 32 - func TestCgroupResourcesCPUQuota(t *testing.T) { 33 - r := cgroupResources(CgroupLimits{CPUQuotaPercent: 200}) 34 - if r.CPU == nil { 35 - t.Fatal("cpu quota should produce a cpu controller config") 36 - } 37 - if got := string(r.CPU.Max); got != "200000 100000" { 38 - t.Errorf("cpu.max = %q, want %q", got, "200000 100000") 39 - } 40 - 41 - r = cgroupResources(CgroupLimits{}) 42 - if r.CPU != nil { 43 - t.Errorf("no quota should leave cpu unlimited, got %v", r.CPU) 44 - } 45 - }