2 * Copyright 2014 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
24 #ifndef _AMDGPU_TEST_H_
25 #define _AMDGPU_TEST_H_
28 #include "amdgpu_drm.h"
31 * Define max. number of card in system which we are able to handle
33 #define MAX_CARDS_SUPPORTED 128
35 /* Forward reference for array to keep "drm" handles */
36 extern int drm_amdgpu[MAX_CARDS_SUPPORTED];
38 /* Global variables */
39 extern int open_render_node;
41 /************************* Basic test suite ********************************/
44 * Define basic test suite to serve as the starting point for future testing
48 * Initialize basic test suite
50 int suite_basic_tests_init();
53 * Deinitialize basic test suite
55 int suite_basic_tests_clean();
58 * Tests in basic test suite
60 extern CU_TestInfo basic_tests[];
63 * Initialize bo test suite
65 int suite_bo_tests_init();
68 * Deinitialize bo test suite
70 int suite_bo_tests_clean();
73 * Tests in bo test suite
75 extern CU_TestInfo bo_tests[];
78 * Initialize cs test suite
80 int suite_cs_tests_init();
83 * Deinitialize cs test suite
85 int suite_cs_tests_clean();
88 * Decide if the suite is enabled by default or not.
90 CU_BOOL suite_cs_tests_enable(void);
93 * Tests in cs test suite
95 extern CU_TestInfo cs_tests[];
98 * Initialize vce test suite
100 int suite_vce_tests_init();
103 * Deinitialize vce test suite
105 int suite_vce_tests_clean();
108 * Decide if the suite is enabled by default or not.
110 CU_BOOL suite_vce_tests_enable(void);
113 * Tests in vce test suite
115 extern CU_TestInfo vce_tests[];
118 + * Initialize vcn test suite
120 int suite_vcn_tests_init();
123 + * Deinitialize vcn test suite
125 int suite_vcn_tests_clean();
128 * Decide if the suite is enabled by default or not.
130 CU_BOOL suite_vcn_tests_enable(void);
133 + * Tests in vcn test suite
135 extern CU_TestInfo vcn_tests[];
138 * Initialize uvd enc test suite
140 int suite_uvd_enc_tests_init();
143 * Deinitialize uvd enc test suite
145 int suite_uvd_enc_tests_clean();
148 * Decide if the suite is enabled by default or not.
150 CU_BOOL suite_uvd_enc_tests_enable(void);
153 * Tests in uvd enc test suite
155 extern CU_TestInfo uvd_enc_tests[];
158 * Initialize deadlock test suite
160 int suite_deadlock_tests_init();
163 * Deinitialize deadlock test suite
165 int suite_deadlock_tests_clean();
168 * Decide if the suite is enabled by default or not.
170 CU_BOOL suite_deadlock_tests_enable(void);
173 * Tests in uvd enc test suite
175 extern CU_TestInfo deadlock_tests[];
178 * Initialize vm test suite
180 int suite_vm_tests_init();
183 * Deinitialize deadlock test suite
185 int suite_vm_tests_clean();
188 * Decide if the suite is enabled by default or not.
190 CU_BOOL suite_vm_tests_enable(void);
193 * Tests in vm test suite
195 extern CU_TestInfo vm_tests[];
199 * Initialize ras test suite
201 int suite_ras_tests_init();
204 * Deinitialize deadlock test suite
206 int suite_ras_tests_clean();
209 * Decide if the suite is enabled by default or not.
211 CU_BOOL suite_ras_tests_enable(void);
214 * Tests in ras test suite
216 extern CU_TestInfo ras_tests[];
222 static inline amdgpu_bo_handle gpu_mem_alloc(
223 amdgpu_device_handle device_handle,
229 amdgpu_va_handle *va_handle)
231 struct amdgpu_bo_alloc_request req = {0};
232 amdgpu_bo_handle buf_handle = NULL;
235 req.alloc_size = size;
236 req.phys_alignment = alignment;
237 req.preferred_heap = type;
240 r = amdgpu_bo_alloc(device_handle, &req, &buf_handle);
241 CU_ASSERT_EQUAL(r, 0);
245 if (vmc_addr && va_handle) {
246 r = amdgpu_va_range_alloc(device_handle,
247 amdgpu_gpu_va_range_general,
248 size, alignment, 0, vmc_addr,
250 CU_ASSERT_EQUAL(r, 0);
254 r = amdgpu_bo_va_op(buf_handle, 0, size, *vmc_addr, 0,
256 CU_ASSERT_EQUAL(r, 0);
264 r = amdgpu_va_range_free(*va_handle);
265 CU_ASSERT_EQUAL(r, 0);
268 r = amdgpu_bo_free(buf_handle);
269 CU_ASSERT_EQUAL(r, 0);
274 static inline int gpu_mem_free(amdgpu_bo_handle bo,
275 amdgpu_va_handle va_handle,
285 r = amdgpu_bo_va_op(bo, 0, size, vmc_addr, 0,
287 CU_ASSERT_EQUAL(r, 0);
291 r = amdgpu_va_range_free(va_handle);
292 CU_ASSERT_EQUAL(r, 0);
297 r = amdgpu_bo_free(bo);
298 CU_ASSERT_EQUAL(r, 0);
304 amdgpu_bo_alloc_wrap(amdgpu_device_handle dev, unsigned size,
305 unsigned alignment, unsigned heap, uint64_t flags,
306 amdgpu_bo_handle *bo)
308 struct amdgpu_bo_alloc_request request = {};
309 amdgpu_bo_handle buf_handle;
312 request.alloc_size = size;
313 request.phys_alignment = alignment;
314 request.preferred_heap = heap;
315 request.flags = flags;
317 r = amdgpu_bo_alloc(dev, &request, &buf_handle);
326 int amdgpu_bo_alloc_and_map_raw(amdgpu_device_handle dev, unsigned size,
327 unsigned alignment, unsigned heap, uint64_t alloc_flags,
328 uint64_t mapping_flags, amdgpu_bo_handle *bo, void **cpu,
329 uint64_t *mc_address,
330 amdgpu_va_handle *va_handle);
333 amdgpu_bo_alloc_and_map(amdgpu_device_handle dev, unsigned size,
334 unsigned alignment, unsigned heap, uint64_t alloc_flags,
335 amdgpu_bo_handle *bo, void **cpu, uint64_t *mc_address,
336 amdgpu_va_handle *va_handle)
338 return amdgpu_bo_alloc_and_map_raw(dev, size, alignment, heap,
339 alloc_flags, 0, bo, cpu, mc_address, va_handle);
343 amdgpu_bo_unmap_and_free(amdgpu_bo_handle bo, amdgpu_va_handle va_handle,
344 uint64_t mc_addr, uint64_t size)
346 amdgpu_bo_cpu_unmap(bo);
347 amdgpu_bo_va_op(bo, 0, size, mc_addr, 0, AMDGPU_VA_OP_UNMAP);
348 amdgpu_va_range_free(va_handle);
356 amdgpu_get_bo_list(amdgpu_device_handle dev, amdgpu_bo_handle bo1,
357 amdgpu_bo_handle bo2, amdgpu_bo_list_handle *list)
359 amdgpu_bo_handle resources[] = {bo1, bo2};
361 return amdgpu_bo_list_create(dev, bo2 ? 2 : 1, resources, NULL, list);
365 static inline CU_ErrorCode amdgpu_set_suite_active(const char *suite_name,
368 CU_ErrorCode r = CU_set_suite_active(CU_get_suite(suite_name), active);
370 if (r != CUE_SUCCESS)
371 fprintf(stderr, "Failed to obtain suite %s\n", suite_name);
376 static inline CU_ErrorCode amdgpu_set_test_active(const char *suite_name,
377 const char *test_name, CU_BOOL active)
380 CU_pSuite pSuite = CU_get_suite(suite_name);
383 fprintf(stderr, "Failed to obtain suite %s\n",
388 r = CU_set_test_active(CU_get_test(pSuite, test_name), active);
389 if (r != CUE_SUCCESS)
390 fprintf(stderr, "Failed to obtain test %s\n", test_name);
395 #endif /* #ifdef _AMDGPU_TEST_H_ */