Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp3019133rdb; Mon, 4 Dec 2023 14:20:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IF1bzwvczYGCPxwpQLSXxB6IT28DpbOzpR4sOeqdP8RV+Zfr3sbE/mWnoaNlCKzcVorLrLn X-Received: by 2002:a17:902:f80f:b0:1d0:488e:3827 with SMTP id ix15-20020a170902f80f00b001d0488e3827mr6364377plb.56.1701728445333; Mon, 04 Dec 2023 14:20:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701728445; cv=none; d=google.com; s=arc-20160816; b=qjCGnk5FARLw4mxReNcNjmOupU9yLbwBCh3mYAbFNlTd5HgrDYiZlCe5C5NvyesE+9 3L/QmMkPrZffjqamsFb1q6Iy2mVqp1u5awyMNWg4bu/GDFobRuMpWyDqgxcbcokvWW84 Eg0fzzMTO9ZZA/L7U06/0ErGibTGKZJYmN4POAhZpUdkVsPW9lE71ciTGOsQLVcNxGE3 KPgqEmOFvRQKUtDalHGEDsLruZ4BfCf/dxEh1ZHEpjWd43kWsFXpEYuFUvRVs5k2vyf5 lbIVKVBLJWx1kLOpq2XfcYy1qzFLX5mcNSna9o1M63PqelHQAPaDvqMAHRvD2bwom+9P FlRA== 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=FbKw92LwzxqFMUL9Ga0oOICdSX1CkrZsFK7gwu7z4qs=; fh=6RrXC9a42eRtUq33jTxbdw6zXjl3feewHokQkvv5rHU=; b=v9jLa0RMjBmtrQjjpWstD/Ztf+ZPA0UI4IhW4qdpcYWy3iX5YM2wDA8V9Cm3nSHL6g Kz8S+3qbV8KC44qQQuAPF5ucNxmOZ7oi9DadCZk9vsTrExlWuZ/Q8vkjdtn3HeoKOlnK fFKpSKt6GP6U2jMjVBSbwaF85zR9Lq8sr5Rj1eipsS+6mMLgePo7iIk8VKn7G2vc9Ixq jvmAe0O1lpwyi923ve+LXiD8NxbNNdNN+2uOk4gk0L3EtSCoMe0qAQ5pZgvsVJI0yAaF ist28IlaNZ8XzPr11X8z8j1umX+fofMxFGanoggPO38+09IVNvtnIV3kUSCLCsLkkFmI js+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=zd1C37Cj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id v11-20020a1709028d8b00b001c589ba4a0bsi8521543plo.195.2023.12.04.14.20.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 14:20:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=zd1C37Cj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id C613C80598B4; Mon, 4 Dec 2023 14:20:36 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235350AbjLDWTw (ORCPT + 99 others); Mon, 4 Dec 2023 17:19:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234696AbjLDWTl (ORCPT ); Mon, 4 Dec 2023 17:19:41 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BEF5135 for ; Mon, 4 Dec 2023 14:19:43 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5d1ed4b268dso83264747b3.0 for ; Mon, 04 Dec 2023 14:19:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701728382; x=1702333182; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=FbKw92LwzxqFMUL9Ga0oOICdSX1CkrZsFK7gwu7z4qs=; b=zd1C37Cj2xtdk9jCiPLarmSLsnGa+vzL7ytwVlrPmbY/bsUz0Rl3gU32DI8qcl1alG /xR0SjCH9iNuJn+kBEwyGbYkK+INcks3VG3CnExAkPwZpGSDl1FaUdPLKf+OlDs3/l8k sgBtqSBI7sI2XQXcvHodguUvNc9smn+rNNEfjxQvf3EYPjpkKG0b3GuWXViyVoQkB8/S /GXZwnUXm6nwzjHyCvdY+QL5C2Ubq7xpocrmBInBAbCRLLj5cSAak54stZnKI3lIzOj0 4StzBMrqiUBEqKQJz6YM4EI+O60yFWA1GdFiMmdmae3dDqULnbqpXuRiqh6vadyAaHr0 Ubgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701728382; x=1702333182; 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=FbKw92LwzxqFMUL9Ga0oOICdSX1CkrZsFK7gwu7z4qs=; b=Jrl9Z6a3koocWRCpC33g2k91roV+Vp3tQlqQOSSWPv0z1KsdKaXNHdWgwT339V38fU S78Qqu09rVX1I0vARAQw/fFNdvLY0woRvPsAF2lUIjvbFw/SLf0BkR4NM1tQGNqiIgk0 t/h9pfukKIqTYM4av8ttNdw8oJefv9zLRLHkInyR7YvH/WUzMB9g6OMyuujogq80BbWP 3qgnCFpm41oJTiRDS/tV6Y1p9zLwRf7SeDk4tub53AQ3H7A4AkSSiVI3CYKuqbtyymzY yj+/vKBA0Xyl1t3248swZsl6SiZksHQSJAP1IhENztiSn0+etpYYiD2Xie7p+Sru8T1R A9eA== X-Gm-Message-State: AOJu0YyP4dq0/YOPCW4sSSWQkGQf4+VJmUFmUDR3cnNCce6p93LKpjhX 1ZUEKx4xh5r9zk79xQyuOQhuEE2nkg== X-Received: from rmoar-specialist.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:45d3]) (user=rmoar job=sendgmr) by 2002:a05:690c:98a:b0:5d4:2ff3:d280 with SMTP id ce10-20020a05690c098a00b005d42ff3d280mr320818ywb.7.1701728382783; Mon, 04 Dec 2023 14:19:42 -0800 (PST) Date: Mon, 4 Dec 2023 22:19:29 +0000 In-Reply-To: <20231204221932.1465004-1-rmoar@google.com> Mime-Version: 1.0 References: <20231204221932.1465004-1-rmoar@google.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog Message-ID: <20231204221932.1465004-4-rmoar@google.com> Subject: [PATCH v3 4/6] kunit: add is_init test attribute From: Rae Moar To: shuah@kernel.org, davidgow@google.com, dlatypov@google.com, brendan.higgins@linux.dev, sadiyakazi@google.com Cc: keescook@chromium.org, arnd@arndb.de, linux-kselftest@vger.kernel.org, linux-arch@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Rae Moar Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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 fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 04 Dec 2023 14:20:37 -0800 (PST) Add is_init test attribute of type bool. Add to_string, get, and filter methods to lib/kunit/attributes.c. Mark each of the tests in the init section with the is_init=true attribute. Add is_init to the attributes documentation. Signed-off-by: Rae Moar --- .../dev-tools/kunit/running_tips.rst | 7 +++ include/kunit/test.h | 3 + lib/kunit/attributes.c | 60 +++++++++++++++++++ lib/kunit/executor.c | 6 +- 4 files changed, 75 insertions(+), 1 deletion(-) diff --git a/Documentation/dev-tools/kunit/running_tips.rst b/Documentation/dev-tools/kunit/running_tips.rst index 766f9cdea0fa..024e9ad1d1e9 100644 --- a/Documentation/dev-tools/kunit/running_tips.rst +++ b/Documentation/dev-tools/kunit/running_tips.rst @@ -428,3 +428,10 @@ This attribute indicates the name of the module associated with the test. This attribute is automatically saved as a string and is printed for each suite. Tests can also be filtered using this attribute. + +``is_init`` + +This attribute indicates whether the test uses init data or functions. + +This attribute is automatically saved as a boolean and tests can also be +filtered using this attribute. diff --git a/include/kunit/test.h b/include/kunit/test.h index 06e826a0b894..65583782903d 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -82,6 +82,9 @@ enum kunit_speed { /* Holds attributes for each test case and suite */ struct kunit_attributes { enum kunit_speed speed; + + /* private: internal use only */ + bool is_init; }; /** diff --git a/lib/kunit/attributes.c b/lib/kunit/attributes.c index 1b512f7e1838..ddacec6a3337 100644 --- a/lib/kunit/attributes.c +++ b/lib/kunit/attributes.c @@ -58,6 +58,16 @@ static const char *attr_enum_to_string(void *attr, const char * const str_list[] return str_list[val]; } +static const char *attr_bool_to_string(void *attr, bool *to_free) +{ + bool val = (bool)attr; + + *to_free = false; + if (val) + return "true"; + return "false"; +} + static const char *attr_speed_to_string(void *attr, bool *to_free) { return attr_enum_to_string(attr, speed_str_list, to_free); @@ -166,6 +176,37 @@ static int attr_string_filter(void *attr, const char *input, int *err) return false; } +static int attr_bool_filter(void *attr, const char *input, int *err) +{ + int i, input_int = -1; + long val = (long)attr; + const char *input_str = NULL; + + for (i = 0; input[i]; i++) { + if (!strchr(op_list, input[i])) { + input_str = input + i; + break; + } + } + + if (!input_str) { + *err = -EINVAL; + pr_err("kunit executor: filter value not found: %s\n", input); + return false; + } + + if (!strcmp(input_str, "true")) + input_int = (int)true; + else if (!strcmp(input_str, "false")) + input_int = (int)false; + else { + *err = -EINVAL; + pr_err("kunit executor: invalid filter input: %s\n", input); + return false; + } + + return int_filter(val, input, input_int, err); +} /* Get Attribute Methods */ @@ -194,6 +235,17 @@ static void *attr_module_get(void *test_or_suite, bool is_test) return (void *) ""; } +static void *attr_is_init_get(void *test_or_suite, bool is_test) +{ + struct kunit_suite *suite = is_test ? NULL : test_or_suite; + struct kunit_case *test = is_test ? test_or_suite : NULL; + + if (test) + return ((void *) test->attr.is_init); + else + return ((void *) suite->attr.is_init); +} + /* List of all Test Attributes */ static struct kunit_attr kunit_attr_list[] = { @@ -212,6 +264,14 @@ static struct kunit_attr kunit_attr_list[] = { .filter = attr_string_filter, .attr_default = (void *)"", .print = PRINT_SUITE, + }, + { + .name = "is_init", + .get_attr = attr_is_init_get, + .to_string = attr_bool_to_string, + .filter = attr_bool_filter, + .attr_default = (void *)false, + .print = PRINT_SUITE, } }; diff --git a/lib/kunit/executor.c b/lib/kunit/executor.c index 847329c51e91..594de994161a 100644 --- a/lib/kunit/executor.c +++ b/lib/kunit/executor.c @@ -300,6 +300,7 @@ struct kunit_suite_set kunit_merge_suite_sets(struct kunit_suite_set init_suite_ struct kunit_suite_set total_suite_set = {NULL, NULL}; struct kunit_suite **total_suite_start = NULL; size_t init_num_suites, num_suites, suite_size; + int i = 0; init_num_suites = init_suite_set.end - init_suite_set.start; num_suites = suite_set.end - suite_set.start; @@ -310,8 +311,11 @@ struct kunit_suite_set kunit_merge_suite_sets(struct kunit_suite_set init_suite_ if (!total_suite_start) return total_suite_set; - /* Append init suites and then all other kunit suites */ + /* Append and mark init suites and then append all other kunit suites */ memcpy(total_suite_start, init_suite_set.start, init_num_suites * suite_size); + for (i = 0; i < init_num_suites; i++) + total_suite_start[i]->attr.is_init = true; + memcpy(total_suite_start + init_num_suites, suite_set.start, num_suites * suite_size); /* Set kunit suite set start and end */ -- 2.43.0.rc2.451.g8631bc7472-goog