Skip to contentSkip to conversation

test: use a map to define test files / devices we need

PATCH In review Hao Xu 2 participants 6 messages Dec 8, 2020 – Jan 27, 2021 io_uring

lore
Share & tools
lore

Hao Xu

author
#0 lore raw

PATCH 1/1 test: use a map to define test files / devices we need

Different tests need different files / devices, use a map to indicate what each test need.

---

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(-)
test/config +1 -1
index cab270359155..1bd9b40207bb 100644
@@ -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=()
test/runtests.sh +6 -7
index fa240f205542..1a6905b42768 100755
@@ -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
 
Signature · 1 line
1.8.3.1
author
#1 lore raw

在 2020/12/8 下午8:28, Hao Xu 写道:
ping...

Quoted 73 lines

Different tests need different files / devices, use a map to indicate what each test need.

---

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(-)
test/config +1 -1
index cab270359155..1bd9b40207bb 100644
@@ -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=()
test/runtests.sh +6 -7
index fa240f205542..1a6905b42768 100755
@@ -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
 
author
#2 lore raw
Quoted 2 lines · 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

Quoted 70 lines
Quoted 70 lines

Different tests need different files / devices, use a map to indicate what each test need.

---

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(-)
test/config +1 -1
index cab270359155..1bd9b40207bb 100644
@@ -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=()
test/runtests.sh +0 -0
index fa240f205542..1a6905b42768 100755
@@ -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"

test/runtests.sh +0 -0
@@ -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

test/runtests.sh +0 -0
@@ -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

author
#3 lore raw
Quoted 9 lines · Hao Xu
Quoted 2 lines · 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

ping again..

Quoted 70 lines
Quoted 70 lines
Quoted 70 lines

Different tests need different files / devices, use a map to indicate what each test need.

---

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(-)
test/config +1 -1
index cab270359155..1bd9b40207bb 100644
@@ -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=()
test/runtests.sh +0 -0
index fa240f205542..1a6905b42768 100755
@@ -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"

test/runtests.sh +0 -0
@@ -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

test/runtests.sh +0 -0
@@ -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

maintainer
#4 lore raw
Quoted 11 lines · Hao Xu
Quoted 9 lines · Hao Xu
Quoted 2 lines · 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

ping again..

Sorry about the delay - I have applied it, thanks.

Signature · 1 line
Jens Axboe
author
#5 lore raw
Quoted 11 lines · Jens Axboe
Quoted 10 lines · Hao Xu
Quoted 9 lines · Hao Xu
Quoted 2 lines · 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

Quoted 4 lines
Quoted 1 line

ping again..

Sorry about the delay - I have applied it, thanks.

No worries. Thanks, Jens.