From patchwork Mon May 24 02:31:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jo=C3=A3o_Marcos_Costa?= X-Patchwork-Id: 1482600 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=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=EuLkHBjN; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 4FpLnz6Bxbz9sRf for ; Mon, 24 May 2021 12:32:07 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 22A0182AD8; Mon, 24 May 2021 04:32:00 +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="EuLkHBjN"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 074D182E92; Mon, 24 May 2021 04:31:55 +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=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) (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 0F33D82AD8 for ; Mon, 24 May 2021 04:31:50 +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-qt1-x836.google.com with SMTP id h21so19690004qtu.5 for ; Sun, 23 May 2021 19:31:49 -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=dHeZ8l+Uc3k2OgaUGpW/3AC+mVH0RHxPpV4Rsnl+ko0=; b=EuLkHBjNCHRMsbkY3rWuf4NBhHEkmUcyD2wFSoXRHZanqmdakMjOyhasjtGBMTQKcx SFk+F2R78GM6QuPwOMizuF18RdYKhG+9WyLMxkAQT4wrdOW9FZZqoG4UVvi95InQf1z+ G7HlWR48zu2Zk8JENNr+MpC+JOwYxQZ3P+O3gBmBi9iF8gYbLF0DbH+E9gfg6bK2iyu+ J/oiDEsOnf93en/8Iu6/SNgNvYrvAL8FTgDjBblRG/jLN3Er6EEt+sMOV8wwcAsTdKc7 FqKZalQ9LGCaXWqIqy38u+o1HPdnE3zPFta3EXonCmquLPB6NYR0EEn/6NXHsOTHl3w3 azig== 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=dHeZ8l+Uc3k2OgaUGpW/3AC+mVH0RHxPpV4Rsnl+ko0=; b=XLkdob2zxCZMzA3NW8dt/CKbyWFpLlSmJUjlwsk6Pv1Eqg13b8sJXisl20KIziG2xt MNJXMPt6i1MJFLlBamofdfHQyVT5RgSc4ErO2qUGDmhRU0CP+grLI0IccsqJayUZs6HL 6p1SEZZnEtqL1vtAa1YdSq0ichP0ig5Yi4/4S/yTnpylqlequeyDYUCIjUbnQXaBeAwW rCDjf4KhNVh1V3CQMKGmi1B+qGL4sRCLsTeHGxGfc3aGvEK5EpHoh6AEiQd5cXCgRSpf FAeeDxTM+xDATZZHHBGve5Qch3O4No5kAhg6f6jgkUxjPj2kKzh02g3VeXo7c1ky+CbW VNIg== X-Gm-Message-State: AOAM533Zcz2v0A0Zb2Eofj9xn3719uAvRXO34BN+n0cWlN/Zc14OWfxl whKASxd4GrVfR4Oko76tZm6Y4GkM8vKvl17c X-Google-Smtp-Source: ABdhPJw9zuCsMLfwWiKcp9FzRCCPJZLiePZ1x+QXtbHktUhuV0pxFFeisx/pCxBRWXwzLyTnt69ikw== X-Received: by 2002:ac8:450c:: with SMTP id q12mr24645539qtn.327.1621823508623; Sun, 23 May 2021 19:31:48 -0700 (PDT) Received: from localhost.localdomain ([177.194.32.83]) by smtp.googlemail.com with ESMTPSA id h5sm10385647qkg.122.2021.05.23.19.31.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 May 2021 19:31:48 -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 1/3] test/py: rewrite common tools for SquashFS tests Date: Sun, 23 May 2021 23:31:31 -0300 Message-Id: <20210524023133.22100-2-jmcosta944@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210524023133.22100-1-jmcosta944@gmail.com> References: <20210524023133.22100-1-jmcosta944@gmail.com> MIME-Version: 1.0 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.4 at phobos.denx.de X-Virus-Status: Clean 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 --- .../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 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(): + # 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' + + file = open(file_name, 'w') file.write(content) file.close() -class Compression: - def __init__(self, name, files, sizes, block_size = 4096): - self.name = name - self.files = files - self.sizes = sizes - self.mksquashfs_opts = " -b " + str(block_size) + " -comp " + self.name - - def add_opt(self, opt): - self.mksquashfs_opts += " " + opt - - def gen_image(self, build_dir): - src = os.path.join(build_dir, "sqfs_src/") - os.mkdir(src) - for (f, s) in zip(self.files, self.sizes): - sqfs_generate_file(src + f, s) - - # the symbolic link always targets the first file - os.symlink(self.files[0], src + "sym") - - sqfs_img = os.path.join(build_dir, "sqfs-" + self.name) - i_o = src + " " + sqfs_img - opts = self.mksquashfs_opts - try: - subprocess.run(["mksquashfs " + i_o + opts], shell = True, check = True) - except: - print("mksquashfs error. Compression type: " + self.name) - raise RuntimeError - - def clean_source(self, build_dir): - src = os.path.join(build_dir, "sqfs_src/") - for f in self.files: - os.remove(src + f) - os.remove(src + "sym") - os.rmdir(src) - - def cleanup(self, build_dir): - self.clean_source(build_dir) - sqfs_img = os.path.join(build_dir, "sqfs-" + self.name) - os.remove(sqfs_img) - -files = ["blks_only", "blks_frag", "frag_only"] -sizes = [4096, 5100, 100] -gzip = Compression("gzip", files, sizes) -zstd = Compression("zstd", files, sizes) -lzo = Compression("lzo", files, sizes) - -# use fragment blocks for files larger than block_size -gzip.add_opt("-always-use-fragments") -zstd.add_opt("-always-use-fragments") - -# avoid fragments if lzo is used -lzo.add_opt("-no-fragments") - -comp_opts = [gzip, zstd, lzo] +""" +sqfs_src_dir +├── empty-dir +├── f1000 +├── f4096 +├── f5096 +├── subdir +│   └── subdir-file +└── sym -> subdir + +3 directories, 4 files +""" +def generate_sqfs_src_dir(build_dir): + path = os.path.join(build_dir, sqfs_src_dir) + print(path) + #path = build_dir + '/' + sqfs_src_dir + # 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) From patchwork Mon May 24 02:31:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jo=C3=A3o_Marcos_Costa?= X-Patchwork-Id: 1482601 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; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=VoukLLHl; dkim-atps=neutral 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 4FpLpB1BrPz9sRf for ; Mon, 24 May 2021 12:32:18 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D179382E9C; Mon, 24 May 2021 04:32:07 +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="VoukLLHl"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id ACE9D82E94; Mon, 24 May 2021 04:31:57 +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=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) (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 B9B3882E8D for ; Mon, 24 May 2021 04:31:52 +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-qk1-x732.google.com with SMTP id 82so14357317qki.8 for ; Sun, 23 May 2021 19:31:52 -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=i/QoXQadgZupvNuLlOoNpLEi/INQocuL+VfaRx7nqSQ=; b=VoukLLHlZdmKgcZDavE6p5Klonpx8dVqwanF97meOKhTkdaNw4jBJuO3fWzvC4bnaF +q8CPe8ZpBPcqthyMXlnz6DLxE+LrqP0ScQI6tf6BaV2s6NP9D9OEDjI8Di90Yg6hVEr osEVLXQpGRh20jkraGwrLVUKB6JVxKP+iCY7m/A1iCKt53Y7vPf4knFySqhFJs9C8lAj LgmHTC+/tNaFL8v2796+3VMtdZut7C/YpMzzxvBfL1/Jvo6F8pyG3uXeHxzWVAfHizqI aWuz6rJa14ZW+tRQ71VBqy+G40dvGszyviL/Q1tcj5W8FjYJXlnzsW5ht16CRBs4O84k YhAg== 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=i/QoXQadgZupvNuLlOoNpLEi/INQocuL+VfaRx7nqSQ=; b=t+uGb+3ZGZ02CdYLHWGU7KO3DxQRVBAELOXfqQ/yKltlUzoZ9r9zgdEtQHpJr70Ytg 1C4ZUqy0MGMH2lCSRZ9xDl6CeW4521zU+pg8+N9JUXyyFjGcOmiT2ogbwXQCB+kPveOT yJ9HEPy6Sr6qfOd7IWy8nQK2mb15exv2RAMXcG/2twZHG1zJC2kRNN47bPzp+oJdSaAv EQteDvPdOQtyNVy4X+FDPbGaQGS7cH7xCF4MILEy7cxoJCpxsr21ZJiJSxgIA5lNQVfW /NgNlvERmHnJHhzBgYyexXcJFZeLlJfMlYvqpv94IuiFvWsdASZht3lhaM8cYoXmYhX1 B9Kw== X-Gm-Message-State: AOAM531mQqmxSFzCvDzkXmh9o/cPnlq7gOFNqj2ESs9xnVSvXiZoZamn YQpIhGI4YstMnEUDu3LRiuep4m+FLzfpKU+n X-Google-Smtp-Source: ABdhPJy8bjZh8CCTzHpaXxWbexHOpPeSFHYvLboLz9MLq9ipQlKNFAO28ntgblc4vrdyiz8tdQMlUg== X-Received: by 2002:a05:620a:200d:: with SMTP id c13mr26983995qka.360.1621823511432; Sun, 23 May 2021 19:31:51 -0700 (PDT) Received: from localhost.localdomain ([177.194.32.83]) by smtp.googlemail.com with ESMTPSA id h5sm10385647qkg.122.2021.05.23.19.31.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 May 2021 19:31:51 -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 2/3] test/py: rewrite sqfsload command test suite Date: Sun, 23 May 2021 23:31:32 -0300 Message-Id: <20210524023133.22100-3-jmcosta944@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210524023133.22100-1-jmcosta944@gmail.com> References: <20210524023133.22100-1-jmcosta944@gmail.com> MIME-Version: 1.0 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.4 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 | 99 +++++++++++++------ 1 file changed, 69 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..0b416eb4c3 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 @@ -1,11 +1,62 @@ # SPDX-License-Identifier: GPL-2.0 -# Copyright (C) 2020 Bootlin +# Copyright (C) 2021 Bootlin # Author: Joao Marcos Costa import os import pytest from sqfs_common import * +@pytest.mark.requiredtool('md5sum') +def original_md5sum(path): + 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): + out = u_boot_console.run_command('md5sum {} {}'.format(address, count)) + checksum = out.split()[-1] + + return checksum + +# loads files and asserts checksums +def sqfs_load_files(u_boot_console, files, sizes, address): + build_dir = u_boot_console.config.build_dir + for (f, size) in zip(files, sizes): + out = u_boot_console.run_command('sqfsload host 0 {} {}'.format(address, f)) + + # 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_checksum = original_md5sum(os.path.join(build_dir, sqfs_src_dir + '/' + f)) + assert u_boot_checksum == original_checksum + +def sqfs_load_files_at_root(u_boot_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): + 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): + address = '$kernel_addr_r' + f = 'non-existent' + out = u_boot_console.run_command('sqfsload host 0 {} {}'.format(address, f)) + assert 'Failed to load' in out + +def sqfs_run_all_load_tests(u_boot_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') @pytest.mark.buildconfigspec('cmd_squashfs') @@ -13,34 +64,22 @@ from sqfs_common import * @pytest.mark.requiredtool('mksquashfs') def test_sqfs_load(u_boot_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 + generate_sqfs_src_dir(build_dir) + make_all_images(build_dir) + + # run all tests for each image + for image in standard_table.keys(): 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) From patchwork Mon May 24 02:31:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jo=C3=A3o_Marcos_Costa?= X-Patchwork-Id: 1482602 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; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=SSGsAmwH; dkim-atps=neutral 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 4FpLpM4LsRz9sRf for ; Mon, 24 May 2021 12:32:27 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BE5DE82EA2; Mon, 24 May 2021 04:32:20 +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="SSGsAmwH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0F34282E94; Mon, 24 May 2021 04:32:00 +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=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qk1-x72b.google.com (mail-qk1-x72b.google.com [IPv6:2607:f8b0:4864:20::72b]) (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 7E50282AD8 for ; Mon, 24 May 2021 04:31:55 +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-qk1-x72b.google.com with SMTP id c20so25768102qkm.3 for ; Sun, 23 May 2021 19:31:55 -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=SumFhDcQo3Zw11+l7vUqk3sldCiuun1QcSyCV/ncZpY=; b=SSGsAmwHGmUN2EH7HnhmGd78arV4QRquhOOnSS2lEn2T4NnOD5nux6qX4ZKRIBK1ei 5sr4/ecTFNeUJyKXngMCIzwj8wqXWTCls+DP/AX7bq2CIQ244Bg9ZyJ/nyHxUbMxhAJU ETTYbbBOK0vxi59IO4yofBhW6dKXsMZYcquWDorkFh5avyJIEUz8fuAURCJE7VF295LZ KcJTPOqKc03v1b9gcXZCLohfbQ2/T25OuHDCnJkAdDUTja+xVj+h36/cQKPB7revw8P8 RoZ/azHTItstQu1avVFbpqb5rUhiTTDvlmmP/5d12aC12PkubANK/Kk/Qp7yNxNGxu2t 6brA== 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=SumFhDcQo3Zw11+l7vUqk3sldCiuun1QcSyCV/ncZpY=; b=M6mnnw8keVY1ohX8aFuj80Bhj8wMvIrQ5ACmVdQQBKKrvZ3YI5U8Dyh2J6gJ2ZU5/I JyFpWsAsfz8Pfo9iAcX+eIG+HkqCZdqFsjUdOGdjiQoI0FnMdNGv9yhsH49h76JGPoE9 TXdum3dfTHA/NeF0f6quI8rDgVErR8lsXmp4r7BZU39kztQ9aTjH2WJAWGaCjd8atUZe jtdTAASttXFQiKWZZIi98TBxoFaw3KxbQP2xy/UXVOIJCHU5sDHYoQNP9k1KrVSRFETL z+50ZYhS9qXGwxNmQsx9tPO8OGgpH64okcXXTiQHrjY/fsVmkIHdMgJCVbC0lGN+ouoz iZ1Q== X-Gm-Message-State: AOAM530LdN6D4LTkWK726ANx46s3eCISNS+HQ33WUIicxT2+IgzZbR+8 pnDsNWHfsp6wRcKgmCcIz7YeDFq0nVvSpdE8 X-Google-Smtp-Source: ABdhPJwwV6vTPMqKSRgcOX8F7cPx9w385sEsEoy+HHZ6/AuI68FpmpLa10buvJCVNzMHksGy0Txyow== X-Received: by 2002:a05:620a:2e4:: with SMTP id a4mr17201495qko.250.1621823514271; Sun, 23 May 2021 19:31:54 -0700 (PDT) Received: from localhost.localdomain ([177.194.32.83]) by smtp.googlemail.com with ESMTPSA id h5sm10385647qkg.122.2021.05.23.19.31.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 May 2021 19:31:54 -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 3/3] test/py: rewrite sqfsls command test suite Date: Sun, 23 May 2021 23:31:33 -0300 Message-Id: <20210524023133.22100-4-jmcosta944@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210524023133.22100-1-jmcosta944@gmail.com> References: <20210524023133.22100-1-jmcosta944@gmail.com> MIME-Version: 1.0 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.4 at phobos.denx.de X-Virus-Status: Clean 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 --- .../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', '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" 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)