head	1.2;
access;
symbols
	netbsd-11-0-RC4:1.1.1.14
	netbsd-11-0-RC3:1.1.1.14
	netbsd-11-0-RC2:1.1.1.14
	netbsd-11-0-RC1:1.1.1.14
	netbsd-11:1.1.1.14.0.2
	netbsd-11-base:1.1.1.14
	libdrm-2-4-124:1.1.1.14
	netbsd-10-1-RELEASE:1.1.1.13
	libdrm-2-4-122:1.1.1.14
	netbsd-8-3-RELEASE:1.1.1.2
	netbsd-9-4-RELEASE:1.1.1.7
	netbsd-10-0-RELEASE:1.1.1.13
	netbsd-10-0-RC6:1.1.1.13
	netbsd-10-0-RC5:1.1.1.13
	netbsd-10-0-RC4:1.1.1.13
	netbsd-10-0-RC3:1.1.1.13
	netbsd-10-0-RC2:1.1.1.13
	netbsd-10-0-RC1:1.1.1.13
	netbsd-10:1.1.1.13.0.2
	netbsd-10-base:1.1.1.13
	libdrm-2-4-114:1.1.1.13
	netbsd-9-3-RELEASE:1.1.1.7
	libdrm-2-4-112:1.1.1.12
	libdrm-2-4-109:1.1.1.11
	libdrm-2-4-107:1.1.1.11
	netbsd-9-2-RELEASE:1.1.1.7
	libdrm-2-4-105:1.1.1.10
	libdrm-2-4-102:1.1.1.9
	netbsd-9-1-RELEASE:1.1.1.7
	netbsd-8-2-RELEASE:1.1.1.2
	libdrm-2-4-100:1.1.1.8
	netbsd-9-0-RELEASE:1.1.1.7
	netbsd-9-0-RC2:1.1.1.7
	netbsd-9-0-RC1:1.1.1.7
	netbsd-9:1.1.1.7.0.2
	netbsd-9-base:1.1.1.7
	libdrm-2-4-99:1.1.1.7
	netbsd-8-1-RELEASE:1.1.1.2
	netbsd-8-1-RC1:1.1.1.2
	libdrm-2-4-97:1.1.1.6
	libdrm-2-4-96:1.1.1.5
	netbsd-8-0-RELEASE:1.1.1.2
	netbsd-8-0-RC2:1.1.1.2
	netbsd-8-0-RC1:1.1.1.2
	libdrm-2-4-91:1.1.1.4
	libdrm-2-4-83:1.1.1.3
	netbsd-8:1.1.1.2.0.2
	netbsd-8-base:1.1.1.2
	libdrm-2-4-75:1.1.1.2
	libdrm-2-4-70:1.1.1.1
	xorg:1.1.1;
locks; strict;
comment	@ * @;


1.2
date	2026.06.10.05.27.43;	author mrg;	state dead;
branches;
next	1.1;
commitid	OkSNQummCTEKcdJG;

1.1
date	2016.08.17.02.14.50;	author mrg;	state Exp;
branches
	1.1.1.1;
next	;
commitid	sjjkW0DDGfxalBiz;

1.1.1.1
date	2016.08.17.02.14.50;	author mrg;	state Exp;
branches;
next	1.1.1.2;
commitid	sjjkW0DDGfxalBiz;

1.1.1.2
date	2017.03.04.23.15.51;	author mrg;	state Exp;
branches;
next	1.1.1.3;
commitid	KFj0R3BffyGbVhIz;

1.1.1.3
date	2017.08.29.06.30.18;	author mrg;	state Exp;
branches;
next	1.1.1.4;
commitid	SwkxfytMMoJtD45A;

1.1.1.4
date	2018.03.14.07.18.37;	author mrg;	state Exp;
branches;
next	1.1.1.5;
commitid	vKK7pL0psl9szouA;

1.1.1.5
date	2019.01.10.08.49.54;	author mrg;	state Exp;
branches;
next	1.1.1.6;
commitid	XNB5UWAmSCOUmd7B;

1.1.1.6
date	2019.03.04.08.20.59;	author mrg;	state Exp;
branches;
next	1.1.1.7;
commitid	8yixCTrntx4nv1eB;

1.1.1.7
date	2019.07.15.05.42.03;	author mrg;	state Exp;
branches;
next	1.1.1.8;
commitid	fTEuGipA3XuNl6vB;

1.1.1.8
date	2020.02.23.09.57.43;	author mrg;	state Exp;
branches;
next	1.1.1.9;
commitid	t5o6MGTQnHc5BMXB;

1.1.1.9
date	2020.11.01.09.51.26;	author mrg;	state Exp;
branches;
next	1.1.1.10;
commitid	af86gKDNccMIsauC;

1.1.1.10
date	2021.04.27.03.01.49;	author mrg;	state Exp;
branches;
next	1.1.1.11;
commitid	bnhxFHsntjvsvSQC;

1.1.1.11
date	2021.07.11.00.27.20;	author mrg;	state Exp;
branches;
next	1.1.1.12;
commitid	ssF6uXIaLv20fv0D;

1.1.1.12
date	2022.07.11.19.19.23;	author mrg;	state Exp;
branches;
next	1.1.1.13;
commitid	wjQfX0qND1IWLvLD;

1.1.1.13
date	2022.11.12.02.04.42;	author mrg;	state Exp;
branches;
next	1.1.1.14;
commitid	fMjFZZt1HqTR3m1E;

1.1.1.14
date	2024.07.04.09.21.32;	author mrg;	state Exp;
branches;
next	;
commitid	yumHpHqYfO9ZbvgF;


