1
0
Fork 0

Adding upstream version 1.11.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-16 10:51:02 +01:00
parent 42ce9d48e1
commit d21edaa886
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
946 changed files with 4896 additions and 1272 deletions

52
test/config/config-diff.sh Normal file → Executable file
View file

@ -1,24 +1,48 @@
#!/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
positional_args=()
sysfs_tar=""
config_json=""
ACTUAL_OUTPUT="${BUILD_DIR}"/$(basename "${EXPECTED_OUTPUT}")
while [[ $# -gt 0 ]]; do
case $1 in
--sysfs-tar)
sysfs_tar=$2
shift 1
;;
--config-json)
config_json=$2
shift 1
;;
*)
positional_args+=("$1")
shift
;;
esac
done
TEST_NAME="$(basename -s .tar.xz $SYSDIR_INPUT)"
TEST_DIR="$BUILD_DIR/$TEST_NAME"
set -- "${positional_args[@]}"
rm -rf "${TEST_DIR}"
mkdir "${TEST_DIR}"
tar -x -f "${SYSDIR_INPUT}" -C "${TEST_DIR}"
test_binary="$1"
build_dir="$2"
expected_output="$3"
LIBNVME_SYSFS_PATH="$TEST_DIR" \
sysfs_path=""
if [[ -n "${sysfs_tar}" ]]; then
test_name="$(basename -s .tar.xz ${sysfs_tar})"
sysfs_path="${build_dir}/${test_name}"
rm -rf "${sysfs_path}"
mkdir "${sysfs_path}"
tar -x -f "${sysfs_tar}" -C "${sysfs_path}"
fi
output="${build_dir}"/$(basename "${expected_output}")
LIBNVME_SYSFS_PATH="${sysfs_path}" \
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"
"${test_binary}" "${config_json}" > "${output}" || echo "test failed"
diff -u "${EXPECTED_OUTPUT}" "${ACTUAL_OUTPUT}"
diff -u "${expected_output}" "${output}"

View file

@ -0,0 +1,21 @@
[
{
"hostnqn":"nqn.2014-08.org.nvmexpress:uuid:befdec4c-2234-11b2-a85c-ca77c773af36",
"hostid":"2cd2c43b-a90a-45c1-a8cd-86b33ab273b6",
"subsystems":[
{
"nqn":"nqn.io-1",
"ports":[
{
"transport":"tcp",
"traddr":"192.168.154.148",
"trsvcid":"4420",
"dhchap_key":"none",
"tls":true,
"tls_key":"NVMeTLSkey-1:01:Hhc5sFjwSZ6w5hPY19tqprajYtuYci3tN+Z2wGViDk3rpSR+:"
}
]
}
]
}
]

View file

@ -0,0 +1,21 @@
[
{
"hostnqn":"nqn.2014-08.org.nvmexpress:uuid:befdec4c-2234-11b2-a85c-ca77c773af36",
"hostid":"2cd2c43b-a90a-45c1-a8cd-86b33ab273b6",
"subsystems":[
{
"nqn":"nqn.io-1",
"ports":[
{
"transport":"tcp",
"traddr":"192.168.154.148",
"trsvcid":"4420",
"dhchap_key":"none",
"tls":true,
"tls_key":"NVMeTLSkey-1:01:Hhc5sFjwSZ6w5hPY19tqprajYtuYci3tN+Z2wGViDk3rpSR+:"
}
]
}
]
}
]

View file

@ -0,0 +1,22 @@
[
{
"hostnqn":"nqn.2014-08.org.nvmexpress:uuid:befdec4c-2234-11b2-a85c-ca77c773af36",
"hostid":"2cd2c43b-a90a-45c1-a8cd-86b33ab273b6",
"subsystems":[
{
"nqn":"nqn.io-1",
"ports":[
{
"transport":"tcp",
"traddr":"192.168.154.148",
"trsvcid":"4420",
"dhchap_key":"none",
"tls":true,
"tls_psk_identity":"NVMe1R01 nqn.2014-08.org.nvmexpress:uuid:befdec4c-2234-11b2-a85c-ca77c773af36 nqn.io-1 QMFIifx2SCVnlE2hc4MQb0r+2g56x3G7P6jJtDiYK+I=",
"tls_key":"NVMeTLSkey-1:01:Hhc5sFjwSZ6w5hPY19tqprajYtuYci3tN+Z2wGViDk3rpSR+:"
}
]
}
]
}
]

