github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/mergeCode/runc/libcontainer/cgroups/fs/net_prio_test.go (about)

     1  // +build linux
     2  
     3  package fs
     4  
     5  import (
     6  	"strings"
     7  	"testing"
     8  
     9  	"github.com/opencontainers/runc/libcontainer/configs"
    10  )
    11  
    12  var (
    13  	prioMap = []*configs.IfPrioMap{
    14  		{
    15  			Interface: "test",
    16  			Priority:  5,
    17  		},
    18  	}
    19  )
    20  
    21  func TestNetPrioSetIfPrio(t *testing.T) {
    22  	helper := NewCgroupTestUtil("net_prio", t)
    23  	defer helper.cleanup()
    24  
    25  	helper.CgroupData.config.Resources.NetPrioIfpriomap = prioMap
    26  	netPrio := &NetPrioGroup{}
    27  	if err := netPrio.Set(helper.CgroupPath, helper.CgroupData.config); err != nil {
    28  		t.Fatal(err)
    29  	}
    30  
    31  	value, err := getCgroupParamString(helper.CgroupPath, "net_prio.ifpriomap")
    32  	if err != nil {
    33  		t.Fatalf("Failed to parse net_prio.ifpriomap - %s", err)
    34  	}
    35  	if !strings.Contains(value, "test 5") {
    36  		t.Fatal("Got the wrong value, set net_prio.ifpriomap failed.")
    37  	}
    38  }