desc
@@


1.2
log
@merge libdrm 2.4.134
@
text
@/*
 * Copyright 2014 Advanced Micro Devices, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
#include <errno.h>
#include <signal.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <stdarg.h>
#include <stdint.h>

#include "drm.h"
#include "xf86drmMode.h"
#include "xf86drm.h"

#include "CUnit/Basic.h"

#include "amdgpu_test.h"

/**
 *  Open handles for amdgpu devices
 *
 */
int drm_amdgpu[MAX_CARDS_SUPPORTED];

/** The table of all known test suites to run */
static CU_SuiteInfo suites[] = {
	{
		.pName = "Basic Tests",
		.pInitFunc = suite_basic_tests_init,
		.pCleanupFunc = suite_basic_tests_clean,
		.pTests = basic_tests,
	},
	{
		.pName = "BO Tests",
		.pInitFunc = suite_bo_tests_init,
		.pCleanupFunc = suite_bo_tests_clean,
		.pTests = bo_tests,
	},
	{
		.pName = "CS Tests",
		.pInitFunc = suite_cs_tests_init,
		.pCleanupFunc = suite_cs_tests_clean,
		.pTests = cs_tests,
	},
	{
		.pName = "VCE Tests",
		.pInitFunc = suite_vce_tests_init,
		.pCleanupFunc = suite_vce_tests_clean,
		.pTests = vce_tests,
	},
	CU_SUITE_INFO_NULL,
};


/** Display information about all  suites and their tests */
static void display_test_suites(void)
{
	int iSuite;
	int iTest;

	printf("Suites\n");

	for (iSuite = 0; suites[iSuite].pName != NULL; iSuite++) {
		printf("Suite id = %d: Name '%s'\n",
				iSuite + 1, suites[iSuite].pName);

		for (iTest = 0; suites[iSuite].pTests[iTest].pName != NULL;
			iTest++) {
			printf("	Test id %d: Name: '%s'\n", iTest + 1,
					suites[iSuite].pTests[iTest].pName);
		}
	}
}


/** Help string for command line parameters */
static const char usage[] = "Usage: %s [-hl] [<-s <suite id>> [-t <test id>]]\n"
				"where:\n"
				"       l - Display all suites and their tests\n"
				"       h - Display this help\n";
/** Specified options strings for getopt */
static const char options[]   = "hls:t:";

/* The main() function for setting up and running the tests.
 * Returns a CUE_SUCCESS on successful running, another
 * CUnit error code on failure.
 */
int main(int argc, char **argv)
{
	int c;			/* Character received from getopt */
	int i = 0;
	int suite_id = -1;	/* By default run everything */
	int test_id  = -1;	/* By default run all tests in the suite */
	CU_pSuite pSuite = NULL;
	CU_pTest  pTest  = NULL;

	int aval = drmAvailable();

	if (aval == 0) {
		fprintf(stderr, "DRM driver is not available\n");
		exit(EXIT_FAILURE);
	}


	for (i = 0; i < MAX_CARDS_SUPPORTED; i++)
		drm_amdgpu[i] = -1;


	/* Parse command line string */
	opterr = 0;		/* Do not print error messages from getopt */
	while ((c = getopt(argc, argv, options)) != -1) {
		switch (c) {
		case 'l':
			display_test_suites();
			exit(EXIT_SUCCESS);
		case 's':
			suite_id = atoi(optarg);
			break;
		case 't':
			test_id = atoi(optarg);
			break;
		case '?':
		case 'h':
			fprintf(stderr, usage, argv[0]);
			exit(EXIT_SUCCESS);
		default:
			fprintf(stderr, usage, argv[0]);
			exit(EXIT_FAILURE);
		}
	}

	/* Try to open all possible radeon connections
	 * Right now: Open only the 0.
	 */
	printf("Try to open the card 0..\n");
	drm_amdgpu[0] = open("/dev/dri/card0", O_RDWR | O_CLOEXEC);

	if (drm_amdgpu[0] < 0) {
		perror("Cannot open /dev/dri/card0\n");
		exit(EXIT_FAILURE);
	}

	/** Display version of DRM driver */
	drmVersionPtr retval = drmGetVersion(drm_amdgpu[0]);

	if (retval == NULL) {
		perror("Could not get information about DRM driver");
		exit(EXIT_FAILURE);
	}

	printf("DRM Driver: Name: [%s] : Date [%s] : Description [%s]\n",
	       retval->name, retval->date, retval->desc);

	drmFreeVersion(retval);

	/* Initialize test suites to run */

	/* initialize the CUnit test registry */
	if (CUE_SUCCESS != CU_initialize_registry()) {
		close(drm_amdgpu[0]);
		return CU_get_error();
	}

	/* Register suites. */
	if (CU_register_suites(suites) != CUE_SUCCESS) {
		fprintf(stderr, "suite registration failed - %s\n",
				CU_get_error_msg());
		CU_cleanup_registry();
		close(drm_amdgpu[0]);
		exit(EXIT_FAILURE);
	}

	/* Run tests using the CUnit Basic interface */
	CU_basic_set_mode(CU_BRM_VERBOSE);

	if (suite_id != -1) {	/* If user specify particular suite? */
		pSuite = CU_get_suite_by_index((unsigned int) suite_id,
						CU_get_registry());

		if (pSuite) {
			if (test_id != -1) {   /* If user specify test id */
				pTest = CU_get_test_by_index(
						(unsigned int) test_id,
						pSuite);
				if (pTest)
					CU_basic_run_test(pSuite, pTest);
				else {
					fprintf(stderr, "Invalid test id: %d\n",
								test_id);
					CU_cleanup_registry();
					close(drm_amdgpu[0]);
					exit(EXIT_FAILURE);
				}
			} else
				CU_basic_run_suite(pSuite);
		} else {
			fprintf(stderr, "Invalid suite id : %d\n",
					suite_id);
			CU_cleanup_registry();
			close(drm_amdgpu[0]);
			exit(EXIT_FAILURE);
		}
	} else
		CU_basic_run_tests();

	CU_cleanup_registry();
	close(drm_amdgpu[0]);
	return CU_get_error();
}
@


