All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: Joao Marcos Costa <jmcosta944@gmail.com>
Cc: U-Boot Mailing List <u-boot@lists.denx.de>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	 Miquel Raynal <miquel.raynal@bootlin.com>,
	Richard Genoud <richard.genoud@posteo.net>
Subject: Re: [PATCH 1/3] test/py: rewrite common tools for SquashFS tests
Date: Thu, 27 May 2021 07:44:06 -0600	[thread overview]
Message-ID: <CAPnjgZ0EUDKrsnxNLVe8nCdwZS2P6v77VqV=hdTjc-p+rtSs4Q@mail.gmail.com> (raw)
In-Reply-To: <20210524023133.22100-2-jmcosta944@gmail.com>

Hi Joao,

On Sun, 23 May 2021 at 20:31, Joao Marcos Costa <jmcosta944@gmail.com> wrote:
>
> Remove the previous OOP approach, which was confusing and incomplete.
> Add more test cases by making SquashFS images with various options,
> concerning file fragmentation and its compression. Add comments to
> properly document the code.
>
> Signed-off-by: Joao Marcos Costa <jmcosta944@gmail.com>
> ---
>  .../test_fs/test_squashfs/sqfs_common.py      | 198 ++++++++++++------
>  1 file changed, 133 insertions(+), 65 deletions(-)
>
> diff --git a/test/py/tests/test_fs/test_squashfs/sqfs_common.py b/test/py/tests/test_fs/test_squashfs/sqfs_common.py
> index c96f92c1d8..81a378a9f9 100644
> --- a/test/py/tests/test_fs/test_squashfs/sqfs_common.py
> +++ b/test/py/tests/test_fs/test_squashfs/sqfs_common.py
> @@ -1,76 +1,144 @@
>  # SPDX-License-Identifier: GPL-2.0
> -# Copyright (C) 2020 Bootlin
> +# Copyright (C) 2021 Bootlin
>  # Author: Joao Marcos Costa <joaomarcos.costa@bootlin.com>
>
>  import os
> -import random
> -import string
> +import shutil
>  import subprocess
>
> -def sqfs_get_random_letters(size):
> -    letters = []
> -    for i in range(0, size):
> -            letters.append(random.choice(string.ascii_letters))
> +"""
> +standard test images table: Each table item is a key:value pair representing the
> +output image name and its respective mksquashfs options. This table should be
> +modified only when adding support for new compression algorithms.
> +The 'default' case takes no options but the input and output names, so it must
> +be assigned with an empty string.
> +"""
> +standard_table = {
> +        'default' : '',
> +        'lzo_comp_frag' : '',
> +        'lzo_frag' : '',
> +        'lzo_no_frag' : '',
> +        'zstd_comp_frag' : '',
> +        'zstd_frag' : '',
> +        'zstd_no_frag' : '',
> +        'gzip_comp_frag' : '',
> +        'gzip_frag' : '',
> +        'gzip_no_frag' : ''
> +}
>
> -    return ''.join(letters)
> +"""
> +extra_table: Set this table's keys and values if you want to make squashfs images with
> +your own customized options.
> +"""
> +extra_table = {}
>
> -def sqfs_generate_file(path, size):
> -    content = sqfs_get_random_letters(size)
> -    file = open(path, "w")
> +# path to source directory used to make squashfs test images
> +sqfs_src_dir = 'sqfs_src_dir'
> +
> +"""
> +Combines fragmentation and compression options into a list of strings.
> +opts_list's firts item is an empty string as standard_table's first item is
> +the 'default' case.
> +"""
> +def get_opts_list():

While we are here, can you please be a little more formal with your
function comments? pylint3 will tell you about it if you run it on
this file.

