From patchwork Thu Feb 14 21:37:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brendan Higgins X-Patchwork-Id: 10813849 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 54FB91390 for ; Thu, 14 Feb 2019 21:38:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4266F2EB15 for ; Thu, 14 Feb 2019 21:38:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 337582E955; Thu, 14 Feb 2019 21:38:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF9D82E955 for ; Thu, 14 Feb 2019 21:38:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389737AbfBNVi2 (ORCPT ); Thu, 14 Feb 2019 16:38:28 -0500 Received: from mail-vk1-f202.google.com ([209.85.221.202]:48841 "EHLO mail-vk1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387671AbfBNVi2 (ORCPT ); Thu, 14 Feb 2019 16:38:28 -0500 Received: by mail-vk1-f202.google.com with SMTP id 15so3109029vkz.15 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=QVh42r+W33HxuF3p0tDWqFJ7UPb/8n5fAWalCVXur0esGiST8QEa+eRws+giNM6MQq ufL1INvF70NfDAz9mOs/Bp9ngyKwS8Fep1sN0aUGKmy/MTfp371fujBUiw9xdC82cYLR AuHKqyArZT7CZuuxfrtURP06kNHFsaWpkEPOEgL2oCLPHjj0g81R/wyMxcmVIDmnbAxk LOHyJOTg99/ix40ccAVn+g6JtbYR24MSbUNPvccmu7RL7HOK+ZmMioDuhc4VTsBS6Gpr Q8vnhMvP37x53LomoSRuUnFVJ5d+xS2t2vo7ME5xStrG51i+6tuaxwTx6KgvLCbjO6HN EEsQ== X-Gm-Message-State: AHQUAuYTl/btq1xJlElkO1QDerywVE/vQHPXugwRhLnRzWrKIty52e8A LHgjY2JY9aWRhPKoOBVvI8jpzR8Wtb9Jt4Ym0MbAvQ== X-Google-Smtp-Source: AHgI3Iac77I1KLzcGAy9rCB+1iutLyogqRzi26kl9vJulzvV5ER8bLUDKX2cY1JjoWxkC59lkG8jeTSNquV0I5/Z3kfSuQ== 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 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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.