1.1
log
@Initial revision
@
text
@@


1.1.1.1
log
@initial import of libdrm-2.4.70
@
text
@@


1.1.1.2
log
@initial import of libdrm-2.4.75
@
text
@a58 3
/** Open render node to test */
int open_render_node = 0;	/* By default run most tests on primary node */

d111 4
a114 10
static const char usage[] =
	"Usage: %s [-hlpr] [<-s <suite id>> [-t <test id>]] "
	"[-b <pci_bus_id> [-d <pci_device_id>]]\n"
	"where:\n"
	"       l - Display all suites and their tests\n"
	"       r - Run the tests on render node\n"
	"       b - Specify device's PCI bus id to run tests\n"
	"       d - Specify device's PCI device id to run tests (optional)\n"
	"       p - Display information of AMDGPU devices in system\n"
	"       h - Display this help\n";
d116 1
a116 164
static const char options[]   = "hlrps:t:b:d:";

/* Open AMD devices.
 * Return the number of AMD device openned.
 */
static int amdgpu_open_devices(int open_render_node)
{
	drmDevicePtr devices[MAX_CARDS_SUPPORTED];
	int ret;
	int i;
	int drm_node;
	int amd_index = 0;
	int drm_count;
	int fd;
	drmVersionPtr version;

	drm_count = drmGetDevices2(0, devices, MAX_CARDS_SUPPORTED);

	if (drm_count < 0) {
		fprintf(stderr,
			"drmGetDevices2() returned an error %d\n",
			drm_count);
		return 0;
	}

	for (i = 0; i < drm_count; i++) {
		/* If this is not PCI device, skip*/
		if (devices[i]->bustype != DRM_BUS_PCI)
			continue;

		/* If this is not AMD GPU vender ID, skip*/
		if (devices[i]->deviceinfo.pci->vendor_id != 0x1002)
			continue;

		if (open_render_node)
			drm_node = DRM_NODE_RENDER;
		else
			drm_node = DRM_NODE_PRIMARY;

		fd = -1;
		if (devices[i]->available_nodes & 1 << drm_node)
			fd = open(
				devices[i]->nodes[drm_node],
				O_RDWR | O_CLOEXEC);

		/* This node is not available. */
		if (fd < 0) continue;

		version = drmGetVersion(fd);
		if (!version) {
			fprintf(stderr,
				"Warning: Cannot get version for %s."
				"Error is %s\n",
				devices[i]->nodes[drm_node],
				strerror(errno));
			close(fd);
			continue;
		}

		if (strcmp(version->name, "amdgpu")) {
			/* This is not AMDGPU driver, skip.*/
			drmFreeVersion(version);
			close(fd);
			continue;
		}

		drmFreeVersion(version);

		drm_amdgpu[amd_index] = fd;
		amd_index++;
	}

	drmFreeDevices(devices, drm_count);
	return amd_index;
}

/* Close AMD devices.
 */
static void amdgpu_close_devices()
{
	int i;
	for (i = 0; i < MAX_CARDS_SUPPORTED; i++)
		if (drm_amdgpu[i] >=0)
			close(drm_amdgpu[i]);
}

/* Print AMD devices information */
static void amdgpu_print_devices()
{
	int i;
	drmDevicePtr device;

	/* Open the first AMD devcie to print driver information. */
	if (drm_amdgpu[0] >=0) {
		/* Display AMD driver version information.*/
		drmVersionPtr retval = drmGetVersion(drm_amdgpu[0]);

		if (retval == NULL) {
			perror("Cannot get version for AMDGPU device");
			return;
		}

		printf("Driver name: %s, Date: %s, Description: %s.\n",
			retval->name, retval->date, retval->desc);
		drmFreeVersion(retval);
	}

	/* Display information of AMD devices */
	printf("Devices:\n");
	for (i = 0; i < MAX_CARDS_SUPPORTED && drm_amdgpu[i] >=0; i++)
		if (drmGetDevice2(drm_amdgpu[i],
			DRM_DEVICE_GET_PCI_REVISION,
			&device) == 0) {
			if (device->bustype == DRM_BUS_PCI) {
				printf("PCI ");
				printf(" domain:%04x",
					device->businfo.pci->domain);
				printf(" bus:%02x",
					device->businfo.pci->bus);
				printf(" device:%02x",
					device->businfo.pci->dev);
				printf(" function:%01x",
					device->businfo.pci->func);
				printf(" vendor_id:%04x",
					device->deviceinfo.pci->vendor_id);
				printf(" device_id:%04x",
					device->deviceinfo.pci->device_id);
				printf(" subvendor_id:%04x",
					device->deviceinfo.pci->subvendor_id);
				printf(" subdevice_id:%04x",
					device->deviceinfo.pci->subdevice_id);
				printf(" revision_id:%02x",
					device->deviceinfo.pci->revision_id);
				printf("\n");
			}
			drmFreeDevice(&device);
		}
}

