From patchwork Tue Sep 11 07:06:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146415 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3321383ljw; Tue, 11 Sep 2018 00:12:19 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYHe8KbtHIiRL1ni+LnjcZT5s8oxAdXhLRRe1UGcYrq1nEtOjTHUBEasUynJoESV84BP6rM X-Received: by 2002:a50:9943:: with SMTP id l3-v6mr26451383edb.198.1536649939224; Tue, 11 Sep 2018 00:12:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536649939; cv=none; d=google.com; s=arc-20160816; b=VDaGj2UmQc0l4T+lb4u1tBpoAsKAm/veSJ31s059+mITFUbOh8fXN5dRoCwhjzwLpL AqgXb1Km4KGesIpdnbqpS94oEknl8a9x+Eag4JPjJ7NGKLOaNtENXyJchldymIGoeHDN xud76cszi1Mj7iFaEsL0tQ4jn7rQPHe2JfRhkVhp7g6LwVxsnckjk72LFUCJNsIs78fB EvXloYhL9UYWqpdC+BHsSxCqRhM3KQXmkR+1xLN9i3nj+GOH56p1WTEFoqPsEKUjsfN9 DAqn/1CBfFsl7NFyUSSeltDQ0sSNhPuH7UrqKdi0QnhtcfH42smcpZp9XD2welmpI7TR aEdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:message-id:date:to:from :dkim-signature; bh=FmI3GIbeEhRmRj7huseHyw17B60qHGP0urOmiV7MDms=; b=fQQDQyWUkzxpFkIlXMtReJQvTZjRInnZ0A1uNlJ2CbsK8ebRB0oIBrXMbi4Ct7//V0 CBR9aVsUIq6MaWvz6wEwJejlG6Tm4ZZpcAypvS4ACnqSov/UrH6MNx/JHHM5EXeAlywV 7rB/Ukp9laX03hXQnITl8vb+ACe21jHIhAdXckXpwqK+TVXqBECHczQ9oxQb4AyxCEom ou9e9P7UMxD9FqqewuBs7X/2pNqnGON0oTmBS2fHR4LRubSLI7Ke4OR6xAWSpB0iSGJx yPNKKXSqMgpNxJ6qIzQJwb5RYJA0/4CkdsIbhfuAkNhuo6Ag0dw1jLd71WwA/+JIkgT1 h1NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=CHtdvC5n; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id k4-v6si2477799edr.290.2018.09.11.00.12.18; Tue, 11 Sep 2018 00:12:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=CHtdvC5n; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id BD910C21E18; Tue, 11 Sep 2018 07:11:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 31FD8C21E18; Tue, 11 Sep 2018 07:08:06 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 1AEE1C21DD9; Tue, 11 Sep 2018 07:05:25 +0000 (UTC) Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by lists.denx.de (Postfix) with ESMTPS id A4B1AC21E76 for ; Tue, 11 Sep 2018 07:05:18 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id b129-v6so11740921pga.13 for ; Tue, 11 Sep 2018 00:05:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=htsTI3uKmEw1mLxTS4jetYUPfQSPLrIfgujWvm4VK3I=; b=CHtdvC5nVFvVQ1xTBZ+VlG41cuZbuHR3ESl9rTNKlgRdx+3ke/CwNzEU4UodKr5NP9 Jw6G67J4BMOU5dznC5c+SozbC2cVfyTPrQgdI95Cgeyhcxdw0vWmp17KhZLMlAQXfKZt LEXeYUSuFMMz+P0HvovOCr/pun1J9jqvFPK2Y= 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; bh=htsTI3uKmEw1mLxTS4jetYUPfQSPLrIfgujWvm4VK3I=; b=FpM4nJvSJ7+dQ6uHz372dEwMkJ6b3JexEkIG2LqJ52h0Ba8MAFQSxOCoJHbeaaMTBG Mr3HPOtK2PZ/gOlL1Q9dzY9NhduiMGluYkZKTOR+ygOL0tMFIIPBwoJBt46TjRlOh/Ee sViz31kcpY6TVtVtKI/W384mBm0Eo9JlMv3rFWvwe/QI7KP5xMvaVmYJpG+CwyrgEs6a +0Z20mF7/DSqLDfnaw161Mrcb31NOc1mncsEJrLPjGj5/Yx88tTzFHeTE9k8rWzNfsLl 60Wr3YH4Sq5DKVfCue+uScnHAM4f2dUtM7ads01q0SIee+HZ8FMcPs5rB9IPkJyRtWo2 kO8w== X-Gm-Message-State: APzg51AzjIFpvvEcyrFwqesjaN0SdBg25SjuXdDjZuvWIZY02Fz/sPfs n4UFMTZBTxQaKXuyTW7rlNNakQ== X-Received: by 2002:a63:d806:: with SMTP id b6-v6mr26250311pgh.347.1536649517204; Tue, 11 Sep 2018 00:05:17 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id u9-v6sm32877743pfi.104.2018.09.11.00.05.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Sep 2018 00:05:16 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 16:06:03 +0900 Message-Id: <20180911070603.19495-1-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 Cc: u-boot@lists.denx.de, xypron.glpk@gmx.de, agraf@suse.de Subject: [U-Boot] [PATCH v3 26/26] test/py: fs: add fstest/unlink test X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" In this commit, test cases for unlink interfaces are added as part of "test_fs" test suite. Signed-off-by: AKASHI Takahiro --- test/py/tests/test_fs/conftest.py | 62 +++++++++++++++ test/py/tests/test_fs/test_unlink.py | 109 +++++++++++++++++++++++++++ 2 files changed, 171 insertions(+) create mode 100644 test/py/tests/test_fs/test_unlink.py diff --git a/test/py/tests/test_fs/conftest.py b/test/py/tests/test_fs/conftest.py index 71abf8fa4222..6404b311bc30 100644 --- a/test/py/tests/test_fs/conftest.py +++ b/test/py/tests/test_fs/conftest.py @@ -12,6 +12,7 @@ from fstest_defs import * supported_fs_basic = ['fat16', 'fat32', 'ext4'] supported_fs_ext = ['fat16', 'fat32'] supported_fs_mkdir = ['fat16', 'fat32'] +supported_fs_unlink = ['fat16', 'fat32'] # # Filesystem test specific setup @@ -24,6 +25,7 @@ def pytest_configure(config): global supported_fs_basic global supported_fs_ext global supported_fs_mkdir + global supported_fs_unlink def intersect(listA, listB): return [x for x in listA if x in listB] @@ -34,6 +36,7 @@ def pytest_configure(config): supported_fs_basic = intersect(supported_fs, supported_fs_basic) supported_fs_ext = intersect(supported_fs, supported_fs_ext) supported_fs_mkdir = intersect(supported_fs, supported_fs_mkdir) + supported_fs_unlink = intersect(supported_fs, supported_fs_unlink) def pytest_generate_tests(metafunc): if 'fs_obj_basic' in metafunc.fixturenames: @@ -45,6 +48,9 @@ def pytest_generate_tests(metafunc): if 'fs_obj_mkdir' in metafunc.fixturenames: metafunc.parametrize('fs_obj_mkdir', supported_fs_mkdir, indirect=True, scope='module') + if 'fs_obj_unlink' in metafunc.fixturenames: + metafunc.parametrize('fs_obj_unlink', supported_fs_unlink, + indirect=True, scope='module') # # Helper functions @@ -328,3 +334,59 @@ def fs_obj_mkdir(request, u_boot_config): finally: if fs_img: call('rm -f %s' % fs_img, shell=True) + +# +# Fixture for unlink test +# +# NOTE: yield_fixture was deprecated since pytest-3.0 +@pytest.yield_fixture() +def fs_obj_unlink(request, u_boot_config): + fs_type = request.param + fs_img = '' + + fs_ubtype = fstype_to_ubname(fs_type) + check_ubconfig(u_boot_config, fs_ubtype) + + mount_dir = u_boot_config.persistent_data_dir + '/mnt' + + try: + + # 128MiB volume + fs_img = mk_fs(u_boot_config, fs_type, 0x8000000, '128MB') + + # Mount the image so we can populate it. + check_call('mkdir -p %s' % mount_dir, shell=True) + mount_fs(fs_type, fs_img, mount_dir) + + # Test Case 1 & 3 + check_call('mkdir %s/dir1' % mount_dir, shell=True) + check_call('dd if=/dev/urandom of=%s/dir1/file1 bs=1K count=1' + % mount_dir, shell=True) + check_call('dd if=/dev/urandom of=%s/dir1/file2 bs=1K count=1' + % mount_dir, shell=True) + + # Test Case 2 + check_call('mkdir %s/dir2' % mount_dir, shell=True) + for i in range(0, 20): + check_call('mkdir %s/dir2/0123456789abcdef%02x' + % (mount_dir, i), shell=True) + + # Test Case 4 + check_call('mkdir %s/dir4' % mount_dir, shell=True) + + # Test Case 5, 6 & 7 + check_call('mkdir %s/dir5' % mount_dir, shell=True) + check_call('dd if=/dev/urandom of=%s/dir5/file1 bs=1K count=1' + % mount_dir, shell=True) + + umount_fs(fs_type, mount_dir) + except CalledProcessError: + pytest.skip('Setup failed for filesystem: ' + fs_type) + return + else: + yield [fs_ubtype, fs_img] + finally: + umount_fs(fs_type, mount_dir) + call('rmdir %s' % mount_dir, shell=True) + if fs_img: + call('rm -f %s' % fs_img, shell=True) diff --git a/test/py/tests/test_fs/test_unlink.py b/test/py/tests/test_fs/test_unlink.py new file mode 100644 index 000000000000..69c1a6e078c3 --- /dev/null +++ b/test/py/tests/test_fs/test_unlink.py @@ -0,0 +1,109 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2018, Linaro Limited +# Author: Takahiro Akashi +# +# U-Boot File System:unlink Test + +""" +This test verifies unlink operation (deleting a file or a directory) +on file system. +""" + +import pytest + +@pytest.mark.boardspec('sandbox') +class TestUnlink(object): + def test_unlink1(self, u_boot_console, fs_obj_unlink): + """ + Test Case 1 - delete a file + """ + fs_type,fs_img = fs_obj_unlink + with u_boot_console.log.section('Test Case 1 - unlink (file)'): + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%srm host 0:0 dir1/file1' % fs_type, + '%sls host 0:0 dir1/file1' % fs_type]) + assert('' == ''.join(output)) + + output = u_boot_console.run_command( + '%sls host 0:0 dir1/' % fs_type) + assert(not 'file1' in output) + assert('file2' in output) + + def test_unlink2(self, u_boot_console, fs_obj_unlink): + """ + Test Case 2 - delete many files + """ + fs_type,fs_img = fs_obj_unlink + with u_boot_console.log.section('Test Case 2 - unlink (many)'): + output = u_boot_console.run_command('host bind 0 %s' % fs_img) + + for i in range(0, 20): + output = u_boot_console.run_command_list([ + '%srm host 0:0 dir2/0123456789abcdef%02x' % (fs_type, i), + '%sls host 0:0 dir2/0123456789abcdef%02x' % (fs_type, i)]) + assert('' == ''.join(output)) + + output = u_boot_console.run_command( + '%sls host 0:0 dir2' % fs_type) + assert('0 file(s), 2 dir(s)' in output) + + def test_unlink3(self, u_boot_console, fs_obj_unlink): + """ + Test Case 3 - trying to delete a non-existing file should fail + """ + fs_type,fs_img = fs_obj_unlink + with u_boot_console.log.section('Test Case 3 - unlink (non-existing)'): + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%srm host 0:0 dir1/nofile' % fs_type]) + assert('nofile: doesn\'t exist' in ''.join(output)) + + def test_unlink4(self, u_boot_console, fs_obj_unlink): + """ + Test Case 4 - delete an empty directory + """ + fs_type,fs_img = fs_obj_unlink + with u_boot_console.log.section('Test Case 4 - unlink (directory)'): + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%srm host 0:0 dir4' % fs_type]) + assert('' == ''.join(output)) + + output = u_boot_console.run_command( + '%sls host 0:0 /' % fs_type) + assert(not 'dir4' in output) + + def test_unlink5(self, u_boot_console, fs_obj_unlink): + """ + Test Case 5 - trying to deleting a non-empty directory ".." + should fail + """ + fs_type,fs_img = fs_obj_unlink + with u_boot_console.log.section('Test Case 5 - unlink ("non-empty directory")'): + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%srm host 0:0 dir5' % fs_type]) + assert('directory is not empty' in ''.join(output)) + + def test_unlink6(self, u_boot_console, fs_obj_unlink): + """ + Test Case 6 - trying to deleting a "." should fail + """ + fs_type,fs_img = fs_obj_unlink + with u_boot_console.log.section('Test Case 6 - unlink (".")'): + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%srm host 0:0 dir5/.' % fs_type]) + assert('directory is not empty' in ''.join(output)) + + def test_unlink7(self, u_boot_console, fs_obj_unlink): + """ + Test Case 7 - trying to deleting a ".." should fail + """ + fs_type,fs_img = fs_obj_unlink + with u_boot_console.log.section('Test Case 7 - unlink ("..")'): + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%srm host 0:0 dir5/..' % fs_type]) + assert('directory is not empty' in ''.join(output))