drivers/gpu/drm/ttm/tests/ttm_device_test.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/ttm/tests/ttm_device_test.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/ttm/tests/ttm_device_test.c
Extension
.c
Size
5875 bytes
Lines
207
Domain
Driver Families
Bucket
drivers/gpu
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct ttm_device_test_case {
	const char *description;
	unsigned int alloc_flags;
	bool pools_init_expected;
};

static void ttm_device_init_basic(struct kunit *test)
{
	struct ttm_test_devices *priv = test->priv;
	struct ttm_device *ttm_dev;
	struct ttm_resource_manager *ttm_sys_man;
	int err;

	ttm_dev = kunit_kzalloc(test, sizeof(*ttm_dev), GFP_KERNEL);
	KUNIT_ASSERT_NOT_NULL(test, ttm_dev);

	err = ttm_device_kunit_init(priv, ttm_dev, 0);
	KUNIT_ASSERT_EQ(test, err, 0);

	KUNIT_EXPECT_PTR_EQ(test, ttm_dev->funcs, &ttm_dev_funcs);
	KUNIT_ASSERT_NOT_NULL(test, ttm_dev->wq);
	KUNIT_ASSERT_NOT_NULL(test, ttm_dev->man_drv[TTM_PL_SYSTEM]);

	ttm_sys_man = &ttm_dev->sysman;
	KUNIT_ASSERT_NOT_NULL(test, ttm_sys_man);
	KUNIT_EXPECT_TRUE(test, ttm_sys_man->use_tt);
	KUNIT_EXPECT_TRUE(test, ttm_sys_man->use_type);
	KUNIT_ASSERT_NOT_NULL(test, ttm_sys_man->func);

	KUNIT_EXPECT_PTR_EQ(test, ttm_dev->dev_mapping,
			    priv->drm->anon_inode->i_mapping);

	ttm_device_fini(ttm_dev);
}

static void ttm_device_init_multiple(struct kunit *test)
{
	struct ttm_test_devices *priv = test->priv;
	struct ttm_device *ttm_devs;
	unsigned int i, num_dev = 3;
	int err;

	ttm_devs = kunit_kcalloc(test, num_dev, sizeof(*ttm_devs), GFP_KERNEL);
	KUNIT_ASSERT_NOT_NULL(test, ttm_devs);

	for (i = 0; i < num_dev; i++) {
		err = ttm_device_kunit_init(priv, &ttm_devs[i], 0);
		KUNIT_ASSERT_EQ(test, err, 0);

		KUNIT_EXPECT_PTR_EQ(test, ttm_devs[i].dev_mapping,
				    priv->drm->anon_inode->i_mapping);
		KUNIT_ASSERT_NOT_NULL(test, ttm_devs[i].wq);
		KUNIT_EXPECT_PTR_EQ(test, ttm_devs[i].funcs, &ttm_dev_funcs);
		KUNIT_ASSERT_NOT_NULL(test, ttm_devs[i].man_drv[TTM_PL_SYSTEM]);
	}

	KUNIT_ASSERT_EQ(test, list_count_nodes(&ttm_devs[0].device_list), num_dev);

	for (i = 0; i < num_dev; i++)
		ttm_device_fini(&ttm_devs[i]);
}

static void ttm_device_fini_basic(struct kunit *test)
{
	struct ttm_test_devices *priv = test->priv;
	struct ttm_device *ttm_dev;
	struct ttm_resource_manager *man;
	int err;

	ttm_dev = kunit_kzalloc(test, sizeof(*ttm_dev), GFP_KERNEL);
	KUNIT_ASSERT_NOT_NULL(test, ttm_dev);

	err = ttm_device_kunit_init(priv, ttm_dev, 0);
	KUNIT_ASSERT_EQ(test, err, 0);

	man = ttm_manager_type(ttm_dev, TTM_PL_SYSTEM);
	KUNIT_ASSERT_NOT_NULL(test, man);

	ttm_device_fini(ttm_dev);

	KUNIT_ASSERT_FALSE(test, man->use_type);
	KUNIT_ASSERT_TRUE(test, list_empty(&man->lru[0]));
	KUNIT_ASSERT_NULL(test, ttm_dev->man_drv[TTM_PL_SYSTEM]);
}

static void ttm_device_init_no_vma_man(struct kunit *test)
{
	struct ttm_test_devices *priv = test->priv;
	struct drm_device *drm = priv->drm;
	struct ttm_device *ttm_dev;

Annotation

Implementation Notes