Skip to content

Commit

Permalink
drm/tests: helpers: rename generic helpers
Browse files Browse the repository at this point in the history
The creation of a dummy device in order to test managed interfaces is a
generally useful test feature. The drm test helpers
drm_kunit_helper_alloc_device() and drm_kunit_helper_free_device()
are doing exactly this. It makes no sense that each and every component
which intends to be testing managed interfaces will create similar
helpers so rename these to more generic format.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
  • Loading branch information
M-Vaittinen committed Mar 15, 2023
1 parent eeac8ed commit 15d07e7
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions drivers/gpu/drm/tests/drm_client_modeset_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static int drm_client_modeset_test_init(struct kunit *test)

test->priv = priv;

priv->dev = drm_kunit_helper_alloc_device(test);
priv->dev = test_kunit_helper_alloc_device(test);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv->dev);

priv->drm = __drm_kunit_helper_alloc_drm_device(test, priv->dev,
Expand All @@ -86,7 +86,7 @@ static void drm_client_modeset_test_exit(struct kunit *test)
{
struct drm_client_modeset_test_priv *priv = test->priv;

drm_kunit_helper_free_device(test, priv->dev);
test_kunit_helper_free_device(test, priv->dev);
}

static void drm_test_pick_cmdline_res_1920_1080_60(struct kunit *test)
Expand Down
16 changes: 8 additions & 8 deletions drivers/gpu/drm/tests/drm_kunit_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ static struct platform_driver fake_platform_driver = {
};

/**
* drm_kunit_helper_alloc_device - Allocate a mock device for a KUnit test
* test_kunit_helper_alloc_device - Allocate a mock device for a KUnit test
* @test: The test context object
*
* This allocates a fake struct &device to create a mock for a KUnit
* test. The device will also be bound to a fake driver. It will thus be
* able to leverage the usual infrastructure and most notably the
* device-managed resources just like a "real" device.
*
* Callers need to make sure drm_kunit_helper_free_device() on the
* Callers need to make sure test_kunit_helper_free_device() on the
* device when done.
*
* Returns:
* A pointer to the new device, or an ERR_PTR() otherwise.
*/
struct device *drm_kunit_helper_alloc_device(struct kunit *test)
struct device *test_kunit_helper_alloc_device(struct kunit *test)
{
struct platform_device *pdev;
int ret;
Expand All @@ -63,23 +63,23 @@ struct device *drm_kunit_helper_alloc_device(struct kunit *test)

return &pdev->dev;
}
EXPORT_SYMBOL_GPL(drm_kunit_helper_alloc_device);
EXPORT_SYMBOL_GPL(test_kunit_helper_alloc_device);

/**
* drm_kunit_helper_free_device - Frees a mock device
* test_kunit_helper_free_device - Frees a mock device
* @test: The test context object
* @dev: The device to free
*
* Frees a device allocated with drm_kunit_helper_alloc_device().
* Frees a device allocated with test_kunit_helper_alloc_device().
*/
void drm_kunit_helper_free_device(struct kunit *test, struct device *dev)
void test_kunit_helper_free_device(struct kunit *test, struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);

platform_device_unregister(pdev);
platform_driver_unregister(&fake_platform_driver);
}
EXPORT_SYMBOL_GPL(drm_kunit_helper_free_device);
EXPORT_SYMBOL_GPL(test_kunit_helper_free_device);

struct drm_device *
__drm_kunit_helper_alloc_drm_device_with_driver(struct kunit *test,
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpu/drm/tests/drm_managed_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static void drm_test_managed_run_action(struct kunit *test)
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv);
init_waitqueue_head(&priv->action_wq);

dev = drm_kunit_helper_alloc_device(test);
dev = test_kunit_helper_alloc_device(test);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);

drm = __drm_kunit_helper_alloc_drm_device(test, dev, sizeof(*drm), 0, DRIVER_MODESET);
Expand All @@ -48,7 +48,7 @@ static void drm_test_managed_run_action(struct kunit *test)
KUNIT_ASSERT_EQ(test, ret, 0);

drm_dev_unregister(drm);
drm_kunit_helper_free_device(test, dev);
test_kunit_helper_free_device(test, dev);

ret = wait_event_interruptible_timeout(priv->action_wq, priv->action_done,
msecs_to_jiffies(TEST_TIMEOUT_MS));
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpu/drm/tests/drm_modes_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static int drm_test_modes_init(struct kunit *test)
priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, priv);

priv->dev = drm_kunit_helper_alloc_device(test);
priv->dev = test_kunit_helper_alloc_device(test);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv->dev);

