* [LTP] [RFC PATCH v2 0/2] Shell: Add TST_TEST_DATA and TST_TEST_DATA_IFS
@ 2018-05-16 16:18 Petr Vorel
2018-05-16 16:18 ` [LTP] [RFC PATCH v2 1/2] tst_test.sh: " Petr Vorel
2018-05-16 16:18 ` [LTP] [RFC PATCH v2 2/2] net/{stress, virt}: Use " Petr Vorel
0 siblings, 2 replies; 8+ messages in thread
From: Petr Vorel @ 2018-05-16 16:18 UTC (permalink / raw)
To: ltp
Hi,
changes v1->v2:
* renamed variables to TST_TEST_DATA and TST_TEST_DATA_IFS (Cyril)
* replace split with IFS by split with while & cut (Cyril)
* TST_TESTFUNC_DATA can be used with TST_CNT
* iteration/sequence number is in $1, data are in $2
* For consistency the test number is now passed also to functions as the
'$1' in tests using $TST_CNT in separate functions (so that
TST_TEST_DATA is always passed as the '$2'). This is also updated in doc.
* improved doc
Petr Vorel (2):
tst_test.sh: Add TST_TEST_DATA and TST_TEST_DATA_IFS
net/{stress,virt}: Use TST_TEST_DATA and TST_TEST_DATA_IFS
doc/test-writing-guidelines.txt | 74 ++++++++++++++++++++++---
lib/newlib_tests/Makefile | 19 -------
testcases/lib/tst_test.sh | 22 ++++++--
testcases/network/stress/dccp/dccp_ipsec.sh | 5 +-
testcases/network/stress/dccp/dccp_ipsec_vti.sh | 5 +-
testcases/network/stress/ipsec/ipsec_lib.sh | 3 +-
testcases/network/stress/sctp/sctp_ipsec.sh | 6 +-
testcases/network/stress/sctp/sctp_ipsec_vti.sh | 7 +--
testcases/network/stress/tcp/tcp_ipsec.sh | 6 +-
testcases/network/stress/tcp/tcp_ipsec_vti.sh | 5 +-
testcases/network/stress/udp/udp_ipsec.sh | 7 +--
testcases/network/stress/udp/udp_ipsec_vti.sh | 7 +--
12 files changed, 100 insertions(+), 66 deletions(-)
delete mode 100644 lib/newlib_tests/Makefile
--
2.16.3
^ permalink raw reply [flat|nested] 8+ messages in thread
* [LTP] [RFC PATCH v2 1/2] tst_test.sh: Add TST_TEST_DATA and TST_TEST_DATA_IFS
2018-05-16 16:18 [LTP] [RFC PATCH v2 0/2] Shell: Add TST_TEST_DATA and TST_TEST_DATA_IFS Petr Vorel
@ 2018-05-16 16:18 ` Petr Vorel
2018-05-16 16:22 ` Petr Vorel
2018-05-22 10:42 ` Cyril Hrubis
2018-05-16 16:18 ` [LTP] [RFC PATCH v2 2/2] net/{stress, virt}: Use " Petr Vorel
1 sibling, 2 replies; 8+ messages in thread
From: Petr Vorel @ 2018-05-16 16:18 UTC (permalink / raw)
To: ltp
This is specific only for shell.
+ for consistency the test number is now passed also to functions as the
'$1' in tests using $TST_CNT in separate functions (so that
TST_TEST_DATA is always passed as the '$2').
This is also updated in doc.
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
doc/test-writing-guidelines.txt | 74 +++++++++++++++++++++++++++++++++++++----
testcases/lib/tst_test.sh | 22 +++++++++---
2 files changed, 85 insertions(+), 11 deletions(-)
diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt
index 0bf698183..031823742 100644
--- a/doc/test-writing-guidelines.txt
+++ b/doc/test-writing-guidelines.txt
@@ -1442,12 +1442,12 @@ TST_CNT=2
test1()
{
- tst_res TPASS "Test 1 passed"
+ tst_res TPASS "Test $1 passed"
}
test2()
{
- tst_res TPASS "Test 2 passed"
+ tst_res TPASS "Test $1 passed"
}
tst_run
@@ -1455,7 +1455,8 @@ tst_run
If '$TST_CNT' is set, the test library looks if there are functions named
'$\{TST_TESTFUNC\}1', ..., '$\{TST_TESTFUNC\}$\{TST_CNT\}' and if these are
-found they are executed one by one.
+found they are executed one by one. The test number is passed to it in the '$1'.
+
[source,sh]
-------------------------------------------------------------------------------
@@ -1471,8 +1472,8 @@ TST_CNT=2
do_test()
{
case $1 in
- 1) tst_res TPASS "Test 1 passed";;
- 2) tst_res TPASS "Test 2 passed";;
+ 1) tst_res TPASS "Test $1 passed";;
+ 2) tst_res TPASS "Test $1 passed";;
esac
}
@@ -1483,6 +1484,65 @@ Otherwise, if '$TST_CNT' is set but there is no '$\{TST_TESTFUNC\}1', etc.,
the '$TST_TESTFUNC' is executed '$TST_CNT' times and the test number is passed
to it in the '$1'.
+[source,sh]
+-------------------------------------------------------------------------------
+#!/bin/sh
+#
+# Example test with tests in a single function, using $TST_TEST_DATA and
+# $TST_TEST_DATA_IFS
+#
+
+TST_TESTFUNC=do_test
+TST_TEST_DATA="foo:bar:d dd"
+TST_TEST_DATA_IFS=":"
+. tst_test.sh
+
+do_test()
+{
+ tst_res TPASS "Test $1 passed with data '$2'"
+}
+
+tst_run
+# output:
+# test 1 TPASS: Test 1 passed with data 'foo'
+# test 2 TPASS: Test 2 passed with data 'bar'
+# test 3 TPASS: Test 3 passed with data 'd dd'
+
+-------------------------------------------------------------------------------
+
+It's possible to pass data for function with '$TST_TEST_DATA'. Optional
+'$TST_TEST_DATA_IFS' is used for splitting, default value is space.
+
+[source,sh]
+-------------------------------------------------------------------------------
+#!/bin/sh
+#
+# Example test with tests in a single function, using $TST_TEST_DATA and $TST_CNT
+#
+
+TST_TESTFUNC=do_test
+TST_CNT=2
+TST_TEST_DATA="foo:bar:d dd"
+. tst_test.sh
+
+do_test()
+{
+ case $1 in
+ 1) tst_res TPASS "Test $1 passed with data '$2'";;
+ 2) tst_res TPASS "Test $1 passed with data '$2'";;
+ esac
+}
+
+tst_run
+# output:
+# test 1 TPASS: Test 1 passed with data 'foo:bar:d'
+# test 2 TPASS: Test 2 passed with data 'foo:bar:d'
+
+-------------------------------------------------------------------------------
+When '$TST_TEST_DATA' is used with '$TST_CNT', it's passed as whole string in
+'$2' ($1 is for the test number), '$TST_TEST_DATA_IFS' is ignored. Similar
+would be when using these variables with separate functions.
+
2.3.2 Library variables
^^^^^^^^^^^^^^^^^^^^^^^
@@ -1587,8 +1647,8 @@ these can be listed with passing help '-h' option to any test.
The function that prints the usage is passed in '$TST_USAGE', the help for
the options implemented in the library is appended when usage is printed.
-Lastly the fucntion '$PARSE_ARGS' is called with the option name in '$1' and,
-if option has argument, its value in '$2'.
+Lastly the fucntion '$PARSE_ARGS' is called with the option name in the '$1'
+and, if option has argument, its value in the '$2'.
[source,sh]
-------------------------------------------------------------------------------
diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index 8d49d34b6..422350ed4 100644
--- a/testcases/lib/tst_test.sh
+++ b/testcases/lib/tst_test.sh
@@ -246,7 +246,7 @@ tst_rescmp()
tst_run()
{
- local tst_i
+ local tst_i tst_data
if [ -n "$TST_TEST_PATH" ]; then
for tst_i in $(grep TST_ "$TST_TEST_PATH" | sed 's/.*TST_//; s/[="} \t\/:`].*//'); do
@@ -255,7 +255,7 @@ tst_run()
OPTS|USAGE|PARSE_ARGS|POS_ARGS);;
NEEDS_ROOT|NEEDS_TMPDIR|NEEDS_DEVICE|DEVICE);;
NEEDS_CMDS|NEEDS_MODULE|MODPATH|DATAROOT);;
- IPV6);;
+ IPV6|TEST_DATA|TEST_DATA_IFS);;
*) tst_res TWARN "Reserved variable TST_$tst_i used!";;
esac
done
@@ -352,18 +352,30 @@ tst_run()
if type test1 > /dev/null 2>&1; then
for tst_i in $(seq $TST_CNT); do
local res=$(tst_resstr)
- $TST_TESTFUNC$tst_i
+ $TST_TESTFUNC$tst_i $tst_i $TST_TEST_DATA
tst_rescmp "$res"
TST_COUNT=$((TST_COUNT+1))
done
else
for tst_i in $(seq $TST_CNT); do
local res=$(tst_resstr)
- $TST_TESTFUNC $tst_i
+ $TST_TESTFUNC $tst_i $TST_TEST_DATA
tst_rescmp "$res"
TST_COUNT=$((TST_COUNT+1))
done
fi
+ elif [ -n "$TST_TEST_DATA" ]; then
+ tst_i=1
+ tst_check_cmds cut
+ while true; do
+ tst_data="$(echo "$TST_TEST_DATA" | cut -d"$TST_TEST_DATA_IFS" -f$tst_i)"
+ [ -z "$tst_data" ] && break
+ local res=$(tst_resstr)
+ $TST_TESTFUNC $tst_i "$tst_data"
+ tst_rescmp "$res"
+ TST_COUNT=$((TST_COUNT+1))
+ tst_i=$((tst_i+1))
+ done
else
local res=$(tst_resstr)
$TST_TESTFUNC
@@ -400,6 +412,8 @@ if [ -z "$TST_NO_DEFAULT_RUN" ]; then
tst_brk TBROK "TST_TESTFUNC is not defined"
fi
+ TST_TEST_DATA_IFS="${TST_TEST_DATA_IFS:- }"
+
if [ -n "$TST_CNT" ]; then
if ! tst_is_int "$TST_CNT"; then
tst_brk TBROK "TST_CNT must be integer"
--
2.16.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [LTP] [RFC PATCH v2 2/2] net/{stress, virt}: Use TST_TEST_DATA and TST_TEST_DATA_IFS
2018-05-16 16:18 [LTP] [RFC PATCH v2 0/2] Shell: Add TST_TEST_DATA and TST_TEST_DATA_IFS Petr Vorel
2018-05-16 16:18 ` [LTP] [RFC PATCH v2 1/2] tst_test.sh: " Petr Vorel
@ 2018-05-16 16:18 ` Petr Vorel
2018-05-16 16:20 ` Petr Vorel
2018-05-17 14:10 ` Petr Vorel
1 sibling, 2 replies; 8+ messages in thread
From: Petr Vorel @ 2018-05-16 16:18 UTC (permalink / raw)
To: ltp
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
lib/newlib_tests/Makefile | 19 -------------------
testcases/network/stress/dccp/dccp_ipsec.sh | 5 +----
testcases/network/stress/dccp/dccp_ipsec_vti.sh | 5 +----
testcases/network/stress/ipsec/ipsec_lib.sh | 3 ++-
testcases/network/stress/sctp/sctp_ipsec.sh | 6 ++----
testcases/network/stress/sctp/sctp_ipsec_vti.sh | 7 ++-----
testcases/network/stress/tcp/tcp_ipsec.sh | 6 ++----
testcases/network/stress/tcp/tcp_ipsec_vti.sh | 5 +----
testcases/network/stress/udp/udp_ipsec.sh | 7 ++-----
testcases/network/stress/udp/udp_ipsec_vti.sh | 7 ++-----
10 files changed, 15 insertions(+), 55 deletions(-)
delete mode 100644 lib/newlib_tests/Makefile
diff --git a/lib/newlib_tests/Makefile b/lib/newlib_tests/Makefile
deleted file mode 100644
index afa09373e..000000000
--- a/lib/newlib_tests/Makefile
+++ /dev/null
@@ -1,19 +0,0 @@
-top_srcdir ?= ../..
-
-include $(top_srcdir)/include/mk/env_pre.mk
-
-CFLAGS += -W -Wall
-LDLIBS += -lltp
-
-test08: CFLAGS+=-pthread
-test09: CFLAGS+=-pthread
-test15: CFLAGS+=-pthread
-test16: CFLAGS+=-pthread
-test16: LDLIBS+=-lrt
-
-ifeq ($(ANDROID),1)
-FILTER_OUT_MAKE_TARGETS += test08
-endif
-
-
-include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/stress/dccp/dccp_ipsec.sh b/testcases/network/stress/dccp/dccp_ipsec.sh
index dae530fa3..edd1917bb 100755
--- a/testcases/network/stress/dccp/dccp_ipsec.sh
+++ b/testcases/network/stress/dccp/dccp_ipsec.sh
@@ -21,10 +21,7 @@ do_setup()
do_test()
{
- for p in $IPSEC_SIZE_ARRAY; do
- tst_netload -H $(tst_ipaddr rhost) -T dccp -n $p -N $p \
- -r $IPSEC_REQUESTS
- done
+ tst_netload -H $(tst_ipaddr rhost) -T dccp -n $2 -N $2 -r $IPSEC_REQUESTS
}
tst_run
diff --git a/testcases/network/stress/dccp/dccp_ipsec_vti.sh b/testcases/network/stress/dccp/dccp_ipsec_vti.sh
index 787460aab..ee2b0d4ca 100755
--- a/testcases/network/stress/dccp/dccp_ipsec_vti.sh
+++ b/testcases/network/stress/dccp/dccp_ipsec_vti.sh
@@ -12,10 +12,7 @@ TST_CLEANUP=tst_ipsec_cleanup
do_test()
{
- for p in $IPSEC_SIZE_ARRAY; do
- tst_netload -H $ip_rmt_tun -T dccp -n $p -N $p \
- -r $IPSEC_REQUESTS
- done
+ tst_netload -H $ip_rmt_tun -T dccp -n $2 -N $2 -r $IPSEC_REQUESTS
}
tst_run
diff --git a/testcases/network/stress/ipsec/ipsec_lib.sh b/testcases/network/stress/ipsec/ipsec_lib.sh
index bfb022bd0..5e6c68278 100644
--- a/testcases/network/stress/ipsec/ipsec_lib.sh
+++ b/testcases/network/stress/ipsec/ipsec_lib.sh
@@ -48,7 +48,8 @@ ipsec_lib_parse_args()
r) IPSEC_REQUESTS="$2" ;;
esac
- IPSEC_SIZE_ARRAY="$(echo $IPSEC_SIZE_ARRAY | sed 's/:/ /g')"
+ TST_TEST_DATA="$IPSEC_SIZE_ARRAY"
+ TST_TEST_DATA_IFS=":"
}
TST_OPTS="l:m:p:s:S:k:A:e:a:c:r:"
diff --git a/testcases/network/stress/sctp/sctp_ipsec.sh b/testcases/network/stress/sctp/sctp_ipsec.sh
index 2dc025352..46f43ea9d 100755
--- a/testcases/network/stress/sctp/sctp_ipsec.sh
+++ b/testcases/network/stress/sctp/sctp_ipsec.sh
@@ -21,10 +21,8 @@ do_setup()
do_test()
{
- for p in $IPSEC_SIZE_ARRAY; do
- tst_netload -H $(tst_ipaddr rhost) -T sctp -n $p -N $p \
- -r $IPSEC_REQUESTS -S $(tst_ipaddr)
- done
+ tst_netload -H $(tst_ipaddr rhost) -T sctp -n $2 -N $2 \
+ -r $IPSEC_REQUESTS -S $(tst_ipaddr)
}
tst_run
diff --git a/testcases/network/stress/sctp/sctp_ipsec_vti.sh b/testcases/network/stress/sctp/sctp_ipsec_vti.sh
index 160b618e7..d0f24c727 100755
--- a/testcases/network/stress/sctp/sctp_ipsec_vti.sh
+++ b/testcases/network/stress/sctp/sctp_ipsec_vti.sh
@@ -7,16 +7,13 @@
TST_NEEDS_TMPDIR=1
TST_SETUP=tst_ipsec_setup_vti
TST_CLEANUP=tst_ipsec_cleanup
-
TST_TESTFUNC=do_test
. ipsec_lib.sh
do_test()
{
- for p in $IPSEC_SIZE_ARRAY; do
- tst_netload -H $ip_rmt_tun -T sctp -n $p -N $p \
- -r $IPSEC_REQUESTS -S $ip_loc_tun
- done
+ tst_netload -H $ip_rmt_tun -T sctp -n $2 -N $2 -r $IPSEC_REQUESTS \
+ -S $ip_loc_tun
}
tst_run
diff --git a/testcases/network/stress/tcp/tcp_ipsec.sh b/testcases/network/stress/tcp/tcp_ipsec.sh
index edea89361..d5254c394 100755
--- a/testcases/network/stress/tcp/tcp_ipsec.sh
+++ b/testcases/network/stress/tcp/tcp_ipsec.sh
@@ -23,10 +23,8 @@ do_setup()
do_test()
{
- for p in $IPSEC_SIZE_ARRAY; do
- tst_netload -H $(tst_ipaddr rhost) -n $p -N $p \
- -r $IPSEC_REQUESTS -R $max_requests
- done
+ tst_netload -H $(tst_ipaddr rhost) -n $2 -N $2 -r $IPSEC_REQUESTS \
+ -R $max_requests
}
tst_run
diff --git a/testcases/network/stress/tcp/tcp_ipsec_vti.sh b/testcases/network/stress/tcp/tcp_ipsec_vti.sh
index 78329f995..2172662eb 100755
--- a/testcases/network/stress/tcp/tcp_ipsec_vti.sh
+++ b/testcases/network/stress/tcp/tcp_ipsec_vti.sh
@@ -14,10 +14,7 @@ max_requests=10
do_test()
{
- for p in $IPSEC_SIZE_ARRAY; do
- tst_netload -H $ip_rmt_tun -n $p -N $p \
- -r $IPSEC_REQUESTS -R $max_requests
- done
+ tst_netload -H $ip_rmt_tun -n $2 -N $2 -r $IPSEC_REQUESTS -R $max_requests
}
tst_run
diff --git a/testcases/network/stress/udp/udp_ipsec.sh b/testcases/network/stress/udp/udp_ipsec.sh
index 063a18705..2a0dee4cd 100755
--- a/testcases/network/stress/udp/udp_ipsec.sh
+++ b/testcases/network/stress/udp/udp_ipsec.sh
@@ -22,12 +22,9 @@ do_setup()
do_test()
{
local type="udp"
- [ $1 -gt 3 ] && type="udp_lite"
+ [ $2 -gt 3 ] && type="udp_lite"
- for p in $IPSEC_SIZE_ARRAY; do
- tst_netload -H $(tst_ipaddr rhost) -T $type -n $p -N $p \
- -r $IPSEC_REQUESTS
- done
+ tst_netload -H $(tst_ipaddr rhost) -T $type -n $2 -N $2 -r $IPSEC_REQUESTS
}
tst_run
diff --git a/testcases/network/stress/udp/udp_ipsec_vti.sh b/testcases/network/stress/udp/udp_ipsec_vti.sh
index a0a8e03fc..7de8761d7 100755
--- a/testcases/network/stress/udp/udp_ipsec_vti.sh
+++ b/testcases/network/stress/udp/udp_ipsec_vti.sh
@@ -13,12 +13,9 @@ TST_CLEANUP=tst_ipsec_setup_vti
do_test()
{
local type="udp"
- [ $1 -gt 3 ] && type="udp_lite"
+ [ $2 -gt 3 ] && type="udp_lite"
- for p in $IPSEC_SIZE_ARRAY; do
- tst_netload -H $ip_rmt_tun -T $type -n $p -N $p \
- -r $IPSEC_REQUESTS
- done
+ tst_netload -H $ip_rmt_tun -T $type -n $2 -N $2 -r $IPSEC_REQUESTS
}
tst_run
--
2.16.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [LTP] [RFC PATCH v2 2/2] net/{stress, virt}: Use TST_TEST_DATA and TST_TEST_DATA_IFS
2018-05-16 16:18 ` [LTP] [RFC PATCH v2 2/2] net/{stress, virt}: Use " Petr Vorel
@ 2018-05-16 16:20 ` Petr Vorel
2018-05-17 14:10 ` Petr Vorel
1 sibling, 0 replies; 8+ messages in thread
From: Petr Vorel @ 2018-05-16 16:20 UTC (permalink / raw)
To: ltp
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
Not-yet-signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
This is just for demonstration purposes as it's not applicable as it
expect more changes to be posted later in patch rewriting
net/{stress,virt} into new shell API (see cover letter).
Kind regards,
Petr
^ permalink raw reply [flat|nested] 8+ messages in thread
* [LTP] [RFC PATCH v2 1/2] tst_test.sh: Add TST_TEST_DATA and TST_TEST_DATA_IFS
2018-05-16 16:18 ` [LTP] [RFC PATCH v2 1/2] tst_test.sh: " Petr Vorel
@ 2018-05-16 16:22 ` Petr Vorel
2018-05-22 10:42 ` Cyril Hrubis
1 sibling, 0 replies; 8+ messages in thread
From: Petr Vorel @ 2018-05-16 16:22 UTC (permalink / raw)
To: ltp
> + for consistency the test number is now passed also to functions as the
> '$1' in tests using $TST_CNT in separate functions (so that
> TST_TEST_DATA is always passed as the '$2').
> This is also updated in doc.
To see changes live look bellow:
https://github.com/pevik/ltp/wiki/TEST#231-basic-test-interface
Kind regards,
Petr
^ permalink raw reply [flat|nested] 8+ messages in thread
* [LTP] [RFC PATCH v2 2/2] net/{stress, virt}: Use TST_TEST_DATA and TST_TEST_DATA_IFS
2018-05-16 16:18 ` [LTP] [RFC PATCH v2 2/2] net/{stress, virt}: Use " Petr Vorel
2018-05-16 16:20 ` Petr Vorel
@ 2018-05-17 14:10 ` Petr Vorel
1 sibling, 0 replies; 8+ messages in thread
From: Petr Vorel @ 2018-05-17 14:10 UTC (permalink / raw)
To: ltp
Hi,
> diff --git a/lib/newlib_tests/Makefile b/lib/newlib_tests/Makefile
> deleted file mode 100644
> index afa09373e..000000000
> --- a/lib/newlib_tests/Makefile
> +++ /dev/null
> @@ -1,19 +0,0 @@
> -top_srcdir ?= ../..
> -
> -include $(top_srcdir)/include/mk/env_pre.mk
> -
> -CFLAGS += -W -Wall
> -LDLIBS += -lltp
> -
> -test08: CFLAGS+=-pthread
> -test09: CFLAGS+=-pthread
> -test15: CFLAGS+=-pthread
> -test16: CFLAGS+=-pthread
> -test16: LDLIBS+=-lrt
> -
> -ifeq ($(ANDROID),1)
> -FILTER_OUT_MAKE_TARGETS += test08
> -endif
> -
> -
This part is obviously added by accident, I'm sorry.
Kind regards,
Petr
^ permalink raw reply [flat|nested] 8+ messages in thread
* [LTP] [RFC PATCH v2 1/2] tst_test.sh: Add TST_TEST_DATA and TST_TEST_DATA_IFS
2018-05-16 16:18 ` [LTP] [RFC PATCH v2 1/2] tst_test.sh: " Petr Vorel
2018-05-16 16:22 ` Petr Vorel
@ 2018-05-22 10:42 ` Cyril Hrubis
2018-05-22 19:37 ` Petr Vorel
1 sibling, 1 reply; 8+ messages in thread
From: Cyril Hrubis @ 2018-05-22 10:42 UTC (permalink / raw)
To: ltp
Hi!
> tst_run()
> {
> - local tst_i
> + local tst_i tst_data
>
> if [ -n "$TST_TEST_PATH" ]; then
> for tst_i in $(grep TST_ "$TST_TEST_PATH" | sed 's/.*TST_//; s/[="} \t\/:`].*//'); do
> @@ -255,7 +255,7 @@ tst_run()
> OPTS|USAGE|PARSE_ARGS|POS_ARGS);;
> NEEDS_ROOT|NEEDS_TMPDIR|NEEDS_DEVICE|DEVICE);;
> NEEDS_CMDS|NEEDS_MODULE|MODPATH|DATAROOT);;
> - IPV6);;
> + IPV6|TEST_DATA|TEST_DATA_IFS);;
> *) tst_res TWARN "Reserved variable TST_$tst_i used!";;
> esac
> done
> @@ -352,18 +352,30 @@ tst_run()
> if type test1 > /dev/null 2>&1; then
> for tst_i in $(seq $TST_CNT); do
> local res=$(tst_resstr)
> - $TST_TESTFUNC$tst_i
> + $TST_TESTFUNC$tst_i $tst_i $TST_TEST_DATA
> tst_rescmp "$res"
> TST_COUNT=$((TST_COUNT+1))
> done
> else
> for tst_i in $(seq $TST_CNT); do
> local res=$(tst_resstr)
> - $TST_TESTFUNC $tst_i
> + $TST_TESTFUNC $tst_i $TST_TEST_DATA
> tst_rescmp "$res"
> TST_COUNT=$((TST_COUNT+1))
> done
> fi
So in this implementation we cannot use IFS to separate the arguments,
without that it's kind of useless as we can pass anything in global
variable anyway...
> + elif [ -n "$TST_TEST_DATA" ]; then
> + tst_i=1
> + tst_check_cmds cut
> + while true; do
> + tst_data="$(echo "$TST_TEST_DATA" | cut -d"$TST_TEST_DATA_IFS" -f$tst_i)"
> + [ -z "$tst_data" ] && break
> + local res=$(tst_resstr)
> + $TST_TESTFUNC $tst_i "$tst_data"
> + tst_rescmp "$res"
> + TST_COUNT=$((TST_COUNT+1))
> + tst_i=$((tst_i+1))
> + done
> else
> local res=$(tst_resstr)
> $TST_TESTFUNC
> @@ -400,6 +412,8 @@ if [ -z "$TST_NO_DEFAULT_RUN" ]; then
> tst_brk TBROK "TST_TESTFUNC is not defined"
> fi
Uff, the maze of if conditions is getting out of hand a bit.
Why dont we move innter part of the while [ $TST_ITERATION -gt 0 ] loop
to a separate tst_run_tests() function and add the ability to pass data
in $1 there. Then we can do something as:
while [ $TST_INTERATION -gt 0 ]; then
if [ -n $TST_TEST_DATA ]; then
for tst_data in ...; do
tst_run_tests "$tst_data"
done
else
tst_run_tests
fi
done
> + TST_TEST_DATA_IFS="${TST_TEST_DATA_IFS:- }"
> +
> if [ -n "$TST_CNT" ]; then
> if ! tst_is_int "$TST_CNT"; then
> tst_brk TBROK "TST_CNT must be integer"
> --
> 2.16.3
>
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 8+ messages in thread
* [LTP] [RFC PATCH v2 1/2] tst_test.sh: Add TST_TEST_DATA and TST_TEST_DATA_IFS
2018-05-22 10:42 ` Cyril Hrubis
@ 2018-05-22 19:37 ` Petr Vorel
0 siblings, 0 replies; 8+ messages in thread
From: Petr Vorel @ 2018-05-22 19:37 UTC (permalink / raw)
To: ltp
Hi Cyril,
> > @@ -352,18 +352,30 @@ tst_run()
> > if type test1 > /dev/null 2>&1; then
> > for tst_i in $(seq $TST_CNT); do
> > local res=$(tst_resstr)
> > - $TST_TESTFUNC$tst_i
> > + $TST_TESTFUNC$tst_i $tst_i $TST_TEST_DATA
> > tst_rescmp "$res"
> > TST_COUNT=$((TST_COUNT+1))
> > done
> > else
> > for tst_i in $(seq $TST_CNT); do
> > local res=$(tst_resstr)
> > - $TST_TESTFUNC $tst_i
> > + $TST_TESTFUNC $tst_i $TST_TEST_DATA
> > tst_rescmp "$res"
> > TST_COUNT=$((TST_COUNT+1))
> > done
> > fi
> So in this implementation we cannot use IFS to separate the arguments,
> without that it's kind of useless as we can pass anything in global
> variable anyway...
> > + elif [ -n "$TST_TEST_DATA" ]; then
> > + tst_i=1
> > + tst_check_cmds cut
> > + while true; do
> > + tst_data="$(echo "$TST_TEST_DATA" | cut -d"$TST_TEST_DATA_IFS" -f$tst_i)"
> > + [ -z "$tst_data" ] && break
> > + local res=$(tst_resstr)
> > + $TST_TESTFUNC $tst_i "$tst_data"
> > + tst_rescmp "$res"
> > + TST_COUNT=$((TST_COUNT+1))
> > + tst_i=$((tst_i+1))
> > + done
> > else
> > local res=$(tst_resstr)
> > $TST_TESTFUNC
> > @@ -400,6 +412,8 @@ if [ -z "$TST_NO_DEFAULT_RUN" ]; then
> > tst_brk TBROK "TST_TESTFUNC is not defined"
> > fi
> Uff, the maze of if conditions is getting out of hand a bit.
> Why dont we move innter part of the while [ $TST_ITERATION -gt 0 ] loop
> to a separate tst_run_tests() function and add the ability to pass data
> in $1 there. Then we can do something as:
> while [ $TST_INTERATION -gt 0 ]; then
> if [ -n $TST_TEST_DATA ]; then
> for tst_data in ...; do
> tst_run_tests "$tst_data"
> done
> else
> tst_run_tests
> fi
> done
Changed in v3 in the way you suggested.
I thought there is a reason not to introduce any function as it'd be exported.
In v3 I added not only tst_run_tests(), but also tst_run_test() helper.
Thanks for your review.
Kind regards,
Petr
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2018-05-22 19:37 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-16 16:18 [LTP] [RFC PATCH v2 0/2] Shell: Add TST_TEST_DATA and TST_TEST_DATA_IFS Petr Vorel
2018-05-16 16:18 ` [LTP] [RFC PATCH v2 1/2] tst_test.sh: " Petr Vorel
2018-05-16 16:22 ` Petr Vorel
2018-05-22 10:42 ` Cyril Hrubis
2018-05-22 19:37 ` Petr Vorel
2018-05-16 16:18 ` [LTP] [RFC PATCH v2 2/2] net/{stress, virt}: Use " Petr Vorel
2018-05-16 16:20 ` Petr Vorel
2018-05-17 14:10 ` Petr Vorel
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.