/* Find a match AMD device in PCI bus
 * Return the index of the device or -1 if not found
 */
static int amdgpu_find_device(uint8_t bus, uint8_t dev)
{
	int i;
	drmDevicePtr device;

	for (i = 0; i < MAX_CARDS_SUPPORTED && drm_amdgpu[i] >=0; i++)
		if (drmGetDevice2(drm_amdgpu[i],
			DRM_DEVICE_GET_PCI_REVISION,
			&device) == 0) {
			if (device->bustype == DRM_BUS_PCI)
				if (device->businfo.pci->bus == bus &&
					device->businfo.pci->dev == dev) {

					drmFreeDevice(&device);
					return i;
				}

			drmFreeDevice(&device);
		}

	return -1;
}
a127 3
	int pci_bus_id = -1;    /* By default PC bus ID is not specified */
	int pci_device_id = 0;  /* By default PC device ID is zero */
	int display_devices = 0;/* By default not to display devices' info */
d130 8
a137 1
	int test_device_index;
a155 12
		case 'b':
			pci_bus_id = atoi(optarg);
			break;
		case 'd':
			pci_device_id = atoi(optarg);
			break;
		case 'p':
			display_devices = 1;
			break;
		case 'r':
			open_render_node = 1;
			break;
d166 8
a173 2
	if (amdgpu_open_devices(open_render_node) <= 0) {
		perror("Cannot open AMDGPU device");
d177 5
a181 2
	if (drm_amdgpu[0] < 0) {
		perror("Cannot open AMDGPU device");
d185 2
a186 5
	if (display_devices) {
		amdgpu_print_devices();
		amdgpu_close_devices();
		exit(EXIT_SUCCESS);
	}
d188 1
a188 18
	if (pci_bus_id > 0) {
		/* A device was specified to run the test */
		test_device_index = amdgpu_find_device((uint8_t)pci_bus_id,
							(uint8_t)pci_device_id);

		if (test_device_index >= 0) {
			/* Most tests run on device of drm_amdgpu[0].
			 * Swap the chosen device to drm_amdgpu[0].
			 */
			i = drm_amdgpu[0];
			drm_amdgpu[0] = drm_amdgpu[test_device_index];
			drm_amdgpu[test_device_index] = i;
		} else {
			fprintf(stderr,
				"The specified GPU device does not exist.\n");
			exit(EXIT_FAILURE);
		}
	}
d194 1
a194 1
		amdgpu_close_devices();
d203 1
a203 1
		amdgpu_close_devices();
d225 1
a225 1
					amdgpu_close_devices();
d234 1
a234 1
			amdgpu_close_devices();
d241 1
a241 1
	amdgpu_close_devices();
@


1.1.1.3
log
@initial import of libdrm-2.4.83
@
text
@a87 12
	{
		.pName = "VCN Tests",
		.pInitFunc = suite_vcn_tests_init,
		.pCleanupFunc = suite_vcn_tests_clean,
		.pTests = vcn_tests,
	},
	{
		.pName = "UVD ENC Tests",
		.pInitFunc = suite_uvd_enc_tests_init,
		.pCleanupFunc = suite_uvd_enc_tests_clean,
		.pTests = uvd_enc_tests,
	},
d267 1
a267 1
static int amdgpu_find_device(uint8_t bus, uint16_t dev)
d272 1
a272 1
	for (i = 0; i < MAX_CARDS_SUPPORTED && drm_amdgpu[i] >= 0; i++) {
d277 3
a279 2
				if ((bus == 0xFF || device->businfo.pci->bus == bus) &&
					device->deviceinfo.pci->device_id == dev) {
a285 1
	}
d328 1
a328 1
			sscanf(optarg, "%x", &pci_device_id);
d362 1
a362 1
	if (pci_bus_id > 0 || pci_device_id) {
d364 2
a365 2
		test_device_index = amdgpu_find_device(pci_bus_id,
						       pci_device_id);
@


1.1.1.4
log
@initial import of libdrm-2.4.91
@
text
@a51 11
#include "amdgpu_internal.h"

/* Test suite names */
#define BASIC_TESTS_STR "Basic Tests"
#define BO_TESTS_STR "BO Tests"
#define CS_TESTS_STR "CS Tests"
#define VCE_TESTS_STR "VCE Tests"
#define VCN_TESTS_STR "VCN Tests"
#define UVD_ENC_TESTS_STR "UVD ENC Tests"
#define DEADLOCK_TESTS_STR "Deadlock Tests"
#define VM_TESTS_STR "VM Tests"
d65 1
a65 1
		.pName = BASIC_TESTS_STR,
d71 1
a71 1
		.pName = BO_TESTS_STR,
d77 1
a77 1
		.pName = CS_TESTS_STR,
d83 1
a83 1
		.pName = VCE_TESTS_STR,
d89 1
a89 1
		.pName = VCN_TESTS_STR,
d95 1
a95 1
		.pName = UVD_ENC_TESTS_STR,
a99 13
	{
		.pName = DEADLOCK_TESTS_STR,
		.pInitFunc = suite_deadlock_tests_init,
		.pCleanupFunc = suite_deadlock_tests_clean,
		.pTests = deadlock_tests,
	},
	{
		.pName = VM_TESTS_STR,
		.pInitFunc = suite_vm_tests_init,
		.pCleanupFunc = suite_vm_tests_clean,
		.pTests = vm_tests,
	},

a102 47
typedef CU_BOOL (*active__stat_func)(void);

typedef struct Suites_Active_Status {
	char*             pName;
	active__stat_func pActive;
}Suites_Active_Status;

static CU_BOOL always_active()
{
	return CU_TRUE;
}

static Suites_Active_Status suites_active_stat[] = {
		{
			.pName = BASIC_TESTS_STR,
			.pActive = always_active,
		},
		{
			.pName = BO_TESTS_STR,
			.pActive = always_active,
		},
		{
			.pName = CS_TESTS_STR,
			.pActive = suite_cs_tests_enable,
		},
		{
			.pName = VCE_TESTS_STR,
			.pActive = suite_vce_tests_enable,
		},
		{
			.pName = VCN_TESTS_STR,
			.pActive = suite_vcn_tests_enable,
		},
		{
			.pName = UVD_ENC_TESTS_STR,
			.pActive = suite_uvd_enc_tests_enable,
		},
		{
			.pName = DEADLOCK_TESTS_STR,
			.pActive = suite_deadlock_tests_enable,
		},
		{
			.pName = VM_TESTS_STR,
			.pActive = suite_vm_tests_enable,
		},
};

d104 1
a104 5
/*
 * Display information about all  suites and their tests
 *
 * NOTE: Must be run after registry is initialized and suites registered.
 */
a108 2
	CU_pSuite pSuite = NULL;
	CU_pTest  pTest  = NULL;
d113 2
a114 14

		pSuite = CU_get_suite_by_index((unsigned int) iSuite + 1,
						      CU_get_registry());

		if (!pSuite) {
			fprintf(stderr, "Invalid suite id : %d\n", iSuite + 1);
			continue;
		}

		printf("Suite id = %d: Name '%s status: %s'\n",
				iSuite + 1, suites[iSuite].pName,
				pSuite->fActive ? "ENABLED" : "DISABLED");


d118 2
a119 13

			pTest = CU_get_test_by_index((unsigned int) iTest + 1,
									pSuite);

			if (!pTest) {
				fprintf(stderr, "Invalid test id : %d\n", iTest + 1);
				continue;
			}

			printf("Test id %d: Name: '%s status: %s'\n", iTest + 1,
					suites[iSuite].pTests[iTest].pName,
					pSuite->fActive && pTest->fActive ?
						     "ENABLED" : "DISABLED");
d127 1
a127 1
	"Usage: %s [-hlpr] [<-s <suite id>> [-t <test id>] [-f]] "
a134 1
	"       f - Force executing inactive suite or test\n"
d137 1
a137 1
static const char options[]   = "hlrps:t:b:d:f";
d145 1
a301 42
static void amdgpu_disable_suites()
{
	amdgpu_device_handle device_handle;
	uint32_t major_version, minor_version, family_id;
	int i;
	int size = sizeof(suites_active_stat) / sizeof(suites_active_stat[0]);

	if (amdgpu_device_initialize(drm_amdgpu[0], &major_version,
				   &minor_version, &device_handle))
		return;

	family_id = device_handle->info.family_id;

	if (amdgpu_device_deinitialize(device_handle))
		return;

	/* Set active status for suites based on their policies */
	for (i = 0; i < size; ++i)
		if (amdgpu_set_suite_active(suites_active_stat[i].pName,
				suites_active_stat[i].pActive()))
			fprintf(stderr, "suite deactivation failed - %s\n", CU_get_error_msg());

	/* Explicitly disable specific tests due to known bugs or preferences */
	/*
	* BUG: Compute ring stalls and never recovers when the address is
	* written after the command already submitted
	*/
	if (amdgpu_set_test_active(DEADLOCK_TESTS_STR, "compute ring block test", CU_FALSE))
		fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());

	if (amdgpu_set_test_active(BO_TESTS_STR, "Metadata", CU_FALSE))
		fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());

	if (amdgpu_set_test_active(BASIC_TESTS_STR, "bo eviction Test", CU_FALSE))
		fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());

	/* This test was ran on GFX8 and GFX9 only */
	if (family_id < AMDGPU_FAMILY_VI || family_id > AMDGPU_FAMILY_RV)
		if (amdgpu_set_test_active(BASIC_TESTS_STR, "Sync dependency Test", CU_FALSE))
			fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());
}

