summaryrefslogtreecommitdiffstats
path: root/test/sysfs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 11:05:25 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 11:05:25 +0000
commitd3b6c0269abf2332f6f4b43760524b040ca58ff8 (patch)
tree6a0ebdb4cb3c7b76c824f021d9f3624d16037457 /test/sysfs
parentAdding upstream version 1.8. (diff)
downloadlibnvme-d3b6c0269abf2332f6f4b43760524b040ca58ff8.tar.xz
libnvme-d3b6c0269abf2332f6f4b43760524b040ca58ff8.zip
Adding upstream version 1.9.upstream/1.9
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--test/sysfs/meson.build45
-rwxr-xr-xtest/sysfs/setup.sh11
-rw-r--r--test/sysfs/sysfs-tree-diff.sh22
-rw-r--r--test/sysfs/sysfs.c77
4 files changed, 54 insertions, 101 deletions
diff --git a/test/sysfs/meson.build b/test/sysfs/meson.build
index c004fc0..119fa97 100644
--- a/test/sysfs/meson.build
+++ b/test/sysfs/meson.build
@@ -5,25 +5,32 @@
#
# Authors: Daniel Wagner <dwagner@suse.de>
+diff = find_program('diff', required : false)
+if diff.found()
+ sysfs_tree_print = executable(
+ 'sysfs-tree-print',
+ ['sysfs.c'],
+ dependencies: libnvme_dep,
+ include_directories: [incdir],
+ )
-sysfs = executable(
- 'test-sysfs',
- ['sysfs.c'],
- dependencies: libnvme_dep,
- include_directories: [incdir, internal_incdir]
-)
+ sysfs_files= [
+ 'nvme-sysfs-tw-carbon-6.8.0-rc1+'
+ ]
-sysfs_files= [
- 'nvme-sysfs-tw-carbon-6.8.0-rc1+'
-]
+ sysfs_tree_diff = find_program('sysfs-tree-diff.sh')
-setup = find_program('setup.sh')
-
-foreach t_file : sysfs_files
- r = run_command(setup, files('data'/t_file + '.tar.xz'), meson.current_build_dir(), check: true)
- i = r.stdout().strip()
- e0 = 'LIBNVME_SYSFS_PATH=' + i
- e1 = 'LIBNVME_HOSTNQN=nqn.2014-08.org.nvmexpress:uuid:ce4fee3e-c02c-11ee-8442-830d068a36c6'
- e2 = 'LIBNVME_HOSTID=ce4fee3e-c02c-11ee-8442-830d068a36c6'
- test('sysfs', sysfs, args : [ i, t_file + '.out', files('data'/t_file + '.out') ], env : [ e0, e1, e2 ])
-endforeach
+ foreach t_file : sysfs_files
+ test(
+ 'sysfs',
+ sysfs_tree_diff,
+ args : [
+ meson.current_build_dir(),
+ sysfs_tree_print.full_path(),
+ files('data'/t_file + '.tar.xz'),
+ files('data'/t_file + '.out'),
+ ],
+ depends : sysfs_tree_print,
+ )
+ endforeach
+endif
diff --git a/test/sysfs/setup.sh b/test/sysfs/setup.sh
deleted file mode 100755
index 3437d4e..0000000
--- a/test/sysfs/setup.sh
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env bash
-# SPDX-License-Identifier: LGPL-2.1-or-later
-
-TARFILE=$1
-BASEDIR=$2
-TESTDIR="$BASEDIR/$(basename -s .tar.xz ${TARFILE})"
-
-mkdir -p "${TESTDIR}"
-tar -x -f "${TARFILE}" -C "${TESTDIR}" || exit 1
-
-echo "${TESTDIR}"
diff --git a/test/sysfs/sysfs-tree-diff.sh b/test/sysfs/sysfs-tree-diff.sh
new file mode 100644
index 0000000..dfe3cb3
--- /dev/null
+++ b/test/sysfs/sysfs-tree-diff.sh
@@ -0,0 +1,22 @@
+#!/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
index c2df178..06d0035 100644
--- a/test/sysfs/sysfs.c
+++ b/test/sysfs/sysfs.c
@@ -4,86 +4,21 @@
* Copyright (c) 2024 Daniel Wagner, SUSE LLC
*/
-#include "nvme/tree.h"
#include <assert.h>
-#include <errno.h>
-#include <string.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <arpa/inet.h>
-
-#include <ccan/array_size/array_size.h>
#include <libnvme.h>
-#include <nvme/private.h>
-static bool test_sysfs(const char *path, const char *filename)
+int main(int argc, char *argv[])
{
- FILE *f;
nvme_root_t r;
- int err;
-
- f = fopen(filename, "w");
- if (!f)
- return false;
- r = nvme_create_root(f, LOG_ERR);
+ r = nvme_create_root(stdout, LOG_ERR);
assert(r);
- err = nvme_scan_topology(r, NULL, NULL);
- if (!err)
- nvme_dump_tree(r);
- fprintf(f, "\n");
-
- nvme_free_tree(r);
- fclose(f);
-
- return err == 0;
-}
-
-static bool compare_content(const char *filename1, const char *filename2)
-{
- FILE *f1, *f2;
- char c1, c2;
- bool pass = false;
-
- f1 = fopen(filename1, "r");
- if (!f1)
- return false;
+ assert(nvme_scan_topology(r, NULL, NULL) == 0);
- f2 = fopen(filename2, "r");
- if (!f2) {
- fclose(f1);
- return false;
- }
+ assert(nvme_dump_tree(r) == 0);
+ printf("\n");
- do {
- c1 = getc(f1);
- c2 = getc(f2);
- if (c1 != c2)
- goto out;
- } while (c1 != EOF || c2 != EOF);
-
- if (c1 == c2)
- pass = true;
-out:
- fclose(f1);
- fclose(f2);
-
- return pass;
-}
-
-int main(int argc, char *argv[])
-{
- bool pass = true;
-
- if (argc < 4) {
- fprintf(stderr, "usage: test-sysfs SYSFS_DIR OUTPUT_FILE COMPARE_FILE\n");
- return EXIT_FAILURE;
- }
-
- pass &= test_sysfs(argv[1], argv[2]);
- pass &= compare_content(argv[2], argv[3]);
-
- exit(pass ? EXIT_SUCCESS : EXIT_FAILURE);
+ nvme_free_tree(r);
}