Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp709941ybp; Fri, 11 Oct 2019 03:08:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqzl/I9UG3LzcgMcTVkfcn1BSWsbSK4VkUVZ72EFwnAsTHVx6U4Yry24AYFUF0vyE5m/vMEf X-Received: by 2002:a05:6402:17a6:: with SMTP id j6mr12327513edy.99.1570788534012; Fri, 11 Oct 2019 03:08:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570788534; cv=none; d=google.com; s=arc-20160816; b=lZMNJ8E0hW1SQ/J/gDIpcqrXAnWmtfUdjgTFHCyFmVqTFOiCjwlkYPYC+UjU5HiNbr jxJxrAQKy0nfPTimbzxBxscfQ44iCWufuaxOGSjmSCEcAAPl4cwRLpt8oPEY86pE5hhB usdoD9aZmvDIc9198xxbr8hsxIZYKHRrDgY+FK5poFYzhFkof7DN3NgsoArvNRhZRWC+ DRerS/PDmLfnwedmFLjEQl5Q9+O0cPogCU1GN2uAYy2d74lGuRfxX3CZHJ8OPy1v2XBs uljRGNJ/ts41zUMy0GLdnbQBhkaYgo9LE9LS4Xq9eqzWqpSytLHxagx9SYvC+GePlRfS XQOA== 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=MNqtgthl8VyBRo/9SmMdv19JQkKzyWONQ2Spmwn+3yU=; b=oUC4IsN1AH4ljnF5twdr3DbyQZgFkqFoaI0FrlARqh2lScNCwKQu73fydOmpLxIkuP nNq9Ezjx2RYwmNrBrffSzXD0eBhogaWiyoXBwJIM2EqZx1i8DRmhGh4XZOdMmP98yMHS /P1ju6uTGcUVLe588nxNc0mkxh9cwu/1FmHQrIzeDX+IZ3RnUEnO/sV6Cl0smpepyJ+L AZNCZZQiEFpU35R0s9TDSczF/H2oBytr4nc6z6romm8OClPr3qfh/5vESIsQysMyp2N4 DwKXmiXCRiJeB7q0NMvfJHUOzIplDAjVYcBITUR1rQhzmTSgR8PqzjOpDirDKHr3U2dy fKRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=TpWNF5Fd; 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 l16si3404303ejq.188.2019.10.11.03.08.19; Fri, 11 Oct 2019 03:08:53 -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=TpWNF5Fd; 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 S1726808AbfJKKF4 (ORCPT + 99 others); Fri, 11 Oct 2019 06:05:56 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:38621 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726585AbfJKKF4 (ORCPT ); Fri, 11 Oct 2019 06:05:56 -0400 Received: by mail-pl1-f194.google.com with SMTP id w8so4239184plq.5 for ; Fri, 11 Oct 2019 03:05:56 -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=MNqtgthl8VyBRo/9SmMdv19JQkKzyWONQ2Spmwn+3yU=; b=TpWNF5FdbzsY5yjRyuNc/WX1V5aEmdKaz44+83keWD0C8QfuO6Z44Dw3G8Hl+1xU6T frLh1buCzNdEA+AxQVztaQtYHwxAYXe/yQQ9P6jMrTV7/yrXLpSNOgF5+f4dZE3FBQ0K JD2/OH9ivAAudfN1H1+1Y2b7SczXtAvAazzkx+DaXkeWdc/FzDaWPL1yML9ZQZBHIWTp cU+vS5x85lPN00MQFUfY4C3LWs/s/CD0oPl/blC2OJ5ZPXlqTFRR9ED5bzmy14HGXVBN dAZFqTUNhH3dkPvY1suY/Yl11ay2xQA45mZWTY3nxWJSgeugdv1Z8bv4nTNzY8KWJWQR s5Iw== 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=MNqtgthl8VyBRo/9SmMdv19JQkKzyWONQ2Spmwn+3yU=; b=iubFgTWa8ZX/iEh3ZsBDeF9D3gObPPQTtlP9OaRo8AO1OjV1BJ9dHDIzX8M5qv63eY IrQdB0jQdtoTKY4bL4NbDDCTMNgVBzuNALmyF+YJ2El3bJfxsT8CbIfADGpbClUndYk7 lIY57+6H/s/scp4q/UcVi90CTrK68+5m6xivOAAICQenlsIsDt7wmqwpjCpRgczw0t8e NDoBO0g1TH/hqWjSpJsaXIJQs6UEFhA0VlhzDRACUZonR/cUbZXwAnh2NdVl2RYoskJN LZjYlLQXauwvOnZWWmMsam8Fz6CnzzizTtKvqws0Y1g/PYDAgxbQgcZZdGTL/u97Ehou Y4+w== X-Gm-Message-State: APjAAAWBoVYiW5/4wYvK3SCRX3q6bQvRYfqnlZm13A/DscAIOeQDxJL+ 2SAljRJt8xxtq8BaxGT2tHy3QtN4At6lI4Dtv3F8Fw== X-Received: by 2002:a17:902:8216:: with SMTP id x22mr14492128pln.232.1570788355057; Fri, 11 Oct 2019 03:05:55 -0700 (PDT) MIME-Version: 1.0 References: <20191010023931.230475-1-yzaikin@google.com> <2f2ea7b0-f683-1cdd-f3f2-ecdf44cb4a97@linuxfoundation.org> In-Reply-To: From: Brendan Higgins Date: Fri, 11 Oct 2019 03:05:43 -0700 Message-ID: Subject: Re: [PATCH linux-kselftest/test v2] ext4: add kunit test for decoding extended timestamps To: Iurii Zaikin Cc: Shuah Khan , "open list:KERNEL SELFTEST FRAMEWORK" , linux-ext4@vger.kernel.org, "Theodore Ts'o" , adilger.kernel@dilger.ca, kunit-dev@googlegroups.com 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 Sorry for the late reply. I am on vacation until Wednesday, October 16th. On Thu, Oct 10, 2019 at 3:14 PM Iurii Zaikin wrote: > > On Thu, Oct 10, 2019 at 10:11 AM Shuah Khan wrote: > > > > On 10/9/19 8:39 PM, Iurii Zaikin wrote: > > > KUnit tests for decoding extended 64 bit timestamps. > > > > > "Added the link to the ext4 docs from which the tests were derived." > > > > Document reference is great. I would still like to see summary > > in the commit log. > > > > As you said below: > > > > "This builds the ext4 inode sysctl unit test, which runs on boot." > > > > Also include what should user expect to see when one of these fails. > Will do. > > > > > 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/. > > > > Please add Documentation/filesystems/ext4/inodes.rst Inode Timestamps > > here as well. > > Yeah. Especially after looking at the document, summary of what these > > test(s) is definitely helpful. You can't expect users to read the > > document before enabling it. Please write a summary of tests and what > > they do and add it here and then in the commit log. Also include what > > user should expect when they pass and when one of them fails. > > > I'm not sure this is compatible with Theodore's preference for having a single > config option for all ext4 tests. If anything, I should be removing That's an interesting point. Should we try to establish a pattern for how tests should be configured? My *very long term* goal is to eventually have tests able to be built and run without any kind of kernel of any kind, but I don't think that having a single config for all tests in a subsystem gets in the way of that, so I don't think I have a strong preference in terms of what I want to do. Nevertheless, I think establishing patterns is good. Do we want to try to follow Ted's preference as a general rule from now on? > all inode-specific > stuff from the description. > I think it makes sense to add wording that this option is only useful > for devs running > a kernel test harness and should not be enabled in production. > > > + > > > + 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 > > > > Yeah. Especially after looking at the document, summary of what these > > test(s) is definitely helpful. You can't expect users to read the > > document before enabling the tests. > > > > > + */ > > > + > > > +#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 = "2446-05-10", > > > + .msb_set = false, > > > + .lower_bound = false, > > > + .extra_bits = 3, > > > + .expected = {.tv_sec = 0x37fffffffLL, .tv_nsec = 0L}, > > > + } > > > + }; > > > + > > > > Is there a way to make the test data dynamic. Can you read from a data > > file? It will be easier to if the data > > > > Maybe this is question to Brendan? > > > From the general unit test philosophy, unit tests must be 100% deterministic, > repeatable and simple enough to be correct by visual inspection, dynamically > generated test data runs contrary to these goals IMHO. I 100% agree with this position on unit tests, Iurii. > As for reading from a data file, not sure what exactly you mean here: > - Having a running kernel read a file in the filesystem, especially as early in > the initialization process as KUnit currently runs is something I'm not sure > how to implement reliably. Also, doing I/O in the tests will make them slower > and require more setup from test running environment. > - Having reading a file in the build stage and linking it as a data > blob into the > kernel image. This approach looks better to me since it avoids the I/O and has > no noticeable speed penalty or test harness requirements. It would be up to > Brendan whether he wants such capability in KUnit and based on the user-space > test code I've seen so far, the number of test data points in this > test doesn't warrant > reading from files even in userspace which has far fewer constraints. I agree with Iurii. I don't think that this example alone warrants adding support for being able to read test data in from a separate file (I would also like some clarification here on what is meant by reading in from a separate file). I can imagine some scenarios where that might make sense, but I think it would be better to get more examples before trying to support that use case. Thanks!