a317 2
	int display_list = 0;
	int force_run = 0;
d328 2
a329 2
			display_list = 1;
			break;
a347 3
		case 'f':
			force_run = 1;
			break;
a412 8
	/* Disable suites and individual tests based on misc. conditions */
	amdgpu_disable_suites();

	if (display_list) {
		display_test_suites();
		goto end;
	}

a417 4

			if (force_run)
				CU_set_suite_active(pSuite, CU_TRUE);

d422 1
a422 4
				if (pTest) {
					if (force_run)
						CU_set_test_active(pTest, CU_TRUE);

a423 1
				}
a442 1
end:
@


1.1.1.5
log
@initial import of libdrm-2.4.96
@
text
@d24 4
@


1.1.1.6
log
@initial import of libdrm-2.4.97
@
text
@d425 1
a425 2
	if (amdgpu_set_test_active(DEADLOCK_TESTS_STR,
			"compute ring block test (set amdgpu.lockup_timeout=50)", CU_FALSE))
@


1.1.1.7
log
@initial import of libdrm-2.4.99
@
text
@a58 2
#define RAS_TESTS_STR "RAS Tests"
#define SYNCOBJ_TIMELINE_TESTS_STR "SYNCOBJ TIMELINE Tests"
a118 12
	{
		.pName = RAS_TESTS_STR,
		.pInitFunc = suite_ras_tests_init,
		.pCleanupFunc = suite_ras_tests_clean,
		.pTests = ras_tests,
	},
	{
		.pName = SYNCOBJ_TIMELINE_TESTS_STR,
		.pInitFunc = suite_syncobj_timeline_tests_init,
		.pCleanupFunc = suite_syncobj_timeline_tests_clean,
		.pTests = syncobj_timeline_tests,
	},
