summaryrefslogtreecommitdiffstats
path: root/test/sysfs
diff options
context:
space:
mode:
Diffstat (limited to 'test/sysfs')
-rw-r--r--test/sysfs/data/tree-pcie.out (renamed from test/sysfs/data/nvme-sysfs-tw-carbon-6.8.0-rc1+.out)16
-rw-r--r--test/sysfs/data/tree-pcie.tar.xz (renamed from test/sysfs/data/nvme-sysfs-tw-carbon-6.8.0-rc1+.tar.xz)bin19712 -> 19712 bytes
-rw-r--r--test/sysfs/meson.build22
-rw-r--r--test/sysfs/sysfs-tree-diff.sh22
-rw-r--r--test/sysfs/sysfs.c24
-rw-r--r--test/sysfs/tree-diff.sh22
-rw-r--r--test/sysfs/tree-dump.c49
7 files changed, 90 insertions, 65 deletions
diff --git a/test/sysfs/data/nvme-sysfs-tw-carbon-6.8.0-rc1+.out b/test/sysfs/data/tree-pcie.out
index 1cb6de4..4a755a7 100644
--- a/test/sysfs/data/nvme-sysfs-tw-carbon-6.8.0-rc1+.out
+++ b/test/sysfs/data/tree-pcie.out
@@ -5,24 +5,24 @@
"hostid":"ce4fee3e-c02c-11ee-8442-830d068a36c6",
"subsystems":[
{
- "name":"nvme-subsys1",
- "nqn":"nqn.2019-08.org.qemu:nvme-0",
+ "name":"nvme-subsys0",
+ "nqn":"nqn.2019-08.org.qemu:subsys1",
"controllers":[
{
- "name":"nvme1",
+ "name":"nvme0",
"transport":"pcie",
- "traddr":"0000:00:05.0"
+ "traddr":"0000:0f:00.0"
}
]
},
{
- "name":"nvme-subsys0",
- "nqn":"nqn.2019-08.org.qemu:subsys1",
+ "name":"nvme-subsys1",
+ "nqn":"nqn.2019-08.org.qemu:nvme-0",
"controllers":[
{
- "name":"nvme0",
+ "name":"nvme1",
"transport":"pcie",
- "traddr":"0000:0f:00.0"
+ "traddr":"0000:00:05.0"
}
]
}
diff --git a/test/sysfs/data/nvme-sysfs-tw-carbon-6.8.0-rc1+.tar.xz b/test/sysfs/data/tree-pcie.tar.xz
index ee11fde..ee11fde 100644
--- a/test/sysfs/data/nvme-sysfs-tw-carbon-6.8.0-rc1+.tar.xz
+++ b/test/sysfs/data/tree-pcie.tar.xz
Binary files differ
diff --git a/test/sysfs/meson.build b/test/sysfs/meson.build
index 119fa97..2a7e8e3 100644
--- a/test/sysfs/meson.build
+++ b/test/sysfs/meson.build
@@ -7,30 +7,30 @@
diff = find_program('diff', required : false)
if diff.found()
- sysfs_tree_print = executable(
- 'sysfs-tree-print',
- ['sysfs.c'],
+ tree_dump = executable(
+ 'test-tree-dump',
+ ['tree-dump.c'],
dependencies: libnvme_dep,
include_directories: [incdir],
)
- sysfs_files= [
- 'nvme-sysfs-tw-carbon-6.8.0-rc1+'
+ tree_data = [
+ 'tree-pcie',
]
- sysfs_tree_diff = find_program('sysfs-tree-diff.sh')
+ tree_diff = find_program('tree-diff.sh')
- foreach t_file : sysfs_files
+ foreach t_file : tree_data
test(
- 'sysfs',
- sysfs_tree_diff,
+ t_file,
+ tree_diff,
args : [
meson.current_build_dir(),
- sysfs_tree_print.full_path(),
+ tree_dump.full_path(),
files('data'/t_file + '.tar.xz'),
files('data'/t_file + '.out'),
],
- depends : sysfs_tree_print,
+ depends : tree_dump,
)
endforeach
endif
diff --git a/test/sysfs/sysfs-tree-diff.sh b/test/sysfs/sysfs-tree-diff.sh
deleted file mode 100644
index dfe3cb3..0000000
--- a/test/sysfs/sysfs-tree-diff.sh
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/bash -e
-# SPDX-License-Identifier: LGPL-2.1-or-later
-
-BUILD_DIR=$1
-SYSFS_TREE_PRINT=$2
-INPUT=$3
-EXPECTED_OUTPUT=$4
-
-TEST_NAME="$(basename -s .tar.xz $INPUT)"
-TEST_DIR="$BUILD_DIR/$TEST_NAME"
-ACTUAL_OUTPUT="$TEST_DIR.out"
-
-rm -rf "$TEST_DIR"
-mkdir "$TEST_DIR"
-tar -x -f "$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 \
-"$SYSFS_TREE_PRINT" > "$ACTUAL_OUTPUT"
-
-diff -u "$EXPECTED_OUTPUT" "$ACTUAL_OUTPUT"
diff --git a/test/sysfs/sysfs.c b/test/sysfs/sysfs.c
deleted file mode 100644
index 06d0035..0000000
--- a/test/sysfs/sysfs.c
+++ /dev/null
@@ -1,24 +0,0 @@
-// SPDX-License-Identifier: LGPL-2.1-or-later
-/**
- * This file is part of libnvme.
- * Copyright (c) 2024 Daniel Wagner, SUSE LLC
- */
-
-#include <assert.h>
-
-#include <libnvme.h>
-
-int main(int argc, char *argv[])
-{
- nvme_root_t r;
-
- r = nvme_create_root(stdout, LOG_ERR);
- assert(r);
-
- assert(nvme_scan_topology(r, NULL, NULL) == 0);
-
- assert(nvme_dump_tree(r) == 0);
- printf("\n");
-
- nvme_free_tree(r);
-}
diff --git a/test/sysfs/tree-diff.sh b/test/sysfs/tree-diff.sh
new file mode 100644
index 0000000..39b8d0d
--- /dev/null
+++ b/test/sysfs/tree-diff.sh
@@ -0,0 +1,22 @@
+#!/bin/bash -e
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+BUILD_DIR=$1
+TREE_DUMP=$2
+SYSFS_INPUT=$3
+EXPECTED_OUTPUT=$4
+
+TEST_NAME="$(basename -s .tar.xz ${SYSFS_INPUT})"
+TEST_DIR="${BUILD_DIR}/${TEST_NAME}"
+ACTUAL_OUTPUT="${TEST_DIR}.out"
+
+rm -rf "${TEST_DIR}"
+mkdir "${TEST_DIR}"
+tar -x -f "${SYSFS_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 \
+"${TREE_DUMP}" > "${ACTUAL_OUTPUT}" || echo "test failed"
+
+diff -u "${EXPECTED_OUTPUT}" "${ACTUAL_OUTPUT}"
diff --git a/test/sysfs/tree-dump.c b/test/sysfs/tree-dump.c
new file mode 100644
index 0000000..bcf871b
--- /dev/null
+++ b/test/sysfs/tree-dump.c
@@ -0,0 +1,49 @@
+// 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 tree_dump(void)
+{
+ bool pass = false;
+ nvme_root_t r;
+ int err;
+
+ r = nvme_create_root(stdout, LOG_ERR);
+ if (!r)
+ return false;
+
+ err = nvme_scan_topology(r, NULL, NULL);
+ if (err) {
+ if (errno != ENOENT)
+ goto out;
+ }
+
+ if (nvme_dump_tree(r))
+ goto out;
+ printf("\n");
+
+ pass = true;
+
+out:
+ nvme_free_tree(r);
+ return pass;
+}
+
+int main(int argc, char *argv[])
+{
+ bool pass = true;
+
+ pass = tree_dump();
+ fflush(stdout);
+
+ exit(pass ? EXIT_SUCCESS : EXIT_FAILURE);
+}