AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: zhoucm1 <david1.zhou-5C7GfCeVMHo@public.gmane.org>
To: Alex Xie <AlexBin.Xie-5C7GfCeVMHo@public.gmane.org>,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Subject: Re: [PATCH libdrm 1/3] amdgpu: verify the tested device
Date: Fri, 20 Jan 2017 11:45:00 +0800	[thread overview]
Message-ID: <588187BC.9070806@amd.com> (raw)
In-Reply-To: <1484866391-17175-1-git-send-email-AlexBin.Xie-5C7GfCeVMHo@public.gmane.org>

some small nitpick...

On 2017年01月20日 06:53, Alex Xie wrote:
> Verify the vender ID and driver name.
> Open all AMDGPU devices.
> Provide an option to open render node.
>
> Tested as root: PASS
> Tested as non-privileged user:
> All tests failed as expected
>
> Signed-off-by: Alex Xie <AlexBin.Xie@amd.com>
> ---
>   tests/amdgpu/amdgpu_test.c | 144 +++++++++++++++++++++++++++++++++++++--------
>   1 file changed, 121 insertions(+), 23 deletions(-)
>
> diff --git a/tests/amdgpu/amdgpu_test.c b/tests/amdgpu/amdgpu_test.c
> index 71f357c..e42ef9d 100644
> --- a/tests/amdgpu/amdgpu_test.c
> +++ b/tests/amdgpu/amdgpu_test.c
> @@ -115,6 +115,119 @@ static const char usage[] = "Usage: %s [-hl] [<-s <suite id>> [-t <test id>]]\n"
>   /** Specified options strings for getopt */
>   static const char options[]   = "hls:t:";
>   
> +/* 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 j;
> +	int amd_index = 0;
> +	int drm_count;
> +	int fd;
> +	char *device_name;
> +	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 AMD GPU vender ID, skip*/
> +		if (devices[i]->bustype == DRM_BUS_PCI)
> +			if (devices[i]->deviceinfo.pci->vendor_id != 0x1002)
> +				continue;
> +
> +		for (j = 0; j < DRM_NODE_MAX; j++) {
> +			if (devices[i]->available_nodes & 1 << j) {
> +				fd = open(
> +					devices[i]->nodes[j],
> +					O_RDONLY | O_CLOEXEC,
> +					0);
> +				if (fd < 0) continue;
> +			}
> +
> +			version = drmGetVersion(fd);
> +			if (!version) {
> +				fprintf(stderr,
> +					"Warning: Cannot get version for %s."
> +					"Error is %s\n",
> +					devices[i]->nodes[j],
> +					strerror(errno));
> +				close(fd);
> +				break;
> +			}
> +
> +			if (strcmp(version->name, "amdgpu")) {
> +				/* This is not AMDGPU driver, skip.*/
> +				drmFreeVersion(version);
> +				close(fd);
> +				break;
> +			}
> +
> +			drmFreeVersion(version);
> +
> +			if (open_render_node)
> +				device_name = drmGetRenderDeviceNameFromFd(fd);
> +			else
> +				device_name = drmGetPrimaryDeviceNameFromFd(fd);
> +
> +			close(fd);
> +
> +			drm_amdgpu[amd_index] = open(device_name,
> +							O_RDWR | O_CLOEXEC);
> +
> +			if (drm_amdgpu[amd_index] >= 0)
> +				amd_index++;
> +
> +			free(device_name);
> +
> +			/* We have open this device. Go to next device.*/
> +			break;
> +		}
> +	}
> +
> +	drmFreeDevices(devices, drm_count);
here needs return value;
> +}
> +
> +/* 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;
> +	for (i = 0; i < MAX_CARDS_SUPPORTED; i++)
> +		if (drm_amdgpu[i] >=0) {
> +			/** Display version of DRM driver */
> +			drmVersionPtr retval = drmGetVersion(drm_amdgpu[0]);
> +
> +			if (retval == NULL) {
> +				perror("Cannot get version for AMDGPU device");
> +				exit(EXIT_FAILURE);
> +			}
> +
> +			printf("AMDGPU device #%d: "
> +				"Name: [%s] : Date [%s] : Description [%s]\n",
> +				i, retval->name, retval->date, retval->desc);
> +			drmFreeVersion(retval);
> +		}
> +}
> +
>   /* The main() function for setting up and running the tests.
>    * Returns a CUE_SUCCESS on successful running, another
>    * CUnit error code on failure.
> @@ -163,35 +276,20 @@ int main(int argc, char **argv)
>   		}
>   	}
>   
> -	/* 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);
> +	amdgpu_open_devices(0);
we'd better to check this function return value.

Regards,
David Zhou
>   
>   	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");
> +		perror("Cannot open AMDGPU device.\n");
>   		exit(EXIT_FAILURE);
>   	}
>   
> -	printf("DRM Driver: Name: [%s] : Date [%s] : Description [%s]\n",
> -	       retval->name, retval->date, retval->desc);
> -
> -	drmFreeVersion(retval);
> +	amdgpu_print_devices();
>   
>   	/* Initialize test suites to run */
>   
>   	/* initialize the CUnit test registry */
>   	if (CUE_SUCCESS != CU_initialize_registry()) {
> -		close(drm_amdgpu[0]);
> +		amdgpu_close_devices();
>   		return CU_get_error();
>   	}
>   
> @@ -200,7 +298,7 @@ int main(int argc, char **argv)
>   		fprintf(stderr, "suite registration failed - %s\n",
>   				CU_get_error_msg());
>   		CU_cleanup_registry();
> -		close(drm_amdgpu[0]);
> +		amdgpu_close_devices();
>   		exit(EXIT_FAILURE);
>   	}
>   
> @@ -222,7 +320,7 @@ int main(int argc, char **argv)
>   					fprintf(stderr, "Invalid test id: %d\n",
>   								test_id);
>   					CU_cleanup_registry();
> -					close(drm_amdgpu[0]);
> +					amdgpu_close_devices();
>   					exit(EXIT_FAILURE);
>   				}
>   			} else
> @@ -231,13 +329,13 @@ int main(int argc, char **argv)
>   			fprintf(stderr, "Invalid suite id : %d\n",
>   					suite_id);
>   			CU_cleanup_registry();
> -			close(drm_amdgpu[0]);
> +			amdgpu_close_devices();
>   			exit(EXIT_FAILURE);
>   		}
>   	} else
>   		CU_basic_run_tests();
>   
>   	CU_cleanup_registry();
> -	close(drm_amdgpu[0]);
> +	amdgpu_close_devices();
>   	return CU_get_error();
>   }

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2017-01-20  3:45 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-19 22:53 [PATCH libdrm 1/3] amdgpu: verify the tested device Alex Xie
     [not found] ` <1484866391-17175-1-git-send-email-AlexBin.Xie-5C7GfCeVMHo@public.gmane.org>
2017-01-19 22:53   ` [PATCH libdrm 2/3] amdgpu: A new option to choose which device to run most tests Alex Xie
     [not found]     ` <1484866391-17175-2-git-send-email-AlexBin.Xie-5C7GfCeVMHo@public.gmane.org>
2017-01-20 13:24       ` Emil Velikov
     [not found]         ` <CACvgo52ia8zBmvFm9P_zSv0fFntO1od71OawQ9e4GD64yj3DQw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-01-20 22:08           ` Xie, AlexBin
     [not found]             ` <CY4PR12MB1640A585145DD409BEB07511F2710-rpdhrqHFk06q//3LJcutlgdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2017-01-22 18:52               ` Emil Velikov
