From patchwork Mon Jul 10 07:47:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 117686 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp4857467vqx; Mon, 10 Jul 2023 01:00:02 -0700 (PDT) X-Google-Smtp-Source: APBJJlFtWgXbr0BAw+/Jpg5E7ktUtZuUMzt5JtdbQZT5ETSCFt85KrUSO50tfGUve1avq0Z9cyKJ X-Received: by 2002:a17:902:e843:b0:1b8:847d:973a with SMTP id t3-20020a170902e84300b001b8847d973amr10998509plg.46.1688976002132; Mon, 10 Jul 2023 01:00:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688976002; cv=none; d=google.com; s=arc-20160816; b=agRC0IyXObB5PrY7ZhVlBgupamNSXxmKLri20uklCtN3ezRE6+iE9Q8bmYdRxYuQUy Qf3WoSalkTG1mVhgz4C0BgUjG0GWe5O24tBBE16EWXdEQLqsIwSlS17EreeDpK48sk9m uXLADq9flid7CF5eZOrWy7fdlnWTQHxiIUAOGuSx911/R2M6Um773bPojeGbHCcAKPPy 8NRp6qoMt2lb8eOXXMqwcQG36xOwtY2Zv1WQTXchHY5WlyxRHqC3tJo6snKxJ2KRgcAj I+ZvngkxDYMwl2QoyfkCRdBHt1EbQr1fZP+m3Kd/GJwNZVupvQe7nEh6vOZeX1Hk3U1D 2yKw== 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=ycbTDumWZCBlJlDRRP8Hjfn2gMHVpQe79ycN6HC1rio=; fh=hv+BGfRnZKm/Mx7Um70Asy2r1y7Zqr2lNnN/bFBL5yk=; b=K948vGf710vozJPVvwYnmbyY5x8MpnQIBF0vtO5hBVw5tBbJZRqvlq/OEmq6Rak7Fh ZmDIVS8vztFkYYk2cxfXcn8JKPv8PqzhN7Opk7+C3262Bd/2hr/y93ccbuMxFxti0/HF zi7mRZxDFIHuvESzgbnk2YE4rV/ciuUqRX1kHgWpw6hw4vys6HqOoeYuKsOH+Zm6NHoK iC5rMPtW9jTNOyDm1PPGo2Vg3HSwhF2H0m2mrIsxV8Hgruy2TinTdUDm9tatefIcfpPU vVUjfTan1g0k2/BxryhhG/sb6vT4RJ74K2pVftlX/XNTasF8qgA3b9oGQfsLHTi3PIll 9peA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ev0++KRl; 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 p18-20020a170902ebd200b001b9d2982365si3782054plg.34.2023.07.10.00.59.49; Mon, 10 Jul 2023 01:00:02 -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=Ev0++KRl; 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 S232004AbjGJHtU (ORCPT + 99 others); Mon, 10 Jul 2023 03:49:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232152AbjGJHsD (ORCPT ); Mon, 10 Jul 2023 03:48:03 -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 044EE115 for ; Mon, 10 Jul 2023 00:48:00 -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 8B57A60EC0 for ; Mon, 10 Jul 2023 07:47:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97EA5C433CC; Mon, 10 Jul 2023 07:47:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1688975279; bh=yyOzLwcA8+MLX2ZufFLGFyhRNFINdgUwJ7WOz6NATOo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Ev0++KRl7X5fDJRzgC0KAVucSZOr90RLppLhwpgBemBAj0uuGAmS64AiBnjD0BY2B 2FwR4AWNDTstXQvI+Dgid9oYaA15ir6wStflexPmIN5QFu+qkajBJTAPazNv6i1Lxz b6xsXQycMFMEUUU4nMaLMhALmIvUG4gUWWk/lSB1LHA64LzwBSIl5Uf+4j/JGwgixv hUkPONa3CBweO0S5I/cLcDvGtWYDX/Mb8G9+5b0viXN2z30dpaY0ChdZASLqGbU6hB 9ELLjgCoIgzmNcPhc4YJ8vs95K3nQDP8bwyuKEkI7svKD9xdgaWNrGQ3eNoOBws2Yr 0CeRp8RNOhE2w== From: Maxime Ripard Date: Mon, 10 Jul 2023 09:47:37 +0200 Subject: [PATCH 06/11] drm/tests: helpers: Create an helper to allocate an atomic state MIME-Version: 1.0 Message-Id: <20230710-kms-kunit-actions-rework-v1-6-722c58d72c72@kernel.org> References: <20230710-kms-kunit-actions-rework-v1-0-722c58d72c72@kernel.org> In-Reply-To: <20230710-kms-kunit-actions-rework-v1-0-722c58d72c72@kernel.org> To: David Airlie , Daniel Vetter , Maarten Lankhorst , Thomas Zimmermann , Emma Anholt Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Maxime Ripard X-Mailer: b4 0.13-dev-099c9 X-Developer-Signature: v=1; a=openpgp-sha256; l=2824; i=mripard@kernel.org; h=from:subject:message-id; bh=yyOzLwcA8+MLX2ZufFLGFyhRNFINdgUwJ7WOz6NATOo=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDCmrt8842N69JPSDNsPi6Zu3qvItcm0TqDt+kOVibJP3lbLd HX3rOkpZGMS4GGTFFFlihM2XxJ2a9bqTjW8ezBxWJpAhDFycAjCR6DaGvxKPdc1f2L4P9kvNubCEn3 PG/TUvDI9tWSTr3HXj9+Xb1VMYGXb8zG2IPMnMGsP0aM6lSU+vNJzrS+6dPqWh8q3f8b7E3TwA 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: 1771019700798157682 X-GMAIL-MSGID: 1771019700798157682 As we gain more tests, boilerplate to allocate an atomic state and free it starts to be there more and more as well. In order to reduce the allocation boilerplate, we can create an helper to create that atomic state, and call an action when the test is done. This will also clean up the exit path. Signed-off-by: Maxime Ripard Reviewed-by: Javier Martinez Canillas --- drivers/gpu/drm/tests/drm_kunit_helpers.c | 39 +++++++++++++++++++++++++++++++ include/drm/drm_kunit_helpers.h | 5 ++++ 2 files changed, 44 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_kunit_helpers.c b/drivers/gpu/drm/tests/drm_kunit_helpers.c index 40a27c78d692..3f3331bc389f 100644 --- a/drivers/gpu/drm/tests/drm_kunit_helpers.c +++ b/drivers/gpu/drm/tests/drm_kunit_helpers.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 +#include #include #include #include @@ -165,5 +166,43 @@ drm_kunit_helper_acquire_ctx_alloc(struct kunit *test) } EXPORT_SYMBOL_GPL(drm_kunit_helper_acquire_ctx_alloc); +/** + * drm_kunit_helper_atomic_state_alloc - Allocates an atomic state + * @test: The test context object + * @drm: The device to alloc the state for + * @ctx: Locking context for that atomic update + * + * Allocates a empty atomic state. + * + * The state is tied to the kunit test context, so we must not call + * drm_atomic_state_put() on it, it will be done so automatically. + * + * Returns: + * An ERR_PTR on error, a pointer to the newly allocated state otherwise + */ +struct drm_atomic_state * +drm_kunit_helper_atomic_state_alloc(struct kunit *test, + struct drm_device *drm, + struct drm_modeset_acquire_ctx *ctx) +{ + struct drm_atomic_state *state; + int ret; + + state = drm_atomic_state_alloc(drm); + if (!state) + return ERR_PTR(-ENOMEM); + + ret = kunit_add_action_or_reset(test, + (kunit_action_t *)drm_atomic_state_put, + state); + if (ret) + return ERR_PTR(ret); + + state->acquire_ctx = ctx; + + return state; +} +EXPORT_SYMBOL_GPL(drm_kunit_helper_atomic_state_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 4ba5e10653c6..514c8a7a32f0 100644 --- a/include/drm/drm_kunit_helpers.h +++ b/include/drm/drm_kunit_helpers.h @@ -90,4 +90,9 @@ __drm_kunit_helper_alloc_drm_device(struct kunit *test, struct drm_modeset_acquire_ctx * drm_kunit_helper_acquire_ctx_alloc(struct kunit *test); +struct drm_atomic_state * +drm_kunit_helper_atomic_state_alloc(struct kunit *test, + struct drm_device *drm, + struct drm_modeset_acquire_ctx *ctx); + #endif // DRM_KUNIT_HELPERS_H_