Skip to content

Commit 664896e

Browse files
authored
chore: Include tests and examples in release builds (#872)
Lets build these for release builds. In release builds there is some optimization added that might help with running tests and seeing performance numbers. The asserts are removed in release builds so a new macro was added to check for return status' of the API calls. Introduced new macro to validate API return statuses (since assert is disabled in release builds). Added Meson options to toggle building of tests and examples. Fixed numerous issues with tests and examples to ensure compatibility with release builds. Signed-off-by: Adit Ranadive <[email protected]>
1 parent 1ee9e6d commit 664896e

22 files changed

+519
-380
lines changed

examples/cpp/meson.build

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515

1616
nixl_example = executable('nixl_example',
1717
'nixl_example.cpp',
18-
dependencies: [nixl_dep, nixl_infra, nixl_common_deps],
18+
dependencies: [nixl_dep, nixl_infra, nixl_common_deps, nixl_test_utils_dep],
1919
include_directories: [nixl_inc_dirs, utils_inc_dirs],
2020
link_with: [serdes_lib],
2121
install: true)
2222

2323
if etcd_dep.found()
2424
etcd_example = executable('nixl_etcd_example',
2525
'nixl_etcd_example.cpp',
26-
dependencies: [nixl_dep, nixl_infra, nixl_common_deps],
26+
dependencies: [nixl_dep, nixl_infra, nixl_common_deps, nixl_test_utils_dep],
2727
include_directories: [nixl_inc_dirs, utils_inc_dirs],
2828
link_with: [serdes_lib],
2929
install: true)

examples/cpp/nixl_etcd_example.cpp

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
* limitations under the License.
1616
*/
1717
#include <iostream>
18-
#include <cassert>
1918
#include <thread>
2019
#include <chrono>
2120
#include <cstring>
2221

2322
#include "nixl.h"
23+
#include "test_utils.h"
24+
2425

2526
// Change these values to match your etcd setup
2627
const std::string ETCD_ENDPOINT = "http://localhost:2379";
@@ -130,7 +131,7 @@ int main() {
130131
std::vector<nixl_backend_t> plugins;
131132

132133
ret1 = A1.getAvailPlugins(plugins);
133-
assert (ret1 == NIXL_SUCCESS);
134+
nixl_exit_on_failure(ret1, "Failed to get available plugins", AGENT1_NAME);
134135

135136
std::cout << "Available plugins:\n";
136137

@@ -140,8 +141,8 @@ int main() {
140141
ret1 = A1.getPluginParams("UCX", mems1, init1);
141142
ret2 = A2.getPluginParams("UCX", mems2, init2);
142143

143-
assert (ret1 == NIXL_SUCCESS);
144-
assert (ret2 == NIXL_SUCCESS);
144+
nixl_exit_on_failure(ret1, "Failed to get plugin params for UCX", AGENT1_NAME);
145+
nixl_exit_on_failure(ret2, "Failed to get plugin params for UCX", AGENT2_NAME);
145146

146147
std::cout << "Params before init:\n";
147148
printParams(init1, mems1);
@@ -151,25 +152,25 @@ int main() {
151152
nixlBackendH* ucx1, *ucx2;
152153
ret1 = A1.createBackend("UCX", init1, ucx1);
153154
ret2 = A2.createBackend("UCX", init2, ucx2);
154-
155-
assert (ret1 == NIXL_SUCCESS);
156-
assert (ret2 == NIXL_SUCCESS);
155+
nixl_exit_on_failure(ret1, "Failed to create UCX backend", AGENT1_NAME);
156+
nixl_exit_on_failure(ret2, "Failed to create UCX backend", AGENT2_NAME);
157157

158158
ret1 = A1.getBackendParams(ucx1, mems1, init1);
159159
ret2 = A2.getBackendParams(ucx2, mems2, init2);
160160

161-
assert (ret1 == NIXL_SUCCESS);
162-
assert (ret2 == NIXL_SUCCESS);
161+
nixl_exit_on_failure(ret1, "Failed to get UCX backend params", AGENT1_NAME);
162+
nixl_exit_on_failure(ret2, "Failed to get UCX backend params", AGENT2_NAME);
163+
163164

164165
std::cout << "Params after init:\n";
165166
printParams(init1, mems1);
166167
printParams(init2, mems2);
167168

168169
// Register memory with both agents
169170
status = registerMemory(&addr1, &A1, &dlist1, &extra_params1, ucx1, 0xaa);
170-
assert(status == NIXL_SUCCESS);
171+
nixl_exit_on_failure(status, "Failed to register memory", AGENT1_NAME);
171172
status = registerMemory(&addr2, &A2, &dlist2, &extra_params2, ucx2, 0xbb);
172-
assert(status == NIXL_SUCCESS);
173+
nixl_exit_on_failure(status, "Failed to register memory", AGENT2_NAME);
173174

174175
std::cout << "\nEtcd Metadata Exchange Demo\n";
175176
std::cout << "==========================\n";
@@ -179,10 +180,10 @@ int main() {
179180

180181
// Both agents send their metadata to etcd
181182
status = A1.sendLocalMD();
182-
assert(status == NIXL_SUCCESS);
183+
nixl_exit_on_failure(status, "Failed to send local MD", AGENT1_NAME);
183184

184185
status = A2.sendLocalMD();
185-
assert(status == NIXL_SUCCESS);
186+
nixl_exit_on_failure(status, "Failed to send local MD", AGENT2_NAME);
186187

187188
// Give etcd time to process
188189
std::this_thread::sleep_for(std::chrono::seconds(1));
@@ -192,11 +193,11 @@ int main() {
192193

193194
// Agent1 fetches metadata for Agent2
194195
status = A1.fetchRemoteMD(AGENT2_NAME);
195-
assert(status == NIXL_SUCCESS);
196+
nixl_exit_on_failure(status, "Failed to fetch remote MD", AGENT1_NAME);
196197

197198
// Agent2 fetches metadata for Agent1
198199
status = A2.fetchRemoteMD(AGENT1_NAME);
199-
assert(status == NIXL_SUCCESS);
200+
nixl_exit_on_failure(status, "Failed to fetch remote MD", AGENT2_NAME);
200201

201202
// Do transfer from Agent 1 to Agent 2
202203
size_t req_size = 8;
@@ -229,8 +230,10 @@ int main() {
229230
extra_params1.hasNotif = true;
230231
ret1 = A1.createXferReq(NIXL_WRITE, req_src_descs, req_dst_descs, AGENT2_NAME, req_handle, &extra_params1);
231232
std::cout << "Xfer request created, status: " << nixlEnumStrings::statusStr(ret1) << std::endl;
233+
nixl_exit_on_failure(ret1, "Failed to create Xfer Req", AGENT1_NAME);
232234

233235
status = A1.postXferReq(req_handle);
236+
nixl_exit_on_failure((status >= NIXL_SUCCESS), "Failed to post Xfer Req", AGENT1_NAME);
234237

235238
std::cout << "Transfer was posted\n";
236239

@@ -240,20 +243,20 @@ int main() {
240243
while (status != NIXL_SUCCESS || n_notifs == 0) {
241244
if (status != NIXL_SUCCESS) status = A1.getXferStatus(req_handle);
242245
if (n_notifs == 0) ret2 = A2.getNotifs(notif_map);
243-
assert (status >= 0);
244-
assert (ret2 == NIXL_SUCCESS);
246+
nixl_exit_on_failure((status >= NIXL_SUCCESS), "Failed to get Xfer status", AGENT1_NAME);
247+
nixl_exit_on_failure(ret2, "Failed to get notifs", AGENT2_NAME);
245248
n_notifs = notif_map.size();
246249
}
247250

248251
std::cout << "Transfer verified\n";
249252

250253
ret1 = A1.releaseXferReq(req_handle);
251-
assert (ret1 == NIXL_SUCCESS);
254+
nixl_exit_on_failure(ret1, "Failed to release Xfer Req", AGENT1_NAME);
252255

253256
ret1 = A1.deregisterMem(dlist1, &extra_params1);
254257
ret2 = A2.deregisterMem(dlist2, &extra_params2);
255-
assert (ret1 == NIXL_SUCCESS);
256-
assert (ret2 == NIXL_SUCCESS);
258+
nixl_exit_on_failure(ret1, "Failed to deregister memory", AGENT1_NAME);
259+
nixl_exit_on_failure(ret2, "Failed to deregister memory", AGENT2_NAME);
257260

258261
// 3. Partial Metadata Exchange
259262
std::cout << "\n3. Sending partial metadata to etcd...\n";
@@ -274,36 +277,36 @@ int main() {
274277

275278
// Send partial metadata
276279
status = A1.sendLocalPartialMD(empty_dlist1, &conn_params1);
277-
assert(status == NIXL_SUCCESS);
280+
nixl_exit_on_failure(status, "Failed to send local partial MD", AGENT1_NAME);
278281

279282
status = A2.sendLocalPartialMD(empty_dlist2, &conn_params2);
280-
assert(status == NIXL_SUCCESS);
283+
nixl_exit_on_failure(status, "Failed to send local partial MD", AGENT2_NAME);
281284

282285
// Send once partial with different label
283286
conn_params1.metadataLabel = PARTIAL_LABEL_2;
284287
status = A1.sendLocalPartialMD(empty_dlist1, &conn_params1);
285-
assert(status == NIXL_SUCCESS);
288+
nixl_exit_on_failure(status, "Failed to send local partial MD", AGENT1_NAME);
286289

287290
conn_params2.metadataLabel = PARTIAL_LABEL_2;
288291
status = A2.sendLocalPartialMD(empty_dlist2, &conn_params2);
289-
assert(status == NIXL_SUCCESS);
292+
nixl_exit_on_failure(status, "Failed to send local partial MD", AGENT2_NAME);
290293

291294
nixl_opt_args_t fetch_params;
292295
fetch_params.metadataLabel = PARTIAL_LABEL_1;
293296
status = A1.fetchRemoteMD(AGENT2_NAME, &fetch_params);
294-
assert(status == NIXL_SUCCESS);
297+
nixl_exit_on_failure(status, "Failed to fetch remote MD", AGENT1_NAME);
295298

296299
status = A2.fetchRemoteMD(AGENT1_NAME, &fetch_params);
297-
assert(status == NIXL_SUCCESS);
300+
nixl_exit_on_failure(status, "Failed to fetch remote MD", AGENT2_NAME);
298301

299302
std::this_thread::sleep_for(std::chrono::seconds(1));
300303

301304
// 4. Invalidate Metadata
302305
std::cout << "\n4. Invalidating metadata in etcd...\n";
303306

304-
// Invalidate agent1's metadata
307+
// Invalidate AGENT1_NAME's metadata
305308
status = A1.invalidateLocalMD();
306-
assert(status == NIXL_SUCCESS);
309+
nixl_exit_on_failure(status, "Failed to invalidate local MD", AGENT1_NAME);
307310

308311
std::this_thread::sleep_for(std::chrono::seconds(1));
309312

@@ -316,14 +319,14 @@ int main() {
316319
// Try invalidating again, this should log a debug message
317320
std::cout << "Trying to invalidate again...\n";
318321
status = A1.invalidateLocalMD();
319-
assert(status == NIXL_SUCCESS);
322+
nixl_exit_on_failure(status, "Failed to invalidate local MD", AGENT1_NAME);
320323

321324
std::this_thread::sleep_for(std::chrono::seconds(1));
322325

323326
// 5. Fetch metadata with invalid label. This should not block forever and print error message.
324327
std::cout << "\n5. Fetching metadata with invalid label...\n";
325328
status = A2.fetchRemoteMD("INVALID_AGENT", &fetch_params);
326-
assert(status == NIXL_SUCCESS);
329+
nixl_exit_on_failure(status, "Failed to fetch remote MD", AGENT2_NAME);
327330

328331
std::this_thread::sleep_for(std::chrono::seconds(1));
329332

examples/cpp/nixl_example.cpp

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <sys/time.h>
2222

2323
#include "nixl.h"
24+
#include "test_utils.h"
25+
2426

2527
std::string agent1("Agent001");
2628
std::string agent2("Agent002");
@@ -29,7 +31,7 @@ void check_buf(void* buf, size_t len) {
2931

3032
// Do some checks on the data.
3133
for(size_t i = 0; i<len; i++){
32-
assert (((uint8_t*) buf)[i] == 0xbb);
34+
nixl_exit_on_failure((((uint8_t *)buf)[i] == 0xbb), "Data mismatch!", agent1);
3335
}
3436
}
3537

@@ -89,7 +91,7 @@ main(int argc, char **argv) {
8991
std::vector<nixl_backend_t> plugins;
9092

9193
ret1 = A1.getAvailPlugins(plugins);
92-
assert (ret1 == NIXL_SUCCESS);
94+
nixl_exit_on_failure(ret1, "Failed to get available plugins", agent1);
9395

9496
std::cout << "Available plugins:\n";
9597

@@ -100,8 +102,8 @@ main(int argc, char **argv) {
100102
ret1 = A1.getPluginParams(backend, mems1, init1);
101103
ret2 = A2.getPluginParams(backend, mems2, init2);
102104

103-
assert (ret1 == NIXL_SUCCESS);
104-
assert (ret2 == NIXL_SUCCESS);
105+
nixl_exit_on_failure(ret1, "Failed to get plugin params", agent1);
106+
nixl_exit_on_failure(ret2, "Failed to get plugin params", agent2);
105107

106108
std::cout << "Params before init:\n";
107109
printParams(init1, mems1);
@@ -115,14 +117,14 @@ main(int argc, char **argv) {
115117
extra_params1.backends.push_back(bknd1);
116118
extra_params2.backends.push_back(bknd2);
117119

118-
assert (ret1 == NIXL_SUCCESS);
119-
assert (ret2 == NIXL_SUCCESS);
120+
nixl_exit_on_failure(ret1, "Failed to create " + backend + " backend", agent1);
121+
nixl_exit_on_failure(ret2, "Failed to create " + backend + " backend", agent2);
120122

121123
ret1 = A1.getBackendParams(bknd1, mems1, init1);
122124
ret2 = A2.getBackendParams(bknd2, mems2, init2);
123125

124-
assert (ret1 == NIXL_SUCCESS);
125-
assert (ret2 == NIXL_SUCCESS);
126+
nixl_exit_on_failure(ret1, "Failed to get " + backend + " backend params", agent1);
127+
nixl_exit_on_failure(ret2, "Failed to get " + backend + " backend params", agent2);
126128

127129
std::cout << "Params after init:\n";
128130
printParams(init1, mems1);
@@ -161,25 +163,22 @@ main(int argc, char **argv) {
161163

162164
ret1 = A1.registerMem(dlist1, &extra_params1);
163165
ret2 = A2.registerMem(dlist2, &extra_params2);
164-
165-
assert (ret1 == NIXL_SUCCESS);
166-
assert (ret2 == NIXL_SUCCESS);
166+
nixl_exit_on_failure(ret1, "Failed to register memory", agent1);
167+
nixl_exit_on_failure(ret2, "Failed to register memory", agent2);
167168

168169
std::string meta1;
169170
ret1 = A1.getLocalMD(meta1);
170171
std::string meta2;
171172
ret2 = A2.getLocalMD(meta2);
172-
173-
assert (ret1 == NIXL_SUCCESS);
174-
assert (ret2 == NIXL_SUCCESS);
173+
nixl_exit_on_failure(ret1, "Failed to get local MD", agent1);
174+
nixl_exit_on_failure(ret2, "Failed to get local MD", agent2);
175175

176176
std::cout << "Agent1's Metadata: " << meta1 << "\n";
177177
std::cout << "Agent2's Metadata: " << meta2 << "\n";
178178

179179
ret1 = A1.loadRemoteMD (meta2, ret_s1);
180180

181-
assert (ret1 == NIXL_SUCCESS);
182-
assert (ret2 == NIXL_SUCCESS);
181+
nixl_exit_on_failure(ret1, "Failed to load remote MD", agent1);
183182

184183
size_t req_size = 8;
185184
size_t dst_offset = 8;
@@ -204,9 +203,10 @@ main(int argc, char **argv) {
204203
extra_params1.notifMsg = "notification";
205204
extra_params1.hasNotif = true;
206205
ret1 = A1.createXferReq(NIXL_WRITE, req_src_descs, req_dst_descs, agent2, req_handle, &extra_params1);
207-
assert (ret1 == NIXL_SUCCESS);
206+
nixl_exit_on_failure(ret1, "Failed to create Xfer Req", agent1);
208207

209208
nixl_status_t status = A1.postXferReq(req_handle);
209+
nixl_exit_on_failure((status >= NIXL_SUCCESS), "Failed to post Xfer Req", agent1);
210210

211211
std::cout << "Transfer was posted\n";
212212

@@ -216,31 +216,33 @@ main(int argc, char **argv) {
216216
while (status != NIXL_SUCCESS || n_notifs == 0) {
217217
if (status != NIXL_SUCCESS) status = A1.getXferStatus(req_handle);
218218
if (n_notifs == 0) ret2 = A2.getNotifs(notif_map);
219-
assert (status >= 0);
220-
assert (ret2 == NIXL_SUCCESS);
219+
nixl_exit_on_failure((status >= NIXL_SUCCESS), "Failed to post Xfer Req", agent1);
220+
nixl_exit_on_failure(ret2, "Failed to get notifs", agent2);
221221
n_notifs = notif_map.size();
222222
}
223223

224224
std::vector<std::string> agent1_notifs = notif_map[agent1];
225-
assert (agent1_notifs.size() == 1);
226-
assert (agent1_notifs.front() == "notification");
225+
nixl_exit_on_failure((agent1_notifs.size() == 1), "Incorrect notif size", agent1);
226+
nixl_exit_on_failure(
227+
(agent1_notifs.front() == "notification"), "Incorrect notification", agent1);
228+
227229
notif_map[agent1].clear(); // Redundant, for testing
228230
notif_map.clear();
229231
n_notifs = 0;
230232

231233
std::cout << "Transfer verified\n";
232234

233235
ret1 = A1.releaseXferReq(req_handle);
234-
assert (ret1 == NIXL_SUCCESS);
236+
nixl_exit_on_failure(ret1, "Failed to release Xfer Req", agent1);
235237

236238
ret1 = A1.deregisterMem(dlist1, &extra_params1);
237239
ret2 = A2.deregisterMem(dlist2, &extra_params2);
238-
assert (ret1 == NIXL_SUCCESS);
239-
assert (ret2 == NIXL_SUCCESS);
240+
nixl_exit_on_failure(ret1, "Failed to deregister memory", agent1);
241+
nixl_exit_on_failure(ret2, "Failed to deregister memory", agent2);
240242

241243
//only initiator should call invalidate
242244
ret1 = A1.invalidateRemoteMD(agent2);
243-
assert (ret1 == NIXL_SUCCESS);
245+
nixl_exit_on_failure(ret1, "Failed to invalidate remote MD", agent1);
244246

245247
free(addr1);
246248
free(addr2);

meson.build

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,11 @@ plugins_inc_dirs = include_directories('src/plugins')
251251
utils_inc_dirs = include_directories('src/utils')
252252

253253
subdir('src')
254-
255-
if get_option('buildtype') != 'release'
256-
subdir('test')
257-
subdir('examples')
254+
if get_option('build_tests')
255+
subdir('test')
256+
endif
257+
if get_option('build_examples')
258+
subdir('examples')
258259
endif
259260

260261
if get_option('install_headers')

meson_options.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@ option('log_level', type: 'combo', choices: ['trace', 'debug', 'info', 'warning'
3030
option('rust', type: 'boolean', value: false, description: 'Build Rust bindings')
3131

3232
# Tests
33+
option('build_tests', type: 'boolean', value: true, description: 'Build all tests')
34+
option('build_examples', type: 'boolean', value: true, description: 'Build all examples')
3335
option('test_all_plugins', type: 'boolean', value: false, description: 'Testing all plugins in addition to the mocks..')

src/infra/meson.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ nixl_build_lib = library('nixl_build',
2121
install: true)
2222

2323
nixl_infra = declare_dependency(link_with: nixl_build_lib)
24+
25+
# Test utilities library that can depend on nixl_dep (created after nixl_dep is defined)
26+
# This will be defined in a separate meson file to avoid circular dependencies

0 commit comments

Comments
 (0)