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.
34 #include <sys/types.h>
36 #include <sys/ioctl.h>
42 #include "xf86drmMode.h"
45 #include "CUnit/Basic.h"
47 #include "amdgpu_test.h"
48 #include "amdgpu_internal.h"
50 /* Test suite names */
51 #define BASIC_TESTS_STR "Basic Tests"
52 #define BO_TESTS_STR "BO Tests"
53 #define CS_TESTS_STR "CS Tests"
54 #define VCE_TESTS_STR "VCE Tests"
55 #define VCN_TESTS_STR "VCN Tests"
56 #define UVD_ENC_TESTS_STR "UVD ENC Tests"
57 #define DEADLOCK_TESTS_STR "Deadlock Tests"
58 #define VM_TESTS_STR "VM Tests"
59 #define RAS_TESTS_STR "RAS Tests"
60 #define SYNCOBJ_TIMELINE_TESTS_STR "SYNCOBJ TIMELINE Tests"
63 * Open handles for amdgpu devices
66 int drm_amdgpu[MAX_CARDS_SUPPORTED];
68 /** Open render node to test */
69 int open_render_node = 0; /* By default run most tests on primary node */
71 /** The table of all known test suites to run */
72 static CU_SuiteInfo suites[] = {
74 .pName = BASIC_TESTS_STR,
75 .pInitFunc = suite_basic_tests_init,
76 .pCleanupFunc = suite_basic_tests_clean,
77 .pTests = basic_tests,
80 .pName = BO_TESTS_STR,
81 .pInitFunc = suite_bo_tests_init,
82 .pCleanupFunc = suite_bo_tests_clean,
86 .pName = CS_TESTS_STR,
87 .pInitFunc = suite_cs_tests_init,
88 .pCleanupFunc = suite_cs_tests_clean,
92 .pName = VCE_TESTS_STR,
93 .pInitFunc = suite_vce_tests_init,
94 .pCleanupFunc = suite_vce_tests_clean,
98 .pName = VCN_TESTS_STR,
99 .pInitFunc = suite_vcn_tests_init,
100 .pCleanupFunc = suite_vcn_tests_clean,
104 .pName = UVD_ENC_TESTS_STR,
105 .pInitFunc = suite_uvd_enc_tests_init,
106 .pCleanupFunc = suite_uvd_enc_tests_clean,
107 .pTests = uvd_enc_tests,
110 .pName = DEADLOCK_TESTS_STR,
111 .pInitFunc = suite_deadlock_tests_init,
112 .pCleanupFunc = suite_deadlock_tests_clean,
113 .pTests = deadlock_tests,
116 .pName = VM_TESTS_STR,
117 .pInitFunc = suite_vm_tests_init,
118 .pCleanupFunc = suite_vm_tests_clean,
122 .pName = RAS_TESTS_STR,
123 .pInitFunc = suite_ras_tests_init,
124 .pCleanupFunc = suite_ras_tests_clean,
128 .pName = SYNCOBJ_TIMELINE_TESTS_STR,
129 .pInitFunc = suite_syncobj_timeline_tests_init,
130 .pCleanupFunc = suite_syncobj_timeline_tests_clean,
131 .pTests = syncobj_timeline_tests,
137 typedef CU_BOOL (*active__stat_func)(void);
139 typedef struct Suites_Active_Status {
141 active__stat_func pActive;
142 }Suites_Active_Status;
144 static CU_BOOL always_active()
149 static Suites_Active_Status suites_active_stat[] = {
151 .pName = BASIC_TESTS_STR,
152 .pActive = always_active,
155 .pName = BO_TESTS_STR,
156 .pActive = always_active,
159 .pName = CS_TESTS_STR,
160 .pActive = suite_cs_tests_enable,
163 .pName = VCE_TESTS_STR,
164 .pActive = suite_vce_tests_enable,
167 .pName = VCN_TESTS_STR,
168 .pActive = suite_vcn_tests_enable,
171 .pName = UVD_ENC_TESTS_STR,
172 .pActive = suite_uvd_enc_tests_enable,
175 .pName = DEADLOCK_TESTS_STR,
176 .pActive = suite_deadlock_tests_enable,
179 .pName = VM_TESTS_STR,
180 .pActive = suite_vm_tests_enable,
183 .pName = RAS_TESTS_STR,
184 .pActive = suite_ras_tests_enable,
187 .pName = SYNCOBJ_TIMELINE_TESTS_STR,
188 .pActive = suite_syncobj_timeline_tests_enable,
194 * Display information about all suites and their tests
196 * NOTE: Must be run after registry is initialized and suites registered.
198 static void display_test_suites(void)
202 CU_pSuite pSuite = NULL;
203 CU_pTest pTest = NULL;
207 for (iSuite = 0; suites[iSuite].pName != NULL; iSuite++) {
209 pSuite = CU_get_suite_by_index((unsigned int) iSuite + 1,
213 fprintf(stderr, "Invalid suite id : %d\n", iSuite + 1);
217 printf("Suite id = %d: Name '%s status: %s'\n",
218 iSuite + 1, suites[iSuite].pName,
219 pSuite->fActive ? "ENABLED" : "DISABLED");
223 for (iTest = 0; suites[iSuite].pTests[iTest].pName != NULL;
226 pTest = CU_get_test_by_index((unsigned int) iTest + 1,
230 fprintf(stderr, "Invalid test id : %d\n", iTest + 1);
234 printf("Test id %d: Name: '%s status: %s'\n", iTest + 1,
235 suites[iSuite].pTests[iTest].pName,
236 pSuite->fActive && pTest->fActive ?
237 "ENABLED" : "DISABLED");
243 /** Help string for command line parameters */
244 static const char usage[] =
245 "Usage: %s [-hlpr] [<-s <suite id>> [-t <test id>] [-f]] "
246 "[-b <pci_bus_id> [-d <pci_device_id>]]\n"
248 " l - Display all suites and their tests\n"
249 " r - Run the tests on render node\n"
250 " b - Specify device's PCI bus id to run tests\n"
251 " d - Specify device's PCI device id to run tests (optional)\n"
252 " p - Display information of AMDGPU devices in system\n"
253 " f - Force executing inactive suite or test\n"
254 " h - Display this help\n";
255 /** Specified options strings for getopt */
256 static const char options[] = "hlrps:t:b:d:f";
259 * Return the number of AMD device opened.
261 static int amdgpu_open_devices(int open_render_node)
263 drmDevicePtr devices[MAX_CARDS_SUPPORTED];
269 drmVersionPtr version;
271 drm_count = drmGetDevices2(0, devices, MAX_CARDS_SUPPORTED);
275 "drmGetDevices2() returned an error %d\n",
280 for (i = 0; i < drm_count; i++) {
281 /* If this is not PCI device, skip*/
282 if (devices[i]->bustype != DRM_BUS_PCI)
285 /* If this is not AMD GPU vender ID, skip*/
286 if (devices[i]->deviceinfo.pci->vendor_id != 0x1002)
289 if (open_render_node)
290 drm_node = DRM_NODE_RENDER;
292 drm_node = DRM_NODE_PRIMARY;
295 if (devices[i]->available_nodes & 1 << drm_node)
297 devices[i]->nodes[drm_node],
300 /* This node is not available. */
301 if (fd < 0) continue;
303 version = drmGetVersion(fd);
306 "Warning: Cannot get version for %s."
308 devices[i]->nodes[drm_node],
314 if (strcmp(version->name, "amdgpu")) {
315 /* This is not AMDGPU driver, skip.*/
316 drmFreeVersion(version);
321 drmFreeVersion(version);
323 drm_amdgpu[amd_index] = fd;
327 drmFreeDevices(devices, drm_count);
331 /* Close AMD devices.
333 static void amdgpu_close_devices()
336 for (i = 0; i < MAX_CARDS_SUPPORTED; i++)
337 if (drm_amdgpu[i] >=0)
338 close(drm_amdgpu[i]);
341 /* Print AMD devices information */
342 static void amdgpu_print_devices()
347 /* Open the first AMD device to print driver information. */
348 if (drm_amdgpu[0] >=0) {
349 /* Display AMD driver version information.*/
350 drmVersionPtr retval = drmGetVersion(drm_amdgpu[0]);
352 if (retval == NULL) {
353 perror("Cannot get version for AMDGPU device");
357 printf("Driver name: %s, Date: %s, Description: %s.\n",
358 retval->name, retval->date, retval->desc);
359 drmFreeVersion(retval);
362 /* Display information of AMD devices */
363 printf("Devices:\n");
364 for (i = 0; i < MAX_CARDS_SUPPORTED && drm_amdgpu[i] >=0; i++)
365 if (drmGetDevice2(drm_amdgpu[i],
366 DRM_DEVICE_GET_PCI_REVISION,
368 if (device->bustype == DRM_BUS_PCI) {
370 printf(" domain:%04x",
371 device->businfo.pci->domain);
373 device->businfo.pci->bus);
374 printf(" device:%02x",
375 device->businfo.pci->dev);
376 printf(" function:%01x",
377 device->businfo.pci->func);
378 printf(" vendor_id:%04x",
379 device->deviceinfo.pci->vendor_id);
380 printf(" device_id:%04x",
381 device->deviceinfo.pci->device_id);
382 printf(" subvendor_id:%04x",
383 device->deviceinfo.pci->subvendor_id);
384 printf(" subdevice_id:%04x",
385 device->deviceinfo.pci->subdevice_id);
386 printf(" revision_id:%02x",
387 device->deviceinfo.pci->revision_id);
390 drmFreeDevice(&device);
394 /* Find a match AMD device in PCI bus
395 * Return the index of the device or -1 if not found
397 static int amdgpu_find_device(uint8_t bus, uint16_t dev)
402 for (i = 0; i < MAX_CARDS_SUPPORTED && drm_amdgpu[i] >= 0; i++) {
403 if (drmGetDevice2(drm_amdgpu[i],
404 DRM_DEVICE_GET_PCI_REVISION,
406 if (device->bustype == DRM_BUS_PCI)
407 if ((bus == 0xFF || device->businfo.pci->bus == bus) &&
408 device->deviceinfo.pci->device_id == dev) {
409 drmFreeDevice(&device);
413 drmFreeDevice(&device);
420 static void amdgpu_disable_suites()
422 amdgpu_device_handle device_handle;
423 uint32_t major_version, minor_version, family_id;
425 int size = sizeof(suites_active_stat) / sizeof(suites_active_stat[0]);
427 if (amdgpu_device_initialize(drm_amdgpu[0], &major_version,
428 &minor_version, &device_handle))
431 family_id = device_handle->info.family_id;
433 if (amdgpu_device_deinitialize(device_handle))
436 /* Set active status for suites based on their policies */
437 for (i = 0; i < size; ++i)
438 if (amdgpu_set_suite_active(suites_active_stat[i].pName,
439 suites_active_stat[i].pActive()))
440 fprintf(stderr, "suite deactivation failed - %s\n", CU_get_error_msg());
442 /* Explicitly disable specific tests due to known bugs or preferences */
444 * BUG: Compute ring stalls and never recovers when the address is
445 * written after the command already submitted
447 if (amdgpu_set_test_active(DEADLOCK_TESTS_STR,
448 "compute ring block test (set amdgpu.lockup_timeout=50)", CU_FALSE))
449 fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());
451 if (amdgpu_set_test_active(DEADLOCK_TESTS_STR,
452 "sdma ring block test (set amdgpu.lockup_timeout=50)", CU_FALSE))
453 fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());
455 /* This test was ran on GFX9 only */
456 //if (family_id < AMDGPU_FAMILY_AI || family_id > AMDGPU_FAMILY_RV)
457 if (amdgpu_set_test_active(DEADLOCK_TESTS_STR,
458 "gfx ring bad dispatch test (set amdgpu.lockup_timeout=50)", CU_FALSE))
459 fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());
461 /* This test was ran on GFX9 only */
462 //if (family_id < AMDGPU_FAMILY_AI || family_id > AMDGPU_FAMILY_RV)
463 if (amdgpu_set_test_active(DEADLOCK_TESTS_STR,
464 "compute ring bad dispatch test (set amdgpu.lockup_timeout=50,50)", CU_FALSE))
465 fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());
467 /* This test was ran on GFX9 only */
468 //if (family_id < AMDGPU_FAMILY_AI || family_id > AMDGPU_FAMILY_RV)
469 if (amdgpu_set_test_active(DEADLOCK_TESTS_STR,
470 "gfx ring bad slow dispatch test (set amdgpu.lockup_timeout=50)", CU_FALSE))
471 fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());
473 /* This test was ran on GFX9 only */
474 //if (family_id < AMDGPU_FAMILY_AI || family_id > AMDGPU_FAMILY_RV)
475 if (amdgpu_set_test_active(DEADLOCK_TESTS_STR,
476 "compute ring bad slow dispatch test (set amdgpu.lockup_timeout=50,50)", CU_FALSE))
477 fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());
479 //if (family_id < AMDGPU_FAMILY_AI || family_id > AMDGPU_FAMILY_RV)
480 if (amdgpu_set_test_active(DEADLOCK_TESTS_STR,
481 "gfx ring bad draw test (set amdgpu.lockup_timeout=50)", CU_FALSE))
482 fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());
484 /* This test was ran on GFX9 only */
485 //if (family_id < AMDGPU_FAMILY_AI || family_id > AMDGPU_FAMILY_RV)
486 if (amdgpu_set_test_active(DEADLOCK_TESTS_STR,
487 "gfx ring slow bad draw test (set amdgpu.lockup_timeout=50)", CU_FALSE))
488 fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());
490 if (amdgpu_set_test_active(BO_TESTS_STR, "Metadata", CU_FALSE))
491 fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());
493 if (amdgpu_set_test_active(BASIC_TESTS_STR, "bo eviction Test", CU_FALSE))
494 fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());
496 /* This test was ran on GFX8 and GFX9 only */
497 if (family_id < AMDGPU_FAMILY_VI || family_id > AMDGPU_FAMILY_RV)
498 if (amdgpu_set_test_active(BASIC_TESTS_STR, "Sync dependency Test", CU_FALSE))
499 fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());
501 /* This test was ran on GFX9 only */
502 if (family_id < AMDGPU_FAMILY_AI || family_id > AMDGPU_FAMILY_RV) {
503 if (amdgpu_set_test_active(BASIC_TESTS_STR, "Dispatch Test (GFX)", CU_FALSE))
504 fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());
505 if (amdgpu_set_test_active(BASIC_TESTS_STR, "Dispatch Test (Compute)", CU_FALSE))
506 fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());
509 /* This test was ran on GFX9 only */
510 if (family_id < AMDGPU_FAMILY_AI || family_id > AMDGPU_FAMILY_RV)
511 if (amdgpu_set_test_active(BASIC_TESTS_STR, "Draw Test", CU_FALSE))
512 fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());
514 /* This test was ran on GFX9 only */
515 //if (family_id < AMDGPU_FAMILY_AI || family_id > AMDGPU_FAMILY_RV)
516 if (amdgpu_set_test_active(BASIC_TESTS_STR, "GPU reset Test", CU_FALSE))
517 fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());
520 /* The main() function for setting up and running the tests.
521 * Returns a CUE_SUCCESS on successful running, another
522 * CUnit error code on failure.
524 int main(int argc, char **argv)
526 int c; /* Character received from getopt */
528 int suite_id = -1; /* By default run everything */
529 int test_id = -1; /* By default run all tests in the suite */
530 int pci_bus_id = -1; /* By default PC bus ID is not specified */
531 int pci_device_id = 0; /* By default PC device ID is zero */
532 int display_devices = 0;/* By default not to display devices' info */
533 CU_pSuite pSuite = NULL;
534 CU_pTest pTest = NULL;
535 int test_device_index;
536 int display_list = 0;
539 for (i = 0; i < MAX_CARDS_SUPPORTED; i++)
543 /* Parse command line string */
544 opterr = 0; /* Do not print error messages from getopt */
545 while ((c = getopt(argc, argv, options)) != -1) {
551 suite_id = atoi(optarg);
554 test_id = atoi(optarg);
557 pci_bus_id = atoi(optarg);
560 sscanf(optarg, "%x", &pci_device_id);
566 open_render_node = 1;
573 fprintf(stderr, usage, argv[0]);
576 fprintf(stderr, usage, argv[0]);
581 if (amdgpu_open_devices(open_render_node) <= 0) {
582 perror("Cannot open AMDGPU device");
586 if (drm_amdgpu[0] < 0) {
587 perror("Cannot open AMDGPU device");
591 if (display_devices) {
592 amdgpu_print_devices();
593 amdgpu_close_devices();
597 if (pci_bus_id > 0 || pci_device_id) {
598 /* A device was specified to run the test */
599 test_device_index = amdgpu_find_device(pci_bus_id,
602 if (test_device_index >= 0) {
603 /* Most tests run on device of drm_amdgpu[0].
604 * Swap the chosen device to drm_amdgpu[0].
607 drm_amdgpu[0] = drm_amdgpu[test_device_index];
608 drm_amdgpu[test_device_index] = i;
611 "The specified GPU device does not exist.\n");
616 /* Initialize test suites to run */
618 /* initialize the CUnit test registry */
619 if (CUE_SUCCESS != CU_initialize_registry()) {
620 amdgpu_close_devices();
621 return CU_get_error();
624 /* Register suites. */
625 if (CU_register_suites(suites) != CUE_SUCCESS) {
626 fprintf(stderr, "suite registration failed - %s\n",
628 CU_cleanup_registry();
629 amdgpu_close_devices();
633 /* Run tests using the CUnit Basic interface */
634 CU_basic_set_mode(CU_BRM_VERBOSE);
636 /* Disable suites and individual tests based on misc. conditions */
637 amdgpu_disable_suites();
640 display_test_suites();
644 if (suite_id != -1) { /* If user specify particular suite? */
645 pSuite = CU_get_suite_by_index((unsigned int) suite_id,
651 CU_set_suite_active(pSuite, CU_TRUE);
653 if (test_id != -1) { /* If user specify test id */
654 pTest = CU_get_test_by_index(
655 (unsigned int) test_id,
659 CU_set_test_active(pTest, CU_TRUE);
661 CU_basic_run_test(pSuite, pTest);
664 fprintf(stderr, "Invalid test id: %d\n",
666 CU_cleanup_registry();
667 amdgpu_close_devices();
671 CU_basic_run_suite(pSuite);
673 fprintf(stderr, "Invalid suite id : %d\n",
675 CU_cleanup_registry();
676 amdgpu_close_devices();
680 CU_basic_run_tests();
683 CU_cleanup_registry();
684 amdgpu_close_devices();
685 return CU_get_error();