Skip to content

Commit 0e0f67b

Browse files
dwsuseigaw
authored andcommitted
test: make config-diff more flexible to use
The config-diff script is expecting a sysfs tar file besides an input and a output file. Let's make the sysfs tar file optional so we can use this config diff script more flexible. Signed-off-by: Daniel Wagner <[email protected]>
1 parent 40230e6 commit 0e0f67b

2 files changed

Lines changed: 50 additions & 22 deletions

File tree

test/config/config-diff.sh

100644100755
Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,48 @@
11
#!/bin/bash -e
22
# SPDX-License-Identifier: LGPL-2.1-or-later
33

4-
BUILD_DIR=$1
5-
CONFIG_DUMP=$2
6-
SYSDIR_INPUT=$3
7-
CONFIG_JSON=$4
8-
EXPECTED_OUTPUT=$5
4+
positional_args=()
5+
sysfs_tar=""
6+
config_json=""
97

10-
ACTUAL_OUTPUT="${BUILD_DIR}"/$(basename "${EXPECTED_OUTPUT}")
8+
while [[ $# -gt 0 ]]; do
9+
case $1 in
10+
--sysfs-tar)
11+
sysfs_tar=$2
12+
shift 1
13+
;;
14+
--config-json)
15+
config_json=$2
16+
shift 1
17+
;;
18+
*)
19+
positional_args+=("$1")
20+
shift
21+
;;
22+
esac
23+
done
1124

12-
TEST_NAME="$(basename -s .tar.xz $SYSDIR_INPUT)"
13-
TEST_DIR="$BUILD_DIR/$TEST_NAME"
25+
set -- "${positional_args[@]}"
1426

15-
rm -rf "${TEST_DIR}"
16-
mkdir "${TEST_DIR}"
17-
tar -x -f "${SYSDIR_INPUT}" -C "${TEST_DIR}"
27+
test_binary="$1"
28+
build_dir="$2"
29+
expected_output="$3"
1830

19-
LIBNVME_SYSFS_PATH="$TEST_DIR" \
31+
sysfs_path=""
32+
if [[ -n "${sysfs_tar}" ]]; then
33+
test_name="$(basename -s .tar.xz ${sysfs_tar})"
34+
sysfs_path="${build_dir}/${test_name}"
35+
36+
rm -rf "${sysfs_path}"
37+
mkdir "${sysfs_path}"
38+
tar -x -f "${sysfs_tar}" -C "${sysfs_path}"
39+
fi
40+
41+
output="${build_dir}"/$(basename "${expected_output}")
42+
43+
LIBNVME_SYSFS_PATH="${sysfs_path}" \
2044
LIBNVME_HOSTNQN=nqn.2014-08.org.nvmexpress:uuid:ce4fee3e-c02c-11ee-8442-830d068a36c6 \
2145
LIBNVME_HOSTID=ce4fee3e-c02c-11ee-8442-830d068a36c6 \
22-
"${CONFIG_DUMP}" "${CONFIG_JSON}" > "${ACTUAL_OUTPUT}" || echo "test failed"
46+
"${test_binary}" "${config_json}" > "${output}" || echo "test failed"
2347

24-
diff -u "${EXPECTED_OUTPUT}" "${ACTUAL_OUTPUT}"
48+
diff -u "${expected_output}" "${output}"

test/config/meson.build

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
diff = find_program('diff', required : false)
99
if diff.found()
10+
11+
srcdir = meson.current_source_dir()
12+
builddir = meson.current_build_dir()
13+
1014
config_dump = executable(
1115
'test-config-dump',
1216
['config-dump.c'],
@@ -26,11 +30,11 @@ if diff.found()
2630
t_file,
2731
config_diff,
2832
args : [
29-
meson.current_build_dir(),
3033
config_dump.full_path(),
31-
files('data'/t_file + '.tar.xz'),
32-
files('data'/t_file + '.json'),
33-
files('data'/t_file + '.out'),
34+
builddir,
35+
srcdir + '/data/' + t_file + '.out',
36+
'--sysfs-tar', srcdir + '/data/' + t_file + '.tar.xz',
37+
'--config-json', srcdir + '/data/' + t_file + '.json',
3438
],
3539
depends : config_dump,
3640
)
@@ -47,11 +51,11 @@ if diff.found()
4751
'hostnqn-order',
4852
config_diff,
4953
args : [
50-
meson.current_build_dir(),
5154
test_hostnqn_order.full_path(),
52-
files('data/hostnqn-order.tar.xz'),
53-
files('data/hostnqn-order.json'),
54-
files('data/hostnqn-order.out'),
55+
builddir,
56+
srcdir + '/data/hostnqn-order.out',
57+
'--sysfs-tar', srcdir + '/data/hostnqn-order.tar.xz',
58+
'--config-json', srcdir + '/data/hostnqn-order.json',
5559
],
5660
depends : test_hostnqn_order,
5761
)

0 commit comments

Comments
 (0)