[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 15/18] iotests: Let _make_test_img guess $TEST_IMG_FILE
From: |
Max Reitz |
Subject: |
[PATCH 15/18] iotests: Let _make_test_img guess $TEST_IMG_FILE |
Date: |
Thu, 19 Dec 2019 15:38:15 +0100 |
When most iotests want to create a test image that is named differently
from the default $TEST_IMG, they do something like this:
TEST_IMG="$TEST_IMG.base" _make_test_img $options
This works fine with the "file" protocol, but not so much for anything
else: _make_test_img tries to create an image under $TEST_IMG_FILE
first, and only under $TEST_IMG if the former is not set; and on
everything but "file", $TEST_IMG_FILE is set.
There are two ways we can fix this: First, we could make all tests
adjust not only TEST_IMG, but also TEST_IMG_FILE if that is present
(e.g. with something like _set_test_img_suffix $suffix that would affect
not only TEST_IMG but also TEST_IMG_FILE, if necessary). This is a
pretty clean solution, and this is maybe what we should have done from
the start.
But it would also require changes to most existing bash tests. So the
alternative is this: Let _make_test_img see whether $TEST_IMG_FILE still
points to the original value. If so, it is possible that the caller has
adjusted $TEST_IMG but not $TEST_IMG_FILE. In such a case, we can (for
most protocols) derive the corresponding $TEST_IMG_FILE value from
$TEST_IMG value and thus work around what technically is the caller
misbehaving.
This second solution is less clean, but it is robust against people
keeping their old habit of adjusting TEST_IMG only, and requires much
less changes. So this patch implements it.
Signed-off-by: Max Reitz <address@hidden>
---
tests/qemu-iotests/common.rc | 42 +++++++++++++++++++++++++++++++++---
1 file changed, 39 insertions(+), 3 deletions(-)
diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
index d088392ab6..192c988401 100644
--- a/tests/qemu-iotests/common.rc
+++ b/tests/qemu-iotests/common.rc
@@ -250,6 +250,7 @@ else
TEST_IMG=$IMGPROTO:$TEST_DIR/t.$IMGFMT
fi
fi
+ORIG_TEST_IMG_FILE=$TEST_IMG_FILE
ORIG_TEST_IMG="$TEST_IMG"
if [ -z "$TEST_DIR" ]; then
@@ -312,6 +313,33 @@ _get_data_file()
| sed -e "s#\\\$TEST_IMG#$1#"
}
+# Translate a $TEST_IMG to its corresponding $TEST_IMG_FILE for
+# different protocols
+_test_img_to_test_img_file()
+{
+ case "$IMGPROTO" in
+ file)
+ echo "$1"
+ ;;
+
+ nfs)
+ echo "$1" | sed -e "s#nfs://127.0.0.1##"
+ ;;
+
+ ssh)
+ echo "$1" | sed -e "s#ssh://127.0.0.1##"
+ ;;
+
+ vxhs)
+ echo "$1" | sed -e "s#vxhs://127.0.0.1:9999#$TEST_DIR#"
+ ;;
+
+ *)
+ return 1
+ ;;
+ esac
+}
+
_make_test_img()
{
# extra qemu-img options can be added by tests
@@ -325,10 +353,18 @@ _make_test_img()
local opts_param=false
local misc_params=()
- if [ -n "$TEST_IMG_FILE" ]; then
- img_name=$TEST_IMG_FILE
- else
+ if [ -z "$TEST_IMG_FILE" ]; then
img_name=$TEST_IMG
+ elif [ "$TEST_IMG_FILE" = "$ORIG_TEST_IMG_FILE" ]; then
+ # Handle cases of tests only updating TEST_IMG, but not TEST_IMG_FILE
+ img_name=$(_test_img_to_test_img_file "$TEST_IMG")
+ if [ "$?" != 0 ]; then
+ img_name=$TEST_IMG_FILE
+ fi
+ else
+ # $TEST_IMG_FILE is not the default value, so it definitely has been
+ # modified by the test
+ img_name=$TEST_IMG_FILE
fi
if [ -n "$IMGOPTS" ]; then
--
2.23.0
- [PATCH 05/18] fuse: Allow growable exports, (continued)
- [PATCH 05/18] fuse: Allow growable exports, Max Reitz, 2019/12/19
- [PATCH 06/18] fuse: (Partially) implement fallocate(), Max Reitz, 2019/12/19
- [PATCH 07/18] fuse: Implement hole detection through lseek, Max Reitz, 2019/12/19
- [PATCH 09/18] iotests: Do not pipe _make_test_img, Max Reitz, 2019/12/19
- [PATCH 08/18] iotests: Do not needlessly filter _make_test_img, Max Reitz, 2019/12/19
- [PATCH 10/18] iotests: Use convert -n in some cases, Max Reitz, 2019/12/19
- [PATCH 14/18] iotests: Restrict some Python tests to file, Max Reitz, 2019/12/19
- [PATCH 13/18] iotests/091: Use _cleanup_qemu instad of "wait", Max Reitz, 2019/12/19
- [PATCH 12/18] iotests: Derive image names from $TEST_IMG, Max Reitz, 2019/12/19
- [PATCH 11/18] iotests: Avoid renaming images, Max Reitz, 2019/12/19
- [PATCH 15/18] iotests: Let _make_test_img guess $TEST_IMG_FILE,
Max Reitz <=
- [PATCH 16/18] iotests: Allow testing FUSE exports, Max Reitz, 2019/12/19
- [PATCH 17/18] iotests: Enable fuse for many tests, Max Reitz, 2019/12/19
- [PATCH 18/18] iotests/281: Add test for FUSE exports, Max Reitz, 2019/12/19
- Re: [PATCH 00/18] block: Allow exporting BDSs via FUSE, Max Reitz, 2019/12/19
- Re: [PATCH 00/18] block: Allow exporting BDSs via FUSE, Stefan Hajnoczi, 2019/12/20