Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6111381yba; Tue, 14 May 2019 01:44:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqzWjHyU5xwBs3gKY8/3zE3px9fzxbJYWh1anmt6eQQbuwqsIMrQ741u8r03um43BDZJmmj8 X-Received: by 2002:a17:902:650f:: with SMTP id b15mr13144169plk.11.1557823474990; Tue, 14 May 2019 01:44:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557823474; cv=none; d=google.com; s=arc-20160816; b=JViWRWSkxzlw67TimuG/N7+UuMVYk00dQcN2IlJGMvIEoh2t+Mn9NMVFF+RyI9PVHW 45MWCxs8vrJfjiqWPW+S5DjKJ3gOpviUgjbMLnwi51rL0lMAKeH8c2b1S3B09D/1G+wA 5t+9Ns4IZc2J6VKw9Qqjm3TKGuxrE8ekj1DskNmgqBmm7WSRDCaeYJ+Pn7M19cW+B6vl xHXDdJXAuRCfDVZtHcrLdbK/IUw2KfGQ5Fbo0LXgoTtmPGYSGhTc9RhmpU9hS2kYw4w2 5DnWnE5ECVY2uP2y8hW+0nKrliaHTdOvTYXOILMcLKc2wdGZg8Zf07v+TKBsLU7IRjoA vEpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=pQNyZmnkLUqdbsnux8K39fvyz0qGerh/7Car1s/R2uk=; b=JKDLIc/BDqkujHQMT6Rtstf3lliQxAfddN7i0J1xjpQykJTFSsB5/etwbKQhiJybNg hjl9xL0oB8vKSKriDuMwVn70fr+PTx+8Ur7sQ4bx+TeA34ZB1+tdmsuTcNFyyKqjf4P+ 1+FnjoagAcoN1kLvk91Ol+QMRJ6Ctj0/NIfwNpntGvXPNEhN8w/+EJkMHrMujCJaTyNi JvOpU2wpT8eV4ftuz2Y/cdOWbisFX3/2oQNZtrCAWdI7Gs9pOeLHVhLTNPZrmdNfmxu0 4CBTQwpNh9SCWqF3xS2eLfVn0ZX+3wL5G+71y5CYftoeuLHhhMgzEm3Lg0l0+7N5E/dR eLUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=tWPxjZov; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 w14si19124337ply.226.2019.05.14.01.44.19; Tue, 14 May 2019 01:44:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=tWPxjZov; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1726210AbfENIWW (ORCPT + 99 others); Tue, 14 May 2019 04:22:22 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:45458 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726179AbfENIWW (ORCPT ); Tue, 14 May 2019 04:22:22 -0400 Received: by mail-pl1-f194.google.com with SMTP id a5so7862053pls.12 for ; Tue, 14 May 2019 01:22:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=pQNyZmnkLUqdbsnux8K39fvyz0qGerh/7Car1s/R2uk=; b=tWPxjZovh3MyjrxN+cixrW9Jv9/RHjc+lJ7GXmNoQ/Ef7+uMw/qQbTw5B9oFRJByIG pu9cyVG7MEJ6Vrt9UDR/0OiBNk3XC3mIME5PnMdl1pxZjgK/yYxMK2jT2bktFIZCLj/9 rAq5RImK1TNYHhzh3BwnBdJnTscEEXpdoCXCZrYFiBJt6MVyxh9eyaIR+hsmrppBY4Er Bq/52n3SPw77fLYMMjIJQxNzhUURTmdWpHo3b3rdN6ULdHR6om48a59eyBuoLr8W0DtP VybSOjpmoyAKFiH9TuBHDkyK9+loWcz1WQPsILkxRVCB7AQgy3rXyfsfxyR+sEcpOSQW MevA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=pQNyZmnkLUqdbsnux8K39fvyz0qGerh/7Car1s/R2uk=; b=Gq/kFHGF3hbJdV/6KxocklooQ1g8opImVMllUMfLzrhWoxOvox7M/CHUIq566nQycM xjg17QVOK/62gOybHvh3ubdHgCyk9SAdwj30AvP/KuNmgXRns/mmdZ83W+7HLPqBGj28 9HsKLsTEFSJ8oPruznV5CiJ9aztOaR1/mUb+MU3uSIO5rgjkYVbtKklzh3neTqP+RGHP LfGRVIFLuvLxYqURmgXZjQLfikfNUd1ejPTcRCaaudDsvc7xGb2gM8jIcXSs11GWbAGq 8Kxmw65mDUQ6v6zrYTyCEfWjVXBVELsPn5UtRZmkxy/z6f+l3r4MtH6PmqyimraZnbtn BhtQ== X-Gm-Message-State: APjAAAWmFfkmP+ZdTTI4oUROhpYsqPQbPfX/3xHL4Tt+zHJla0Kwkbzi w5ysN6FgEVE6TCs2F80UZRJPgg== X-Received: by 2002:a17:902:28ab:: with SMTP id f40mr8616928plb.295.1557822140758; Tue, 14 May 2019 01:22:20 -0700 (PDT) Received: from google.com ([2620:15c:2cd:2:d714:29b4:a56b:b23b]) by smtp.gmail.com with ESMTPSA id d67sm23500676pfa.35.2019.05.14.01.22.18 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 14 May 2019 01:22:19 -0700 (PDT) Date: Tue, 14 May 2019 01:22:14 -0700 From: Brendan Higgins To: Frank Rowand Cc: Theodore Ts'o , Greg KH , keescook@google.com, kieran.bingham@ideasonboard.com, mcgrof@kernel.org, robh@kernel.org, sboyd@kernel.org, shuah@kernel.org, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-nvdimm@lists.01.org, linux-um@lists.infradead.org, Alexander.Levin@microsoft.com, Tim.Bird@sony.com, amir73il@gmail.com, dan.carpenter@oracle.com, dan.j.williams@intel.com, daniel@ffwll.ch, jdike@addtoit.com, joel@jms.id.au, julia.lawall@lip6.fr, khilman@baylibre.com, knut.omang@oracle.com, logang@deltatee.com, mpe@ellerman.id.au, pmladek@suse.com, richard@nod.at, rientjes@google.com, rostedt@goodmis.org, wfg@linux.intel.com Subject: Re: [PATCH v2 00/17] kunit: introduce KUnit, the Linux kernel unit testing framework Message-ID: <20190514082214.GB230665@google.com> References: <20190501230126.229218-1-brendanhiggins@google.com> <54940124-50df-16ec-1a32-ad794ee05da7@gmail.com> <20190507080119.GB28121@kroah.com> <20190507172256.GB5900@mit.edu> <4d963cdc-1cbb-35a3-292c-552f865ed1f7@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4d963cdc-1cbb-35a3-292c-552f865ed1f7@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 08, 2019 at 05:58:49PM -0700, Frank Rowand wrote: > Hi Ted, > > On 5/7/19 10:22 AM, Theodore Ts'o wrote: > > On Tue, May 07, 2019 at 10:01:19AM +0200, Greg KH wrote: > Not very helpful to cut the text here, plus not explicitly indicating that > text was cut (yes, I know the ">>>" will be a clue for the careful reader), > losing the set up for my question. > > > >>> My understanding is that the intent of KUnit is to avoid booting a kernel on > >>> real hardware or in a virtual machine. That seems to be a matter of semantics > >>> to me because isn't invoking a UML Linux just running the Linux kernel in > >>> a different form of virtualization? > >>> > >>> So I do not understand why KUnit is an improvement over kselftest. > >>> > >>> It seems to me that KUnit is just another piece of infrastructure that I > >>> am going to have to be familiar with as a kernel developer. More overhead, > >>> more information to stuff into my tiny little brain. > >>> > >>> I would guess that some developers will focus on just one of the two test > >>> environments (and some will focus on both), splitting the development > >>> resources instead of pooling them on a common infrastructure. > >>> > >>> What am I missing? > >> > >> kselftest provides no in-kernel framework for testing kernel code > >> specifically. That should be what kunit provides, an "easy" way to > >> write in-kernel tests for things. > >> > >> Brendan, did I get it right? > > > > Yes, that's basically right. You don't *have* to use KUnit. It's > > If KUnit is added to the kernel, and a subsystem that I am submitting > code for has chosen to use KUnit instead of kselftest, then yes, I do > *have* to use KUnit if my submission needs to contain a test for the > code unless I want to convince the maintainer that somehow my case > is special and I prefer to use kselftest instead of KUnittest. > > > > supposed to be a simple way to run a large number of small tests that > > for specific small components in a system. > > kselftest also supports running a subset of tests. That subset of tests > can also be a large number of small tests. There is nothing inherent > in KUnit vs kselftest in this regard, as far as I am aware. > > > > For example, I currently use xfstests using KVM and GCE to test all of > > ext4. These tests require using multiple 5 GB and 20GB virtual disks, > > and it works by mounting ext4 file systems and exercising ext4 through > > the system call interfaces, using userspace tools such as fsstress, > > fsx, fio, etc. It requires time overhead to start the VM, create and > > allocate virtual disks, etc. For example, to run a single 3 seconds > > xfstest (generic/001), it requires full 10 seconds to run it via > > kvm-xfstests. > > > > > > KUnit is something else; it's specifically intended to allow you to > > create lightweight tests quickly and easily, and by reducing the > > effort needed to write and run unit tests, hopefully we'll have a lot > > more of them and thus improve kernel quality. > > The same is true of kselftest. You can create lightweight tests in > kselftest. > > > > As an example, I have a volunteer working on developing KUinit tests > > for ext4. We're going to start by testing the ext4 extent status > > tree. The source code is at fs/ext4/extent_status.c; it's > > approximately 1800 LOC. The Kunit tests for the extent status tree > > will exercise all of the corner cases for the various extent status > > tree functions --- e.g., ext4_es_insert_delayed_block(), > > ext4_es_remove_extent(), ext4_es_cache_extent(), etc. And it will do > > this in isolation without our needing to create a test file system or > > using a test block device. > > > > > Next we'll test the ext4 block allocator, again in isolation. To test > > the block allocator we will have to write "mock functions" which > > simulate reading allocation bitmaps from disk. Again, this will allow > > the test writer to explicitly construct corner cases and validate that > > the block allocator works as expected without having to reverese > > engineer file system data structures which will force a particular > > code path to be executed. > > This would be a difference, but mock functions do not exist in KUnit. > The KUnit test will call the real kernel function in the UML kernel. > > I think Brendan has indicated a desire to have mock functions in the > future. > > Brendan, do I understand that correctly? Oh, sorry, I missed this comment from earlier. Yes, you are correct. Function mocking is a feature I will be introducing in a follow up patchset (assuming this one gets merged of course ;-) ). Cheers! > -Frank > > > So this is why it's largely irrelevant to me that KUinit uses UML. In > > fact, it's a feature. We're not testing device drivers, or the > > scheduler, or anything else architecture-specific. UML is not about > > virtualization. What it's about in this context is allowing us to > > start running test code as quickly as possible. Booting KVM takes > > about 3-4 seconds, and this includes initializing virtio_scsi and > > other device drivers. If by using UML we can hold the amount of > > unnecessary kernel subsystem initialization down to the absolute > > minimum, and if it means that we can communicating to the test > > framework via a userspace "printf" from UML/KUnit code, as opposed to > > via a virtual serial port to KVM's virtual console, it all makes for > > lighter weight testing. > > > > Why did I go looking for a volunteer to write KUnit tests for ext4? > > Well, I have a plan to make some changes in restructing how ext4's > > write path works, in order to support things like copy-on-write, a > > more efficient delayed allocation system, etc. This will require > > making changes to the extent status tree, and by having unit tests for > > the extent status tree, we'll be able to detect any bugs that we might > > accidentally introduce in the es tree far more quickly than if we > > didn't have those tests available. Google has long found that having > > these sorts of unit tests is a real win for developer velocity for any > > non-trivial code module (or C++ class), even when you take into > > account the time it takes to create the unit tests. > > > > - Ted> > > P.S. Many thanks to Brendan for finding such a volunteer for me; the > > person in question is a SRE from Switzerland who is interested in > > getting involved with kernel testing, and this is going to be their > > 20% project. :-) > > > >