Debian Codegraph @

Documentation/testing.md

raw
1 # Testing in rdma-core
2
3 rdma-core now offers an infrastructure for quick and easy additions of feature-
4 specific tests.
5
6 ## Design
7 ### Resources Management
8 `BaseResources` class is the basic objects aggregator available. It includes a
9 Context and a PD.
10 Inheriting from it is `TrafficResources` class, which also holds a MR, CQ and
11 QP, making it enough to support loopback traffic testing. It exposes methods for
12 creation of these objects which can be overridden by inheriting classes.
13 Inheriting from `TrafficResources` are currently three classes:
14 - `RCResources`
15 - `UDResources`
16 - `XRXResources`
17
18 The above subclasses add traffic-specific constants. For example, `UDResources`
19 overrides create_mr and adds the size of the GRH header to the message size.
20 `RCResources` exposes a wrapper to modify the QP to RTS.
21
22 ### Tests-related Classes
23 `unittest.TestCase` is a logical test unit in Python's unittest module.
24 `RDMATestCase` inherits from it and adds the option to accept parameters
25 (example will follow below) or use a random set of valid parameters:
26 - If no device was provided, it iterates over the existing devices, for each
27 port of each device, it checks which GID indexes are valid (in RoCE, only
28 IPv4 and IPv6 based GIDs are used). Each <dev, port, gid> is added to an array
29 and one entry is selected.
30 - If a device was provided, the same process is done for all ports of this
31 device, and so on.
32
33 ### Traffic Utilities
34 tests/utils.py offers a few wrappers for common traffic operations, making the
35 use of default values even shorter. Those traffic utilities accept an
36 aggregation object as their first parameter and rely on that object to have
37 valid RDMA resources for proper functioning.
38 - get_[send, recv]_wr() creates a [Send, Recv]WR object with a single SGE. It
39 also sets the MR content to be 'c's for client side or 's's for server side
40 (this is later validated).
41 - post_send() posts a single send request to the aggregation object's QP. If the
42 QP is a UD QP, an address vector will be added to the send WR.
43 - post_recv() posts the given RecvWR <num> times, so it can be used to fill the
44 RQ prior to traffic as well as during traffic.
45 - poll_cq() polls <num> completions from the CQ and raises an exception on a
46 non-success status.
47 - validate() verifies that the data in the MR is as expected ('c's for server,
48 's's for client).
49 - traffic() runs <num> iterations of send/recv between 2 players.
50
51 ## How to run rdma-core's tests
52 #### Developers
53 The tests can be executed from ./build/bin:
54 ```
55 ./build.sh
56 ./build/bin/run_tests.py
57 ```
58 #### Users
59 The tests are not a Python package, as such they can be found under
60 /usr/share/doc/rdma-core-{version}/tests.
61 In order to run all tests:
62 ```
63 python /usr/share/doc/rdma-core-<version>/tests/run_tests.py
64 ```
65 #### Execution output
66 Output will be something like:
67 ```
68 $ ./build/bin/run_tests.py
69 ..........................................ss...............
70 ----------------------------------------------------------------------
71 Ran 59 tests in 13.268s
72
73 OK (skipped=2)
74 ```
75 A dot represents a passing test. 's' means a skipped test. 'E' means a test
76 that failed.
77
78 Tests can also be executed in verbose mode:
79 ```
80 $ python3 /usr/share/doc/rdma-core-26.0/tests/run_tests.py -v
81 test_create_ah (test_addr.AHTest) ... ok
82 test_create_ah_roce (test_addr.AHTest) ... ok
83 test_destroy_ah (test_addr.AHTest) ... ok
84 test_create_comp_channel (test_cq.CCTest) ... ok
85 < many more lines here>
86 test_odp_rc_traffic (test_odp.OdpTestCase) ... skipped 'No port is up, can't run traffic'
87 test_odp_ud_traffic (test_odp.OdpTestCase) ... skipped 'No port is up, can't run traffic'
88 <more lines>
89
90 ----------------------------------------------------------------------
91 Ran 59 tests in 12.857s
92
93 OK (skipped=2)
94 ```
95 Verbose mode provides the reason for skipping the test (if one was provided by
96 the test developer).
97
98 ### Customized Execution
99 tests/\_\_init\_\_.py defines a `_load_tests` function that returns an array with
100 the tests that will be executed.
101 The default implementation collects all test_* methods from all the classes that
102 inherit from `unittest.TestCase` (or `RDMATestCase`) and located in files under
103 tests directory which names starts with test_.
104 Users can execute part of the tests by adding `-k` to the run_tests.py command.
105 The following example executes only tests cases in files starting with
106 `test_device` and not `test_`.
107
108 ```
109 $ build/bin/run_tests.py -v -k test_device
110 test_create_dm (tests.test_device.DMTest) ... ok
111 test_create_dm_bad_flow (tests.test_device.DMTest) ... ok
112 test_destroy_dm (tests.test_device.DMTest) ... ok
113 test_destroy_dm_bad_flow (tests.test_device.DMTest) ... ok
114 test_dm_read (tests.test_device.DMTest) ... ok
115 test_dm_write (tests.test_device.DMTest) ... ok
116 test_dm_write_bad_flow (tests.test_device.DMTest) ... ok
117 test_dev_list (tests.test_device.DeviceTest) ... ok
118 test_open_dev (tests.test_device.DeviceTest) ... ok
119 test_query_device (tests.test_device.DeviceTest) ... ok
120 test_query_device_ex (tests.test_device.DeviceTest) ... ok
121 test_query_gid (tests.test_device.DeviceTest) ... ok
122 test_query_port (tests.test_device.DeviceTest) ... ok
123 test_query_port_bad_flow (tests.test_device.DeviceTest) ... ok
124
125 ----------------------------------------------------------------------
126 Ran 14 tests in 0.152s
127
128 OK
129 ```
130
131 ### GPUDirect RDMA
132 Part of the available tests includes GPUDirect RDMA.
133 Those tests run RDMA traffic over CUDA-allocated memory.
134 In order to run them successfully it's required to have a supported NVIDIA GPU,
135 CUDA 11.7 and above with "Open flavor" ("-m kernel-open") Driver 515 or later
136 and cuda-python 12.0 and above.
137 Running the tests is similar to other tests, with the option to choose which GPU
138 unit to use in case there are multiple GPUs on the setup.
139 ```
140 $ build/bin/run_tests.py -v --gpu 0 -k cuda
141 test_cuda_dmabuf_rdma_write_traffic (tests.test_cuda_dmabuf.DmabufCudaTest)
142 Runs RDMA Write traffic over CUDA allocated memory using DMA BUF and ... ok
143 test_mlx_devx_cuda_send_imm_traffic (tests.test_mlx5_cuda_umem.Mlx5GpuDevxRcTrafficTest)
144 Creates two DevX RC QPs and runs SEND_IMM traffic over CUDA allocated ... ok
145
146 ----------------------------------------------------------------------
147 Ran 2 tests in 3.033s
148
149 OK
150 ```
151
152 ## Writing Tests
153 The following section explains how to add a new test, using tests/test_odp.py
154 as an example. It's a simple test that runs ping-pong over a few different
155 traffic types.
156
157 ODP requires capability check, so a decorator was added to tests/utils.py.
158 The first change for ODP execution is when registering a memory region (need to
159 set the ON_DEMAND access flag), so we do as follows:
160 1. Create the players by inheriting from `RCResources` (for RC traffic).
161 2. In the player, override create_mr() and add the decorator to it. It will run
162 before the actual call to ibv_reg_mr and if ODP caps are off, the test will
163 be skipped.
164 3. Create the `OdpTestCase` by inheriting from `RDMATestCase`.
165 4. In the test case, add a method starting with test_, to let the unittest
166 infrastructure that this is a test.
167 5. In the test method, create the players (which already check the ODP caps)
168 and call the traffic() function, providing it the two players.