diff mbox

[libdrm,1/9] tests/dristat: don't include C files

Message ID 1427061825-27470-2-git-send-email-emil.l.velikov@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Emil Velikov March 22, 2015, 10:03 p.m. UTC
Remove the hack of including C files, by reworking the only requirement
drmOpenMinor() to an open(buf...). After all we do know the exact name
of the device we're going to open, so might as well use it. Replace
hard-coded 16 with DRM_MAX_MINOR while we're here.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
---
 tests/dristat.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

Comments

Jan Vesely March 23, 2015, 10:10 p.m. UTC | #1
On Sun, 2015-03-22 at 22:03 +0000, Emil Velikov wrote:
> Remove the hack of including C files, by reworking the only requirement
> drmOpenMinor() to an open(buf...). After all we do know the exact name
> of the device we're going to open, so might as well use it. Replace
> hard-coded 16 with DRM_MAX_MINOR while we're here.
> 
> Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
> ---
>  tests/dristat.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/tests/dristat.c b/tests/dristat.c
> index cca4b03..cc23e16 100644
> --- a/tests/dristat.c
> +++ b/tests/dristat.c
> @@ -31,13 +31,14 @@
>  # include <config.h>
>  #endif
>  
> +#include <ctype.h>
> +#include <fcntl.h>
>  #include <stdio.h>
>  #include <stdlib.h>
> +#include <string.h>
> +#include <sys/stat.h>
>  #include <unistd.h>
>  #include "xf86drm.h"
> -#include "xf86drmRandom.c"
> -#include "xf86drmHash.c"
> -#include "xf86drm.c"
>  
>  #define DRM_VERSION 0x00000001
>  #define DRM_MEMORY  0x00000002
> @@ -267,9 +268,9 @@ int main(int argc, char **argv)
>  	    return 1;
>  	}
>  
> -    for (i = 0; i < 16; i++) if (!minor || i == minor) {
> +    for (i = 0; i < DRM_MAX_MINOR; i++) if (!minor || i == minor) {
>  	sprintf(buf, DRM_DEV_NAME, DRM_DIR_NAME, i);
> -	fd = drmOpenMinor(i, 1, DRM_NODE_PRIMARY);
> +	fd = open(buf, O_RDWR, 0);

What about the "create" (second) argument? The original code creates the
node if it does not exist (on non-UDEV systems), or waits some time for
udev to create it.
Not sure how this is relevant for the test.


>  	if (fd >= 0) {
>  	    printf("%s\n", buf);
>  	    if (mask & DRM_BUSID)   getbusid(fd);
Emil Velikov March 26, 2015, 2:59 p.m. UTC | #2
On 23/03/15 22:10, Jan Vesely wrote:
> On Sun, 2015-03-22 at 22:03 +0000, Emil Velikov wrote:
>> Remove the hack of including C files, by reworking the only requirement
>> drmOpenMinor() to an open(buf...). After all we do know the exact name
>> of the device we're going to open, so might as well use it. Replace
>> hard-coded 16 with DRM_MAX_MINOR while we're here.
>>
>> Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
>> ---
>>  tests/dristat.c | 11 ++++++-----
>>  1 file changed, 6 insertions(+), 5 deletions(-)
>>
>> diff --git a/tests/dristat.c b/tests/dristat.c
>> index cca4b03..cc23e16 100644
>> --- a/tests/dristat.c
>> +++ b/tests/dristat.c
>> @@ -31,13 +31,14 @@
>>  # include <config.h>
>>  #endif
>>  
>> +#include <ctype.h>
>> +#include <fcntl.h>
>>  #include <stdio.h>
>>  #include <stdlib.h>
>> +#include <string.h>
>> +#include <sys/stat.h>
>>  #include <unistd.h>
>>  #include "xf86drm.h"
>> -#include "xf86drmRandom.c"
>> -#include "xf86drmHash.c"
>> -#include "xf86drm.c"
>>  
>>  #define DRM_VERSION 0x00000001
>>  #define DRM_MEMORY  0x00000002
>> @@ -267,9 +268,9 @@ int main(int argc, char **argv)
>>  	    return 1;
>>  	}
>>  
>> -    for (i = 0; i < 16; i++) if (!minor || i == minor) {
>> +    for (i = 0; i < DRM_MAX_MINOR; i++) if (!minor || i == minor) {
>>  	sprintf(buf, DRM_DEV_NAME, DRM_DIR_NAME, i);
>> -	fd = drmOpenMinor(i, 1, DRM_NODE_PRIMARY);
>> +	fd = open(buf, O_RDWR, 0);
> 
> What about the "create" (second) argument? The original code creates the
> node if it does not exist (on non-UDEV systems), or waits some time for
> udev to create it.
> Not sure how this is relevant for the test.
> 
Hmm brain triggered this as "create = 0", as I was going through. Fwiw I
would opt for nuking this custom hack, and stick with open().

If one needs to wait for udev or manually create the nod then they have
bigger ship to fry. All of that should be resolved before anyone has the
change to run the program.

Let's give it some time for people to voice their opinions on the topic.
Could be that something more elaborate is happing if create is set.


-Emil
diff mbox

Patch

diff --git a/tests/dristat.c b/tests/dristat.c
index cca4b03..cc23e16 100644
--- a/tests/dristat.c
+++ b/tests/dristat.c
@@ -31,13 +31,14 @@ 
 # include <config.h>
 #endif
 
+#include <ctype.h>
+#include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
 #include <unistd.h>
 #include "xf86drm.h"
-#include "xf86drmRandom.c"
-#include "xf86drmHash.c"
-#include "xf86drm.c"
 
 #define DRM_VERSION 0x00000001
 #define DRM_MEMORY  0x00000002
@@ -267,9 +268,9 @@  int main(int argc, char **argv)
 	    return 1;
 	}
 
-    for (i = 0; i < 16; i++) if (!minor || i == minor) {
+    for (i = 0; i < DRM_MAX_MINOR; i++) if (!minor || i == minor) {
 	sprintf(buf, DRM_DEV_NAME, DRM_DIR_NAME, i);
-	fd = drmOpenMinor(i, 1, DRM_NODE_PRIMARY);
+	fd = open(buf, O_RDWR, 0);
 	if (fd >= 0) {
 	    printf("%s\n", buf);
 	    if (mask & DRM_BUSID)   getbusid(fd);