Skip to content

Commit ce4a044

Browse files
committed
MI: reinstate init_ep and crc32 functions for use in test
Ideally, we would be using the actual implementation of nvme_mi_init_ep() and nvme_mi_crc32_update for our tests, rather than open-coding it in the test init. This change exports nvme_mi_init_ep and nvme_mi_crc32_update from libnvme-mi.so, but both remain excluded from the headers, as they are only intended for use in the transport API. This means we can call them from the tests, but keep somewhat-internal. We put this into a specific _TEST section of the version script, to keep separate from the public symbols, and add a comment to suit. This prevents us from diverging the endpoint init process in our testcases. Signed-off-by: Jeremy Kerr <[email protected]>
1 parent b7fe911 commit ce4a044

2 files changed

Lines changed: 12 additions & 17 deletions

File tree

src/libnvme-mi.map

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@ LIBNVME_MI_1_1 {
1919
local:
2020
*;
2121
};
22+
# API exported only for libnvme-mi internal test functions. These should
23+
# not be used other than through the in-tree tests, and cannot be considered
24+
# at all stable.
25+
LIBNVME_MI_TEST {
26+
global:
27+
nvme_mi_init_ep;
28+
nvme_mi_crc32_update;
29+
};

test/mi.c

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,6 @@ struct test_transport_data {
3030

3131
static const int test_transport_magic = 0x74657374;
3232

33-
static __u32 crc32_update(__u32 crc, void *data, size_t len)
34-
{
35-
int i;
36-
37-
while (len--) {
38-
crc ^= *(unsigned char *)(data++);
39-
for (i = 0; i < 8; i++)
40-
crc = (crc >> 1) ^ ((crc & 1) ? 0x82F63B78 : 0);
41-
}
42-
return crc;
43-
}
44-
4533
static int test_transport_submit(struct nvme_mi_ep *ep,
4634
struct nvme_mi_req *req,
4735
struct nvme_mi_resp *resp)
@@ -70,11 +58,11 @@ static void test_transport_close(struct nvme_mi_ep *ep)
7058
/* internal test helper to generate correct response crc */
7159
static void test_transport_resp_calc_mic(struct nvme_mi_resp *resp)
7260
{
73-
extern __u32 crc32_update(__u32 crc, void *data, size_t len);
61+
extern __u32 nvme_mi_crc32_update(__u32 crc, void *data, size_t len);
7462
__u32 crc = 0xffffffff;
7563

76-
crc = crc32_update(crc, resp->hdr, resp->hdr_len);
77-
crc = crc32_update(crc, resp->data, resp->data_len);
64+
crc = nvme_mi_crc32_update(crc, resp->hdr, resp->hdr_len);
65+
crc = nvme_mi_crc32_update(crc, resp->data, resp->data_len);
7866

7967
resp->mic = ~crc;
8068
}
@@ -101,9 +89,8 @@ nvme_mi_ep_t nvme_mi_open_test(nvme_root_t root)
10189
struct test_transport_data *tpd;
10290
struct nvme_mi_ep *ep;
10391

104-
ep = malloc(sizeof(*ep));
92+
ep = nvme_mi_init_ep(root);
10593
assert(ep);
106-
ep->root = root;
10794

10895
tpd = malloc(sizeof(*tpd));
10996
assert(tpd);

0 commit comments

Comments
 (0)