github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/mergeCode/runc/libcontainer/cgroups/fs/net_cls_test.go (about) 1 // +build linux 2 3 package fs 4 5 import ( 6 "strconv" 7 "testing" 8 ) 9 10 const ( 11 classidBefore = 0x100002 12 classidAfter = 0x100001 13 ) 14 15 func TestNetClsSetClassid(t *testing.T) { 16 helper := NewCgroupTestUtil("net_cls", t) 17 defer helper.cleanup() 18 19 helper.writeFileContents(map[string]string{ 20 "net_cls.classid": strconv.FormatUint(classidBefore, 10), 21 }) 22 23 helper.CgroupData.config.Resources.NetClsClassid = classidAfter 24 netcls := &NetClsGroup{} 25 if err := netcls.Set(helper.CgroupPath, helper.CgroupData.config); err != nil { 26 t.Fatal(err) 27 } 28 29 // As we are in mock environment, we can't get correct value of classid from 30 // net_cls.classid. 31 // So. we just judge if we successfully write classid into file 32 value, err := getCgroupParamUint(helper.CgroupPath, "net_cls.classid") 33 if err != nil { 34 t.Fatalf("Failed to parse net_cls.classid - %s", err) 35 } 36 if value != classidAfter { 37 t.Fatal("Got the wrong value, set net_cls.classid failed.") 38 } 39 }