diff mbox series

[kvm-unit-tests] run_tests: add list tests name option on command line

Message ID 20230511083329.3432954-1-renmm6@chinaunicom.cn (mailing list archive)
State New, archived
Headers show
Series [kvm-unit-tests] run_tests: add list tests name option on command line | expand

Commit Message

From: rminmin <renmm6@chinaunicom.cn>

Add '-l | --list' option on command line to output
all tests name only, and cloud be filtered by group
with '-g | --group' option.

E.g.
  List all vmx group tests name:
  $ ./run_tests.sh -g vmx -l

  List all tests name:
  $ ./run_tests.sh -l

Signed-off-by: rminmin <renmm6@chinaunicom.cn>
---
 run_tests.sh        | 14 ++++++++++++--
 scripts/common.bash | 24 ++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 2 deletions(-)

--
2.33.0

Èç¹ûÄú´íÎó½ÓÊÕÁ˸ÃÓʼþ£¬Çëͨ¹ýµç×ÓÓʼþÁ¢¼´Í¨ÖªÎÒÃÇ¡£Çë»Ø¸´Óʼþµ½ hqs-spmc@chinaunicom.cn£¬¼´¿ÉÒÔÍ˶©´ËÓʼþ¡£ÎÒÃǽ«Á¢¼´½«ÄúµÄÐÅÏ¢´ÓÎÒÃǵķ¢ËÍĿ¼ÖÐɾ³ý¡£ If you have received this email in error please notify us immediately by e-mail. Please reply to hqs-spmc@chinaunicom.cn ,you can unsubscribe from this mail. We will immediately remove your information from send catalogue of our.

Comments

Andrew Jones May 11, 2023, 10:06 a.m. UTC | #1
On Thu, May 11, 2023 at 04:33:29PM +0800, 任敏敏(联通集团联通数字科技有限公司本部) wrote:
> From: rminmin <renmm6@chinaunicom.cn>
> 
> Add '-l | --list' option on command line to output
> all tests name only, and cloud be filtered by group
> with '-g | --group' option.
> 
> E.g.
>   List all vmx group tests name:
>   $ ./run_tests.sh -g vmx -l
> 
>   List all tests name:
>   $ ./run_tests.sh -l
> 
> Signed-off-by: rminmin <renmm6@chinaunicom.cn>
> ---
>  run_tests.sh        | 14 ++++++++++++--
>  scripts/common.bash | 24 ++++++++++++++++++++++++
>  2 files changed, 36 insertions(+), 2 deletions(-)
> 
> diff --git a/run_tests.sh b/run_tests.sh
> index f61e005..a95c2bc 100755
> --- a/run_tests.sh
> +++ b/run_tests.sh
> @@ -15,7 +15,7 @@ function usage()
>  {
>  cat <<EOF
> 
> -Usage: $0 [-h] [-v] [-a] [-g group] [-j NUM-TASKS] [-t]
> +Usage: $0 [-h] [-v] [-a] [-g group] [-j NUM-TASKS] [-t] [-l]
> 
>      -h, --help      Output this help text
>      -v, --verbose   Enables verbose mode
> @@ -24,6 +24,7 @@ Usage: $0 [-h] [-v] [-a] [-g group] [-j NUM-TASKS] [-t]
>      -g, --group     Only execute tests in the given group
>      -j, --parallel  Execute tests in parallel
>      -t, --tap13     Output test results in TAP format
> +    -l, --list      Only output all tests list
> 
>  Set the environment variable QEMU=/path/to/qemu-system-ARCH to
>  specify the appropriate qemu binary for ARCH-run.
> @@ -42,7 +43,8 @@ if [ $? -ne 4 ]; then
>  fi
> 
>  only_tests=""
> -args=$(getopt -u -o ag:htj:v -l all,group:,help,tap13,parallel:,verbose -- $*)
> +list_tests=""
> +args=$(getopt -u -o ag:htj:v:l -l all,group:,help,tap13,parallel:,verbose:,list -- $*)
>  [ $? -ne 0 ] && exit 2;
>  set -- $args;
>  while [ $# -gt 0 ]; do
> @@ -73,6 +75,9 @@ while [ $# -gt 0 ]; do
>          -t | --tap13)
>              tap_output="yes"
>              ;;
> +       -l | --list)
> +           list_tests="yes"
> +           ;;

run_tests.sh is a complete mess for space/tab style, but it looks like
you've used tabs when the rest of this case statement is using spaces...

>          --)
>              ;;
>          *)
> @@ -154,6 +159,11 @@ function run_task()
>  : ${unittest_run_queues:=1}
>  config=$TEST_DIR/unittests.cfg
> 
> +if [[ $list_tests == "yes" ]];then
                                 ^ please add a space here after ;

