From: Daniel Wagner Date: Wed, 22 Jun 2022 06:52:32 +0000 (+0200) Subject: test: Remove code dependency for mi test X-Git-Tag: v1.1-rc0~27^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=0f6ee9b8bbf69b6378cc25ed7a85d8442a25d4ba;p=users%2Fsagi%2Flibnvme.git test: Remove code dependency for mi test When generating th coverage report, lcov chokes on the '../src/nvme' paths prefix: geninfo: WARNING: GCOV did not produce any data for /home/wagi/work/libnvme-upstream/obj/src/test-mi.p/.._test_mi.c.gcda We could restructure the project layout, e.g. by moving the test/mi.c file to the src/nvme direcotry. But that looks ugly and as it turns out we only really need one function copied over nvme_mi_crc32_update() to resolve the dependency. The other function is nvme_mi_init_ep() which we can easily open code. Obviously, it would be better to fix the path issue for lcov but for the time being let's go with this. Signed-off-by: Daniel Wagner --- diff --git a/test/meson.build b/test/meson.build index 4dd4031f..8324ed13 100644 --- a/test/meson.build +++ b/test/meson.build @@ -39,17 +39,9 @@ zns = executable( include_directories: [incdir, internal_incdir] ) -# The management interface tests don't require hardware, we have a small -# test-mi endpoint instead. -mi_sources = [ - '../src/nvme/mi.c', - '../src/nvme/log.c', - '../src/nvme/cleanup.c', -] - mi = executable( 'test-mi', - ['mi.c'] + mi_sources, + ['mi.c'], dependencies: libnvme_mi_dep, include_directories: [incdir, internal_incdir] ) diff --git a/test/mi.c b/test/mi.c index 077f89b8..0165211b 100644 --- a/test/mi.c +++ b/test/mi.c @@ -30,6 +30,18 @@ struct test_transport_data { static const int test_transport_magic = 0x74657374; +static __u32 crc32_update(__u32 crc, void *data, size_t len) +{ + int i; + + while (len--) { + crc ^= *(unsigned char *)(data++); + for (i = 0; i < 8; i++) + crc = (crc >> 1) ^ ((crc & 1) ? 0x82F63B78 : 0); + } + return crc; +} + static int test_transport_submit(struct nvme_mi_ep *ep, struct nvme_mi_req *req, struct nvme_mi_resp *resp) @@ -58,11 +70,11 @@ static void test_transport_close(struct nvme_mi_ep *ep) /* internal test helper to generate correct response crc */ static void test_transport_resp_calc_mic(struct nvme_mi_resp *resp) { - extern __u32 nvme_mi_crc32_update(__u32 crc, void *data, size_t len); + extern __u32 crc32_update(__u32 crc, void *data, size_t len); __u32 crc = 0xffffffff; - crc = nvme_mi_crc32_update(crc, resp->hdr, resp->hdr_len); - crc = nvme_mi_crc32_update(crc, resp->data, resp->data_len); + crc = crc32_update(crc, resp->hdr, resp->hdr_len); + crc = crc32_update(crc, resp->data, resp->data_len); resp->mic = ~crc; } @@ -89,8 +101,9 @@ nvme_mi_ep_t nvme_mi_open_test(nvme_root_t root) struct test_transport_data *tpd; struct nvme_mi_ep *ep; - ep = nvme_mi_init_ep(root); + ep = malloc(sizeof(*ep)); assert(ep); + ep->root = root; tpd = malloc(sizeof(*tpd)); assert(tpd);