Re: [PATCH v7 6/8] drm/ttm/tests: Test simple BO creation and validation
Am 17.11.23 um 09:49 schrieb Karolina Stolarek: Add tests for ttm_bo_init_reserved() and ttm_bo_validate() that use sys manager. Define a simple move function in ttm_device_funcs. Expose destroy callback of the buffer object to make testing of ttm_bo_init_reserved() behaviour easier. Signed-off-by: Karolina Stolarek Quite a bit hacky, but I think you got that correct. Reviewed-by: Christian König --- drivers/gpu/drm/ttm/tests/Makefile| 1 + .../gpu/drm/ttm/tests/ttm_bo_validate_test.c | 211 ++ drivers/gpu/drm/ttm/tests/ttm_kunit_helpers.c | 14 +- drivers/gpu/drm/ttm/tests/ttm_kunit_helpers.h | 1 + 4 files changed, 226 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/ttm/tests/ttm_bo_validate_test.c diff --git a/drivers/gpu/drm/ttm/tests/Makefile b/drivers/gpu/drm/ttm/tests/Makefile index 468535f7eed2..2e5ed63fb414 100644 --- a/drivers/gpu/drm/ttm/tests/Makefile +++ b/drivers/gpu/drm/ttm/tests/Makefile @@ -6,4 +6,5 @@ obj-$(CONFIG_DRM_TTM_KUNIT_TEST) += \ ttm_resource_test.o \ ttm_tt_test.o \ ttm_bo_test.o \ +ttm_bo_validate_test.o \ ttm_kunit_helpers.o diff --git a/drivers/gpu/drm/ttm/tests/ttm_bo_validate_test.c b/drivers/gpu/drm/ttm/tests/ttm_bo_validate_test.c new file mode 100644 index ..1d50e4ba9775 --- /dev/null +++ b/drivers/gpu/drm/ttm/tests/ttm_bo_validate_test.c @@ -0,0 +1,211 @@ +// SPDX-License-Identifier: GPL-2.0 AND MIT +/* + * Copyright © 2023 Intel Corporation + */ + +#include +#include +#include + +#include "ttm_kunit_helpers.h" + +#define BO_SIZESZ_4K + +struct ttm_bo_validate_test_case { + const char *description; + enum ttm_bo_type bo_type; + bool with_ttm; +}; + +static struct ttm_placement *ttm_placement_kunit_init(struct kunit *test, + struct ttm_place *places, + unsigned int num_places, + struct ttm_place *busy_places, + unsigned int num_busy_places) +{ + struct ttm_placement *placement; + + placement = kunit_kzalloc(test, sizeof(*placement), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, placement); + + placement->num_placement = num_places; + placement->placement = places; + placement->num_busy_placement = num_busy_places; + placement->busy_placement = busy_places; + + return placement; +} + +static void ttm_bo_validate_case_desc(const struct ttm_bo_validate_test_case *t, + char *desc) +{ + strscpy(desc, t->description, KUNIT_PARAM_DESC_SIZE); +} + +static const struct ttm_bo_validate_test_case ttm_bo_type_cases[] = { + { + .description = "Buffer object for userspace", + .bo_type = ttm_bo_type_device, + }, + { + .description = "Kernel buffer object", + .bo_type = ttm_bo_type_kernel, + }, + { + .description = "Shared buffer object", + .bo_type = ttm_bo_type_sg, + }, +}; + +KUNIT_ARRAY_PARAM(ttm_bo_types, ttm_bo_type_cases, + ttm_bo_validate_case_desc); + +static void ttm_bo_init_reserved_sys_man(struct kunit *test) +{ + const struct ttm_bo_validate_test_case *params = test->param_value; + struct ttm_test_devices *priv = test->priv; + struct ttm_buffer_object *bo; + struct ttm_place *place; + struct ttm_placement *placement; + enum ttm_bo_type bo_type = params->bo_type; + struct ttm_operation_ctx ctx = { }; + uint32_t size = ALIGN(BO_SIZE, PAGE_SIZE); + int err; + + bo = kunit_kzalloc(test, sizeof(*bo), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, bo); + + place = ttm_place_kunit_init(test, TTM_PL_SYSTEM, 0); + placement = ttm_placement_kunit_init(test, place, 1, NULL, 0); + + drm_gem_private_object_init(priv->drm, >base, size); + + err = ttm_bo_init_reserved(priv->ttm_dev, bo, bo_type, placement, + PAGE_SIZE, , NULL, NULL, + _ttm_bo_destroy); + dma_resv_unlock(bo->base.resv); + + KUNIT_EXPECT_EQ(test, err, 0); + KUNIT_EXPECT_EQ(test, kref_read(>kref), 1); + KUNIT_EXPECT_PTR_EQ(test, bo->bdev, priv->ttm_dev); + KUNIT_EXPECT_EQ(test, bo->type, bo_type); + KUNIT_EXPECT_EQ(test, bo->page_alignment, PAGE_SIZE); + KUNIT_EXPECT_PTR_EQ(test, bo->destroy, _ttm_bo_destroy); + KUNIT_EXPECT_EQ(test, bo->pin_count, 0); + KUNIT_EXPECT_NULL(test, bo->bulk_move); + KUNIT_EXPECT_NOT_NULL(test, bo->ttm); + KUNIT_EXPECT_FALSE(test, ttm_tt_is_populated(bo->ttm)); + KUNIT_EXPECT_NOT_NULL(test, (void *)bo->base.resv->fences); + KUNIT_EXPECT_EQ(test, ctx.bytes_moved, size); + +
Re: [PATCH v7 6/8] drm/ttm/tests: Test simple BO creation and validation
Hi Karolina, kernel test robot noticed the following build warnings: [auto build test WARNING on drm-misc/drm-misc-next] [also build test WARNING on drm/drm-next drm-exynos/exynos-drm-next drm-intel/for-linux-next drm-intel/for-linux-next-fixes drm-tip/drm-tip linus/master v6.7-rc1 next-20231117] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Karolina-Stolarek/drm-ttm-tests-Add-tests-for-ttm_resource-and-ttm_sys_man/20231117-165755 base: git://anongit.freedesktop.org/drm/drm-misc drm-misc-next patch link: https://lore.kernel.org/r/fe0d1ba291b12e7b4671bee8b95812ac30a469df.1700207346.git.karolina.stolarek%40intel.com patch subject: [PATCH v7 6/8] drm/ttm/tests: Test simple BO creation and validation config: x86_64-randconfig-122-20231117 (https://download.01.org/0day-ci/archive/20231118/202311180247.4a61hkyg-...@intel.com/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231118/202311180247.4a61hkyg-...@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot | Closes: https://lore.kernel.org/oe-kbuild-all/202311180247.4a61hkyg-...@intel.com/ sparse warnings: (new ones prefixed by >>) >> drivers/gpu/drm/ttm/tests/ttm_bo_validate_test.c:98:9: sparse: sparse: cast >> removes address space '__rcu' of expression >> drivers/gpu/drm/ttm/tests/ttm_bo_validate_test.c:98:9: sparse: sparse: cast >> removes address space '__rcu' of expression vim +/__rcu +98 drivers/gpu/drm/ttm/tests/ttm_bo_validate_test.c 59 60 KUNIT_ARRAY_PARAM(ttm_bo_types, ttm_bo_type_cases, 61ttm_bo_validate_case_desc); 62 63 static void ttm_bo_init_reserved_sys_man(struct kunit *test) 64 { 65 const struct ttm_bo_validate_test_case *params = test->param_value; 66 struct ttm_test_devices *priv = test->priv; 67 struct ttm_buffer_object *bo; 68 struct ttm_place *place; 69 struct ttm_placement *placement; 70 enum ttm_bo_type bo_type = params->bo_type; 71 struct ttm_operation_ctx ctx = { }; 72 uint32_t size = ALIGN(BO_SIZE, PAGE_SIZE); 73 int err; 74 75 bo = kunit_kzalloc(test, sizeof(*bo), GFP_KERNEL); 76 KUNIT_ASSERT_NOT_NULL(test, bo); 77 78 place = ttm_place_kunit_init(test, TTM_PL_SYSTEM, 0); 79 placement = ttm_placement_kunit_init(test, place, 1, NULL, 0); 80 81 drm_gem_private_object_init(priv->drm, >base, size); 82 83 err = ttm_bo_init_reserved(priv->ttm_dev, bo, bo_type, placement, 84 PAGE_SIZE, , NULL, NULL, 85 _ttm_bo_destroy); 86 dma_resv_unlock(bo->base.resv); 87 88 KUNIT_EXPECT_EQ(test, err, 0); 89 KUNIT_EXPECT_EQ(test, kref_read(>kref), 1); 90 KUNIT_EXPECT_PTR_EQ(test, bo->bdev, priv->ttm_dev); 91 KUNIT_EXPECT_EQ(test, bo->type, bo_type); 92 KUNIT_EXPECT_EQ(test, bo->page_alignment, PAGE_SIZE); 93 KUNIT_EXPECT_PTR_EQ(test, bo->destroy, _ttm_bo_destroy); 94 KUNIT_EXPECT_EQ(test, bo->pin_count, 0); 95 KUNIT_EXPECT_NULL(test, bo->bulk_move); 96 KUNIT_EXPECT_NOT_NULL(test, bo->ttm); 97 KUNIT_EXPECT_FALSE(test, ttm_tt_is_populated(bo->ttm)); > 98 KUNIT_EXPECT_NOT_NULL(test, (void *)bo->base.resv->fences); 99 KUNIT_EXPECT_EQ(test, ctx.bytes_moved, size); 100 101 if (bo_type != ttm_bo_type_kernel) 102 KUNIT_EXPECT_TRUE(test, 103 drm_mm_node_allocated(>base.vma_node.vm_node)); 104 105 ttm_resource_free(bo, >resource); 106 ttm_bo_put(bo); 107 } 108 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
[PATCH v7 6/8] drm/ttm/tests: Test simple BO creation and validation
Add tests for ttm_bo_init_reserved() and ttm_bo_validate() that use sys manager. Define a simple move function in ttm_device_funcs. Expose destroy callback of the buffer object to make testing of ttm_bo_init_reserved() behaviour easier. Signed-off-by: Karolina Stolarek --- drivers/gpu/drm/ttm/tests/Makefile| 1 + .../gpu/drm/ttm/tests/ttm_bo_validate_test.c | 211 ++ drivers/gpu/drm/ttm/tests/ttm_kunit_helpers.c | 14 +- drivers/gpu/drm/ttm/tests/ttm_kunit_helpers.h | 1 + 4 files changed, 226 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/ttm/tests/ttm_bo_validate_test.c diff --git a/drivers/gpu/drm/ttm/tests/Makefile b/drivers/gpu/drm/ttm/tests/Makefile index 468535f7eed2..2e5ed63fb414 100644 --- a/drivers/gpu/drm/ttm/tests/Makefile +++ b/drivers/gpu/drm/ttm/tests/Makefile @@ -6,4 +6,5 @@ obj-$(CONFIG_DRM_TTM_KUNIT_TEST) += \ ttm_resource_test.o \ ttm_tt_test.o \ ttm_bo_test.o \ +ttm_bo_validate_test.o \ ttm_kunit_helpers.o diff --git a/drivers/gpu/drm/ttm/tests/ttm_bo_validate_test.c b/drivers/gpu/drm/ttm/tests/ttm_bo_validate_test.c new file mode 100644 index ..1d50e4ba9775 --- /dev/null +++ b/drivers/gpu/drm/ttm/tests/ttm_bo_validate_test.c @@ -0,0 +1,211 @@ +// SPDX-License-Identifier: GPL-2.0 AND MIT +/* + * Copyright © 2023 Intel Corporation + */ + +#include +#include +#include + +#include "ttm_kunit_helpers.h" + +#define BO_SIZESZ_4K + +struct ttm_bo_validate_test_case { + const char *description; + enum ttm_bo_type bo_type; + bool with_ttm; +}; + +static struct ttm_placement *ttm_placement_kunit_init(struct kunit *test, + struct ttm_place *places, + unsigned int num_places, + struct ttm_place *busy_places, + unsigned int num_busy_places) +{ + struct ttm_placement *placement; + + placement = kunit_kzalloc(test, sizeof(*placement), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, placement); + + placement->num_placement = num_places; + placement->placement = places; + placement->num_busy_placement = num_busy_places; + placement->busy_placement = busy_places; + + return placement; +} + +static void ttm_bo_validate_case_desc(const struct ttm_bo_validate_test_case *t, + char *desc) +{ + strscpy(desc, t->description, KUNIT_PARAM_DESC_SIZE); +} + +static const struct ttm_bo_validate_test_case ttm_bo_type_cases[] = { + { + .description = "Buffer object for userspace", + .bo_type = ttm_bo_type_device, + }, + { + .description = "Kernel buffer object", + .bo_type = ttm_bo_type_kernel, + }, + { + .description = "Shared buffer object", + .bo_type = ttm_bo_type_sg, + }, +}; + +KUNIT_ARRAY_PARAM(ttm_bo_types, ttm_bo_type_cases, + ttm_bo_validate_case_desc); + +static void ttm_bo_init_reserved_sys_man(struct kunit *test) +{ + const struct ttm_bo_validate_test_case *params = test->param_value; + struct ttm_test_devices *priv = test->priv; + struct ttm_buffer_object *bo; + struct ttm_place *place; + struct ttm_placement *placement; + enum ttm_bo_type bo_type = params->bo_type; + struct ttm_operation_ctx ctx = { }; + uint32_t size = ALIGN(BO_SIZE, PAGE_SIZE); + int err; + + bo = kunit_kzalloc(test, sizeof(*bo), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, bo); + + place = ttm_place_kunit_init(test, TTM_PL_SYSTEM, 0); + placement = ttm_placement_kunit_init(test, place, 1, NULL, 0); + + drm_gem_private_object_init(priv->drm, >base, size); + + err = ttm_bo_init_reserved(priv->ttm_dev, bo, bo_type, placement, + PAGE_SIZE, , NULL, NULL, + _ttm_bo_destroy); + dma_resv_unlock(bo->base.resv); + + KUNIT_EXPECT_EQ(test, err, 0); + KUNIT_EXPECT_EQ(test, kref_read(>kref), 1); + KUNIT_EXPECT_PTR_EQ(test, bo->bdev, priv->ttm_dev); + KUNIT_EXPECT_EQ(test, bo->type, bo_type); + KUNIT_EXPECT_EQ(test, bo->page_alignment, PAGE_SIZE); + KUNIT_EXPECT_PTR_EQ(test, bo->destroy, _ttm_bo_destroy); + KUNIT_EXPECT_EQ(test, bo->pin_count, 0); + KUNIT_EXPECT_NULL(test, bo->bulk_move); + KUNIT_EXPECT_NOT_NULL(test, bo->ttm); + KUNIT_EXPECT_FALSE(test, ttm_tt_is_populated(bo->ttm)); + KUNIT_EXPECT_NOT_NULL(test, (void *)bo->base.resv->fences); + KUNIT_EXPECT_EQ(test, ctx.bytes_moved, size); + + if (bo_type != ttm_bo_type_kernel) + KUNIT_EXPECT_TRUE(test, +