Skip to content

Commit ac734b2

Browse files
dwsuseigaw
authored andcommitted
test: revamp sysfs tree dump test
In order to extend the sysfs tree dump tests, let's improve it. Signed-off-by: Daniel Wagner <[email protected]>
1 parent cce8b86 commit ac734b2

8 files changed

Lines changed: 83 additions & 58 deletions

File tree

test/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,5 @@ subdir('ioctl')
108108
subdir('nbft')
109109

110110
if json_c_dep.found()
111-
subdir('sysfs')
111+
subdir('sysfs')
112112
endif

test/sysfs/data/nvme-sysfs-tw-carbon-6.8.0-rc1+.out renamed to test/sysfs/data/tree-pcie.out

File renamed without changes.

test/sysfs/data/nvme-sysfs-tw-carbon-6.8.0-rc1+.tar.xz renamed to test/sysfs/data/tree-pcie.tar.xz

File renamed without changes.

test/sysfs/meson.build

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,30 @@
77

88
diff = find_program('diff', required : false)
99
if diff.found()
10-
sysfs_tree_print = executable(
11-
'sysfs-tree-print',
12-
['sysfs.c'],
10+
tree_dump = executable(
11+
'test-tree-dump',
12+
['tree-dump.c'],
1313
dependencies: libnvme_dep,
1414
include_directories: [incdir],
1515
)
1616

17-
sysfs_files= [
18-
'nvme-sysfs-tw-carbon-6.8.0-rc1+'
17+
tree_data = [
18+
'tree-pcie',
1919
]
2020

21-
sysfs_tree_diff = find_program('sysfs-tree-diff.sh')
21+
tree_diff = find_program('tree-diff.sh')
2222

23-
foreach t_file : sysfs_files
23+
foreach t_file : tree_data
2424
test(
25-
'sysfs',
26-
sysfs_tree_diff,
25+
t_file,
26+
tree_diff,
2727
args : [
2828
meson.current_build_dir(),
29-
sysfs_tree_print.full_path(),
29+
tree_dump.full_path(),
3030
files('data'/t_file + '.tar.xz'),
3131
files('data'/t_file + '.out'),
3232
],
33-
depends : sysfs_tree_print,
33+
depends : tree_dump,
3434
)
3535
endforeach
3636
endif

test/sysfs/sysfs-tree-diff.sh

Lines changed: 0 additions & 22 deletions
This file was deleted.

test/sysfs/sysfs.c

Lines changed: 0 additions & 24 deletions
This file was deleted.

test/sysfs/tree-diff.sh

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

test/sysfs/tree-dump.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 tree_dump(void)
15+
{
16+
bool pass = false;
17+
nvme_root_t r;
18+
int err;
19+
20+
r = nvme_create_root(stdout, 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+
if (nvme_dump_tree(r))
31+
goto out;
32+
printf("\n");
33+
34+
pass = true;
35+
36+
out:
37+
nvme_free_tree(r);
38+
return pass;
39+
}
40+
41+
int main(int argc, char *argv[])
42+
{
43+
bool pass = true;
44+
45+
pass = tree_dump();
46+
fflush(stdout);
47+
48+
exit(pass ? EXIT_SUCCESS : EXIT_FAILURE);
49+
}

0 commit comments

Comments
 (0)