...

Source file src/github.com/opencontainers/runc/libcontainer/intelrdt/mbm_test.go

Documentation: github.com/opencontainers/runc/libcontainer/intelrdt

     1  package intelrdt
     2  
     3  import (
     4  	"path/filepath"
     5  	"testing"
     6  )
     7  
     8  func TestGetMBMNumaNodeStats(t *testing.T) {
     9  	mocksNUMANodesToCreate := []string{"mon_l3_00", "mon_l3_01"}
    10  
    11  	mocksFilesToCreate := map[string]uint64{
    12  		"mbm_total_bytes": 9123911,
    13  		"mbm_local_bytes": 2361361,
    14  	}
    15  
    16  	mockedL3_MON := mockResctrlL3_MON(t, mocksNUMANodesToCreate, mocksFilesToCreate)
    17  
    18  	t.Run("Gather mbm", func(t *testing.T) {
    19  		enabledMonFeatures.mbmTotalBytes = true
    20  		enabledMonFeatures.mbmLocalBytes = true
    21  
    22  		stats := make([]MBMNumaNodeStats, 0, len(mocksNUMANodesToCreate))
    23  		for _, numa := range mocksNUMANodesToCreate {
    24  			other, err := getMBMNumaNodeStats(filepath.Join(mockedL3_MON, "mon_data", numa))
    25  			if err != nil {
    26  				t.Fatal(err)
    27  			}
    28  			stats = append(stats, *other)
    29  		}
    30  
    31  		expectedStats := MBMNumaNodeStats{
    32  			MBMTotalBytes: mocksFilesToCreate["mbm_total_bytes"],
    33  			MBMLocalBytes: mocksFilesToCreate["mbm_local_bytes"],
    34  		}
    35  
    36  		checkMBMStatCorrection(stats[0], expectedStats, t)
    37  		checkMBMStatCorrection(stats[1], expectedStats, t)
    38  	})
    39  }
    40  
    41  func checkMBMStatCorrection(got MBMNumaNodeStats, expected MBMNumaNodeStats, t *testing.T) {
    42  	if got.MBMTotalBytes != expected.MBMTotalBytes {
    43  		t.Fatalf("Wrong value of mbm_total_bytes. Expected: %v but got: %v",
    44  			expected.MBMTotalBytes,
    45  			got.MBMTotalBytes)
    46  	}
    47  
    48  	if got.MBMLocalBytes != expected.MBMLocalBytes {
    49  		t.Fatalf("Wrong value of mbm_local_bytes. Expected: %v but got: %v",
    50  			expected.MBMLocalBytes,
    51  			got.MBMLocalBytes)
    52  	}
    53  }
    54  

View as plain text