Skip to contentSkip to conversation

drm/test: add a test suite for GEM objects backed by shmem

PATCH Superseded Marco Pagani 2 participants 4 messages Nov 23, 2023 – Nov 28, 2023

Subsystems (3)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 drm/test: add a test suite for GEM objects backed by shmem

This patch introduces an initial KUnit test suite for GEM objects backed by shmem buffers.

v4:
- Add missing MMU dependency for DRM_GEM_SHMEM_HELPER (kernel test robot) v3:
- Explicitly cast pointers in the helpers
- Removed unused pointer to parent dev in struct fake_dev
- Test entries reordering in Kconfig and Makefile sent as a separate patch v2:
- Improved description of test cases
- Cleaner error handling using KUnit actions
- Alphabetical order in Kconfig and Makefile

---
 drivers/gpu/drm/Kconfig                    |   3 +-
 drivers/gpu/drm/tests/Makefile             |   1 +
 drivers/gpu/drm/tests/drm_gem_shmem_test.c | 385 +++++++++++++++++++++
 3 files changed, 388 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/tests/drm_gem_shmem_test.c
drivers/gpu/drm/Kconfig +2 -1
index cdbc56e07649..435dca95fac8 100644
@@ -74,12 +74,13 @@ config DRM_KUNIT_TEST_HELPERS
 
 config DRM_KUNIT_TEST
 	tristate "KUnit tests for DRM" if !KUNIT_ALL_TESTS
-	depends on DRM && KUNIT
+	depends on DRM && KUNIT && MMU
 	select DRM_BUDDY
 	select DRM_DISPLAY_DP_HELPER
 	select DRM_DISPLAY_HELPER
 	select DRM_EXEC
 	select DRM_EXPORT_FOR_TESTS if m
+	select DRM_GEM_SHMEM_HELPER
 	select DRM_KMS_HELPER
 	select DRM_KUNIT_TEST_HELPERS
 	select DRM_LIB_RANDOM
drivers/gpu/drm/tests/Makefile +1 -0
index 2645af241ff0..d6183b3d7688 100644
@@ -13,6 +13,7 @@ obj-$(CONFIG_DRM_KUNIT_TEST) += \
 	drm_format_helper_test.o \
 	drm_format_test.o \
 	drm_framebuffer_test.o \
+	drm_gem_shmem_test.o \
 	drm_managed_test.o \
 	drm_mm_test.o \
 	drm_modes_test.o \
drivers/gpu/drm/tests/drm_gem_shmem_test.c new file +385 -0

385 lines not on this page · raw message

base-commit: c79b972eb88b077d2765e7790d0902b3dc94d55c

Signature · 1 line
2.42.0
maintainer
#1 lore raw

Hi,

Quoted 7 lines · Marco Pagani
drivers/gpu/drm/tests/drm_gem_shmem_test.c new file +7 -0
+static int drm_gem_shmem_test_init(struct kunit *test)
+{
+	struct device *dev;
+	struct fake_dev {
+		struct drm_device drm_dev;
+	} *fdev;
+

[...]

drivers/gpu/drm/tests/drm_gem_shmem_test.c line 358

Quoted 9 lines
drivers/gpu/drm/tests/drm_gem_shmem_test.c new file +9 -0
+
+	/*
+	 * The DRM core will automatically initialize the GEM core and create
+	 * a DRM Memory Manager object which provides an address space pool
+	 * for GEM objects allocation.
+	 */
+	fdev = drm_kunit_helper_alloc_drm_device(test, dev, struct fake_dev,
+						 drm_dev, DRIVER_GEM);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, fdev);

Sorry I missed it earlier, but you don't need the intermediate structure if you use

struct drm_device *drm;

drm = __drm_kunit_helper_alloc_drm_device(test, dev, sizeof(*drm), 0, DRIVER_GEM); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm);

Maxime

#2 lore raw
Quoted 26 lines · Maxime Ripard

Hi,

Quoted 7 lines · Marco Pagani
drivers/gpu/drm/tests/drm_gem_shmem_test.c new file +7 -0
+static int drm_gem_shmem_test_init(struct kunit *test)
+{
+	struct device *dev;
+	struct fake_dev {
+		struct drm_device drm_dev;
+	} *fdev;
+

[...]

drivers/gpu/drm/tests/drm_gem_shmem_test.c line 358

Quoted 9 lines
drivers/gpu/drm/tests/drm_gem_shmem_test.c new file +9 -0
+
+	/*
+	 * The DRM core will automatically initialize the GEM core and create
+	 * a DRM Memory Manager object which provides an address space pool
+	 * for GEM objects allocation.
+	 */
+	fdev = drm_kunit_helper_alloc_drm_device(test, dev, struct fake_dev,
+						 drm_dev, DRIVER_GEM);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, fdev);

Sorry I missed it earlier, but you don't need the intermediate structure if you use

Quoted 5 lines

struct drm_device *drm;

drm = __drm_kunit_helper_alloc_drm_device(test, dev, sizeof(*drm), 0, DRIVER_GEM); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm);

I prefer to use drm_kunit_helper_alloc_drm_device() with the intermediate structure. It makes the code clearer, in my opinion. Initially, when developing the suite, I was using __drm_kunit_helper_alloc_drm_device() as most test suites do, but I feel the list of arguments including "sizeof(*drm), 0," is less straightforward to understand.

Thanks,
Marco

maintainer
#3 lore raw
Quoted 35 lines · Marco Pagani
Quoted 26 lines · Maxime Ripard

Hi,

Quoted 7 lines · Marco Pagani
drivers/gpu/drm/tests/drm_gem_shmem_test.c new file +7 -0
+static int drm_gem_shmem_test_init(struct kunit *test)
+{
+	struct device *dev;
+	struct fake_dev {
+		struct drm_device drm_dev;
+	} *fdev;
+

[...]

drivers/gpu/drm/tests/drm_gem_shmem_test.c line 358

Quoted 9 lines
drivers/gpu/drm/tests/drm_gem_shmem_test.c new file +9 -0
+
+	/*
+	 * The DRM core will automatically initialize the GEM core and create
+	 * a DRM Memory Manager object which provides an address space pool
+	 * for GEM objects allocation.
+	 */
+	fdev = drm_kunit_helper_alloc_drm_device(test, dev, struct fake_dev,
+						 drm_dev, DRIVER_GEM);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, fdev);

Sorry I missed it earlier, but you don't need the intermediate structure if you use

Quoted 5 lines

struct drm_device *drm;

drm = __drm_kunit_helper_alloc_drm_device(test, dev, sizeof(*drm), 0, DRIVER_GEM); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm);

Quoted 5 lines

I prefer to use drm_kunit_helper_alloc_drm_device() with the intermediate structure. It makes the code clearer, in my opinion. Initially, when developing the suite, I was using __drm_kunit_helper_alloc_drm_device() as most test suites do, but I feel the list of arguments including "sizeof(*drm), 0," is less straightforward to understand.

Then we can create an init helper, and you can allocate the drm_device through drmm_kzalloc, but I'd like tests to use consistent constructs.

This can of course be made as a later patch: you use the same construct the other tests do here, and later we work on the init function and convert all tests to use it.

Maxime