Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp346657img; Wed, 20 Mar 2019 22:28:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqxyUmvElPKm2F8QeZBDQmP4hHipVA9lrihdLwoa9WO+CCFeVWakFxzKT/7N1HQszNEB1dlk X-Received: by 2002:a17:902:526:: with SMTP id 35mr1631731plf.276.1553146100588; Wed, 20 Mar 2019 22:28:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553146100; cv=none; d=google.com; s=arc-20160816; b=cvuk5TMSTUwvjb16vpjhpYhvpcZMWXXTlMQ+yiDwBm7TUjKF4afT/T2wzVNrowo0HU 7r9Aba/NxbsSwtfRamnvjzK84l99DNiHdXI09j8WkDt8jQuHVC0U/vQzOKxno1ScnVFi S39axA4G99ks7rps5WgBw5mjjx53ObaEFTFhfsvZyT11KLtIByJiqj3yXGcNR/5zbh5U r4gx0J6a+uQr1c80yOuYZjVTnXf0kgC0LliX9Wutqne7Mq2edA4urwMkpv9sLw8db1Re eRDqlR4SDSdNZX21I55mPAx4egRKXgkm74QFghvHhCruQkUzUeo8E+oMAeYXiUQIdW3A BS9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:organization:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=CYXv3U6J+BKsaMJ1kigCPH8LU08LREjp5kfcSQ/+bpc=; b=W2gwHsQu93xHGiInJQc+FAuDBYlJPVZVBH+30W8gg2NY/UJZLHHxff/eFDsfJJzpJS tCG06mSI7Vscn8ZlvqMiQuKABPHk+d+Qu4xgb4c/9jHqkPU0JySCyx8eqXCnbhR8GiAw +K5JqrEk8hd3CvxN+WyRQLbpKydv1XJe/J17wzCryKEBHlB+ihYzpTXICHkiOgP2TXhS C1aPN7Us8rmO3n7CJ3ZyA89kLSqfVIPOfhb1c9aWPZXmYsVBQ9UARGCTT2ajzP5Kc2SJ oDIhnIbLetXqTWNDE0W2NqxW6Y2JM/ptg3VsGAKPDC6QOCWSvetyr8P/Rr63xDiL6t85 aXCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=GqEaOGrv; 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=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t33si3415465pgl.530.2019.03.20.22.28.03; Wed, 20 Mar 2019 22:28:20 -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=@oracle.com header.s=corp-2018-07-02 header.b=GqEaOGrv; 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=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726212AbfCUF0K (ORCPT + 99 others); Thu, 21 Mar 2019 01:26:10 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:34052 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725971AbfCUF0K (ORCPT ); Thu, 21 Mar 2019 01:26:10 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x2L5OQ0I172795; Thu, 21 Mar 2019 05:24:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=message-id : subject : from : to : cc : date : in-reply-to : references : content-type : mime-version : content-transfer-encoding; s=corp-2018-07-02; bh=CYXv3U6J+BKsaMJ1kigCPH8LU08LREjp5kfcSQ/+bpc=; b=GqEaOGrvgWTaH/o/1prKPUqJG3AT04QkGJ8yt52ZXCcNZVlXcWWFta1kppCeGiYwSv5v m3gqY2VUffBri/VsHbmCr0XazGyCPj+OWFSP0TsJwH9RQtd2mZaMECmSTL9fgmRHvx5y ZKql6GE9QWRV10tzKZSjw1mq8hKFEdBOPXYYf2heLGzcQ5MeU8d//zLOoImDMcvZnz6W Xjx8vx4pP12KHjmJEIqVtQ1r+twmE1IPI+cTslOPTPfTwUKLHSVmHNlaRsY2XhVOgdcM oX62mkvAOaH89C+4NeZfawHt7nWjgFwlrry4n/3YVWXuiPtIxqqNW0CFdyrxde5W6ZLT eA== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2130.oracle.com with ESMTP id 2r8pnexp97-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 21 Mar 2019 05:24:26 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x2L5OKjq000918 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 21 Mar 2019 05:24:20 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x2L5OE50027680; Thu, 21 Mar 2019 05:24:14 GMT Received: from ovo (/213.188.19.88) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 20 Mar 2019 22:24:12 -0700 Message-ID: <01b2a950f661e8ebd6acbc45c2f89c8f10063daf.camel@oracle.com> Subject: Re: [RFC v4 00/17] kunit: introduce KUnit, the Linux kernel unit testing framework From: Knut Omang To: Logan Gunthorpe , Brendan Higgins , keescook@google.com, mcgrof@kernel.org, shuah@kernel.org, robh@kernel.org, kieran.bingham@ideasonboard.com, frowand.list@gmail.com Cc: gregkh@linuxfoundation.org, joel@jms.id.au, mpe@ellerman.id.au, joe@perches.com, brakmo@fb.com, rostedt@goodmis.org, Tim.Bird@sony.com, khilman@baylibre.com, julia.lawall@lip6.fr, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, jdike@addtoit.com, richard@nod.at, linux-um@lists.infradead.org, daniel@ffwll.ch, dri-devel@lists.freedesktop.org, dan.j.williams@intel.com, linux-nvdimm@lists.01.org, devicetree@vger.kernel.org, pmladek@suse.com, Alexander.Levin@microsoft.com, amir73il@gmail.com, dan.carpenter@oracle.com, wfg@linux.intel.com Date: Thu, 21 Mar 2019 06:23:59 +0100 In-Reply-To: <6d9b3b21-1179-3a45-7545-30aa15306cb4@deltatee.com> References: <20190214213729.21702-1-brendanhiggins@google.com> <6d9b3b21-1179-3a45-7545-30aa15306cb4@deltatee.com> Organization: Oracle Inc Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.30.5 (3.30.5-1.fc29) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9201 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903210037 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Logan, On Wed, 2019-03-20 at 19:07 -0600, Logan Gunthorpe wrote: > Hi, > > On 2019-02-14 2:37 p.m., Brendan Higgins wrote: > > This patch set proposes KUnit, a lightweight unit testing and mocking > > framework for the Linux kernel. > > I haven't followed the entire conversation but I saw the KUnit write-up > on LWN and ended up, as an exercise, giving it a try. > > I really like the idea of having a fast unit testing infrastructure in > the kernel. Occasionally, I write userspace tests for tricky functions > that I essentially write by copying the code over to a throw away C file > and exercise them as I need. I think it would be great to be able to > keep these tests around in a way that they can be run by anyone who > wants to touch the code. > > I was just dealing with some functions that required some mocked up > tests so I thought I'd give KUnit a try. I found writing the code very > easy and the infrastructure I was testing was quite simple to mock out > the hardware. > > However, I got a bit hung up by one issue: I was writing unit tests for > code in the NTB tree which itself depends on CONFIG_PCI which cannot be > enabled in UML (for what should be obvious reasons). I managed to work > around this because, as luck would have it, all the functions I cared > about testing were actually static inline functions in headers. So I > placed my test code in the kunit folder (so it would compile) and hacked > around a couple a of functions I didn't care about that would not be > compiled. > > In the end I got it to work acceptably, but I get the impression that > KUnit will not be usable for wide swaths of kernel code that can't be > compiled in UML. Has there been any discussion or ideas on how to work > around this so it can be more generally useful? Or will this feature be > restricted roughly to non-drivers and functions in headers that don't > have #ifdefs around them? Testing drivers, hardware and firmware within production kernels was the use case that inspired KTF (Kernel Test Framework). Currently KTF is available as a standalone git repository. That's been the most efficient form for us so far, as we typically want tests to be developed once but deployed on many different kernel versions simultaneously, as part of continuous integration. But we're also working towards a suitable proposal for how it can be smoothly integrated into the kernel, but while still keeping the benefits and tools to allow cross-kernel development of tests. As part of this, I have a master student who has been looking at converting some of the existing kernel test suites to KTF, and we have more examples coming from our internal usage, as we get more mileage and more users. See for instance this recent blog entry testing skbuff as an example, on the Oracle kernel development blog: https://blogs.oracle.com/linux/writing-kernel-tests-with-the-new-kernel-test-framework-ktf Other relevant links: Git repo: https://github.com/oracle/ktf Formatted docs: http://heim.ifi.uio.no/~knuto/ktf/ LWN mention from my presentation at LPC'17: https://lwn.net/Articles/735034/ Earlier Oracle blog post: https://blogs.oracle.com/linux/oracles-new-kernel-test-framework-for-linux-v2 OSS'18 presentation slides: https://events.linuxfoundation.org/wp-content/uploads/2017/12/Test-Driven-Kernel-Development-Knut-Omang-Oracle.pdf > If you're interested in seeing the unit tests I ended up writing you can > find the commits here[1]. It would certainly be interesting to see how the use cases you struggled with would work with KTF ;-) Thanks, Knut > > Thanks, > > Logan > > [1] https://github.com/sbates130272/linux-p2pmem/ ntb_kunit