@@ -12,11 +12,35 @@
#include <drm/drm_exec.h>
#include <drm/drm_device.h>
+#include <drm/drm_drv.h>
#include <drm/drm_gem.h>
+#include <drm/drm_kunit_helpers.h>
#include "../lib/drm_random.h"
-static struct drm_device dev;
+struct drm_exec_priv {
+ struct device *dev;
+ struct drm_device *drm;
+};
+
+static int drm_exec_test_init(struct kunit *test)
+{
+ struct drm_exec_priv *priv;
+
+ priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv);
+
+ test->priv = priv;
+
+ priv->dev = drm_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, sizeof(*priv->drm), 0,
+ DRIVER_MODESET);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv->drm);
+
+ return 0;
+}
static void sanitycheck(struct kunit *test)
{
@@ -29,11 +53,12 @@ static void sanitycheck(struct kunit *test)
static void test_lock(struct kunit *test)
{
+ struct drm_exec_priv *priv = test->priv;
struct drm_gem_object gobj = { };
struct drm_exec exec;
int ret;
- drm_gem_private_object_init(&dev, &gobj, PAGE_SIZE);
+ drm_gem_private_object_init(priv->drm, &gobj, PAGE_SIZE);
drm_exec_init(&exec, DRM_EXEC_INTERRUPTIBLE_WAIT);
drm_exec_until_all_locked(&exec) {
@@ -48,11 +73,12 @@ static void test_lock(struct kunit *test)
static void test_lock_unlock(struct kunit *test)
{
+ struct drm_exec_priv *priv = test->priv;
struct drm_gem_object gobj = { };
struct drm_exec exec;
int ret;
- drm_gem_private_object_init(&dev, &gobj, PAGE_SIZE);
+ drm_gem_private_object_init(priv->drm, &gobj, PAGE_SIZE);
drm_exec_init(&exec, DRM_EXEC_INTERRUPTIBLE_WAIT);
drm_exec_until_all_locked(&exec) {
@@ -74,11 +100,12 @@ static void test_lock_unlock(struct kunit *test)
static void test_duplicates(struct kunit *test)
{
+ struct drm_exec_priv *priv = test->priv;
struct drm_gem_object gobj = { };
struct drm_exec exec;
int ret;
- drm_gem_private_object_init(&dev, &gobj, PAGE_SIZE);
+ drm_gem_private_object_init(priv->drm, &gobj, PAGE_SIZE);
drm_exec_init(&exec, DRM_EXEC_IGNORE_DUPLICATES);
drm_exec_until_all_locked(&exec) {
@@ -102,11 +129,12 @@ static void test_duplicates(struct kunit *test)
static void test_prepare(struct kunit *test)
{
+ struct drm_exec_priv *priv = test->priv;
struct drm_gem_object gobj = { };
struct drm_exec exec;
int ret;
- drm_gem_private_object_init(&dev, &gobj, PAGE_SIZE);
+ drm_gem_private_object_init(priv->drm, &gobj, PAGE_SIZE);
drm_exec_init(&exec, DRM_EXEC_INTERRUPTIBLE_WAIT);
drm_exec_until_all_locked(&exec) {
@@ -121,14 +149,15 @@ static void test_prepare(struct kunit *test)
static void test_prepare_array(struct kunit *test)
{
+ struct drm_exec_priv *priv = test->priv;
struct drm_gem_object gobj1 = { };
struct drm_gem_object gobj2 = { };
struct drm_gem_object *array[] = { &gobj1, &gobj2 };
struct drm_exec exec;
int ret;
- drm_gem_private_object_init(&dev, &gobj1, PAGE_SIZE);
- drm_gem_private_object_init(&dev, &gobj2, PAGE_SIZE);
+ drm_gem_private_object_init(priv->drm, &gobj1, PAGE_SIZE);
+ drm_gem_private_object_init(priv->drm, &gobj2, PAGE_SIZE);
drm_exec_init(&exec, DRM_EXEC_INTERRUPTIBLE_WAIT);
drm_exec_until_all_locked(&exec)
@@ -150,6 +179,7 @@ static struct kunit_case drm_exec_tests[] = {
static struct kunit_suite drm_exec_test_suite = {
.name = "drm_exec",
+ .init = drm_exec_test_init,
.test_cases = drm_exec_tests,
};