diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-06-30 22:36:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-06-30 22:36:10 +0000 |
commit | 61d0a8bdffbbb7229776d2f4f2e79ed22d21551f (patch) | |
tree | 2e249969fedce45eb37ae6314ad167595900fe38 /test | |
parent | Releasing debian version 1.4-4. (diff) | |
download | libnvme-61d0a8bdffbbb7229776d2f4f2e79ed22d21551f.tar.xz libnvme-61d0a8bdffbbb7229776d2f4f2e79ed22d21551f.zip |
Merging upstream version 1.5.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test')
25 files changed, 930 insertions, 8 deletions
diff --git a/test/meson.build b/test/meson.build index d90f835..49cd1ac 100644 --- a/test/meson.build +++ b/test/meson.build @@ -65,3 +65,23 @@ uuid = executable( ) test('uuid', uuid) + +if conf.get('HAVE_NETDB') + tree = executable( + 'tree', + ['tree.c'], + dependencies: libnvme_dep, + include_directories: [incdir, internal_incdir] + ) + + test('tree', tree) + + test_util = executable( + 'test-util', + ['test-util.c'], + include_directories: [incdir, internal_incdir] + ) + test('Test util.c', test_util) +endif + +subdir('nbft') @@ -1291,7 +1291,7 @@ static int test_admin_ns_mgmt_cb(struct nvme_mi_ep *ep, void *data) { __u8 *rq_hdr, *rs_hdr, sel, csi; - struct nvme_id_ns *id; + struct nvme_ns_mgmt_host_sw_specified *create_data; __u32 nsid; rq_hdr = (__u8 *)req->hdr; @@ -1305,15 +1305,15 @@ static int test_admin_ns_mgmt_cb(struct nvme_mi_ep *ep, switch (sel) { case NVME_NS_MGMT_SEL_CREATE: - assert(req->data_len == sizeof(struct nvme_id_ns)); - id = req->data; + assert(req->data_len == sizeof(struct nvme_ns_mgmt_host_sw_specified)); + create_data = req->data; /* No NSID on created namespaces */ assert(nsid == 0); assert(csi == 0); /* allow operations on nsze == 42, reject others */ - if (le64_to_cpu(id->nsze) != 42) { + if (le64_to_cpu(create_data->nsze) != 42) { rs_hdr[4] = 0; /* response cdw0 is created NSID */ rs_hdr[8] = 0x04; @@ -1342,7 +1342,7 @@ static int test_admin_ns_mgmt_cb(struct nvme_mi_ep *ep, static void test_admin_ns_mgmt_create(struct nvme_mi_ep *ep) { - struct nvme_id_ns nsid = { 0 }; + struct nvme_ns_mgmt_host_sw_specified data = { 0 }; nvme_mi_ctrl_t ctrl; __u32 ns; int rc; @@ -1352,12 +1352,12 @@ static void test_admin_ns_mgmt_create(struct nvme_mi_ep *ep) ctrl = nvme_mi_init_ctrl(ep, 5); assert(ctrl); - rc = nvme_mi_admin_ns_mgmt_create(ctrl, &nsid, 0, &ns); + rc = nvme_mi_admin_ns_mgmt_create(ctrl, NULL, 0, &ns, &data); assert(!rc); assert(ns == 0x01020304); - nsid.nsze = cpu_to_le64(42); - rc = nvme_mi_admin_ns_mgmt_create(ctrl, &nsid, 0, &ns); + data.nsze = cpu_to_le64(42); + rc = nvme_mi_admin_ns_mgmt_create(ctrl, NULL, 0, &ns, &data); assert(rc); } diff --git a/test/nbft/README b/test/nbft/README new file mode 100644 index 0000000..0f252a5 --- /dev/null +++ b/test/nbft/README @@ -0,0 +1,17 @@ +This is a simple testcase to verify the NBFT parser output over a set +of provided ACPI NBFT tables. + +The 'nbft-dump' test utility is a simple tool to print out all elements +and nested arrays of the nbft_info structs, bearing only minimal logic. + +The 'tables' directory contains sample binary files taken from +/sys/firmware/acpi/tables. The 'tables_bad' then contains experiments, older +table revisions or malformed data to test the parser error path. + +The "diffs" directory contains reference output generated by the 'nbft-dump' +utility that is being compared against actual testcase run output. Everytime +'nbft-dump.c' is modified these reference output files need to be regenerated +by calling `ninja -C .build nbft-diffs` over the configured meson project. + +The tests are typically ran as part of the standard `meson test -C .build` +invocation. diff --git a/test/nbft/diffs/NBFT-auto-ipv6 b/test/nbft/diffs/NBFT-auto-ipv6 new file mode 100644 index 0000000..32a8b60 --- /dev/null +++ b/test/nbft/diffs/NBFT-auto-ipv6 @@ -0,0 +1,39 @@ +raw_nbft_size=721 +host.id=1ee8b170eb4c864fb7957d179e201a +host.nqn=nqn.2014-08.org.nvmexpress:uuid:70b1e81e-4ceb-4f86-b709-57d1079e201a +host.host_id_configured=1 +host.host_nqn_configured=1 +host.primary=0 +hfi_list[0]->index=1 +hfi_list[0]->transport=tcp +hfi_list[0]->tcp_info.pci_sbdf=512 +hfi_list[0]->tcp_info.mac_addr=525409e201a +hfi_list[0]->tcp_info.vlan=0 +hfi_list[0]->tcp_info.ip_origin=1 +hfi_list[0]->tcp_info.ipaddr=fd09:9a46:b5c1:1ff:5054:ff:fe9e:201a +hfi_list[0]->tcp_info.subnet_mask_prefix=64 +hfi_list[0]->tcp_info.gateway_ipaddr=:: +hfi_list[0]->tcp_info.route_metric=0 +hfi_list[0]->tcp_info.primary_dns_ipaddr=:: +hfi_list[0]->tcp_info.secondary_dns_ipaddr=:: +hfi_list[0]->tcp_info.dhcp_server_ipaddr= +hfi_list[0]->tcp_info.host_name=nvmepoc-sles15-sp5 +hfi_list[0]->tcp_info.this_hfi_is_default_route=1 +hfi_list[0]->tcp_info.dhcp_override=0 +subsystem_ns_list[0]->index=1 +subsystem_ns_list[0]->num_hfis=1 +subsystem_ns_list[0]->hfis[0]->index=1 +subsystem_ns_list[0]->hfis[1]->index=1 +subsystem_ns_list[0]->transport=tcp +subsystem_ns_list[0]->traddr=fd09:9a46:b5c1:1ff:5054:ff:fefd:9e66 +subsystem_ns_list[0]->trsvcid=4420 +subsystem_ns_list[0]->subsys_port_id=0 +subsystem_ns_list[0]->nsid=1 +subsystem_ns_list[0]->nid_type=3 +subsystem_ns_list[0]->nid=848f4dc06d394968bf180569b8eea97 +subsystem_ns_list[0]->subsys_nqn=nqn.2022-12.de.suse.mwilck:zeus.vagrant-nvmet.subsys04 +subsystem_ns_list[0]->pdu_header_digest_required=0 +subsystem_ns_list[0]->data_digest_required=0 +subsystem_ns_list[0]->controller_id=1 +subsystem_ns_list[0]->asqsz=0 +subsystem_ns_list[0]->dhcp_root_path_string=(null) diff --git a/test/nbft/diffs/NBFT-dhcp-ipv4 b/test/nbft/diffs/NBFT-dhcp-ipv4 new file mode 100644 index 0000000..cb280d9 --- /dev/null +++ b/test/nbft/diffs/NBFT-dhcp-ipv4 @@ -0,0 +1,44 @@ +raw_nbft_size=825 +host.id=e359b7a15d37747b3cc1754b8b819b9 +host.nqn=nqn.2014-08.org.nvmexpress:uuid:a1b759e3-035d-4777-b3cc-1754b8b819b9 +host.host_id_configured=1 +host.host_nqn_configured=1 +host.primary=0 +hfi_list[0]->index=1 +hfi_list[0]->transport=tcp +hfi_list[0]->tcp_info.pci_sbdf=8 +hfi_list[0]->tcp_info.mac_addr=52540b819b9 +hfi_list[0]->tcp_info.vlan=0 +hfi_list[0]->tcp_info.ip_origin=3 +hfi_list[0]->tcp_info.ipaddr=192.168.49.155 +hfi_list[0]->tcp_info.subnet_mask_prefix=24 +hfi_list[0]->tcp_info.gateway_ipaddr=0.0.0.0 +hfi_list[0]->tcp_info.route_metric=0 +hfi_list[0]->tcp_info.primary_dns_ipaddr=192.168.49.1 +hfi_list[0]->tcp_info.secondary_dns_ipaddr=0.0.0.0 +hfi_list[0]->tcp_info.dhcp_server_ipaddr=192.168.49.1 +hfi_list[0]->tcp_info.host_name=nvmeof-sles +hfi_list[0]->tcp_info.this_hfi_is_default_route=1 +hfi_list[0]->tcp_info.dhcp_override=1 +discovery_list[0]->index=1 +discovery_list[0]->hfi->index=1 +discovery_list[0]->uri=nvme+tcp://192.168.49.10:4420/ +discovery_list[0]->nqn=nqn.2014-08.org.nvmexpress.discovery +subsystem_ns_list[0]->index=1 +subsystem_ns_list[0]->discovery->index=1 +subsystem_ns_list[0]->num_hfis=1 +subsystem_ns_list[0]->hfis[0]->index=1 +subsystem_ns_list[0]->hfis[1]->index=1 +subsystem_ns_list[0]->transport=tcp +subsystem_ns_list[0]->traddr=192.168.49.10 +subsystem_ns_list[0]->trsvcid=4420 +subsystem_ns_list[0]->subsys_port_id=0 +subsystem_ns_list[0]->nsid=1 +subsystem_ns_list[0]->nid_type=3 +subsystem_ns_list[0]->nid=df669a88bd6f4dd68a505f97eb55c835 +subsystem_ns_list[0]->subsys_nqn=nqn.2022-12.org.nvmexpress.boot.poc:bremer.vagrant-nvmet.subsys02 +subsystem_ns_list[0]->pdu_header_digest_required=0 +subsystem_ns_list[0]->data_digest_required=0 +subsystem_ns_list[0]->controller_id=7 +subsystem_ns_list[0]->asqsz=0 +subsystem_ns_list[0]->dhcp_root_path_string=(null) diff --git a/test/nbft/diffs/NBFT-dhcp-ipv6 b/test/nbft/diffs/NBFT-dhcp-ipv6 new file mode 100644 index 0000000..b94cc39 --- /dev/null +++ b/test/nbft/diffs/NBFT-dhcp-ipv6 @@ -0,0 +1,39 @@ +raw_nbft_size=725 +host.id=e359b7a15d37747b3cc1754b8b819b9 +host.nqn=nqn.2014-08.org.nvmexpress:uuid:a1b759e3-035d-4777-b3cc-1754b8b819b9 +host.host_id_configured=1 +host.host_nqn_configured=1 +host.primary=0 +hfi_list[0]->index=1 +hfi_list[0]->transport=tcp +hfi_list[0]->tcp_info.pci_sbdf=8 +hfi_list[0]->tcp_info.mac_addr=52540b819b9 +hfi_list[0]->tcp_info.vlan=0 +hfi_list[0]->tcp_info.ip_origin=3 +hfi_list[0]->tcp_info.ipaddr=fddf:d:f:49::eb +hfi_list[0]->tcp_info.subnet_mask_prefix=64 +hfi_list[0]->tcp_info.gateway_ipaddr=:: +hfi_list[0]->tcp_info.route_metric=0 +hfi_list[0]->tcp_info.primary_dns_ipaddr=:: +hfi_list[0]->tcp_info.secondary_dns_ipaddr=:: +hfi_list[0]->tcp_info.dhcp_server_ipaddr=:: +hfi_list[0]->tcp_info.host_name=nvmeof-sles +hfi_list[0]->tcp_info.this_hfi_is_default_route=1 +hfi_list[0]->tcp_info.dhcp_override=1 +subsystem_ns_list[0]->index=1 +subsystem_ns_list[0]->num_hfis=1 +subsystem_ns_list[0]->hfis[0]->index=1 +subsystem_ns_list[0]->hfis[1]->index=1 +subsystem_ns_list[0]->transport=tcp +subsystem_ns_list[0]->traddr=fddf:d:f:49::10 +subsystem_ns_list[0]->trsvcid=4420 +subsystem_ns_list[0]->subsys_port_id=0 +subsystem_ns_list[0]->nsid=1 +subsystem_ns_list[0]->nid_type=3 +subsystem_ns_list[0]->nid=df669a88bd6f4dd68a505f97eb55c835 +subsystem_ns_list[0]->subsys_nqn=nqn.2022-12.org.nvmexpress.boot.poc:bremer.vagrant-nvmet.subsys02 +subsystem_ns_list[0]->pdu_header_digest_required=0 +subsystem_ns_list[0]->data_digest_required=0 +subsystem_ns_list[0]->controller_id=34 +subsystem_ns_list[0]->asqsz=0 +subsystem_ns_list[0]->dhcp_root_path_string=(null) diff --git a/test/nbft/diffs/NBFT-rhpoc b/test/nbft/diffs/NBFT-rhpoc new file mode 100644 index 0000000..d4b4ad8 --- /dev/null +++ b/test/nbft/diffs/NBFT-rhpoc @@ -0,0 +1,39 @@ +raw_nbft_size=724 +host.id=b4bb164e7f9be448c7f77d8b4fc9f39 +host.nqn=nqn.2014-08.org.nvmexpress:uuid:f8131bac-cdef-4165-866b-5998c1e67890 +host.host_id_configured=1 +host.host_nqn_configured=1 +host.primary=0 +hfi_list[0]->index=1 +hfi_list[0]->transport=tcp +hfi_list[0]->tcp_info.pci_sbdf=40 +hfi_list[0]->tcp_info.mac_addr=eaebd3588958 +hfi_list[0]->tcp_info.vlan=0 +hfi_list[0]->tcp_info.ip_origin=1 +hfi_list[0]->tcp_info.ipaddr=192.168.101.30 +hfi_list[0]->tcp_info.subnet_mask_prefix=24 +hfi_list[0]->tcp_info.gateway_ipaddr=0.0.0.0 +hfi_list[0]->tcp_info.route_metric=0 +hfi_list[0]->tcp_info.primary_dns_ipaddr=0.0.0.0 +hfi_list[0]->tcp_info.secondary_dns_ipaddr=0.0.0.0 +hfi_list[0]->tcp_info.dhcp_server_ipaddr= +hfi_list[0]->tcp_info.host_name=host-vm +hfi_list[0]->tcp_info.this_hfi_is_default_route=1 +hfi_list[0]->tcp_info.dhcp_override=0 +subsystem_ns_list[0]->index=1 +subsystem_ns_list[0]->num_hfis=1 +subsystem_ns_list[0]->hfis[0]->index=1 +subsystem_ns_list[0]->hfis[1]->index=1 +subsystem_ns_list[0]->transport=tcp +subsystem_ns_list[0]->traddr=192.168.101.20 +subsystem_ns_list[0]->trsvcid=4420 +subsystem_ns_list[0]->subsys_port_id=0 +subsystem_ns_list[0]->nsid=1 +subsystem_ns_list[0]->nid_type=3 +subsystem_ns_list[0]->nid=bee9c2b7176144b5a4e6f69498a94b +subsystem_ns_list[0]->subsys_nqn=nqn.2014-08.org.nvmexpress:uuid:0c468c4d-a385-47e0-8299-6e95051277db +subsystem_ns_list[0]->pdu_header_digest_required=0 +subsystem_ns_list[0]->data_digest_required=0 +subsystem_ns_list[0]->controller_id=12 +subsystem_ns_list[0]->asqsz=0 +subsystem_ns_list[0]->dhcp_root_path_string=(null) diff --git a/test/nbft/diffs/NBFT-static-ipv4 b/test/nbft/diffs/NBFT-static-ipv4 new file mode 100644 index 0000000..715b30d --- /dev/null +++ b/test/nbft/diffs/NBFT-static-ipv4 @@ -0,0 +1,39 @@ +raw_nbft_size=725 +host.id=e359b7a15d37747b3cc1754b8b819b9 +host.nqn=nqn.2014-08.org.nvmexpress:uuid:a1b759e3-035d-4777-b3cc-1754b8b819b9 +host.host_id_configured=1 +host.host_nqn_configured=1 +host.primary=0 +hfi_list[0]->index=1 +hfi_list[0]->transport=tcp +hfi_list[0]->tcp_info.pci_sbdf=8 +hfi_list[0]->tcp_info.mac_addr=52540b819b9 +hfi_list[0]->tcp_info.vlan=0 +hfi_list[0]->tcp_info.ip_origin=1 +hfi_list[0]->tcp_info.ipaddr=192.168.49.50 +hfi_list[0]->tcp_info.subnet_mask_prefix=24 +hfi_list[0]->tcp_info.gateway_ipaddr=0.0.0.0 +hfi_list[0]->tcp_info.route_metric=0 +hfi_list[0]->tcp_info.primary_dns_ipaddr=0.0.0.0 +hfi_list[0]->tcp_info.secondary_dns_ipaddr=0.0.0.0 +hfi_list[0]->tcp_info.dhcp_server_ipaddr= +hfi_list[0]->tcp_info.host_name=nvmeof-sles +hfi_list[0]->tcp_info.this_hfi_is_default_route=1 +hfi_list[0]->tcp_info.dhcp_override=0 +subsystem_ns_list[0]->index=1 +subsystem_ns_list[0]->num_hfis=1 +subsystem_ns_list[0]->hfis[0]->index=1 +subsystem_ns_list[0]->hfis[1]->index=1 +subsystem_ns_list[0]->transport=tcp +subsystem_ns_list[0]->traddr=192.168.49.10 +subsystem_ns_list[0]->trsvcid=4420 +subsystem_ns_list[0]->subsys_port_id=0 +subsystem_ns_list[0]->nsid=1 +subsystem_ns_list[0]->nid_type=3 +subsystem_ns_list[0]->nid=df669a88bd6f4dd68a505f97eb55c835 +subsystem_ns_list[0]->subsys_nqn=nqn.2022-12.org.nvmexpress.boot.poc:bremer.vagrant-nvmet.subsys02 +subsystem_ns_list[0]->pdu_header_digest_required=0 +subsystem_ns_list[0]->data_digest_required=0 +subsystem_ns_list[0]->controller_id=38 +subsystem_ns_list[0]->asqsz=0 +subsystem_ns_list[0]->dhcp_root_path_string=(null) diff --git a/test/nbft/diffs/NBFT-static-ipv4-discovery b/test/nbft/diffs/NBFT-static-ipv4-discovery new file mode 100644 index 0000000..67881b6 --- /dev/null +++ b/test/nbft/diffs/NBFT-static-ipv4-discovery @@ -0,0 +1,44 @@ +raw_nbft_size=825 +host.id=e359b7a15d37747b3cc1754b8b819b9 +host.nqn=nqn.2014-08.org.nvmexpress:uuid:a1b759e3-035d-4777-b3cc-1754b8b819b9 +host.host_id_configured=1 +host.host_nqn_configured=1 +host.primary=0 +hfi_list[0]->index=1 +hfi_list[0]->transport=tcp +hfi_list[0]->tcp_info.pci_sbdf=8 +hfi_list[0]->tcp_info.mac_addr=52540b819b9 +hfi_list[0]->tcp_info.vlan=0 +hfi_list[0]->tcp_info.ip_origin=1 +hfi_list[0]->tcp_info.ipaddr=192.168.49.50 +hfi_list[0]->tcp_info.subnet_mask_prefix=24 +hfi_list[0]->tcp_info.gateway_ipaddr=0.0.0.0 +hfi_list[0]->tcp_info.route_metric=0 +hfi_list[0]->tcp_info.primary_dns_ipaddr=0.0.0.0 +hfi_list[0]->tcp_info.secondary_dns_ipaddr=0.0.0.0 +hfi_list[0]->tcp_info.dhcp_server_ipaddr= +hfi_list[0]->tcp_info.host_name=nvmeof-sles +hfi_list[0]->tcp_info.this_hfi_is_default_route=1 +hfi_list[0]->tcp_info.dhcp_override=0 +discovery_list[0]->index=1 +discovery_list[0]->hfi->index=1 +discovery_list[0]->uri=nvme+tcp://192.168.49.10:4420/ +discovery_list[0]->nqn=nqn.2014-08.org.nvmexpress.discovery +subsystem_ns_list[0]->index=1 +subsystem_ns_list[0]->discovery->index=1 +subsystem_ns_list[0]->num_hfis=1 +subsystem_ns_list[0]->hfis[0]->index=1 +subsystem_ns_list[0]->hfis[1]->index=1 +subsystem_ns_list[0]->transport=tcp +subsystem_ns_list[0]->traddr=192.168.49.10 +subsystem_ns_list[0]->trsvcid=4420 +subsystem_ns_list[0]->subsys_port_id=0 +subsystem_ns_list[0]->nsid=1 +subsystem_ns_list[0]->nid_type=3 +subsystem_ns_list[0]->nid=df669a88bd6f4dd68a505f97eb55c835 +subsystem_ns_list[0]->subsys_nqn=nqn.2022-12.org.nvmexpress.boot.poc:bremer.vagrant-nvmet.subsys02 +subsystem_ns_list[0]->pdu_header_digest_required=0 +subsystem_ns_list[0]->data_digest_required=0 +subsystem_ns_list[0]->controller_id=13 +subsystem_ns_list[0]->asqsz=0 +subsystem_ns_list[0]->dhcp_root_path_string=(null) diff --git a/test/nbft/diffs/NBFT-static-ipv6 b/test/nbft/diffs/NBFT-static-ipv6 new file mode 100644 index 0000000..a5b02c1 --- /dev/null +++ b/test/nbft/diffs/NBFT-static-ipv6 @@ -0,0 +1,39 @@ +raw_nbft_size=721 +host.id=1ee8b170eb4c864fb7957d179e201a +host.nqn=nqn.2014-08.org.nvmexpress:uuid:70b1e81e-4ceb-4f86-b709-57d1079e201a +host.host_id_configured=1 +host.host_nqn_configured=1 +host.primary=0 +hfi_list[0]->index=1 +hfi_list[0]->transport=tcp +hfi_list[0]->tcp_info.pci_sbdf=512 +hfi_list[0]->tcp_info.mac_addr=525409e201a +hfi_list[0]->tcp_info.vlan=0 +hfi_list[0]->tcp_info.ip_origin=1 +hfi_list[0]->tcp_info.ipaddr=fd09:9a46:b5c1:1fe::10 +hfi_list[0]->tcp_info.subnet_mask_prefix=64 +hfi_list[0]->tcp_info.gateway_ipaddr=:: +hfi_list[0]->tcp_info.route_metric=0 +hfi_list[0]->tcp_info.primary_dns_ipaddr=:: +hfi_list[0]->tcp_info.secondary_dns_ipaddr=:: +hfi_list[0]->tcp_info.dhcp_server_ipaddr= +hfi_list[0]->tcp_info.host_name=nvmepoc-sles15-sp5 +hfi_list[0]->tcp_info.this_hfi_is_default_route=1 +hfi_list[0]->tcp_info.dhcp_override=0 +subsystem_ns_list[0]->index=1 +subsystem_ns_list[0]->num_hfis=1 +subsystem_ns_list[0]->hfis[0]->index=1 +subsystem_ns_list[0]->hfis[1]->index=1 +subsystem_ns_list[0]->transport=tcp +subsystem_ns_list[0]->traddr=fd09:9a46:b5c1:1fe::13f +subsystem_ns_list[0]->trsvcid=4420 +subsystem_ns_list[0]->subsys_port_id=0 +subsystem_ns_list[0]->nsid=1 +subsystem_ns_list[0]->nid_type=3 +subsystem_ns_list[0]->nid=aab2c3c8444c47c599f23632e6364528 +subsystem_ns_list[0]->subsys_nqn=nqn.2022-12.de.suse.mwilck:zeus.vagrant-nvmet.subsys04 +subsystem_ns_list[0]->pdu_header_digest_required=0 +subsystem_ns_list[0]->data_digest_required=0 +subsystem_ns_list[0]->controller_id=9 +subsystem_ns_list[0]->asqsz=0 +subsystem_ns_list[0]->dhcp_root_path_string=(null) diff --git a/test/nbft/gen-nbft-diffs.sh.in b/test/nbft/gen-nbft-diffs.sh.in new file mode 100755 index 0000000..8b0b982 --- /dev/null +++ b/test/nbft/gen-nbft-diffs.sh.in @@ -0,0 +1,5 @@ +#!/bin/sh + +for T in "@TABLES_DIR@"/*; do + "@NBFT_DUMP_PATH@" "$T" > "@DIFF_DIR@/`basename $T`" +done diff --git a/test/nbft/meson.build b/test/nbft/meson.build new file mode 100644 index 0000000..67b2d95 --- /dev/null +++ b/test/nbft/meson.build @@ -0,0 +1,83 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +# +# This file is part of libnvme. +# Copyright (c) 2023 Red Hat Inc. +# +# Authors: Tomas Bzatek <tbzatek@redhat.com> + +# NBFT parser tests over supplied NBFT ACPI table dumps + +tables_dir = 'tables' +tables_bad_dir = 'tables_bad' +diff_dir = 'diffs' + +tables = [ + 'NBFT-auto-ipv6', + 'NBFT-dhcp-ipv6', + 'NBFT-rhpoc', + 'NBFT-static-ipv4', + 'NBFT-static-ipv4-discovery', + 'NBFT-static-ipv6', +] + +tables_bad = [ + 'NBFT-bad-oldspec', + 'NBFT-random-noise', +] + +nbft_dump = executable( + 'nbft-dump', + ['nbft-dump.c'], + dependencies: libnvme_dep, + include_directories: [incdir, internal_incdir] +) + + +helper_data = configuration_data() +helper_data.set('NBFT_DUMP_PATH', nbft_dump.full_path()) +helper_data.set('TABLES_DIR', meson.current_source_dir()/tables_dir) +helper_data.set('DIFF_DIR', meson.current_source_dir()/diff_dir) + +dump_helper = configure_file( + input: 'nbft-dump-diff.sh.in', + output: '@BASENAME@', + configuration: helper_data +) + +gen_diffs_helper = configure_file( + input: 'gen-nbft-diffs.sh.in', + output: '@BASENAME@', + configuration: helper_data +) + + +run_target( + 'nbft-diffs', + depends: nbft_dump, + command: [gen_diffs_helper] +) + + +diffcmd = find_program( + 'diff', + required: false +) +if diffcmd.found() + foreach table: tables + test( + table, + dump_helper, + args: [files(tables_dir/table), + files(diff_dir/table)] + ) + endforeach +endif + +foreach table: tables_bad + test( + table, + nbft_dump, + args: [files(tables_bad_dir/table)], + should_fail: true + ) +endforeach diff --git a/test/nbft/nbft-dump-diff.sh.in b/test/nbft/nbft-dump-diff.sh.in new file mode 100755 index 0000000..f697bce --- /dev/null +++ b/test/nbft/nbft-dump-diff.sh.in @@ -0,0 +1,8 @@ +#!/bin/sh + +if [ $# -ne 2 ]; then + echo "Usage: $0 TABLE DIFF" >&2 + exit 255 +fi + +"@NBFT_DUMP_PATH@" "$1" | diff --unified "$2" - diff --git a/test/nbft/nbft-dump.c b/test/nbft/nbft-dump.c new file mode 100644 index 0000000..3ff5efa --- /dev/null +++ b/test/nbft/nbft-dump.c @@ -0,0 +1,121 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/** + * This file is part of libnvme. + * Copyright (c) 2023 Red Hat Inc. + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <inttypes.h> +#include "libnvme.h" + +static void print_hex(unsigned char *buf, int len) +{ + int i; + + for (i = 0; i < len; i++, buf++) + printf("%x", *buf); +} + +static void print_nbft(struct nbft_info *table) +{ + unsigned int i, j; + struct nbft_info_hfi **hfi; + struct nbft_info_security **sec; + struct nbft_info_discovery **disc; + struct nbft_info_subsystem_ns **ssns; + + printf("raw_nbft_size=%zd\n", table->raw_nbft_size); + + printf("host.id="); + print_hex(table->host.id, NVME_UUID_LEN); + printf("\n"); + printf("host.nqn=%s\n", table->host.nqn); + printf("host.host_id_configured=%d\n", table->host.host_id_configured); + printf("host.host_nqn_configured=%d\n", table->host.host_nqn_configured); + printf("host.primary=%d\n", table->host.primary); + + for (hfi = table->hfi_list, i = 0; hfi && *hfi; hfi++, i++) { + printf("hfi_list[%u]->index=%d\n", i, (*hfi)->index); + printf("hfi_list[%u]->transport=%.*s\n", i, (int)sizeof((*hfi)->transport), (*hfi)->transport); + printf("hfi_list[%u]->tcp_info.pci_sbdf=%"PRIu32"\n", i, (*hfi)->tcp_info.pci_sbdf); + printf("hfi_list[%u]->tcp_info.mac_addr=", i); + print_hex((*hfi)->tcp_info.mac_addr, sizeof((*hfi)->tcp_info.mac_addr)); + printf("\n"); + printf("hfi_list[%u]->tcp_info.vlan=%"PRIu16"\n", i, (*hfi)->tcp_info.vlan); + printf("hfi_list[%u]->tcp_info.ip_origin=%u\n", i, (*hfi)->tcp_info.ip_origin); + printf("hfi_list[%u]->tcp_info.ipaddr=%s\n", i, (*hfi)->tcp_info.ipaddr); + printf("hfi_list[%u]->tcp_info.subnet_mask_prefix=%u\n", i, (*hfi)->tcp_info.subnet_mask_prefix); + printf("hfi_list[%u]->tcp_info.gateway_ipaddr=%s\n", i, (*hfi)->tcp_info.gateway_ipaddr); + printf("hfi_list[%u]->tcp_info.route_metric=%"PRIu16"\n", i, (*hfi)->tcp_info.route_metric); + printf("hfi_list[%u]->tcp_info.primary_dns_ipaddr=%s\n", i, (*hfi)->tcp_info.primary_dns_ipaddr); + printf("hfi_list[%u]->tcp_info.secondary_dns_ipaddr=%s\n", i, (*hfi)->tcp_info.secondary_dns_ipaddr); + printf("hfi_list[%u]->tcp_info.dhcp_server_ipaddr=%s\n", i, (*hfi)->tcp_info.dhcp_server_ipaddr); + printf("hfi_list[%u]->tcp_info.host_name=%s\n", i, (*hfi)->tcp_info.host_name); + printf("hfi_list[%u]->tcp_info.this_hfi_is_default_route=%d\n", i, (*hfi)->tcp_info.this_hfi_is_default_route); + printf("hfi_list[%u]->tcp_info.dhcp_override=%d\n", i, (*hfi)->tcp_info.dhcp_override); + } + + for (sec = table->security_list, i = 0; sec && *sec; sec++, i++) { + printf("security_list[%u]->index=%d\n", i, (*sec)->index); + } + + for (disc = table->discovery_list, i = 0; disc && *disc; disc++, i++) { + printf("discovery_list[%u]->index=%d\n", i, (*disc)->index); + if ((*disc)->security) + printf("discovery_list[%u]->security->index=%d\n", i, (*disc)->security->index); + if ((*disc)->hfi) + printf("discovery_list[%u]->hfi->index=%d\n", i, (*disc)->hfi->index); + printf("discovery_list[%u]->uri=%s\n", i, (*disc)->uri); + printf("discovery_list[%u]->nqn=%s\n", i, (*disc)->nqn); + } + + for (ssns = table->subsystem_ns_list, i = 0; ssns && *ssns; ssns++, i++) { + printf("subsystem_ns_list[%u]->index=%d\n", i, (*ssns)->index); + if ((*ssns)->discovery) + printf("subsystem_ns_list[%u]->discovery->index=%d\n", i, (*ssns)->discovery->index); + if ((*ssns)->security) + printf("subsystem_ns_list[%u]->security->index=%d\n", i, (*ssns)->security->index); + printf("subsystem_ns_list[%u]->num_hfis=%d\n", i, (*ssns)->num_hfis); + for (hfi = (*ssns)->hfis, j = 0; hfi && *hfi; hfi++, j++) + printf("subsystem_ns_list[%u]->hfis[%u]->index=%d\n", i, j, (*hfi)->index); + printf("subsystem_ns_list[%u]->transport=%s\n", i, (*ssns)->transport); + printf("subsystem_ns_list[%u]->traddr=%s\n", i, (*ssns)->traddr); + printf("subsystem_ns_list[%u]->trsvcid=%s\n", i, (*ssns)->trsvcid); + printf("subsystem_ns_list[%u]->subsys_port_id=%"PRIu16"\n", i, (*ssns)->subsys_port_id); + printf("subsystem_ns_list[%u]->nsid=%"PRIu32"\n", i, (*ssns)->nsid); + printf("subsystem_ns_list[%u]->nid_type=%d\n", i, (*ssns)->nid_type); + printf("subsystem_ns_list[%u]->nid=", i); + print_hex((*ssns)->nid, 16); + printf("\n"); + printf("subsystem_ns_list[%u]->subsys_nqn=%s\n", i, (*ssns)->subsys_nqn); + printf("subsystem_ns_list[%u]->pdu_header_digest_required=%d\n", i, (*ssns)->pdu_header_digest_required); + printf("subsystem_ns_list[%u]->data_digest_required=%d\n", i, (*ssns)->data_digest_required); + printf("subsystem_ns_list[%u]->controller_id=%d\n", i, (*ssns)->controller_id); + printf("subsystem_ns_list[%u]->asqsz=%d\n", i, (*ssns)->asqsz); + printf("subsystem_ns_list[%u]->dhcp_root_path_string=%s\n", i, (*ssns)->dhcp_root_path_string); + } +} + +int main(int argc, char **argv) +{ + struct nbft_info *table = NULL; + + if (argc < 2) { + fprintf(stderr, "Usage: %s TABLE\n", argv[0]); + return 1; + } + + if (nvme_nbft_read(&table, argv[1]) != 0) { + fprintf(stderr, "Error parsing the NBFT table %s: %m\n", + argv[1]); + return 2; + } + + print_nbft(table); + + nvme_nbft_free(table); + return 0; +} diff --git a/test/nbft/tables/NBFT-auto-ipv6 b/test/nbft/tables/NBFT-auto-ipv6 Binary files differnew file mode 100644 index 0000000..64457d7 --- /dev/null +++ b/test/nbft/tables/NBFT-auto-ipv6 diff --git a/test/nbft/tables/NBFT-dhcp-ipv4 b/test/nbft/tables/NBFT-dhcp-ipv4 Binary files differnew file mode 100644 index 0000000..1af159d --- /dev/null +++ b/test/nbft/tables/NBFT-dhcp-ipv4 diff --git a/test/nbft/tables/NBFT-dhcp-ipv6 b/test/nbft/tables/NBFT-dhcp-ipv6 Binary files differnew file mode 100644 index 0000000..20715ee --- /dev/null +++ b/test/nbft/tables/NBFT-dhcp-ipv6 diff --git a/test/nbft/tables/NBFT-rhpoc b/test/nbft/tables/NBFT-rhpoc Binary files differnew file mode 100644 index 0000000..5d0a6cc --- /dev/null +++ b/test/nbft/tables/NBFT-rhpoc diff --git a/test/nbft/tables/NBFT-static-ipv4 b/test/nbft/tables/NBFT-static-ipv4 Binary files differnew file mode 100644 index 0000000..bf3f840 --- /dev/null +++ b/test/nbft/tables/NBFT-static-ipv4 diff --git a/test/nbft/tables/NBFT-static-ipv4-discovery b/test/nbft/tables/NBFT-static-ipv4-discovery Binary files differnew file mode 100644 index 0000000..7ebb40e --- /dev/null +++ b/test/nbft/tables/NBFT-static-ipv4-discovery diff --git a/test/nbft/tables/NBFT-static-ipv6 b/test/nbft/tables/NBFT-static-ipv6 Binary files differnew file mode 100644 index 0000000..07b09cf --- /dev/null +++ b/test/nbft/tables/NBFT-static-ipv6 diff --git a/test/nbft/tables_bad/NBFT-bad-oldspec b/test/nbft/tables_bad/NBFT-bad-oldspec Binary files differnew file mode 100644 index 0000000..e09d6ad --- /dev/null +++ b/test/nbft/tables_bad/NBFT-bad-oldspec diff --git a/test/nbft/tables_bad/NBFT-random-noise b/test/nbft/tables_bad/NBFT-random-noise Binary files differnew file mode 100644 index 0000000..296bcfe --- /dev/null +++ b/test/nbft/tables_bad/NBFT-random-noise diff --git a/test/test-util.c b/test/test-util.c new file mode 100644 index 0000000..e32f030 --- /dev/null +++ b/test/test-util.c @@ -0,0 +1,122 @@ +/** + SPDX-License-Identifier: LGPL-2.1-or-later + + This file is part of libnvme. + Copyright (c) 2023 Dell Inc. + + Authors: Martin Belanger <Martin.Belanger@dell.com> +*/ + +/** + * In this file we test private and public functions found in + * "src/nvme/util.c". Note that the source files are included + * directly because the private functions are not available from + * the libnvme.so. + */ + +#include <stdlib.h> +#include <stdio.h> +#include <stdbool.h> +#include <netdb.h> +#include <string.h> + +#include "nvme/cleanup.c" /* to resolve cleanup_charp() */ +#include "nvme/log.c" /* to resolve __nvme_msg() */ +#include "nvme/util.c" + +static size_t safe_strlen(const char *p) { + return p ? strlen(p) : strlen("null"); +} + +static bool test_nvme_get_version(enum nvme_version type, const char * exp_str) { + const char * str; + str = nvme_get_version(type); + return !strcmp(str, exp_str); +} + +static bool test_ipaddrs_eq() { + int test_success = true; + static const char *x = "1.1.1.1"; + struct { + const char *a; + const char *b; + bool exp_result; + } addrs[] = { + {"192.168.56.101", "192.168.56.101", true}, + {"2001:0db8:0000:0000:0000:ff00:0042:8329", "2001:0db8::ff00:0042:8329", true}, + {NULL, NULL, true}, + {x, x, true}, + {"::ffff:192.168.56.101", "::ffff:192.168.56.101", true}, + {"::ffff:192.168.56.101", "192.168.56.101", true}, + {"192.168.56.101", "::ffff:192.168.56.101", true}, + {"::ffff:192.168.56.222", "192.168.56.101", false}, + {"192.168.56.101", "::ffff:192.168.56.222", false}, + {"1.2.3.4", "192.168.56.101", false}, + {"!@#$", "192.168.56.101", false}, + {"192.168.56.101", "!@#$", false}, + {"2001:0db8:0001:0000:0000:ff00:0042:8329", "2001:0db8::ff00:0042:8329", false}, + {"2001:0db8:0001:0000:0000:ff00:0042:8329", NULL, false}, + }; + + size_t i; + size_t n = sizeof(addrs) / sizeof(addrs[0]); + size_t longest_a = 0, longest_b = 0; + + for (i = 0; i < n; i++) { + size_t l; + l = safe_strlen(addrs[i].a); + if (l > longest_a) longest_a = l; + l = safe_strlen(addrs[i].b); + if (l > longest_b) longest_b = l; + } + + for (i = 0; i < n; i++) { + bool result = nvme_ipaddrs_eq(addrs[i].a, addrs[i].b); + bool pass = result == addrs[i].exp_result; + int pad_a = longest_a - safe_strlen(addrs[i].a); + int pad_b = longest_b - safe_strlen(addrs[i].b); + printf("%s %*.*s %s %*.*s -> %-10s %s\n", + addrs[i].a ? addrs[i].a : "null", + pad_a, pad_a, "", + addrs[i].b ? addrs[i].b : "null", + pad_b, pad_b, "", + result ? "equal/same" : "different", + pass ? "[PASS]" : "[FAIL]"); + + if (!pass) + test_success = false; + } + + return test_success; +} + +int main(int argc, char *argv[]) { + int exit_val = EXIT_SUCCESS; + bool pass; + + printf("\n------------------------------------------------------------------------------\n"); + pass = test_nvme_get_version(NVME_VERSION_PROJECT, PROJECT_VERSION); + printf("nvme_get_version(NVME_VERSION_PROJECT) %s\n", pass ? "[PASS]" : "[FAIL]"); + if (!pass) + exit_val = EXIT_FAILURE; + + printf("\n------------------------------------------------------------------------------\n"); + pass = test_nvme_get_version(NVME_VERSION_GIT, GIT_VERSION); + printf("nvme_get_version(NVME_VERSION_GIT) %s\n", pass ? "[PASS]" : "[FAIL]"); + if (!pass) + exit_val = EXIT_FAILURE; + + printf("\n------------------------------------------------------------------------------\n"); + pass = test_nvme_get_version(-1, "n/a"); + printf("nvme_get_version(-1) %s\n", pass ? "[PASS]" : "[FAIL]"); + if (!pass) + exit_val = EXIT_FAILURE; + + printf("\n------------------------------------------------------------------------------\n"); + pass = test_ipaddrs_eq(); + printf("nvme_ipaddrs_eq() %s", pass ? "[PASS]" : "[FAIL]"); + if (!pass) + exit_val = EXIT_FAILURE; + + exit(exit_val); +} diff --git a/test/tree.c b/test/tree.c new file mode 100644 index 0000000..b3baac8 --- /dev/null +++ b/test/tree.c @@ -0,0 +1,263 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/** + * This file is part of libnvme. + * Copyright (c) 2023 Daniel Wagner, SUSE LLC + */ + +#include <assert.h> +#include <string.h> + +#include <ccan/array_size/array_size.h> + +#include <libnvme.h> + +struct test_data { + /* input data */ + const char *subsysname; + const char *subsysnqn; + const char *transport; + const char *traddr; + const char *host_traddr; + const char *host_iface; + const char *trsvcid; + + /* track controller generated by input data */ + nvme_subsystem_t s; + nvme_ctrl_t c; + int ctrl_id; +}; + +#define DEFAULT_SUBSYSNAME "subsysname" +#define DEFAULT_SUBSYSNQN "subsysnqn" + +struct test_data test_data[] = { + { DEFAULT_SUBSYSNAME, DEFAULT_SUBSYSNQN, "tcp", "192.168.1.1", "192.168.1.20", NULL, "4420" }, + { DEFAULT_SUBSYSNAME, DEFAULT_SUBSYSNQN, "tcp", "192.168.1.1", "192.168.1.20", NULL, "4421" }, + { DEFAULT_SUBSYSNAME, DEFAULT_SUBSYSNQN, "tcp", "192.168.1.2", "192.168.1.20", "eth1", "4420" }, + { DEFAULT_SUBSYSNAME, DEFAULT_SUBSYSNQN, "tcp", "192.168.1.2", "192.168.1.20", "eth1", "4421" }, + { DEFAULT_SUBSYSNAME, DEFAULT_SUBSYSNQN, "rdma", "192.168.1.3", "192.168.1.20", NULL, NULL }, + { DEFAULT_SUBSYSNAME, DEFAULT_SUBSYSNQN, "rdma", "192.168.1.4", "192.168.1.20", NULL, NULL }, + { DEFAULT_SUBSYSNAME, DEFAULT_SUBSYSNQN, "fc", + "nn-0x201700a09890f5bf:pn-0x201900a09890f5bf", + "nn-0x200000109b579ef3:pn-0x100000109b579ef3" + }, + { DEFAULT_SUBSYSNAME, DEFAULT_SUBSYSNQN, "fc", + "nn-0x201700a09890f5bf:pn-0x201900a09890f5bf", + "nn-0x200000109b579ef6:pn-0x100000109b579ef6", + }, +}; + +static struct test_data *find_test_data(nvme_ctrl_t c) +{ + for (int i = 0; i < ARRAY_SIZE(test_data); i++) { + struct test_data *d = &test_data[i]; + + if (d->c == c) + return d; + } + + return NULL; +} + +static void show_ctrl(nvme_ctrl_t c) +{ + struct test_data *d = find_test_data(c); + + if (d) + printf("ctrl%d ", d->ctrl_id); + + printf("0x%p: %s %s %s %s %s\n", + c, + nvme_ctrl_get_transport(c), + nvme_ctrl_get_traddr(c), + nvme_ctrl_get_host_traddr(c), + nvme_ctrl_get_host_iface(c), + nvme_ctrl_get_trsvcid(c)); +} + +static nvme_root_t create_tree() +{ + nvme_root_t r; + nvme_host_t h; + + r = nvme_create_root(stdout, LOG_DEBUG); + assert(r); + h = nvme_default_host(r); + assert(h); + + printf(" ctrls created:\n"); + for (int i = 0; i < ARRAY_SIZE(test_data); i++) { + struct test_data *d = &test_data[i]; + + d->s = nvme_lookup_subsystem(h, d->subsysname, d->subsysnqn); + assert(d->s); + d->c = nvme_lookup_ctrl(d->s, d->transport, d->traddr, + d->host_traddr, d->host_iface, + d->trsvcid, NULL); + assert(d->c); + d->ctrl_id = i; + + assert(!strcmp(d->transport, nvme_ctrl_get_transport(d->c))); + assert(!strcmp(d->traddr, nvme_ctrl_get_traddr(d->c))); + assert(!d->host_traddr || !strcmp(d->host_traddr, nvme_ctrl_get_host_traddr(d->c))); + assert(!d->host_iface || !strcmp(d->host_iface, nvme_ctrl_get_host_iface(d->c))); + assert(!d->trsvcid || !strcmp(d->trsvcid, nvme_ctrl_get_trsvcid(d->c))); + + printf(" "); + show_ctrl(d->c); + } + printf("\n"); + + return r; +} + +static unsigned int count_entries(nvme_root_t r) +{ + nvme_host_t h; + nvme_subsystem_t s; + nvme_ctrl_t c; + unsigned int i = 0; + + nvme_for_each_host(r, h) { + nvme_for_each_subsystem(h, s) { + nvme_subsystem_for_each_ctrl(s, c) { + i++; + } + } + } + + return i; +} + +static void ctrl_lookups(nvme_root_t r) +{ + nvme_host_t h; + nvme_subsystem_t s; + nvme_ctrl_t c; + + h = nvme_first_host(r); + s = nvme_lookup_subsystem(h, DEFAULT_SUBSYSNAME, DEFAULT_SUBSYSNQN); + + printf(" lookup controller:\n"); + for (int i = 0; i < ARRAY_SIZE(test_data); i++) { + struct test_data *d = &test_data[i]; + + printf("%10s %10s ", "", ""); + show_ctrl(d->c); + c = nvme_lookup_ctrl(s, d->transport, d->traddr, d->host_traddr, + NULL, NULL, NULL); + printf("%10s %10s -> ", "-", "-"); + show_ctrl(c); + + assert(!strcmp(d->transport, nvme_ctrl_get_transport(c))); + assert(!strcmp(d->traddr, nvme_ctrl_get_traddr(c))); + assert(!strcmp(d->host_traddr, nvme_ctrl_get_host_traddr(c))); + + if (d->host_iface) { + c = nvme_lookup_ctrl(s, d->transport, d->traddr, d->host_traddr, + d->host_iface, NULL, NULL); + printf("%10s %10s -> ", d->host_iface, "-"); + show_ctrl(c); + + assert(!strcmp(d->transport, nvme_ctrl_get_transport(c))); + assert(!strcmp(d->traddr, nvme_ctrl_get_traddr(c))); + assert(!strcmp(d->host_traddr, nvme_ctrl_get_host_traddr(c))); + assert(!strcmp(d->host_iface, nvme_ctrl_get_host_iface(c))); + } + + if (d->trsvcid) { + c = nvme_lookup_ctrl(s, d->transport, d->traddr, d->host_traddr, + NULL, d->trsvcid, NULL); + printf("%10s %10s -> ", "-", d->trsvcid); + show_ctrl(c); + + assert(!strcmp(d->transport, nvme_ctrl_get_transport(c))); + assert(!strcmp(d->traddr, nvme_ctrl_get_traddr(c))); + assert(!strcmp(d->host_traddr, nvme_ctrl_get_host_traddr(c))); + assert(!strcmp(d->trsvcid, nvme_ctrl_get_trsvcid(c))); + } + + if (d->host_iface && d->trsvcid) { + c = nvme_lookup_ctrl(s, d->transport, d->traddr, d->host_traddr, + d->host_iface, d->trsvcid, NULL); + printf("%10s %10s -> ", d->host_iface, d->trsvcid); + show_ctrl(c); + + assert(!strcmp(d->transport, nvme_ctrl_get_transport(c))); + assert(!strcmp(d->traddr, nvme_ctrl_get_traddr(c))); + assert(!strcmp(d->host_traddr, nvme_ctrl_get_host_traddr(c))); + assert(!strcmp(d->trsvcid, nvme_ctrl_get_trsvcid(c))); + assert(!strcmp(d->host_iface, nvme_ctrl_get_host_iface(c))); + } + + printf("\n"); + } +} + +static void test_lookup_1(void) +{ + nvme_root_t r; + + printf("test_lookup_1:\n"); + + r = create_tree(); + assert(count_entries(r) == ARRAY_SIZE(test_data)); + ctrl_lookups(r); + + nvme_free_tree(r); +} + +static void test_lookup_2(void) +{ + nvme_root_t r; + nvme_subsystem_t s; + nvme_host_t h; + nvme_ctrl_t c1, c2, c3, c4; + + printf("test_lookup_2:\n"); + + r = nvme_create_root(stdout, LOG_DEBUG); + assert(r); + h = nvme_default_host(r); + assert(h); + + s = nvme_lookup_subsystem(h, DEFAULT_SUBSYSNAME, DEFAULT_SUBSYSNQN); + assert(s); + + assert(nvme_lookup_ctrl(s, "tcp", "192.168.2.1", "192.168.2.20", + "eth0", "4420", NULL)); + + c1 = nvme_lookup_ctrl(s, "tcp", "192.168.1.1", "192.168.1.20", + NULL, NULL, NULL); + assert(c1); + printf("%10s %10s ", "", ""); + show_ctrl(c1); + + c2 = nvme_lookup_ctrl(s, "tcp", "192.168.1.1", "192.168.1.20", + "eth0", NULL, NULL); + assert(c1 == c2); + printf("%10s %10s ", "eth0", "-"); + show_ctrl(c2); + + c3 = nvme_lookup_ctrl(s, "tcp", "192.168.1.1", "192.168.1.20", + NULL, "4420", NULL); + assert(c1 == c3); + printf("%10s %10s ", "-", "4420"); + show_ctrl(c3); + + c4 = nvme_lookup_ctrl(s, "tcp", "192.168.1.1", "192.168.1.20", + "eth0", "4420", NULL); + assert(c1 == c4); + printf("%10s %10s ", "eth0", "4420"); + show_ctrl(c4); + + nvme_free_tree(r); +} + +int main(int argc, char *argv[]) +{ + test_lookup_1(); + test_lookup_2(); + + return 0; +} |