Basically you do something like this (omitting Args or Returns if
there isn't anything):

def get_opts_list():
    """Combine fragmentation and compression options into a list of strings

   The first returned item is an empty string as standard_table's first item is
   the 'default' case.

   Args:
      fred: Description

   Returns:
      what it returns
   """

> +    # supported compression options only
> +    comp_opts = ['-comp lzo', '-comp zstd', '-comp gzip']
> +    # file fragmentation options
> +    frag_opts = ['-always-use-fragments', '-always-use-fragments -noF', '-no-fragments']
> +
> +    opts_list = [' ']
> +    for c in comp_opts:
> +        for f in frag_opts:
> +            opts_list.append(' '.join([c, f]))
> +
> +    return opts_list
> +
> +def init_standard_table():
> +    opts_list = get_opts_list()
> +
> +    for key, value in zip(standard_table.keys(), opts_list):
> +            standard_table[key] = value
> +
> +def generate_file(file_name, file_size):
> +    # file is filled with file_size * 'x'
> +    content = ''
> +    for i in range(file_size):
> +        content += 'x'

content = 'x' * file_size

> +
> +    file = open(file_name, 'w')
>      file.write(content)
>      file.close()
>
[..]

[..]

> +"""
> +sqfs_src_dir
> +├── empty-dir
> +├── f1000
> +├── f4096
> +├── f5096
> +├── subdir
> +│   └── subdir-file
> +└── sym -> subdir
> +
> +3 directories, 4 files
> +"""

That should be a comment for this function.

> +def generate_sqfs_src_dir(build_dir):

   """What this function does

   put above info here
   """

> +    path = os.path.join(build_dir, sqfs_src_dir)

Call it root ?

> +    print(path)
> +    #path = build_dir + '/' + sqfs_src_dir

Can we drop those two lines?

> +    # make root directory
> +    os.makedirs(path)
> +
> +    # 4096: minimum block size
> +    file_name = 'f4096'
> +    generate_file(os.path.join(path, file_name), 4096)
> +
> +    # 5096: minimum block size + 1000 chars (fragment)
> +    file_name = 'f5096'
> +    generate_file(os.path.join(path, file_name), 5096)
> +
> +    # 1000: less than minimum block size (fragment only)
> +    file_name = 'f1000'
> +    generate_file(os.path.join(path, file_name), 1000)
> +
> +    # sub-directory with a single file inside
> +    subdir_path = os.path.join(path, 'subdir')
> +    os.makedirs(subdir_path)
> +    generate_file(os.path.join(subdir_path, 'subdir-file'), 100)
> +
> +    # symlink (target: sub-directory)
> +    os.symlink('subdir', os.path.join(path, 'sym'))
> +
> +    # empty directory
> +    os.makedirs(os.path.join(path, 'empty-dir'))
> +
> +def mksquashfs(args):
> +    subprocess.run(['mksquashfs ' + args], shell = True, check = True,
> +            stdout = subprocess.DEVNULL)
> +
> +def make_all_images(build_dir):
> +
> +    init_standard_table()
> +    input_path = os.path.join(build_dir, sqfs_src_dir)
> +
> +    # make squashfs images according to standard_table
> +    for out, opts in zip(standard_table.keys(), standard_table.values()):
> +        output_path = os.path.join(build_dir, out)
> +        mksquashfs(' '.join([input_path, output_path, opts]))
> +
> +    # make squashfs images according to extra_table
> +    for out, opts in zip(extra_table.keys(), extra_table.values()):
> +        output_path = os.path.join(build_dir, out)
> +        mksquashfs(' '.join([input_path, output_path, opts]))
> +
> +def clean_all_images(build_dir):
> +    for image_name in standard_table.keys():
> +        image_path = os.path.join(build_dir, image_name)
> +        os.remove(image_path)
> +
> +    for image_name in extra_table.keys():
> +        image_path = os.path.join(build_dir, image_name)
> +        os.remove(image_path)
> +
> +def clean_sqfs_src_dir(build_dir):
> +    path = os.path.join(build_dir, sqfs_src_dir)
> +    shutil.rmtree(path)
> --
> 2.25.1
>

Regards,
Simon

  parent reply	other threads:[~2021-05-27 13:44 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-24  2:31 [PATCH 0/3] test/py: Rewrite SquashFS commands test suite Joao Marcos Costa
2021-05-24  2:31 ` [PATCH 1/3] test/py: rewrite common tools for SquashFS tests Joao Marcos Costa
2021-05-25 16:58   ` Tom Rini
2021-05-27 13:44   ` Simon Glass [this message]
2021-05-29 18:14     ` João Marcos Costa
2021-05-24  2:31 ` [PATCH 2/3] test/py: rewrite sqfsload command test suite Joao Marcos Costa
2021-05-24  2:31 ` [PATCH 3/3] test/py: rewrite sqfsls " Joao Marcos Costa
2021-05-26 13:37 ` [PATCH 0/3] test/py: Rewrite SquashFS commands " Richard Genoud

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPnjgZ0EUDKrsnxNLVe8nCdwZS2P6v77VqV=hdTjc-p+rtSs4Q@mail.gmail.com' \
    --to=sjg@chromium.org \
    --cc=jmcosta944@gmail.com \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard.genoud@posteo.net \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.