]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
test/py: Add tests for the SquashFS commands
authorJoao Marcos Costa <joaomarcos.costa@bootlin.com>
Thu, 30 Jul 2020 13:33:52 +0000 (15:33 +0200)
committerTom Rini <trini@konsulko.com>
Sat, 8 Aug 2020 02:31:32 +0000 (22:31 -0400)
Add Python scripts to test 'ls' and 'load' commands. The scripts
generate a SquashFS image and clean the directory after the assertions,
or if an exception is raised.

Signed-off-by: Joao Marcos Costa <joaomarcos.costa@bootlin.com>
MAINTAINERS
configs/sandbox_defconfig
test/py/tests/test_fs/test_squashfs/sqfs_common.py [new file with mode: 0644]
test/py/tests/test_fs/test_squashfs/test_sqfs_load.py [new file with mode: 0644]
test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py [new file with mode: 0644]

index 8ec6c5db810862471cea0349730a6f7ea14db334..b12074ff3f80af51e0e5df56c426d8d671285890 100644 (file)
@@ -975,6 +975,7 @@ S:  Maintained
 F:     fs/squashfs/
 F:     include/sqfs.h
 F:     cmd/sqfs.c
+F:     test/py/tests/test_fs/test_squashfs/
 
 TARGET_BCMNS3
 M:     Bharat Gooty <bharat.gooty@broadcom.com>
index 65cfc85e518ab25bf3f0d430292dd57db556a045..8309ce6a8bff60f42ff3170752f2ddca332b46e2 100644 (file)
@@ -89,6 +89,7 @@ CONFIG_CMD_TPM=y
 CONFIG_CMD_TPM_TEST=y
 CONFIG_CMD_BTRFS=y
 CONFIG_CMD_CBFS=y
+CONFIG_CMD_SQUASHFS=y
 CONFIG_CMD_CRAMFS=y
 CONFIG_CMD_EXT4_WRITE=y
 CONFIG_CMD_MTDPARTS=y
diff --git a/test/py/tests/test_fs/test_squashfs/sqfs_common.py b/test/py/tests/test_fs/test_squashfs/sqfs_common.py
new file mode 100644 (file)
index 0000000..9ef7b19
--- /dev/null
@@ -0,0 +1,42 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2020 Bootlin
+# Author: Joao Marcos Costa <joaomarcos.costa@bootlin.com>
+
+import os
+import random
+import string
+
+def sqfs_get_random_letters(size):
+    letters = []
+    for i in range(0, size):
+            letters.append(random.choice(string.ascii_letters))
+
+    return ''.join(letters)
+
+def sqfs_generate_file(path, size):
+    content = sqfs_get_random_letters(size)
+    file = open(path, "w")
+    file.write(content)
+    file.close()
+
+# generate image with three files and a symbolic link
+def sqfs_generate_image():
+    src = "test/py/tests/test_fs/test_squashfs/sqfs_src/"
+    dest = "test/py/tests/test_fs/test_squashfs/sqfs"
+    os.mkdir(src)
+    sqfs_generate_file(src + "frag_only", 100)
+    sqfs_generate_file(src + "blks_frag", 5100)
+    sqfs_generate_file(src + "blks_only", 4096)
+    os.symlink("frag_only", src + "sym")
+    os.system("mksquashfs " + src + " " + dest + " -b 4096 -always-use-fragments")
+
+# removes all files created by sqfs_generate_image()
+def sqfs_clean():
+    src = "test/py/tests/test_fs/test_squashfs/sqfs_src/"
+    dest = "test/py/tests/test_fs/test_squashfs/sqfs"
+    os.remove(src + "frag_only")
+    os.remove(src + "blks_frag")
+    os.remove(src + "blks_only")
+    os.remove(src + "sym")
+    os.rmdir(src)
+    os.remove(dest)
diff --git a/test/py/tests/test_fs/test_squashfs/test_sqfs_load.py b/test/py/tests/test_fs/test_squashfs/test_sqfs_load.py
new file mode 100644 (file)
index 0000000..9b828fd
--- /dev/null
@@ -0,0 +1,33 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2020 Bootlin
+# Author: Joao Marcos Costa <joaomarcos.costa@bootlin.com>
+
+import os
+import pytest
+from sqfs_common import *
+
+@pytest.mark.boardspec('sandbox')
+@pytest.mark.buildconfigspec('cmd_fs_generic')
+@pytest.mark.buildconfigspec('cmd_squashfs')
+@pytest.mark.buildconfigspec('fs_squashfs')
+@pytest.mark.requiredtool('mksquashfs')
+def test_sqfs_load(u_boot_console):
+    sqfs_generate_image()
+    command = "sqfsload host 0 $kernel_addr_r "
+    path = "test/py/tests/test_fs/test_squashfs/sqfs"
+
+    try:
+        output = u_boot_console.run_command("host bind 0 " + path)
+        output = u_boot_console.run_command(command + "xxx")
+        assert "File not found." in output
+        output = u_boot_console.run_command(command + "frag_only")
+        assert "100 bytes read in" in output
+        output = u_boot_console.run_command(command + "blks_frag")
+        assert "5100 bytes read in" in output
+        output = u_boot_console.run_command(command + "blks_only")
+        assert "4096 bytes read in" in output
+        output = u_boot_console.run_command(command + "sym")
+        assert "100 bytes read in" in output
+    except:
+        sqfs_clean()
+    sqfs_clean()
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
new file mode 100644 (file)
index 0000000..dc31f1a
--- /dev/null
@@ -0,0 +1,26 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2020 Bootlin
+# Author: Joao Marcos Costa <joaomarcos.costa@bootlin.com>
+
+import os
+import pytest
+from sqfs_common import *
+
+@pytest.mark.boardspec('sandbox')
+@pytest.mark.buildconfigspec('cmd_fs_generic')
+@pytest.mark.buildconfigspec('cmd_squashfs')
+@pytest.mark.buildconfigspec('fs_squashfs')
+@pytest.mark.requiredtool('mksquashfs')
+def test_sqfs_ls(u_boot_console):
+    sqfs_generate_image()
+    path = "test/py/tests/test_fs/test_squashfs/sqfs"
+    try:
+        output = u_boot_console.run_command("host bind 0 " + path)
+        output = u_boot_console.run_command("sqfsls host 0")
+        assert "4 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
+    except:
+        sqfs_clean()
+    sqfs_clean()