priv->drm = __drm_kunit_helper_alloc_drm_device(test, priv->dev,
Expand All @@ -40,7 +40,7 @@ static void drm_test_modes_exit(struct kunit *test)
{
struct drm_test_modes_priv *priv = test->priv;

drm_kunit_helper_free_device(test, priv->dev);
test_kunit_helper_free_device(test, priv->dev);
}

static void drm_test_modes_analog_tv_ntsc_480i(struct kunit *test)
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpu/drm/tests/drm_probe_helper_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static int drm_probe_helper_test_init(struct kunit *test)
KUNIT_ASSERT_NOT_NULL(test, priv);
test->priv = priv;

priv->dev = drm_kunit_helper_alloc_device(test);
priv->dev = test_kunit_helper_alloc_device(test);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv->dev);

priv->drm = __drm_kunit_helper_alloc_drm_device(test, priv->dev,
Expand All @@ -64,7 +64,7 @@ static void drm_probe_helper_test_exit(struct kunit *test)
{
struct drm_probe_helper_test_priv *priv = test->priv;

drm_kunit_helper_free_device(test, priv->dev);
test_kunit_helper_free_device(test, priv->dev);
}

typedef struct drm_display_mode *(*expected_mode_func_t)(struct drm_device *);
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/vc4/tests/vc4_mock.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ static struct vc4_dev *__mock_device(struct kunit *test, bool is_vc5)
struct device *dev;
int ret;

dev = drm_kunit_helper_alloc_device(test);
dev = test_kunit_helper_alloc_device(test);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);

vc4 = drm_kunit_helper_alloc_drm_device_with_driver(test, dev,
Expand Down
8 changes: 4 additions & 4 deletions drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ static void vc4_pv_muxing_test_exit(struct kunit *test)
drm_modeset_drop_locks(&priv->ctx);
drm_modeset_acquire_fini(&priv->ctx);
drm_dev_unregister(drm);
drm_kunit_helper_free_device(test, vc4->dev);
test_kunit_helper_free_device(test, vc4->dev);
}

static struct kunit_case vc4_pv_muxing_tests[] = {
Expand Down Expand Up @@ -873,7 +873,7 @@ static void drm_test_vc5_pv_muxing_bugs_subsequent_crtc_enable(struct kunit *tes
drm_modeset_drop_locks(&ctx);
drm_modeset_acquire_fini(&ctx);
drm_dev_unregister(drm);
drm_kunit_helper_free_device(test, vc4->dev);
test_kunit_helper_free_device(test, vc4->dev);
}

static void drm_test_vc5_pv_muxing_bugs_stable_fifo(struct kunit *test)
Expand Down Expand Up @@ -963,7 +963,7 @@ static void drm_test_vc5_pv_muxing_bugs_stable_fifo(struct kunit *test)
drm_modeset_drop_locks(&ctx);
drm_modeset_acquire_fini(&ctx);
drm_dev_unregister(drm);
drm_kunit_helper_free_device(test, vc4->dev);
test_kunit_helper_free_device(test, vc4->dev);
}

static void
Expand Down Expand Up @@ -1017,7 +1017,7 @@ drm_test_vc5_pv_muxing_bugs_subsequent_crtc_enable_too_many_crtc_state(struct ku
drm_modeset_drop_locks(&ctx);
drm_modeset_acquire_fini(&ctx);
drm_dev_unregister(drm);
drm_kunit_helper_free_device(test, vc4->dev);
test_kunit_helper_free_device(test, vc4->dev);
}

static struct kunit_case vc5_pv_muxing_bugs_tests[] = {
Expand Down
8 changes: 4 additions & 4 deletions include/drm/drm_kunit_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
struct drm_device;
struct kunit;

struct device *drm_kunit_helper_alloc_device(struct kunit *test);
void drm_kunit_helper_free_device(struct kunit *test, struct device *dev);
struct device *test_kunit_helper_alloc_device(struct kunit *test);
void test_kunit_helper_free_device(struct kunit *test, struct device *dev);

struct drm_device *
__drm_kunit_helper_alloc_drm_device_with_driver(struct kunit *test,
Expand All @@ -27,7 +27,7 @@ __drm_kunit_helper_alloc_drm_device_with_driver(struct kunit *test,
*
* This function creates a struct &drm_device from @_dev and @_drv.
*
* @_dev should be allocated using drm_kunit_helper_alloc_device().
* @_dev should be allocated using test_kunit_helper_alloc_device().
*
* The driver is tied to the @_test context and will get cleaned at the
* end of the test. The drm_device is allocated through
Expand Down Expand Up @@ -72,7 +72,7 @@ __drm_kunit_helper_alloc_drm_device(struct kunit *test,
* This function creates a struct &drm_driver and will create a struct
* &drm_device from @_dev and that driver.
*
* @_dev should be allocated using drm_kunit_helper_alloc_device().
* @_dev should be allocated using test_kunit_helper_alloc_device().
*
* The driver is tied to the @_test context and will get cleaned at the
* end of the test. The drm_device is allocated through
Expand Down

0 comments on commit 15d07e7

Please sign in to comment.