Skip to content

Commit ab11b28

Browse files
dwsuseigaw
authored andcommitted
test: add config dump test
These test infrastructure tests the nvme_dump_config interfacce. Signed-off-by: Daniel Wagner <[email protected]>
1 parent ac734b2 commit ab11b28

7 files changed

Lines changed: 115 additions & 0 deletions

File tree

test/config/config-diff.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash -e
2+
# SPDX-License-Identifier: LGPL-2.1-or-later
3+
4+
BUILD_DIR=$1
5+
CONFIG_DUMP=$2
6+
SYSDIR_INPUT=$3
7+
CONFIG_JSON=$4
8+
EXPECTED_OUTPUT=$5
9+
10+
ACTUAL_OUTPUT="${BUILD_DIR}"/$(basename "${EXPECTED_OUTPUT}")
11+
12+
TEST_NAME="$(basename -s .tar.xz $SYSDIR_INPUT)"
13+
TEST_DIR="$BUILD_DIR/$TEST_NAME"
14+
15+
rm -rf "${TEST_DIR}"
16+
mkdir "${TEST_DIR}"
17+
tar -x -f "${SYSDIR_INPUT}" -C "${TEST_DIR}"
18+
19+
LIBNVME_SYSFS_PATH="$TEST_DIR" \
20+
LIBNVME_HOSTNQN=nqn.2014-08.org.nvmexpress:uuid:ce4fee3e-c02c-11ee-8442-830d068a36c6 \
21+
LIBNVME_HOSTID=ce4fee3e-c02c-11ee-8442-830d068a36c6 \
22+
"${CONFIG_DUMP}" "${CONFIG_JSON}" > "${ACTUAL_OUTPUT}" || echo "test failed"
23+
24+
diff -u "${EXPECTED_OUTPUT}" "${ACTUAL_OUTPUT}"

test/config/config-dump.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// SPDX-License-Identifier: LGPL-2.1-or-later
2+
/**
3+
* This file is part of libnvme.
4+
* Copyright (c) 2024 Daniel Wagner, SUSE LLC
5+
*/
6+
7+
#include <string.h>
8+
#include <stdbool.h>
9+
#include <stdlib.h>
10+
#include <errno.h>
11+
12+
#include <libnvme.h>
13+
14+
static bool config_dump(const char *file)
15+
{
16+
bool pass = false;
17+
nvme_root_t r;
18+
int err;
19+
20+
r = nvme_create_root(stderr, LOG_ERR);
21+
if (!r)
22+
return false;
23+
24+
err = nvme_scan_topology(r, NULL, NULL);
25+
if (err) {
26+
if (errno != ENOENT)
27+
goto out;
28+
}
29+
30+
err = nvme_read_config(r, file);
31+
if (err)
32+
goto out;
33+
34+
err = nvme_dump_config(r);
35+
if (err)
36+
goto out;
37+
38+
pass = true;
39+
40+
out:
41+
nvme_free_tree(r);
42+
return pass;
43+
}
44+
45+
int main(int argc, char *argv[])
46+
{
47+
bool pass = true;
48+
49+
config_dump(argv[1]);
50+
fflush(stdout);
51+
52+
exit(pass ? EXIT_SUCCESS : EXIT_FAILURE);
53+
}

test/config/data/config-pcie.json

Whitespace-only changes.

test/config/data/config-pcie.out

Whitespace-only changes.
19.3 KB
Binary file not shown.

test/config/meson.build

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# SPDX-License-Identifier: LGPL-2.1-or-later
2+
#
3+
# This file is part of libnvme.
4+
# Copyright (c) 2024 SUSE LLC.
5+
#
6+
# Authors: Daniel Wagner <[email protected]>
7+
8+
diff = find_program('diff', required : false)
9+
if diff.found()
10+
config_dump = executable(
11+
'test-config-dump',
12+
['config-dump.c'],
13+
dependencies: libnvme_dep,
14+
include_directories: [incdir],
15+
)
16+
17+
config_data = [
18+
'config-pcie',
19+
]
20+
21+
config_diff = find_program('config-diff.sh')
22+
23+
foreach t_file : config_data
24+
test(
25+
t_file,
26+
config_diff,
27+
args : [
28+
meson.current_build_dir(),
29+
config_dump.full_path(),
30+
files('data'/t_file + '.tar.xz'),
31+
files('data'/t_file + '.json'),
32+
files('data'/t_file + '.out'),
33+
],
34+
depends : config_dump,
35+
)
36+
endforeach
37+
endif

test/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,5 @@ subdir('nbft')
109109

110110
if json_c_dep.found()
111111
subdir('sysfs')
112+
subdir('config')
112113
endif

0 commit comments

Comments
 (0)