...

Source file src/github.com/opencontainers/runc/libcontainer/cgroups/fscommon/rdma_test.go

Documentation: github.com/opencontainers/runc/libcontainer/cgroups/fscommon

     1  package fscommon
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	"github.com/opencontainers/runc/libcontainer/configs"
     9  )
    10  
    11  /* Roadmap for future */
    12  // (Low-priority)  TODO: Check if it is possible to virtually mimic an actual RDMA device.
    13  // TODO: Think of more edge-cases to add.
    14  
    15  // TestRdmaSet performs an E2E test of RdmaSet(), parseRdmaKV() using dummy device and a dummy cgroup file-system.
    16  // Note: Following test does not guarantees that your host supports RDMA since this mocks underlying infrastructure.
    17  func TestRdmaSet(t *testing.T) {
    18  	testCgroupPath := filepath.Join(t.TempDir(), "rdma")
    19  
    20  	// Ensure the full mock cgroup path exists.
    21  	err := os.Mkdir(testCgroupPath, 0o755)
    22  	if err != nil {
    23  		t.Fatal(err)
    24  	}
    25  
    26  	rdmaDevice := "mlx5_1"
    27  	maxHandles := uint32(100)
    28  	maxObjects := uint32(300)
    29  
    30  	rdmaStubResource := &configs.Resources{
    31  		Rdma: map[string]configs.LinuxRdma{
    32  			rdmaDevice: {
    33  				HcaHandles: &maxHandles,
    34  				HcaObjects: &maxObjects,
    35  			},
    36  		},
    37  	}
    38  
    39  	if err := RdmaSet(testCgroupPath, rdmaStubResource); err != nil {
    40  		t.Fatal(err)
    41  	}
    42  
    43  	// The default rdma.max must be written.
    44  	rdmaEntries, err := readRdmaEntries(testCgroupPath, "rdma.max")
    45  	if err != nil {
    46  		t.Fatal(err)
    47  	}
    48  	if len(rdmaEntries) != 1 {
    49  		t.Fatal("rdma_test: Got the wrong values while parsing entries from rdma.max")
    50  	}
    51  	if rdmaEntries[0].HcaHandles != maxHandles {
    52  		t.Fatalf("rdma_test: Got the wrong value for hca_handles")
    53  	}
    54  	if rdmaEntries[0].HcaObjects != maxObjects {
    55  		t.Fatalf("rdma_test: Got the wrong value for hca_Objects")
    56  	}
    57  }
    58  

View as plain text