Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp188428imj; Thu, 14 Feb 2019 18:16:37 -0800 (PST) X-Google-Smtp-Source: AHgI3Iaz6y7uF4FqIuFqMXbZW7Ej3PfmOrfD2O4C924W0gkXgYfxDRnRWTvX2GvooYxG9kF+JU84 X-Received: by 2002:a62:61c3:: with SMTP id v186mr7421488pfb.55.1550196997503; Thu, 14 Feb 2019 18:16:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550196997; cv=none; d=google.com; s=arc-20160816; b=lu4TRvAJefo5028duyONqMGJpIcY6OfMW8ji/gxeGWATKisrkTWO4yJUg30lN6jOxi fVF9G0P20BtrK9z4GUb3U69ONMIiksVVKUWC2Z9cy7mMZ91FEvnX17VSPJ1r9yvklVGp uU+MmBsbeAvNSx3JkFayJIkVh5XuQJItJnNqb521IT6nLhXRV/BohBWHWr9DTZrZ4M+7 /Yd6xh7fLj2V5gfENH62dxilbVbIMBXzbgfPym3ozoZzGWNr38bAHkc4jiy/gn3HfmPi 2jXsuxXl6tnRTE1XF/GgVtjU/zEDhW2QNdGvaMXTR2BAsYnkFy/2sCIgx9YeLuftcgN+ vVog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=XAFqFRHtufV1TyXpwD7i7TQuN1zCaRKMtzttQApxZxg=; b=FbT4uaR/+AW2m7V7xeRyJCLx4M0W8J/xEqqrvJcFUm7kQlbiLzpfLX24IE0cv2fTkc EzynhdLSIN+LMJFqjmJS6//gHpUByAQicwxPp0evYXz8TH7TYDVGMVOogEYPB7lQHbwU 9ik4VaK5Q2mP+ASJjg29v47cPcrrkVoN079UpH1CWrcvs1BdS+NFzRLhJl7jav3Njcas vjyW5CzucRsB0tQuncLRG/Z9BDoNsRo4fd6lIHOQeYQco8QUU1mTQTPjA56+h9KFx/Nx Cz2wZGpArL3A94frFD76zkGH/yEPHakBZG12CAap346x83AnkJQQkqInVK5RD1zWMm7W 8maw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="BdL/fcvd"; 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 b60si3620821plc.95.2019.02.14.18.16.21; Thu, 14 Feb 2019 18:16:37 -0800 (PST) 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="BdL/fcvd"; 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 S2404270AbfBNVi2 (ORCPT + 99 others); Thu, 14 Feb 2019 16:38:28 -0500 Received: from mail-vk1-f201.google.com ([209.85.221.201]:41648 "EHLO mail-vk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389588AbfBNVi2 (ORCPT ); Thu, 14 Feb 2019 16:38:28 -0500 Received: by mail-vk1-f201.google.com with SMTP id q188so3047110vke.8 for ; Thu, 14 Feb 2019 13:38:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=XAFqFRHtufV1TyXpwD7i7TQuN1zCaRKMtzttQApxZxg=; b=BdL/fcvd1OIXVuElU90Wg/eAZ3CSR08SOA8jU3xROSAwWXWSNEUdFqg+28urkUA5zs Wd9uhNTWNt2O9PpXZ0yAFvIgffsO7kMf3v8H0xreL0BpMH3dYMolzIj9ZUIqFpK83nzI DAJEVFZDsizFILfcpq0ycEXv5oGec7lhZfgk0odFAIehmDp6Z5Cr1QlNCe9dcfe83szt jMtQEwDWLya8vyZ+Ohz2r+2f4KeofLhFlFq1tgYiLahFQI0HeBztNICk6ZPEbRSQ357B oCWRm0LHdkq2XH5heYuGvt/19hhK7jqCeiRQOPiL6P9S+wPd+fv96GmmoXjsTzkrtcQ1 Rg+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=XAFqFRHtufV1TyXpwD7i7TQuN1zCaRKMtzttQApxZxg=; b=l7OYDdaquyOEuZsTVDcNH6JlqOza0P/F1RAiyTnQbbxabFwPH8/N94ISbrn0JRlRpG Xh1+WNeD1x5Tod5JAPkdApKW39iu4IMvHj7AJRvsRa0jRlBaUsN9e3lwKSIxjLaZIyma ATlb4QjGmkQOUT+LUtwulSkeR5DCrekAOU3rpPly9lL1mKx0ZGuYwE8MftLaOOEs7fKf DqwV9QhZVD/CE4i14P7ddldXn6nvVkJSNgyFJQ1GBmEDidyZ7880+0xHg3HhzgEvr/Lh Cb/kqyj99WHMlHaMvFs/Na/K3WiXxDxMFOeseocRbzQxz4S+BhsDFVNcfwbncDuad2zi yaLw== X-Gm-Message-State: AHQUAuYooPf6ceUcFm2y2N9wVh22fx+p5kor8WwGAiS+8QGLxQTfFXCl tnuDl/FeKnxSRUA0zvIMH0sEqla9lCqo+B9nVaRiqA== X-Received: by 2002:a67:ecc3:: with SMTP id i3mr3852765vsp.23.1550180306702; Thu, 14 Feb 2019 13:38:26 -0800 (PST) Date: Thu, 14 Feb 2019 13:37:12 -0800 Message-Id: <20190214213729.21702-1-brendanhiggins@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.21.0.rc0.258.g878e2cd30e-goog Subject: [RFC v4 00/17] kunit: introduce KUnit, the Linux kernel unit testing framework From: Brendan Higgins To: 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, knut.omang@oracle.com, devicetree@vger.kernel.org, pmladek@suse.com, Alexander.Levin@microsoft.com, amir73il@gmail.com, dan.carpenter@oracle.com, wfg@linux.intel.com, Brendan Higgins Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch set proposes KUnit, a lightweight unit testing and mocking framework for the Linux kernel. Unlike Autotest and kselftest, KUnit is a true unit testing framework; it does not require installing the kernel on a test machine or in a VM and does not require tests to be written in userspace running on a host kernel. Additionally, KUnit is fast: From invocation to completion KUnit can run several dozen tests in under a second. Currently, the entire KUnit test suite for KUnit runs in under a second from the initial invocation (build time excluded). KUnit is heavily inspired by JUnit, Python's unittest.mock, and Googletest/Googlemock for C++. KUnit provides facilities for defining unit test cases, grouping related test cases into test suites, providing common infrastructure for running tests, mocking, spying, and much more. ## What's so special about unit testing? A unit test is supposed to test a single unit of code in isolation, hence the name. There should be no dependencies outside the control of the test; this means no external dependencies, which makes tests orders of magnitudes faster. Likewise, since there are no external dependencies, there are no hoops to jump through to run the tests. Additionally, this makes unit tests deterministic: a failing unit test always indicates a problem. Finally, because unit tests necessarily have finer granularity, they are able to test all code paths easily solving the classic problem of difficulty in exercising error handling code. ## Is KUnit trying to replace other testing frameworks for the kernel? No. Most existing tests for the Linux kernel are end-to-end tests, which have their place. A well tested system has lots of unit tests, a reasonable number of integration tests, and some end-to-end tests. KUnit is just trying to address the unit test space which is currently not being addressed. ## More information on KUnit There is a bunch of documentation near the end of this patch set that describes how to use KUnit and best practices for writing unit tests. For convenience I am hosting the compiled docs here: https://google.github.io/kunit-docs/third_party/kernel/docs/ Additionally for convenience, I have applied these patches to a branch: https://kunit.googlesource.com/linux/+/kunit/rfc/5.0-rc5/v4 The repo may be cloned with: git clone https://kunit.googlesource.com/linux This patchset is on the kunit/rfc/5.0-rc5/v4 branch. ## Changes Since Last Version - Got KUnit working on (hypothetically) all architectures (tested on x86), as per Rob's (and other's) request - Punting all KUnit features/patches depending on UML for now. - Broke out UML specific support into arch/um/* as per "[RFC v3 01/19] kunit: test: add KUnit test runner core", as requested by Luis. - Added support to kunit_tool to allow it to build kernels in external directories, as suggested by Kieran. - Added a UML defconfig, and a config fragment for KUnit as suggested by Kieran and Luis. - Cleaned up, and reformatted a bunch of stuff. -- 2.21.0.rc0.258.g878e2cd30e-goog