在 2020/12/15 上午10:44, Hao Xu 写道:
在 2020/12/8 下午8:28, Hao Xu 写道: ping...
Hi Jens, I'm currently develop a test which need a device arg, so I leverage TEST_FILES, I found it may be better to form TEST_FILES as a key-value structure. Thanks && Regards, Hao
Different tests need different files / devices, use a map to indicate what each test need. Signed-off-by: Hao Xu <haoxu@xxxxxxxxxxxxxxxxx> --- the former implementation use a array for the global list TEST_FILES, which may causes this: TEST_FILES="dev0 dev1" dev0 required by test0 dev1 required by test1 In the <for tst in $TESTS> loop, we run the test for each $dev, which makes <test0 dev1> and <test1 dev0> run, these are not expected. Currently I see that statx.c accept argv[1] as a file_name, if someone writes another test which defines a device(say nvme0n1) in TEST_FILES, it may cause issues. test/config | 2 +- test/runtests.sh | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/test/config b/test/config index cab270359155..1bd9b40207bb 100644 --- a/test/config +++ b/test/config @@ -4,4 +4,4 @@ # TEST_EXCLUDE="" # # Define raw test devices (or files) for test cases, if any -# TEST_FILES="/dev/nvme0n1p2 /data/file" +# declare -A TEST_FILES=() diff --git a/test/runtests.sh b/test/runtests.sh index fa240f205542..1a6905b42768 100755 --- a/test/runtests.sh +++ b/test/runtests.sh @@ -5,10 +5,10 @@ RET=0 TIMEOUT=60 DMESG_FILTER="cat" TEST_DIR=$(dirname $0) -TEST_FILES="" FAILED="" SKIPPED="" MAYBE_FAILED="" +declare -A TEST_FILES # Only use /dev/kmsg if running as root DO_KMSG="1" @@ -17,7 +17,7 @@ DO_KMSG="1" # Include config.local if exists and check TEST_FILES for valid devices if [ -f "$TEST_DIR/config.local" ]; then . $TEST_DIR/config.local - for dev in $TEST_FILES; do + for dev in ${TEST_FILES[@]}; do if [ ! -e "$dev" ]; then echo "Test file $dev not valid" exit 1 @@ -109,11 +109,10 @@ run_test() # Run all specified tests for tst in $TESTS; do - run_test $tst - if [ ! -z "$TEST_FILES" ]; then - for dev in $TEST_FILES; do - run_test $tst $dev - done + if [ ! -n "${TEST_FILES[$tst]}" ]; then + run_test $tst + else + run_test $tst ${TEST_FILES[$tst]} fi done