amdgpu_test.c revision 5324fb0d
13f012e29Smrg/* 23f012e29Smrg * Copyright 2014 Advanced Micro Devices, Inc. 33f012e29Smrg * 43f012e29Smrg * Permission is hereby granted, free of charge, to any person obtaining a 53f012e29Smrg * copy of this software and associated documentation files (the "Software"), 63f012e29Smrg * to deal in the Software without restriction, including without limitation 73f012e29Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 83f012e29Smrg * and/or sell copies of the Software, and to permit persons to whom the 93f012e29Smrg * Software is furnished to do so, subject to the following conditions: 103f012e29Smrg * 113f012e29Smrg * The above copyright notice and this permission notice shall be included in 123f012e29Smrg * all copies or substantial portions of the Software. 133f012e29Smrg * 143f012e29Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 153f012e29Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 163f012e29Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 173f012e29Smrg * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 183f012e29Smrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 193f012e29Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 203f012e29Smrg * OTHER DEALINGS IN THE SOFTWARE. 213f012e29Smrg * 223f012e29Smrg*/ 233f012e29Smrg 243f012e29Smrg#include <string.h> 253f012e29Smrg#include <stdio.h> 263f012e29Smrg#include <stdlib.h> 273f012e29Smrg#include <unistd.h> 283f012e29Smrg#include <string.h> 293f012e29Smrg#include <ctype.h> 303f012e29Smrg#include <fcntl.h> 313f012e29Smrg#include <errno.h> 323f012e29Smrg#include <signal.h> 333f012e29Smrg#include <time.h> 343f012e29Smrg#include <sys/types.h> 353f012e29Smrg#include <sys/stat.h> 363f012e29Smrg#include <sys/ioctl.h> 373f012e29Smrg#include <sys/time.h> 383f012e29Smrg#include <stdarg.h> 393f012e29Smrg#include <stdint.h> 403f012e29Smrg 413f012e29Smrg#include "drm.h" 423f012e29Smrg#include "xf86drmMode.h" 433f012e29Smrg#include "xf86drm.h" 443f012e29Smrg 453f012e29Smrg#include "CUnit/Basic.h" 463f012e29Smrg 473f012e29Smrg#include "amdgpu_test.h" 4800a23bdaSmrg#include "amdgpu_internal.h" 4900a23bdaSmrg 5000a23bdaSmrg/* Test suite names */ 5100a23bdaSmrg#define BASIC_TESTS_STR "Basic Tests" 5200a23bdaSmrg#define BO_TESTS_STR "BO Tests" 5300a23bdaSmrg#define CS_TESTS_STR "CS Tests" 5400a23bdaSmrg#define VCE_TESTS_STR "VCE Tests" 5500a23bdaSmrg#define VCN_TESTS_STR "VCN Tests" 5600a23bdaSmrg#define UVD_ENC_TESTS_STR "UVD ENC Tests" 5700a23bdaSmrg#define DEADLOCK_TESTS_STR "Deadlock Tests" 5800a23bdaSmrg#define VM_TESTS_STR "VM Tests" 595324fb0dSmrg#define RAS_TESTS_STR "RAS Tests" 605324fb0dSmrg#define SYNCOBJ_TIMELINE_TESTS_STR "SYNCOBJ TIMELINE Tests" 613f012e29Smrg 623f012e29Smrg/** 633f012e29Smrg * Open handles for amdgpu devices 643f012e29Smrg * 653f012e29Smrg */ 663f012e29Smrgint drm_amdgpu[MAX_CARDS_SUPPORTED]; 673f012e29Smrg 68037b3c26Smrg/** Open render node to test */ 69037b3c26Smrgint open_render_node = 0; /* By default run most tests on primary node */ 70037b3c26Smrg 713f012e29Smrg/** The table of all known test suites to run */ 723f012e29Smrgstatic CU_SuiteInfo suites[] = { 733f012e29Smrg { 7400a23bdaSmrg .pName = BASIC_TESTS_STR, 753f012e29Smrg .pInitFunc = suite_basic_tests_init, 763f012e29Smrg .pCleanupFunc = suite_basic_tests_clean, 773f012e29Smrg .pTests = basic_tests, 783f012e29Smrg }, 793f012e29Smrg { 8000a23bdaSmrg .pName = BO_TESTS_STR, 813f012e29Smrg .pInitFunc = suite_bo_tests_init, 823f012e29Smrg .pCleanupFunc = suite_bo_tests_clean, 833f012e29Smrg .pTests = bo_tests, 843f012e29Smrg }, 853f012e29Smrg { 8600a23bdaSmrg .pName = CS_TESTS_STR, 873f012e29Smrg .pInitFunc = suite_cs_tests_init, 883f012e29Smrg .pCleanupFunc = suite_cs_tests_clean, 893f012e29Smrg .pTests = cs_tests, 903f012e29Smrg }, 913f012e29Smrg { 9200a23bdaSmrg .pName = VCE_TESTS_STR, 933f012e29Smrg .pInitFunc = suite_vce_tests_init, 943f012e29Smrg .pCleanupFunc = suite_vce_tests_clean, 953f012e29Smrg .pTests = vce_tests, 963f012e29Smrg }, 97d8807b2fSmrg { 9800a23bdaSmrg .pName = VCN_TESTS_STR, 99d8807b2fSmrg .pInitFunc = suite_vcn_tests_init, 100d8807b2fSmrg .pCleanupFunc = suite_vcn_tests_clean, 101d8807b2fSmrg .pTests = vcn_tests, 102d8807b2fSmrg }, 103d8807b2fSmrg { 10400a23bdaSmrg .pName = UVD_ENC_TESTS_STR, 105d8807b2fSmrg .pInitFunc = suite_uvd_enc_tests_init, 106d8807b2fSmrg .pCleanupFunc = suite_uvd_enc_tests_clean, 107d8807b2fSmrg .pTests = uvd_enc_tests, 108d8807b2fSmrg }, 10900a23bdaSmrg { 11000a23bdaSmrg .pName = DEADLOCK_TESTS_STR, 11100a23bdaSmrg .pInitFunc = suite_deadlock_tests_init, 11200a23bdaSmrg .pCleanupFunc = suite_deadlock_tests_clean, 11300a23bdaSmrg .pTests = deadlock_tests, 11400a23bdaSmrg }, 11500a23bdaSmrg { 11600a23bdaSmrg .pName = VM_TESTS_STR, 11700a23bdaSmrg .pInitFunc = suite_vm_tests_init, 11800a23bdaSmrg .pCleanupFunc = suite_vm_tests_clean, 11900a23bdaSmrg .pTests = vm_tests, 12000a23bdaSmrg }, 1215324fb0dSmrg { 1225324fb0dSmrg .pName = RAS_TESTS_STR, 1235324fb0dSmrg .pInitFunc = suite_ras_tests_init, 1245324fb0dSmrg .pCleanupFunc = suite_ras_tests_clean, 1255324fb0dSmrg .pTests = ras_tests, 1265324fb0dSmrg }, 1275324fb0dSmrg { 1285324fb0dSmrg .pName = SYNCOBJ_TIMELINE_TESTS_STR, 1295324fb0dSmrg .pInitFunc = suite_syncobj_timeline_tests_init, 1305324fb0dSmrg .pCleanupFunc = suite_syncobj_timeline_tests_clean, 1315324fb0dSmrg .pTests = syncobj_timeline_tests, 1325324fb0dSmrg }, 13300a23bdaSmrg 1343f012e29Smrg CU_SUITE_INFO_NULL, 1353f012e29Smrg}; 1363f012e29Smrg 13700a23bdaSmrgtypedef CU_BOOL (*active__stat_func)(void); 13800a23bdaSmrg 13900a23bdaSmrgtypedef struct Suites_Active_Status { 14000a23bdaSmrg char* pName; 14100a23bdaSmrg active__stat_func pActive; 14200a23bdaSmrg}Suites_Active_Status; 1433f012e29Smrg 14400a23bdaSmrgstatic CU_BOOL always_active() 14500a23bdaSmrg{ 14600a23bdaSmrg return CU_TRUE; 14700a23bdaSmrg} 14800a23bdaSmrg 14900a23bdaSmrgstatic Suites_Active_Status suites_active_stat[] = { 15000a23bdaSmrg { 15100a23bdaSmrg .pName = BASIC_TESTS_STR, 15200a23bdaSmrg .pActive = always_active, 15300a23bdaSmrg }, 15400a23bdaSmrg { 15500a23bdaSmrg .pName = BO_TESTS_STR, 15600a23bdaSmrg .pActive = always_active, 15700a23bdaSmrg }, 15800a23bdaSmrg { 15900a23bdaSmrg .pName = CS_TESTS_STR, 16000a23bdaSmrg .pActive = suite_cs_tests_enable, 16100a23bdaSmrg }, 16200a23bdaSmrg { 16300a23bdaSmrg .pName = VCE_TESTS_STR, 16400a23bdaSmrg .pActive = suite_vce_tests_enable, 16500a23bdaSmrg }, 16600a23bdaSmrg { 16700a23bdaSmrg .pName = VCN_TESTS_STR, 16800a23bdaSmrg .pActive = suite_vcn_tests_enable, 16900a23bdaSmrg }, 17000a23bdaSmrg { 17100a23bdaSmrg .pName = UVD_ENC_TESTS_STR, 17200a23bdaSmrg .pActive = suite_uvd_enc_tests_enable, 17300a23bdaSmrg }, 17400a23bdaSmrg { 17500a23bdaSmrg .pName = DEADLOCK_TESTS_STR, 17600a23bdaSmrg .pActive = suite_deadlock_tests_enable, 17700a23bdaSmrg }, 17800a23bdaSmrg { 17900a23bdaSmrg .pName = VM_TESTS_STR, 18000a23bdaSmrg .pActive = suite_vm_tests_enable, 18100a23bdaSmrg }, 1825324fb0dSmrg { 1835324fb0dSmrg .pName = RAS_TESTS_STR, 1845324fb0dSmrg .pActive = suite_ras_tests_enable, 1855324fb0dSmrg }, 1865324fb0dSmrg { 1875324fb0dSmrg .pName = SYNCOBJ_TIMELINE_TESTS_STR, 1885324fb0dSmrg .pActive = suite_syncobj_timeline_tests_enable, 1895324fb0dSmrg }, 19000a23bdaSmrg}; 19100a23bdaSmrg 19200a23bdaSmrg 19300a23bdaSmrg/* 19400a23bdaSmrg * Display information about all suites and their tests 19500a23bdaSmrg * 19600a23bdaSmrg * NOTE: Must be run after registry is initialized and suites registered. 19700a23bdaSmrg */ 1983f012e29Smrgstatic void display_test_suites(void) 1993f012e29Smrg{ 2003f012e29Smrg int iSuite; 2013f012e29Smrg int iTest; 20200a23bdaSmrg CU_pSuite pSuite = NULL; 20300a23bdaSmrg CU_pTest pTest = NULL; 2043f012e29Smrg 2053f012e29Smrg printf("Suites\n"); 2063f012e29Smrg 2073f012e29Smrg for (iSuite = 0; suites[iSuite].pName != NULL; iSuite++) { 20800a23bdaSmrg 20900a23bdaSmrg pSuite = CU_get_suite_by_index((unsigned int) iSuite + 1, 21000a23bdaSmrg CU_get_registry()); 21100a23bdaSmrg 21200a23bdaSmrg if (!pSuite) { 21300a23bdaSmrg fprintf(stderr, "Invalid suite id : %d\n", iSuite + 1); 21400a23bdaSmrg continue; 21500a23bdaSmrg } 21600a23bdaSmrg 21700a23bdaSmrg printf("Suite id = %d: Name '%s status: %s'\n", 21800a23bdaSmrg iSuite + 1, suites[iSuite].pName, 21900a23bdaSmrg pSuite->fActive ? "ENABLED" : "DISABLED"); 22000a23bdaSmrg 22100a23bdaSmrg 2223f012e29Smrg 2233f012e29Smrg for (iTest = 0; suites[iSuite].pTests[iTest].pName != NULL; 2243f012e29Smrg iTest++) { 22500a23bdaSmrg 22600a23bdaSmrg pTest = CU_get_test_by_index((unsigned int) iTest + 1, 22700a23bdaSmrg pSuite); 22800a23bdaSmrg 22900a23bdaSmrg if (!pTest) { 23000a23bdaSmrg fprintf(stderr, "Invalid test id : %d\n", iTest + 1); 23100a23bdaSmrg continue; 23200a23bdaSmrg } 23300a23bdaSmrg 23400a23bdaSmrg printf("Test id %d: Name: '%s status: %s'\n", iTest + 1, 23500a23bdaSmrg suites[iSuite].pTests[iTest].pName, 23600a23bdaSmrg pSuite->fActive && pTest->fActive ? 23700a23bdaSmrg "ENABLED" : "DISABLED"); 2383f012e29Smrg } 2393f012e29Smrg } 2403f012e29Smrg} 2413f012e29Smrg 2423f012e29Smrg 2433f012e29Smrg/** Help string for command line parameters */ 244037b3c26Smrgstatic const char usage[] = 24500a23bdaSmrg "Usage: %s [-hlpr] [<-s <suite id>> [-t <test id>] [-f]] " 246037b3c26Smrg "[-b <pci_bus_id> [-d <pci_device_id>]]\n" 247037b3c26Smrg "where:\n" 248037b3c26Smrg " l - Display all suites and their tests\n" 249037b3c26Smrg " r - Run the tests on render node\n" 250037b3c26Smrg " b - Specify device's PCI bus id to run tests\n" 251037b3c26Smrg " d - Specify device's PCI device id to run tests (optional)\n" 252037b3c26Smrg " p - Display information of AMDGPU devices in system\n" 25300a23bdaSmrg " f - Force executing inactive suite or test\n" 254037b3c26Smrg " h - Display this help\n"; 2553f012e29Smrg/** Specified options strings for getopt */ 25600a23bdaSmrgstatic const char options[] = "hlrps:t:b:d:f"; 257037b3c26Smrg 258037b3c26Smrg/* Open AMD devices. 2595324fb0dSmrg * Return the number of AMD device opened. 260037b3c26Smrg */ 261037b3c26Smrgstatic int amdgpu_open_devices(int open_render_node) 262037b3c26Smrg{ 263037b3c26Smrg drmDevicePtr devices[MAX_CARDS_SUPPORTED]; 264037b3c26Smrg int i; 265037b3c26Smrg int drm_node; 266037b3c26Smrg int amd_index = 0; 267037b3c26Smrg int drm_count; 268037b3c26Smrg int fd; 269037b3c26Smrg drmVersionPtr version; 270037b3c26Smrg 271037b3c26Smrg drm_count = drmGetDevices2(0, devices, MAX_CARDS_SUPPORTED); 272037b3c26Smrg 273037b3c26Smrg if (drm_count < 0) { 274037b3c26Smrg fprintf(stderr, 275037b3c26Smrg "drmGetDevices2() returned an error %d\n", 276037b3c26Smrg drm_count); 277037b3c26Smrg return 0; 278037b3c26Smrg } 279037b3c26Smrg 280037b3c26Smrg for (i = 0; i < drm_count; i++) { 281037b3c26Smrg /* If this is not PCI device, skip*/ 282037b3c26Smrg if (devices[i]->bustype != DRM_BUS_PCI) 283037b3c26Smrg continue; 284037b3c26Smrg 285037b3c26Smrg /* If this is not AMD GPU vender ID, skip*/ 286037b3c26Smrg if (devices[i]->deviceinfo.pci->vendor_id != 0x1002) 287037b3c26Smrg continue; 288037b3c26Smrg 289037b3c26Smrg if (open_render_node) 290037b3c26Smrg drm_node = DRM_NODE_RENDER; 291037b3c26Smrg else 292037b3c26Smrg drm_node = DRM_NODE_PRIMARY; 293037b3c26Smrg 294037b3c26Smrg fd = -1; 295037b3c26Smrg if (devices[i]->available_nodes & 1 << drm_node) 296037b3c26Smrg fd = open( 297037b3c26Smrg devices[i]->nodes[drm_node], 298037b3c26Smrg O_RDWR | O_CLOEXEC); 299037b3c26Smrg 300037b3c26Smrg /* This node is not available. */ 301037b3c26Smrg if (fd < 0) continue; 302037b3c26Smrg 303037b3c26Smrg version = drmGetVersion(fd); 304037b3c26Smrg if (!version) { 305037b3c26Smrg fprintf(stderr, 306037b3c26Smrg "Warning: Cannot get version for %s." 307037b3c26Smrg "Error is %s\n", 308037b3c26Smrg devices[i]->nodes[drm_node], 309037b3c26Smrg strerror(errno)); 310037b3c26Smrg close(fd); 311037b3c26Smrg continue; 312037b3c26Smrg } 313037b3c26Smrg 314037b3c26Smrg if (strcmp(version->name, "amdgpu")) { 315037b3c26Smrg /* This is not AMDGPU driver, skip.*/ 316037b3c26Smrg drmFreeVersion(version); 317037b3c26Smrg close(fd); 318037b3c26Smrg continue; 319037b3c26Smrg } 320037b3c26Smrg 321037b3c26Smrg drmFreeVersion(version); 322037b3c26Smrg 323037b3c26Smrg drm_amdgpu[amd_index] = fd; 324037b3c26Smrg amd_index++; 325037b3c26Smrg } 326037b3c26Smrg 327037b3c26Smrg drmFreeDevices(devices, drm_count); 328037b3c26Smrg return amd_index; 329037b3c26Smrg} 330037b3c26Smrg 331037b3c26Smrg/* Close AMD devices. 332037b3c26Smrg */ 333037b3c26Smrgstatic void amdgpu_close_devices() 334037b3c26Smrg{ 335037b3c26Smrg int i; 336037b3c26Smrg for (i = 0; i < MAX_CARDS_SUPPORTED; i++) 337037b3c26Smrg if (drm_amdgpu[i] >=0) 338037b3c26Smrg close(drm_amdgpu[i]); 339037b3c26Smrg} 340037b3c26Smrg 341037b3c26Smrg/* Print AMD devices information */ 342037b3c26Smrgstatic void amdgpu_print_devices() 343037b3c26Smrg{ 344037b3c26Smrg int i; 345037b3c26Smrg drmDevicePtr device; 346037b3c26Smrg 3475324fb0dSmrg /* Open the first AMD device to print driver information. */ 348037b3c26Smrg if (drm_amdgpu[0] >=0) { 349037b3c26Smrg /* Display AMD driver version information.*/ 350037b3c26Smrg drmVersionPtr retval = drmGetVersion(drm_amdgpu[0]); 351037b3c26Smrg 352037b3c26Smrg if (retval == NULL) { 353037b3c26Smrg perror("Cannot get version for AMDGPU device"); 354037b3c26Smrg return; 355037b3c26Smrg } 356037b3c26Smrg 357037b3c26Smrg printf("Driver name: %s, Date: %s, Description: %s.\n", 358037b3c26Smrg retval->name, retval->date, retval->desc); 359037b3c26Smrg drmFreeVersion(retval); 360037b3c26Smrg } 361037b3c26Smrg 362037b3c26Smrg /* Display information of AMD devices */ 363037b3c26Smrg printf("Devices:\n"); 364037b3c26Smrg for (i = 0; i < MAX_CARDS_SUPPORTED && drm_amdgpu[i] >=0; i++) 365037b3c26Smrg if (drmGetDevice2(drm_amdgpu[i], 366037b3c26Smrg DRM_DEVICE_GET_PCI_REVISION, 367037b3c26Smrg &device) == 0) { 368037b3c26Smrg if (device->bustype == DRM_BUS_PCI) { 369037b3c26Smrg printf("PCI "); 370037b3c26Smrg printf(" domain:%04x", 371037b3c26Smrg device->businfo.pci->domain); 372037b3c26Smrg printf(" bus:%02x", 373037b3c26Smrg device->businfo.pci->bus); 374037b3c26Smrg printf(" device:%02x", 375037b3c26Smrg device->businfo.pci->dev); 376037b3c26Smrg printf(" function:%01x", 377037b3c26Smrg device->businfo.pci->func); 378037b3c26Smrg printf(" vendor_id:%04x", 379037b3c26Smrg device->deviceinfo.pci->vendor_id); 380037b3c26Smrg printf(" device_id:%04x", 381037b3c26Smrg device->deviceinfo.pci->device_id); 382037b3c26Smrg printf(" subvendor_id:%04x", 383037b3c26Smrg device->deviceinfo.pci->subvendor_id); 384037b3c26Smrg printf(" subdevice_id:%04x", 385037b3c26Smrg device->deviceinfo.pci->subdevice_id); 386037b3c26Smrg printf(" revision_id:%02x", 387037b3c26Smrg device->deviceinfo.pci->revision_id); 388037b3c26Smrg printf("\n"); 389037b3c26Smrg } 390037b3c26Smrg drmFreeDevice(&device); 391037b3c26Smrg } 392037b3c26Smrg} 393037b3c26Smrg 394037b3c26Smrg/* Find a match AMD device in PCI bus 395037b3c26Smrg * Return the index of the device or -1 if not found 396037b3c26Smrg */ 397d8807b2fSmrgstatic int amdgpu_find_device(uint8_t bus, uint16_t dev) 398037b3c26Smrg{ 399037b3c26Smrg int i; 400037b3c26Smrg drmDevicePtr device; 401037b3c26Smrg 402d8807b2fSmrg for (i = 0; i < MAX_CARDS_SUPPORTED && drm_amdgpu[i] >= 0; i++) { 403037b3c26Smrg if (drmGetDevice2(drm_amdgpu[i], 404037b3c26Smrg DRM_DEVICE_GET_PCI_REVISION, 405037b3c26Smrg &device) == 0) { 406037b3c26Smrg if (device->bustype == DRM_BUS_PCI) 407d8807b2fSmrg if ((bus == 0xFF || device->businfo.pci->bus == bus) && 408d8807b2fSmrg device->deviceinfo.pci->device_id == dev) { 409037b3c26Smrg drmFreeDevice(&device); 410037b3c26Smrg return i; 411037b3c26Smrg } 412037b3c26Smrg 413037b3c26Smrg drmFreeDevice(&device); 414037b3c26Smrg } 415d8807b2fSmrg } 416037b3c26Smrg 417037b3c26Smrg return -1; 418037b3c26Smrg} 4193f012e29Smrg 42000a23bdaSmrgstatic void amdgpu_disable_suites() 42100a23bdaSmrg{ 42200a23bdaSmrg amdgpu_device_handle device_handle; 42300a23bdaSmrg uint32_t major_version, minor_version, family_id; 42400a23bdaSmrg int i; 42500a23bdaSmrg int size = sizeof(suites_active_stat) / sizeof(suites_active_stat[0]); 42600a23bdaSmrg 42700a23bdaSmrg if (amdgpu_device_initialize(drm_amdgpu[0], &major_version, 42800a23bdaSmrg &minor_version, &device_handle)) 42900a23bdaSmrg return; 43000a23bdaSmrg 43100a23bdaSmrg family_id = device_handle->info.family_id; 43200a23bdaSmrg 43300a23bdaSmrg if (amdgpu_device_deinitialize(device_handle)) 43400a23bdaSmrg return; 43500a23bdaSmrg 43600a23bdaSmrg /* Set active status for suites based on their policies */ 43700a23bdaSmrg for (i = 0; i < size; ++i) 43800a23bdaSmrg if (amdgpu_set_suite_active(suites_active_stat[i].pName, 43900a23bdaSmrg suites_active_stat[i].pActive())) 44000a23bdaSmrg fprintf(stderr, "suite deactivation failed - %s\n", CU_get_error_msg()); 44100a23bdaSmrg 44200a23bdaSmrg /* Explicitly disable specific tests due to known bugs or preferences */ 44300a23bdaSmrg /* 44400a23bdaSmrg * BUG: Compute ring stalls and never recovers when the address is 44500a23bdaSmrg * written after the command already submitted 44600a23bdaSmrg */ 4476532f28eSmrg if (amdgpu_set_test_active(DEADLOCK_TESTS_STR, 4486532f28eSmrg "compute ring block test (set amdgpu.lockup_timeout=50)", CU_FALSE)) 44900a23bdaSmrg fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg()); 45000a23bdaSmrg 4515324fb0dSmrg if (amdgpu_set_test_active(DEADLOCK_TESTS_STR, 4525324fb0dSmrg "sdma ring block test (set amdgpu.lockup_timeout=50)", CU_FALSE)) 4535324fb0dSmrg fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg()); 4545324fb0dSmrg 45500a23bdaSmrg if (amdgpu_set_test_active(BO_TESTS_STR, "Metadata", CU_FALSE)) 45600a23bdaSmrg fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg()); 45700a23bdaSmrg 45800a23bdaSmrg if (amdgpu_set_test_active(BASIC_TESTS_STR, "bo eviction Test", CU_FALSE)) 45900a23bdaSmrg fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg()); 46000a23bdaSmrg 46100a23bdaSmrg /* This test was ran on GFX8 and GFX9 only */ 46200a23bdaSmrg if (family_id < AMDGPU_FAMILY_VI || family_id > AMDGPU_FAMILY_RV) 46300a23bdaSmrg if (amdgpu_set_test_active(BASIC_TESTS_STR, "Sync dependency Test", CU_FALSE)) 46400a23bdaSmrg fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg()); 4655324fb0dSmrg 4665324fb0dSmrg /* This test was ran on GFX9 only */ 4675324fb0dSmrg if (family_id < AMDGPU_FAMILY_AI || family_id > AMDGPU_FAMILY_RV) 4685324fb0dSmrg if (amdgpu_set_test_active(BASIC_TESTS_STR, "Dispatch Test", CU_FALSE)) 4695324fb0dSmrg fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg()); 4705324fb0dSmrg 4715324fb0dSmrg /* This test was ran on GFX9 only */ 4725324fb0dSmrg if (family_id < AMDGPU_FAMILY_AI || family_id > AMDGPU_FAMILY_RV) 4735324fb0dSmrg if (amdgpu_set_test_active(BASIC_TESTS_STR, "Draw Test", CU_FALSE)) 4745324fb0dSmrg fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg()); 47500a23bdaSmrg} 47600a23bdaSmrg 4773f012e29Smrg/* The main() function for setting up and running the tests. 4783f012e29Smrg * Returns a CUE_SUCCESS on successful running, another 4793f012e29Smrg * CUnit error code on failure. 4803f012e29Smrg */ 4813f012e29Smrgint main(int argc, char **argv) 4823f012e29Smrg{ 4833f012e29Smrg int c; /* Character received from getopt */ 4843f012e29Smrg int i = 0; 4853f012e29Smrg int suite_id = -1; /* By default run everything */ 4863f012e29Smrg int test_id = -1; /* By default run all tests in the suite */ 487037b3c26Smrg int pci_bus_id = -1; /* By default PC bus ID is not specified */ 488037b3c26Smrg int pci_device_id = 0; /* By default PC device ID is zero */ 489037b3c26Smrg int display_devices = 0;/* By default not to display devices' info */ 4903f012e29Smrg CU_pSuite pSuite = NULL; 4913f012e29Smrg CU_pTest pTest = NULL; 492037b3c26Smrg int test_device_index; 49300a23bdaSmrg int display_list = 0; 49400a23bdaSmrg int force_run = 0; 4953f012e29Smrg 4963f012e29Smrg for (i = 0; i < MAX_CARDS_SUPPORTED; i++) 4973f012e29Smrg drm_amdgpu[i] = -1; 4983f012e29Smrg 4993f012e29Smrg 5003f012e29Smrg /* Parse command line string */ 5013f012e29Smrg opterr = 0; /* Do not print error messages from getopt */ 5023f012e29Smrg while ((c = getopt(argc, argv, options)) != -1) { 5033f012e29Smrg switch (c) { 5043f012e29Smrg case 'l': 50500a23bdaSmrg display_list = 1; 50600a23bdaSmrg break; 5073f012e29Smrg case 's': 5083f012e29Smrg suite_id = atoi(optarg); 5093f012e29Smrg break; 5103f012e29Smrg case 't': 5113f012e29Smrg test_id = atoi(optarg); 5123f012e29Smrg break; 513037b3c26Smrg case 'b': 514037b3c26Smrg pci_bus_id = atoi(optarg); 515037b3c26Smrg break; 516037b3c26Smrg case 'd': 517d8807b2fSmrg sscanf(optarg, "%x", &pci_device_id); 518037b3c26Smrg break; 519037b3c26Smrg case 'p': 520037b3c26Smrg display_devices = 1; 521037b3c26Smrg break; 522037b3c26Smrg case 'r': 523037b3c26Smrg open_render_node = 1; 524037b3c26Smrg break; 52500a23bdaSmrg case 'f': 52600a23bdaSmrg force_run = 1; 52700a23bdaSmrg break; 5283f012e29Smrg case '?': 5293f012e29Smrg case 'h': 5303f012e29Smrg fprintf(stderr, usage, argv[0]); 5313f012e29Smrg exit(EXIT_SUCCESS); 5323f012e29Smrg default: 5333f012e29Smrg fprintf(stderr, usage, argv[0]); 5343f012e29Smrg exit(EXIT_FAILURE); 5353f012e29Smrg } 5363f012e29Smrg } 5373f012e29Smrg 538037b3c26Smrg if (amdgpu_open_devices(open_render_node) <= 0) { 539037b3c26Smrg perror("Cannot open AMDGPU device"); 5403f012e29Smrg exit(EXIT_FAILURE); 5413f012e29Smrg } 5423f012e29Smrg 543037b3c26Smrg if (drm_amdgpu[0] < 0) { 544037b3c26Smrg perror("Cannot open AMDGPU device"); 5453f012e29Smrg exit(EXIT_FAILURE); 5463f012e29Smrg } 5473f012e29Smrg 548037b3c26Smrg if (display_devices) { 549037b3c26Smrg amdgpu_print_devices(); 550037b3c26Smrg amdgpu_close_devices(); 551037b3c26Smrg exit(EXIT_SUCCESS); 552037b3c26Smrg } 5533f012e29Smrg 554d8807b2fSmrg if (pci_bus_id > 0 || pci_device_id) { 555037b3c26Smrg /* A device was specified to run the test */ 556d8807b2fSmrg test_device_index = amdgpu_find_device(pci_bus_id, 557d8807b2fSmrg pci_device_id); 558037b3c26Smrg 559037b3c26Smrg if (test_device_index >= 0) { 560037b3c26Smrg /* Most tests run on device of drm_amdgpu[0]. 561037b3c26Smrg * Swap the chosen device to drm_amdgpu[0]. 562037b3c26Smrg */ 563037b3c26Smrg i = drm_amdgpu[0]; 564037b3c26Smrg drm_amdgpu[0] = drm_amdgpu[test_device_index]; 565037b3c26Smrg drm_amdgpu[test_device_index] = i; 566037b3c26Smrg } else { 567037b3c26Smrg fprintf(stderr, 568037b3c26Smrg "The specified GPU device does not exist.\n"); 569037b3c26Smrg exit(EXIT_FAILURE); 570037b3c26Smrg } 571037b3c26Smrg } 5723f012e29Smrg 5733f012e29Smrg /* Initialize test suites to run */ 5743f012e29Smrg 5753f012e29Smrg /* initialize the CUnit test registry */ 5763f012e29Smrg if (CUE_SUCCESS != CU_initialize_registry()) { 577037b3c26Smrg amdgpu_close_devices(); 5783f012e29Smrg return CU_get_error(); 5793f012e29Smrg } 5803f012e29Smrg 5813f012e29Smrg /* Register suites. */ 5823f012e29Smrg if (CU_register_suites(suites) != CUE_SUCCESS) { 5833f012e29Smrg fprintf(stderr, "suite registration failed - %s\n", 5843f012e29Smrg CU_get_error_msg()); 5853f012e29Smrg CU_cleanup_registry(); 586037b3c26Smrg amdgpu_close_devices(); 5873f012e29Smrg exit(EXIT_FAILURE); 5883f012e29Smrg } 5893f012e29Smrg 5903f012e29Smrg /* Run tests using the CUnit Basic interface */ 5913f012e29Smrg CU_basic_set_mode(CU_BRM_VERBOSE); 5923f012e29Smrg 59300a23bdaSmrg /* Disable suites and individual tests based on misc. conditions */ 59400a23bdaSmrg amdgpu_disable_suites(); 59500a23bdaSmrg 59600a23bdaSmrg if (display_list) { 59700a23bdaSmrg display_test_suites(); 59800a23bdaSmrg goto end; 59900a23bdaSmrg } 60000a23bdaSmrg 6013f012e29Smrg if (suite_id != -1) { /* If user specify particular suite? */ 6023f012e29Smrg pSuite = CU_get_suite_by_index((unsigned int) suite_id, 6033f012e29Smrg CU_get_registry()); 6043f012e29Smrg 6053f012e29Smrg if (pSuite) { 60600a23bdaSmrg 60700a23bdaSmrg if (force_run) 60800a23bdaSmrg CU_set_suite_active(pSuite, CU_TRUE); 60900a23bdaSmrg 6103f012e29Smrg if (test_id != -1) { /* If user specify test id */ 6113f012e29Smrg pTest = CU_get_test_by_index( 6123f012e29Smrg (unsigned int) test_id, 6133f012e29Smrg pSuite); 61400a23bdaSmrg if (pTest) { 61500a23bdaSmrg if (force_run) 61600a23bdaSmrg CU_set_test_active(pTest, CU_TRUE); 61700a23bdaSmrg 6183f012e29Smrg CU_basic_run_test(pSuite, pTest); 61900a23bdaSmrg } 6203f012e29Smrg else { 6213f012e29Smrg fprintf(stderr, "Invalid test id: %d\n", 6223f012e29Smrg test_id); 6233f012e29Smrg CU_cleanup_registry(); 624037b3c26Smrg amdgpu_close_devices(); 6253f012e29Smrg exit(EXIT_FAILURE); 6263f012e29Smrg } 6273f012e29Smrg } else 6283f012e29Smrg CU_basic_run_suite(pSuite); 6293f012e29Smrg } else { 6303f012e29Smrg fprintf(stderr, "Invalid suite id : %d\n", 6313f012e29Smrg suite_id); 6323f012e29Smrg CU_cleanup_registry(); 633037b3c26Smrg amdgpu_close_devices(); 6343f012e29Smrg exit(EXIT_FAILURE); 6353f012e29Smrg } 6363f012e29Smrg } else 6373f012e29Smrg CU_basic_run_tests(); 6383f012e29Smrg 63900a23bdaSmrgend: 6403f012e29Smrg CU_cleanup_registry(); 641037b3c26Smrg amdgpu_close_devices(); 6423f012e29Smrg return CU_get_error(); 6433f012e29Smrg} 644