a167 8
		{
			.pName = RAS_TESTS_STR,
			.pActive = suite_ras_tests_enable,
		},
		{
			.pName = SYNCOBJ_TIMELINE_TESTS_STR,
			.pActive = suite_syncobj_timeline_tests_enable,
		},
d237 1
a237 1
 * Return the number of AMD device opened.
d325 1
a325 1
	/* Open the first AMD device to print driver information. */
a428 4
	if (amdgpu_set_test_active(DEADLOCK_TESTS_STR,
				"sdma ring block test (set amdgpu.lockup_timeout=50)", CU_FALSE))
		fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());

a438 10

	/* This test was ran on GFX9 only */
	if (family_id < AMDGPU_FAMILY_AI || family_id > AMDGPU_FAMILY_RV)
		if (amdgpu_set_test_active(BASIC_TESTS_STR, "Dispatch Test", CU_FALSE))
			fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());

	/* This test was ran on GFX9 only */
	if (family_id < AMDGPU_FAMILY_AI || family_id > AMDGPU_FAMILY_RV)
		if (amdgpu_set_test_active(BASIC_TESTS_STR, "Draw Test", CU_FALSE))
			fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());
@


1.1.1.8
log
@initial import of libdrm-2.4.100
@
text
@d467 2
a468 4
	if (family_id < AMDGPU_FAMILY_AI || family_id > AMDGPU_FAMILY_RV) {
		if (amdgpu_set_test_active(BASIC_TESTS_STR, "Dispatch Test (GFX)", CU_FALSE))
			fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());
		if (amdgpu_set_test_active(BASIC_TESTS_STR, "Dispatch Test (Compute)", CU_FALSE))
a469 1
	}
a474 5

	/* This test was ran on GFX9 only */
	//if (family_id < AMDGPU_FAMILY_AI || family_id > AMDGPU_FAMILY_RV)
		if (amdgpu_set_test_active(BASIC_TESTS_STR, "GPU reset Test", CU_FALSE))
			fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());
@


1.1.1.9
log
@initial import of libdrm-2.4.102
@
text
@d205 1
a205 1
	printf("%5s: %2s: %8s: %s\n", "What", "ID", "Status", "Name");
d210 1
a210 1
					       CU_get_registry());
d217 4
a220 4
		printf("Suite: %2d: %8s: %s\n",
		       iSuite + 1,
		       pSuite->fActive ? "ENABLED" : "DISABLED",
		       suites[iSuite].pName);
a221 2
		if (!pSuite->fActive)
			continue;
d224 2
a225 1
		     iTest++) {
d227 2
a228 1
						     pSuite);
d233 5
a237 4
			printf(" Test: %2d: %8s: %s\n",
			       iTest + 1,
			       pSuite->fActive && pTest->fActive ? "ENABLED" : "DISABLED",
			       suites[iSuite].pTests[iTest].pName);
d242 1
a454 35
	/* This test was ran on GFX9 only */
	//if (family_id < AMDGPU_FAMILY_AI || family_id > AMDGPU_FAMILY_RV)
		if (amdgpu_set_test_active(DEADLOCK_TESTS_STR,
				"gfx ring bad dispatch test (set amdgpu.lockup_timeout=50)", CU_FALSE))
			fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());

	/* This test was ran on GFX9 only */
	//if (family_id < AMDGPU_FAMILY_AI || family_id > AMDGPU_FAMILY_RV)
		if (amdgpu_set_test_active(DEADLOCK_TESTS_STR,
				"compute ring bad dispatch test (set amdgpu.lockup_timeout=50,50)", CU_FALSE))
			fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());

	/* This test was ran on GFX9 only */
	//if (family_id < AMDGPU_FAMILY_AI || family_id > AMDGPU_FAMILY_RV)
		if (amdgpu_set_test_active(DEADLOCK_TESTS_STR,
				"gfx ring bad slow dispatch test (set amdgpu.lockup_timeout=50)", CU_FALSE))
			fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());

	/* This test was ran on GFX9 only */
	//if (family_id < AMDGPU_FAMILY_AI || family_id > AMDGPU_FAMILY_RV)
		if (amdgpu_set_test_active(DEADLOCK_TESTS_STR,
				"compute ring bad slow dispatch test (set amdgpu.lockup_timeout=50,50)", CU_FALSE))
			fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());

	//if (family_id < AMDGPU_FAMILY_AI || family_id > AMDGPU_FAMILY_RV)
		if (amdgpu_set_test_active(DEADLOCK_TESTS_STR,
				"gfx ring bad draw test (set amdgpu.lockup_timeout=50)", CU_FALSE))
			fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());

	/* This test was ran on GFX9 only */
	//if (family_id < AMDGPU_FAMILY_AI || family_id > AMDGPU_FAMILY_RV)
		if (amdgpu_set_test_active(DEADLOCK_TESTS_STR,
				"gfx ring slow bad draw test (set amdgpu.lockup_timeout=50)", CU_FALSE))
			fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());

@


1.1.1.10
log
@initial import of libdrm-2.4.105
@
text
@a60 1
#define SECURITY_TESTS_STR "Security Tests"
a132 6
	{
		.pName = SECURITY_TESTS_STR,
		.pInitFunc = suite_security_tests_init,
		.pCleanupFunc = suite_security_tests_clean,
		.pTests = security_tests,
	},
