[PATCH libdrm 1/3] amdgpu: verify the tested device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Alex,

Thanks for doing this. There's a few nitpicks on top of what David and
Christian has spotted.

On 19 January 2017 at 22:53, Alex Xie <AlexBin.Xie at amd.com> 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 at 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;
> +                       }
You don't need to iterate over all the available nodes. Just fetch the
PRIMARY or RENDER based on open_render_node.
Note that a device can be missing some node types (say RENDER) so make
sure the available_nodes bitmask is set.


> +                       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);
> +
With the above comment this becomes redundant.

> +                       /* We have open this device. Go to next device.*/
> +                       break;
> +               }
> +       }
> +
Here you want to initialise the remainder of drm_amdgpu[] (since
drm_count can be less than MAX_CARDS_SUPPORTED) with -1.
Otherwise you'll have fun experiences during close/print (below).

-Emil


[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux