File: mbm_test.go

package info (click to toggle)
runc 1.0.3%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,836 kB
  • sloc: sh: 1,571; ansic: 1,236; makefile: 136
file content (67 lines) | stat: -rw-r--r-- 1,629 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// +build linux

package intelrdt

import (
	"os"
	"path/filepath"
	"testing"
)

func TestGetMBMNumaNodeStats(t *testing.T) {
	mocksNUMANodesToCreate := []string{"mon_l3_00", "mon_l3_01"}

	mocksFilesToCreate := map[string]uint64{
		"mbm_total_bytes": 9123911,
		"mbm_local_bytes": 2361361,
	}

	mockedL3_MON, err := mockResctrlL3_MON(mocksNUMANodesToCreate, mocksFilesToCreate)

	defer func() {
		err := os.RemoveAll(mockedL3_MON)
		if err != nil {
			t.Fatal(err)
		}
	}()

	if err != nil {
		t.Fatal(err)
	}

	t.Run("Gather mbm", func(t *testing.T) {
		enabledMonFeatures.mbmTotalBytes = true
		enabledMonFeatures.mbmLocalBytes = true

		stats := make([]MBMNumaNodeStats, 0, len(mocksNUMANodesToCreate))
		for _, numa := range mocksNUMANodesToCreate {
			other, err := getMBMNumaNodeStats(filepath.Join(mockedL3_MON, "mon_data", numa))
			if err != nil {
				t.Fatal(err)
			}
			stats = append(stats, *other)
		}

		expectedStats := MBMNumaNodeStats{
			MBMTotalBytes: mocksFilesToCreate["mbm_total_bytes"],
			MBMLocalBytes: mocksFilesToCreate["mbm_local_bytes"],
		}

		checkMBMStatCorrection(stats[0], expectedStats, t)
		checkMBMStatCorrection(stats[1], expectedStats, t)
	})
}

func checkMBMStatCorrection(got MBMNumaNodeStats, expected MBMNumaNodeStats, t *testing.T) {
	if got.MBMTotalBytes != expected.MBMTotalBytes {
		t.Fatalf("Wrong value of mbm_total_bytes. Expected: %v but got: %v",
			expected.MBMTotalBytes,
			got.MBMTotalBytes)
	}

	if got.MBMLocalBytes != expected.MBMLocalBytes {
		t.Fatalf("Wrong value of mbm_local_bytes. Expected: %v but got: %v",
			expected.MBMLocalBytes,
			got.MBMLocalBytes)
	}
}