d152 1
a152 1
			.pActive = suite_basic_tests_enable,
a189 4
		{
			.pName = SECURITY_TESTS_STR,
			.pActive = suite_security_tests_enable,
		},
d488 6
@


1.1.1.11
log
@initial import of libdrm-2.4.107
@
text
@a39 12
#ifdef __linux__
#include <linux/limits.h>
#elif __FreeBSD__
/* SPECNAMELEN in FreeBSD is defined here: */
#include <sys/param.h>
#endif
#ifdef MAJOR_IN_MKDEV
#include <sys/mkdev.h>
#endif
#ifdef MAJOR_IN_SYSMACROS
#include <sys/sysmacros.h>
#endif
a61 1
#define HOTUNPLUG_TESTS_STR "Hotunplug Tests"
a139 6
	{
		.pName = HOTUNPLUG_TESTS_STR,
		.pInitFunc = suite_hotunplug_tests_init,
		.pCleanupFunc = suite_hotunplug_tests_clean,
		.pTests = hotunplug_tests,
	},
a200 4
		{
			.pName = HOTUNPLUG_TESTS_STR,
			.pActive = suite_hotunplug_tests_enable,
		},
d342 1
a342 1
void amdgpu_close_devices()
d346 1
a346 1
		if (drm_amdgpu[i] >=0) {
a347 1
		}
d433 1
a433 2
	drmDevicePtr devices[MAX_CARDS_SUPPORTED];
	int i, drm_count;
a444 2
	drm_count = drmGetDevices2(0, devices, MAX_CARDS_SUPPORTED);

a498 3
	if (amdgpu_set_test_active(BASIC_TESTS_STR, "bo eviction Test", CU_FALSE))
		fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());

a520 78

	/* You need at least 2 devices for this	*/
	if (drm_count < 2)
		if (amdgpu_set_test_active(HOTUNPLUG_TESTS_STR, "Unplug with exported fence", CU_FALSE))
			fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());
}

int test_device_index;

int amdgpu_open_device_on_test_index(int render_node)
{
	int i;

	if (amdgpu_open_devices(open_render_node) <= 0) {
		perror("Cannot open AMDGPU device");
		return -1;
	}

	if (test_device_index >= 0) {
		/* Most tests run on device of drm_amdgpu[0].
		 * Swap the chosen device to drm_amdgpu[0].
		 */
		i = drm_amdgpu[0];
		drm_amdgpu[0] = drm_amdgpu[test_device_index];
		drm_amdgpu[test_device_index] = i;
	}

	return 0;


}


static bool amdgpu_node_is_drm(int maj, int min)
{
#ifdef __linux__
    char path[64];
    struct stat sbuf;

    snprintf(path, sizeof(path), "/sys/dev/char/%d:%d/device/drm",
             maj, min);
    return stat(path, &sbuf) == 0;
#elif defined(__FreeBSD__)
    char name[SPECNAMELEN];

    if (!devname_r(makedev(maj, min), S_IFCHR, name, sizeof(name)))
      return 0;
    /* Handle drm/ and dri/ as both are present in different FreeBSD version
     * FreeBSD on amd64/i386/powerpc external kernel modules create node in
     * in /dev/drm/ and links in /dev/dri while a WIP in kernel driver creates
     * only device nodes in /dev/dri/ */
    return (!strncmp(name, "drm/", 4) || !strncmp(name, "dri/", 4));
#else
    return maj == DRM_MAJOR;
#endif
}

char *amdgpu_get_device_from_fd(int fd)
{
#ifdef __linux__
    struct stat sbuf;
    char path[PATH_MAX + 1];
    unsigned int maj, min;

    if (fstat(fd, &sbuf))
        return NULL;

    maj = major(sbuf.st_rdev);
    min = minor(sbuf.st_rdev);

    if (!amdgpu_node_is_drm(maj, min) || !S_ISCHR(sbuf.st_mode))
        return NULL;

    snprintf(path, sizeof(path), "/sys/dev/char/%d:%d/device", maj, min);
    return strdup(path);
#else
    return NULL;
#endif
d538 1
@


1.1.1.12
log
@initial import of libdrm-2.4.112
@
text
@a67 1
#define JPEG_TESTS_STR "JPEG Tests"
a74 1
#define CP_DMA_TESTS_STR "CP DMA Tests"
a117 6
		.pName = JPEG_TESTS_STR,
		.pInitFunc = suite_jpeg_tests_init,
		.pCleanupFunc = suite_jpeg_tests_clean,
		.pTests = jpeg_tests,
	},
	{
a158 6
	{
		.pName = CP_DMA_TESTS_STR,
		.pInitFunc = suite_cp_dma_tests_init,
		.pCleanupFunc = suite_cp_dma_tests_clean,
		.pTests = cp_dma_tests,
	},
a196 4
			.pName = JPEG_TESTS_STR,
			.pActive = suite_jpeg_tests_enable,
		},
		{
a223 4
		{
			.pName = CP_DMA_TESTS_STR,
			.pActive = suite_cp_dma_tests_enable,
		},
a302 4
	for (i = 0; i < MAX_CARDS_SUPPORTED; i++) {
		drm_amdgpu[i] = -1;
	}

@


1.1.1.13
log
@initial import of libdrm-2.4.114
@
text
@a551 8
	if (amdgpu_set_test_active(DEADLOCK_TESTS_STR,
			"sdma ring corrupted header test (set amdgpu.lockup_timeout=50)", CU_FALSE))
		fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());

	if (amdgpu_set_test_active(DEADLOCK_TESTS_STR,
			"sdma ring slow linear copy test (set amdgpu.lockup_timeout=50)", CU_FALSE))
		fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());

