diff mbox series

[05/18] iotests: Add -o and --no-opts to _make_test_img

Message ID 20190927094242.11152-6-mreitz@redhat.com (mailing list archive)
State New, archived
Headers show
Series iotests: Allow ./check -o data_file | expand

Commit Message

Max Reitz Sept. 27, 2019, 9:42 a.m. UTC
Blindly overriding IMGOPTS is suboptimal as this discards user-specified
options.  Whatever options the test needs should simply be appended.

Some tests do this (with IMGOPTS=$(_optstr_add "$IMGOPTS" "...")), but
that is cumbersome.  It’s simpler to just give _make_test_img an -o
parameter with which tests can add options.

Some tests actually must override the user-specified options, though,
for example when creating an image in a different format than the test
$IMGFMT.  For such cases, --no-opts allows clearing the current option
list.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 tests/qemu-iotests/common.rc | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Maxim Levitsky Sept. 29, 2019, 4:32 p.m. UTC | #1
On Fri, 2019-09-27 at 11:42 +0200, Max Reitz wrote:
> Blindly overriding IMGOPTS is suboptimal as this discards user-specified
> options.  Whatever options the test needs should simply be appended.
> 
> Some tests do this (with IMGOPTS=$(_optstr_add "$IMGOPTS" "...")), but
> that is cumbersome.  It’s simpler to just give _make_test_img an -o
> parameter with which tests can add options.
> 
> Some tests actually must override the user-specified options, though,
> for example when creating an image in a different format than the test
> $IMGFMT.  For such cases, --no-opts allows clearing the current option
> list.
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  tests/qemu-iotests/common.rc | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
> index 3e7adc4834..f3784077de 100644
> --- a/tests/qemu-iotests/common.rc
> +++ b/tests/qemu-iotests/common.rc
> @@ -287,6 +287,7 @@ _make_test_img()
>      local use_backing=0
>      local backing_file=""
>      local object_options=""
> +    local opts_param=false
>      local misc_params=()
>  
>      if [ -n "$TEST_IMG_FILE" ]; then
> @@ -307,6 +308,10 @@ _make_test_img()
>          if [ "$use_backing" = "1" -a -z "$backing_file" ]; then
>              backing_file=$param
>              continue
> +        elif $opts_param; then
> +            optstr=$(_optstr_add "$optstr" "$param")
> +            opts_param=false
> +            continue
>          fi
>  
>          case "$param" in
> @@ -314,6 +319,14 @@ _make_test_img()
>                  use_backing=1
>                  ;;
>  
> +            -o)
> +                opts_param=true
> +                ;;
> +
> +            --no-opts)
> +                optstr=""
> +                ;;
> +
>              *)
>                  misc_params=("${misc_params[@]}" "$param")
>                  ;;


Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>

Best regards,
	Maxim Levitsky
diff mbox series

Patch

diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
index 3e7adc4834..f3784077de 100644
--- a/tests/qemu-iotests/common.rc
+++ b/tests/qemu-iotests/common.rc
@@ -287,6 +287,7 @@  _make_test_img()
     local use_backing=0
     local backing_file=""
     local object_options=""
+    local opts_param=false
     local misc_params=()
 
     if [ -n "$TEST_IMG_FILE" ]; then
@@ -307,6 +308,10 @@  _make_test_img()
         if [ "$use_backing" = "1" -a -z "$backing_file" ]; then
             backing_file=$param
             continue
+        elif $opts_param; then
+            optstr=$(_optstr_add "$optstr" "$param")
+            opts_param=false
+            continue
         fi
 
         case "$param" in
@@ -314,6 +319,14 @@  _make_test_img()
                 use_backing=1
                 ;;
 
+            -o)
+                opts_param=true
+                ;;
+
+            --no-opts)
+                optstr=""
+                ;;
+
             *)
                 misc_params=("${misc_params[@]}" "$param")
                 ;;