On Mon, Jul 13, 2020 at 08:32:04PM +0200, Philippe Mathieu-Daudé wrote: > In few commits we won't allow SD card images with invalid size > (not aligned to a power of 2). Prepare the tests: add the > pow2ceil() and image_pow2ceil_expand() methods and resize the > images (expanding) of the tests using SD cards. > > Signed-off-by: Philippe Mathieu-Daudé <f4...@amsat.org> > --- > Since v1: Addressed review comments > - truncate -> expand reword (Alistair Francis) > - expand after uncompress (Niek Linnenbank) > --- > tests/acceptance/boot_linux_console.py | 27 +++++++++++++++++--------- > 1 file changed, 18 insertions(+), 9 deletions(-) > > diff --git a/tests/acceptance/boot_linux_console.py > b/tests/acceptance/boot_linux_console.py > index b7e8858c2d..8f2a6aa8a4 100644 > --- a/tests/acceptance/boot_linux_console.py > +++ b/tests/acceptance/boot_linux_console.py > @@ -28,6 +28,18 @@ > except CmdNotFoundError: > P7ZIP_AVAILABLE = False > > +# round up to next power of 2 > +def pow2ceil(x): > + return 1 if x == 0 else 2**(x - 1).bit_length() > +
Nitpick: turn the comment into a docstring. Then, I was going to have a second nitpick about the method name, but realized it was following qemu-common.h's implementation. > +# 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) > + Same nitpick comment about comment -> docstring here. Either way, Reviewed-by: Cleber Rosa <cr...@redhat.com>
signature.asc
Description: PGP signature