amdgpu: verify the tested device
PATCH 1/3 amdgpu: verify the tested device
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
--- tests/amdgpu/amdgpu_test.c | 144 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 121 insertions(+), 23 deletions(-)
tests/amdgpu/amdgpu_test.c +121 -23
@@ -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); +} + +/* 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 );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 (); }
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1484866391-17175-1-git-send-email-AlexBin.Xie-5C7GfCeVMHo@public.gmane.org
PATCH 2/3 amdgpu: A new option to choose which device to run most tests
This can be used to test multiple GPUs
--- tests/amdgpu/amdgpu_test.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-)
tests/amdgpu/amdgpu_test.c +20 -5
@@ -108,12 +108,14 @@ static void display_test_suites(void)/** 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" ; +static const char usage[] = +"Usage: %s [-hl] [<-s <suite id>> [-t <test id>]] [-d <device_id>]\n" +"where:\n" +" l - Display all suites and their tests\n" +" d - Choose which device to run tests\n" +" h - Display this help\n" ;/** Specified options strings for getopt */ -static const char options[] ="hls:t:" ; +static const char options[] ="hls:t:d:" ;/* Open AMD devices. * Return the number of AMD device openned.
@@ -238,6 +240,7 @@ int main(int argc, char **argv)int i =0 ;int suite_id =-1 ;/* By default run everything */ int test_id =-1 ;/* By default run all tests in the suite */ +int device_id =0 ;/* By default run most tests on device 0 */ CU_pSuite pSuite =NULL ;CU_pTest pTest =NULL ;
@@ -266,6 +269,9 @@ int main(int argc, char **argv)case 't' : test_id =atoi (optarg);break ; +case 'd' : + device_id =atoi (optarg); +break ;case '?' :case 'h' :fprintf (stderr, usage, argv[0 ]);
@@ -283,6 +289,15 @@ int main(int argc, char **argv)exit (EXIT_FAILURE ); } +if (device_id) { +/* Most tests run on device 0. +* Swap the chosen device to device 0. +*/ + i = drm_amdgpu[0 ]; + drm_amdgpu[0 ] = drm_amdgpu[device_id]; + drm_amdgpu[device_id] = i; + } +amdgpu_print_devices ();/* Initialize test suites to run */
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1484866391-17175-2-git-send-email-AlexBin.Xie-5C7GfCeVMHo@public.gmane.org
Re: [PATCH libdrm 2/3] amdgpu: A new option to choose which device to run most tests
Quoted 14 lines · Alex Xie
This can be used to test multiple GPUs
Signed-off-by Alex Xie <[email protected]>--- tests/amdgpu/amdgpu_test.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-)tests/amdgpu/amdgpu_test.c +0
-0@@ -108,12 +108,14 @@ static void display_test_suites(void)
tests/amdgpu/amdgpu_test.c static void display_test_suites(void) · line 115
Quoted 10 lines
tests/amdgpu/amdgpu_test.c +5
-4/** 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" ; +static const char usage[] = +"Usage: %s [-hl] [<-s <suite id>> [-t <test id>]] [-d <device_id>]\n" +"where:\n" +" l - Display all suites and their tests\n" +" d - Choose which device to run tests\n"
You want to elaborate on what you mean with "device" here. Even if currently "card0 is my Kabini, card1 Hawaii, card2 other" that may change upon reboot.
So although very nice to say "0,1, 2..." things are non-deterministic.
-Emil
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): CACvgo52ia8zBmvFm9P_zSv0fFntO1od71OawQ9e4GD64yj3DQw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Re: [PATCH libdrm 2/3] amdgpu: A new option to choose which device to run most tests
HI Emil,
See below.
Thanks,
Alex
________________________________
From: Emil Velikov <[email protected]>
Sent: Friday, January 20, 2017 8:24 AM
To: Xie, AlexBin
Cc: amd-gfx mailing list
Subject: Re: [PATCH libdrm 2/3] amdgpu: A new option to choose which device to run most tests
Quoted 14 lines · Alex Xie
This can be used to test multiple GPUs
Signed-off-by Alex Xie <[email protected]>--- tests/amdgpu/amdgpu_test.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-)tests/amdgpu/amdgpu_test.c +0
-0@@ -108,12 +108,14 @@ static void display_test_suites(void)
tests/amdgpu/amdgpu_test.c static void display_test_suites(void) · line 115
Quoted 10 lines
tests/amdgpu/amdgpu_test.c +5
-4/** 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" ; +static const char usage[] = +"Usage: %s [-hl] [<-s <suite id>> [-t <test id>]] [-d <device_id>]\n" +"where:\n" +" l - Display all suites and their tests\n" +" d - Choose which device to run tests\n"
You want to elaborate on what you mean with "device" here. Even if currently "card0 is my Kabini, card1 Hawaii, card2 other" that may change upon reboot.
So although very nice to say "0,1, 2..." things are non-deterministic.
[Alex Bin Xie] Originally I just want to give a simple solution for people to swap to test another GPU device.
Every time amdgpu_test runs, it lists the device id and its information. I was thinking to improve this but such as adding an option to list the devices. So that the 0, 1 ,2 does not change if computer is not reboot. If 0, 1, 2 is not deterministic, I have to give up this human friendly interface...
How about choose the test device by bus ID? I will add an option to list the devices with BUS ID (if people run drmdevice program, they know the information too). Then people can choose device on which BUS ID to run the test. I will provide a new patch if there is no object to this.
-Emil
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): CY4PR12MB1640A585145DD409BEB07511F2710-rpdhrqHFk06q//[email protected]
Re: [PATCH libdrm 2/3] amdgpu: A new option to choose which device to run most tests
Quoted 61 lines · AlexBin
HI Emil,
See below.
Thanks,
Alex
________________________________
From: Emil Velikov <[email protected]>
Sent: Friday, January 20, 2017 8:24 AM
To: Xie, AlexBin
Cc: amd-gfx mailing list
Subject: Re: [PATCH libdrm 2/3] amdgpu: A new option to choose which device to run most testsQuoted 24 lines · Alex Xie
This can be used to test multiple GPUs
Signed-off-by Alex Xie <[email protected]>--- tests/amdgpu/amdgpu_test.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-)tests/amdgpu/amdgpu_test.c +0
-1@@ -108,12 +108,14 @@ static void display_test_suites(void)/** Help string for command line parameters */ -static const char usage[] = "Usage: %s [-hl] [<-s <suite id>> [-t <testid>]]\n"
tests/amdgpu/amdgpu_test.c +0
-2-"where:\n" - " l - Display all suites and theirtests\n"
tests/amdgpu/amdgpu_test.c +2
-1-" h - Display this help\n" ; +static const char usage[] = + "Usage: %s [-hl] [<-s <suite id>> [-t <test id>]] [-d<device_id>]\n"
tests/amdgpu/amdgpu_test.c static void display_test_suites(void) · line 115
Quoted 3 lines
tests/amdgpu/amdgpu_test.c +3
-0+"where:\n" +" l - Display all suites and their tests\n" +" d - Choose which device to run tests\n" You want to elaborate on what you mean with "device" here. Even if currently "card0 is my Kabini, card1 Hawaii, card2 other" that may change upon reboot.
So although very nice to say "0,1, 2..." things are non-deterministic.[Alex Bin Xie] Originally I just want to give a simple solution for people to swap to test another GPU device.
Every timeamdgpu_testruns, it lists the device id and its information. I was thinking to improve this but such as adding an option to list the devices. So that the 0, 1 ,2 does not change if computer is not reboot. If 0, 1, 2 is not deterministic, I have to give up this human friendly interface...
Quoted 5 lines
How about choose the test device by bus ID? I will add an option to list the devices with BUS ID (if people run drmdevice program, they know the information too). Then people can choose device on which BUS ID to run the test. I will provide a new patch if there is no object to this.
Using BUS ID will a lot better and more robust.
Thanks again for sorting these out !
Emil
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/3 amdgpu: A new option to run tests on render node
In reply to a message not in the archiveTested:
1. As root, tests passed on primary.
2. As root, BO export/import failed on render node as expected.
3. As non-privileged user, tests failed on primary as expected.
4. As non-privileged user, only BO export/import failed on render node as expected.
--- tests/amdgpu/amdgpu_test.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
tests/amdgpu/amdgpu_test.c +8 -3
@@ -109,13 +109,14 @@ static void display_test_suites(void)/** Help string for command line parameters */ static const char usage[] = -"Usage: %s [-hl] [<-s <suite id>> [-t <test id>]] [-d <device_id>]\n" +"Usage: %s [-hlr] [<-s <suite id>> [-t <test id>]] [-d <device_id>]\n" "where:\n" " l - Display all suites and their tests\n" +" r - Run the tests on render node\n" " d - Choose which device to run tests\n" " h - Display this help\n" ;/** Specified options strings for getopt */ -static const char options[] ="hls:t:d:" ; +static const char options[] ="hlrs:t:d:" ;/* Open AMD devices. * Return the number of AMD device openned.
@@ -241,6 +242,7 @@ int main(int argc, char **argv)int suite_id =-1 ;/* By default run everything */ int test_id =-1 ;/* By default run all tests in the suite */ int device_id =0 ;/* By default run most tests on device 0 */ +int render_node =0 ;/* By default run most tests on primary node */ CU_pSuite pSuite =NULL ;CU_pTest pTest =NULL ;
@@ -272,6 +274,9 @@ int main(int argc, char **argv)case 'd' : device_id =atoi (optarg);break ; +case 'r' : + render_node =1 ; +break ;case '?' :case 'h' :fprintf (stderr, usage, argv[0 ]);
@@ -282,7 +287,7 @@ int main(int argc, char **argv) } } -amdgpu_open_devices (0 ); +amdgpu_open_devices (render_node);if (drm_amdgpu[0 ] <0 ) {perror ("Cannot open AMDGPU device.\n" );
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1484866391-17175-3-git-send-email-AlexBin.Xie-5C7GfCeVMHo@public.gmane.org
Re: [PATCH libdrm 3/3] amdgpu: A new option to run tests on render node
HI Alex,
A couple of small idea(s) for future work (?).
Quoted 2 lines · Alex Xie
Tested:
1. As root, tests passed on primary.
Add auth mechanism and request run outside of X environment (switching to TTY should work).
Then adjust the suggestion s/run as root/run in TTY/ ?
Quoted 1 line
2. As root, BO export/import failed on render node as expected.
Afaict those can never succeed, so might as well change the test to expect failure [when using the render node], or at least print a message "the following failure is expected" ?
Thanks the series !
Emil
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): CACvgo50NfvLd08LAf3xs6AzCBD3ir7PgFMaxRwiwRezB02iy2w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
RE: [PATCH libdrm 3/3] amdgpu: A new option to run tests on render node
Hi Emil,
Point 1 will be left for future patch.
Current error message is following.
Error: Permission denied. Hint:Try to run this test program as root.
I am thinking change it. Error message will be:
Error: Permission denied. Hint:Try to run this test program as root or in TTY.
Thanks,
Alex Bin Xie
-----Original Message-----
From: Emil Velikov [mailto:[email protected]]
Sent: Friday, January 20, 2017 8:31 AM
To: Xie, AlexBin <[email protected]>
Cc: amd-gfx mailing list <[email protected]>
Subject: Re: [PATCH libdrm 3/3] amdgpu: A new option to run tests on render node
HI Alex,
A couple of small idea(s) for future work (?).
Quoted 2 lines · Alex Xie
Tested:
1. As root, tests passed on primary.
Add auth mechanism and request run outside of X environment (switching to TTY should work).
Then adjust the suggestion s/run as root/run in TTY/ ?
Quoted 1 line
2. As root, BO export/import failed on render node as expected.
Afaict those can never succeed, so might as well change the test to expect failure [when using the render node], or at least print a message "the following failure is expected" ?
Thanks the series !
Emil
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): CY4PR12MB164084A3028286BAA685F682F2750-rpdhrqHFk06q//[email protected]
Re: [PATCH libdrm 3/3] amdgpu: A new option to run tests on render node
Quoted 4 lines · AlexBin
Hi Emil,
Point 1 will be left for future patch.
Definitely. I did not mean to ask/push you to address that here.
Quoted 6 lines
Current error message is following.
Error: Permission denied. Hint:Try to run this test program as root.I am thinking change it. Error message will be:
Error: Permission denied. Hint:Try to run this test program as root or in TTY.
I'm still leaning that in 2017 asking people to run anything as root is bad idea. Anyway it's just be being pedantic.
-Emil
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
some small nitpick...
Quoted 91 lines · Alex Xie
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 expectedSigned-off-by Alex Xie <[email protected]>--- tests/amdgpu/amdgpu_test.c | 144 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 121 insertions(+), 23 deletions(-)tests/amdgpu/amdgpu_test.c +70
-0@@ -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 )
tests/amdgpu/amdgpu_test.c static const char usage[] = "Usage: %s [-hl] [<-s <suite id>> [-t <test id>]]\n" · line 197
Quoted 10 lines
tests/amdgpu/amdgpu_test.c +10
-0+ amd_index++; + +free (device_name); + +/* We have open this device. Go to next device.*/ +break ; + } + } + +drmFreeDevices (devices, drm_count);
here needs return value;
Quoted 37 lines
tests/amdgpu/amdgpu_test.c +33
-0+} + +/* 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.
tests/amdgpu/amdgpu_test.c int main(int argc, char **argv) · line 279
Quoted 9 lines
tests/amdgpu/amdgpu_test.c +1
-5@@ -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
Quoted 54 lines
tests/amdgpu/amdgpu_test.c +6
-17if (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 ();
tests/amdgpu/amdgpu_test.c int main(int argc, char **argv) · line 341
Quoted 10 lines
tests/amdgpu/amdgpu_test.c +1
-1exit (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
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): [email protected]
Am 20.01.2017 um 04:45 schrieb zhoucm1:
Quoted 46 lines
some small nitpick...
Quoted 43 lines · Alex Xie
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 expectedSigned-off-by Alex Xie <[email protected]>--- tests/amdgpu/amdgpu_test.c | 144 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 121 insertions(+), 23 deletions(-)tests/amdgpu/amdgpu_test.c +0
-0@@ -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.
+ */tests/amdgpu/amdgpu_test.c +18
-0+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);
Quoted 8 lines
tests/amdgpu/amdgpu_test.c static const char usage[] = "Usage: %s [-hl] [<-s <suite id>> [-t <test id>]]\n" · line 146
Quoted 8 lines
tests/amdgpu/amdgpu_test.c +8
-0+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 ;
Additional to what David noted that check probably needs to be:
if (devices[i]->bustype != DRM_BUS_PCI ||
devices[i]->deviceinfo.pci->vendor_id != 0x1002)
continue;Or do we sell GPUs connected to USB as well?
Apart from that looks good to me and it is really good that somebody finally looks into this cause trouble with that on my A+A laptop.
Regards,
Christian.
Quoted 155 lines
Quoted 41 lines
tests/amdgpu/amdgpu_test.c +41
-0+ +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 )tests/amdgpu/amdgpu_test.c static const char usage[] = "Usage: %s [-hl] [<-s <suite id>> [-t <test id>]]\n" · line 197
Quoted 10 lines
tests/amdgpu/amdgpu_test.c +10
-0+ amd_index++; + +free (device_name); + +/* We have open this device. Go to next device.*/ +break ; + } + } + +drmFreeDevices (devices, drm_count);here needs return value;
Quoted 37 lines
tests/amdgpu/amdgpu_test.c +33
-0+} + +/* 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. tests/amdgpu/amdgpu_test.c int main(int argc, char **argv) · line 279
Quoted 8 lines
tests/amdgpu/amdgpu_test.c +1
-4@@ -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 ZhouQuoted 54 lines
tests/amdgpu/amdgpu_test.c +6
-17if (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 ]);
Quoted 8 lines
tests/amdgpu/amdgpu_test.c int main(int argc, char **argv) · line 294
Quoted 3 lines
tests/amdgpu/amdgpu_test.c +1
-0+amdgpu_close_devices ();return CU_get_error (); }_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Hi Alex,
Thanks for doing this. There's a few nitpicks on top of what David and Christian has spotted.
Quoted 49 lines · Alex Xie
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 expectedSigned-off-by Alex Xie <[email protected]>--- tests/amdgpu/amdgpu_test.c | 144 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 121 insertions(+), 23 deletions(-)tests/amdgpu/amdgpu_test.c +28
-0@@ -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 )
tests/amdgpu/amdgpu_test.c static const char usage[] = "Usage: %s [-hl] [<-s <suite id>> [-t <test id>]]\n" · line 155
Quoted 10 lines
tests/amdgpu/amdgpu_test.c +10
-0+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.
Quoted 5 lines
tests/amdgpu/amdgpu_test.c +5
-0+if (open_render_node) + device_name =drmGetRenderDeviceNameFromFd (fd); +else + device_name =drmGetPrimaryDeviceNameFromFd (fd); +
tests/amdgpu/amdgpu_test.c static const char usage[] = "Usage: %s [-hl] [<-s <suite id>> [-t <test id>]]\n" · line 191
Quoted 10 lines
tests/amdgpu/amdgpu_test.c +10
-0+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.
tests/amdgpu/amdgpu_test.c static const char usage[] = "Usage: %s [-hl] [<-s <suite id>> [-t <test id>]]\n" · line 196
Quoted 5 lines
tests/amdgpu/amdgpu_test.c +5
-0+/* 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
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): CACvgo50HCafUSw7zDjkS+_1xs67=QgHcOWcO1DDqzBL4RcRBJA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Hi Emil,
Thanks for the comments.
Please see below.
Regards,
Alex Bin Xie
________________________________
From: Emil Velikov <[email protected]>
Sent: Friday, January 20, 2017 8:18 AM
To: Xie, AlexBin
Cc: amd-gfx mailing list
Subject: Re: [PATCH libdrm 1/3] amdgpu: verify the tested device
Hi Alex,
Thanks for doing this. There's a few nitpicks on top of what David and Christian has spotted.
Quoted 49 lines · Alex Xie
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 expectedSigned-off-by Alex Xie <[email protected]>--- tests/amdgpu/amdgpu_test.c | 144 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 121 insertions(+), 23 deletions(-)tests/amdgpu/amdgpu_test.c +28
-0@@ -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 )
tests/amdgpu/amdgpu_test.c static const char usage[] = "Usage: %s [-hl] [<-s <suite id>> [-t <test id>]]\n" · line 155
Quoted 10 lines
tests/amdgpu/amdgpu_test.c +10
-0+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.
[Alex Bin Xie]:
That was my original design, but later I changed.
I knew this work for the current xf86drm.c. But is the nodes[0] always primary?
I was afraid that this may be changed in future. I searched all drm tests. I did not see an example.
So amdgpu_test will be the first to access nodes like: open(devices[i]->nodes[DRM_NODE_PRIMARY]), for example.
Quoted 5 lines
tests/amdgpu/amdgpu_test.c +5
-0+if (open_render_node) + device_name =drmGetRenderDeviceNameFromFd (fd); +else + device_name =drmGetPrimaryDeviceNameFromFd (fd); +
tests/amdgpu/amdgpu_test.c static const char usage[] = "Usage: %s [-hl] [<-s <suite id>> [-t <test id>]]\n" · line 191
Quoted 10 lines
tests/amdgpu/amdgpu_test.c +10
-0+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.
tests/amdgpu/amdgpu_test.c static const char usage[] = "Usage: %s [-hl] [<-s <suite id>> [-t <test id>]]\n" · line 196
Quoted 5 lines
tests/amdgpu/amdgpu_test.c +5
-0+/* 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).
[Alex Bin Xie]: This initialization is done in existing main() function (not introduced this patch).
-Emil
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): CY4PR12MB1640D78EBE9F998A00F5323FF2710-rpdhrqHFk06q//[email protected]
Quoted 102 lines · AlexBin
Hi Emil,
Thanks for the comments.
Please see below.
Regards,
Alex Bin Xie
________________________________
From: Emil Velikov <[email protected]>
Sent: Friday, January 20, 2017 8:18 AM
To: Xie, AlexBin
Cc: amd-gfx mailing list
Subject: Re: [PATCH libdrm 1/3] amdgpu: verify the tested deviceHi Alex,
Thanks for doing this. There's a few nitpicks on top of what David and Christian has spotted.
Quoted 52 lines · Alex Xie
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 expectedSigned-off-by Alex Xie <[email protected]>--- tests/amdgpu/amdgpu_test.c | 144 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 121 insertions(+), 23 deletions(-)tests/amdgpu/amdgpu_test.c +0
-0@@ -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:";tests/amdgpu/amdgpu_test.c +28
-0+/* 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)tests/amdgpu/amdgpu_test.c static const char usage[] = "Usage: %s [-hl] [<-s <suite id>> [-t <test id>]]\n" · line 155
Quoted 10 lines
tests/amdgpu/amdgpu_test.c +10
-0+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 theavailable_nodesbitmask is set.[Alex Bin Xie]:
That was my original design, but later I changed.
I knew this work for the currentxf86drm.c. But is the nodes[0] always primary?
I was afraid that this may be changed in future. I searched all drm tests. I did not see an example.
Quoted 3 lines
So
amdgpu_testwill be the first to access nodes like:open(devices[i]->nodes[DRM_NODE_PRIMARY]), for example.
Please avoid nodes[0] and use the symbolic name - nodes[DRM_NODE_PRIMARY]. Comment applies for any DRM_NODE_*.
Quoted 25 lines
Quoted 12 lines
tests/amdgpu/amdgpu_test.c +2
-0+if (open_render_node) + device_name =drmGetRenderDeviceNameFromFd(fd);
tests/amdgpu/amdgpu_test.c +2
-0+else + device_name =drmGetPrimaryDeviceNameFromFd(fd);
tests/amdgpu/amdgpu_test.c +5
-0+ +close (fd); + + drm_amdgpu[amd_index] = open(device_name, + O_RDWR |
O_CLOEXEC);tests/amdgpu/amdgpu_test.c static const char usage[] = "Usage: %s [-hl] [<-s <suite id>> [-t <test id>]]\n" · line 191
Quoted 6 lines
tests/amdgpu/amdgpu_test.c +6
-0+ +if (drm_amdgpu[amd_index] >=0 ) + amd_index++; + +free (device_name); +With the above comment this becomes redundant.
tests/amdgpu/amdgpu_test.c static const char usage[] = "Usage: %s [-hl] [<-s <suite id>> [-t <test id>]]\n" · line 196
Quoted 5 lines
tests/amdgpu/amdgpu_test.c +5
-0+/* We have open this device. Go to next device.*/ +break ; + } + } +
Quoted 7 lines
Here you want to initialise the remainder of drm_amdgpu[] (since
drm_countcan be less thanMAX_CARDS_SUPPORTED) with -1. Otherwise you'll have fun experiences during close/print (below).[Alex Bin Xie]: This initialization is done in existing
main()function (not introduced this patch).
Indeed that's correct. It looks a bit strange to have it separate, but not my call.
Unrelated:
Fwiw please can drop the legacy drmAvailable() from the test, if you have a minute.
Thanks !
Emil
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx