Lines Matching full:test

3  * KUnit test suite for GEM objects backed by shmem buffers
14 #include <kunit/test.h>
38 * Test creating a shmem GEM object backed by shmem buffer. The test
43 static void drm_gem_shmem_test_obj_create(struct kunit *test) in drm_gem_shmem_test_obj_create() argument
45 struct drm_device *drm_dev = test->priv; in drm_gem_shmem_test_obj_create()
49 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, shmem); in drm_gem_shmem_test_obj_create()
50 KUNIT_EXPECT_EQ(test, shmem->base.size, TEST_SIZE); in drm_gem_shmem_test_obj_create()
51 KUNIT_EXPECT_NOT_NULL(test, shmem->base.filp); in drm_gem_shmem_test_obj_create()
52 KUNIT_EXPECT_NOT_NULL(test, shmem->base.funcs); in drm_gem_shmem_test_obj_create()
58 * Test creating a shmem GEM object from a scatter/gather table exported
59 * via a DMA-BUF. The test case succeed if the GEM object is successfully
63 static void drm_gem_shmem_test_obj_create_private(struct kunit *test) in drm_gem_shmem_test_obj_create_private() argument
65 struct drm_device *drm_dev = test->priv; in drm_gem_shmem_test_obj_create_private()
75 buf = kunit_kzalloc(test, TEST_SIZE, GFP_KERNEL); in drm_gem_shmem_test_obj_create_private()
76 KUNIT_ASSERT_NOT_NULL(test, buf); in drm_gem_shmem_test_obj_create_private()
79 KUNIT_ASSERT_NOT_NULL(test, sgt); in drm_gem_shmem_test_obj_create_private()
81 ret = kunit_add_action_or_reset(test, kfree_wrapper, sgt); in drm_gem_shmem_test_obj_create_private()
82 KUNIT_ASSERT_EQ(test, ret, 0); in drm_gem_shmem_test_obj_create_private()
85 KUNIT_ASSERT_EQ(test, ret, 0); in drm_gem_shmem_test_obj_create_private()
87 ret = kunit_add_action_or_reset(test, sg_free_table_wrapper, sgt); in drm_gem_shmem_test_obj_create_private()
88 KUNIT_ASSERT_EQ(test, ret, 0); in drm_gem_shmem_test_obj_create_private()
98 KUNIT_ASSERT_EQ(test, ret, 0); in drm_gem_shmem_test_obj_create_private()
101 KUNIT_ASSERT_EQ(test, ret, 0); in drm_gem_shmem_test_obj_create_private()
108 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, gem_obj); in drm_gem_shmem_test_obj_create_private()
109 KUNIT_EXPECT_EQ(test, gem_obj->size, TEST_SIZE); in drm_gem_shmem_test_obj_create_private()
110 KUNIT_EXPECT_NULL(test, gem_obj->filp); in drm_gem_shmem_test_obj_create_private()
111 KUNIT_EXPECT_NOT_NULL(test, gem_obj->funcs); in drm_gem_shmem_test_obj_create_private()
114 kunit_remove_action(test, sg_free_table_wrapper, sgt); in drm_gem_shmem_test_obj_create_private()
115 kunit_remove_action(test, kfree_wrapper, sgt); in drm_gem_shmem_test_obj_create_private()
118 KUNIT_EXPECT_PTR_EQ(test, shmem->sgt, sgt); in drm_gem_shmem_test_obj_create_private()
124 * Test pinning backing pages for a shmem GEM object. The test case
128 static void drm_gem_shmem_test_pin_pages(struct kunit *test) in drm_gem_shmem_test_pin_pages() argument
130 struct drm_device *drm_dev = test->priv; in drm_gem_shmem_test_pin_pages()
135 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, shmem); in drm_gem_shmem_test_pin_pages()
136 KUNIT_EXPECT_NULL(test, shmem->pages); in drm_gem_shmem_test_pin_pages()
137 KUNIT_EXPECT_EQ(test, shmem->pages_use_count, 0); in drm_gem_shmem_test_pin_pages()
139 ret = kunit_add_action_or_reset(test, drm_gem_shmem_free_wrapper, shmem); in drm_gem_shmem_test_pin_pages()
140 KUNIT_ASSERT_EQ(test, ret, 0); in drm_gem_shmem_test_pin_pages()
143 KUNIT_ASSERT_EQ(test, ret, 0); in drm_gem_shmem_test_pin_pages()
144 KUNIT_ASSERT_NOT_NULL(test, shmem->pages); in drm_gem_shmem_test_pin_pages()
145 KUNIT_EXPECT_EQ(test, shmem->pages_use_count, 1); in drm_gem_shmem_test_pin_pages()
148 KUNIT_ASSERT_NOT_NULL(test, shmem->pages[i]); in drm_gem_shmem_test_pin_pages()
151 KUNIT_EXPECT_NULL(test, shmem->pages); in drm_gem_shmem_test_pin_pages()
152 KUNIT_EXPECT_EQ(test, shmem->pages_use_count, 0); in drm_gem_shmem_test_pin_pages()
156 * Test creating a virtual mapping for a shmem GEM object. The test
158 * counter for virtual mapping is increased by one. Moreover, the test
159 * case writes and then reads a test pattern over the mapped memory.
161 static void drm_gem_shmem_test_vmap(struct kunit *test) in drm_gem_shmem_test_vmap() argument
163 struct drm_device *drm_dev = test->priv; in drm_gem_shmem_test_vmap()
169 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, shmem); in drm_gem_shmem_test_vmap()
170 KUNIT_EXPECT_NULL(test, shmem->vaddr); in drm_gem_shmem_test_vmap()
171 KUNIT_EXPECT_EQ(test, shmem->vmap_use_count, 0); in drm_gem_shmem_test_vmap()
173 ret = kunit_add_action_or_reset(test, drm_gem_shmem_free_wrapper, shmem); in drm_gem_shmem_test_vmap()
174 KUNIT_ASSERT_EQ(test, ret, 0); in drm_gem_shmem_test_vmap()
177 KUNIT_ASSERT_EQ(test, ret, 0); in drm_gem_shmem_test_vmap()
178 KUNIT_ASSERT_NOT_NULL(test, shmem->vaddr); in drm_gem_shmem_test_vmap()
179 KUNIT_ASSERT_FALSE(test, iosys_map_is_null(&map)); in drm_gem_shmem_test_vmap()
180 KUNIT_EXPECT_EQ(test, shmem->vmap_use_count, 1); in drm_gem_shmem_test_vmap()
184 KUNIT_EXPECT_EQ(test, iosys_map_rd(&map, i, u8), TEST_BYTE); in drm_gem_shmem_test_vmap()
187 KUNIT_EXPECT_NULL(test, shmem->vaddr); in drm_gem_shmem_test_vmap()
188 KUNIT_EXPECT_EQ(test, shmem->vmap_use_count, 0); in drm_gem_shmem_test_vmap()
192 * Test exporting a scatter/gather table of pinned pages suitable for
193 * PRIME usage from a shmem GEM object. The test case succeeds if a
197 static void drm_gem_shmem_test_get_pages_sgt(struct kunit *test) in drm_gem_shmem_test_get_pages_sgt() argument
199 struct drm_device *drm_dev = test->priv; in drm_gem_shmem_test_get_pages_sgt()
207 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, shmem); in drm_gem_shmem_test_get_pages_sgt()
209 ret = kunit_add_action_or_reset(test, drm_gem_shmem_free_wrapper, shmem); in drm_gem_shmem_test_get_pages_sgt()
210 KUNIT_ASSERT_EQ(test, ret, 0); in drm_gem_shmem_test_get_pages_sgt()
213 KUNIT_ASSERT_EQ(test, ret, 0); in drm_gem_shmem_test_get_pages_sgt()
216 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, sgt); in drm_gem_shmem_test_get_pages_sgt()
217 KUNIT_EXPECT_NULL(test, shmem->sgt); in drm_gem_shmem_test_get_pages_sgt()
219 ret = kunit_add_action_or_reset(test, sg_free_table_wrapper, sgt); in drm_gem_shmem_test_get_pages_sgt()
220 KUNIT_ASSERT_EQ(test, ret, 0); in drm_gem_shmem_test_get_pages_sgt()
223 KUNIT_EXPECT_NOT_NULL(test, sg); in drm_gem_shmem_test_get_pages_sgt()
227 KUNIT_EXPECT_GE(test, len, TEST_SIZE); in drm_gem_shmem_test_get_pages_sgt()
231 * Test pinning pages and exporting a scatter/gather table suitable for
232 * driver usage from a shmem GEM object. The test case succeeds if the
236 static void drm_gem_shmem_test_get_sg_table(struct kunit *test) in drm_gem_shmem_test_get_sg_table() argument
238 struct drm_device *drm_dev = test->priv; in drm_gem_shmem_test_get_sg_table()
245 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, shmem); in drm_gem_shmem_test_get_sg_table()
247 ret = kunit_add_action_or_reset(test, drm_gem_shmem_free_wrapper, shmem); in drm_gem_shmem_test_get_sg_table()
248 KUNIT_ASSERT_EQ(test, ret, 0); in drm_gem_shmem_test_get_sg_table()
252 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, sgt); in drm_gem_shmem_test_get_sg_table()
253 KUNIT_ASSERT_NOT_NULL(test, shmem->pages); in drm_gem_shmem_test_get_sg_table()
254 KUNIT_EXPECT_EQ(test, shmem->pages_use_count, 1); in drm_gem_shmem_test_get_sg_table()
255 KUNIT_EXPECT_PTR_EQ(test, sgt, shmem->sgt); in drm_gem_shmem_test_get_sg_table()
258 KUNIT_EXPECT_NOT_NULL(test, sg); in drm_gem_shmem_test_get_sg_table()
262 KUNIT_EXPECT_GE(test, len, TEST_SIZE); in drm_gem_shmem_test_get_sg_table()
266 * Test updating the madvise state of a shmem GEM object. The test
271 static void drm_gem_shmem_test_madvise(struct kunit *test) in drm_gem_shmem_test_madvise() argument
273 struct drm_device *drm_dev = test->priv; in drm_gem_shmem_test_madvise()
278 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, shmem); in drm_gem_shmem_test_madvise()
279 KUNIT_ASSERT_EQ(test, shmem->madv, 0); in drm_gem_shmem_test_madvise()
281 ret = kunit_add_action_or_reset(test, drm_gem_shmem_free_wrapper, shmem); in drm_gem_shmem_test_madvise()
282 KUNIT_ASSERT_EQ(test, ret, 0); in drm_gem_shmem_test_madvise()
285 KUNIT_EXPECT_TRUE(test, ret); in drm_gem_shmem_test_madvise()
286 KUNIT_ASSERT_EQ(test, shmem->madv, 1); in drm_gem_shmem_test_madvise()
290 KUNIT_EXPECT_FALSE(test, ret); in drm_gem_shmem_test_madvise()
291 KUNIT_ASSERT_EQ(test, shmem->madv, -1); in drm_gem_shmem_test_madvise()
295 KUNIT_EXPECT_FALSE(test, ret); in drm_gem_shmem_test_madvise()
296 KUNIT_ASSERT_EQ(test, shmem->madv, -1); in drm_gem_shmem_test_madvise()
300 * Test purging a shmem GEM object. First, assert that a newly created
306 static void drm_gem_shmem_test_purge(struct kunit *test) in drm_gem_shmem_test_purge() argument
308 struct drm_device *drm_dev = test->priv; in drm_gem_shmem_test_purge()
314 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, shmem); in drm_gem_shmem_test_purge()
316 ret = kunit_add_action_or_reset(test, drm_gem_shmem_free_wrapper, shmem); in drm_gem_shmem_test_purge()
317 KUNIT_ASSERT_EQ(test, ret, 0); in drm_gem_shmem_test_purge()
320 KUNIT_EXPECT_FALSE(test, ret); in drm_gem_shmem_test_purge()
323 KUNIT_EXPECT_TRUE(test, ret); in drm_gem_shmem_test_purge()
327 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, sgt); in drm_gem_shmem_test_purge()
330 KUNIT_EXPECT_TRUE(test, ret); in drm_gem_shmem_test_purge()
333 KUNIT_EXPECT_NULL(test, shmem->pages); in drm_gem_shmem_test_purge()
334 KUNIT_EXPECT_NULL(test, shmem->sgt); in drm_gem_shmem_test_purge()
335 KUNIT_EXPECT_EQ(test, shmem->madv, -1); in drm_gem_shmem_test_purge()
338 static int drm_gem_shmem_test_init(struct kunit *test) in drm_gem_shmem_test_init() argument
344 dev = drm_kunit_helper_alloc_device(test); in drm_gem_shmem_test_init()
345 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev); in drm_gem_shmem_test_init()
352 drm_dev = __drm_kunit_helper_alloc_drm_device(test, dev, sizeof(*drm_dev), in drm_gem_shmem_test_init()
354 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm_dev); in drm_gem_shmem_test_init()
356 test->priv = drm_dev; in drm_gem_shmem_test_init()
381 MODULE_DESCRIPTION("KUnit test suite for GEM objects backed by shmem buffers");