From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06779C11F66 for ; Wed, 30 Jun 2021 22:45:38 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 596176140A for ; Wed, 30 Jun 2021 22:45:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 596176140A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A823D831AF; Thu, 1 Jul 2021 00:45:27 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Zvpguau2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 60AFE831AF; Thu, 1 Jul 2021 00:45:26 +0200 (CEST) Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6EE198319E for ; Thu, 1 Jul 2021 00:45:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jmcosta944@gmail.com Received: by mail-pf1-x42d.google.com with SMTP id d12so4035233pfj.2 for ; Wed, 30 Jun 2021 15:45:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NMdkRFUiSQON4KUcyOMGeI6jLtERK7x2Np29gtAzSqc=; b=Zvpguau2lS4HvMkKadiF1XRhOyNk43rAbkCp9cRlKZFoNROhkyFnIrFA5Mg7d6kGyF JI9geXb1q/tqK3YpMJuYjNQ1QSo3VYZkBt3q7d9SAvXj3AUQ3VIF11mT57WaYBCUfndZ SsN/kwXQ8dkrLVeK88ndSFOqUakXVW3tuvssTyaiTy/kYBB88z4O3aeWracVv32aO0ij pQDYTu4JDPLKwKajxSMXAEIhqnVtbfZaJivgkopwyBkRS8HotriAhmOmClFWNHk3xSaQ W0hxLruP3Kqw+9jRo95bwk2ddfAysbJZbjRtK5aTAsctVIzh9rZaVovhqIi63ql99muh CYDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NMdkRFUiSQON4KUcyOMGeI6jLtERK7x2Np29gtAzSqc=; b=ncJOlEK4EDvKJjcMFvCBCa62T9Q0M3vG372s9h5J7DnJEke+OQprWzvMN2h1ZSWCRC 4W4tTxMtkZCwpL0p1OTXbSYM+IkSw1fx33+jMWzS9f44hrwL8un9DB1J/15NvDFe8Bgn crM011uorXgVrbCDwXrEbMfbUG9ZFqr8ghxiJqORDZRYmm0t9U+RMKqYtr+4c0hKzdVW SmNDUZRxoO/gIUct0kRnGAWDR7A62WWmtG35OHnlCjA5DdiqLj9Y4rw1lRi5oh6ro+Q2 FlaB6EYHMA59WTpmKDaBKgqwfgTrBo3jsZR6RUQk1w4s+/qIbJQnuQ/7wifhYy2EcsLC FQ5A== X-Gm-Message-State: AOAM533pSDXIgqv+OFz99UGZ45v1NSp+OYXM68byIxG8s4UfTFSDmMKJ OgY59kQTQzS1D1gd8b2yCJg6+TtOEsodjdvJ X-Google-Smtp-Source: ABdhPJyWKhfby5RkRS70mdsMWC5mJ8KVHc/xU1yA0mo0DM4GsAQFl83PSDi1JHQ45Nnbj8W0rebbhA== X-Received: by 2002:a62:7d55:0:b029:30f:e8b3:925 with SMTP id y82-20020a627d550000b029030fe8b30925mr5702138pfc.80.1625093120585; Wed, 30 Jun 2021 15:45:20 -0700 (PDT) Received: from localhost.localdomain ([177.194.32.83]) by smtp.googlemail.com with ESMTPSA id e3sm4964592pge.85.2021.06.30.15.45.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 15:45:20 -0700 (PDT) From: Joao Marcos Costa 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 Subject: [PATCH v3 2/3] test/py: rewrite sqfsload command test suite Date: Wed, 30 Jun 2021 19:45:04 -0300 Message-Id: <20210630224505.104648-3-jmcosta944@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210630224505.104648-1-jmcosta944@gmail.com> References: <20210630224505.104648-1-jmcosta944@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.103.2 at phobos.denx.de X-Virus-Status: Clean The previous strategy to know if a file was correctly loaded was to check for how many bytes were read and compare it against the file's original size. Since this is not a good solution, replace it by comparing the checksum of the loaded bytes against the original file's checksum. Add more test cases: files at a sub-directory and non-existent file. Signed-off-by: Joao Marcos Costa --- .../test_fs/test_squashfs/test_sqfs_load.py | 168 ++++++++++++++---- 1 file changed, 138 insertions(+), 30 deletions(-) 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 index 9e90062384..6ec6ccec6c 100644 --- a/test/py/tests/test_fs/test_squashfs/test_sqfs_load.py +++ b/test/py/tests/test_fs/test_squashfs/test_sqfs_load.py @@ -3,8 +3,118 @@ # Author: Joao Marcos Costa import os +import subprocess import pytest -from sqfs_common import * + +from sqfs_common import SQFS_SRC_DIR, STANDARD_TABLE +from sqfs_common import generate_sqfs_src_dir, make_all_images +from sqfs_common import clean_sqfs_src_dir, clean_all_images +from sqfs_common import check_mksquashfs_version + +@pytest.mark.requiredtool('md5sum') +def original_md5sum(path): + """ Runs md5sum command. + + Args: + path: path to original file. + Returns: + The original file's checksum as a string. + """ + + out = subprocess.run(['md5sum ' + path], shell=True, check=True, + capture_output=True, text=True) + checksum = out.stdout.split()[0] + + return checksum + +def uboot_md5sum(u_boot_console, address, count): + """ Runs U-Boot's md5sum command. + + Args: + u_boot_console: provides the means to interact with U-Boot's console. + address: address where the file was loaded (e.g.: $kernel_addr_r). + count: file's size. It was named 'count' to match md5sum's respective + argument name. + Returns: + The checksum of the file loaded with sqfsload as a string. + """ + + out = u_boot_console.run_command('md5sum {} {}'.format(address, count)) + checksum = out.split()[-1] + + return checksum + +def sqfs_load_files(u_boot_console, files, sizes, address): + """ Loads files and asserts their checksums. + + Args: + u_boot_console: provides the means to interact with U-Boot's console. + files: list of files to be loaded. + sizes: the sizes of each file. + address: the address where the files should be loaded. + """ + build_dir = u_boot_console.config.build_dir + for (file, size) in zip(files, sizes): + out = u_boot_console.run_command('sqfsload host 0 {} {}'.format(address, file)) + + # check if the right amount of bytes was read + assert size in out + + # compare original file's checksum against u-boot's + u_boot_checksum = uboot_md5sum(u_boot_console, address, hex(int(size))) + original_file_path = os.path.join(build_dir, SQFS_SRC_DIR + '/' + file) + original_checksum = original_md5sum(original_file_path) + assert u_boot_checksum == original_checksum + +def sqfs_load_files_at_root(u_boot_console): + """ Calls sqfs_load_files passing the files at the SquashFS image's root. + + Args: + u_boot_console: provides the means to interact with U-Boot's console. + """ + + files = ['f4096', 'f5096', 'f1000'] + sizes = ['4096', '5096', '1000'] + address = '$kernel_addr_r' + sqfs_load_files(u_boot_console, files, sizes, address) + +def sqfs_load_files_at_subdir(u_boot_console): + """ Calls sqfs_load_files passing the files at the SquashFS image's subdir. + + This test checks if the path resolution works, since the file is not at the + root directory. + + Args: + u_boot_console: provides the means to interact with U-Boot's console. + """ + files = ['subdir/subdir-file'] + sizes = ['100'] + address = '$kernel_addr_r' + sqfs_load_files(u_boot_console, files, sizes, address) + +def sqfs_load_non_existent_file(u_boot_console): + """ Calls sqfs_load_files passing an non-existent file to raise an error. + + This test checks if the SquashFS support won't crash if it doesn't find the + specified file. + + Args: + u_boot_console: provides the means to interact with U-Boot's console. + """ + address = '$kernel_addr_r' + file = 'non-existent' + out = u_boot_console.run_command('sqfsload host 0 {} {}'.format(address, file)) + assert 'Failed to load' in out + +def sqfs_run_all_load_tests(u_boot_console): + """ Runs all the previously defined test cases. + + Args: + u_boot_console: provides the means to interact with U-Boot's console. + """ + sqfs_load_files_at_root(u_boot_console) + sqfs_load_files_at_subdir(u_boot_console) + sqfs_load_non_existent_file(u_boot_console) @pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('cmd_fs_generic') @@ -12,35 +122,33 @@ from sqfs_common import * @pytest.mark.buildconfigspec('fs_squashfs') @pytest.mark.requiredtool('mksquashfs') def test_sqfs_load(u_boot_console): + """ Executes the sqfsload test suite. + + First, it generates the SquashFS images, then it runs the test cases and + finally cleans the workspace. If an exception is raised, the workspace is + cleaned before exiting. + + Args: + u_boot_console: provides the means to interact with U-Boot's console. + """ build_dir = u_boot_console.config.build_dir - command = "sqfsload host 0 $kernel_addr_r " - for opt in comp_opts: - # generate and load the squashfs image + # setup test environment + check_mksquashfs_version() + generate_sqfs_src_dir(build_dir) + make_all_images(build_dir) + + # run all tests for each image + for image in STANDARD_TABLE: 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) - - output = u_boot_console.run_command(command + "xxx") - assert "File not found." in output - - for (f, s) in zip(opt.files, opt.sizes): - try: - output = u_boot_console.run_command(command + f) - assert str(s) in output - except: - assert False - opt.cleanup(build_dir) - - # test symbolic link - output = u_boot_console.run_command(command + "sym") - assert str(opt.sizes[0]) in output - - # remove generated files - opt.cleanup(build_dir) + image_path = os.path.join(build_dir, image) + u_boot_console.run_command('host bind 0 {}'.format(image_path)) + sqfs_run_all_load_tests(u_boot_console) + except: + 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