@


1.1.1.14
log
@initial import of libdrm-2.4.122
@
text
@d299 10
a308 15
	"Usage: %s [-hlpr] [-s <suite id>] [-e <s>[.<t>] [-e ...]] [-t <test id>] [-f] "
	"[-b <pci_bus_id>] [-d <pci_device_id>]\n"
	"Where,\n"
	"  -b      Specify device's PCI bus id to run tests\n"
	"  -d      Specify device's PCI device id to run tests (optional)\n"
	"  -e <s>[.<t>]  Disable test <t> of suite <s>. If only <s> is given, then disable\n"
	"          the whole suite. Can be specified more than once on the command line\n"
	"          to disable multiple tests or suites.\n"
	"  -f      Force executing inactive suite or test\n"
	"  -h      Display this help\n"
	"  -l      Display all test suites and their tests\n"
	"  -p      Display information of AMDGPU devices in system\n"
	"  -r      Run the tests on render node\n"
	"  -s <s>  Enable only test suite <s>\n"
	"  -t <t>  Enable only test <t> of test suite <s>\n";
d310 1
a310 1
static const char options[]   = "hlrps:t:e:b:d:f";
a664 42
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(_A) (sizeof(_A)/sizeof(_A[0]))
#endif

static void amdgpu_test_disable(long suite, long test)
{
	const char *suite_name;

	if (suite < 1)
		return;

	/* The array is 0-based, so subract 1. */
	suite--;
	if (suite >= ARRAY_SIZE(suites) - 1)
		return;

	suite_name = suites[suite].pName;
	if (test < 1) {
		fprintf(stderr, "Deactivating suite %s\n", suite_name);
		amdgpu_set_suite_active(suite_name, CU_FALSE);
	} else {
		int ii;

		/* The array is 0-based so subtract 1. */
		test--;
		for (ii = 0; suites[suite].pTests[ii].pName; ii++) {
			if (ii == test) {
				fprintf(stderr, "Deactivating %s:%s\n",
					suite_name,
					suites[suite].pTests[ii].pName);
				amdgpu_set_test_active(suite_name,
						       suites[suite].pTests[ii].pName,
						       CU_FALSE);
				break;
			}
		}

		if (suites[suite].pTests[ii].pName == NULL)
			fprintf(stderr, "No such suite.test %ld.%ld\n", suite, test);
	}
}

d683 5
a687 3
	/* Parse command line string.
	 * Process various command line options as early as possible.
	 */
d691 25
d719 3
a724 3
	for (i = 0; i < MAX_CARDS_SUPPORTED; i++)
		drm_amdgpu[i] = -1;

a734 11
	/* Parse command line string */
	opterr = 0;		/* Do not print error messages from getopt */
	optind = 1;
	while ((c = getopt(argc, argv, options)) != -1) {
		switch (c) {
		case 'p':
			display_devices = 1;
			break;
		}
	}

a740 14
	/* Parse command line string */
	opterr = 0;		/* Do not print error messages from getopt */
	optind = 1;
	while ((c = getopt(argc, argv, options)) != -1) {
		switch (c) {
		case 'b':
			pci_bus_id = atoi(optarg);
			break;
		case 'd':
			sscanf(optarg, "%x", &pci_device_id);
			break;
		}
	}

a782 11
	/* Parse command line string */
	opterr = 0;		/* Do not print error messages from getopt */
	optind = 1;
	while ((c = getopt(argc, argv, options)) != -1) {
		switch (c) {
		case 'l':
			display_list = 1;
			break;
		}
	}

a787 63
	/* Parse command line string */
	opterr = 0;		/* Do not print error messages from getopt */
	optind = 1;
	while ((c = getopt(argc, argv, options)) != -1) {
		long esuite = -1;
		long etest = -1;
		char *endp;
		switch (c) {
		case 's':
			suite_id = atoi(optarg);
			break;
		case 't':
			test_id = atoi(optarg);
			break;
		case 'r':
                       open_render_node = 1;
                       break;
		case 'f':
			force_run = 1;
			break;
		case 'e':
			esuite = strtol(optarg, &endp, 0);
			if (endp == optarg) {
				fprintf(stderr, "No digits given for -e argument\n");
				goto end;
			} else if (endp && *endp == '.' && esuite > 0) {
				char *tt = endp + 1;
				etest = strtol(tt, &endp, 0);
				if (endp == tt) {
					fprintf(stderr, "No digits given for test in -e s.t argument\n");
					goto end;
				} else if (endp && *endp != '\0') {
					fprintf(stderr, "Bad input given for test in -e s.t argument\n");
					goto end;
				} else if (etest < 1) {
					fprintf(stderr, "Test in -e s.t argument cannot be smaller than 1\n");
					goto end;
				}
			} else if (endp && *endp != '\0') {
				fprintf(stderr, "Bad input given for suite for -e s argument\n");
				goto end;
			} else if (esuite < 1) {
				fprintf(stderr, "Suite in -e s argument cannot be smaller than 1\n");
				goto end;
			}
			amdgpu_test_disable(esuite, etest);
			break;
		case 'h':
		case 'p':
		case 'b':
		case 'd':
		case 'l':
			/* Those have been processed earlier.
			 */
			break;
		case '?':
		default:
			fprintf(stderr, "Unknown command line option '%c'. Try -h.\n",
				c == '?' ? optopt : c);
			goto end;
		}
	}

@


