diff mbox series

[06/17] iotests: Drop format-specific in _filter_img_info

Message ID 20171123020832.8165-7-mreitz@redhat.com
State New
Headers show
Series iotests: Fix iotests for weird formats/options | expand

Commit Message

Max Reitz Nov. 23, 2017, 2:08 a.m. UTC
_filter_img_info should remove format-specific information, too.  We
already have such a filter in _img_info, and it is very useful for
query-block-named-block-nodes (etc.), too.

However, in 198 we need that information (but we still want the rest of
the filter), so make that filtering optional.  Note that "the rest of
the filter" includes filtering of the test directory, so we can drop the
_filter_testdir from 198 at the same time.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 tests/qemu-iotests/198           |  6 ++++--
 tests/qemu-iotests/common.filter | 29 ++++++++++++++++++++++++++++-
 2 files changed, 32 insertions(+), 3 deletions(-)

Comments

Fam Zheng Nov. 30, 2017, 3:16 a.m. UTC | #1
On Thu, 11/23 03:08, Max Reitz wrote:
> _filter_img_info should remove format-specific information, too.  We
> already have such a filter in _img_info, and it is very useful for
> query-block-named-block-nodes (etc.), too.
> 
> However, in 198 we need that information (but we still want the rest of
> the filter), so make that filtering optional.  Note that "the rest of
> the filter" includes filtering of the test directory, so we can drop the
> _filter_testdir from 198 at the same time.
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  tests/qemu-iotests/198           |  6 ++++--
>  tests/qemu-iotests/common.filter | 29 ++++++++++++++++++++++++++++-
>  2 files changed, 32 insertions(+), 3 deletions(-)
> 
> diff --git a/tests/qemu-iotests/198 b/tests/qemu-iotests/198
> index 34ef666381..a84a058396 100755
> --- a/tests/qemu-iotests/198
> +++ b/tests/qemu-iotests/198
> @@ -91,11 +91,13 @@ $QEMU_IO --object $SECRET0 --object $SECRET1 -c "read -P 0x9 0 $size" --image-op
>  
>  echo
>  echo "== checking image base =="
> -$QEMU_IMG info --image-opts $IMGSPECBASE | _filter_img_info | _filter_testdir | sed -e "/^disk size:/ D"
> +$QEMU_IMG info --image-opts $IMGSPECBASE | _filter_img_info --format-specific \
> +    | sed -e "/^disk size:/ D"
>  
>  echo
>  echo "== checking image layer =="
> -$QEMU_IMG info --image-opts $IMGSPECLAYER | _filter_img_info | _filter_testdir | sed -e "/^disk size:/ D"
> +$QEMU_IMG info --image-opts $IMGSPECLAYER | _filter_img_info --format-specific \
> +    | sed -e "/^disk size:/ D"
>  
>  
>  # success, all done
> diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter
> index d9237799e9..0c0e53fae7 100644
> --- a/tests/qemu-iotests/common.filter
> +++ b/tests/qemu-iotests/common.filter
> @@ -139,6 +139,15 @@ _filter_img_create()
>  
>  _filter_img_info()
>  {
> +    if [[ "$1" == "--format-specific" ]]; then
> +        local format_specific=1
> +        shift
> +    else
> +        local format_specific=0
> +    fi
> +
> +    discard=0
> +    regex_json_spec_start='^ *"format-specific": \{'
>      sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
>          -e "s#$TEST_DIR#TEST_DIR#g" \
>          -e "s#$IMGFMT#IMGFMT#g" \
> @@ -159,7 +168,25 @@ _filter_img_info()
>          -e "/block_state_zero: \\(on\\|off\\)/d" \
>          -e "/log_size: [0-9]\\+/d" \
>          -e "s/iters: [0-9]\\+/iters: 1024/" \
> -        -e "s/uuid: [-a-f0-9]\\+/uuid: 00000000-0000-0000-0000-000000000000/"
> +        -e "s/uuid: [-a-f0-9]\\+/uuid: 00000000-0000-0000-0000-000000000000/" | \
> +    while IFS='' read -r line; do
> +        if [[ $format_specific == 1 ]]; then
> +            discard=0
> +        elif [[ $line == "Format specific information:" ]]; then
> +            discard=1
> +        elif [[ $line =~ $regex_json_spec_start ]]; then
> +            discard=2
> +            regex_json_spec_end="^${line%%[^ ]*}\\},? *$"
> +        fi
> +        if [[ $discard == 0 ]]; then
> +            echo "$line"
> +        elif [[ $discard == 1 && ! $line ]]; then

s/\$line/"\$line"/ ?

> +            echo
> +            discard=0
> +        elif [[ $discard == 2 && $line =~ $regex_json_spec_end ]]; then

Ditto.

> +            discard=0
> +        fi
> +    done
>  }
>  
>  # filter out offsets and file names from qemu-img map; good for both
> -- 
> 2.13.6
>
Max Reitz Nov. 30, 2017, 1:22 p.m. UTC | #2
On 2017-11-30 04:16, Fam Zheng wrote:
> On Thu, 11/23 03:08, Max Reitz wrote:
>> _filter_img_info should remove format-specific information, too.  We
>> already have such a filter in _img_info, and it is very useful for
>> query-block-named-block-nodes (etc.), too.
>>
>> However, in 198 we need that information (but we still want the rest of
>> the filter), so make that filtering optional.  Note that "the rest of
>> the filter" includes filtering of the test directory, so we can drop the
>> _filter_testdir from 198 at the same time.
>>
>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>> ---
>>  tests/qemu-iotests/198           |  6 ++++--
>>  tests/qemu-iotests/common.filter | 29 ++++++++++++++++++++++++++++-
>>  2 files changed, 32 insertions(+), 3 deletions(-)
>>
>> diff --git a/tests/qemu-iotests/198 b/tests/qemu-iotests/198
>> index 34ef666381..a84a058396 100755
>> --- a/tests/qemu-iotests/198
>> +++ b/tests/qemu-iotests/198
>> @@ -91,11 +91,13 @@ $QEMU_IO --object $SECRET0 --object $SECRET1 -c "read -P 0x9 0 $size" --image-op
>>  
>>  echo
>>  echo "== checking image base =="
>> -$QEMU_IMG info --image-opts $IMGSPECBASE | _filter_img_info | _filter_testdir | sed -e "/^disk size:/ D"
>> +$QEMU_IMG info --image-opts $IMGSPECBASE | _filter_img_info --format-specific \
>> +    | sed -e "/^disk size:/ D"
>>  
>>  echo
>>  echo "== checking image layer =="
>> -$QEMU_IMG info --image-opts $IMGSPECLAYER | _filter_img_info | _filter_testdir | sed -e "/^disk size:/ D"
>> +$QEMU_IMG info --image-opts $IMGSPECLAYER | _filter_img_info --format-specific \
>> +    | sed -e "/^disk size:/ D"
>>  
>>  
>>  # success, all done
>> diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter
>> index d9237799e9..0c0e53fae7 100644
>> --- a/tests/qemu-iotests/common.filter
>> +++ b/tests/qemu-iotests/common.filter
>> @@ -139,6 +139,15 @@ _filter_img_create()
>>  
>>  _filter_img_info()
>>  {
>> +    if [[ "$1" == "--format-specific" ]]; then
>> +        local format_specific=1
>> +        shift
>> +    else
>> +        local format_specific=0
>> +    fi
>> +
>> +    discard=0
>> +    regex_json_spec_start='^ *"format-specific": \{'
>>      sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
>>          -e "s#$TEST_DIR#TEST_DIR#g" \
>>          -e "s#$IMGFMT#IMGFMT#g" \
>> @@ -159,7 +168,25 @@ _filter_img_info()
>>          -e "/block_state_zero: \\(on\\|off\\)/d" \
>>          -e "/log_size: [0-9]\\+/d" \
>>          -e "s/iters: [0-9]\\+/iters: 1024/" \
>> -        -e "s/uuid: [-a-f0-9]\\+/uuid: 00000000-0000-0000-0000-000000000000/"
>> +        -e "s/uuid: [-a-f0-9]\\+/uuid: 00000000-0000-0000-0000-000000000000/" | \
>> +    while IFS='' read -r line; do
>> +        if [[ $format_specific == 1 ]]; then
>> +            discard=0
>> +        elif [[ $line == "Format specific information:" ]]; then
>> +            discard=1
>> +        elif [[ $line =~ $regex_json_spec_start ]]; then
>> +            discard=2
>> +            regex_json_spec_end="^${line%%[^ ]*}\\},? *$"
>> +        fi
>> +        if [[ $discard == 0 ]]; then
>> +            echo "$line"
>> +        elif [[ $discard == 1 && ! $line ]]; then
> 
> s/\$line/"\$line"/ ?
> 
>> +            echo
>> +            discard=0
>> +        elif [[ $discard == 2 && $line =~ $regex_json_spec_end ]]; then
> 
> Ditto.

It's in double brackets, so it should be fine.

(I just copied it from _img_info in common.rc, and that was reviewed by
Eric, so I assume it's fine. :-))

Max

>> +            discard=0
>> +        fi
>> +    done
>>  }
>>  
>>  # filter out offsets and file names from qemu-img map; good for both
>> -- 
>> 2.13.6
>>
Eric Blake Nov. 30, 2017, 3:42 p.m. UTC | #3
On 11/29/2017 09:16 PM, Fam Zheng wrote:
> On Thu, 11/23 03:08, Max Reitz wrote:
>> _filter_img_info should remove format-specific information, too.  We
>> already have such a filter in _img_info, and it is very useful for
>> query-block-named-block-nodes (etc.), too.
>>
>> However, in 198 we need that information (but we still want the rest of
>> the filter), so make that filtering optional.  Note that "the rest of
>> the filter" includes filtering of the test directory, so we can drop the
>> _filter_testdir from 198 at the same time.
>>

>> +        if [[ $discard == 0 ]]; then
>> +            echo "$line"
>> +        elif [[ $discard == 1 && ! $line ]]; then
> 
> s/\$line/"\$line"/ ?
> 

Not necessary; [[ ]] is a bashism, which is part of the shell grammar so 
it doesn't need quoting.  In fact, there are some expressions in [[ ]] 
where comparing to "$foo" is actively different than comparing to $foo 
(mostly in regex, as the quotes change whether \ inside $foo are special 
to the regex or literally matched).

So this part is fine.
Eric Blake Nov. 30, 2017, 3:44 p.m. UTC | #4
On 11/22/2017 08:08 PM, Max Reitz wrote:
> _filter_img_info should remove format-specific information, too.  We
> already have such a filter in _img_info, and it is very useful for
> query-block-named-block-nodes (etc.), too.
> 
> However, in 198 we need that information (but we still want the rest of
> the filter), so make that filtering optional.  Note that "the rest of
> the filter" includes filtering of the test directory, so we can drop the
> _filter_testdir from 198 at the same time.
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>   tests/qemu-iotests/198           |  6 ++++--
>   tests/qemu-iotests/common.filter | 29 ++++++++++++++++++++++++++++-
>   2 files changed, 32 insertions(+), 3 deletions(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>
Fam Zheng Dec. 1, 2017, 1:33 a.m. UTC | #5
On Thu, 11/30 09:42, Eric Blake wrote:
> On 11/29/2017 09:16 PM, Fam Zheng wrote:
> > On Thu, 11/23 03:08, Max Reitz wrote:
> > > _filter_img_info should remove format-specific information, too.  We
> > > already have such a filter in _img_info, and it is very useful for
> > > query-block-named-block-nodes (etc.), too.
> > > 
> > > However, in 198 we need that information (but we still want the rest of
> > > the filter), so make that filtering optional.  Note that "the rest of
> > > the filter" includes filtering of the test directory, so we can drop the
> > > _filter_testdir from 198 at the same time.
> > > 
> 
> > > +        if [[ $discard == 0 ]]; then
> > > +            echo "$line"
> > > +        elif [[ $discard == 1 && ! $line ]]; then
> > 
> > s/\$line/"\$line"/ ?
> > 
> 
> Not necessary; [[ ]] is a bashism, which is part of the shell grammar so it
> doesn't need quoting.  In fact, there are some expressions in [[ ]] where
> comparing to "$foo" is actively different than comparing to $foo (mostly in
> regex, as the quotes change whether \ inside $foo are special to the regex
> or literally matched).
> 
> So this part is fine.

Interesting.. Thank you!

Reviewed-by: Fam Zheng <famz@redhat.com>
diff mbox series

Patch

diff --git a/tests/qemu-iotests/198 b/tests/qemu-iotests/198
index 34ef666381..a84a058396 100755
--- a/tests/qemu-iotests/198
+++ b/tests/qemu-iotests/198
@@ -91,11 +91,13 @@  $QEMU_IO --object $SECRET0 --object $SECRET1 -c "read -P 0x9 0 $size" --image-op
 
 echo
 echo "== checking image base =="
-$QEMU_IMG info --image-opts $IMGSPECBASE | _filter_img_info | _filter_testdir | sed -e "/^disk size:/ D"
+$QEMU_IMG info --image-opts $IMGSPECBASE | _filter_img_info --format-specific \
+    | sed -e "/^disk size:/ D"
 
 echo
 echo "== checking image layer =="
-$QEMU_IMG info --image-opts $IMGSPECLAYER | _filter_img_info | _filter_testdir | sed -e "/^disk size:/ D"
+$QEMU_IMG info --image-opts $IMGSPECLAYER | _filter_img_info --format-specific \
+    | sed -e "/^disk size:/ D"
 
 
 # success, all done
diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter
index d9237799e9..0c0e53fae7 100644
--- a/tests/qemu-iotests/common.filter
+++ b/tests/qemu-iotests/common.filter
@@ -139,6 +139,15 @@  _filter_img_create()
 
 _filter_img_info()
 {
+    if [[ "$1" == "--format-specific" ]]; then
+        local format_specific=1
+        shift
+    else
+        local format_specific=0
+    fi
+
+    discard=0
+    regex_json_spec_start='^ *"format-specific": \{'
     sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
         -e "s#$TEST_DIR#TEST_DIR#g" \
         -e "s#$IMGFMT#IMGFMT#g" \
@@ -159,7 +168,25 @@  _filter_img_info()
         -e "/block_state_zero: \\(on\\|off\\)/d" \
         -e "/log_size: [0-9]\\+/d" \
         -e "s/iters: [0-9]\\+/iters: 1024/" \
-        -e "s/uuid: [-a-f0-9]\\+/uuid: 00000000-0000-0000-0000-000000000000/"
+        -e "s/uuid: [-a-f0-9]\\+/uuid: 00000000-0000-0000-0000-000000000000/" | \
+    while IFS='' read -r line; do
+        if [[ $format_specific == 1 ]]; then
+            discard=0
+        elif [[ $line == "Format specific information:" ]]; then
+            discard=1
+        elif [[ $line =~ $regex_json_spec_start ]]; then
+            discard=2
+            regex_json_spec_end="^${line%%[^ ]*}\\},? *$"
+        fi
+        if [[ $discard == 0 ]]; then
+            echo "$line"
+        elif [[ $discard == 1 && ! $line ]]; then
+            echo
+            discard=0
+        elif [[ $discard == 2 && $line =~ $regex_json_spec_end ]]; then
+            discard=0
+        fi
+    done
 }
 
 # filter out offsets and file names from qemu-img map; good for both