[kvm-unit-tests] scripts: Fix the check whether testname is in the only_tests list
diff mbox series

Message ID 20200701083753.31366-1-thuth@redhat.com
State New
Headers show
Series
  • [kvm-unit-tests] scripts: Fix the check whether testname is in the only_tests list
Related show

Commit Message

Thomas Huth July 1, 2020, 8:37 a.m. UTC
When you currently run

 ./run_tests.sh ioapic-split

the kvm-unit-tests run scripts do not only execute the "ioapic-split"
test, but also the "ioapic" test, which is quite surprising. This
happens because we use "grep -w" for checking whether a test should
be run or not - and "grep -w" does not consider the "-" character as
part of a word.

To fix the issue, convert the dash into an underscore character before
running "grep -w".

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 scripts/runtime.bash | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Paolo Bonzini July 1, 2020, 8:51 a.m. UTC | #1
On 01/07/20 10:37, Thomas Huth wrote:
> When you currently run
> 
>  ./run_tests.sh ioapic-split
> 
> the kvm-unit-tests run scripts do not only execute the "ioapic-split"
> test, but also the "ioapic" test, which is quite surprising. This
> happens because we use "grep -w" for checking whether a test should
> be run or not - and "grep -w" does not consider the "-" character as
> part of a word.
> 
> To fix the issue, convert the dash into an underscore character before
> running "grep -w".
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>  scripts/runtime.bash | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/scripts/runtime.bash b/scripts/runtime.bash
> index 8bfe31c..03fd20a 100644
> --- a/scripts/runtime.bash
> +++ b/scripts/runtime.bash
> @@ -84,7 +84,8 @@ function run()
>          return
>      fi
>  
> -    if [ -n "$only_tests" ] && ! grep -qw "$testname" <<<$only_tests; then
> +    if [ -n "$only_tests" ] && ! sed s/-/_/ <<<$only_tests \
> +                               | grep -qw $(sed s/-/_/ <<< "$testname") ; then
>          return
>      fi
>  
> 

Simpler: grep -q " $testname " <<< " $only_tests "

Also, please do the same for groups in the two "if" statements right below.

Paolo
Thomas Huth July 1, 2020, 8:57 a.m. UTC | #2
On 01/07/2020 10.51, Paolo Bonzini wrote:
> On 01/07/20 10:37, Thomas Huth wrote:
>> When you currently run
>>
>>   ./run_tests.sh ioapic-split
>>
>> the kvm-unit-tests run scripts do not only execute the "ioapic-split"
>> test, but also the "ioapic" test, which is quite surprising. This
>> happens because we use "grep -w" for checking whether a test should
>> be run or not - and "grep -w" does not consider the "-" character as
>> part of a word.
>>
>> To fix the issue, convert the dash into an underscore character before
>> running "grep -w".
>>
>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>> ---
>>   scripts/runtime.bash | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/scripts/runtime.bash b/scripts/runtime.bash
>> index 8bfe31c..03fd20a 100644
>> --- a/scripts/runtime.bash
>> +++ b/scripts/runtime.bash
>> @@ -84,7 +84,8 @@ function run()
>>           return
>>       fi
>>   
>> -    if [ -n "$only_tests" ] && ! grep -qw "$testname" <<<$only_tests; then
>> +    if [ -n "$only_tests" ] && ! sed s/-/_/ <<<$only_tests \
>> +                               | grep -qw $(sed s/-/_/ <<< "$testname") ; then
>>           return
>>       fi
>>   
>>
> 
> Simpler: grep -q " $testname " <<< " $only_tests "

That doesn't work:

$ ./run_tests.sh ioapic-split
PASS apic-split (53 tests)
PASS ioapic-split (19 tests)
PASS apic (53 tests)
PASS ioapic (26 tests)

... because the $testname comes from unittests.cfg and $only_tests is 
the list that has been given on the command line. It would maybe work if 
the check was the other way round ... but that would require to rewrite 
quite a bit of the script logic...

By the way, you can currently also run "./run_test.sh badname" and it 
does *not* complain that "badname" is an illegal test name...

  Thomas
Paolo Bonzini July 1, 2020, 9:43 a.m. UTC | #3
On 01/07/20 10:57, Thomas Huth wrote:
>>>
>>
>> Simpler: grep -q " $testname " <<< " $only_tests "
> 
> That doesn't work:
> 
> $ ./run_tests.sh ioapic-split
> PASS apic-split (53 tests)
> PASS ioapic-split (19 tests)
> PASS apic (53 tests)
> PASS ioapic (26 tests)
> 
> ... because the $testname comes from unittests.cfg and $only_tests is
> the list that has been given on the command line. It would maybe work if
> the check was the other way round ... but that would require to rewrite
> quite a bit of the script logic...

It works here.  I'll send a patch.

Paolo

> By the way, you can currently also run "./run_test.sh badname" and it
> does *not* complain that "badname" is an illegal test name...
Thomas Huth July 1, 2020, 9:55 a.m. UTC | #4
On 01/07/2020 10.57, Thomas Huth wrote:
> On 01/07/2020 10.51, Paolo Bonzini wrote:
>> On 01/07/20 10:37, Thomas Huth wrote:
>>> When you currently run
>>>
>>>   ./run_tests.sh ioapic-split
>>>
>>> the kvm-unit-tests run scripts do not only execute the "ioapic-split"
>>> test, but also the "ioapic" test, which is quite surprising. This
>>> happens because we use "grep -w" for checking whether a test should
>>> be run or not - and "grep -w" does not consider the "-" character as
>>> part of a word.
>>>
>>> To fix the issue, convert the dash into an underscore character before
>>> running "grep -w".
>>>
>>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>>> ---
>>>   scripts/runtime.bash | 3 ++-
>>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/scripts/runtime.bash b/scripts/runtime.bash
>>> index 8bfe31c..03fd20a 100644
>>> --- a/scripts/runtime.bash
>>> +++ b/scripts/runtime.bash
>>> @@ -84,7 +84,8 @@ function run()
>>>           return
>>>       fi
>>> -    if [ -n "$only_tests" ] && ! grep -qw "$testname" 
>>> <<<$only_tests; then
>>> +    if [ -n "$only_tests" ] && ! sed s/-/_/ <<<$only_tests \
>>> +                               | grep -qw $(sed s/-/_/ <<< 
>>> "$testname") ; then
>>>           return
>>>       fi
>>>
>>
>> Simpler: grep -q " $testname " <<< " $only_tests "
> 
> That doesn't work:

I obviously missed the surrounding spaces ... not enough coffee... ;-)

  Thomas

Patch
diff mbox series

diff --git a/scripts/runtime.bash b/scripts/runtime.bash
index 8bfe31c..03fd20a 100644
--- a/scripts/runtime.bash
+++ b/scripts/runtime.bash
@@ -84,7 +84,8 @@  function run()
         return
     fi
 
-    if [ -n "$only_tests" ] && ! grep -qw "$testname" <<<$only_tests; then
+    if [ -n "$only_tests" ] && ! sed s/-/_/ <<<$only_tests \
+                               | grep -qw $(sed s/-/_/ <<< "$testname") ; then
         return
     fi