From patchwork Thu Jul 30 13:33:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Marcos Costa X-Patchwork-Id: 1338831 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bootlin.com Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BHWcY0MtQz9s1x for ; Thu, 30 Jul 2020 23:35:08 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CFD17826D2; Thu, 30 Jul 2020 15:34:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=bootlin.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 07269826B6; Thu, 30 Jul 2020 15:34:07 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E655582677 for ; Thu, 30 Jul 2020 15:33:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=bootlin.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=joaomarcos.costa@bootlin.com X-Originating-IP: 46.193.64.106 Received: from localhost.localdomain (eth-east-parth2-46-193-64-106.wb.wifirst.net [46.193.64.106]) (Authenticated sender: joaomarcos.costa@bootlin.com) by relay7-d.mail.gandi.net (Postfix) with ESMTPA id EC42B20002; Thu, 30 Jul 2020 13:33:55 +0000 (UTC) From: Joao Marcos Costa To: u-boot@lists.denx.de Cc: joaomarcos.costa@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com Subject: [PATCH v4 6/6] test/py: Add tests for the SquashFS commands Date: Thu, 30 Jul 2020 15:33:52 +0200 Message-Id: <20200730133352.18223-7-joaomarcos.costa@bootlin.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200730133352.18223-1-joaomarcos.costa@bootlin.com> References: <20200730133352.18223-1-joaomarcos.costa@bootlin.com> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean 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 --- Changes in v4: - This patch was added in v4 and did not exist in the last version. MAINTAINERS | 1 + configs/sandbox_defconfig | 1 + .../test_fs/test_squashfs/sqfs_common.py | 42 +++++++++++++++++++ .../test_fs/test_squashfs/test_sqfs_load.py | 33 +++++++++++++++ .../test_fs/test_squashfs/test_sqfs_ls.py | 26 ++++++++++++ 5 files changed, 103 insertions(+) create mode 100644 test/py/tests/test_fs/test_squashfs/sqfs_common.py create mode 100644 test/py/tests/test_fs/test_squashfs/test_sqfs_load.py create mode 100644 test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py diff --git a/MAINTAINERS b/MAINTAINERS index 8ec6c5db81..b12074ff3f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -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 diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 829056e9ce..4dd5f87c68 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -84,6 +84,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 index 0000000000..9ef7b19ad9 --- /dev/null +++ b/test/py/tests/test_fs/test_squashfs/sqfs_common.py @@ -0,0 +1,42 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2020 Bootlin +# Author: Joao Marcos Costa + +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 index 0000000000..9b828fdf04 --- /dev/null +++ b/test/py/tests/test_fs/test_squashfs/test_sqfs_load.py @@ -0,0 +1,33 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2020 Bootlin +# Author: Joao Marcos Costa + +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 index 0000000000..dc31f1a50e --- /dev/null +++ b/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py @@ -0,0 +1,26 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2020 Bootlin +# Author: Joao Marcos Costa + +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" in output + output = u_boot_console.run_command("sqfsls host 0 xxx") + assert "** Cannot find directory. **" in output + except: + sqfs_clean() + sqfs_clean()