github.com/opencontainers/runc@v1.2.0-rc.1.0.20240520010911-492dc558cdd6/libcontainer/cgroups/fs/net_cls_test.go (about) 1 package fs 2 3 import ( 4 "strconv" 5 "testing" 6 7 "github.com/opencontainers/runc/libcontainer/cgroups/fscommon" 8 "github.com/opencontainers/runc/libcontainer/configs" 9 ) 10 11 const ( 12 classidBefore = 0x100002 13 classidAfter = 0x100001 14 ) 15 16 func TestNetClsSetClassid(t *testing.T) { 17 path := tempDir(t, "net_cls") 18 19 writeFileContents(t, path, map[string]string{ 20 "net_cls.classid": strconv.FormatUint(classidBefore, 10), 21 }) 22 23 r := &configs.Resources{ 24 NetClsClassid: classidAfter, 25 } 26 netcls := &NetClsGroup{} 27 if err := netcls.Set(path, r); err != nil { 28 t.Fatal(err) 29 } 30 31 // As we are in mock environment, we can't get correct value of classid from 32 // net_cls.classid. 33 // So. we just judge if we successfully write classid into file 34 value, err := fscommon.GetCgroupParamUint(path, "net_cls.classid") 35 if err != nil { 36 t.Fatal(err) 37 } 38 if value != classidAfter { 39 t.Fatal("Got the wrong value, set net_cls.classid failed.") 40 } 41 }