iotests: Allow running from different directory
PATCH 1/1 iotests: Allow running from different directory
It is convenient to be able to edit the tests and run them without changing the current working directory back and forth. Instead of assuming that $PWD is the qemu-iotests build directory, derive the build directory from the executed script.
This allows 'check' to find the required files even when called from another directory. The scratch directory will still be in the current working directory.
--- tests/qemu-iotests/check | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qemu-iotests/check +1 -1
@@ -44,7 +44,7 @@ then _init_error "failed to obtain source tree name from check symlink" fi source_iotests=$(cd "$source_iotests"; pwd) || _init_error "failed to enter source tree" - build_iotests=$PWD + build_iotests=$(dirname "$0") else # called from the source tree source_iotests=$PWD
Signature · 1 line
2.25.4
Quoted 20 lines · Kevin Wolf
It is convenient to be able to edit the tests and run them without changing the current working directory back and forth. Instead of assuming that $PWD is the qemu-iotests build directory, derive the build directory from the executed script.
This allows 'check' to find the required files even when called from another directory. The scratch directory will still be in the current working directory.
Signed-off-by Kevin Wolf <[email protected]>--- tests/qemu-iotests/check | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/qemu-iotests/check +0
-0
tests/qemu-iotests/check then · line 50
Quoted 8 lines
tests/qemu-iotests/check +1
-1@@ -44,7 +44,7 @@ then _init_error "failed to obtain source tree name from check symlink" fi source_iotests=$(cd "$source_iotests"; pwd) || _init_error "failed to enter source tree" - build_iotests=$PWD + build_iotests=$(dirname "$0") else # called from the source tree source_iotests=$PWD
Like it, thanks!
Quoted 19 lines · Kevin Wolf
It is convenient to be able to edit the tests and run them without changing the current working directory back and forth. Instead of assuming that $PWD is the qemu-iotests build directory, derive the build directory from the executed script.
This allows 'check' to find the required files even when called from another directory. The scratch directory will still be in the current working directory.
Signed-off-by Kevin Wolf <[email protected]>--- tests/qemu-iotests/check | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/qemu-iotests/check +0
-0
tests/qemu-iotests/check then · line 47
Quoted 5 lines
tests/qemu-iotests/check +1
-1@@ -44,7 +44,7 @@ then _init_error "failed to obtain source tree name from check symlink" fi source_iotests=$(cd "$source_iotests"; pwd) || _init_error "failed to enter source tree" - build_iotests=$PWD + build_iotests=$(dirname "$0")
This breaks running check from the build tree.
(i.e. cd $build/tests/qemu-iotests; ./check)
The problem is that to run the test, we do cd to the source directory ($source_iotests), and so $build_iotests then becomes invalid if it’s just a relative path. In my case, this leads to the following error:
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 +./common.rc: line 139: $QEMU/tests/qemu-iotests/../../qemu-img: No such file or directory
I think this could be resolved by wrapping the $(dirname) in $(realpath), i.e.
build_iotests=$(realpath "$(dirname "$0")")
Max
Quoted 4 lines
tests/qemu-iotests/check +0
-0else # called from the source tree source_iotests=$PWD
Am 03.09.2020 um 14:54 hat Max Reitz geschrieben:
Quoted 29 lines · Kevin Wolf
Quoted 19 lines
It is convenient to be able to edit the tests and run them without changing the current working directory back and forth. Instead of assuming that $PWD is the qemu-iotests build directory, derive the build directory from the executed script.
This allows 'check' to find the required files even when called from another directory. The scratch directory will still be in the current working directory.
Signed-off-by Kevin Wolf <[email protected]>--- tests/qemu-iotests/check | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/qemu-iotests/check +0
-0tests/qemu-iotests/check then · line 47
Quoted 5 lines
tests/qemu-iotests/check +1
-1@@ -44,7 +44,7 @@ then _init_error "failed to obtain source tree name from check symlink" fi source_iotests=$(cd "$source_iotests"; pwd) || _init_error "failed to enter source tree" - build_iotests=$PWD + build_iotests=$(dirname "$0")This breaks running check from the build tree.
(i.e. cd $build/tests/qemu-iotests; ./check)
Quoted 7 lines
The problem is that to run the test, we do cd to the source directory ($source_iotests), and so $build_iotests then becomes invalid if it’s just a relative path. In my case, this leads to the following error:
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 +./common.rc: line 139: $QEMU/tests/qemu-iotests/../../qemu-img: No such file or directory
Ah, my symlinks in the source tree made it work for me.
Quoted 4 lines
I think this could be resolved by wrapping the $(dirname) in $(realpath), i.e.
build_iotests=$(realpath "$(dirname "$0")")
Sounds good, I'll update it in my tree.
Kevin
Quoted 40 lines · Kevin Wolf
Am 03.09.2020 um 14:54 hat Max Reitz geschrieben:
Quoted 29 lines · Kevin Wolf
Quoted 19 lines
It is convenient to be able to edit the tests and run them without changing the current working directory back and forth. Instead of assuming that $PWD is the qemu-iotests build directory, derive the build directory from the executed script.
This allows 'check' to find the required files even when called from another directory. The scratch directory will still be in the current working directory.
Signed-off-by Kevin Wolf <[email protected]>--- tests/qemu-iotests/check | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/qemu-iotests/check +0
-0tests/qemu-iotests/check then · line 47
Quoted 5 lines
tests/qemu-iotests/check +1
-1@@ -44,7 +44,7 @@ then _init_error "failed to obtain source tree name from check symlink" fi source_iotests=$(cd "$source_iotests"; pwd) || _init_error "failed to enter source tree" - build_iotests=$PWD + build_iotests=$(dirname "$0")This breaks running check from the build tree.
(i.e. cd $build/tests/qemu-iotests; ./check)Quoted 7 lines
The problem is that to run the test, we do cd to the source directory ($source_iotests), and so $build_iotests then becomes invalid if it’s just a relative path. In my case, this leads to the following error:
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 +./common.rc: line 139: $QEMU/tests/qemu-iotests/../../qemu-img: No such file or directory
Ah, my symlinks in the source tree made it work for me.
Quoted 9 lines
Quoted 4 lines
I think this could be resolved by wrapping the $(dirname) in $(realpath), i.e.
build_iotests=$(realpath "$(dirname "$0")")
Sounds good, I'll update it in my tree.
Kevin
Hello Kevin,
the committed patch in master is now (not sure where it changed):
tests/qemu-iotests/check +1 -1
@@ -44,7 +44,7 @@ then _init_error "failed to obtain source tree name from check symlink" fi source_iotests=$(cd "$source_iotests"; pwd) || _init_error "failed to enter source tree" - build_iotests=$PWD + build_iotests=$(readlink -f $(dirname "$0")) else # called from the source tree source_iotests=$PWD
-----
This seems to break the MacOS build (Cirrus-ci) though:
readlink: illegal option -- f
usage: readlink [-n] [file ...]
./check: line 60: /common.env: No such file or directory
check: failed to source common.env (make sure the qemu-iotests are run from tests/qemu-iotests in the build tree)
gmake: *** [/private/var/folders/3y/l0z1x3693dl_8n0qybp4dqwh0000gn/T/cirrus-ci-build/tests/Makefile.include:144: check-block] Error 1 Exit status: 2
Ciao,
Claudio