diff mbox series

[4/9] tests/acceptance: Extract image_expand() helper

Message ID 20210623180021.898286-5-f4bug@amsat.org (mailing list archive)
State New, archived
Headers show
Series hw/sd: Allow card size not power of 2 again | expand

Commit Message

Philippe Mathieu-Daudé June 23, 2021, 6 p.m. UTC
To be able to expand an image to a non-power-of-2 value,
extract image_expand() from image_pow2ceil_expand().

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 tests/acceptance/boot_linux_console.py | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

Comments

Willian Rampazzo July 5, 2021, 3:27 p.m. UTC | #1
On Wed, Jun 23, 2021 at 3:06 PM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
>
> To be able to expand an image to a non-power-of-2 value,
> extract image_expand() from image_pow2ceil_expand().
>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>  tests/acceptance/boot_linux_console.py | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
>

Reviewed-by: Willian Rampazzo <willianr@redhat.com>
Cleber Rosa July 13, 2021, 5:02 p.m. UTC | #2
Philippe Mathieu-Daudé writes:

> To be able to expand an image to a non-power-of-2 value,
> extract image_expand() from image_pow2ceil_expand().
>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>  tests/acceptance/boot_linux_console.py | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
> index 20d57c1a8c6..61069f0064f 100644
> --- a/tests/acceptance/boot_linux_console.py
> +++ b/tests/acceptance/boot_linux_console.py
> @@ -35,15 +35,19 @@
>  def pow2ceil(x):
>      return 1 if x == 0 else 2**(x - 1).bit_length()
>  
> +"""
> +Expand file size
> +"""
> +def image_expand(path, size):
> +    if size != os.path.getsize(path):
> +        with open(path, 'ab+') as fd:
> +            fd.truncate(size)
> +

This would be a good time to make the comment section, into a proper
docstring, that is:

def image_expand(path, size):
   """Expand file size"""
    if size != os.path.getsize(path):
        with open(path, 'ab+') as fd:
            fd.truncate(size)

- Cleber.
diff mbox series

Patch

diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
index 20d57c1a8c6..61069f0064f 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -35,15 +35,19 @@ 
 def pow2ceil(x):
     return 1 if x == 0 else 2**(x - 1).bit_length()
 
+"""
+Expand file size
+"""
+def image_expand(path, size):
+    if size != os.path.getsize(path):
+        with open(path, 'ab+') as fd:
+            fd.truncate(size)
+
 """
 Expand file size to next power of 2
 """
 def image_pow2ceil_expand(path):
-        size = os.path.getsize(path)
-        size_aligned = pow2ceil(size)
-        if size != size_aligned:
-            with open(path, 'ab+') as fd:
-                fd.truncate(size_aligned)
+    image_expand(path, pow2ceil(os.path.getsize(path)))
 
 class LinuxKernelTest(Test):
     KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '