From patchwork Thu Jul 20 11:15:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 123198 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp3044058vqt; Thu, 20 Jul 2023 04:20:34 -0700 (PDT) X-Google-Smtp-Source: APBJJlHQQFVXVpFEy5rf89U7nSH8hMes/vhls5l3kRT5SdwPzCafaOmp9a2iMyZa1A4jqdrmWzVv X-Received: by 2002:a05:6402:1295:b0:51a:3159:53c7 with SMTP id w21-20020a056402129500b0051a315953c7mr4461349edv.30.1689852034311; Thu, 20 Jul 2023 04:20:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689852034; cv=none; d=google.com; s=arc-20160816; b=TCAtNfzrSQmJeHe18YWXdp7SZmapCSsXCMP/PCJikWKEzvGf17Js5sqHfeSsXqTxA1 pNIG+hKorETu5DMJC4B8zsEPXYasDd4H9ayQmVa0KY28C0CMAYWVgZpFrO3YejF4GF8T a/vyXQa2ocIQD7Rf8mRevtpdhwibNWKwXibX3j2dVzzUcH/7X+is+5R46KuNTV61qcOE pTPCI7BJDsYGQFMNanp4dR71nfs+OOhAcbqwpMqhRsk1CQhiAgUhUBO/8ON69GCLkne6 JKShSQafrOjDj8hGJOmAjNMxN0M7jT2BpQd1gXRprtnlsG+fDwft/MqnhhQCbZEpEME0 amwA== 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=eqrhzIYNn52lMZe4570iCTbn1rTyWaMEUi5d/UX23k8=; fh=r3YnEVRF2ge3yIgpTE2H86lvFoURZyw1nrIW71mPVsw=; b=qgxVD3Z1knwzjwORne7eKdPePkl70DBr6fTICa4573oBN4uMdJAj5Xh/C9FQvf5xzz wJBcT2paj0XPFp5SOr+1zIbLeTjg/I7RVkqZ6gGXcQZqX4UBbyL11+GhvcjDjFJFzoiv vOlr6D4pYEdFWVkQpHUlV1ddqaxEgEHHE3dYvuac/7oFyqPNcF/cZNw2YHl/SKcDG6CO cC6FwCLxFUxlrMYTerxaoe35s7zRL1Bmpv3Y2CYyN1wEP6+XvL7FHBhPYft8OjSol8ZN RbIWw0aCbS+qSmH0Qs775+K6i97gX3J1AzCLilHVKNSBG4zAeMuUEiABErm1XAWc9Zai ZjBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=peC6XHDl; 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 bc6-20020a056402204600b0051e0d936760si670824edb.14.2023.07.20.04.20.10; Thu, 20 Jul 2023 04:20:34 -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=peC6XHDl; 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 S230493AbjGTLQk (ORCPT + 99 others); Thu, 20 Jul 2023 07:16:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230169AbjGTLQd (ORCPT ); Thu, 20 Jul 2023 07:16:33 -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 31D152706; Thu, 20 Jul 2023 04:16:11 -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 7C43C61A33; Thu, 20 Jul 2023 11:16:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67340C433C8; Thu, 20 Jul 2023 11:16:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689851769; bh=CXPsdCVxz77cgfDGMI4BSalP4ePPYu8Tjf40VvpURr4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=peC6XHDlEo9ViqK8GjRcdygHlyFRs4WTMcmRssoW59KEKeh3xvg9kpYr+4c/3R7Wq d6VUIrqPvsBxv6MWCQ5huSN+Nm/oOFrtPjBeL8gJa5oeL8o4dpLIRv9w89rkWloDuu aWaEQJgNtCOvyv0ELmmuFoy3xKTS1uxGQyvCd6lTaFFIQoyFgu8mwaB4u0g6uJyHV5 A4ET8iadCrvlGJ2doFhrrWS1SeVwHIEknYq1+VDbRysTskWEB12h1ho0qMIOZ6anUk 7tGJfrB6SdjO3/PE+RR6eh17XxtlvOFBzLRNXtfKPPdOA5/gY7EW1TfVWjHUPfecgF kHeyl98s0yTnQ== From: Maxime Ripard Date: Thu, 20 Jul 2023 13:15:50 +0200 Subject: [PATCH v2 05/11] drm/tests: helpers: Create a helper to allocate a locking ctx MIME-Version: 1.0 Message-Id: <20230720-kms-kunit-actions-rework-v2-5-175017bd56ab@kernel.org> References: <20230720-kms-kunit-actions-rework-v2-0-175017bd56ab@kernel.org> In-Reply-To: <20230720-kms-kunit-actions-rework-v2-0-175017bd56ab@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=2652; i=mripard@kernel.org; h=from:subject:message-id; bh=CXPsdCVxz77cgfDGMI4BSalP4ePPYu8Tjf40VvpURr4=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDCk7xTOKj0Vt+pHu+uzCVas+w/2m0qWbm/zXOqXZ+9/5s WffA9XVHaUsDGJcDLJiiiwxwuZL4k7Net3JxjcPZg4rE8gQBi5OAZgIz39Ghom3ShRDzrhZBcdO va37oeD4z0v8+153n3Xb6rP+bXcN90ZGhrcd5V85I9QfbDk3gYlrVqGr4CWpsC/SnrUuJ9q4Vx5 7zQkA X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,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: 1771938286617991990 X-GMAIL-MSGID: 1771938286617991990 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 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 5856beb7f7d7..5130d4553262 100644 --- a/drivers/gpu/drm/tests/drm_kunit_helpers.c +++ b/drivers/gpu/drm/tests/drm_kunit_helpers.c @@ -120,5 +120,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_