diff mbox

[kvm-unit-tests,v2,02/12] run_tests: prepare for changes in scripts/mkstandalone

Message ID 1450374823-7648-3-git-send-email-rkrcmar@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Radim Krčmář Dec. 17, 2015, 5:53 p.m. UTC
mkstandalone has a different mechanism for running tests as well as a
different handling of output and return codes.
 - create two shell function to capture test execution and logging
 - return the return value of unit-test
 - cope with empty $verbose in `run`

Signed-off-by: Radim Kr?má? <rkrcmar@redhat.com>
---
 v2: new (reused the bitshift and comment from v1)
 
 run_tests.sh     |  4 ++++
 scripts/run.bash | 13 +++++++++----
 2 files changed, 13 insertions(+), 4 deletions(-)

Comments

Andrew Jones Dec. 17, 2015, 6:53 p.m. UTC | #1
On Thu, Dec 17, 2015 at 06:53:33PM +0100, Radim Kr?má? wrote:
> mkstandalone has a different mechanism for running tests as well as a
> different handling of output and return codes.
>  - create two shell function to capture test execution and logging
>  - return the return value of unit-test
>  - cope with empty $verbose in `run`
> 
> Signed-off-by: Radim Kr?má? <rkrcmar@redhat.com>
> ---
>  v2: new (reused the bitshift and comment from v1)
>  
>  run_tests.sh     |  4 ++++
>  scripts/run.bash | 13 +++++++++----
>  2 files changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/run_tests.sh b/run_tests.sh
> index 58949e39c38c..e09d410beaa4 100755
> --- a/run_tests.sh
> +++ b/run_tests.sh
> @@ -28,7 +28,11 @@ specify the appropriate qemu binary for ARCH-run.
>  EOF
>  }
>  
> +__run() { ./$TEST_DIR-run "${@}"; }
> +__eval_log() { eval "${@}" >> test.log; }
> +
>  echo > test.log
> +
>  while getopts "g:hv" opt; do
>      case $opt in
>          g)
> diff --git a/scripts/run.bash b/scripts/run.bash
> index 0c5a2569d80e..243586c6d2fc 100644
> --- a/scripts/run.bash
> +++ b/scripts/run.bash
> @@ -34,18 +34,23 @@ function run()
>          fi
>      done
>  
> -    cmdline="TESTNAME=$testname ACCEL=$accel ./$TEST_DIR-run $kernel -smp $smp $opts"
> -    if [ $verbose != 0 ]; then
> +    cmdline="TESTNAME=$testname ACCEL=$accel __run $kernel -smp $smp $opts"
> +    if [ "$verbose" -a "$verbose" != 0 ]; then

For bash bools I prefer just doing 'if [ "$verbose" = "yes" ]', allowing it
to be empty.

>          echo $cmdline
>      fi
>  
>      # extra_params in the config file may contain backticks that need to be
>      # expanded, so use eval to start qemu
> -    eval $cmdline >> test.log
> +    __eval_log "$cmdline"
> +    # The first bit of return value is too hard to use, just skip it.
> +    # Unit-tests' return value is shifted by one.
> +    ret=$(($? >> 1))

I just wrote a patch, inspired by reviewing your v1 of this series, that
tackles the ambiguous exit code problem. I'll post it now, but obviously
we'll need to rebase one or the other of our run_tests.sh series'.

>  
> -    if [ $? -le 1 ]; then
> +    if [ $ret -eq 0 ]; then
>          echo -e "\e[32mPASS\e[0m $1"
>      else
>          echo -e "\e[31mFAIL\e[0m $1"
>      fi
> +
> +    return $ret
>  }
> -- 
> 2.6.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Radim Krčmář Dec. 18, 2015, 10:49 a.m. UTC | #2
2015-12-17 12:53-0600, Andrew Jones:
> On Thu, Dec 17, 2015 at 06:53:33PM +0100, Radim Kr?má? wrote:
>> mkstandalone has a different mechanism for running tests as well as a
>> different handling of output and return codes.
>>  - create two shell function to capture test execution and logging
>>  - return the return value of unit-test
>>  - cope with empty $verbose in `run`
>> 
>> Signed-off-by: Radim Kr?má? <rkrcmar@redhat.com>
>> ---
>>  v2: new (reused the bitshift and comment from v1)
>>  
>> diff --git a/run_tests.sh b/run_tests.sh
>> -    cmdline="TESTNAME=$testname ACCEL=$accel ./$TEST_DIR-run $kernel -smp $smp $opts"
>> -    if [ $verbose != 0 ]; then
>> +    cmdline="TESTNAME=$testname ACCEL=$accel __run $kernel -smp $smp $opts"
>> +    if [ "$verbose" -a "$verbose" != 0 ]; then
> 
> For bash bools I prefer just doing 'if [ "$verbose" = "yes" ]', allowing it
> to be empty.

Yeah, I guess it's a bit better.
(I prefer just [ "$verbose" ].)

>>      # extra_params in the config file may contain backticks that need to be
>>      # expanded, so use eval to start qemu
>> -    eval $cmdline >> test.log
>> +    __eval_log "$cmdline"
>> +    # The first bit of return value is too hard to use, just skip it.
>> +    # Unit-tests' return value is shifted by one.
>> +    ret=$(($? >> 1))
> 
> I just wrote a patch, inspired by reviewing your v1 of this series, that
> tackles the ambiguous exit code problem. I'll post it now, but obviously
> we'll need to rebase one or the other of our run_tests.sh series'.

Nice, I'll review it later today (I'll travel for most of the afternoon).
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/run_tests.sh b/run_tests.sh
index 58949e39c38c..e09d410beaa4 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -28,7 +28,11 @@  specify the appropriate qemu binary for ARCH-run.
 EOF
 }
 
+__run() { ./$TEST_DIR-run "${@}"; }
+__eval_log() { eval "${@}" >> test.log; }
+
 echo > test.log
+
 while getopts "g:hv" opt; do
     case $opt in
         g)
diff --git a/scripts/run.bash b/scripts/run.bash
index 0c5a2569d80e..243586c6d2fc 100644
--- a/scripts/run.bash
+++ b/scripts/run.bash
@@ -34,18 +34,23 @@  function run()
         fi
     done
 
-    cmdline="TESTNAME=$testname ACCEL=$accel ./$TEST_DIR-run $kernel -smp $smp $opts"
-    if [ $verbose != 0 ]; then
+    cmdline="TESTNAME=$testname ACCEL=$accel __run $kernel -smp $smp $opts"
+    if [ "$verbose" -a "$verbose" != 0 ]; then
         echo $cmdline
     fi
 
     # extra_params in the config file may contain backticks that need to be
     # expanded, so use eval to start qemu
-    eval $cmdline >> test.log
+    __eval_log "$cmdline"
+    # The first bit of return value is too hard to use, just skip it.
+    # Unit-tests' return value is shifted by one.
+    ret=$(($? >> 1))
 
-    if [ $? -le 1 ]; then
+    if [ $ret -eq 0 ]; then
         echo -e "\e[32mPASS\e[0m $1"
     else
         echo -e "\e[31mFAIL\e[0m $1"
     fi
+
+    return $ret
 }