> +       output_tests_list $config
> +       exit
> +fi
> +
>  rm -rf $unittest_log_dir.old
>  [ -d $unittest_log_dir ] && mv $unittest_log_dir $unittest_log_dir.old
>  mkdir $unittest_log_dir || exit 2
> diff --git a/scripts/common.bash b/scripts/common.bash
> index 7b983f7..7ff1098 100644
> --- a/scripts/common.bash
> +++ b/scripts/common.bash
> @@ -61,6 +61,30 @@ function arch_cmd()
>         [ "${ARCH_CMD}" ] && echo "${ARCH_CMD}"
>  }
> 
> +function output_tests_list()
> +{
> +       local unittests="$1"
> +       local testname=""
> +       local group=""
> +       exec {fd}<"$unittests"
> +       while read -r -u $fd line; do
> +               if [[ "$line" =~ ^\[(.*)\]$ ]]; then
> +                       if [ -z "${only_group}" ] || [[ -n "${group}" ]];then
> +                               if [ -n "${testname}" ];then
> +                                       echo "${testname}"
> +                               fi
> +                       fi
> +                       testname=${BASH_REMATCH[1]}
> +                       group=""
> +               elif [[ $line =~ ^groups\ *=\ *(.*)$ ]]; then
> +                       local groups=${BASH_REMATCH[1]}
> +                       if [ -n "$only_group" ] && find_word "$only_group" "$groups";then
> +                               group=$only_group
> +                       fi
> +               fi
> +       done
> +}
> +

None of this is necessary. All you need is to add the '--list' option and
then do

diff --git a/run_tests.sh b/run_tests.sh
index f61e0057b537..4c1b174a20bb 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -154,6 +154,12 @@ function run_task()
 : ${unittest_run_queues:=1}
 config=$TEST_DIR/unittests.cfg

+print_testname() { echo "$1"; }
+if [[ $list_tests == "yes" ]]; then
+       for_each_unittest $config print_testname
+       exit
+fi
+
 rm -rf $unittest_log_dir.old
 [ -d $unittest_log_dir ] && mv $unittest_log_dir $unittest_log_dir.old
 mkdir $unittest_log_dir || exit 2


Thanks,
drew
diff mbox series

Patch

diff --git a/run_tests.sh b/run_tests.sh
index f61e005..a95c2bc 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -15,7 +15,7 @@  function usage()
 {
 cat <<EOF

-Usage: $0 [-h] [-v] [-a] [-g group] [-j NUM-TASKS] [-t]
+Usage: $0 [-h] [-v] [-a] [-g group] [-j NUM-TASKS] [-t] [-l]

     -h, --help      Output this help text
     -v, --verbose   Enables verbose mode
@@ -24,6 +24,7 @@  Usage: $0 [-h] [-v] [-a] [-g group] [-j NUM-TASKS] [-t]
     -g, --group     Only execute tests in the given group
     -j, --parallel  Execute tests in parallel
     -t, --tap13     Output test results in TAP format
+    -l, --list      Only output all tests list

 Set the environment variable QEMU=/path/to/qemu-system-ARCH to
 specify the appropriate qemu binary for ARCH-run.
@@ -42,7 +43,8 @@  if [ $? -ne 4 ]; then
 fi

 only_tests=""
-args=$(getopt -u -o ag:htj:v -l all,group:,help,tap13,parallel:,verbose -- $*)
+list_tests=""
+args=$(getopt -u -o ag:htj:v:l -l all,group:,help,tap13,parallel:,verbose:,list -- $*)
 [ $? -ne 0 ] && exit 2;
 set -- $args;
 while [ $# -gt 0 ]; do
@@ -73,6 +75,9 @@  while [ $# -gt 0 ]; do
         -t | --tap13)
             tap_output="yes"
             ;;
+       -l | --list)
+           list_tests="yes"
+           ;;
         --)
             ;;
         *)
@@ -154,6 +159,11 @@  function run_task()
 : ${unittest_run_queues:=1}
 config=$TEST_DIR/unittests.cfg

+if [[ $list_tests == "yes" ]];then
+       output_tests_list $config
+       exit
+fi
+
 rm -rf $unittest_log_dir.old
 [ -d $unittest_log_dir ] && mv $unittest_log_dir $unittest_log_dir.old
 mkdir $unittest_log_dir || exit 2
diff --git a/scripts/common.bash b/scripts/common.bash
index 7b983f7..7ff1098 100644
--- a/scripts/common.bash
+++ b/scripts/common.bash
@@ -61,6 +61,30 @@  function arch_cmd()
        [ "${ARCH_CMD}" ] && echo "${ARCH_CMD}"
 }

+function output_tests_list()
+{
+       local unittests="$1"
+       local testname=""
+       local group=""
+       exec {fd}<"$unittests"
+       while read -r -u $fd line; do
+               if [[ "$line" =~ ^\[(.*)\]$ ]]; then
+                       if [ -z "${only_group}" ] || [[ -n "${group}" ]];then
+                               if [ -n "${testname}" ];then
+                                       echo "${testname}"
+                               fi
+                       fi
+                       testname=${BASH_REMATCH[1]}
+                       group=""
+               elif [[ $line =~ ^groups\ *=\ *(.*)$ ]]; then
+                       local groups=${BASH_REMATCH[1]}
+                       if [ -n "$only_group" ] && find_word "$only_group" "$groups";then
+                               group=$only_group
+                       fi
+               fi
+       done
+}
+
 # The current file has to be the only file sourcing the arch helper
 # file
 ARCH_FUNC=scripts/${ARCH}/func.bash