File: rdma_test.go

package info (click to toggle)
golang-github-opencontainers-cgroups 0.0.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 844 kB
  • sloc: makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,512 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
package fscommon

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

	"github.com/opencontainers/cgroups"
)

/* Roadmap for future */
// (Low-priority)  TODO: Check if it is possible to virtually mimic an actual RDMA device.
// TODO: Think of more edge-cases to add.

// TestRdmaSet performs an E2E test of RdmaSet(), parseRdmaKV() using dummy device and a dummy cgroup file-system.
// Note: Following test does not guarantees that your host supports RDMA since this mocks underlying infrastructure.
func TestRdmaSet(t *testing.T) {
	testCgroupPath := filepath.Join(t.TempDir(), "rdma")

	// Ensure the full mock cgroup path exists.
	err := os.Mkdir(testCgroupPath, 0o755)
	if err != nil {
		t.Fatal(err)
	}

	rdmaDevice := "mlx5_1"
	maxHandles := uint32(100)
	maxObjects := uint32(300)

	rdmaStubResource := &cgroups.Resources{
		Rdma: map[string]cgroups.LinuxRdma{
			rdmaDevice: {
				HcaHandles: &maxHandles,
				HcaObjects: &maxObjects,
			},
		},
	}

	if err := RdmaSet(testCgroupPath, rdmaStubResource); err != nil {
		t.Fatal(err)
	}

	// The default rdma.max must be written.
	rdmaEntries, err := readRdmaEntries(testCgroupPath, "rdma.max")
	if err != nil {
		t.Fatal(err)
	}
	if len(rdmaEntries) != 1 {
		t.Fatal("rdma_test: Got the wrong values while parsing entries from rdma.max")
	}
	if rdmaEntries[0].HcaHandles != maxHandles {
		t.Fatalf("rdma_test: Got the wrong value for hca_handles")
	}
	if rdmaEntries[0].HcaObjects != maxObjects {
		t.Fatalf("rdma_test: Got the wrong value for hca_Objects")
	}
}