From patchwork Tue Oct 16 23:50:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brendan Higgins X-Patchwork-Id: 10644357 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 1481317D4 for ; Tue, 16 Oct 2018 23:53:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 043852582C for ; Tue, 16 Oct 2018 23:53:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB48626E47; Tue, 16 Oct 2018 23:53:27 +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 851F62582C for ; Tue, 16 Oct 2018 23:53:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727191AbeJQHqP (ORCPT ); Wed, 17 Oct 2018 03:46:15 -0400 Received: from mail-qt1-f201.google.com ([209.85.160.201]:41360 "EHLO mail-qt1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727064AbeJQHqP (ORCPT ); Wed, 17 Oct 2018 03:46:15 -0400 Received: by mail-qt1-f201.google.com with SMTP id j60-v6so26219076qtb.8 for ; Tue, 16 Oct 2018 16:53:26 -0700 (PDT) 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=gQdq5fFuo7J9iL+wWi/DYDZLWnOLQeSM2bBV4pqEMaU=; b=u7sM1dfw3W6YLtoL2O1mN3AkSjvkrHRDFsdiv3JxZ70XRYQo2/vGFQvAcYCK8DPx0B uxahW/Pvcr9RGuWdh29GATWj8ZnxmzHutuM90DLwgn9CTt2QrLn93j4zIwyXInYjYV7I DM1jOBXynBdZQuqKtlRh76DPZ1EPukEZapzU0hq20BAMCl1CApBsrHRdTaEG55I5bBXh 1h48qJV7HWjKvXe5MErtT4ufNipg2YcD0OQYV0AYPnO9rrDXPSoH5LMJhFthGRFSqNOf QoSWFQEh3PQX+JIftNoyKafCvUzcEBzM0mqb34HR458N921ITPegfQn08OKLuwihxjrh +eXA== 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=gQdq5fFuo7J9iL+wWi/DYDZLWnOLQeSM2bBV4pqEMaU=; b=pYAZRHEYOuZj1nM3hKr5MX4JDefa5LNEcL+28zJxE04QxTAI4U3NEM78qST02OumxY OijvAnpUjmiHAL5SegrrtoGON7XvVDLM7u5+nFQKXe7P9UWDjT3Xoyi8/DmTteqjUEI4 mE8deGy9Wpexat0E+RBXMwjGCFnYZP9Lg6H8s9FZweMTgzjSXMmnAav3pOZPjUYuIE8E U0RTe5o2fU0ttgxCS7e/e37qo90ZadpY9JN36AjSPhmPuj+acvdcnGERE9Gy2WFGgJCA YPfWZb9jUlCplij5VGD4PtbRQFPTY5H9ti/EBrCDCj+d4Q3wL71oqs4x/YewlZ5WepV3 MivQ== X-Gm-Message-State: ABuFfoiVzV2FmTseyHIYeDEW1x4o8wovfjulUuQJeNdKZWWY9qNdGlmk cskTSYMnkiGMBSuzAQAKYmPWv8ul6KTIQAo4T+Kc2Q== X-Google-Smtp-Source: ACcGV6189le67K3C7ljYXSE78Y2eccwuuQt4t2ajkYLMbvrcRRjMhmvJKEIPJO9MaydmIoClUvPNiwfvBYIuEY0NbQFwvw== X-Received: by 2002:aed:23ac:: with SMTP id j41-v6mr18937185qtc.5.1539734006237; Tue, 16 Oct 2018 16:53:26 -0700 (PDT) Date: Tue, 16 Oct 2018 16:50:49 -0700 Message-Id: <20181016235120.138227-1-brendanhiggins@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.19.1.331.ge82ca0e54c-goog Subject: [RFC v1 00/31] kunit: Introducing KUnit, the Linux kernel unit testing framework From: Brendan Higgins To: gregkh@linuxfoundation.org, keescook@google.com, mcgrof@kernel.org, shuah@kernel.org Cc: 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, 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/