All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joao Marcos Costa <jmcosta944@gmail.com>
To: u-boot@lists.denx.de
Cc: thomas.petazzoni@bootlin.com, miquel.raynal@bootlin.com,
	richard.genoud@posteo.net, sjg@chromium.org,
	Joao Marcos Costa <jmcosta944@gmail.com>
Subject: [PATCH 3/3] test/py: rewrite sqfsls command test suite
Date: Sun, 23 May 2021 23:31:33 -0300	[thread overview]
Message-ID: <20210524023133.22100-4-jmcosta944@gmail.com> (raw)
In-Reply-To: <20210524023133.22100-1-jmcosta944@gmail.com>

Add more details to test cases by comparing each expected line with the
command's output. Add new test cases:
- sqfsls at an empty directory
- sqfsls at a sub-directory

Signed-off-by: Joao Marcos Costa <jmcosta944@gmail.com>
---
 .../test_fs/test_squashfs/test_sqfs_ls.py     | 80 ++++++++++++++-----
 1 file changed, 62 insertions(+), 18 deletions(-)

diff --git a/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py b/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py
index a0dca2e2fc..2895aefc3b 100644
--- a/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py
+++ b/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py
@@ -6,6 +6,52 @@ import os
 import pytest
 from sqfs_common import *
 
+def sqfs_ls_at_root(u_boot_console):
+    # first and most basic test is to check if these two give the same output
+    no_slash = u_boot_console.run_command('sqfsls host 0')
+    slash = u_boot_console.run_command('sqfsls host 0 /')
+    assert no_slash == slash
+
+    expected_lines = ['empty-dir/', '1000   f1000', '4096   f4096', '5096   f5096',
+            'subdir/', '<SYM>   sym', '4 file(s), 2 dir(s)']
+
+    output = u_boot_console.run_command('sqfsls host 0')
+    for line in expected_lines:
+        assert line in output
+
+def sqfs_ls_at_empty_dir(u_boot_console):
+    assert u_boot_console.run_command('sqfsls host 0 empty-dir') == 'Empty directory.'
+
+def sqfs_ls_at_subdir(u_boot_console):
+    expected_lines = ['100   subdir-file', '1 file(s), 0 dir(s)']
+    output = u_boot_console.run_command('sqfsls host 0 subdir')
+    for line in expected_lines:
+        assert line in output
+
+def sqfs_ls_at_symlink(u_boot_console):
+    # since sym -> subdir, the following outputs must be equal
+    output = u_boot_console.run_command('sqfsls host 0 sym')
+    output_subdir= u_boot_console.run_command('sqfsls host 0 subdir')
+    assert output == output_subdir
+
+    expected_lines = ['100   subdir-file', '1 file(s), 0 dir(s)']
+    for line in expected_lines:
+        assert line in output
+
+# output should be the same for non-existent directories and files
+def sqfs_ls_at_non_existent_dir(u_boot_console):
+    out_non_existent = u_boot_console.run_command('sqfsls host 0 fff')
+    out_not_dir = u_boot_console.run_command('sqfsls host 0 f1000')
+    assert out_non_existent == out_not_dir
+    assert '** Cannot find directory. **' in out_non_existent
+
+def sqfs_run_all_ls_tests(u_boot_console):
+    sqfs_ls_at_root(u_boot_console)
+    sqfs_ls_at_empty_dir(u_boot_console)
+    sqfs_ls_at_subdir(u_boot_console)
+    sqfs_ls_at_symlink(u_boot_console)
+    sqfs_ls_at_non_existent_dir(u_boot_console)
+
 @pytest.mark.boardspec('sandbox')
 @pytest.mark.buildconfigspec('cmd_fs_generic')
 @pytest.mark.buildconfigspec('cmd_squashfs')
@@ -13,24 +59,22 @@ from sqfs_common import *
 @pytest.mark.requiredtool('mksquashfs')
 def test_sqfs_ls(u_boot_console):
     build_dir = u_boot_console.config.build_dir
-    for opt in comp_opts:
-        try:
-            opt.gen_image(build_dir)
-        except RuntimeError:
-            opt.clean_source(build_dir)
-            # skip unsupported compression types
-            continue
-        path = os.path.join(build_dir, "sqfs-" + opt.name)
-        output = u_boot_console.run_command("host bind 0 " + path)
 
+    # setup test environment
+    generate_sqfs_src_dir(build_dir)
+    make_all_images(build_dir)
+
+    # run all tests for each image
+    for image in standard_table.keys():
         try:
-            # list files in root directory
-            output = u_boot_console.run_command("sqfsls host 0")
-            assert str(len(opt.files) + 1) + " file(s), 0 dir(s)" in output
-            assert "<SYM>   sym" in output
-            output = u_boot_console.run_command("sqfsls host 0 xxx")
-            assert "** Cannot find directory. **" in output
+            image_path = os.path.join(build_dir, image)
+            u_boot_console.run_command('host bind 0 {}'.format(image_path))
+            sqfs_run_all_ls_tests(u_boot_console)
         except:
-            opt.cleanup(build_dir)
-            assert False
-        opt.cleanup(build_dir)
+            clean_all_images(build_dir)
+            clean_sqfs_src_dir(build_dir)
+            raise AssertionError
+
+    # clean test environment
+    clean_all_images(build_dir)
+    clean_sqfs_src_dir(build_dir)
-- 
2.25.1


  parent reply	other threads:[~2021-05-24  2:32 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
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 ` Joao Marcos Costa [this message]
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=20210524023133.22100-4-jmcosta944@gmail.com \
    --to=jmcosta944@gmail.com \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard.genoud@posteo.net \
    --cc=sjg@chromium.org \
    --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.