From patchwork Wed Nov 28 19:36:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brendan Higgins X-Patchwork-Id: 10704157 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 F23181057 for ; Thu, 29 Nov 2018 08:04:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E89EF2B9BB for ; Thu, 29 Nov 2018 08:04:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA5F12EC37; Thu, 29 Nov 2018 08:04:04 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C450F2B9BB for ; Thu, 29 Nov 2018 08:04:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 099246E466; Thu, 29 Nov 2018 08:03:52 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by gabe.freedesktop.org (Postfix) with ESMTPS id 23E326E0FE for ; Wed, 28 Nov 2018 19:37:12 +0000 (UTC) Received: by mail-qk1-x749.google.com with SMTP id n68so27148376qkn.8 for ; Wed, 28 Nov 2018 11:37:12 -0800 (PST) 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=99nVbqfKL8VgOyeZOYLd9fGPS1EwErpNGV1fQd8c1qI=; b=mmv9/XAznrdMhCmjdmPijWH7LJlfTIfciog6m6A3gs4ZhT9Us0N6LPeIGfsS7Al0r3 2og6HnWl65MMRkwV3Rkvig2smo9GPFdM2V04X5FtB8F7ewnRKdHCSaw1OwUu0l0Rv725 eqkFLXHm16fiz25tHn6RIfDCsfJoTrrU5L7pspd+9r0UnvNkxH2Ft/BkC8a4vcA+ompl 6HyntENp/Fpv5aT/9wl9icZX6Q+x0nUpjiF24hHDXHzH7x5XN2dfSTDzp+NV0M0Z15AB fqjMuSpdYVZ6CnlPLZk8yvbz7He4lcnOv4XrwB62UT6Ys3d/bINOGJ/2usbZ5I7nPshP 6xsQ== X-Gm-Message-State: AA+aEWbAy0yuqkxBBKN6ZADcjtQY5fjuPJV/DLT2fdyrU1YdsfGrqLg7 qguhBF99QMfPXCHPUq9GPQbpIhh8A20hzlwzH8j9IA== X-Google-Smtp-Source: AFSGD/VCWycCbDmFp6Z5qNxzgmexxk1/jZS8YbUaoMOmSU6YkTfkM2zG1R/OjWIDtfLq/fQe62iAC1tOjqPaVFw87UApQA== X-Received: by 2002:ac8:7244:: with SMTP id l4mr4486112qtp.21.1543433831218; Wed, 28 Nov 2018 11:37:11 -0800 (PST) Date: Wed, 28 Nov 2018 11:36:17 -0800 Message-Id: <20181128193636.254378-1-brendanhiggins@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.20.0.rc0.387.gc7a69e6b6c-goog Subject: [RFC v3 00/19] kunit: introduce KUnit, the Linux kernel unit testing framework From: Brendan Higgins To: gregkh@linuxfoundation.org, keescook@google.com, mcgrof@kernel.org, shuah@kernel.org X-Mailman-Approved-At: Thu, 29 Nov 2018 08:03:11 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: brakmo@fb.com, jdike@addtoit.com, dri-devel@lists.freedesktop.org, linux-kselftest@vger.kernel.org, frowand.list@gmail.com, linux-nvdimm@lists.01.org, richard@nod.at, knut.omang@oracle.com, kieran.bingham@ideasonboard.com, joel@jms.id.au, khilman@baylibre.com, Brendan Higgins , Tim.Bird@sony.com, linux-um@lists.infradead.org, rostedt@goodmis.org, julia.lawall@lip6.fr, dan.j.williams@intel.com, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, mpe@ellerman.id.au, joe@perches.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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/4.19/v3 The repo may be cloned with: git clone https://kunit.googlesource.com/linux This patchset is on the kunit/rfc/4.19/v3 branch. ## Changes Since Last Version - Changed namespace prefix from `test_*` to `kunit_*` as requested by Shuah. - Started converting/cleaning up the device tree unittest to use KUnit. - Started adding KUnit expectations with custom messages.