Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id C1F4CC38A02 for ; Sun, 30 Oct 2022 01:49:46 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7AD1185162; Sun, 30 Oct 2022 02:47:52 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="PfvIdOY+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 35CB78511F; Sun, 30 Oct 2022 02:47:47 +0100 (CET) Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) (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 5BBCF85106 for ; Sun, 30 Oct 2022 02:47:44 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x129.google.com with SMTP id o2so4771488ilo.8 for ; Sat, 29 Oct 2022 18:47:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=U3a+x9jMH+IlWM90PL7jFoJwrVgr+1Jmv3UDytO6DYU=; b=PfvIdOY+pu0QXNVWCeh6OeAAdsaG2vrMxTMD43e1QBY8SItJ1FpgZeyXUSzDnW76CP oJrorwTweuMeircGLqvD+dT808kMEves40P/KYKVXeCXZYHjwBoqw/v1PxBxWs9yeKB4 g09Eh6g0+8R8vqlbSZ0BHnAbedvL6WodneGOM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=U3a+x9jMH+IlWM90PL7jFoJwrVgr+1Jmv3UDytO6DYU=; b=xoJ9l0E+mOCW3ystViH/Ap0mT53Ck/k6VzfD7K0emcIJuzU+HTtDGCoIGjXDqn03Wo mCkbERDHq7ZH/3Y6WORiG5bDiE8LEgAEiry5ehMfIQd6tPdVnsRhPB2umDUz8lx4VZT7 7GPQm2jXURgOJ5PVYDuRK9CLOenWdD2cnZxtq9Fb4fkYqbVwK1pq+Qcy8zF852oy99ps 2BbSCxlhf9VpmpbTTuMwanf4jkZUtRGTPbQUjuoN9p0Pjuo8tfwHeBeJtfLjfGeqj27J aNM6w39BQt5XXkTCXIyWP75I/GuNdOOLAfYUq2VPI0G9PTN0FXoQo3rNhdsCf1S333Si WWCQ== X-Gm-Message-State: ACrzQf1OdnBVzMx/W1a3Hdw6McGpk+qIxovJ2/SMs+XNAx+rUZNdcrIh EmzyWe3/ktlB9ZfnH+yFD+OPdAIZwZNqtQ== X-Google-Smtp-Source: AMsMyM7CWKs2TtvwWCwW520WLDu8oPdr0MuZOsWxZIMeuzIdrxxPe+272uLEwyysPBIPWmXb0PYydw== X-Received: by 2002:a05:6e02:19cd:b0:2fa:22ce:5c05 with SMTP id r13-20020a056e0219cd00b002fa22ce5c05mr3107520ill.305.1667094462782; Sat, 29 Oct 2022 18:47:42 -0700 (PDT) Received: from sjg1.roam.corp.google.com (c-67-190-102-125.hsd1.co.comcast.net. [67.190.102.125]) by smtp.gmail.com with ESMTPSA id x66-20020a0294c8000000b00363c4307bb2sm810287jah.79.2022.10.29.18.47.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Oct 2022 18:47:42 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Heinrich Schuchardt , Simon Glass Subject: [PATCH 03/17] test: Split out mk_fs function into a helper Date: Sat, 29 Oct 2022 19:47:05 -0600 Message-Id: <20221030014719.147327-4-sjg@chromium.org> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog In-Reply-To: <20221030014719.147327-1-sjg@chromium.org> References: <20221030014719.147327-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.6 at phobos.denx.de X-Virus-Status: Clean This function is useful for other tests. Move it into common code. Signed-off-by: Simon Glass --- test/py/tests/fs_helper.py | 54 ++++++++++++++++++++++++++++ test/py/tests/test_fs/conftest.py | 58 ++++--------------------------- 2 files changed, 60 insertions(+), 52 deletions(-) create mode 100644 test/py/tests/fs_helper.py diff --git a/test/py/tests/fs_helper.py b/test/py/tests/fs_helper.py new file mode 100644 index 00000000000..2d8f1f63add --- /dev/null +++ b/test/py/tests/fs_helper.py @@ -0,0 +1,54 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Helper functions for dealing with filesystems +# +# Copyright (c) 2018, Linaro Limited +# Author: Takahiro Akashi + +import re +import os +from subprocess import call, check_call, check_output, CalledProcessError + +def mk_fs(config, fs_type, size, prefix): + """Create a file system volume + + Args: + fs_type (str): File system type, e.g. 'ext4' + size (int): Size of file system in bytes + prefix (str): Prefix string of volume's file name + """ + fs_img = '%s.%s.img' % (prefix, fs_type) + fs_img = config.persistent_data_dir + '/' + fs_img + + if fs_type == 'fat16': + mkfs_opt = '-F 16' + elif fs_type == 'fat32': + mkfs_opt = '-F 32' + else: + mkfs_opt = '' + + if re.match('fat', fs_type): + fs_lnxtype = 'vfat' + else: + fs_lnxtype = fs_type + + count = (size + 1048576 - 1) / 1048576 + + # Some distributions do not add /sbin to the default PATH, where mkfs lives + if '/sbin' not in os.environ["PATH"].split(os.pathsep): + os.environ["PATH"] += os.pathsep + '/sbin' + + try: + check_call('rm -f %s' % fs_img, shell=True) + check_call('dd if=/dev/zero of=%s bs=1M count=%d' + % (fs_img, count), shell=True) + check_call('mkfs.%s %s %s' + % (fs_lnxtype, mkfs_opt, fs_img), shell=True) + if fs_type == 'ext4': + sb_content = check_output('tune2fs -l %s' % fs_img, shell=True).decode() + if 'metadata_csum' in sb_content: + check_call('tune2fs -O ^metadata_csum %s' % fs_img, shell=True) + return fs_img + except CalledProcessError: + call('rm -f %s' % fs_img, shell=True) + raise diff --git a/test/py/tests/test_fs/conftest.py b/test/py/tests/test_fs/conftest.py index b638284e076..9329ec6f1b2 100644 --- a/test/py/tests/test_fs/conftest.py +++ b/test/py/tests/test_fs/conftest.py @@ -9,6 +9,7 @@ import re from subprocess import call, check_call, check_output, CalledProcessError from fstest_defs import * import u_boot_utils as util +from tests import fs_helper supported_fs_basic = ['fat16', 'fat32', 'ext4'] supported_fs_ext = ['fat16', 'fat32'] @@ -132,53 +133,6 @@ def check_ubconfig(config, fs_type): pytest.skip('.config feature "%s_WRITE" not enabled' % fs_type.upper()) -def mk_fs(config, fs_type, size, id): - """Create a file system volume. - - Args: - fs_type: File system type. - size: Size of file system in MiB. - id: Prefix string of volume's file name. - - Return: - Nothing. - """ - fs_img = '%s.%s.img' % (id, fs_type) - fs_img = config.persistent_data_dir + '/' + fs_img - - if fs_type == 'fat16': - mkfs_opt = '-F 16' - elif fs_type == 'fat32': - mkfs_opt = '-F 32' - else: - mkfs_opt = '' - - if re.match('fat', fs_type): - fs_lnxtype = 'vfat' - else: - fs_lnxtype = fs_type - - count = (size + 1048576 - 1) / 1048576 - - # Some distributions do not add /sbin to the default PATH, where mkfs lives - if '/sbin' not in os.environ["PATH"].split(os.pathsep): - os.environ["PATH"] += os.pathsep + '/sbin' - - try: - check_call('rm -f %s' % fs_img, shell=True) - check_call('dd if=/dev/zero of=%s bs=1M count=%d' - % (fs_img, count), shell=True) - check_call('mkfs.%s %s %s' - % (fs_lnxtype, mkfs_opt, fs_img), shell=True) - if fs_type == 'ext4': - sb_content = check_output('tune2fs -l %s' % fs_img, shell=True).decode() - if 'metadata_csum' in sb_content: - check_call('tune2fs -O ^metadata_csum %s' % fs_img, shell=True) - return fs_img - except CalledProcessError: - call('rm -f %s' % fs_img, shell=True) - raise - # from test/py/conftest.py def tool_is_in_path(tool): """Check whether a given command is available on host. @@ -283,7 +237,7 @@ def fs_obj_basic(request, u_boot_config): try: # 3GiB volume - fs_img = mk_fs(u_boot_config, fs_type, 0xc0000000, '3GB') + fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0xc0000000, '3GB') except CalledProcessError as err: pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) return @@ -405,7 +359,7 @@ def fs_obj_ext(request, u_boot_config): try: # 128MiB volume - fs_img = mk_fs(u_boot_config, fs_type, 0x8000000, '128MB') + fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB') except CalledProcessError as err: pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) return @@ -500,7 +454,7 @@ def fs_obj_mkdir(request, u_boot_config): try: # 128MiB volume - fs_img = mk_fs(u_boot_config, fs_type, 0x8000000, '128MB') + fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB') except: pytest.skip('Setup failed for filesystem: ' + fs_type) return @@ -534,7 +488,7 @@ def fs_obj_unlink(request, u_boot_config): try: # 128MiB volume - fs_img = mk_fs(u_boot_config, fs_type, 0x8000000, '128MB') + fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB') except CalledProcessError as err: pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) return @@ -617,7 +571,7 @@ def fs_obj_symlink(request, u_boot_config): try: # 1GiB volume - fs_img = mk_fs(u_boot_config, fs_type, 0x40000000, '1GB') + fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x40000000, '1GB') except CalledProcessError as err: pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) return -- 2.38.1.273.g43a17bfeac-goog