Skip to content

Commit a144a9d

Browse files
committed
test: ignore ENOENT and EACCES from nvme_scan_topology
Replace nvme_scan with nvme_scan_topology and ignore any ENOENT and EACCES. Either the nvme module is not loaded/present or the current user might now have permissions to access the device. Signed-off-by: Daniel Wagner <[email protected]>
1 parent 321e561 commit a144a9d

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

libnvme/test/cpp.cc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,16 @@ int main()
1818
nvme_ctrl_t c;
1919
nvme_path_t p;
2020
nvme_ns_t n;
21+
int err;
2122

22-
if (nvme_scan(NULL, &ctx))
23-
return -1;
23+
ctx = nvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL);
24+
if (!ctx)
25+
return 1;
26+
27+
err = nvme_scan_topology(ctx, NULL, NULL);
28+
if (err && !(err == -ENOENT || err == -EACCES))
29+
goto out;
30+
err = 0;
2431

2532
nvme_for_each_host(ctx, h) {
2633
nvme_for_each_subsystem(h, s) {
@@ -60,7 +67,9 @@ int main()
6067
}
6168
}
6269
std::cout << "\n";
70+
71+
out:
6372
nvme_free_global_ctx(ctx);
6473

65-
return 0;
74+
return err != 0 ? 1 : 0;
6675
}

0 commit comments

Comments
 (0)