Improve test coverage of TTM
Subsystems (3)
PATCH v4 1/4 drm/ttm/tests: Add tests for ttm_resource and ttm_sys_man
In reply to Karolina StolarekTest initialization of ttm_resource using different memory domains. Add tests for a system memory manager and functions that can be tested without a fully-featured resource manager. Update ttm_bo_kunit_init() to initialize BO's kref and a genuine GEM drm object. Export ttm_resource_alloc for test purposes only.
--- drivers/gpu/drm/ttm/tests/Makefile | 1 + drivers/gpu/drm/ttm/tests/ttm_kunit_helpers.c | 25 +- drivers/gpu/drm/ttm/tests/ttm_kunit_helpers.h | 4 + drivers/gpu/drm/ttm/tests/ttm_resource_test.c | 335 ++++++++++++++++++ drivers/gpu/drm/ttm/ttm_resource.c | 3 + 5 files changed, 367 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/ttm/tests/ttm_resource_test.c
drivers/gpu/drm/ttm/tests/Makefile +1 -0
@@ -3,4 +3,5 @@ obj-$(CONFIG_DRM_TTM_KUNIT_TEST) += \ ttm_device_test.o \ ttm_pool_test.o \ + ttm_resource_test.o \ ttm_kunit_helpers.o
drivers/gpu/drm/ttm/tests/ttm_kunit_helpers.c +24 -1
@@ -29,19 +29,42 @@ struct ttm_buffer_object *ttm_bo_kunit_init(struct kunit *test, struct ttm_test_devices *devs, size_t size) { -struct drm_gem_object gem_obj = { .size = size }; +struct drm_gem_object gem_obj = { };struct ttm_buffer_object *bo; +int err; bo =kunit_kzalloc (test,sizeof (*bo),GFP_KERNEL );KUNIT_ASSERT_NOT_NULL (test, bo); bo->base = gem_obj; + err =drm_gem_object_init (devs->drm, &bo->base, size); +KUNIT_ASSERT_EQ (test, err,0 ); + bo->bdev = devs->ttm_dev; +kref_init (&bo->kref);return bo; }EXPORT_SYMBOL_GPL (ttm_bo_kunit_init); +struct ttm_place *ttm_place_kunit_init (struct kunit *test, +uint32_t mem_type,uint32_t flags, +size_t size) +{ +struct ttm_place *place; + + place =kunit_kzalloc (test,sizeof (*place),GFP_KERNEL ); +KUNIT_ASSERT_NOT_NULL (test, place); + + place->mem_type = mem_type; + place->flags = flags; + place->fpfn = size >>PAGE_SHIFT ; + place->lpfn = place->fpfn + (size >>PAGE_SHIFT ); + +return place; +} +EXPORT_SYMBOL_GPL (ttm_place_kunit_init); +struct ttm_test_devices *ttm_test_devices_basic (struct kunit *test) {struct ttm_test_devices *devs;
drivers/gpu/drm/ttm/tests/ttm_kunit_helpers.h +4 -0
@@ -8,6 +8,7 @@#include <drm/drm_drv.h> #include <drm/ttm/ttm_device.h> #include <drm/ttm/ttm_bo.h> +#include <drm/ttm/ttm_placement.h> #include <drm/drm_kunit_helpers.h> #include <kunit/test.h>
@@ -28,6 +29,9 @@ int ttm_device_kunit_init(struct ttm_test_devices *priv,struct ttm_buffer_object *ttm_bo_kunit_init (struct kunit *test,struct ttm_test_devices *devs,size_t size); +struct ttm_place *ttm_place_kunit_init (struct kunit *test, +uint32_t mem_type,uint32_t flags, +size_t size);struct ttm_test_devices *ttm_test_devices_basic (struct kunit *test);struct ttm_test_devices *ttm_test_devices_all (struct kunit *test);
drivers/gpu/drm/ttm/tests/ttm_resource_test.c new file +335 -0
335 lines not on this page · raw message
drivers/gpu/drm/ttm/ttm_resource.c +3 -0
@@ -30,6 +30,8 @@#include <drm/ttm/ttm_placement.h> #include <drm/ttm/ttm_resource.h> +#include <drm/drm_util.h> +/** * ttm_lru_bulk_move_init - initialize a bulk move structure * @bulk: the structure to init
@@ -240,6 +242,7 @@ int ttm_resource_alloc(struct ttm_buffer_object *bo,spin_unlock (&bo->bdev->lru_lock);return 0 ; } +EXPORT_SYMBOL_FOR_TESTS_ONLY (ttm_resource_alloc);void ttm_resource_free (struct ttm_buffer_object *bo,struct ttm_resource **res) {
Signature · 1 line
2.25.1
PATCH v4 4/4 drm/ttm/tests: Fix argument in ttm_tt_kunit_init()
In reply to Karolina StolarekRemove a leftover definition of page order and pass an empty flag value in ttm_pool_pre_populated().
--- drivers/gpu/drm/ttm/tests/ttm_pool_test.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/ttm/tests/ttm_pool_test.c +1 -2
@@ -78,10 +78,9 @@ static struct ttm_pool *ttm_pool_pre_populated(struct kunit *test,struct ttm_test_devices *devs = priv->devs;struct ttm_pool *pool;struct ttm_tt *tt; -unsigned long order =__fls (size /PAGE_SIZE );int err; - tt =ttm_tt_kunit_init (test, order, caching, size); + tt =ttm_tt_kunit_init (test,0 , caching, size);KUNIT_ASSERT_NOT_NULL (test, tt); pool =kunit_kzalloc (test,sizeof (*pool),GFP_KERNEL );
Signature · 1 line
2.25.1
PATCH v4 3/4 drm/ttm/tests: Add tests for ttm_bo functions
In reply to Karolina StolarekTest reservation and release of TTM buffer objects. Add tests to check pin and unpin operations.
--- drivers/gpu/drm/ttm/tests/Makefile | 1 + drivers/gpu/drm/ttm/tests/ttm_bo_test.c | 619 ++++++++++++++++++ drivers/gpu/drm/ttm/tests/ttm_kunit_helpers.c | 6 + 3 files changed, 626 insertions(+) create mode 100644 drivers/gpu/drm/ttm/tests/ttm_bo_test.c
drivers/gpu/drm/ttm/tests/Makefile +1 -0
@@ -5,4 +5,5 @@ obj-$(CONFIG_DRM_TTM_KUNIT_TEST) += \ ttm_pool_test.o \ ttm_resource_test.o \ ttm_tt_test.o \ + ttm_bo_test.o \ ttm_kunit_helpers.o
drivers/gpu/drm/ttm/tests/ttm_bo_test.c new file +619 -0
619 lines not on this page · raw message
drivers/gpu/drm/ttm/tests/ttm_kunit_helpers.c +6 -0
@@ -22,6 +22,10 @@ static void ttm_tt_simple_destroy(struct ttm_device *bdev, struct ttm_tt *ttm)kfree (ttm); } +static void dummy_ttm_bo_destroy (struct ttm_buffer_object *bo) +{ +} +struct ttm_device_funcs ttm_dev_funcs = { .ttm_tt_create = ttm_tt_simple_create, .ttm_tt_destroy = ttm_tt_simple_destroy,
@@ -61,6 +65,8 @@ struct ttm_buffer_object *ttm_bo_kunit_init(struct kunit *test,KUNIT_ASSERT_EQ (test, err,0 ); bo->bdev = devs->ttm_dev; + bo->destroy = dummy_ttm_bo_destroy; +kref_init (&bo->kref);return bo;
Signature · 1 line
2.25.1
PATCH v4 2/4 drm/ttm/tests: Add tests for ttm_tt
In reply to Karolina StolarekTest initialization, creation and destruction of ttm_tt instances. Export ttm_tt_destroy and ttm_tt_create symbols for testing purposes.
--- drivers/gpu/drm/ttm/tests/Makefile | 1 + drivers/gpu/drm/ttm/tests/ttm_kunit_helpers.c | 20 ++ drivers/gpu/drm/ttm/tests/ttm_tt_test.c | 295 ++++++++++++++++++ drivers/gpu/drm/ttm/ttm_tt.c | 3 + 4 files changed, 319 insertions(+) create mode 100644 drivers/gpu/drm/ttm/tests/ttm_tt_test.c
drivers/gpu/drm/ttm/tests/Makefile +1 -0
@@ -4,4 +4,5 @@ obj-$(CONFIG_DRM_TTM_KUNIT_TEST) += \ ttm_device_test.o \ ttm_pool_test.o \ ttm_resource_test.o \ + ttm_tt_test.o \ ttm_kunit_helpers.o
drivers/gpu/drm/ttm/tests/ttm_kunit_helpers.c +20 -0
@@ -2,9 +2,29 @@/* * Copyright © 2023 Intel Corporation */ +#include <drm/ttm/ttm_tt.h> +#include "ttm_kunit_helpers.h" +static struct ttm_tt *ttm_tt_simple_create (struct ttm_buffer_object *bo, +uint32_t page_flags) +{ +struct ttm_tt *tt; + + tt =kzalloc (sizeof (*tt),GFP_KERNEL ); +ttm_tt_init (tt, bo,0 , ttm_cached,0 ); + +return tt; +} + +static void ttm_tt_simple_destroy (struct ttm_device *bdev,struct ttm_tt *ttm) +{ +kfree (ttm); +} +struct ttm_device_funcs ttm_dev_funcs = { + .ttm_tt_create = ttm_tt_simple_create, + .ttm_tt_destroy = ttm_tt_simple_destroy, };EXPORT_SYMBOL_GPL (ttm_dev_funcs);
drivers/gpu/drm/ttm/tests/ttm_tt_test.c new file +295 -0
295 lines not on this page · raw message
drivers/gpu/drm/ttm/ttm_tt.c +3 -0
@@ -36,6 +36,7 @@#include <linux/file.h> #include <linux/module.h> #include <drm/drm_cache.h> +#include <drm/drm_util.h> #include <drm/ttm/ttm_bo.h> #include <drm/ttm/ttm_tt.h>
@@ -91,6 +92,7 @@ int ttm_tt_create(struct ttm_buffer_object *bo, bool zero_alloc)return 0 ; } +EXPORT_SYMBOL_FOR_TESTS_ONLY (ttm_tt_create);/* * Allocates storage for pointers to the pages that back the ttm.
@@ -129,6 +131,7 @@ void ttm_tt_destroy(struct ttm_device *bdev, struct ttm_tt *ttm) { bdev->funcs->ttm_tt_destroy (bdev, ttm); } +EXPORT_SYMBOL_FOR_TESTS_ONLY (ttm_tt_destroy); static void ttm_tt_init_fields(struct ttm_tt *ttm, struct ttm_buffer_object *bo,
Signature · 1 line
2.25.1
v4 cover Improve test coverage of TTM
Add tests for building blocks of the TTM subsystem, such as ttm_resource, ttm_resource_manager, ttm_tt and ttm_buffer_object. This series covers basic functions such as initialization, allocation and clean-up of each struct. Testing of ttm_buffer_object also includes locking and unlocking the object for validation, with special scenarios such as an interrupted wait or deadlock.
Some of the test cases check the bulk move mechanism and how it interacts with pinned buffers. This is to be seen if we want to add dedicated testing for bulk move or not. The resource allocation subtests use ttm_sys_manager for now. Resources that don't use system memory will be indirectly tested via tests for ttm_bo_validate()/ttm_bo_init_validate(), using a mock resource manager.
Use kunit_tool script to manually run all the tests:
$ ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/gpu/drm/ttm/tests
To build a kernel with TTM KUnit tests, first enable CONFIG_KUNIT, and then CONFIG_DRM_TTM_KUNIT_TEST.
Many thanks,
Karolina
v4:
- First unreserve the object before calling ww_acquire_fini() in ttm_bo_reserve_double_resv subtest
- Silence lockdep in ttm_bo_reserve_deadlock subtest (open to suggestions how to fix it in a different way)
- Use a genuine GEM object in ttm_buffer_object instead of an empty one
v3:
- Instead of modifying the main TTM Makefile, use EXPORT_SYMBOL_FOR_TESTS_ONLY() macro for symbols that are tested but not widely exported. Thanks to this change, TTM tests can be built as modules, even when non-exported functions are used
- Change the description of a patch that fixes ttm_pool_pre_populated()
v2:
- Remove Makefile for KUnit tests and move the definitions to the TTM's one
- Switch on CONFIG_DRM_TTM_KUNIT_TEST=m so the tests and TTM module are built as one. This allows building the tests as a module, even if it uses functions that are not exported
- Fix ttm_pool_pre_populated(); a wrong flag was passed to ttm_tt_kunit_init() function
Karolina Stolarek (4):
drm/ttm/tests: Add tests for ttm_resource and ttm_sys_man drm/ttm/tests: Add tests for ttm_tt drm/ttm/tests: Add tests for ttm_bo functions drm/ttm/tests: Fix argument in ttm_tt_kunit_init()
drivers/gpu/drm/ttm/tests/Makefile | 3 + drivers/gpu/drm/ttm/tests/ttm_bo_test.c | 619 ++++++++++++++++++ drivers/gpu/drm/ttm/tests/ttm_kunit_helpers.c | 51 +- drivers/gpu/drm/ttm/tests/ttm_kunit_helpers.h | 4 + drivers/gpu/drm/ttm/tests/ttm_pool_test.c | 3 +- drivers/gpu/drm/ttm/tests/ttm_resource_test.c | 335 ++++++++++ drivers/gpu/drm/ttm/tests/ttm_tt_test.c | 295 +++++++++ drivers/gpu/drm/ttm/ttm_resource.c | 3 + drivers/gpu/drm/ttm/ttm_tt.c | 3 + 9 files changed, 1313 insertions(+), 3 deletions(-) create mode 100644 drivers/gpu/drm/ttm/tests/ttm_bo_test.c create mode 100644 drivers/gpu/drm/ttm/tests/ttm_resource_test.c create mode 100644 drivers/gpu/drm/ttm/tests/ttm_tt_test.c
Signature · 1 line
2.25.1