Skip to contentSkip to conversation

modetest: fix some compiler warnings

PATCH New Paulo Zanoni 1 participant 5 messages Mar 20, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/5 modetest: fix some compiler warnings

From: Paulo Zanoni <[email protected]>

Use unsigned int instead of int:
- modetest.c:89:1: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
- modetest.c:97:1: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
- modetest.c:117:1: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
- modetest.c:772:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]

The 'fd' variable is global, we don't need to pass it as an argument:
- modetest.c:698:40: warning: unused parameter ‘fd’ [-Wunused-parameter]

We don't use the 'modeset' variable:
- modetest.c:725:8: warning: variable ‘modeset’ set but not used [-Wunused-but-set-variable]

---
 tests/modetest/modetest.c |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)
tests/modetest/modetest.c +5 -6
index 229ab8a..c0f7ad7 100644
@@ -70,7 +70,7 @@ struct type_name {
 
 #define type_name_fn(res) \
 char * res##_str(int type) {			\
-	int i;						\
+	unsigned int i;					\
 	for (i = 0; i < ARRAY_SIZE(res##_names); i++) { \
 		if (res##_names[i].type == type)	\
 			return res##_names[i].name;	\
@@ -695,7 +695,7 @@ void usage(char *name)
 
 #define dump_resource(res) if (res) dump_##res()
 
-static int page_flipping_supported(int fd)
+static int page_flipping_supported(void)
 {
 	/*FIXME: generic ioctl needed? */
 	return 1;
@@ -722,8 +722,8 @@ int main(int argc, char **argv)
 	int encoders = 0, connectors = 0, crtcs = 0, framebuffers = 0;
 	int test_vsync = 0;
 	char *modules[] = { "i915", "radeon", "nouveau", "vmwgfx" };
-	char *modeset = NULL;
-	int i, count = 0;
+	unsigned int i;
+	int count = 0;
 	struct connector con_args[2];
 	
 	opterr = 0;
@@ -748,7 +748,6 @@ int main(int argc, char **argv)
 			test_vsync = 1;
 			break;
 		case 's':
-			modeset = strdup(optarg);
 			con_args[count].crtc = -1;
 			if (sscanf(optarg, "%d:%64s",
 				   &con_args[count].id,
@@ -780,7 +779,7 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (test_vsync && !page_flipping_supported(fd)) {
+	if (test_vsync && !page_flipping_supported()) {
 		fprintf(stderr, "page flipping not supported by drm.\n");
 		return -1;
 	}
Signature · 6 lines
1.7.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH 2/5 modetest: fix memory leak

From: Paulo Zanoni <[email protected]>

Don't "continue" without freeing the connector.

192 bytes in 6 blocks are indirectly lost in loss record 6 of 12
at 0x4C2779D: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) by 0x4E30DD8: drmMalloc (xf86drm.c:147)
by 0x4E35024: drmAllocCpy (xf86drmMode.c:73)
by 0x4E35D69: drmModeGetConnector (xf86drmMode.c:507)
by 0x402F22: dump_connectors (modetest.c:181)
by 0x40261B: main (modetest.c:801)

---
 tests/modetest/modetest.c |   21 ++++++++++-----------
 1 files changed, 10 insertions(+), 11 deletions(-)
tests/modetest/modetest.c +10 -11
index c0f7ad7..2779d4f 100644
@@ -198,17 +198,16 @@ void dump_connectors(void)
 			printf("%s%d", j > 0 ? ", " : "", connector->encoders[j]);
 		printf("\n");
 
-		if (!connector->count_modes)
-			continue;
-
-		printf("  modes:\n");
-		printf("  name refresh (Hz) hdisp hss hse htot vdisp "
-		       "vss vse vtot)\n");
-		for (j = 0; j < connector->count_modes; j++)
-			dump_mode(&connector->modes[j]);
-
-		printf("  props:\n");
-		dump_props(connector);
+		if (connector->count_modes) {
+			printf("  modes:\n");
+			printf("  name refresh (Hz) hdisp hss hse htot vdisp "
+			       "vss vse vtot)\n");
+			for (j = 0; j < connector->count_modes; j++)
+				dump_mode(&connector->modes[j]);
+
+			printf("  props:\n");
+			dump_props(connector);
+		}
 
 		drmModeFreeConnector(connector);
 	}
Signature · 1 line
1.7.9.1
#2 lore raw

PATCH 3/5 modetest: print more about our properties

In reply to Paulo Zanoni

From: Paulo Zanoni <[email protected]>

In the future we'll have more than just connector properties, so create a dump_prop function that can handle any property (instead of the current dump_props function that only handles connector properties).

Also, make this function print a lot more information about the existing properties.

Also change the printed indentation of the modes to make the output more readable.

The previous function dump_props also segfaulted when we didn't have enought permissions. The new function does not segfault in this case (by checking for the return value of drmModeGetProperty).

---
 tests/modetest/modetest.c |   92 ++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 83 insertions(+), 9 deletions(-)
tests/modetest/modetest.c +83 -9
index 2779d4f..52c81a9 100644
@@ -43,6 +43,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
+#include <inttypes.h>
 #include <unistd.h>
 #include <string.h>
 #include <errno.h>
@@ -144,7 +145,7 @@ void dump_encoders(void)
 
 void dump_mode(drmModeModeInfo *mode)
 {
-	printf("  %s %d %d %d %d %d %d %d %d %d\n",
+	printf("\t%s %d %d %d %d %d %d %d %d %d\n",
 	       mode->name,
 	       mode->vrefresh,
 	       mode->hdisplay,
@@ -158,16 +159,87 @@ void dump_mode(drmModeModeInfo *mode)
 }
 
 static void
-dump_props(drmModeConnector *connector)
+dump_blob(uint32_t blob_id)
+{
+	uint32_t i;
+	unsigned char *blob_data;
+	drmModePropertyBlobPtr blob;
+
+	blob = drmModeGetPropertyBlob(fd, blob_id);
+	blob_data = blob->data;
+
+	for (i = 0; i < blob->length; i++) {
+		if (i % 16 == 0)
+			printf("\n\t\t\t");
+		printf("%.2hhx", blob_data[i]);
+	}
+	printf("\n");
+
+	drmModeFreePropertyBlob(blob);
+}
+
+static void
+dump_prop(uint32_t prop_id, uint64_t value)
 {
-	drmModePropertyPtr props;
 	int i;
+	drmModePropertyPtr prop;
+
+	prop = drmModeGetProperty(fd, prop_id);
+
+	printf("\t%d", prop_id);
+	if (!prop) {
+		printf("\n");
+		return;
+	}
+
+	printf(" %s:\n", prop->name);
+
+	printf("\t\tflags:");
+	if (prop->flags & DRM_MODE_PROP_PENDING)
+		printf(" pending");
+	if (prop->flags & DRM_MODE_PROP_RANGE)
+		printf(" range");
+	if (prop->flags & DRM_MODE_PROP_IMMUTABLE)
+		printf(" immutable");
+	if (prop->flags & DRM_MODE_PROP_ENUM)
+		printf(" enum");
+	if (prop->flags & DRM_MODE_PROP_BLOB)
+		printf(" blob");
+	printf("\n");
 
-	for (i = 0; i < connector->count_props; i++) {
-		props = drmModeGetProperty(fd, connector->props[i]);
-		printf("\t%s, flags %d\n", props->name, props->flags);
-		drmModeFreeProperty(props);
+	if (prop->flags & DRM_MODE_PROP_RANGE) {
+		printf("\t\tvalues:");
+		for (i = 0; i < prop->count_values; i++)
+			printf(" %"PRIu64, prop->values[i]);
+		printf("\n");
+	}
+
+	if (prop->flags & DRM_MODE_PROP_ENUM) {
+		printf("\t\tenums:");
+		for (i = 0; i < prop->count_enums; i++)
+			printf(" %s=%llu", prop->enums[i].name,
+			       prop->enums[i].value);
+		printf("\n");
+	} else {
+		assert(prop->count_enums == 0);
 	}
+
+	if (prop->flags & DRM_MODE_PROP_BLOB) {
+		printf("\t\tblobs:\n");
+		for (i = 0; i < prop->count_blobs; i++)
+			dump_blob(prop->blob_ids[i]);
+		printf("\n");
+	} else {
+		assert(prop->count_blobs == 0);
+	}
+
+	printf("\t\tvalue:");
+	if (prop->flags & DRM_MODE_PROP_BLOB)
+		dump_blob(value);
+	else
+		printf(" %"PRIu64"\n", value);
+
+	drmModeFreeProperty(prop);
 }
 
 void dump_connectors(void)
@@ -200,13 +272,15 @@ void dump_connectors(void)
 
 		if (connector->count_modes) {
 			printf("  modes:\n");
-			printf("  name refresh (Hz) hdisp hss hse htot vdisp "
+			printf("\tname refresh (Hz) hdisp hss hse htot vdisp "
 			       "vss vse vtot)\n");
 			for (j = 0; j < connector->count_modes; j++)
 				dump_mode(&connector->modes[j]);
 
 			printf("  props:\n");
-			dump_props(connector);
+			for (j = 0; j < connector->count_props; j++)
+				dump_prop(connector->props[j],
+					  connector->prop_values[j]);
 		}
 
 		drmModeFreeConnector(connector);
Signature · 1 line
1.7.9.1
#3 lore raw

PATCH 4/5 Add support for CRTC properties

In reply to Paulo Zanoni

From: Paulo Zanoni <[email protected]>

New library calls:
- drmModeCrtcGetProperties
- drmModeFreeCrtcProperties
- drmModeCrtcSetProperties

---
 include/drm/drm.h      |    2 +
 include/drm/drm_mode.h |   13 ++++++++
 xf86drmMode.c          |   79 ++++++++++++++++++++++++++++++++++++++++++++++++
 xf86drmMode.h          |   12 +++++++
 4 files changed, 106 insertions(+), 0 deletions(-)
include/drm/drm.h +2 -0
index 8adb9d5..45eef57 100644
@@ -717,6 +717,8 @@ struct drm_get_cap {
 #define DRM_IOCTL_MODE_GETPLANE	DRM_IOWR(0xB6, struct drm_mode_get_plane)
 #define DRM_IOCTL_MODE_SETPLANE	DRM_IOWR(0xB7, struct drm_mode_set_plane)
 #define DRM_IOCTL_MODE_ADDFB2		DRM_IOWR(0xB8, struct drm_mode_fb_cmd2)
+#define DRM_IOCTL_MODE_CRTC_GETPROPERTIES	DRM_IOWR(0xB9, struct drm_mode_crtc_get_properties)
+#define DRM_IOCTL_MODE_CRTC_SETPROPERTY	DRM_IOWR(0xBA, struct drm_mode_crtc_set_property)
 
 /**
  * Device specific ioctls should only be in their respective headers
include/drm/drm_mode.h +13 -0
index f36c61a..2bc6b83 100644
@@ -250,6 +250,19 @@ struct drm_mode_connector_set_property {
 	__u32 connector_id;
 };
 
+struct drm_mode_crtc_get_properties {
+	__u64 props_ptr;
+	__u64 prop_values_ptr;
+	__u32 count_props;
+	__u32 crtc_id;
+};
+
+struct drm_mode_crtc_set_property {
+	__u64 value;
+	__u32 prop_id;
+	__u32 crtc_id;
+};
+
 struct drm_mode_get_blob {
 	__u32 blob_id;
 	__u32 length;
xf86drmMode.c +79 -0

82 lines not on this page · raw message

xf86drmMode.h +12 -0
index 991e3f9..f2733ec 100644
@@ -281,6 +281,12 @@ typedef struct _drmModeConnector {
 	uint32_t *encoders; /**< List of encoder ids */
 } drmModeConnector, *drmModeConnectorPtr;
 
+typedef struct _drmModeCrtcProperties {
+	uint32_t count_props;
+	uint32_t *props;
+	uint64_t *prop_values;
+} drmModeCrtcProperties, *drmModeCrtcPropertiesPtr;
+
 typedef struct _drmModePlane {
 	uint32_t count_formats;
 	uint32_t *formats;
@@ -428,6 +434,12 @@ extern int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t crtc_id,
 			   uint32_t src_x, uint32_t src_y,
 			   uint32_t src_w, uint32_t src_h);
 
+extern drmModeCrtcPropertiesPtr drmModeCrtcGetProperties(int fd,
+							 uint32_t crtc_id);
+extern void drmModeFreeCrtcProperties(drmModeCrtcPropertiesPtr ptr);
+extern int drmModeCrtcSetProperty(int fd, uint32_t crtc_id,
+				  uint32_t property_id, uint64_t value);
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif
Signature · 1 line
1.7.9.1
#4 lore raw

PATCH 5/5 modetest: print CRTC properties

In reply to Paulo Zanoni

From: Paulo Zanoni <[email protected]>

---
 tests/modetest/modetest.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
tests/modetest/modetest.c +13 -0
index 52c81a9..58bb39e 100644
@@ -291,7 +291,9 @@ void dump_connectors(void)
 void dump_crtcs(void)
 {
 	drmModeCrtc *crtc;
+	drmModeCrtcPropertiesPtr props;
 	int i;
+	uint32_t j;
 
 	printf("CRTCs:\n");
 	printf("id\tfb\tpos\tsize\n");
@@ -310,6 +312,17 @@ void dump_crtcs(void)
 		       crtc->width, crtc->height);
 		dump_mode(&crtc->mode);
 
+		printf("  props:\n");
+		props = drmModeCrtcGetProperties(fd, crtc->crtc_id);
+		if (props) {
+			for (j = 0; j < props->count_props; j++)
+				dump_prop(props->props[j],
+					  props->prop_values[j]);
+			drmModeFreeCrtcProperties(props);
+		} else {
+			printf("\tcould not get crtc properties\n");
+		}
+
 		drmModeFreeCrtc(crtc);
 	}
 	printf("\n");
Signature · 1 line
1.7.9.1