Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2258306ybi; Mon, 17 Jun 2019 01:29:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqzJS2XTJGUDThKq+ovf+7benb/O0XZXxE8wGbVAsMOpYlYOcXd6RPVdySW7fs3uBXLu8fjY X-Received: by 2002:aa7:9834:: with SMTP id q20mr70892050pfl.196.1560760167886; Mon, 17 Jun 2019 01:29:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560760167; cv=none; d=google.com; s=arc-20160816; b=WQA4qRKu0RrsTFYq1zC8qfyJvWi2DOM8ryqMEPFRkOXsTvTl63j3K5pzjDLdzXr4F6 57RXcXfKkhpIlHnVhO/Y9NApUu1l2Ysu34UIL9PlHVZvqeO/CsbiRAQD+mQHNaCva7/o KhgoVu5Umjs/ZdXHdfWZqgfVhM2oZK9APNF7J/tc3ZtsS0sCMNgA7WGz6xKiJYs9vWgz JUkI9mYzIyHFBWEXzy17reinEpMlS5QSHReAwpwvQL0Lj5s2eONqvqC9VTQu1Ivwhx3b vbCUO5JQApWL4nbgBP0/y1ga2r5VHedyi1tXO+mO0cN9TmWRLHpYL0h0aoivQKcLX/Z6 Vs8g== 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:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=KY/n5n08DNNwzzOt2NpPZO1jsdMpuV8r/7DR2vhL0/g=; b=0lOm3vHNA9Mbr82AJOnxZA2PnLj0D1GfId4tilqXbV5gMdHwIfgkkKW7tb873wpb3H p73+PGRvFrvK72ol5fmSMvgpEETFtSSkKTZX5tCfHOlr30oUDyRAY7rBmNfMvkwRrOEG 23Zv7+JM5XmdKI4rGSJRb77cS5a2ZqkT/s24ncX8TqxUpTqI4ZaYo9pbm65THCpS7wyT r3ASFDzP6dIgI/WmQyGSjoh0CQcXqwRVMRGyXdUv6/1+SS7Cfv22uhUZ//ph2rGbKH3i McANZluLGLa0dtYQ2QjVsB/VXiCFvUt5Ebkek0SjkPlZsB9zIzKLPhMJuB4GSufi+KcZ Zgxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="q/ODDwhA"; 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 l7si10061481pgl.562.2019.06.17.01.29.12; Mon, 17 Jun 2019 01:29:27 -0700 (PDT) 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="q/ODDwhA"; 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 S1727802AbfFQI12 (ORCPT + 99 others); Mon, 17 Jun 2019 04:27:28 -0400 Received: from mail-qt1-f202.google.com ([209.85.160.202]:52232 "EHLO mail-qt1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727878AbfFQI1Y (ORCPT ); Mon, 17 Jun 2019 04:27:24 -0400 Received: by mail-qt1-f202.google.com with SMTP id d26so682104qte.19 for ; Mon, 17 Jun 2019 01:27: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=KY/n5n08DNNwzzOt2NpPZO1jsdMpuV8r/7DR2vhL0/g=; b=q/ODDwhAqKOOiCxSwz4+lG1McMEc9y5H+DzydXrrUKfUIpWOITBaQS4h6r5e8uhTYL 35FkAc8AkNNK9UGFxQmNhZzLUq2bTCf0YNU1/9lCVMoiMJv3ozdOP1dE2VJcykod8SYA fp1WPz4nTHkiPystbW71OVZ7DbBbmEcnaGFpE2WcWzFxXqsAjaSuAI46xWLRPlbms8fp XIbX/yt+4xjWdOf/AMYK0Lc91DnlTl5wg5wcf5ltaqWPgiCJlAVUwLmrFI5rg8wuJ4u7 BOOpAtZX3oVW6pMsQyR698D5r9Vz+Oj2QB1TUXqKDYi5g5rSgHnEmf7Qsg+zHHi1eTV9 lITA== 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=KY/n5n08DNNwzzOt2NpPZO1jsdMpuV8r/7DR2vhL0/g=; b=PWlWUh5njMtUGsxmw3KAJO7sb+T8usLUUMNAvVIVHoallPLir6DFqqRPqTK/HVyoyK fyk4lfY98QR3ME301Wb2CUX6Nfzgb4TJvr4bDhH1M24s5MuCdTLUB0rW1EjKxhyIoW4Z u/R+EC8NtmesCu9D/W3F7/GdpxLZTUc+hYvwE2DtcBVOHO4xTA5f+CIVlbF6i0rT3LT3 2cVNjSHtXqDr0DV6kyIkzOEHgUH5YUn6rpJ7ZFHLs9P7bC8+7uO6+fWHXujHiWwolBMT 9rPBRxinlYOsLbNEnGDX64CIkfjBOAElSdIT+au8m3lvl1uPiAnuOmRMU5TCwYUDc4ya rGRQ== X-Gm-Message-State: APjAAAXOrqqqyqaEg+RzMnigg+XaFTuWCP4t3BdBoCuhYPRDScUrDBpL gF2GM/ojBEPiOlfXLAVRQdtJH6nfGLAw0K+b5QetZg== X-Received: by 2002:a05:620a:136d:: with SMTP id d13mr62994339qkl.22.1560760043194; Mon, 17 Jun 2019 01:27:23 -0700 (PDT) Date: Mon, 17 Jun 2019 01:26:05 -0700 In-Reply-To: <20190617082613.109131-1-brendanhiggins@google.com> Message-Id: <20190617082613.109131-11-brendanhiggins@google.com> Mime-Version: 1.0 References: <20190617082613.109131-1-brendanhiggins@google.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog Subject: [PATCH v5 10/18] kunit: test: add tests for kunit test abort From: Brendan Higgins To: frowand.list@gmail.com, gregkh@linuxfoundation.org, jpoimboe@redhat.com, keescook@google.com, kieran.bingham@ideasonboard.com, mcgrof@kernel.org, peterz@infradead.org, robh@kernel.org, sboyd@kernel.org, shuah@kernel.org, tytso@mit.edu, yamada.masahiro@socionext.com Cc: devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-nvdimm@lists.01.org, linux-um@lists.infradead.org, Alexander.Levin@microsoft.com, Tim.Bird@sony.com, amir73il@gmail.com, dan.carpenter@oracle.com, daniel@ffwll.ch, jdike@addtoit.com, joel@jms.id.au, julia.lawall@lip6.fr, khilman@baylibre.com, knut.omang@oracle.com, logang@deltatee.com, mpe@ellerman.id.au, pmladek@suse.com, rdunlap@infradead.org, richard@nod.at, rientjes@google.com, rostedt@goodmis.org, 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 Add KUnit tests for the KUnit test abort mechanism (see preceding commit). Add tests both for general try catch mechanism as well as non-architecture specific mechanism. Signed-off-by: Brendan Higgins Reviewed-by: Greg Kroah-Hartman Reviewed-by: Logan Gunthorpe --- kunit/Makefile | 3 +- kunit/test-test.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 kunit/test-test.c diff --git a/kunit/Makefile b/kunit/Makefile index 1f7680cfa11ad..533355867abd2 100644 --- a/kunit/Makefile +++ b/kunit/Makefile @@ -3,6 +3,7 @@ obj-$(CONFIG_KUNIT) += test.o \ kunit-stream.o \ try-catch.o -obj-$(CONFIG_KUNIT_TEST) += string-stream-test.o +obj-$(CONFIG_KUNIT_TEST) += test-test.o \ + string-stream-test.o obj-$(CONFIG_KUNIT_EXAMPLE_TEST) += example-test.o diff --git a/kunit/test-test.c b/kunit/test-test.c new file mode 100644 index 0000000000000..5d14e1ae35ed5 --- /dev/null +++ b/kunit/test-test.c @@ -0,0 +1,101 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit test for core test infrastructure. + * + * Copyright (C) 2019, Google LLC. + * Author: Brendan Higgins + */ +#include + +struct kunit_try_catch_test_context { + struct kunit_try_catch *try_catch; + bool function_called; +}; + +void kunit_test_successful_try(void *data) +{ + struct kunit *test = data; + struct kunit_try_catch_test_context *ctx = test->priv; + + ctx->function_called = true; +} + +void kunit_test_no_catch(void *data) +{ + struct kunit *test = data; + + KUNIT_FAIL(test, "Catch should not be called\n"); +} + +static void kunit_test_try_catch_successful_try_no_catch(struct kunit *test) +{ + struct kunit_try_catch_test_context *ctx = test->priv; + struct kunit_try_catch *try_catch = ctx->try_catch; + + kunit_try_catch_init(try_catch, + test, + kunit_test_successful_try, + kunit_test_no_catch); + kunit_try_catch_run(try_catch, test); + + KUNIT_EXPECT_TRUE(test, ctx->function_called); +} + +void kunit_test_unsuccessful_try(void *data) +{ + struct kunit *test = data; + struct kunit_try_catch_test_context *ctx = test->priv; + struct kunit_try_catch *try_catch = ctx->try_catch; + + kunit_try_catch_throw(try_catch); + KUNIT_FAIL(test, "This line should never be reached\n"); +} + +void kunit_test_catch(void *data) +{ + struct kunit *test = data; + struct kunit_try_catch_test_context *ctx = test->priv; + + ctx->function_called = true; +} + +static void kunit_test_try_catch_unsuccessful_try_does_catch(struct kunit *test) +{ + struct kunit_try_catch_test_context *ctx = test->priv; + struct kunit_try_catch *try_catch = ctx->try_catch; + + kunit_try_catch_init(try_catch, + test, + kunit_test_unsuccessful_try, + kunit_test_catch); + kunit_try_catch_run(try_catch, test); + + KUNIT_EXPECT_TRUE(test, ctx->function_called); +} + +static int kunit_try_catch_test_init(struct kunit *test) +{ + struct kunit_try_catch_test_context *ctx; + + ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL); + test->priv = ctx; + + ctx->try_catch = kunit_kmalloc(test, + sizeof(*ctx->try_catch), + GFP_KERNEL); + + return 0; +} + +static struct kunit_case kunit_try_catch_test_cases[] = { + KUNIT_CASE(kunit_test_try_catch_successful_try_no_catch), + KUNIT_CASE(kunit_test_try_catch_unsuccessful_try_does_catch), + {} +}; + +static struct kunit_module kunit_try_catch_test_module = { + .name = "kunit-try-catch-test", + .init = kunit_try_catch_test_init, + .test_cases = kunit_try_catch_test_cases, +}; +module_test(kunit_try_catch_test_module); -- 2.22.0.410.gd8fdbe21b5-goog