Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/ttm/tests: Add tests for ttm_tt_populate

Add tests for functions that add and release pages to TTs. Test the
swapin operation. Export ttm_tt_unpopulate, ttm_tt_swapin and
ttm_tt_swapout symbols for testing purposes.

Signed-off-by: Karolina Stolarek <karolina.stolarek@intel.com>
Reviewed-by: Somalapuram, Amaranath <asomalap@amd.com>
Tested-by: Somalapuram, Amaranath <asomalap@amd.com>
Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/ee42d83a472ba6bca22b4bce58f332f800891186.1718192625.git.karolina.stolarek@intel.com

authored by

Karolina Stolarek and committed by
Arunpravin Paneer Selvam
d6a82a15 5fe39433

+122
+119
drivers/gpu/drm/ttm/tests/ttm_tt_test.c
··· 256 256 ttm_tt_destroy(devs->ttm_dev, bo->ttm); 257 257 } 258 258 259 + static void ttm_tt_populate_null_ttm(struct kunit *test) 260 + { 261 + const struct ttm_test_devices *devs = test->priv; 262 + struct ttm_operation_ctx ctx = { }; 263 + int err; 264 + 265 + err = ttm_tt_populate(devs->ttm_dev, NULL, &ctx); 266 + KUNIT_ASSERT_EQ(test, err, -EINVAL); 267 + } 268 + 269 + static void ttm_tt_populate_populated_ttm(struct kunit *test) 270 + { 271 + const struct ttm_test_devices *devs = test->priv; 272 + struct ttm_operation_ctx ctx = { }; 273 + struct ttm_buffer_object *bo; 274 + struct ttm_tt *tt; 275 + struct page *populated_page; 276 + int err; 277 + 278 + bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE, NULL); 279 + 280 + tt = kunit_kzalloc(test, sizeof(*tt), GFP_KERNEL); 281 + KUNIT_ASSERT_NOT_NULL(test, tt); 282 + 283 + err = ttm_tt_init(tt, bo, 0, ttm_cached, 0); 284 + KUNIT_ASSERT_EQ(test, err, 0); 285 + 286 + err = ttm_tt_populate(devs->ttm_dev, tt, &ctx); 287 + KUNIT_ASSERT_EQ(test, err, 0); 288 + populated_page = *tt->pages; 289 + 290 + err = ttm_tt_populate(devs->ttm_dev, tt, &ctx); 291 + KUNIT_ASSERT_PTR_EQ(test, populated_page, *tt->pages); 292 + } 293 + 294 + static void ttm_tt_unpopulate_basic(struct kunit *test) 295 + { 296 + const struct ttm_test_devices *devs = test->priv; 297 + struct ttm_operation_ctx ctx = { }; 298 + struct ttm_buffer_object *bo; 299 + struct ttm_tt *tt; 300 + int err; 301 + 302 + bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE, NULL); 303 + 304 + tt = kunit_kzalloc(test, sizeof(*tt), GFP_KERNEL); 305 + KUNIT_ASSERT_NOT_NULL(test, tt); 306 + 307 + err = ttm_tt_init(tt, bo, 0, ttm_cached, 0); 308 + KUNIT_ASSERT_EQ(test, err, 0); 309 + 310 + err = ttm_tt_populate(devs->ttm_dev, tt, &ctx); 311 + KUNIT_ASSERT_EQ(test, err, 0); 312 + KUNIT_ASSERT_TRUE(test, ttm_tt_is_populated(tt)); 313 + 314 + ttm_tt_unpopulate(devs->ttm_dev, tt); 315 + KUNIT_ASSERT_FALSE(test, ttm_tt_is_populated(tt)); 316 + } 317 + 318 + static void ttm_tt_unpopulate_empty_ttm(struct kunit *test) 319 + { 320 + const struct ttm_test_devices *devs = test->priv; 321 + struct ttm_buffer_object *bo; 322 + struct ttm_tt *tt; 323 + int err; 324 + 325 + bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE, NULL); 326 + 327 + tt = kunit_kzalloc(test, sizeof(*tt), GFP_KERNEL); 328 + KUNIT_ASSERT_NOT_NULL(test, tt); 329 + 330 + err = ttm_tt_init(tt, bo, 0, ttm_cached, 0); 331 + KUNIT_ASSERT_EQ(test, err, 0); 332 + 333 + ttm_tt_unpopulate(devs->ttm_dev, tt); 334 + /* Expect graceful handling of unpopulated TTs */ 335 + } 336 + 337 + static void ttm_tt_swapin_basic(struct kunit *test) 338 + { 339 + const struct ttm_test_devices *devs = test->priv; 340 + int expected_num_pages = BO_SIZE >> PAGE_SHIFT; 341 + struct ttm_operation_ctx ctx = { }; 342 + struct ttm_buffer_object *bo; 343 + struct ttm_tt *tt; 344 + int err, num_pages; 345 + 346 + bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE, NULL); 347 + 348 + tt = kunit_kzalloc(test, sizeof(*tt), GFP_KERNEL); 349 + KUNIT_ASSERT_NOT_NULL(test, tt); 350 + 351 + err = ttm_tt_init(tt, bo, 0, ttm_cached, 0); 352 + KUNIT_ASSERT_EQ(test, err, 0); 353 + 354 + err = ttm_tt_populate(devs->ttm_dev, tt, &ctx); 355 + KUNIT_ASSERT_EQ(test, err, 0); 356 + KUNIT_ASSERT_TRUE(test, ttm_tt_is_populated(tt)); 357 + 358 + num_pages = ttm_tt_swapout(devs->ttm_dev, tt, GFP_KERNEL); 359 + KUNIT_ASSERT_EQ(test, num_pages, expected_num_pages); 360 + KUNIT_ASSERT_NOT_NULL(test, tt->swap_storage); 361 + KUNIT_ASSERT_TRUE(test, tt->page_flags & TTM_TT_FLAG_SWAPPED); 362 + 363 + /* Swapout depopulates TT, allocate pages and then swap them in */ 364 + err = ttm_pool_alloc(&devs->ttm_dev->pool, tt, &ctx); 365 + KUNIT_ASSERT_EQ(test, err, 0); 366 + 367 + err = ttm_tt_swapin(tt); 368 + KUNIT_ASSERT_EQ(test, err, 0); 369 + KUNIT_ASSERT_NULL(test, tt->swap_storage); 370 + KUNIT_ASSERT_FALSE(test, tt->page_flags & TTM_TT_FLAG_SWAPPED); 371 + } 372 + 259 373 static struct kunit_case ttm_tt_test_cases[] = { 260 374 KUNIT_CASE_PARAM(ttm_tt_init_basic, ttm_tt_init_basic_gen_params), 261 375 KUNIT_CASE(ttm_tt_init_misaligned), ··· 381 267 KUNIT_CASE(ttm_tt_create_ttm_exists), 382 268 KUNIT_CASE(ttm_tt_create_failed), 383 269 KUNIT_CASE(ttm_tt_destroy_basic), 270 + KUNIT_CASE(ttm_tt_populate_null_ttm), 271 + KUNIT_CASE(ttm_tt_populate_populated_ttm), 272 + KUNIT_CASE(ttm_tt_unpopulate_basic), 273 + KUNIT_CASE(ttm_tt_unpopulate_empty_ttm), 274 + KUNIT_CASE(ttm_tt_swapin_basic), 384 275 {} 385 276 }; 386 277
+3
drivers/gpu/drm/ttm/ttm_tt.c
··· 251 251 out_err: 252 252 return ret; 253 253 } 254 + EXPORT_SYMBOL_FOR_TESTS_ONLY(ttm_tt_swapin); 254 255 255 256 /** 256 257 * ttm_tt_swapout - swap out tt object ··· 309 308 310 309 return ret; 311 310 } 311 + EXPORT_SYMBOL_FOR_TESTS_ONLY(ttm_tt_swapout); 312 312 313 313 int ttm_tt_populate(struct ttm_device *bdev, 314 314 struct ttm_tt *ttm, struct ttm_operation_ctx *ctx) ··· 388 386 389 387 ttm->page_flags &= ~TTM_TT_FLAG_PRIV_POPULATED; 390 388 } 389 + EXPORT_SYMBOL_FOR_TESTS_ONLY(ttm_tt_unpopulate); 391 390 392 391 #ifdef CONFIG_DEBUG_FS 393 392