2017-01-19 22:53   ` [PATCH libdrm 3/3] amdgpu: A new option to run tests on render node Alex Xie
     [not found]     ` <1484866391-17175-3-git-send-email-AlexBin.Xie-5C7GfCeVMHo@public.gmane.org>
2017-01-20 13:31       ` Emil Velikov
     [not found]         ` <CACvgo50NfvLd08LAf3xs6AzCBD3ir7PgFMaxRwiwRezB02iy2w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-01-24 22:39           ` Xie, AlexBin
     [not found]             ` <CY4PR12MB164084A3028286BAA685F682F2750-rpdhrqHFk06q//3LJcutlgdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2017-01-26 23:59               ` Emil Velikov
2017-01-20  3:45   ` zhoucm1 [this message]
     [not found]     ` <588187BC.9070806-5C7GfCeVMHo@public.gmane.org>
2017-01-20  8:40       ` [PATCH libdrm 1/3] amdgpu: verify the tested device Christian König
2017-01-20 13:18   ` Emil Velikov
     [not found]     ` <CACvgo50HCafUSw7zDjkS+_1xs67=QgHcOWcO1DDqzBL4RcRBJA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-01-20 19:14       ` Xie, AlexBin
     [not found]         ` <CY4PR12MB1640D78EBE9F998A00F5323FF2710-rpdhrqHFk06q//3LJcutlgdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2017-01-20 19:45           ` Emil Velikov
  -- strict thread matches above, loose matches on Subject: below --
2017-01-24 22:29 Alex Xie
     [not found] ` <1485296992-2719-1-git-send-email-AlexBin.Xie-5C7GfCeVMHo@public.gmane.org>
2017-01-27  0:08   ` Emil Velikov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=588187BC.9070806@amd.com \
    --to=david1.zhou-5c7gfcevmho@public.gmane.org \
    --cc=AlexBin.Xie-5C7GfCeVMHo@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox