Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp8781741rwp; Wed, 19 Jul 2023 15:32:07 -0700 (PDT) X-Google-Smtp-Source: APBJJlE4Gr8TxjXqLgjSSpVwDzAngbicj56t7NFN5I2EItzgG1e04ML8z7kZiJry1IaPYyBUrlmb X-Received: by 2002:a17:906:2343:b0:982:30e3:ddcb with SMTP id m3-20020a170906234300b0098230e3ddcbmr3486028eja.65.1689805927375; Wed, 19 Jul 2023 15:32:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689805927; cv=none; d=google.com; s=arc-20160816; b=Rq/kSxSOtbd/D03aFx5rWqKwBE1XRyGd09lx3MovzkmgQZdDHki39JIQd4LKH3YrC/ +yw859i/PURUC7LfkIot8I2H8pWHO58QSLUidmbCkWln87lly8BwPA8PhO0EpZRi75EX uoW/hl13ldBO4Ib5zBusvIWnsOz7+MaCzezx8nQ48yprx+r44gra8pV5Eggk+Ft1FWyT /Z69c2Qq5eDEYFBdZrD4XUZAhFdUkgihG0kPm+JJveXmFs+5TZnet7E9sEcC8/QEpns/ P6S/lNYcOxeB/9qLbXgtFtP2WX3rhN505/9kqaqekSJy6T4wA3qogmM8RxkQZokFdL+D ye4A== 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=Rd3boOdAlfH2nRM3+RX0LZSIemRKG8MVf9sKC/jWVn8=; fh=eSOGplXNKm0TQlVMiAPjma3ZxjxuDQ0l9LD5ETEQPUY=; b=KesDEnZRYwL3ysBvmINTEB6e47PiaY+dZlaOZg3gzVM756329Q7VITjjNvwDRiGw9r yTjzMsdZ9u9kXACePUwVtOVe2JA9DfBhUI0VcLgxeZqokwBN6v98ostfHaZl/M2iDKLN wSCeGvD+1kbhyoVIbN0MXpKhiNqIQjwVD3kFfXkUd3dfNhKRPQXrW0A82iuxEEj2HX2y ZgFVmb6fy593qyck5lLocDfhYO7YDwP7WXtb4kqUN2d4Pz4rL8FM9au+cfo2hxA4eMkc GIuNnBCZiOJWuDof85THSKa2m8oyzV5MBIF3kRv1HYp75FTP1QME/hulo9Fe4WF/YmId Tcuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=ZxrsLCF8; 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 gh5-20020a170906e08500b0098cd60e4571si3531631ejb.801.2023.07.19.15.31.42; Wed, 19 Jul 2023 15:32:07 -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=ZxrsLCF8; 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 S230318AbjGSWYI (ORCPT + 99 others); Wed, 19 Jul 2023 18:24:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229622AbjGSWYA (ORCPT ); Wed, 19 Jul 2023 18:24:00 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94BCD2112 for ; Wed, 19 Jul 2023 15:23:57 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-bd69bb4507eso112798276.2 for ; Wed, 19 Jul 2023 15:23:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689805436; x=1692397436; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Rd3boOdAlfH2nRM3+RX0LZSIemRKG8MVf9sKC/jWVn8=; b=ZxrsLCF8zArTqOVJ6JX4jfVhGjbQDfz604yPryk2p5bCmj3ZcxkurE6OosjJIz2dqe 1wrHH00+ExltFh++DlxRaxwseeAZaN/WsUt4cc18viWQTwhfQNhUOD6xiH8fAFt546wk /Lwjx6v4/dapgFODMZg9a4bTtx0vMOXdxBluDQi6ZPE6ZULysdMCV9jn4M4xXEjamXaX QOPS7HCzF0iImxVDcPXS0qWQiWnVUwVoLrvU0zzVb0CNZWBs9BYywXExdHg9fxrc4HJZ NtXX1MKs05AABQQ/0jjgKpU2J1Mwfoz2JcXiAGPwWN3UD+1etnHzP4AYg0Psx0SKTCEi pt4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689805436; x=1692397436; 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=Rd3boOdAlfH2nRM3+RX0LZSIemRKG8MVf9sKC/jWVn8=; b=bYUp+L6SqlyIzG5+yRcMfFpeknnUxgoF22w0Y/WjsiaFh5jkSqnw8f8NZZKTWogdI/ dPY57hZupHiXuJJ2RyumanvcLpBPbUK5eFqEy1lC56+ThqPjGtu9e/nNi75V8ytWO7nz gekh6tEo508kiUu0HvJqkqBX4XCFtrH6W/sGuN1UljQq1Fq0uzN8V8r7ST0tp5ghzzxI xPybz37bc2Ihhi+YNjmlmgBWlJO7vcdp1Mi/EZcz8M3EzdqlnLSsAEUWoe913U//FVjC JABg88MOEdPqps5ptL1fRlFWw1FRLD4tDbUi5Q5YjrwHFFvzWRnclBmvorwZWT/BRg+W g+hQ== X-Gm-Message-State: ABy/qLZks0wyGMl//ivDRqrB4iavcCcZnWz+xx2daMHuM+7tPKL3tTd5 w3bXnU+bJe6PBARldoqxEyO5QcpsSw== X-Received: from rmoar-specialist.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:45d3]) (user=rmoar job=sendgmr) by 2002:a25:ab04:0:b0:bfe:ea69:91b4 with SMTP id u4-20020a25ab04000000b00bfeea6991b4mr29862ybi.4.1689805436512; Wed, 19 Jul 2023 15:23:56 -0700 (PDT) Date: Wed, 19 Jul 2023 22:23:30 +0000 In-Reply-To: <20230719222338.259684-1-rmoar@google.com> Mime-Version: 1.0 References: <20230719222338.259684-1-rmoar@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230719222338.259684-4-rmoar@google.com> Subject: [PATCH v1 3/9] kunit: Add module attribute 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 module attribute to the test attribute API. This attribute stores the module name associated with the test using KBUILD_MODNAME. The name of a test suite and the module name often do not match. A reference to the module name associated with the suite could be extremely helpful in running tests as modules without needing to check the codebase. This attribute will be printed for each suite. Reviewed-by: David Gow Signed-off-by: Rae Moar --- Changes since RFC v2: - No changes. Changes: since RFC v1: - This is a new patch. include/kunit/test.h | 13 ++++++++----- lib/kunit/attributes.c | 28 +++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/include/kunit/test.h b/include/kunit/test.h index ed5f5000a095..011e0d6bb506 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -131,6 +131,7 @@ struct kunit_case { /* private: internal use only. */ enum kunit_status status; + char *module_name; char *log; }; @@ -155,7 +156,9 @@ static inline char *kunit_status_to_ok_not_ok(enum kunit_status status) * &struct kunit_case object from it. See the documentation for * &struct kunit_case for an example on how to use it. */ -#define KUNIT_CASE(test_name) { .run_case = test_name, .name = #test_name } +#define KUNIT_CASE(test_name) \ + { .run_case = test_name, .name = #test_name, \ + .module_name = KBUILD_MODNAME} /** * KUNIT_CASE_ATTR - A helper for creating a &struct kunit_case @@ -167,7 +170,7 @@ static inline char *kunit_status_to_ok_not_ok(enum kunit_status status) */ #define KUNIT_CASE_ATTR(test_name, attributes) \ { .run_case = test_name, .name = #test_name, \ - .attr = attributes } + .attr = attributes, .module_name = KBUILD_MODNAME} /** * KUNIT_CASE_SLOW - A helper for creating a &struct kunit_case @@ -178,7 +181,7 @@ static inline char *kunit_status_to_ok_not_ok(enum kunit_status status) #define KUNIT_CASE_SLOW(test_name) \ { .run_case = test_name, .name = #test_name, \ - .attr.speed = KUNIT_SPEED_SLOW } + .attr.speed = KUNIT_SPEED_SLOW, .module_name = KBUILD_MODNAME} /** * KUNIT_CASE_PARAM - A helper for creation a parameterized &struct kunit_case @@ -199,7 +202,7 @@ static inline char *kunit_status_to_ok_not_ok(enum kunit_status status) */ #define KUNIT_CASE_PARAM(test_name, gen_params) \ { .run_case = test_name, .name = #test_name, \ - .generate_params = gen_params } + .generate_params = gen_params, .module_name = KBUILD_MODNAME} /** * KUNIT_CASE_PARAM_ATTR - A helper for creating a parameterized &struct @@ -213,7 +216,7 @@ static inline char *kunit_status_to_ok_not_ok(enum kunit_status status) #define KUNIT_CASE_PARAM_ATTR(test_name, gen_params, attributes) \ { .run_case = test_name, .name = #test_name, \ .generate_params = gen_params, \ - .attr = attributes } + .attr = attributes, .module_name = KBUILD_MODNAME} /** * struct kunit_suite - describes a related collection of &struct kunit_case diff --git a/lib/kunit/attributes.c b/lib/kunit/attributes.c index e97096dbb3b1..43dcb5de8b8f 100644 --- a/lib/kunit/attributes.c +++ b/lib/kunit/attributes.c @@ -61,6 +61,12 @@ static const char *attr_speed_to_string(void *attr, bool *to_free) return attr_enum_to_string(attr, speed_str_list, to_free); } +static const char *attr_string_to_string(void *attr, bool *to_free) +{ + *to_free = false; + return (char *) attr; +} + /* Get Attribute Methods */ static void *attr_speed_get(void *test_or_suite, bool is_test) @@ -74,6 +80,18 @@ static void *attr_speed_get(void *test_or_suite, bool is_test) return ((void *) suite->attr.speed); } +static void *attr_module_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; + + // Suites get their module attribute from their first test_case + if (test) + return ((void *) test->module_name); + else + return ((void *) suite->test_cases[0].module_name); +} + /* Attribute Struct Definitions */ static const struct kunit_attr speed_attr = { @@ -84,9 +102,17 @@ static const struct kunit_attr speed_attr = { .print = PRINT_ALWAYS, }; +static const struct kunit_attr module_attr = { + .name = "module", + .get_attr = attr_module_get, + .to_string = attr_string_to_string, + .attr_default = (void *)"", + .print = PRINT_SUITE, +}; + /* List of all Test Attributes */ -static struct kunit_attr kunit_attr_list[] = {speed_attr}; +static struct kunit_attr kunit_attr_list[] = {speed_attr, module_attr}; /* Helper Functions to Access Attributes */ -- 2.41.0.255.g8b1d071c50-goog