modetest: Dump bit field names
authorKristian Høgsberg <krh@bitplanet.net>
Thu, 28 Jun 2012 14:48:31 +0000 (10:48 -0400)
committerKristian Høgsberg <krh@bitplanet.net>
Thu, 28 Jun 2012 17:24:36 +0000 (13:24 -0400)
tests/modetest/modetest.c

index dc84cf32bda1ad68d67174c595f15a7a1d4c027c..ec3121e1afd12fc4535dcd98aa48a7400bf7c0b8 100644 (file)
@@ -118,6 +118,49 @@ struct type_name connector_type_names[] = {
 
 type_name_fn(connector_type)
 
+#define bit_name_fn(res)                                       \
+char * res##_str(int type) {                                   \
+       int i;                                                  \
+       const char *sep = "";                                   \
+       for (i = 0; i < ARRAY_SIZE(res##_names); i++) {         \
+               if (type & (1 << i)) {                          \
+                       printf("%s%s", sep, res##_names[i]);    \
+                       sep = ", ";                             \
+               }                                               \
+       }                                                       \
+}
+
+static const char *mode_type_names[] = {
+       "builtin",
+       "clock_c",
+       "crtc_c",
+       "preferred",
+       "default",
+       "userdef",
+       "driver",
+};
+
+bit_name_fn(mode_type)
+
+static const char *mode_flag_names[] = {
+       "phsync",
+       "nhsync",
+       "pvsync",
+       "nvsync",
+       "interlace",
+       "dblscan",
+       "csync",
+       "pcsync",
+       "ncsync",
+       "hskew",
+       "bcast",
+       "pixmux",
+       "dblclk",
+       "clkdiv2"
+};
+
+bit_name_fn(mode_flag)
+
 void dump_encoders(void)
 {
        drmModeEncoder *encoder;
@@ -146,7 +189,7 @@ void dump_encoders(void)
 
 void dump_mode(drmModeModeInfo *mode)
 {
-       printf("\t%s %d %d %d %d %d %d %d %d %d\n",
+       printf("  %s %d %d %d %d %d %d %d %d %d",
               mode->name,
               mode->vrefresh,
               mode->hdisplay,
@@ -157,6 +200,12 @@ void dump_mode(drmModeModeInfo *mode)
               mode->vsync_start,
               mode->vsync_end,
               mode->vtotal);
+
+       printf(" flags: ");
+       mode_flag_str(mode->flags);
+       printf("; type: ");
+       mode_type_str(mode->type);
+       printf("\n");
 }
 
 static void