diff mbox series

[v4,4/6] drm/tests: managed: Add comments and expect fail messages

Message ID 20240105101324.26811-5-michal.winiarski@intel.com (mailing list archive)
State New, archived
Headers show
Series drm/managed: Add drmm_release_action | expand

Commit Message

Michał Winiarski Jan. 5, 2024, 10:13 a.m. UTC
Add comments explaining the intention behind the test and certain
implementation details related to device lifetime.

Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
---
 drivers/gpu/drm/tests/drm_managed_test.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Comments

Maxime Ripard Jan. 8, 2024, 10:47 a.m. UTC | #1
On Fri, Jan 05, 2024 at 11:13:22AM +0100, Michał Winiarski wrote:
> Add comments explaining the intention behind the test and certain
> implementation details related to device lifetime.
> 
> Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
> ---
>  drivers/gpu/drm/tests/drm_managed_test.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/tests/drm_managed_test.c b/drivers/gpu/drm/tests/drm_managed_test.c
> index e4790ae838ba7..986a38c9144a5 100644
> --- a/drivers/gpu/drm/tests/drm_managed_test.c
> +++ b/drivers/gpu/drm/tests/drm_managed_test.c
> @@ -19,6 +19,10 @@ static void drm_action(struct drm_device *drm, void *ptr)
>  	priv->action_done = true;
>  }
>  
> +/*
> + * The test verifies that the release action is called automatically when the
> + * device is released.
> + */
>  static void drm_test_managed_run_action(struct kunit *test)
>  {
>  	struct managed_test_priv *priv;
> @@ -32,6 +36,11 @@ static void drm_test_managed_run_action(struct kunit *test)
>  	dev = drm_kunit_helper_alloc_device(test);
>  	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
>  
> +	/*
> +	 * DRM device can't be embedded in priv, since priv->action_done needs
> +	 * to remain allocated beyond both parent device and drm_device
> +	 * lifetime.
> +	 */
>  	drm = __drm_kunit_helper_alloc_drm_device(test, dev, sizeof(*drm), 0, DRIVER_MODESET);
>  	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm);
>  
> @@ -44,7 +53,7 @@ static void drm_test_managed_run_action(struct kunit *test)
>  	drm_dev_unregister(drm);
>  	drm_kunit_helper_free_device(test, dev);
>  
> -	KUNIT_EXPECT_TRUE(test, priv->action_done);
> +	KUNIT_EXPECT_TRUE_MSG(test, priv->action_done, "Release action was not called");

I'm fine with the other two comments, but I'm not really sure what that
message brings to the table. It should be pretty obvious from the
function name, variable name and comments already.

Maxime
diff mbox series

Patch

diff --git a/drivers/gpu/drm/tests/drm_managed_test.c b/drivers/gpu/drm/tests/drm_managed_test.c
index e4790ae838ba7..986a38c9144a5 100644
--- a/drivers/gpu/drm/tests/drm_managed_test.c
+++ b/drivers/gpu/drm/tests/drm_managed_test.c
@@ -19,6 +19,10 @@  static void drm_action(struct drm_device *drm, void *ptr)
 	priv->action_done = true;
 }
 
+/*
+ * The test verifies that the release action is called automatically when the
+ * device is released.
+ */
 static void drm_test_managed_run_action(struct kunit *test)
 {
 	struct managed_test_priv *priv;
@@ -32,6 +36,11 @@  static void drm_test_managed_run_action(struct kunit *test)
 	dev = drm_kunit_helper_alloc_device(test);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
 
+	/*
+	 * DRM device can't be embedded in priv, since priv->action_done needs
+	 * to remain allocated beyond both parent device and drm_device
+	 * lifetime.
+	 */
 	drm = __drm_kunit_helper_alloc_drm_device(test, dev, sizeof(*drm), 0, DRIVER_MODESET);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm);
 
@@ -44,7 +53,7 @@  static void drm_test_managed_run_action(struct kunit *test)
 	drm_dev_unregister(drm);
 	drm_kunit_helper_free_device(test, dev);
 
-	KUNIT_EXPECT_TRUE(test, priv->action_done);
+	KUNIT_EXPECT_TRUE_MSG(test, priv->action_done, "Release action was not called");
 }
 
 static struct kunit_case drm_managed_tests[] = {