From patchwork Tue Oct 29 12:09:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yong X-Patchwork-Id: 13854824 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E0590D2AB36 for ; Tue, 29 Oct 2024 12:11:57 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1t5l4o-0007zJ-4q; Tue, 29 Oct 2024 12:11:57 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1t5l4k-0007ys-Gd for linux-f2fs-devel@lists.sourceforge.net; Tue, 29 Oct 2024 12:11:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=MIME-Version:Content-Type:Content-Transfer-Encoding :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=K9q+3wzhHhMEQR6AG32KbB7p+8mI0YvjNUs2WlLJ6Yk=; b=hX7kwsWr0bWIb6ida/kuIlE+EA eUU+mQjYsOit7I1WYQRUW0V5SDcx1xZjMa4htxUiX1dTpIPUugJOQpiQZqMUucv2IgPqNMcFeG1uw 7BkFQ30CpVIyI5t4o3TCQMLsTPc6VTt4K7XGlk9yh9IJOHTRLZmElR5ftp0JFk5R5O+w=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=MIME-Version:Content-Type:Content-Transfer-Encoding:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=K9q+3wzhHhMEQR6AG32KbB7p+8mI0YvjNUs2WlLJ6Yk=; b=KbWaIPr0vTk+IpFLAzkkoEc66G UQr/CqoqaNFurD9ywdlcAcFlE4ZwYaEn1Np1f6mODOfUiDjzwUPqzhnLKOG3L1GQbwYXICjqVdiEv ESAD+AsYGfu4hp1/+Jg/LRyLedWfJZV3TemHI2s16tCI7qJqTVjnzupvyuEGnOTUjPTs=; Received: from mail-psaapc01on2084.outbound.protection.outlook.com ([40.107.255.84] helo=APC01-PSA-obe.outbound.protection.outlook.com) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1t5l4i-0007Qb-PE for linux-f2fs-devel@lists.sourceforge.net; Tue, 29 Oct 2024 12:11:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MMbFT78K0Ipz6+loqhVd9GrJntoFPXcFg3Tb9Uuvewq8ojXP1Yv1vPQNJDnV+KbW9HDJAaYsJ0XQZcqiLVUZq6GG6MI3sAPm9xjpwbf0rqAcCcUcs9jG+84IIMeLq3o/JKLGbEwRxSEOjdc80YMBgdHeFG/amR5yA1jtZMaNZi1PjLB3sulbrCFetv9dUnQbzhHepU0gptnaMQRfWiSl+cXRtjSXzRLl5CWrhdTHcTE3qkCTb11h/Fid50ymKdwgwCEO+JN/AD7rJL9POsHlHj/TmCAlJQ96ItR9vDQH2w4BF9qp+Dp3ASRhYuSc7gf1w6Bmswr4Rm4QFza1qGhR6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=K9q+3wzhHhMEQR6AG32KbB7p+8mI0YvjNUs2WlLJ6Yk=; b=L3zLbcdLyOPyXPRHE6xIC7qakpdiPGbhw+7Qfb4jWpCKgQVPclWNxWygANFZwGeBDPJPeKSRg+P12LwEg07XMeIGt1RMMOQPhd16s+mmR3mw5FaAx7Iz+Xi68D+rcZyGN84z9wiFOyogT77TNcN9ZzsKqe+olDQHFjwGsRaCWyPp4IyN8+ZWromvkWFx67HH7rtsoXg1ZL952/RBu3ukHYB+nJbgPgcaFyyeYHhrLj0bfOi33vaZuJTcGyodBo7NT1qnPHEHCgGluTyExVq2u0x5IKNGlcG/xrNgGq9e7oOwCYdjfw9ONzNecOZ2m6GkG8PbFKRaV0g0qLKH7hknKQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oppo.com; dmarc=pass action=none header.from=oppo.com; dkim=pass header.d=oppo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oppo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=K9q+3wzhHhMEQR6AG32KbB7p+8mI0YvjNUs2WlLJ6Yk=; b=MrRRZZ1/Yytv2Vu7+l03kYLdos+XtL8tKMsmyoYCzYkrDsPFfG3ktuoXntPwgSwLI6wpmUELFTWmxxbwdtXFCtExYCBy8baysKUSnQn6RhYe4nKZ0xkjJwyW/hxR2sgdjVTq7rr0ioVYfr36d1Tzy2JAKz00H5JPyEKV7/WMup0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oppo.com; Received: from SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) by SEZPR02MB7326.apcprd02.prod.outlook.com (2603:1096:101:1f4::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.32; Tue, 29 Oct 2024 12:11:37 +0000 Received: from SEYPR02MB6014.apcprd02.prod.outlook.com ([fe80::bb06:c283:a50:7796]) by SEYPR02MB6014.apcprd02.prod.outlook.com ([fe80::bb06:c283:a50:7796%7]) with mapi id 15.20.8093.023; Tue, 29 Oct 2024 12:11:37 +0000 To: jaegeuk@kernel.org, chao@kernel.org Date: Tue, 29 Oct 2024 20:09:40 +0800 Message-Id: <20241029120956.4186731-9-shengyong@oppo.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20241029120956.4186731-1-shengyong@oppo.com> References: <20241029120956.4186731-1-shengyong@oppo.com> X-ClientProxiedBy: SG2PR01CA0175.apcprd01.prod.exchangelabs.com (2603:1096:4:28::31) To SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR02MB6014:EE_|SEZPR02MB7326:EE_ X-MS-Office365-Filtering-Correlation-Id: 1a590c74-e3c6-4c1a-ec27-08dcf812d669 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|52116014|376014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: poFyDWcveHpyACfxBKveh5nxZ0iR3sGAO4TYZkf4knGc4EW3gSfQQERXf9pr+M0MMtyCH94J91YfnTshniKQto8mCp18OplTig9mbhpVZUs82CbWtLyy5Qq3LKRKY4XPyuVvPrEL8Rn+M3oJFVjiHuS55H0/N706IafpHLTHZ6twOeZ0Y1I0GwE9amIfaVzj3aXTonwU6tFLvyJZfsBpSqwYqbb5cjM4mVk3Q0GXY9gWe5mHMCm47elaVdnPHk7y+dsMdvsfFkm48kX8Lc0P9Yl+yO6bA0JMqvSN9AK9KZiiPafLfr/AS7Pa0bjjWl17h+8/2UQQm6SmU4bYGQy5Au9HjRYYsFDujOnVDuD9ziZyc/BUU4gTyVHnc0cml7DeTmbZAkVeYtuUcZ0DOavDMKSn0dqp7zIB6wR4L3B2R+2gv0INRMyBEC25HrmmaKIFgz63KelblqOL5F6d+yysypFACa1GCZ0B4NPWuExZIHzbz9X6qWZgLe7dHW+WAAHYWor1c63zhSi2Xt2r6BkYrBAMlBHTzKfZVf6ZipATCIjUJWxawVDnF4MGwhyLxLGdmFIeFjQFkSgx2DL8EvQBsvTssbjThRV7119JjBjBuCGJVEllxWLVZWax0qs7HCTao7/hyyzeps/jbwQHcRu5RctdKzZ7q1O+f9pTzIrF3LIyDBdKH/RjGf9hJebKbDjRrFQpKlWXKy4KEy6W7CB3II3Km6SIIdiCoDkqyifDNeBDURNIDQhL1b29IGXbqLtLzlNme+NSJ/uG3p5GDfZbp1E1AUhc613lvuIXT7jQKyN7aj3loBi0Fqpq08TU2ls/7Dykboxh3e/s36qbjTPw0qqVs8fFrn/f6byTxEukON5UDmyvoMmpI/YY/+9Yft1KAoJPyY25wz2oSSfNb7sIN2bbo3C3AsDmyZ6EKBJcADtIplNk7ucwxIwloFfz5I0IlQ3v9EgcwOEkOXwfj7wCSuQRO3vm6/Y6MGUXmoJhGRLHBQzkWG1IkUiuxG+Gwd/gg/FtmQDxiO4QtFjIiUxAUgdZWUevBBCI+n8+/Qya1hhCoyVaj8jSuVeNXrhlXjvUd4Lp8ZmwFWUNimoVH4zeVMac2jqC9ygK+2p6bjGgl0DNfVvBIyGDIUwTdlVPLMNuoF+SxyfuWMJUnaPUCWtGO4xbWX5UIJVokAJrJdLAWWpNRQ53jALG3pwvOu1POUY2vc5adahzpLw2ljdq2xWLd06EEqepPepv+s4f7vlsTTuk2pDr7hLjTSSbMEgf9v177hvkLpg5M+oFYD0IGqdI3zev6sCuGIMfErDBrpHolS1fr5IUAs6HinXq/9/+2dadV7MxM1N9Jo+X4r4z9w1vYSQgUzlBue1LZAoTqoB/SxE= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SEYPR02MB6014.apcprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(52116014)(376014)(1800799024)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GCUIbfRtG5glrvxjHWd5Y0sCCx+s2BzSU2YMnrISszv2Goe2A1gRe4qdP1y495XNLd4dkYzh1Dve9mkLC9KgBVcD0PiK6kpE/tdiW2sepEbBZs0iYiPKiR7C2z6Mm8a6+CCp/tESSdFVSK5ufWUXjz1uBEb4Zk0s/t+7jCr6trRQuXrdj9mN8hDvxRN8x6+tdQknOQHB8CECs3duF7CoSE9NPlyQiPlpxdC7HPOT1pilLmb6ZbpbhD8cm64zKzHXg8OOpnSTBbIBMMm6LafjYlliKo1FFb+ag4MDMkHeXyHov/dd47J16/c1dD3O8+N3lA2754OWjWYOEK1nEt7tViRVl7ECNPe83TktPytWveWIBgs7K6nSqgvJJ6bOM2MlJOoNOxaae7nZJwLLeaWb1tP/pKGZXYbs5njoHXO47Q2bzPwUpomdGBdhBfbRaWQ8zSkTmCiO4V0LoQmU2JI2PNJkzGRSSkfBFvxCxQ0WwnpTgSXkzPV/MpZQitK+49HCIU3YtjPFi3ROYbPeyoOu4dKhSU7XyXV/FtsPOenmnmcHBsazaFzvsjiTzBlOvHz3oTExYvW6FdtVSjxLHkZiWHew3ag+dwHo9k0CuCKSfNZfsS3tdhJiJAPpT0ATK/lyV6nKAczLoptTcqEKLlFpg2GQ+rkzy6Dp3aXMZ77M9ayFgS7SAqR/VQyqwFfKjtcZgalD+nFOQ8fmhKr8mpNZ5L7WHjnNtT7FYHkoJ/o3wdlJrGT8tbluyglDjsJia0SSsaWBiwGV0iPk+f15St/sC/VsMXihwHxZY1akbRQd6fQ2tmU8GvLO5Sae8BstS8WxriqyLAmSgLql/n20CGZVAFiufRBCY1zy6gdTs1gC+LmF2DKSMKXP2ETv5I2lp5lwKYPSAz5nJ+xUzA4w2f9yJDpVP5Q1QozE/sIAlNmEwOoA+6cz63MJhIArho8RtnG/FBHA0xl1/pEF8Jcz/3a/WnH23vzuYZaK63+ffJyu9RTbsRsJDF0Lxt7EDcJYVo6aHymdq4hZCAz7RWjdJ16vklUFuGnBkYT+zSVYRYV20bEt9O6GxO7OJr1mJGX7d481waZFh9WEU5eVdjEN3PqWGFLIaHms0GHUNamyeXcrg4/OFh+5Zb40m7yW12XNnN8EGefm7s47opZHl7/tBM5vSBM75UAnrru8cE8OBzf6wEOVgzibXvnYX5nJRVvFNdmQysFm+VgvL5MbPOsuMOUp2onCjb6EYd22wSXqv+D4DZcMewq3TRlf5Zx6/lrVLl/vEtGc2ITpRso1Y3WuSJuaHolACmwQ9fUARyqKcRQFZz92ncbxe0CBimoUvvfDyA0hd49OwX0pKDabGmN9o+UNv8hPOPyji9nKsRA9O0Brft10iX14Kmj3bFPSzWsg0mjRX5cv9vLf6yDLpJUbRACmHyZNJ7C/BYKCKf2jkjwqOKPTyjJTYkeR/DofO59TiAZ1pwYd0ZK3mBskgVFvCF2j0gBXje8Kj1ZnoaqIRi9dbgKL1Anepf6spQV8UM+XDXuTq7VKrjeyp63Yl88DcLmKgX31QNIGiQtU+HsK/8QQ2mKm5QQ3EQUL+elDS+LIDiuL X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1a590c74-e3c6-4c1a-ec27-08dcf812d669 X-MS-Exchange-CrossTenant-AuthSource: SEYPR02MB6014.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Oct 2024 12:11:37.1829 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f1905eb1-c353-41c5-9516-62b4a54b5ee6 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: W02+kbBVSKfXXCCxeRIXRs0ECl/jUiDa0xTbp3O5rV5/xAFjCAUXH3lqKaiwZFYg3bWOEBAkszUVPN8VgMxxAg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEZPR02MB7326 X-Headers-End: 1t5l4i-0007Qb-PE Subject: [f2fs-dev] [RFC PATCH 08/24] tests: prepare helper scripts for testcases X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sheng Yong via Linux-f2fs-devel From: Sheng Yong Reply-To: Sheng Yong Cc: linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net This patch addes helper scripts for auto testcases, and testcases of fsck will be submitted in the following commits. The basic idea of these testcases are: 1. create f2fs image 2. corrupt the image by inject specific fields 3. fsck fixes the corrupted image 4. verify fsck output with expected message The helper scripts include: * test_config.in: is used to generate the basic configurations of all testcases. * runtests.in: is used to generate `runtests'. * filter.sed: is used to remove unnecessary messages and cleanup arbitrary values. * helpers: provides helper functions The usage of runtests: * run all testcases: runtests * run one testcase: runtests * cleanup previous results: runtests clean Each testcase should have a sub-directory, where three files should be included: * README: describe information of the testcase * script: testcase itself * expect.in: expected output message an optional file is: * img.tar.gz: if some scenario is too complex to create by script, the gz file could be prepared in advance, and the operations of how to create the image should be described in README New files are generated in the testcase directory after test: * log: output in detail * expect: derived from expect.in * out: output that will be compared with expect * PASS: testcase is passed * FAIL: testcase is failed Signed-off-by: Sheng Yong --- .gitignore | 13 ++++ Makefile.am | 2 +- configure.ac | 1 + tests/Makefile.am | 28 ++++++++ tests/filter.sed | 60 +++++++++++++++++ tests/helpers | 157 +++++++++++++++++++++++++++++++++++++++++++ tests/runtests.in | 46 +++++++++++++ tests/test_config.in | 47 +++++++++++++ 8 files changed, 353 insertions(+), 1 deletion(-) create mode 100644 tests/Makefile.am create mode 100644 tests/filter.sed create mode 100644 tests/helpers create mode 100644 tests/runtests.in create mode 100644 tests/test_config.in diff --git a/.gitignore b/.gitignore index 49809446793d..c824e8f8091f 100644 --- a/.gitignore +++ b/.gitignore @@ -46,6 +46,8 @@ stamp-h1 /mkfs/mkfs.f2fs /fsck/fsck.f2fs +/fsck/dump.f2fs +/fsck/inject.f2fs /tools/fibmap.f2fs /tools/parse.f2fs /tools/f2fscrypt @@ -54,3 +56,14 @@ stamp-h1 # cscope files cscope.* ncscope.* + +# testcase files +tests/*/log +tests/*/out +tests/*/PASS +tests/*/FAIL +tests/*/expect +tests/meta.img +tests/data.img +tests/runtests +tests/test_config diff --git a/Makefile.am b/Makefile.am index d2921d626e48..0c9ec66d02b6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,4 +2,4 @@ ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = man lib mkfs fsck tools +SUBDIRS = man lib mkfs fsck tools tests diff --git a/configure.ac b/configure.ac index 2053a65bbb36..364dd162e7c0 100644 --- a/configure.ac +++ b/configure.ac @@ -263,6 +263,7 @@ AC_CONFIG_FILES([ fsck/Makefile tools/Makefile tools/f2fs_io/Makefile + tests/Makefile ]) AC_CHECK_MEMBER([struct blk_zone.capacity], diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 000000000000..670cd373c628 --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,28 @@ +## Makefile.am + +noinst_SCRIPTS = test_config runtests +CLEANFILES = $(bin_SCRIPTS) +EXTRA_DIST = test_config.in runtests.in + +test_config: $(srcdir)/test_config.in + @echo "Creating test_config script..." + @[ -f test_config ] && chmod u+w test_config || true + @echo "#!/bin/bash" > test_config + @echo "" >> test_config + @echo "TOPDIR=@top_srcdir@" >> test_config + @cat $(srcdir)/test_config.in >> test_config + @chmod +x-w test_config + +runtests: $(srcdir)/runtests.in + @echo "Creating runtests script..." + @[ -f runtests ] && chmod u+w runtests || true + @echo "#!/bin/bash" > runtests + @echo "" >> runtests + @echo "SRCDIR=@srcdir@" >> runtests + @cat $(srcdir)/runtests.in >> runtests + @chmod +x-w runtests + +clean-local: + @[ -f runtests ] && runtests clean || true + @rm -f runtests test_config + diff --git a/tests/filter.sed b/tests/filter.sed new file mode 100644 index 000000000000..ea69c8eb65a4 --- /dev/null +++ b/tests/filter.sed @@ -0,0 +1,60 @@ +## f2fs info that could be ignored + +/^Info: No Kernel Check/d +/^Info: not exist \/proc\/version!/d +/^Info: version timestamp/d +/be careful to overwrite a mounted loopback file/d +/^Info: MKFS version/,+1d +/^Info: FSCK version/,+2d +/^Info: superblock encrypt level/d +/^Info: total FS sectors/d +/^Done: [0-9\.]\+ secs/d +/^Info: total FS sectors/d +/^\[FSCK\] Max image size/d +/^Info: flush_journal_entries/d +/^Info: Segments per section =/d +/^Info: Sections per zone =/d +/^Info: Device\[[0-9]\]/d +/^Info: CKPT version =/d +/^Info: superblock features =/d +/^Info: flush_journal_entries/d +/^Info: Corrupted valid nat_bits in checkpoint/d +/^Info: Checked valid nat_bits in checkpoint/d + +## fsck messages should be kept, but some numeric is arbitrary and should +## be removed + +# e.g [ASSERT] (is_valid_ssa_data_blk: 340) => [ASSERT] (is_valid_ssa_data_blk: x) +s/\(\[ASSERT\] ([a-zA-Z_][0-9a-zA-Z_]\+:\s*\)[0-9]\+)/\1x)/g +# e.g [FIX] (nullify_nat_entry:3274) => [FIX] (nullify_nat_entry:x) +s/\(\[FIX\] ([a-zA-Z_][0-9a-zA-Z_]\+:\s*\)[0-9]\+)/\1x)/g +# e.g [fsck_chk_quota_files:2242] => [fsck_chk_quota_files:x] +s/^\(\[[a-zA-Z_][0-9a-zA-Z_]\+:\s*\)[0-9]\+\]/\1x\]/g +# e.g Info: Duplicate valid checkpoint to mirror position 270848 -> 270336 => +# Info: Duplicate valid checkpoint to mirror position x -> x +s/\(Info: Duplicate valid checkpoint to mirror position \)[0-9]\+\( -> \)[0-9]\+/\1x\2x/g +# e.g Info: checkpoint state = 1c5 : trimmed nat_bits crc compacted_summary unmount => +# Info: checkpoint state = x : nat_bits crc compacted_summary unmount +s/\(Info: checkpoint state = \)[0-9a-f]\+ :/\1x :/g +s/\(Info: checkpoint state = x :.*\) trimmed\(.*$\)/\1\2/g +# e.g Info: write_checkpoint() cur_cp:1 => Info: write_checkpoint() cur_cp:x +s/\(Info: write_checkpoint() cur_cp:\)[0-1]/\1x/g +# e.g Info: fix_checkpoint() cur_cp:1 => Info: fix_checkpoint() cur_cp:x +s/\(Info: fix_checkpoint() cur_cp:\)[0-1]/\1x/g +# e.g [FSCK] Unreachable nat entries [Fail] [0x1] => +# [FSCK] Unreachable nat entries [Fail] [x] +# e.g [FSCK] Unreachable nat entries [Ok...] [0x0] => +# [FSCK] Unreachable nat entries [Ok...] [x] => +s/\(\[FSCK\] Unreachable nat entries\s*\[\(Ok\.\.\|Fail\)\] \[\)0x[0-9a-f]\+\]/\1x\]/g +s/\(\[FSCK\] Hard link checking for regular file\s*\[\(Ok\.\.\|Fail\)\] \[\)0x[0-9a-f]\+\]/\1x\]/g +# e.g [FSCK] valid_block_count matching with CP [Ok..] [0x10] => +# [FSCK] valid_block_count matching with CP [Ok..] [x] +# e.g [FSCK] valid_block_count matching with CP [Fail] [0x10, 0x9] => +# [FSCK] valid_block_count matching with CP [Fail] [x, x] +s/\(\[FSCK\] valid_block_count matching with CP\s*\[\(Ok\.\.\|Fail\)\] \[\)[0-9a-fx, ]\+\]/\1x\]/g +s/\(\[FSCK\] valid_node_count matching with CP (de lookup)\s*\[\(Ok\.\.\|Fail\)\] \[\)[0-9a-fx, ]\+\]/\1x\]/g +s/\(\[FSCK\] valid_node_count matching with CP (nat lookup)\s*\[\(Ok\.\.\|Fail\)\] \[\)[0-9a-fx, ]\+\]/\1x\]/g +s/\(\[FSCK\] valid_inode_count matched with CP\s*\[\(Ok\.\.\|Fail\)\] \[\)[0-9a-fx, ]\+\]/\1x\]/g +s/\(\[FSCK\] free segment_count matched with CP\s*\[\(Ok\.\.\|Fail\)\] \[\)[0-9a-fx, ]\+\]/\1x\]/g + +## inject info is verifed by fsck result, so it also could be removed diff --git a/tests/helpers b/tests/helpers new file mode 100644 index 000000000000..312ecb9c8e99 --- /dev/null +++ b/tests/helpers @@ -0,0 +1,157 @@ +#!/bin/sh + +# If multiple devices are used, META is the first device and DATA is the +# second device. If there is only one device, META is used only. +META=`realpath $TOPDIR/tests/meta.img` +DATA=`realpath $TOPDIR/tests/data.img` +OUT=$TESTDIR/out +EXP=$TESTDIR/expect +LOG=$TESTDIR/log + +# $1: pre: cleanup previous test result +# post: remove image files +cleanup() { + if [ x"$1" = x"pre" ]; then + rm $TESTDIR/PASS $TESTDIR/FAIL $TESTDIR/expect $OUT $LOG + fi + + if [ x"$1" = x"pre" ] || [ x"$1" = x"post" ]; then + echo "rm $META $DATA" + fi +} + +# check test result +check_result() { + local NAME=`basename $TESTDIR` + + if [ ! -e $EXP ]; then + cp "$EXP".in $EXP + fi + sed -f $FILTER -i $OUT + cmp -s $OUT $EXP + if [ x"$?" = x"0" ]; then + echo "$NAME: $DESC: pass" + touch $TESTDIR/PASS + else + echo "$NAME: $DESC: failed" + echo "diff $EXP $OUT" + diff $EXP $OUT > $TESTDIR/FAIL + exit + fi +} + +# $1: path of image file +# $2: size in MB +create_img_file() { + truncate -s $2"M" $1 +} + +make_f2fs() { + local metasize=10 + local datasize=118 + + if [ $SEGS_PER_SEC -gt 1 ]; then + metasize=$((3 * ($SEGS_PER_SEC * 2))) + datasize=$((11* ($SEGS_PER_SEC * 2))) + MKFS_OPTS="$MKFS_OPTS -s $SEGS_PER_SEC" + fi + if [ $MULTIDEV -eq 1 ]; then + create_img_file $META $metasize + create_img_file $DATA $datasize + MKFS_OPTS="$MKFS_OPTS -c $DATA" + else + create_img_file $META $(($metasize + $datasize)) + fi + + $MKFS $MKFS_OPTS $META + $DUMP -d 1 $META + + return $? +} + +safe_mount() { + local dev="" + + # If multiple devices are used, DATA should be associated to a + # loop device in advance. + # dump/fsck will check the path of the the DATA device, to make + # them happy, replace devs[1].path with the loop device before + # mount, and restore it after umount. + if [ $MULTIDEV -eq 1 ]; then + dev=`losetup -f` + losetup $dev $DATA + if [ $? -ne 0 ]; then + echo "cannot setup loop dev: losetup $dev $DATA" + return -1 + fi + $INJECT --sb 1 --mb devs.path --idx 1 --str $dev $META + fi + + mount -t f2fs $* + return $? +} + +#1: mntpoint +safe_umount() { + local max_retry=10 + local dev="" + local i=0 + + umount $1 + while [ $? -ne 0 ]; do + i=$(($i + 1)) + if [ $i -gt $max_retry ]; then + return 1 + fi + echo "cannot umount f2fs image, retry: $i" + sleep 1 + umount $1 + done + + dev=`losetup -j $DATA | cut -d ":" -f 1` + if [ x"$dev" != x"" ]; then + losetup -d $dev + # restore devs[1].path from $dev to $DATA + $INJECT --sb 1 --mb devs.path --idx 1 --str $DATA $META + fi + return 0 +} + +# $1: member of sb +get_sb() { + local sb_cp="`$DUMP $DUMP_OPT -d 1 $META`" + local cut_here=`echo "$sb_cp" | awk '/^\| Checkpoint/ {print NR}'` + local sb="`echo "$sb_cp" | head -n $(($cut_here - 2))`" + local val=`echo "$sb" | grep "^$1\s" | sed "s/^$1\s*\[0x\s*[0-9a-f]\+ : \([0-9]*\)\]/\1/g"` + echo $val +} + +# $1: member of cp +get_cp() { + local sb_cp="`$DUMP $DUMP_OPT -d 1 $META`" + local cut_here=`echo "$sb_cp" | awk '/^\| Checkpoint/ {print NR}'` + local cp="`echo "$sb_cp" | tail -n +$(($cut_here - 2))`" + local val=`echo "$cp" | grep "^$1\s" | sed "s/^$1\s*\[0x\s*[0-9a-f]\+ : \([0-9]*\)\]/\1/g"` + echo $val +} + +# $1: blkaddr +get_segno() { + local main_blkaddr=`get_sb main_blkaddr` + local log_blks_per_seg=`get_sb log_blocks_per_seg` + echo $((($1 - $main_blkaddr) >> $log_blks_per_seg)) +} + +# $1: segno +start_block() { + local main_blkaddr=`get_sb main_blkaddr` + local log_blks_per_seg=`get_sb log_blocks_per_seg` + echo $(($main_blkaddr + ($1 << $log_blks_per_seg))) +} + +# $1: blkaddr +offset_in_seg() { + local main_blkaddr=`get_sb main_blkaddr` + local log_blks_per_seg=`get_sb log_blocks_per_seg` + echo $((($1 - $main_blkaddr) % (1 << $log_blks_per_seg))) +} diff --git a/tests/runtests.in b/tests/runtests.in new file mode 100644 index 000000000000..d49634752d42 --- /dev/null +++ b/tests/runtests.in @@ -0,0 +1,46 @@ +#!/bin/sh +# +# run testcases +# +# run all testcases: +# runtests +# +# run one testcase: +# runtests +# +# cleanup: +# runtests clean +# + +# clean temporary files +if [ x"$1" = x"clean" ]; then + find $SRCDIR \( -name FAIL -o -name PASS -o -name expect -o -name log -o -name out -o -name meta.img -o -name data.img \) -exec rm -f {} \; + exit +fi + +TEST_CONFIG=$SRCDIR/test_config +. $TEST_CONFIG + +# $1: path of testcase path +run_one_test() { + local subdir=`realpath $1` + local name=`basename $subdir` + echo "Run testcase: $name ..." + TESTDIR=$subdir + . $subdir/script + echo "" +} + +# run one testcase +# $1: testcase path +if [ x"$1" != x"" ]; then + run_one_test $1 + exit +fi + +# run all testcases +TESTS=`find ./ -type f -name script` +for testcase in ${TESTS[@]}; do + subdir=`dirname $testcase` + run_one_test $subdir +done diff --git a/tests/test_config.in b/tests/test_config.in new file mode 100644 index 000000000000..b4249dc26179 --- /dev/null +++ b/tests/test_config.in @@ -0,0 +1,47 @@ +#!/bin/sh +# +# Test configuration +# + +check_executable() { + file $1 | grep ELF > /dev/null + [ $? -ne 0 ] && { echo "ERROR: $1 not ELF"; exit; } +} + +check_diff() { + diff $1 $2 > /dev/null + [ $? -ne 0 ] && { echo "WARNING: $1 and $2 differ"; } +} + +# path of tools +MKFS="$TOPDIR/mkfs/mkfs.f2fs" +FSCK="$TOPDIR/fsck/fsck.f2fs" +DUMP="$TOPDIR/fsck/dump.f2fs" +INJECT="$TOPDIR/fsck/inject.f2fs" +F2FS_IO="$TOPDIR/tools/f2fs_io/f2fs_io" +FILTER="$TOPDIR/tests/filter.sed" +[ ! -e $MKFS ] && { echo "$MKFS not exist"; exit; } +[ ! -e $FSCK ] && { echo "$FSCK not exist"; exit; } +check_executable $FSCK +[ ! -e $DUMP ] && { cp $FSCK $DUMP; } +check_executable $DUMP +check_diff $FSCK $DUMP +[ ! -e $F2FS_IO ] && { echo "$F2FS_IO not exist"; exit; } +[ ! -e $INJECT ] && { cp $FSCK $INJECT; } +check_executable $INJECT +check_diff $FSCK $INJECT + +# config of mkfs +F2FS_FEATURES="encrypt,extra_attr,compression" +MKFS_OPTS="-O $F2FS_FEATURES -f" +MULTIDEV=0 +SEGS_PER_SEC=1 + +# config of fsck +FSCK_OPTS="--no-kernel-check -N" + +# config of dump +DUMP_OPTS="-N" + +# config of mount +MNT_OPTS=""