Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp32475322rwd; Fri, 7 Jul 2023 14:50:54 -0700 (PDT) X-Google-Smtp-Source: APBJJlGbrEexLTZYPn1yIuJ4ogVWQI9dIPy1DAjO1gIM1GgP0d/KIIfKT//kbMTpcaLDa0Ux3poM X-Received: by 2002:a17:90a:fc86:b0:263:20b:2238 with SMTP id ci6-20020a17090afc8600b00263020b2238mr4551531pjb.40.1688766654133; Fri, 07 Jul 2023 14:50:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688766654; cv=none; d=google.com; s=arc-20160816; b=z6R89FLFzqcQQLr5N0p4q6Lcc4pLxhpyRs+O5IXQwFDHWpagwCxEfK23vaTwZC/ibZ agtAQTFBb9F8Apj01Z1rwLR4VicvaFjvuA88QjgdhmEwgbkWvgi69/TGyk08Gjh4/64y MhefJOVeBU+hyR2fjnGuzhPzsurO6RftJmNbdBVdSbyvfoB6HDC8FC+V+qqmTu6KxOYG TKksuxIx56hi1cUxAXLVBo/bfSAVTVI6CXjgCFHmb2aMOA/atoSDDE2GunJS3RKC552n ft9ij28x/xaWK7bjdgtnTtSa+i+7lZp6cW6wivRKIEBKNBDnUOo2uK2rwYXseHvz6esK X95Q== 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:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=OCdYM+laUObv12QZRXNdyVrCp7VSyxqP7z9SYrIpXU4=; fh=eSOGplXNKm0TQlVMiAPjma3ZxjxuDQ0l9LD5ETEQPUY=; b=xIkpDzbjKVu7FYRV3JKWhXsgr7Tj3phHNF7fI3oHh0mUs2kZo99zURisFRc9j3FF9E PAMcvm+CSrXx3Acwx3OiVPo2ctkXFIkU4cG9iXIrR3nLcVW/NA16EXMq1Hv34XLgvLeu 19gDMlS9Vo0E/QHqM4nnAhLkqrVozuS2VFuRq1WBHaJTDorotaJeDy/pl6GG/aNFT/9K 6PcCCpFJUIBBDoua3hG4VTw4Kn0vodyWImG8+aiA9FZgMArQooTVttIq3yxE/aTUbQIL x8xubt0akRtekhvZDP6i6DeWbexoxCxpk6XQedUhQb5btJjQJGpiB7lC4JqPp7uHklj3 gdmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="C/48yVJ/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lw15-20020a17090b180f00b0026306246efdsi3346022pjb.84.2023.07.07.14.50.40; Fri, 07 Jul 2023 14:50:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="C/48yVJ/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S232856AbjGGVKa (ORCPT + 99 others); Fri, 7 Jul 2023 17:10:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232847AbjGGVKS (ORCPT ); Fri, 7 Jul 2023 17:10:18 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88BDB26BC for ; Fri, 7 Jul 2023 14:10:09 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-57003dac4a8so50806027b3.1 for ; Fri, 07 Jul 2023 14:10:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688764208; x=1691356208; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=OCdYM+laUObv12QZRXNdyVrCp7VSyxqP7z9SYrIpXU4=; b=C/48yVJ/nm+zWtoBMLXZov8rRtY6Dd85sMEM1zZkoGRnXkmj1f6P/U44LGP6EGYupB WgcYdWylvSC9ii73E/WJW3Kjv1jy3av9qdSG1IYQpmNTodvJABuoVo2Lm9ingiBVUwz5 mEGzz/H4uZLdI3jZ0B95NmYlheKDTEAtqgNNyCto+EMQRiv4nZvES74zlTFmSTm97Ea5 R3dDO8FIL1zFvSspQd1Lhwn14HQLlHfHMnW9RjQIyWlLv8Wgf9pqPRsJiit+RLkhITS/ X+BzBxAKK/nLe2f/koHvgoD6d6oBQwgo3pjFP8wYy0y7noDPVwXptPBO+RU3mM6SF+Uj ssWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688764208; x=1691356208; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=OCdYM+laUObv12QZRXNdyVrCp7VSyxqP7z9SYrIpXU4=; b=f3SZEJcYWkrbyo/s90BHpxFIi/TrJeaLI/rv/Bsa8iqZxVh7ltXz/zL6RxU6fd/fXu TPSHDyohuH5UbUUyX81netLipmFh1OAtQmFnMzUNsGEzq6zri2ue9Vr8BXrJH3QpUceX r/gUaSbhkRh6OuCuqPAhA35DkdlCfBn7HySgiMRqnUKW46iM1f1uX0xzXERMC7Fnh37I m6GbtZk7PD4AmTe1XyUQ1hLPUKY6lk9QambfVYhIfJK9mIXoaX3yeXYf5Z+Sef87rlGN X76KTk64UWQfAh9Zk4LPyXrVKdQm+XyJEAKC95UC9QWd2MJCB9V/YID90XD4892DG0/R eoVA== X-Gm-Message-State: ABy/qLbiLoOCeEHBf2AfiTXbnb/UZm0m3UVhI8HMuOlCqb5KE7Ce0zLj q6dH0n/h36kN+l1OGlqbJutEYlJkBA== X-Received: from rmoar-specialist.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:45d3]) (user=rmoar job=sendgmr) by 2002:a81:ef0f:0:b0:56c:f903:8678 with SMTP id o15-20020a81ef0f000000b0056cf9038678mr79465ywm.2.1688764207805; Fri, 07 Jul 2023 14:10:07 -0700 (PDT) Date: Fri, 7 Jul 2023 21:09:46 +0000 In-Reply-To: <20230707210947.1208717-1-rmoar@google.com> Mime-Version: 1.0 References: <20230707210947.1208717-1-rmoar@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230707210947.1208717-9-rmoar@google.com> Subject: [RFC v2 8/9] kunit: add tests for filtering attributes From: Rae Moar To: shuah@kernel.org, davidgow@google.com, dlatypov@google.com, brendan.higgins@linux.dev Cc: linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, keescook@chromium.org, linux-hardening@vger.kernel.org, jstultz@google.com, tglx@linutronix.de, sboyd@kernel.org, Rae Moar Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add four tests to executor_test.c to test behavior of filtering attributes. - parse_filter_attr_test - to test the parsing of inputted filters - filter_attr_test - to test the filtering procedure on attributes - filter_attr_empty_test - to test the behavior when all tests are filtered out - filter_attr_skip_test - to test the configurable filter_skip option Signed-off-by: Rae Moar --- Changes since v1: - This is a new patch lib/kunit/executor_test.c | 107 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/lib/kunit/executor_test.c b/lib/kunit/executor_test.c index d7ab069324b5..145a78ade33d 100644 --- a/lib/kunit/executor_test.c +++ b/lib/kunit/executor_test.c @@ -7,6 +7,7 @@ */ #include +#include static void kfree_at_end(struct kunit *test, const void *to_free); static struct kunit_suite *alloc_fake_suite(struct kunit *test, @@ -22,6 +23,14 @@ static struct kunit_case dummy_test_cases[] = { {}, }; +static struct kunit_case dummy_attr_test_cases[] = { + /* .run_case is not important, just needs to be non-NULL */ + { .name = "test1", .run_case = dummy_test, .module_name = "dummy", + .attr.speed = KUNIT_SPEED_SLOW }, + { .name = "test2", .run_case = dummy_test, .module_name = "dummy" }, + {}, +}; + static void parse_filter_test(struct kunit *test) { struct kunit_glob_filter filter = {NULL, NULL}; @@ -108,11 +117,109 @@ static void filter_suites_to_empty_test(struct kunit *test) "should be empty to indicate no match"); } +static void parse_filter_attr_test(struct kunit *test) +{ + int j, filter_count; + struct kunit_attr_filter *parsed_filters; + char *filters = "speed>slow, module!=example"; + int err = 0; + + filter_count = kunit_get_filter_count(filters); + KUNIT_EXPECT_EQ(test, filter_count, 2); + + parsed_filters = kcalloc(filter_count + 1, sizeof(*parsed_filters), GFP_KERNEL); + for (j = 0; j < filter_count; j++) + parsed_filters[j] = kunit_next_attr_filter(&filters, &err); + + KUNIT_EXPECT_STREQ(test, kunit_attr_filter_name(parsed_filters[0]), "speed"); + KUNIT_EXPECT_STREQ(test, parsed_filters[0].input, ">slow"); + + KUNIT_EXPECT_STREQ(test, kunit_attr_filter_name(parsed_filters[1]), "module"); + KUNIT_EXPECT_STREQ(test, parsed_filters[1].input, "!=example"); + + kfree(parsed_filters); +} + +static void filter_attr_test(struct kunit *test) +{ + struct kunit_suite *subsuite[3] = {NULL, NULL}; + struct suite_set suite_set = {.start = subsuite, .end = &subsuite[2]}; + struct suite_set got; + int err = 0; + + subsuite[0] = alloc_fake_suite(test, "suite1", dummy_attr_test_cases); + subsuite[1] = alloc_fake_suite(test, "suite2", dummy_attr_test_cases); + subsuite[1]->attr.speed = KUNIT_SPEED_SLOW; // Set suite attribute + + /* Want: suite1(test1, test2), suite2(test1, test2), NULL -> suite1(test2), NULL */ + got = kunit_filter_suites(&suite_set, NULL, "speed>slow", NULL, &err); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, got.start); + KUNIT_ASSERT_EQ(test, err, 0); + kfree_at_end(test, got.start); + + /* Validate we just have suite1 */ + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, got.start[0]); + KUNIT_EXPECT_STREQ(test, (const char *)got.start[0]->name, "suite1"); + KUNIT_ASSERT_EQ(test, got.end - got.start, 1); + + /* Now validate we just have test2 */ + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, got.start[0]->test_cases); + KUNIT_EXPECT_STREQ(test, (const char *)got.start[0]->test_cases[0].name, "test2"); + KUNIT_EXPECT_FALSE(test, got.start[0]->test_cases[1].name); +} + +static void filter_attr_empty_test(struct kunit *test) +{ + struct kunit_suite *subsuite[3] = {NULL, NULL}; + struct suite_set suite_set = {.start = subsuite, .end = &subsuite[2]}; + struct suite_set got; + int err = 0; + + subsuite[0] = alloc_fake_suite(test, "suite1", dummy_attr_test_cases); + subsuite[1] = alloc_fake_suite(test, "suite2", dummy_attr_test_cases); + + got = kunit_filter_suites(&suite_set, NULL, "module!=dummy", NULL, &err); + KUNIT_ASSERT_EQ(test, err, 0); + kfree_at_end(test, got.start); /* just in case */ + + KUNIT_EXPECT_PTR_EQ_MSG(test, got.start, got.end, + "should be empty to indicate no match"); +} + +static void filter_attr_skip_test(struct kunit *test) +{ + struct kunit_suite *subsuite[2] = {NULL}; + struct suite_set suite_set = {.start = subsuite, .end = &subsuite[1]}; + struct suite_set got; + int err = 0; + + subsuite[0] = alloc_fake_suite(test, "suite1", dummy_attr_test_cases); + + /* Want: suite1(test1, test2), NULL -> suite1(test1 with SKIP, test2), NULL */ + got = kunit_filter_suites(&suite_set, NULL, "speed>slow", "skip", &err); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, got.start); + KUNIT_ASSERT_EQ(test, err, 0); + kfree_at_end(test, got.start); + + /* Validate we have both test1 and test2 */ + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, got.start[0]->test_cases); + KUNIT_EXPECT_STREQ(test, (const char *)got.start[0]->test_cases[0].name, "test1"); + KUNIT_EXPECT_STREQ(test, (const char *)got.start[0]->test_cases[1].name, "test2"); + + /* Now ensure test1 is skipped and test2 is not */ + KUNIT_EXPECT_EQ(test, got.start[0]->test_cases[0].status, KUNIT_SKIPPED); + KUNIT_EXPECT_FALSE(test, got.start[0]->test_cases[1].status); +} + static struct kunit_case executor_test_cases[] = { KUNIT_CASE(parse_filter_test), KUNIT_CASE(filter_suites_test), KUNIT_CASE(filter_suites_test_glob_test), KUNIT_CASE(filter_suites_to_empty_test), + KUNIT_CASE(parse_filter_attr_test), + KUNIT_CASE(filter_attr_test), + KUNIT_CASE(filter_attr_empty_test), + KUNIT_CASE(filter_attr_skip_test), {} }; -- 2.41.0.255.g8b1d071c50-goog