LCOV - code coverage report
Current view: top level - drivers/gpu/drm/tests - drm_managed_test.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 22 22 100.0 %
Date: 2023-04-06 08:38:28 Functions: 2 2 100.0 %

          Line data    Source code
       1             : // SPDX-License-Identifier: GPL-2.0
       2             : 
       3             : #include <drm/drm_drv.h>
       4             : #include <drm/drm_kunit_helpers.h>
       5             : #include <drm/drm_managed.h>
       6             : 
       7             : #include <kunit/resource.h>
       8             : 
       9             : #include <linux/device.h>
      10             : 
      11             : /* Ought to be enough for anybody */
      12             : #define TEST_TIMEOUT_MS 100
      13             : 
      14             : struct managed_test_priv {
      15             :         bool action_done;
      16             :         wait_queue_head_t action_wq;
      17             : };
      18             : 
      19           1 : static void drm_action(struct drm_device *drm, void *ptr)
      20             : {
      21           1 :         struct managed_test_priv *priv = ptr;
      22             : 
      23           1 :         priv->action_done = true;
      24           1 :         wake_up_interruptible(&priv->action_wq);
      25           1 : }
      26             : 
      27           1 : static void drm_test_managed_run_action(struct kunit *test)
      28             : {
      29             :         struct managed_test_priv *priv;
      30             :         struct drm_device *drm;
      31             :         struct device *dev;
      32             :         int ret;
      33             : 
      34           1 :         priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL);
      35           2 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv);
      36           1 :         init_waitqueue_head(&priv->action_wq);
      37             : 
      38           1 :         dev = drm_kunit_helper_alloc_device(test);
      39           2 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
      40             : 
      41           1 :         drm = __drm_kunit_helper_alloc_drm_device(test, dev, sizeof(*drm), 0, DRIVER_MODESET);
      42           2 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm);
      43             : 
      44           1 :         ret = drmm_add_action_or_reset(drm, drm_action, priv);
      45           1 :         KUNIT_EXPECT_EQ(test, ret, 0);
      46             : 
      47           1 :         ret = drm_dev_register(drm, 0);
      48           1 :         KUNIT_ASSERT_EQ(test, ret, 0);
      49             : 
      50           1 :         drm_dev_unregister(drm);
      51           1 :         drm_kunit_helper_free_device(test, dev);
      52             : 
      53           1 :         ret = wait_event_interruptible_timeout(priv->action_wq, priv->action_done,
      54             :                                                msecs_to_jiffies(TEST_TIMEOUT_MS));
      55           1 :         KUNIT_EXPECT_GT(test, ret, 0);
      56           1 : }
      57             : 
      58             : static struct kunit_case drm_managed_tests[] = {
      59             :         KUNIT_CASE(drm_test_managed_run_action),
      60             :         {}
      61             : };
      62             : 
      63             : static struct kunit_suite drm_managed_test_suite = {
      64             :         .name = "drm-test-managed",
      65             :         .test_cases = drm_managed_tests
      66             : };
      67             : 
      68             : kunit_test_suite(drm_managed_test_suite);
      69             : 
      70             : MODULE_AUTHOR("Maxime Ripard <maxime@cerno.tech>");
      71             : MODULE_LICENSE("GPL");

Generated by: LCOV version 1.14