Merging upstream version 1.10.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
05578a6ab9
commit
a02d194ad0
946 changed files with 4401 additions and 1290 deletions
24
test/config/config-diff.sh
Normal file
24
test/config/config-diff.sh
Normal file
|
@ -0,0 +1,24 @@
|
|||
#!/bin/bash -e
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
BUILD_DIR=$1
|
||||
CONFIG_DUMP=$2
|
||||
SYSDIR_INPUT=$3
|
||||
CONFIG_JSON=$4
|
||||
EXPECTED_OUTPUT=$5
|
||||
|
||||
ACTUAL_OUTPUT="${BUILD_DIR}"/$(basename "${EXPECTED_OUTPUT}")
|
||||
|
||||
TEST_NAME="$(basename -s .tar.xz $SYSDIR_INPUT)"
|
||||
TEST_DIR="$BUILD_DIR/$TEST_NAME"
|
||||
|
||||
rm -rf "${TEST_DIR}"
|
||||
mkdir "${TEST_DIR}"
|
||||
tar -x -f "${SYSDIR_INPUT}" -C "${TEST_DIR}"
|
||||
|
||||
LIBNVME_SYSFS_PATH="$TEST_DIR" \
|
||||
LIBNVME_HOSTNQN=nqn.2014-08.org.nvmexpress:uuid:ce4fee3e-c02c-11ee-8442-830d068a36c6 \
|
||||
LIBNVME_HOSTID=ce4fee3e-c02c-11ee-8442-830d068a36c6 \
|
||||
"${CONFIG_DUMP}" "${CONFIG_JSON}" > "${ACTUAL_OUTPUT}" || echo "test failed"
|
||||
|
||||
diff -u "${EXPECTED_OUTPUT}" "${ACTUAL_OUTPUT}"
|
53
test/config/config-dump.c
Normal file
53
test/config/config-dump.c
Normal file
|
@ -0,0 +1,53 @@
|
|||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/**
|
||||
* This file is part of libnvme.
|
||||
* Copyright (c) 2024 Daniel Wagner, SUSE LLC
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <libnvme.h>
|
||||
|
||||
static bool config_dump(const char *file)
|
||||
{
|
||||
bool pass = false;
|
||||
nvme_root_t r;
|
||||
int err;
|
||||
|
||||
r = nvme_create_root(stderr, LOG_ERR);
|
||||
if (!r)
|
||||
return false;
|
||||
|
||||
err = nvme_scan_topology(r, NULL, NULL);
|
||||
if (err) {
|
||||
if (errno != ENOENT)
|
||||
goto out;
|
||||
}
|
||||
|
||||
err = nvme_read_config(r, file);
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
err = nvme_dump_config(r);
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
pass = true;
|
||||
|
||||
out:
|
||||
nvme_free_tree(r);
|
||||
return pass;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
bool pass;
|
||||
|
||||
pass = config_dump(argv[1]);
|
||||
fflush(stdout);
|
||||
|
||||
exit(pass ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
}
|
48
test/config/data/config-pcie-with-tcp-config.json
Normal file
48
test/config/data/config-pcie-with-tcp-config.json
Normal file
|
@ -0,0 +1,48 @@
|
|||
[
|
||||
{
|
||||
"hostnqn":"nqn.2014-08.org.nvmexpress:uuid:2cd2c43b-a90a-45c1-a8cd-86b33ab273b5",
|
||||
"hostid":"2cd2c43b-a90a-45c1-a8cd-86b33ab273b5",
|
||||
"subsystems":[
|
||||
{
|
||||
"nqn":"nqn.io-1",
|
||||
"ports":[
|
||||
{
|
||||
"transport":"tcp",
|
||||
"traddr":"192.168.154.144",
|
||||
"trsvcid":"4420",
|
||||
"dhchap_key":"none"
|
||||
},
|
||||
{
|
||||
"transport":"tcp",
|
||||
"traddr":"192.168.154.144",
|
||||
"trsvcid":"4421",
|
||||
"dhchap_key":"none"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"hostnqn":"nqn.2014-08.org.nvmexpress:uuid:befdec4c-2234-11b2-a85c-ca77c773af36",
|
||||
"hostid":"befdec4c-2234-11b2-a85c-ca77c773af36",
|
||||
"subsystems":[
|
||||
{
|
||||
"nqn":"nqn.io-1",
|
||||
"ports":[
|
||||
{
|
||||
"transport":"tcp",
|
||||
"traddr":"192.168.154.144",
|
||||
"trsvcid":"4420",
|
||||
"dhchap_key":"none"
|
||||
},
|
||||
{
|
||||
"transport":"tcp",
|
||||
"traddr":"192.168.154.144",
|
||||
"trsvcid":"4421",
|
||||
"dhchap_key":"none"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
48
test/config/data/config-pcie-with-tcp-config.out
Normal file
48
test/config/data/config-pcie-with-tcp-config.out
Normal file
|
@ -0,0 +1,48 @@
|
|||
[
|
||||
{
|
||||
"hostnqn":"nqn.2014-08.org.nvmexpress:uuid:2cd2c43b-a90a-45c1-a8cd-86b33ab273b5",
|
||||
"hostid":"2cd2c43b-a90a-45c1-a8cd-86b33ab273b5",
|
||||
"subsystems":[
|
||||
{
|
||||
"nqn":"nqn.io-1",
|
||||
"ports":[
|
||||
{
|
||||
"transport":"tcp",
|
||||
"traddr":"192.168.154.144",
|
||||
"trsvcid":"4420",
|
||||
"dhchap_key":"none"
|
||||
},
|
||||
{
|
||||
"transport":"tcp",
|
||||
"traddr":"192.168.154.144",
|
||||
"trsvcid":"4421",
|
||||
"dhchap_key":"none"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"hostnqn":"nqn.2014-08.org.nvmexpress:uuid:befdec4c-2234-11b2-a85c-ca77c773af36",
|
||||
"hostid":"befdec4c-2234-11b2-a85c-ca77c773af36",
|
||||
"subsystems":[
|
||||
{
|
||||
"nqn":"nqn.io-1",
|
||||
"ports":[
|
||||
{
|
||||
"transport":"tcp",
|
||||
"traddr":"192.168.154.144",
|
||||
"trsvcid":"4420",
|
||||
"dhchap_key":"none"
|
||||
},
|
||||
{
|
||||
"transport":"tcp",
|
||||
"traddr":"192.168.154.144",
|
||||
"trsvcid":"4421",
|
||||
"dhchap_key":"none"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
BIN
test/config/data/config-pcie-with-tcp-config.tar.xz
Normal file
BIN
test/config/data/config-pcie-with-tcp-config.tar.xz
Normal file
Binary file not shown.
0
test/config/data/config-pcie.json
Normal file
0
test/config/data/config-pcie.json
Normal file
0
test/config/data/config-pcie.out
Normal file
0
test/config/data/config-pcie.out
Normal file
BIN
test/config/data/config-pcie.tar.xz
Normal file
BIN
test/config/data/config-pcie.tar.xz
Normal file
Binary file not shown.
48
test/config/data/hostnqn-order.json
Normal file
48
test/config/data/hostnqn-order.json
Normal file
|
@ -0,0 +1,48 @@
|
|||
[
|
||||
{
|
||||
"hostnqn":"nqn.2014-08.org.nvmexpress:uuid:2cd2c43b-a90a-45c1-a8cd-86b33ab273b5",
|
||||
"hostid":"2cd2c43b-a90a-45c1-a8cd-86b33ab273b5",
|
||||
"subsystems":[
|
||||
{
|
||||
"nqn":"nqn.io-1",
|
||||
"ports":[
|
||||
{
|
||||
"transport":"tcp",
|
||||
"traddr":"192.168.154.144",
|
||||
"trsvcid":"4420",
|
||||
"dhchap_key":"none"
|
||||
},
|
||||
{
|
||||
"transport":"tcp",
|
||||
"traddr":"192.168.154.144",
|
||||
"trsvcid":"4421",
|
||||
"dhchap_key":"none"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"hostnqn":"nqn.2014-08.org.nvmexpress:uuid:befdec4c-2234-11b2-a85c-ca77c773af36",
|
||||
"hostid":"befdec4c-2234-11b2-a85c-ca77c773af36",
|
||||
"subsystems":[
|
||||
{
|
||||
"nqn":"nqn.io-1",
|
||||
"ports":[
|
||||
{
|
||||
"transport":"tcp",
|
||||
"traddr":"192.168.154.144",
|
||||
"trsvcid":"4420",
|
||||
"dhchap_key":"none"
|
||||
},
|
||||
{
|
||||
"transport":"tcp",
|
||||
"traddr":"192.168.154.144",
|
||||
"trsvcid":"4421",
|
||||
"dhchap_key":"none"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
0
test/config/data/hostnqn-order.out
Normal file
0
test/config/data/hostnqn-order.out
Normal file
BIN
test/config/data/hostnqn-order.tar.xz
Normal file
BIN
test/config/data/hostnqn-order.tar.xz
Normal file
Binary file not shown.
164
test/config/hostnqn-order.c
Normal file
164
test/config/hostnqn-order.c
Normal file
|
@ -0,0 +1,164 @@
|
|||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/**
|
||||
* This file is part of libnvme.
|
||||
* Copyright (c) 2024 Daniel Wagner, SUSE LLC
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <libnvme.h>
|
||||
|
||||
static bool command_line(void)
|
||||
{
|
||||
bool pass = false;
|
||||
nvme_root_t r;
|
||||
int err;
|
||||
char *hostnqn, *hostid, *hnqn, *hid;
|
||||
|
||||
r = nvme_create_root(stderr, LOG_ERR);
|
||||
if (!r)
|
||||
return false;
|
||||
|
||||
err = nvme_scan_topology(r, NULL, NULL);
|
||||
if (err) {
|
||||
if (errno != ENOENT)
|
||||
goto out;
|
||||
}
|
||||
|
||||
hostnqn = "nqn.2014-08.org.nvmexpress:uuid:ce4fee3e-c02c-11ee-8442-830d068a36c6";
|
||||
hostid = "ce4fee3e-c02c-11ee-8442-830d068a36c6";
|
||||
|
||||
err = nvme_host_get_ids(r, hostnqn, hostid, &hnqn, &hid);
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
if (strcmp(hostnqn, hnqn)) {
|
||||
printf("json config hostnqn '%s' does not match '%s'\n", hostnqn, hnqn);
|
||||
goto out;
|
||||
}
|
||||
if (strcmp(hostid, hid)) {
|
||||
printf("json config hostid '%s' does not match '%s'\n", hostid, hid);
|
||||
goto out;
|
||||
}
|
||||
|
||||
free(hnqn);
|
||||
free(hid);
|
||||
|
||||
pass = true;
|
||||
|
||||
out:
|
||||
nvme_free_tree(r);
|
||||
return pass;
|
||||
}
|
||||
|
||||
static bool json_config(char *file)
|
||||
{
|
||||
bool pass = false;
|
||||
nvme_root_t r;
|
||||
int err;
|
||||
char *hostnqn, *hostid, *hnqn, *hid;
|
||||
|
||||
setenv("LIBNVME_HOSTNQN", "", 1);
|
||||
setenv("LIBNVME_HOSTID", "", 1);
|
||||
|
||||
r = nvme_create_root(stderr, LOG_ERR);
|
||||
if (!r)
|
||||
return false;
|
||||
|
||||
/* We need to read the config in before we scan */
|
||||
err = nvme_read_config(r, file);
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
err = nvme_scan_topology(r, NULL, NULL);
|
||||
if (err) {
|
||||
if (errno != ENOENT)
|
||||
goto out;
|
||||
}
|
||||
|
||||
hostnqn = "nqn.2014-08.org.nvmexpress:uuid:2cd2c43b-a90a-45c1-a8cd-86b33ab273b5";
|
||||
hostid = "2cd2c43b-a90a-45c1-a8cd-86b33ab273b5";
|
||||
|
||||
err = nvme_host_get_ids(r, NULL, NULL, &hnqn, &hid);
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
if (strcmp(hostnqn, hnqn)) {
|
||||
printf("json config hostnqn '%s' does not match '%s'\n", hostnqn, hnqn);
|
||||
goto out;
|
||||
}
|
||||
if (strcmp(hostid, hid)) {
|
||||
printf("json config hostid '%s' does not match '%s'\n", hostid, hid);
|
||||
goto out;
|
||||
}
|
||||
|
||||
free(hnqn);
|
||||
free(hid);
|
||||
|
||||
pass = true;
|
||||
|
||||
out:
|
||||
nvme_free_tree(r);
|
||||
return pass;
|
||||
}
|
||||
|
||||
static bool from_file(void)
|
||||
{
|
||||
bool pass = false;
|
||||
nvme_root_t r;
|
||||
int err;
|
||||
char *hostnqn, *hostid, *hnqn, *hid;
|
||||
|
||||
hostnqn = "nqn.2014-08.org.nvmexpress:uuid:ce4fee3e-c02c-11ee-8442-830d068a36c6";
|
||||
hostid = "ce4fee3e-c02c-11ee-8442-830d068a36c6";
|
||||
|
||||
setenv("LIBNVME_HOSTNQN", hostnqn, 1);
|
||||
setenv("LIBNVME_HOSTID", hostid, 1);
|
||||
|
||||
r = nvme_create_root(stderr, LOG_ERR);
|
||||
if (!r)
|
||||
return false;
|
||||
|
||||
err = nvme_scan_topology(r, NULL, NULL);
|
||||
if (err) {
|
||||
if (errno != ENOENT)
|
||||
goto out;
|
||||
}
|
||||
|
||||
err = nvme_host_get_ids(r, NULL, NULL, &hnqn, &hid);
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
if (strcmp(hostnqn, hnqn)) {
|
||||
printf("json config hostnqn '%s' does not match '%s'\n", hostnqn, hnqn);
|
||||
goto out;
|
||||
}
|
||||
if (strcmp(hostid, hid)) {
|
||||
printf("json config hostid '%s' does not match '%s'\n", hostid, hid);
|
||||
goto out;
|
||||
}
|
||||
|
||||
free(hnqn);
|
||||
free(hid);
|
||||
|
||||
pass = true;
|
||||
|
||||
out:
|
||||
nvme_free_tree(r);
|
||||
return pass;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
bool pass;
|
||||
|
||||
pass = command_line();
|
||||
pass &= json_config(argv[1]);
|
||||
pass &= from_file();
|
||||
fflush(stdout);
|
||||
|
||||
exit(pass ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
}
|
59
test/config/meson.build
Normal file
59
test/config/meson.build
Normal file
|
@ -0,0 +1,59 @@
|
|||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
#
|
||||
# This file is part of libnvme.
|
||||
# Copyright (c) 2024 SUSE LLC.
|
||||
#
|
||||
# Authors: Daniel Wagner <dwagner@suse.de>
|
||||
|
||||
diff = find_program('diff', required : false)
|
||||
if diff.found()
|
||||
config_dump = executable(
|
||||
'test-config-dump',
|
||||
['config-dump.c'],
|
||||
dependencies: libnvme_dep,
|
||||
include_directories: [incdir],
|
||||
)
|
||||
|
||||
config_data = [
|
||||
'config-pcie',
|
||||
'config-pcie-with-tcp-config',
|
||||
]
|
||||
|
||||
config_diff = find_program('config-diff.sh')
|
||||
|
||||
foreach t_file : config_data
|
||||
test(
|
||||
t_file,
|
||||
config_diff,
|
||||
args : [
|
||||
meson.current_build_dir(),
|
||||
config_dump.full_path(),
|
||||
files('data'/t_file + '.tar.xz'),
|
||||
files('data'/t_file + '.json'),
|
||||
files('data'/t_file + '.out'),
|
||||
],
|
||||
depends : config_dump,
|
||||
)
|
||||
endforeach
|
||||
|
||||
test_hostnqn_order = executable(
|
||||
'test-hostnqn-order',
|
||||
['hostnqn-order.c'],
|
||||
dependencies: libnvme_dep,
|
||||
include_directories: [incdir],
|
||||
)
|
||||
|
||||
test(
|
||||
'hostnqn-order',
|
||||
config_diff,
|
||||
args : [
|
||||
meson.current_build_dir(),
|
||||
test_hostnqn_order.full_path(),
|
||||
files('data/hostnqn-order.tar.xz'),
|
||||
files('data/hostnqn-order.json'),
|
||||
files('data/hostnqn-order.out'),
|
||||
],
|
||||
depends : test_hostnqn_order,
|
||||
)
|
||||
|
||||
endif
|
Loading…
Add table
Add a link
Reference in a new issue