View file

@ -0,0 +1,21 @@
[
{
"hostnqn":"nqn.2014-08.org.nvmexpress:uuid:befdec4c-2234-11b2-a85c-ca77c773af36",
"hostid":"2cd2c43b-a90a-45c1-a8cd-86b33ab273b6",
"subsystems":[
{
"nqn":"nqn.io-1",
"ports":[
{
"transport":"tcp",
"traddr":"192.168.154.148",
"trsvcid":"4420",
"dhchap_key":"none",
"tls":true,
"tls_key":"NVMeTLSkey-1:01:Hhc5sFjwSZ6w5hPY19tqprajYtuYci3tN+Z2wGViDk3rpSR+:"
}
]
}
]
}
]

View file

@ -7,6 +7,10 @@
diff = find_program('diff', required : false)
if diff.found()
srcdir = meson.current_source_dir()
builddir = meson.current_build_dir()
config_dump = executable(
'test-config-dump',
['config-dump.c'],
@ -26,11 +30,11 @@ if diff.found()
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'),
builddir,
srcdir + '/data/' + t_file + '.out',
'--sysfs-tar', srcdir + '/data/' + t_file + '.tar.xz',
'--config-json', srcdir + '/data/' + t_file + '.json',
],
depends : config_dump,
)
@ -47,13 +51,38 @@ if diff.found()
'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'),
builddir,
srcdir + '/data/hostnqn-order.out',
'--sysfs-tar', srcdir + '/data/hostnqn-order.tar.xz',
'--config-json', srcdir + '/data/hostnqn-order.json',
],
depends : test_hostnqn_order,
)
test_psk_json = executable(
'test-psk-json',
['psk-json.c'],
dependencies: libnvme_dep,
include_directories: [incdir],
)
config_data = [
'tls_key-1',
'tls_key-2',
]
foreach t_file : config_data
test(
'psk-json-' + t_file,
config_diff,
args : [
test_psk_json.full_path(),
builddir,
srcdir + '/data/' + t_file + '.out',
'--config-json', srcdir + '/data/' + t_file + '.json',
],
depends : test_psk_json,
)
endforeach
endif

89
test/config/psk-json.c Normal file
View file

@ -0,0 +1,89 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/**
* This file is part of libnvme.
* Copyright (c) 2024 Daniel Wagner, SUSE LLC
*/
#include "nvme/linux.h"
#include "nvme/tree.h"
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <errno.h>
#include <libnvme.h>
static bool import_export_key(nvme_ctrl_t c)
{
unsigned char version, hmac, *key;
char *encoded_key;
size_t len;
key = nvme_import_tls_key_versioned(nvme_ctrl_get_tls_key(c),
&version, &hmac, &len);
if (!key) {
printf("ERROR: nvme_import_tls_key_versioned failed with %d\n",
errno);
return false;
}
encoded_key = nvme_export_tls_key_versioned(version, hmac, key, len);
free(key);
if (!encoded_key) {
printf("ERROR: nvme_export_tls_key_versioned failed with %d\n",
errno);
return false;
}
nvme_ctrl_set_tls_key(c, encoded_key);
free(encoded_key);
return true;
}
static bool psk_json_test(char *file)
{
bool pass = false;
nvme_root_t r;
nvme_host_t h;
nvme_subsystem_t s;
nvme_ctrl_t c;
int err;
r = nvme_create_root(stderr, LOG_ERR);
if (!r)
return false;
err = nvme_read_config(r, file);
if (err)
goto out;
nvme_for_each_host(r, h)
nvme_for_each_subsystem(h, s)
nvme_subsystem_for_each_ctrl(s, c)
if (!import_export_key(c))
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 = psk_json_test(argv[1]);
fflush(stdout);
exit(pass ? EXIT_SUCCESS : EXIT_FAILURE);
}