From patchwork Fri Jul 28 09:06:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 127467 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp311707vqg; Fri, 28 Jul 2023 02:39:20 -0700 (PDT) X-Google-Smtp-Source: APBJJlEa7oKoOAZLWf1TZhQ+CeAF1nhQkS0grFPFU6Fw4OH+bYHgzibz1V/s+BUzjM8MyovIejrQ X-Received: by 2002:a05:6512:e9c:b0:4f9:72a5:2b76 with SMTP id bi28-20020a0565120e9c00b004f972a52b76mr1544697lfb.65.1690537159766; Fri, 28 Jul 2023 02:39:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690537159; cv=none; d=google.com; s=arc-20160816; b=nHT0ok2PWs4NIGo1O2ZhkUUhCQLf9bwAvKVNvzqg+75ni1peAJmjW14id53Lax3AyT UFdYIpiVxcuD1MZ/ADiK/e1LMrD8cglLFBUEq11ixSZIO51Ie8TDgLxQf5fdPgae0l8m YxN+O2C/tUoKb9dNv2U7KIayRZU/VDJWkflJzWCjsPfwXwfMLTqBwCsMMBtb8MwJJMoy wF0A4EipqBtCb6mEjjGqXhCBBrPie3HBwVeIqPeBJZXslGLkLLofowviEYcN5mUAWKu7 EaM6IOmvpbBRJayp4ncaVwRKlkSwneuqBj/PpJDI9IUgocUO7LcB7JPthfRUpdbuf7Eh CgSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=XGoSUVc6/th7389d/S9oD6WemPACbzku6Nmq6ZtUb8w=; fh=r3YnEVRF2ge3yIgpTE2H86lvFoURZyw1nrIW71mPVsw=; b=FZOCJgR0UGHb3+bjQ1sKmGpzt6Qu+GfNDjI47RF6BJZTuSUaz3Cx1t71n7Hlx9Lmbw GlXlccb8Br4gYFSP5SxFYaQOnkM67O1T1q0FlzDxkboKJTI5vx49aPOnxlBajB282Shj RAqIy12G8nTODcLxNGvljFB7Gn0eB8JFeJmW1Acuz5Ccb0d4EHkzoNe3vZ+pzEYNDlAF PMQ14kCixWcG1zmCiqyTy3Ff5jhitzgYqfgnJtda7aZgJ735Otj0SzyDwjue3Nazurwj 4I5x6t01e882adb/b1j9fVHLz4PmkHPvZR7QBggORd6KZjTH0MY/MtLEh7FgQidt3kFn d0PQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BfiZkwkX; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t10-20020a17090616ca00b009662960f217si2409483ejd.303.2023.07.28.02.38.56; Fri, 28 Jul 2023 02:39:19 -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=@kernel.org header.s=k20201202 header.b=BfiZkwkX; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235220AbjG1JHM (ORCPT + 99 others); Fri, 28 Jul 2023 05:07:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235198AbjG1JGn (ORCPT ); Fri, 28 Jul 2023 05:06:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83B383C04; Fri, 28 Jul 2023 02:06:37 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0644862094; Fri, 28 Jul 2023 09:06:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14D09C433C9; Fri, 28 Jul 2023 09:06:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690535196; bh=rR8033KXv0zZnQXPCqyRQXfcEtV4ucVkU5KdD2FOX+8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=BfiZkwkXfy7WLkYzfOkdcBv5YfU7F+Q6m2UJj42jABhHfacU3cmqh0PjuF7IS/b4h ECdB6oA/6Ko8RKrd2STzJ59Is4h4eGABWIB8cOHccg4ujVpUoNjXL8ABQ8JBnE3G5F Pp3Nncbzfqz1BdDA7MdrzZcXmSHWefzo//YKrv2HjQlDrb/A2Q80UN6/AXm9oPVaqa pR9DkUc/xt9nqqSfwy1q7iXwM/L6g17WaovnTvK8UBz7hW8JQ2lYCmy4usRFRvT7zo GtqwpcxWC4YhZlhjq4DmbZrWn0L/+QC9CfKY2UkwGvpcDBFI5E6w/CEBhgHG9V3WvD JTNH2WVH5HIGA== From: Maxime Ripard Date: Fri, 28 Jul 2023 11:06:18 +0200 Subject: [PATCH v3 05/11] drm/tests: helpers: Create a helper to allocate a locking ctx MIME-Version: 1.0 Message-Id: <20230728-kms-kunit-actions-rework-v3-5-952565ccccfe@kernel.org> References: <20230728-kms-kunit-actions-rework-v3-0-952565ccccfe@kernel.org> In-Reply-To: <20230728-kms-kunit-actions-rework-v3-0-952565ccccfe@kernel.org> To: David Airlie , Daniel Vetter , Maarten Lankhorst , Thomas Zimmermann , Emma Anholt Cc: =?utf-8?q?Ma=C3=ADra_Canal?= , Javier Martinez Canillas , dri-devel@lists.freedesktop.org, David Gow , linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Maxime Ripard , Brendan Higgins X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2703; i=mripard@kernel.org; h=from:subject:message-id; bh=rR8033KXv0zZnQXPCqyRQXfcEtV4ucVkU5KdD2FOX+8=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDCmHW7muGUf+2Sg4L7NBgcdTNDtDcsE3iZN9HbUC4c+TG /SLuRg6SlkYxLgYZMUUWWKEzZfEnZr1upONbx7MHFYmkCEMXJwCMBEpZkaGhn3/ZzSfUDxXMq05 KVaBT3KeydettTYXL7gt2fjr0R51WYb/HmllL0TeCywrLAhO+H4mcPK31h09E6xz7rTWJZ87PKu WAwA= X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772656692969243635 X-GMAIL-MSGID: 1772656692969243635 As we get more and more tests, the locking context initialisation creates more and more boilerplate, both at creation and destruction. Let's create a helper that will allocate, initialise a context, and register kunit actions to clean up once the test is done. Reviewed-by: Javier Martinez Canillas Reviewed-by: MaĆ­ra Canal Signed-off-by: Maxime Ripard --- drivers/gpu/drm/tests/drm_kunit_helpers.c | 41 +++++++++++++++++++++++++++++++ include/drm/drm_kunit_helpers.h | 2 ++ 2 files changed, 43 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_kunit_helpers.c b/drivers/gpu/drm/tests/drm_kunit_helpers.c index cdf35421e641..35ea4a34909d 100644 --- a/drivers/gpu/drm/tests/drm_kunit_helpers.c +++ b/drivers/gpu/drm/tests/drm_kunit_helpers.c @@ -146,5 +146,46 @@ __drm_kunit_helper_alloc_drm_device_with_driver(struct kunit *test, } EXPORT_SYMBOL_GPL(__drm_kunit_helper_alloc_drm_device_with_driver); +static void action_drm_release_context(void *ptr) +{ + struct drm_modeset_acquire_ctx *ctx = ptr; + + drm_modeset_drop_locks(ctx); + drm_modeset_acquire_fini(ctx); +} + +/** + * drm_kunit_helper_context_alloc - Allocates an acquire context + * @test: The test context object + * + * Allocates and initializes a modeset acquire context. + * + * The context is tied to the kunit test context, so we must not call + * drm_modeset_acquire_fini() on it, it will be done so automatically. + * + * Returns: + * An ERR_PTR on error, a pointer to the newly allocated context otherwise + */ +struct drm_modeset_acquire_ctx * +drm_kunit_helper_acquire_ctx_alloc(struct kunit *test) +{ + struct drm_modeset_acquire_ctx *ctx; + int ret; + + ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, ctx); + + drm_modeset_acquire_init(ctx, 0); + + ret = kunit_add_action_or_reset(test, + action_drm_release_context, + ctx); + if (ret) + return ERR_PTR(ret); + + return ctx; +} +EXPORT_SYMBOL_GPL(drm_kunit_helper_acquire_ctx_alloc); + MODULE_AUTHOR("Maxime Ripard "); MODULE_LICENSE("GPL"); diff --git a/include/drm/drm_kunit_helpers.h b/include/drm/drm_kunit_helpers.h index ed013fdcc1ff..4ba5e10653c6 100644 --- a/include/drm/drm_kunit_helpers.h +++ b/include/drm/drm_kunit_helpers.h @@ -87,5 +87,7 @@ __drm_kunit_helper_alloc_drm_device(struct kunit *test, sizeof(_type), \ offsetof(_type, _member), \ _feat)) +struct drm_modeset_acquire_ctx * +drm_kunit_helper_acquire_ctx_alloc(struct kunit *test); #endif // DRM_KUNIT_HELPERS_H_