Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5048271pxj; Wed, 26 May 2021 01:17:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxy6X8XkhTe+Cq90oMtM5/dqu+IcheRa50XA/hB5/se7pl2DA5aCBObLZu83TH5L7vRP7Th X-Received: by 2002:a17:906:351a:: with SMTP id r26mr1157451eja.389.1622017051687; Wed, 26 May 2021 01:17:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622017051; cv=none; d=google.com; s=arc-20160816; b=B7zXei14cNsZvaceRm+72w0S171YA7WT4aK7iZvt+LFc6jRCf71cxouMaDHbNgBt6s D0xcCeYAMt35uYLRBTJFf33fa6yEV/ILsPo6lPNtOtnSCtdEmhGUo/VebRpDxogcaSXg 9sFHEMPysKuvHoO+XK14RSfdkJaQbTPHrE/BO2osm/5qjT1N55gtZxlx72GkDl9fUhVJ FII5/5wNawmn947uOOD1X5Fo2+rUONl0OO2ENGIVWFP0+Y4iqfr8JZ3CpAelHZMMX8Qr ouZuO3WvvZBDQMDC+MyNYJSoEgS0zd/GNFDKfL7y1auwy6dGDsYPbTvaRATynmXufy5z qNwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=TccYnAk92fbSMDbrufKidZyWvSdAcbuvQv0kTQ1sGd8=; b=mrxLVHqblF2HAptEM/yjA27d43GWgv+vBTa92clFNVYPMTebFi6vU525Q1NpPd6+Ed ltvsFr5E5QqpWfaQSoVz688lDkvqrwtJ0rjNQflAHt92OhZaAR2N1fftcOzokA0a3KZZ QLEq/SVggWLwYg+VGe0I8rm4JHf8hwj3h+FNLjLIVDCkV1MFvYBLLbhIq0uo0RIdHOXP ibhNztsCCv7Gi5Ha/SrKDJxolC+rmpZ9Wk+1tRm3EU/zTWXZ1YYAYqsxVwTkGCQA5why 8/Dno31I3rNCSWqxsPn32u7CXrbnGNaCfcvLKKNPLSAIyQmWkc5KPGdr+roqbM+9sq5t LKlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VheGPqmZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id f16si19015962edy.298.2021.05.26.01.17.02; Wed, 26 May 2021 01:17:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VheGPqmZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S233410AbhEZINN (ORCPT + 99 others); Wed, 26 May 2021 04:13:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233328AbhEZIMz (ORCPT ); Wed, 26 May 2021 04:12:55 -0400 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEFD7C06138A for ; Wed, 26 May 2021 01:11:23 -0700 (PDT) Received: by mail-qv1-xf49.google.com with SMTP id u16-20020ad448700000b0290212abee977cso581246qvy.10 for ; Wed, 26 May 2021 01:11:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=TccYnAk92fbSMDbrufKidZyWvSdAcbuvQv0kTQ1sGd8=; b=VheGPqmZczRMJo0WtEivSffIheup6wkGynTDJekzs8b5Tt8q08spRx9OtZFPaBHs5q RswMXFjNfYUKwGlKaGcehJFMAoRn1g/Kp7FPSZU3WBPr7gqE7RNkG2umXsIQ0VOHKqFP ecCEpcltPV8uxwGa/eZpl3DCRQoH+zlrhD9vJeMyIQqvfxdZj6kjtEcQyxojLcmGj/14 UwaumwBFlCFja5Kbkpbet17r6Zzx5pD4xcobnhcx8wRSJEFHXWaiWEYUkYgjMJB9SD9G RXtdLvzV6Lb1m0w7FWu3c5oCC/YRdIfvdgURP4nzbPO8QhwrZOJjTJwzcVNk4sxEwi4h me0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=TccYnAk92fbSMDbrufKidZyWvSdAcbuvQv0kTQ1sGd8=; b=N884Q4ekZrJ7SSB96Kk5V7vR+4LN1Uo8kx1YgpuUnCeMcG98utD6NARjS9mrzar+gQ NJ8H8OAjM2VIw3VP5L5rQW1Wo/V3khHM5pcmNnhiucPqf/SxOKuEEXgc6dCAasP8lYqZ 2yfwMxZdC7OximS8D0c1x3tQKLYrdAYlV4rB1cNfDx3E4iXZAOiD3hyuv/Gh7Vbg8YuV 27PRGJbW53YkVd87x7ckNN0Zxuv1MJmLueDW54An8lbNty33pvJLVA36jyUsJDyxjFVn ig+gnhJz/bMS4AhYH3G3vaqP8AlrKutI7odXUxQoWRv6407PWCJbHkgv5QTvM056Kmoo uG+g== X-Gm-Message-State: AOAM531XLs/QKxoOc2bYpRsKPVrPmSAWbfR3BRC0qxrKBNQ/dcZxqz6n 2Jee6YzpLSRleTzVfeWpZUd/NDCFnQcn+g== X-Received: from spirogrip.svl.corp.google.com ([2620:15c:2cb:201:90cb:eafc:a44d:da3d]) (user=davidgow job=sendgmr) by 2002:a0c:edcf:: with SMTP id i15mr42224753qvr.10.1622016682848; Wed, 26 May 2021 01:11:22 -0700 (PDT) Date: Wed, 26 May 2021 01:11:12 -0700 In-Reply-To: <20210526081112.3652290-1-davidgow@google.com> Message-Id: <20210526081112.3652290-3-davidgow@google.com> Mime-Version: 1.0 References: <20210526081112.3652290-1-davidgow@google.com> X-Mailer: git-send-email 2.31.1.818.g46aad6cb9e-goog Subject: [PATCH 3/3] kunit: test: Add example_skip test suite which is always skipped From: David Gow To: Brendan Higgins , Alan Maguire Cc: David Gow , Shuah Khan , Marco Elver , kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a new KUnit test suite which contains tests which are always skipped. This is used as an example for how to write tests which are skipped, and to demonstrate the difference between kunit_skip() and kunit_mark_skipped(). Because these tests do not pass (they're skipped), they are not enabled by default, or by the KUNIT_ALL_TESTS config option: they must be enabled explicitly by setting CONFIG_KUNIT_EXAMPLE_SKIP_TEST=y in either a .config or .kunitconfig file. Signed-off-by: David Gow --- lib/kunit/Kconfig | 15 +++++++++ lib/kunit/Makefile | 2 ++ lib/kunit/kunit-example-skip-test.c | 52 +++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 lib/kunit/kunit-example-skip-test.c diff --git a/lib/kunit/Kconfig b/lib/kunit/Kconfig index 0b5dfb001bac..399fe5f789f7 100644 --- a/lib/kunit/Kconfig +++ b/lib/kunit/Kconfig @@ -45,6 +45,21 @@ config KUNIT_EXAMPLE_TEST is intended for curious hackers who would like to understand how to use KUnit for kernel development. +config KUNIT_EXAMPLE_SKIP_TEST + tristate "Skipped test example for KUnit" + default n + help + Enables an example unit test that is always skipped. + + This test only exists to help new users understand what KUnit is and + how it is used. Please refer to the example test itself, + lib/kunit/example-test.c, for more information. This option is + intended for curious hackers who would like to understand how to use + KUnit for kernel development. + + Because this test does not pass, it is not enabled by + CONFIG_KUNIT_ALL_TESTS + config KUNIT_ALL_TESTS tristate "All KUnit tests with satisfied dependencies" help diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index c49f4ffb6273..8a99ff2f83bd 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -18,3 +18,5 @@ obj-$(CONFIG_KUNIT_TEST) += string-stream-test.o endif obj-$(CONFIG_KUNIT_EXAMPLE_TEST) += kunit-example-test.o + +obj-$(CONFIG_KUNIT_EXAMPLE_SKIP_TEST) += kunit-example-skip-test.o diff --git a/lib/kunit/kunit-example-skip-test.c b/lib/kunit/kunit-example-skip-test.c new file mode 100644 index 000000000000..5395ee0be485 --- /dev/null +++ b/lib/kunit/kunit-example-skip-test.c @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Example KUnit test which is always skipped. + * + * Copyright (C) 2021, Google LLC. + * Author: David Gow + */ + +#include + +/* + * This test should always be skipped. + */ + +static void example_skip_test(struct kunit *test) +{ + /* This line should run */ + kunit_log(KERN_INFO, test, "You should not see a line below."); + + /* Skip (and abort) the test */ + kunit_skip(test, "this test should be skipped"); + + /* This line should not execute */ + kunit_log(KERN_INFO, test, "You should not see this line."); +} + +static void example_mark_skipped_test(struct kunit *test) +{ + /* This line should run */ + kunit_log(KERN_INFO, test, "You should see a line below."); + + /* Skip (but do not abort) the test */ + kunit_mark_skipped(test, "this test should be skipped"); + + /* This line should run */ + kunit_log(KERN_INFO, test, "You should see this line."); +} + +static struct kunit_case example_skip_test_cases[] = { + KUNIT_CASE(example_skip_test), + KUNIT_CASE(example_mark_skipped_test), + {} +}; + +static struct kunit_suite example_skip_test_suite = { + .name = "example_skip", + .test_cases = example_skip_test_cases, +}; + +kunit_test_suites(&example_skip_test_suite); + +MODULE_LICENSE("GPL v2"); -- 2.31.1.818.g46aad6cb9e-goog