OSDN Git Service

81870b19ee95715d5e536ca1e05c2883d071e50a
[android-x86/external-libdrm.git] / tests / amdgpu / amdgpu_test.c
1 /*
2  * Copyright 2014 Advanced Micro Devices, Inc.
3  *
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:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
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.
21  *
22 */
23
24 #include <string.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <string.h>
29 #include <ctype.h>
30 #include <fcntl.h>
31 #include <errno.h>
32 #include <signal.h>
33 #include <time.h>
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <sys/ioctl.h>
37 #include <sys/time.h>
38 #include <stdarg.h>
39 #include <stdint.h>
40
41 #include "drm.h"
42 #include "xf86drmMode.h"
43 #include "xf86drm.h"
44
45 #include "CUnit/Basic.h"
46
47 #include "amdgpu_test.h"
48 #include "amdgpu_internal.h"
49
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"
61
62 /**
63  *  Open handles for amdgpu devices
64  *
65  */
66 int drm_amdgpu[MAX_CARDS_SUPPORTED];
67
68 /** Open render node to test */
69 int open_render_node = 0;       /* By default run most tests on primary node */
70
71 /** The table of all known test suites to run */
72 static CU_SuiteInfo suites[] = {
73         {
74                 .pName = BASIC_TESTS_STR,
75                 .pInitFunc = suite_basic_tests_init,
76                 .pCleanupFunc = suite_basic_tests_clean,
77                 .pTests = basic_tests,
78         },
79         {
80                 .pName = BO_TESTS_STR,
81                 .pInitFunc = suite_bo_tests_init,
82                 .pCleanupFunc = suite_bo_tests_clean,
83                 .pTests = bo_tests,
84         },
85         {
86                 .pName = CS_TESTS_STR,
87                 .pInitFunc = suite_cs_tests_init,
88                 .pCleanupFunc = suite_cs_tests_clean,
89                 .pTests = cs_tests,
90         },
91         {
92                 .pName = VCE_TESTS_STR,
93                 .pInitFunc = suite_vce_tests_init,
94                 .pCleanupFunc = suite_vce_tests_clean,
95                 .pTests = vce_tests,
96         },
97         {
98                 .pName = VCN_TESTS_STR,
99                 .pInitFunc = suite_vcn_tests_init,
100                 .pCleanupFunc = suite_vcn_tests_clean,
101                 .pTests = vcn_tests,
102         },
103         {
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,
108         },
109         {
110                 .pName = DEADLOCK_TESTS_STR,
111                 .pInitFunc = suite_deadlock_tests_init,
112                 .pCleanupFunc = suite_deadlock_tests_clean,
113                 .pTests = deadlock_tests,
114         },
115         {
116                 .pName = VM_TESTS_STR,
117                 .pInitFunc = suite_vm_tests_init,
118                 .pCleanupFunc = suite_vm_tests_clean,
119                 .pTests = vm_tests,
120         },
121         {
122                 .pName = RAS_TESTS_STR,
123                 .pInitFunc = suite_ras_tests_init,
124                 .pCleanupFunc = suite_ras_tests_clean,
125                 .pTests = ras_tests,
126         },
127         {
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,
132         },
133
134         CU_SUITE_INFO_NULL,
135 };
136
137 typedef CU_BOOL (*active__stat_func)(void);
138
139 typedef struct Suites_Active_Status {
140         char*             pName;
141         active__stat_func pActive;
142 }Suites_Active_Status;
143
144 static CU_BOOL always_active()
145 {
146         return CU_TRUE;
147 }
148
149 static Suites_Active_Status suites_active_stat[] = {
150                 {
151                         .pName = BASIC_TESTS_STR,
152                         .pActive = always_active,
153                 },
154                 {
155                         .pName = BO_TESTS_STR,
156                         .pActive = always_active,
157                 },
158                 {
159                         .pName = CS_TESTS_STR,
160                         .pActive = suite_cs_tests_enable,
161                 },
162                 {
163                         .pName = VCE_TESTS_STR,
164                         .pActive = suite_vce_tests_enable,
165                 },
166                 {
167                         .pName = VCN_TESTS_STR,
168                         .pActive = suite_vcn_tests_enable,
169                 },
170                 {
171                         .pName = UVD_ENC_TESTS_STR,
172                         .pActive = suite_uvd_enc_tests_enable,
173                 },
174                 {
175                         .pName = DEADLOCK_TESTS_STR,
176                         .pActive = suite_deadlock_tests_enable,
177                 },
178                 {
179                         .pName = VM_TESTS_STR,
180                         .pActive = suite_vm_tests_enable,
181                 },
182                 {
183                         .pName = RAS_TESTS_STR,
184                         .pActive = suite_ras_tests_enable,
185                 },
186                 {
187                         .pName = SYNCOBJ_TIMELINE_TESTS_STR,
188                         .pActive = suite_syncobj_timeline_tests_enable,
189                 },
190 };
191
192
193 /*
194  * Display information about all  suites and their tests
195  *
196  * NOTE: Must be run after registry is initialized and suites registered.
197  */
198 static void display_test_suites(void)
199 {
200         int iSuite;
201         int iTest;
202         CU_pSuite pSuite = NULL;
203         CU_pTest  pTest  = NULL;
204
205         printf("Suites\n");
206
207         for (iSuite = 0; suites[iSuite].pName != NULL; iSuite++) {
208
209                 pSuite = CU_get_suite_by_index((unsigned int) iSuite + 1,
210                                                       CU_get_registry());
211
212                 if (!pSuite) {
213                         fprintf(stderr, "Invalid suite id : %d\n", iSuite + 1);
214                         continue;
215                 }
216
217                 printf("Suite id = %d: Name '%s status: %s'\n",
218                                 iSuite + 1, suites[iSuite].pName,
219                                 pSuite->fActive ? "ENABLED" : "DISABLED");
220
221
222
223                 for (iTest = 0; suites[iSuite].pTests[iTest].pName != NULL;
224                         iTest++) {
225
226                         pTest = CU_get_test_by_index((unsigned int) iTest + 1,
227                                                                         pSuite);
228
229                         if (!pTest) {
230                                 fprintf(stderr, "Invalid test id : %d\n", iTest + 1);
231                                 continue;
232                         }
233
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");
238                 }
239         }
240 }
241
242
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"
247         "where:\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";
257
258 /* Open AMD devices.
259  * Return the number of AMD device opened.
260  */
261 static int amdgpu_open_devices(int open_render_node)
262 {
263         drmDevicePtr devices[MAX_CARDS_SUPPORTED];
264         int i;
265         int drm_node;
266         int amd_index = 0;
267         int drm_count;
268         int fd;
269         drmVersionPtr version;
270
271         drm_count = drmGetDevices2(0, devices, MAX_CARDS_SUPPORTED);
272
273         if (drm_count < 0) {
274                 fprintf(stderr,
275                         "drmGetDevices2() returned an error %d\n",
276                         drm_count);
277                 return 0;
278         }
279
280         for (i = 0; i < drm_count; i++) {
281                 /* If this is not PCI device, skip*/
282                 if (devices[i]->bustype != DRM_BUS_PCI)
283                         continue;
284
285                 /* If this is not AMD GPU vender ID, skip*/
286                 if (devices[i]->deviceinfo.pci->vendor_id != 0x1002)
287                         continue;
288
289                 if (open_render_node)
290                         drm_node = DRM_NODE_RENDER;
291                 else
292                         drm_node = DRM_NODE_PRIMARY;
293
294                 fd = -1;
295                 if (devices[i]->available_nodes & 1 << drm_node)
296                         fd = open(
297                                 devices[i]->nodes[drm_node],
298                                 O_RDWR | O_CLOEXEC);
299
300                 /* This node is not available. */
301                 if (fd < 0) continue;
302
303                 version = drmGetVersion(fd);
304                 if (!version) {
305                         fprintf(stderr,
306                                 "Warning: Cannot get version for %s."
307                                 "Error is %s\n",
308                                 devices[i]->nodes[drm_node],
309                                 strerror(errno));
310                         close(fd);
311                         continue;
312                 }
313
314                 if (strcmp(version->name, "amdgpu")) {
315                         /* This is not AMDGPU driver, skip.*/
316                         drmFreeVersion(version);
317                         close(fd);
318                         continue;
319                 }
320
321                 drmFreeVersion(version);
322
323                 drm_amdgpu[amd_index] = fd;
324                 amd_index++;
325         }
326
327         drmFreeDevices(devices, drm_count);
328         return amd_index;
329 }
330
331 /* Close AMD devices.
332  */
333 static void amdgpu_close_devices()
334 {
335         int i;
336         for (i = 0; i < MAX_CARDS_SUPPORTED; i++)
337                 if (drm_amdgpu[i] >=0)
338                         close(drm_amdgpu[i]);
339 }
340
341 /* Print AMD devices information */
342 static void amdgpu_print_devices()
343 {
344         int i;
345         drmDevicePtr device;
346
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]);
351
352                 if (retval == NULL) {
353                         perror("Cannot get version for AMDGPU device");
354                         return;
355                 }
356
357                 printf("Driver name: %s, Date: %s, Description: %s.\n",
358                         retval->name, retval->date, retval->desc);
359                 drmFreeVersion(retval);
360         }
361
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,
367                         &device) == 0) {
368                         if (device->bustype == DRM_BUS_PCI) {
369                                 printf("PCI ");
370                                 printf(" domain:%04x",
371                                         device->businfo.pci->domain);
372                                 printf(" bus:%02x",
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);
388                                 printf("\n");
389                         }
390                         drmFreeDevice(&device);
391                 }
392 }
393
394 /* Find a match AMD device in PCI bus
395  * Return the index of the device or -1 if not found
396  */
397 static int amdgpu_find_device(uint8_t bus, uint16_t dev)
398 {
399         int i;
400         drmDevicePtr device;
401
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,
405                         &device) == 0) {
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);
410                                         return i;
411                                 }
412
413                         drmFreeDevice(&device);
414                 }
415         }
416
417         return -1;
418 }
419
420 static void amdgpu_disable_suites()
421 {
422         amdgpu_device_handle device_handle;
423         uint32_t major_version, minor_version, family_id;
424         int i;
425         int size = sizeof(suites_active_stat) / sizeof(suites_active_stat[0]);
426
427         if (amdgpu_device_initialize(drm_amdgpu[0], &major_version,
428                                    &minor_version, &device_handle))
429                 return;
430
431         family_id = device_handle->info.family_id;
432
433         if (amdgpu_device_deinitialize(device_handle))
434                 return;
435
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());
441
442         /* Explicitly disable specific tests due to known bugs or preferences */
443         /*
444         * BUG: Compute ring stalls and never recovers when the address is
445         * written after the command already submitted
446         */
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());
450
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());
454
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());
460
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());
466
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());
472
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());
478
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());
483
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());
489
490         if (amdgpu_set_test_active(BO_TESTS_STR, "Metadata", CU_FALSE))
491                 fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());
492
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());
495
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());
500
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());
507         }
508
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());
513
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());
518 }
519
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.
523  */
524 int main(int argc, char **argv)
525 {
526         int c;                  /* Character received from getopt */
527         int i = 0;
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;
537         int force_run = 0;
538
539         for (i = 0; i < MAX_CARDS_SUPPORTED; i++)
540                 drm_amdgpu[i] = -1;
541
542
543         /* Parse command line string */
544         opterr = 0;             /* Do not print error messages from getopt */
545         while ((c = getopt(argc, argv, options)) != -1) {
546                 switch (c) {
547                 case 'l':
548                         display_list = 1;
549                         break;
550                 case 's':
551                         suite_id = atoi(optarg);
552                         break;
553                 case 't':
554                         test_id = atoi(optarg);
555                         break;
556                 case 'b':
557                         pci_bus_id = atoi(optarg);
558                         break;
559                 case 'd':
560                         sscanf(optarg, "%x", &pci_device_id);
561                         break;
562                 case 'p':
563                         display_devices = 1;
564                         break;
565                 case 'r':
566                         open_render_node = 1;
567                         break;
568                 case 'f':
569                         force_run = 1;
570                         break;
571                 case '?':
572                 case 'h':
573                         fprintf(stderr, usage, argv[0]);
574                         exit(EXIT_SUCCESS);
575                 default:
576                         fprintf(stderr, usage, argv[0]);
577                         exit(EXIT_FAILURE);
578                 }
579         }
580
581         if (amdgpu_open_devices(open_render_node) <= 0) {
582                 perror("Cannot open AMDGPU device");
583                 exit(EXIT_FAILURE);
584         }
585
586         if (drm_amdgpu[0] < 0) {
587                 perror("Cannot open AMDGPU device");
588                 exit(EXIT_FAILURE);
589         }
590
591         if (display_devices) {
592                 amdgpu_print_devices();
593                 amdgpu_close_devices();
594                 exit(EXIT_SUCCESS);
595         }
596
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,
600                                                        pci_device_id);
601
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].
605                          */
606                         i = drm_amdgpu[0];
607                         drm_amdgpu[0] = drm_amdgpu[test_device_index];
608                         drm_amdgpu[test_device_index] = i;
609                 } else {
610                         fprintf(stderr,
611                                 "The specified GPU device does not exist.\n");
612                         exit(EXIT_FAILURE);
613                 }
614         }
615
616         /* Initialize test suites to run */
617
618         /* initialize the CUnit test registry */
619         if (CUE_SUCCESS != CU_initialize_registry()) {
620                 amdgpu_close_devices();
621                 return CU_get_error();
622         }
623
624         /* Register suites. */
625         if (CU_register_suites(suites) != CUE_SUCCESS) {
626                 fprintf(stderr, "suite registration failed - %s\n",
627                                 CU_get_error_msg());
628                 CU_cleanup_registry();
629                 amdgpu_close_devices();
630                 exit(EXIT_FAILURE);
631         }
632
633         /* Run tests using the CUnit Basic interface */
634         CU_basic_set_mode(CU_BRM_VERBOSE);
635
636         /* Disable suites and individual tests based on misc. conditions */
637         amdgpu_disable_suites();
638
639         if (display_list) {
640                 display_test_suites();
641                 goto end;
642         }
643
644         if (suite_id != -1) {   /* If user specify particular suite? */
645                 pSuite = CU_get_suite_by_index((unsigned int) suite_id,
646                                                 CU_get_registry());
647
648                 if (pSuite) {
649
650                         if (force_run)
651                                 CU_set_suite_active(pSuite, CU_TRUE);
652
653                         if (test_id != -1) {   /* If user specify test id */
654                                 pTest = CU_get_test_by_index(
655                                                 (unsigned int) test_id,
656                                                 pSuite);
657                                 if (pTest) {
658                                         if (force_run)
659                                                 CU_set_test_active(pTest, CU_TRUE);
660
661                                         CU_basic_run_test(pSuite, pTest);
662                                 }
663                                 else {
664                                         fprintf(stderr, "Invalid test id: %d\n",
665                                                                 test_id);
666                                         CU_cleanup_registry();
667                                         amdgpu_close_devices();
668                                         exit(EXIT_FAILURE);
669                                 }
670                         } else
671                                 CU_basic_run_suite(pSuite);
672                 } else {
673                         fprintf(stderr, "Invalid suite id : %d\n",
674                                         suite_id);
675                         CU_cleanup_registry();
676                         amdgpu_close_devices();
677                         exit(EXIT_FAILURE);
678                 }
679         } else
680                 CU_basic_run_tests();
681
682 end:
683         CU_cleanup_registry();
684         amdgpu_close_devices();
685         return CU_get_error();
686 }