Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2605861ybp; Thu, 10 Oct 2019 09:46:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqwFJejPSfF7Qcw0jutyY9C+6kDWo0pnkj+K73ZFjeRVJ+zwlK+XLB1TK/HJseNM+Diei3sA X-Received: by 2002:aa7:d04b:: with SMTP id n11mr9284690edo.104.1570726005900; Thu, 10 Oct 2019 09:46:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570726005; cv=none; d=google.com; s=arc-20160816; b=rHp7luCLZyfCoqQJmM7ThA9r3F0RvJtZ0Iv0tjt7xZmSqnLitLLQDPyTSbWlNVgkD9 AG8ZdrWWxsz+wkdOp9D9qG21vsMpsO10apu/tyPIXiPi0WmK+a1EAIFghLhqROdiNAOV riQFS0cGhIwc0O4LmzdQnrYdoPY/xYIlnvyRIsykuKpNyWrLQstJrGBSItt7f6LanPJZ 1RD9smQO4/a6XDFOU3ELP+e0pZmDRtiyJVvKn07fgX5Vdbud5yyBj/aqUNX2mDu0w06A cclOBaAGEzNRQtVoOg5x8wypSN3YMVzDSdxRQP3Y3doezw7Ye9tADmyyb7FXTg3LPhik 71UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=nj4bBE3BvV1UZmyzEaSgOKADKX40E4zF9+r4XI1/Wek=; b=ekqeMSEQCPZKTLDHjS/S718ki3Y7A7Ao50eMF80ill/opkwHoyX5zUb+vCxZ6a+qED EGMgxQU6ysLoO3cIWz4tzwRbuFd3JeSq7BPZs/46dT3tn77yThfyS82jZQRPtcGFjzEa IArXmrPvrp6ghvt2nJDm2UlBNy5XQu1f7ueom7GVZI++Opb+Lhk7A8TZPZlz5j4IQP9m RBqhrc9a4BuAI5W9Hc+99UhgC1I/kSOA6F8ljk1UhxVJsb8g3EWt5CsCFnxkn7Kq9zL6 MsYUmhIQ/4DWXxfIpYiADH8abY5AQrfxD24iDfvZciBOnD+eouRfWmHtgktj7gA1oL+L Od7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Os7EBDKX; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z55si3986839edb.41.2019.10.10.09.46.11; Thu, 10 Oct 2019 09:46:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Os7EBDKX; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726157AbfJJQps (ORCPT + 99 others); Thu, 10 Oct 2019 12:45:48 -0400 Received: from mail-qk1-f194.google.com ([209.85.222.194]:45084 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726038AbfJJQps (ORCPT ); Thu, 10 Oct 2019 12:45:48 -0400 Received: by mail-qk1-f194.google.com with SMTP id z67so6176941qkb.12 for ; Thu, 10 Oct 2019 09:45:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=nj4bBE3BvV1UZmyzEaSgOKADKX40E4zF9+r4XI1/Wek=; b=Os7EBDKXyoW+fAsiMGwPkWaJKN2cj791yXW0+gXvda4+hk83J5H5/ZcsiVWlPHzE8u OuR5IUq73yjlijc8EoLnLvfYRkNyosO8FqSmPCZiAE4m+JEk9UPy9AFxxgJBv/DyrsgU S/GAT1PB+FmZYVCC/JzXR4KeCc+N311tjGLqKjIKIUhdZDOM5iInPA1pPVsqCkUM6O6v xBEdrwKc/YLkutH+oTv+8w8vMEpeJPVJP61ws38FeL7W/NnruWKDjRvNw1nt/pCzg5WQ JGAFxKJeqGoLmTEFd1x8kPodcFsonn9FWsNvbzvbwNtkJgNy/woTYAZBPSLHiRE275jZ Bqzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=nj4bBE3BvV1UZmyzEaSgOKADKX40E4zF9+r4XI1/Wek=; b=fjSTahGUSMQ4Vi53QbqXfnHVwftHaQTq/BFj+HIw7F3qZcGzvEDp8twfZsxbcpR1C+ N+1+vG7i1psPnfcjOT6pJZQf2MAA+AXeEFeUgoWj0w9t+j3poCUBpM54aZhXA05gNv8n nKruWifqM58l2gKo9IOhg8wyS9Mj7r0kuifSctXCU/e3CgJXOdR/IUVG3qEZS/2Dw4Nh W+q3epX83CVXZsjsjVcnTfcp3FNxGy6BVaUmcaaaM/wlEq9NFQit+a40+MFDj22OwR0w eaH7gbpRKKPNFxZ09VMRW8fp2Xf/jg9xAmHQ3xMEzkRz48giXAah9M9iqT/hnBHe7EEy EQDA== X-Gm-Message-State: APjAAAX3Y04K4POBW8QkiyMBeP3clHRZyuDBSfHcHBT5ofjFc2BHgLsM Rn/nRvHoPtvv/t1GM1fNCp/851l0SbxTTFQxup7h X-Received: by 2002:a05:620a:136e:: with SMTP id d14mr10633675qkl.393.1570725947085; Thu, 10 Oct 2019 09:45:47 -0700 (PDT) MIME-Version: 1.0 References: <20191010023931.230475-1-yzaikin@google.com> In-Reply-To: From: Iurii Zaikin Date: Thu, 10 Oct 2019 09:45:09 -0700 Message-ID: Subject: Re: [PATCH linux-kselftest/test v2] ext4: add kunit test for decoding extended timestamps To: "Bird, Timothy" Cc: "open list:KERNEL SELFTEST FRAMEWORK" , linux-ext4@vger.kernel.org, Shuah Khan , "Theodore Ts'o" , adilger.kernel@dilger.ca, kunit-dev@googlegroups.com, Brendan Higgins Content-Type: text/plain; charset="UTF-8" Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Wed, Oct 9, 2019 at 8:47 PM wrote: > > > > -----Original Message----- > > From Iurii Zaikin on Wednesday, October 09, 2019 4:40 PM > > > > KUnit tests for decoding extended 64 bit timestamps. > > > > Signed-off-by: Iurii Zaikin > > --- > > fs/ext4/Kconfig | 12 +++ > > fs/ext4/Makefile | 1 + > > fs/ext4/inode-test.c | 221 > > +++++++++++++++++++++++++++++++++++++++++++ > > 3 files changed, 234 insertions(+) > > create mode 100644 fs/ext4/inode-test.c > > > > diff --git a/fs/ext4/Kconfig b/fs/ext4/Kconfig > > index cbb5ca830e57..cb0b52753674 100644 > > --- a/fs/ext4/Kconfig > > +++ b/fs/ext4/Kconfig > > @@ -106,3 +106,15 @@ config EXT4_DEBUG > > If you select Y here, then you will be able to turn on debugging > > with a command such as: > > echo 1 > /sys/module/ext4/parameters/mballoc_debug > > + > > +config EXT4_KUNIT_TESTS > > + bool "KUnit test for ext4 inode" > > + depends on EXT4_FS > > + depends on KUNIT > > + help > > + This builds the ext4 inode sysctl unit test, which runs on boot. > > + Tests the encoding correctness of ext4 inode. > > + For more information on KUnit and unit tests in general please refer > > + to the KUnit documentation in Documentation/dev-tools/kunit/. > > + > > + If unsure, say N. > > diff --git a/fs/ext4/Makefile b/fs/ext4/Makefile > > index b17ddc229ac5..a0588fd2eea6 100644 > > --- a/fs/ext4/Makefile > > +++ b/fs/ext4/Makefile > > @@ -13,4 +13,5 @@ ext4-y := balloc.o bitmap.o block_validity.o dir.o > > ext4_jbd2.o extents.o \ > > > > ext4-$(CONFIG_EXT4_FS_POSIX_ACL) += acl.o > > ext4-$(CONFIG_EXT4_FS_SECURITY) += xattr_security.o > > +ext4-$(CONFIG_EXT4_KUNIT_TESTS) += inode-test.o > > ext4-$(CONFIG_FS_VERITY) += verity.o > > diff --git a/fs/ext4/inode-test.c b/fs/ext4/inode-test.c > > new file mode 100644 > > index 000000000000..43bc6cb547cd > > --- /dev/null > > +++ b/fs/ext4/inode-test.c > > @@ -0,0 +1,221 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* > > + * KUnit test of ext4 inode that verify the seconds part of [a/c/m] > > + * timestamps in ext4 inode structs are decoded correctly. > > + * These tests are derived from the table under > > + * Documentation/filesystems/ext4/inodes.rst Inode Timestamps > > + */ > > + > > +#include > > +#include > > +#include > > + > > +#include "ext4.h" > > + > > +/* binary: 00000000 00000000 00000000 00000000 */ > > +#define LOWER_MSB_0 0L > > +/* binary: 01111111 11111111 11111111 11111111 */ > > +#define UPPER_MSB_0 0x7fffffffL > > +/* binary: 10000000 00000000 00000000 00000000 */ > > +#define LOWER_MSB_1 (-0x80000000L) > > +/* binary: 11111111 11111111 11111111 11111111 */ > > +#define UPPER_MSB_1 (-1L) > > +/* binary: 00111111 11111111 11111111 11111111 */ > > +#define MAX_NANOSECONDS ((1L << 30) - 1) > > + > > +#define CASE_NAME_FORMAT "%s: msb:%x lower_bound:%x extra_bits: > > %x" > > + > > +struct timestamp_expectation { > > + const char *test_case_name; > > + struct timespec64 expected; > > + u32 extra_bits; > > + bool msb_set; > > + bool lower_bound; > > +}; > > + > > +static time64_t get_32bit_time(const struct timestamp_expectation * const > > test) > > +{ > > + if (test->msb_set) { > > + if (test->lower_bound) > > + return LOWER_MSB_1; > > + > > + return UPPER_MSB_1; > > + } > > + > > + if (test->lower_bound) > > + return LOWER_MSB_0; > > + return UPPER_MSB_0; > > +} > > + > > + > > +static void inode_test_xtimestamp_decoding(struct kunit *test) > > +{ > > + const struct timestamp_expectation test_data[] = { > > + { > > + .test_case_name = "1901-12-13", > > + .msb_set = true, > > + .lower_bound = true, > > + .extra_bits = 0, > > + .expected = {.tv_sec = -0x80000000LL, .tv_nsec = 0L}, > > + }, > > + > > + { > > + .test_case_name = "1969-12-31", > > + .msb_set = true, > > + .lower_bound = false, > > + .extra_bits = 0, > > + .expected = {.tv_sec = -1LL, .tv_nsec = 0L}, > > + }, > > + > > + { > > + .test_case_name = "1970-01-01", > > + .msb_set = false, > > + .lower_bound = true, > > + .extra_bits = 0, > > + .expected = {0LL, 0L}, > > + }, > > + > > + { > > + .test_case_name = "2038-01-19", > > + .msb_set = false, > > + .lower_bound = false, > > + .extra_bits = 0, > > + .expected = {.tv_sec = 0x7fffffffLL, .tv_nsec = 0L}, > > + }, > > + > > + { > > + .test_case_name = "2038-01-19", > It's quite handy if testcase names can be unique, and describe what it is they are testing. > > If someone unfamiliar with this test looks at the results, it's nice if they can > intuit what it was that went wrong, based on the test case name. > > IMHO these names are too short and not descriptive enough. The test cases are pretty much 1:1 to the examples table referenced at the top comment of the file. Would it help if I move the reference comment closer to the test case definition or would you like the test name to have a reference to a table entry encoded into it? > -- Tim > > > > + .msb_set = true, > > + .lower_bound = true, > > + .extra_bits = 1, > > + .expected = {.tv_sec = 0x80000000LL, .tv_nsec = 0L}, > > + }, > > + > > + { > > + .test_case_name = "2106-02-07", > > + .msb_set = true, > > + .lower_bound = false, > > + .extra_bits = 1, > > + .expected = {.tv_sec = 0xffffffffLL, .tv_nsec = 0L}, > > + }, > > + > > + { > > + .test_case_name = "2106-02-07", > > + .msb_set = false, > > + .lower_bound = true, > > + .extra_bits = 1, > > + .expected = {.tv_sec = 0x100000000LL, .tv_nsec = 0L}, > > + }, > > + > > + { > > + .test_case_name = "2174-02-25", > > + .msb_set = false, > > + .lower_bound = false, > > + .extra_bits = 1, > > + .expected = {.tv_sec = 0x17fffffffLL, .tv_nsec = 0L}, > > + }, > > + > > + { > > + .test_case_name = "2174-02-25", > > + .msb_set = true, > > + .lower_bound = true, > > + .extra_bits = 2, > > + .expected = {.tv_sec = 0x180000000LL, .tv_nsec = 0L}, > > + }, > > + > > + { > > + .test_case_name = "2242-03-16", > > + .msb_set = true, > > + .lower_bound = false, > > + .extra_bits = 2, > > + .expected = {.tv_sec = 0x1ffffffffLL, .tv_nsec = 0L}, > > + }, > > + > > + { > > + .test_case_name = "2242-03-16", > > + .msb_set = false, > > + .lower_bound = true, > > + .extra_bits = 2, > > + .expected = {.tv_sec = 0x200000000LL, .tv_nsec = 0L}, > > + }, > > + > > + { > > + .test_case_name = " 2310-04-04", > > + .msb_set = false, > > + .lower_bound = false, > > + .extra_bits = 2, > > + .expected = {.tv_sec = 0x27fffffffLL, .tv_nsec = 0L}, > > + }, > > + > > + { > > + .test_case_name = " 2310-04-04 00:00:00.1", > > + .msb_set = false, > > + .lower_bound = false, > > + .extra_bits = 6, > > + .expected = {.tv_sec = 0x27fffffffLL, .tv_nsec = 1L}, > > + }, > > + > > + { > > + .test_case_name = "2378-04-22 > > 00:00:00.MAX_NSEC", > > + .msb_set = false, > > + .lower_bound = true, > > + .extra_bits = 0xFFFFFFFF, > > + .expected = {.tv_sec = 0x300000000LL, > > + .tv_nsec = MAX_NANOSECONDS}, > > + }, > > + > > + { > > + .test_case_name = "2378-04-22", > > + .msb_set = false, > > + .lower_bound = true, > > + .extra_bits = 3, > > + .expected = {.tv_sec = 0x300000000LL, .tv_nsec = 0L}, > > + }, > > + > > + { > > + .test_case_name = "2446-05-10", > > + .msb_set = false, > > + .lower_bound = false, > > + .extra_bits = 3, > > + .expected = {.tv_sec = 0x37fffffffLL, .tv_nsec = 0L}, > > + } > > + }; > > + > > + struct timespec64 timestamp; > > + int i; > > + > > + for (i = 0; i < ARRAY_SIZE(test_data); ++i) { > > + timestamp.tv_sec = get_32bit_time(&test_data[i]); > > + ext4_decode_extra_time(×tamp, > > + cpu_to_le32(test_data[i].extra_bits)); > > + > > + KUNIT_EXPECT_EQ_MSG(test, > > + test_data[i].expected.tv_sec, > > + timestamp.tv_sec, > > + CASE_NAME_FORMAT, > > + test_data[i].test_case_name, > > + test_data[i].msb_set, > > + test_data[i].lower_bound, > > + test_data[i].extra_bits); > > + KUNIT_EXPECT_EQ_MSG(test, > > + test_data[i].expected.tv_nsec, > > + timestamp.tv_nsec, > > + CASE_NAME_FORMAT, > > + test_data[i].test_case_name, > > + test_data[i].msb_set, > > + test_data[i].lower_bound, > > + test_data[i].extra_bits); > > + } > > +} > > + > > +static struct kunit_case ext4_inode_test_cases[] = { > > + KUNIT_CASE(inode_test_xtimestamp_decoding), > > + {} > > +}; > > + > > +static struct kunit_suite ext4_inode_test_suite = { > > + .name = "ext4_inode_test", > > + .test_cases = ext4_inode_test_cases, > > +}; > > + > > +kunit_test_suite(ext4_inode_test_suite); > > -- > > 2.23.0.700.g56cf767bdb-goog