Skip to contentSkip to conversation

tests/util: Reindent using editorconfig settings

PATCH In review Thierry Reding 2 participants 6 messages Jan 30, 2017 – Feb 1, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 tests/util: Reindent using editorconfig settings

From: Thierry Reding <[email protected]>

Apply editorconfig settings to the tests/util library code in order to facilitate making subsequent changes.

---
 tests/util/format.c  |  128 ++---
 tests/util/format.h  |   36 +-
 tests/util/kms.c     |  186 +++----
 tests/util/pattern.c | 1446 +++++++++++++++++++++++++-------------------------
 tests/util/pattern.h |   10 +-
 5 files changed, 899 insertions(+), 907 deletions(-)
tests/util/format.c +64 -64
index 043cfe7f1eaf..b1055cfc8bbd 100644
@@ -37,84 +37,84 @@
 #include "format.h"
 
 #define MAKE_RGB_INFO(rl, ro, gl, go, bl, bo, al, ao) \
-	.rgb = { { (rl), (ro) }, { (gl), (go) }, { (bl), (bo) }, { (al), (ao) } }
+    .rgb = { { (rl), (ro) }, { (gl), (go) }, { (bl), (bo) }, { (al), (ao) } }
 
 #define MAKE_YUV_INFO(order, xsub, ysub, chroma_stride) \
-	.yuv = { (order), (xsub), (ysub), (chroma_stride) }
+    .yuv = { (order), (xsub), (ysub), (chroma_stride) }
 
 static const struct util_format_info format_info[] = {
-	/* YUV packed */
-	{ DRM_FORMAT_UYVY, "UYVY", MAKE_YUV_INFO(YUV_YCbCr | YUV_CY, 2, 2, 2) },
-	{ DRM_FORMAT_VYUY, "VYUY", MAKE_YUV_INFO(YUV_YCrCb | YUV_CY, 2, 2, 2) },
-	{ DRM_FORMAT_YUYV, "YUYV", MAKE_YUV_INFO(YUV_YCbCr | YUV_YC, 2, 2, 2) },
-	{ DRM_FORMAT_YVYU, "YVYU", MAKE_YUV_INFO(YUV_YCrCb | YUV_YC, 2, 2, 2) },
-	/* YUV semi-planar */
-	{ DRM_FORMAT_NV12, "NV12", MAKE_YUV_INFO(YUV_YCbCr, 2, 2, 2) },
-	{ DRM_FORMAT_NV21, "NV21", MAKE_YUV_INFO(YUV_YCrCb, 2, 2, 2) },
-	{ DRM_FORMAT_NV16, "NV16", MAKE_YUV_INFO(YUV_YCbCr, 2, 1, 2) },
-	{ DRM_FORMAT_NV61, "NV61", MAKE_YUV_INFO(YUV_YCrCb, 2, 1, 2) },
-	/* YUV planar */
-	{ DRM_FORMAT_YUV420, "YU12", MAKE_YUV_INFO(YUV_YCbCr, 2, 2, 1) },
-	{ DRM_FORMAT_YVU420, "YV12", MAKE_YUV_INFO(YUV_YCrCb, 2, 2, 1) },
-	/* RGB16 */
-	{ DRM_FORMAT_ARGB4444, "AR12", MAKE_RGB_INFO(4, 8, 4, 4, 4, 0, 4, 12) },
-	{ DRM_FORMAT_XRGB4444, "XR12", MAKE_RGB_INFO(4, 8, 4, 4, 4, 0, 0, 0) },
-	{ DRM_FORMAT_ABGR4444, "AB12", MAKE_RGB_INFO(4, 0, 4, 4, 4, 8, 4, 12) },
-	{ DRM_FORMAT_XBGR4444, "XB12", MAKE_RGB_INFO(4, 0, 4, 4, 4, 8, 0, 0) },
-	{ DRM_FORMAT_RGBA4444, "RA12", MAKE_RGB_INFO(4, 12, 4, 8, 4, 4, 4, 0) },
-	{ DRM_FORMAT_RGBX4444, "RX12", MAKE_RGB_INFO(4, 12, 4, 8, 4, 4, 0, 0) },
-	{ DRM_FORMAT_BGRA4444, "BA12", MAKE_RGB_INFO(4, 4, 4, 8, 4, 12, 4, 0) },
-	{ DRM_FORMAT_BGRX4444, "BX12", MAKE_RGB_INFO(4, 4, 4, 8, 4, 12, 0, 0) },
-	{ DRM_FORMAT_ARGB1555, "AR15", MAKE_RGB_INFO(5, 10, 5, 5, 5, 0, 1, 15) },
-	{ DRM_FORMAT_XRGB1555, "XR15", MAKE_RGB_INFO(5, 10, 5, 5, 5, 0, 0, 0) },
-	{ DRM_FORMAT_ABGR1555, "AB15", MAKE_RGB_INFO(5, 0, 5, 5, 5, 10, 1, 15) },
-	{ DRM_FORMAT_XBGR1555, "XB15", MAKE_RGB_INFO(5, 0, 5, 5, 5, 10, 0, 0) },
-	{ DRM_FORMAT_RGBA5551, "RA15", MAKE_RGB_INFO(5, 11, 5, 6, 5, 1, 1, 0) },
-	{ DRM_FORMAT_RGBX5551, "RX15", MAKE_RGB_INFO(5, 11, 5, 6, 5, 1, 0, 0) },
-	{ DRM_FORMAT_BGRA5551, "BA15", MAKE_RGB_INFO(5, 1, 5, 6, 5, 11, 1, 0) },
-	{ DRM_FORMAT_BGRX5551, "BX15", MAKE_RGB_INFO(5, 1, 5, 6, 5, 11, 0, 0) },
-	{ DRM_FORMAT_RGB565, "RG16", MAKE_RGB_INFO(5, 11, 6, 5, 5, 0, 0, 0) },
-	{ DRM_FORMAT_BGR565, "BG16", MAKE_RGB_INFO(5, 0, 6, 5, 5, 11, 0, 0) },
-	/* RGB24 */
-	{ DRM_FORMAT_BGR888, "BG24", MAKE_RGB_INFO(8, 0, 8, 8, 8, 16, 0, 0) },
-	{ DRM_FORMAT_RGB888, "RG24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 0, 0) },
-	/* RGB32 */
-	{ DRM_FORMAT_ARGB8888, "AR24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 8, 24) },
-	{ DRM_FORMAT_XRGB8888, "XR24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 0, 0) },
-	{ DRM_FORMAT_ABGR8888, "AB24", MAKE_RGB_INFO(8, 0, 8, 8, 8, 16, 8, 24) },
-	{ DRM_FORMAT_XBGR8888, "XB24", MAKE_RGB_INFO(8, 0, 8, 8, 8, 16, 0, 0) },
-	{ DRM_FORMAT_RGBA8888, "RA24", MAKE_RGB_INFO(8, 24, 8, 16, 8, 8, 8, 0) },
-	{ DRM_FORMAT_RGBX8888, "RX24", MAKE_RGB_INFO(8, 24, 8, 16, 8, 8, 0, 0) },
-	{ DRM_FORMAT_BGRA8888, "BA24", MAKE_RGB_INFO(8, 8, 8, 16, 8, 24, 8, 0) },
-	{ DRM_FORMAT_BGRX8888, "BX24", MAKE_RGB_INFO(8, 8, 8, 16, 8, 24, 0, 0) },
-	{ DRM_FORMAT_ARGB2101010, "AR30", MAKE_RGB_INFO(10, 20, 10, 10, 10, 0, 2, 30) },
-	{ DRM_FORMAT_XRGB2101010, "XR30", MAKE_RGB_INFO(10, 20, 10, 10, 10, 0, 0, 0) },
-	{ DRM_FORMAT_ABGR2101010, "AB30", MAKE_RGB_INFO(10, 0, 10, 10, 10, 20, 2, 30) },
-	{ DRM_FORMAT_XBGR2101010, "XB30", MAKE_RGB_INFO(10, 0, 10, 10, 10, 20, 0, 0) },
-	{ DRM_FORMAT_RGBA1010102, "RA30", MAKE_RGB_INFO(10, 22, 10, 12, 10, 2, 2, 0) },
-	{ DRM_FORMAT_RGBX1010102, "RX30", MAKE_RGB_INFO(10, 22, 10, 12, 10, 2, 0, 0) },
-	{ DRM_FORMAT_BGRA1010102, "BA30", MAKE_RGB_INFO(10, 2, 10, 12, 10, 22, 2, 0) },
-	{ DRM_FORMAT_BGRX1010102, "BX30", MAKE_RGB_INFO(10, 2, 10, 12, 10, 22, 0, 0) },
+    /* YUV packed */
+    { DRM_FORMAT_UYVY, "UYVY", MAKE_YUV_INFO(YUV_YCbCr | YUV_CY, 2, 2, 2) },
+    { DRM_FORMAT_VYUY, "VYUY", MAKE_YUV_INFO(YUV_YCrCb | YUV_CY, 2, 2, 2) },
+    { DRM_FORMAT_YUYV, "YUYV", MAKE_YUV_INFO(YUV_YCbCr | YUV_YC, 2, 2, 2) },
+    { DRM_FORMAT_YVYU, "YVYU", MAKE_YUV_INFO(YUV_YCrCb | YUV_YC, 2, 2, 2) },
+    /* YUV semi-planar */
+    { DRM_FORMAT_NV12, "NV12", MAKE_YUV_INFO(YUV_YCbCr, 2, 2, 2) },
+    { DRM_FORMAT_NV21, "NV21", MAKE_YUV_INFO(YUV_YCrCb, 2, 2, 2) },
+    { DRM_FORMAT_NV16, "NV16", MAKE_YUV_INFO(YUV_YCbCr, 2, 1, 2) },
+    { DRM_FORMAT_NV61, "NV61", MAKE_YUV_INFO(YUV_YCrCb, 2, 1, 2) },
+    /* YUV planar */
+    { DRM_FORMAT_YUV420, "YU12", MAKE_YUV_INFO(YUV_YCbCr, 2, 2, 1) },
+    { DRM_FORMAT_YVU420, "YV12", MAKE_YUV_INFO(YUV_YCrCb, 2, 2, 1) },
+    /* RGB16 */
+    { DRM_FORMAT_ARGB4444, "AR12", MAKE_RGB_INFO(4, 8, 4, 4, 4, 0, 4, 12) },
+    { DRM_FORMAT_XRGB4444, "XR12", MAKE_RGB_INFO(4, 8, 4, 4, 4, 0, 0, 0) },
+    { DRM_FORMAT_ABGR4444, "AB12", MAKE_RGB_INFO(4, 0, 4, 4, 4, 8, 4, 12) },
+    { DRM_FORMAT_XBGR4444, "XB12", MAKE_RGB_INFO(4, 0, 4, 4, 4, 8, 0, 0) },
+    { DRM_FORMAT_RGBA4444, "RA12", MAKE_RGB_INFO(4, 12, 4, 8, 4, 4, 4, 0) },
+    { DRM_FORMAT_RGBX4444, "RX12", MAKE_RGB_INFO(4, 12, 4, 8, 4, 4, 0, 0) },
+    { DRM_FORMAT_BGRA4444, "BA12", MAKE_RGB_INFO(4, 4, 4, 8, 4, 12, 4, 0) },
+    { DRM_FORMAT_BGRX4444, "BX12", MAKE_RGB_INFO(4, 4, 4, 8, 4, 12, 0, 0) },
+    { DRM_FORMAT_ARGB1555, "AR15", MAKE_RGB_INFO(5, 10, 5, 5, 5, 0, 1, 15) },
+    { DRM_FORMAT_XRGB1555, "XR15", MAKE_RGB_INFO(5, 10, 5, 5, 5, 0, 0, 0) },
+    { DRM_FORMAT_ABGR1555, "AB15", MAKE_RGB_INFO(5, 0, 5, 5, 5, 10, 1, 15) },
+    { DRM_FORMAT_XBGR1555, "XB15", MAKE_RGB_INFO(5, 0, 5, 5, 5, 10, 0, 0) },
+    { DRM_FORMAT_RGBA5551, "RA15", MAKE_RGB_INFO(5, 11, 5, 6, 5, 1, 1, 0) },
+    { DRM_FORMAT_RGBX5551, "RX15", MAKE_RGB_INFO(5, 11, 5, 6, 5, 1, 0, 0) },
+    { DRM_FORMAT_BGRA5551, "BA15", MAKE_RGB_INFO(5, 1, 5, 6, 5, 11, 1, 0) },
+    { DRM_FORMAT_BGRX5551, "BX15", MAKE_RGB_INFO(5, 1, 5, 6, 5, 11, 0, 0) },
+    { DRM_FORMAT_RGB565, "RG16", MAKE_RGB_INFO(5, 11, 6, 5, 5, 0, 0, 0) },
+    { DRM_FORMAT_BGR565, "BG16", MAKE_RGB_INFO(5, 0, 6, 5, 5, 11, 0, 0) },
+    /* RGB24 */
+    { DRM_FORMAT_BGR888, "BG24", MAKE_RGB_INFO(8, 0, 8, 8, 8, 16, 0, 0) },
+    { DRM_FORMAT_RGB888, "RG24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 0, 0) },
+    /* RGB32 */
+    { DRM_FORMAT_ARGB8888, "AR24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 8, 24) },
+    { DRM_FORMAT_XRGB8888, "XR24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 0, 0) },
+    { DRM_FORMAT_ABGR8888, "AB24", MAKE_RGB_INFO(8, 0, 8, 8, 8, 16, 8, 24) },
+    { DRM_FORMAT_XBGR8888, "XB24", MAKE_RGB_INFO(8, 0, 8, 8, 8, 16, 0, 0) },
+    { DRM_FORMAT_RGBA8888, "RA24", MAKE_RGB_INFO(8, 24, 8, 16, 8, 8, 8, 0) },
+    { DRM_FORMAT_RGBX8888, "RX24", MAKE_RGB_INFO(8, 24, 8, 16, 8, 8, 0, 0) },
+    { DRM_FORMAT_BGRA8888, "BA24", MAKE_RGB_INFO(8, 8, 8, 16, 8, 24, 8, 0) },
+    { DRM_FORMAT_BGRX8888, "BX24", MAKE_RGB_INFO(8, 8, 8, 16, 8, 24, 0, 0) },
+    { DRM_FORMAT_ARGB2101010, "AR30", MAKE_RGB_INFO(10, 20, 10, 10, 10, 0, 2, 30) },
+    { DRM_FORMAT_XRGB2101010, "XR30", MAKE_RGB_INFO(10, 20, 10, 10, 10, 0, 0, 0) },
+    { DRM_FORMAT_ABGR2101010, "AB30", MAKE_RGB_INFO(10, 0, 10, 10, 10, 20, 2, 30) },
+    { DRM_FORMAT_XBGR2101010, "XB30", MAKE_RGB_INFO(10, 0, 10, 10, 10, 20, 0, 0) },
+    { DRM_FORMAT_RGBA1010102, "RA30", MAKE_RGB_INFO(10, 22, 10, 12, 10, 2, 2, 0) },
+    { DRM_FORMAT_RGBX1010102, "RX30", MAKE_RGB_INFO(10, 22, 10, 12, 10, 2, 0, 0) },
+    { DRM_FORMAT_BGRA1010102, "BA30", MAKE_RGB_INFO(10, 2, 10, 12, 10, 22, 2, 0) },
+    { DRM_FORMAT_BGRX1010102, "BX30", MAKE_RGB_INFO(10, 2, 10, 12, 10, 22, 0, 0) },
 };
 
 uint32_t util_format_fourcc(const char *name)
 {
-	unsigned int i;
+    unsigned int i;
 
-	for (i = 0; i < ARRAY_SIZE(format_info); i++)
-		if (!strcmp(format_info[i].name, name))
-			return format_info[i].format;
+    for (i = 0; i < ARRAY_SIZE(format_info); i++)
+        if (!strcmp(format_info[i].name, name))
+            return format_info[i].format;
 
-	return 0;
+    return 0;
 }
 
 const struct util_format_info *util_format_info_find(uint32_t format)
 {
-	unsigned int i;
+    unsigned int i;
 
-	for (i = 0; i < ARRAY_SIZE(format_info); i++)
-		if (format_info[i].format == format)
-			return &format_info[i];
+    for (i = 0; i < ARRAY_SIZE(format_info); i++)
+        if (format_info[i].format == format)
+            return &format_info[i];
 
-	return NULL;
+    return NULL;
 }
tests/util/format.h +18 -18
index 2ce1c021fd78..3e3cd5469958 100644
@@ -27,36 +27,36 @@
 #define UTIL_FORMAT_H
 
 struct util_color_component {
-	unsigned int length;
-	unsigned int offset;
+    unsigned int length;
+    unsigned int offset;
 };
 
 struct util_rgb_info {
-	struct util_color_component red;
-	struct util_color_component green;
-	struct util_color_component blue;
-	struct util_color_component alpha;
+    struct util_color_component red;
+    struct util_color_component green;
+    struct util_color_component blue;
+    struct util_color_component alpha;
 };
 
 enum util_yuv_order {
-	YUV_YCbCr = 1,
-	YUV_YCrCb = 2,
-	YUV_YC = 4,
-	YUV_CY = 8,
+    YUV_YCbCr = 1,
+    YUV_YCrCb = 2,
+    YUV_YC = 4,
+    YUV_CY = 8,
 };
 
 struct util_yuv_info {
-	enum util_yuv_order order;
-	unsigned int xsub;
-	unsigned int ysub;
-	unsigned int chroma_stride;
+    enum util_yuv_order order;
+    unsigned int xsub;
+    unsigned int ysub;
+    unsigned int chroma_stride;
 };
 
 struct util_format_info {
-	uint32_t format;
-	const char *name;
-	const struct util_rgb_info rgb;
-	const struct util_yuv_info yuv;
+    uint32_t format;
+    const char *name;
+    const struct util_rgb_info rgb;
+    const struct util_yuv_info yuv;
 };
 
 uint32_t util_format_fourcc(const char *name);
tests/util/kms.c +93 -93

224 lines not on this page · raw message

tests/util/pattern.c +719 -727

1,536 lines not on this page · raw message

tests/util/pattern.h +5 -5
index d5c4260cc6ed..80fade3856de 100644
@@ -27,13 +27,13 @@
 #define UTIL_PATTERN_H
 
 enum util_fill_pattern {
-	UTIL_PATTERN_TILES,
-	UTIL_PATTERN_PLAIN,
-	UTIL_PATTERN_SMPTE,
+    UTIL_PATTERN_TILES,
+    UTIL_PATTERN_PLAIN,
+    UTIL_PATTERN_SMPTE,
 };
 
 void util_fill_pattern(uint32_t format, enum util_fill_pattern pattern,
-		       void *planes[3], unsigned int width,
-		       unsigned int height, unsigned int stride);
+                       void *planes[3], unsigned int width,
+                       unsigned int height, unsigned int stride);
 
 #endif /* UTIL_PATTERN_H */
Signature · 6 lines
2.11.0

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

PATCH 2/3 tests/util: Make util_open() use drmDevice

From: Thierry Reding <[email protected]>

The util_open() helper is used in a couple of test programs to open an appropriate device. It takes a device path and a module name, both are optional, as parameters. If a device path is specified, it will try to open the given device. Otherwise it will try all available devices. If only a specific subset is desired, the module parameter can be used as a filter. The function will use it to open only devices whose kernel driver matches the given module name.

Instead of relying on the legacy drmOpen() function to do this, convert util_open() to use the new drmDevice helpers. This gets it functionally much closer to what other DRM/KMS users, such as the X.Org Server or a Wayland server, do.

---
 tests/util/kms.c | 167 +++++++++++++++++++++++++++++++++++++++++--------------
 tests/util/kms.h |  43 ++++++++++++++
 2 files changed, 168 insertions(+), 42 deletions(-)
tests/util/kms.c +125 -42
index d866398237bb..c5d35ab616d1 100644
@@ -42,15 +42,18 @@
 #endif
 
 #include <errno.h>
+#include <fcntl.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 
 #include "xf86drm.h"
 #include "xf86drmMode.h"
 
 #include "common.h"
+#include "kms.h"
 
 struct type_name {
     unsigned int type;
@@ -125,58 +128,138 @@ const char *util_lookup_connector_type_name(unsigned int type)
                                  ARRAY_SIZE(connector_type_names));
 }
 
-static const char * const modules[] = {
-    "i915",
-    "amdgpu",
-    "radeon",
-    "nouveau",
-    "vmwgfx",
-    "omapdrm",
-    "exynos",
-    "tilcdc",
-    "msm",
-    "sti",
-    "tegra",
-    "imx-drm",
-    "rockchip",
-    "atmel-hlcdc",
-    "fsl-dcu-drm",
-    "vc4",
-    "virtio_gpu",
-    "mediatek",
-    "meson",
-};
+char *util_get_driver(int fd)
+{
+    drmVersionPtr version;
+    char *driver;
 
-int util_open(const char *device, const char *module)
+    version = drmGetVersion(fd);
+    if (!version)
+        return NULL;
+
+    driver = strdup(version->name);
+
+    drmFreeVersion(version);
+
+    return driver;
+}
+
+int util_get_devices(drmDevicePtr **devicesp, uint32_t flags)
+{
+    drmDevicePtr *devices;
+    unsigned int count;
+    int err;
+
+    err = drmGetDevices2(flags, NULL, 0);
+    if (err < 0)
+        return err;
+
+    /*
+     * If the caller hasn't specified a return pointer for the new devices
+     * array, all of the below is pointless, so simply return the number of
+     * devices available.
+     */
+    if (!devicesp)
+        return err;
+
+    count = err;
+
+    devices = calloc(count, sizeof(*devices));
+    if (!devices)
+        return -ENOMEM;
+
+    err = drmGetDevices2(flags, devices, count);
+    if (err < 0) {
+        free(devices);
+        return err;
+    }
+
+    if (devicesp)
+        *devicesp = devices;
+    else
+        free(devices);
+
+    return count;
+}
+
+void util_free_devices(drmDevicePtr *devices, unsigned int count)
+{
+    drmFreeDevices(devices, count);
+    free(devices);
+}
+
+int util_open_with_module(const char *device, const char *module)
 {
-    int fd;
+    int fd, err = 0;
+
+    if (module)
+        printf("trying to open `%s' with `%s'...", device, module);
+    else
+        printf("trying to open `%s'...", device);
+
+    fd = open(device, O_RDWR);
+    if (fd < 0) {
+        err = -errno;
+        goto out;
+    }
 
     if (module) {
-        fd = drmOpen(module, device);
-        if (fd < 0) {
-            fprintf(stderr, "failed to open device '%s': %s\n",
-                module, strerror(errno));
-            return -errno;
+        char *driver = util_get_driver(fd);
+        if (!driver) {
+            err = -EINVAL;
+            goto close;
         }
-    } else {
-        unsigned int i;
 
-        for (i = 0; i < ARRAY_SIZE(modules); i++) {
-            printf("trying to open device '%s'...", modules[i]);
+        if (strcmp(module, driver) != 0)
+            err = -EINVAL;
+
+        free(driver);
+
+        if (err < 0)
+            goto close;
+    }
+
+    printf("done\n");
+    return fd;
+
+close:
+    close(fd);
+out:
+    printf("failed\n");
+    return err;
+}
 
-            fd = drmOpen(modules[i], device);
-            if (fd < 0) {
-                printf("failed\n");
-            } else {
-                printf("done\n");
+int util_open(const char *device, const char *module)
+{
+    int fd, err;
+
+    if (!device) {
+        drmDevicePtr *devices, dev;
+        unsigned int count, i, j;
+        const char *node;
+
+        err = util_get_devices(&devices, 0);
+        if (err < 0)
+            return err;
+
+        count = err;
+
+        util_for_each_device(dev, i, devices, count) {
+            node = util_device_get_node(dev, DRM_NODE_PRIMARY);
+            if (!node)
+                continue;
+
+            fd = util_open_with_module(node, module);
+            if (fd >= 0)
                 break;
-            }
         }
 
-        if (fd < 0) {
-            fprintf(stderr, "no device found\n");
-            return -ENODEV;
-        }
+        util_free_devices(devices, count);
+
+        if (i == count)
+            fd = -ENOENT;
+    } else {
+        fd = util_open_with_module(device, module);
     }
 
     return fd;
tests/util/kms.h +43 -0

49 lines not on this page · raw message

Signature · 6 lines
2.11.0

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

PATCH 3/3 tests/util: Add some API documentation

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

None of the helpers currently have any documentation. Add some to make it more obvious how these should be used.

---
 tests/util/kms.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
tests/util/kms.c +51 -0
index c5d35ab616d1..226386519d49 100644
@@ -128,6 +128,13 @@ const char *util_lookup_connector_type_name(unsigned int type)
                                  ARRAY_SIZE(connector_type_names));
 }
 
+/**
+ * Retrieve the name of the kernel driver for a DRM device.
+ *
+ * \param fd the file descriptor of the DRM device
+ *
+ * \return On success, returns the name of the kernel driver.
+ */
 char *util_get_driver(int fd)
 {
     drmVersionPtr version;
@@ -144,6 +151,16 @@ char *util_get_driver(int fd)
     return driver;
 }
 
+/**
+ * Retrieve a list of available DRM devices.
+ *
+ * \param devicesp return location for the list of DRM devices
+ * \param flags bitmask of flags controlling operation
+ *
+ * \return On success, returns the number of devices found. The list of DRM
+ * devices is dynamically allocated and needs to be freed by a call to the
+ * util_free_devices() function.
+ */
 int util_get_devices(drmDevicePtr **devicesp, uint32_t flags)
 {
     drmDevicePtr *devices;
@@ -182,12 +199,32 @@ int util_get_devices(drmDevicePtr **devicesp, uint32_t flags)
     return count;
 }
 
+/**
+ * Free a list of DRM devices.
+ *
+ * \param devices a list of DRM devices, allocated by util_get_devices()
+ * \param count the number of DRM devices in \p devices
+ */
 void util_free_devices(drmDevicePtr *devices, unsigned int count)
 {
     drmFreeDevices(devices, count);
     free(devices);
 }
 
+/**
+ * Opens a DRM device, optionally checking against its kernel driver.
+ *
+ * \param device path to DRM device
+ * \param module optional name of kernel driver
+ *
+ * \return On success, a file descriptor to \p device, or a negative error
+ * code on failure.
+ *
+ * If the caller doesn't care about the kernel driver associated with the DRM
+ * device, then the \p module parameter can be NULL. If \p module is not NULL
+ * this function will retrieve the name of the kernel driver and compare it
+ * to the \p module parameter. If the names don't match, the call will fail.
+ */
 int util_open_with_module(const char *device, const char *module)
 {
     int fd, err = 0;
@@ -229,6 +266,20 @@ out:
     return err;
 }
 
+/**
+ * Opens a DRM device, optionally checking against its kernel driver.
+ *
+ * \param device
+ * \param module
+ *
+ * \return On success, a file descriptor to \p device, or a negative error
+ * code on failure.
+ *
+ * This is similar to util_open_with_module(), except that \p device can be
+ * NULL, in which case all available devices will be tried. If \p module is
+ * specified it will act as a filter. Otherwise the first available device
+ * that can be opened will be used.
+ */
 int util_open(const char *device, const char *module)
 {
     int fd, err;
Signature · 6 lines
2.11.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#5 lore raw
In reply to Thierry Reding
Quoted 5 lines · Thierry Reding

From: Thierry Reding <[email protected]>

Apply editorconfig settings to the tests/util library code in order to facilitate making subsequent changes.

Quoted 8 lines
---
 tests/util/format.c  |  128 ++---
 tests/util/format.h  |   36 +-
 tests/util/kms.c     |  186 +++----
 tests/util/pattern.c | 1446 +++++++++++++++++++++++++-------------------------
 tests/util/pattern.h |   10 +-
 5 files changed, 899 insertions(+), 907 deletions(-)

This is obviously a lot of churn, but for reference, here's the diff ignoring all whitespace changes (--ignore-all-space):

--- >8 ---
commit f920fb0b72ddd12f18c42ddd96114213868331e3

Author: Thierry Reding <[email protected]>
Date:   Fri Jan 27 11:36:10 2017 +0100

tests/util: Reindent using editorconfig settings

Apply editorconfig settings to the tests/util library code in order to facilitate making subsequent changes.

tests/util/pattern.c +20 -28
index 00b08a8cb8eb..5d653afbee24 100644
@@ -472,8 +472,8 @@ static void fill_smpte(const struct util_format_info *info, void *planes[3],
     case DRM_FORMAT_VYUY:
     case DRM_FORMAT_YUYV:
     case DRM_FORMAT_YVYU:
-		return fill_smpte_yuv_packed(&info->yuv, planes[0], width,
-					     height, stride);
+        return fill_smpte_yuv_packed(&info->yuv, planes[0], width, height,
+                                     stride);
 
     case DRM_FORMAT_NV12:
     case DRM_FORMAT_NV21:
@@ -481,8 +481,8 @@ static void fill_smpte(const struct util_format_info *info, void *planes[3],
     case DRM_FORMAT_NV61:
         u = info->yuv.order & YUV_YCbCr ? planes[1] : planes[1] + 1;
         v = info->yuv.order & YUV_YCrCb ? planes[1] : planes[1] + 1;
-		return fill_smpte_yuv_planar(&info->yuv, planes[0], u, v,
-					     width, height, stride);
+        return fill_smpte_yuv_planar(&info->yuv, planes[0], u, v, width,
+                                     height, stride);
 
     case DRM_FORMAT_YUV420:
         return fill_smpte_yuv_planar(&info->yuv, planes[0], planes[1],
@@ -510,13 +510,12 @@ static void fill_smpte(const struct util_format_info *info, void *planes[3],
     case DRM_FORMAT_RGBX5551:
     case DRM_FORMAT_BGRA5551:
     case DRM_FORMAT_BGRX5551:
-		return fill_smpte_rgb16(&info->rgb, planes[0],
-					width, height, stride);
+        return fill_smpte_rgb16(&info->rgb, planes[0], width, height, stride);
 
     case DRM_FORMAT_BGR888:
     case DRM_FORMAT_RGB888:
-		return fill_smpte_rgb24(&info->rgb, planes[0],
-					width, height, stride);
+        return fill_smpte_rgb24(&info->rgb, planes[0], width, height, stride);
+
     case DRM_FORMAT_ARGB8888:
     case DRM_FORMAT_XRGB8888:
     case DRM_FORMAT_ABGR8888:
@@ -533,8 +532,7 @@ static void fill_smpte(const struct util_format_info *info, void *planes[3],
     case DRM_FORMAT_RGBX1010102:
     case DRM_FORMAT_BGRA1010102:
     case DRM_FORMAT_BGRX1010102:
-		return fill_smpte_rgb32(&info->rgb, planes[0],
-					width, height, stride);
+        return fill_smpte_rgb32(&info->rgb, planes[0], width, height, stride);
     }
 }
 
@@ -568,10 +566,8 @@ static void make_pwetty(void *data, unsigned int width, unsigned int height,
         return;
     }
 
-	surface = cairo_image_surface_create_for_data(data,
-						      cairo_format,
-						      width, height,
-						      stride);
+    surface = cairo_image_surface_create_for_data(data, cairo_format, width,
+                                                  height, stride);
     cr = cairo_create(surface);
     cairo_surface_destroy(surface);
 
@@ -758,8 +754,7 @@ static void fill_tiles(const struct util_format_info *info, void *planes[3],
     case DRM_FORMAT_VYUY:
     case DRM_FORMAT_YUYV:
     case DRM_FORMAT_YVYU:
-		return fill_tiles_yuv_packed(info, planes[0],
-					     width, height, stride);
+        return fill_tiles_yuv_packed(info, planes[0], width, height, stride);
 
     case DRM_FORMAT_NV12:
     case DRM_FORMAT_NV21:
@@ -767,16 +762,16 @@ static void fill_tiles(const struct util_format_info *info, void *planes[3],
     case DRM_FORMAT_NV61:
         u = info->yuv.order & YUV_YCbCr ? planes[1] : planes[1] + 1;
         v = info->yuv.order & YUV_YCrCb ? planes[1] : planes[1] + 1;
-		return fill_tiles_yuv_planar(info, planes[0], u, v,
-					     width, height, stride);
+        return fill_tiles_yuv_planar(info, planes[0], u, v, width, height,
+                                     stride);
 
     case DRM_FORMAT_YUV420:
-		return fill_tiles_yuv_planar(info, planes[0], planes[1],
-					     planes[2], width, height, stride);
+        return fill_tiles_yuv_planar(info, planes[0], planes[1], planes[2],
+                                     width, height, stride);
 
     case DRM_FORMAT_YVU420:
-		return fill_tiles_yuv_planar(info, planes[0], planes[2],
-					     planes[1], width, height, stride);
+        return fill_tiles_yuv_planar(info, planes[0], planes[2], planes[1],
+                                     width, height, stride);
 
     case DRM_FORMAT_ARGB4444:
     case DRM_FORMAT_XRGB4444:
@@ -796,13 +791,11 @@ static void fill_tiles(const struct util_format_info *info, void *planes[3],
     case DRM_FORMAT_RGBX5551:
     case DRM_FORMAT_BGRA5551:
     case DRM_FORMAT_BGRX5551:
-		return fill_tiles_rgb16(info, planes[0],
-					width, height, stride);
+        return fill_tiles_rgb16(info, planes[0], width, height, stride);
 
     case DRM_FORMAT_BGR888:
     case DRM_FORMAT_RGB888:
-		return fill_tiles_rgb24(info, planes[0],
-					width, height, stride);
+        return fill_tiles_rgb24(info, planes[0], width, height, stride);
     case DRM_FORMAT_ARGB8888:
     case DRM_FORMAT_XRGB8888:
     case DRM_FORMAT_ABGR8888:
@@ -819,8 +812,7 @@ static void fill_tiles(const struct util_format_info *info, void *planes[3],
     case DRM_FORMAT_RGBX1010102:
     case DRM_FORMAT_BGRA1010102:
     case DRM_FORMAT_BGRX1010102:
-		return fill_tiles_rgb32(info, planes[0],
-					width, height, stride);
+        return fill_tiles_rgb32(info, planes[0], width, height, stride);
     }
 }
 

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Reviewed-by on v1 2/3
#2 lore raw

Re: [PATCH libdrm 2/3] tests/util: Make util_open() use drmDevice

In reply to Thierry Reding
Quoted 25 lines · Thierry Reding

From: Thierry Reding <[email protected]>

The util_open() helper is used in a couple of test programs to open an appropriate device. It takes a device path and a module name, both are optional, as parameters. If a device path is specified, it will try to open the given device. Otherwise it will try all available devices. If only a specific subset is desired, the module parameter can be used as a filter. The function will use it to open only devices whose kernel driver matches the given module name.

Instead of relying on the legacy drmOpen() function to do this, convert util_open() to use the new drmDevice helpers. This gets it functionally much closer to what other DRM/KMS users, such as the X.Org Server or a Wayland server, do.

---
 tests/util/kms.c | 167 +++++++++++++++++++++++++++++++++++++++++--------------
 tests/util/kms.h |  43 ++++++++++++++
 2 files changed, 168 insertions(+), 42 deletions(-)
tests/util/kms.c +0 -0
index d866398237bb..c5d35ab616d1 100644

tests/util/kms.c const char *util_lookup_connector_type_name(unsigned int type) · line 147

Quoted 2 lines
tests/util/kms.c +1 -0
 
+int util_get_devices(drmDevicePtr **devicesp, uint32_t flags)

Personally I would not have bothered with this helper, but it's nice to have ;-)

tests/util/kms.c const char *util_lookup_connector_type_name(unsigned int type)

Quoted 8 lines
tests/util/kms.c +6 -0
+{
 
+    if (!devicesp)
+        return err;
+
 
+
+    if (devicesp)

With the "if !devicesp" check above this should always be true, no ?

Quoted 1 line

+int util_open_with_module(const char *device, const char *module)

Name and thus distinction vs util_open is blurred - here we require non-null device... which we should check for.
Sadly I'm out of ideas for better name(s) :-(

tests/util/kms.c const char *util_lookup_connector_type_name(unsigned int type) · line 200

Quoted 10 lines

{

tests/util/kms.c +8 -1
-    int fd;
+    int fd, err = 0;
+
+    if (module)
+        printf("trying to open `%s' with `%s'...", device, module);
+    else
+        printf("trying to open `%s'...", device);
+
+    fd = open(device, O_RDWR);

Not sure how much we should care here, but O_CLOEXEC would be nice.

tests/util/kms.c const char *util_lookup_connector_type_name(unsigned int type) · line 262

Quoted 6 lines
tests/util/kms.c +4 -0
+int util_open(const char *device, const char *module)
+{
 
 
+    } else {
+        fd = util_open_with_module(device, module);

Nit: one can drop a level of indentation/brackets - I have no strong preference either way.

int util_open(...)
{
if (device)

      return util_open_with_module(device, module);

...
get_devices
...
}

tests/util/kms.h const char *util_lookup_encoder_type_name(unsigned int type); · line 58

Quoted 10 lines
tests/util/kms.h +7 -0
 
+
+static inline char *util_device_get_node(drmDevicePtr device,
+                                         unsigned int type)
+{
+    if (type >= DRM_NODE_MAX)
+        return NULL;
+

IMHO it's better to honour the ::available_nodes bitmask here, since we already check if we're within range.

This the above the series is

-Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw

Re: [PATCH libdrm 2/3] tests/util: Make util_open() use drmDevice

Quoted 22 lines · Emil Velikov
Quoted 21 lines · Thierry Reding

From: Thierry Reding <[email protected]>

The util_open() helper is used in a couple of test programs to open an appropriate device. It takes a device path and a module name, both are optional, as parameters. If a device path is specified, it will try to open the given device. Otherwise it will try all available devices. If only a specific subset is desired, the module parameter can be used as a filter. The function will use it to open only devices whose kernel driver matches the given module name.

Instead of relying on the legacy drmOpen() function to do this, convert util_open() to use the new drmDevice helpers. This gets it functionally much closer to what other DRM/KMS users, such as the X.Org Server or a Wayland server, do.

---
 tests/util/kms.c | 167 +++++++++++++++++++++++++++++++++++++++++--------------
 tests/util/kms.h |  43 ++++++++++++++
 2 files changed, 168 insertions(+), 42 deletions(-)
Quoted 7 lines

tests/util/kms.c const char *util_lookup_connector_type_name(unsigned int type) · line 147

Quoted 6 lines
tests/util/kms.c +1 -0
index d866398237bb..c5d35ab616d1 100644
 
+int util_get_devices(drmDevicePtr **devicesp, uint32_t flags)

Personally I would not have bothered with this helper, but it's nice to have ;-)

Yeah, I added this after realizing that I was typing the same code sequence for the second time.

Quoted 9 lines

tests/util/kms.c const char *util_lookup_connector_type_name(unsigned int type)

Quoted 8 lines
tests/util/kms.c +6 -0
+{
 
+    if (!devicesp)
+        return err;
+
 
+
+    if (devicesp)

With the "if !devicesp" check above this should always be true, no ?

Yes, you're absolutely right. I added the above shortcut in a very late iteration and forgot to update the tail of the function.

Quoted 3 lines
Quoted 1 line

+int util_open_with_module(const char *device, const char *module)

Name and thus distinction vs util_open is blurred - here we require non-null device... which we should check for.

Yes, I've added a check for that now.

Quoted 1 line

Sadly I'm out of ideas for better name(s) :-(

I know this isn't ideal, but hopefully the doxygen in patch 3/3 will clarify somewhat how these are to be used.

Quoted 12 lines

tests/util/kms.c const char *util_lookup_connector_type_name(unsigned int type) · line 200

Quoted 11 lines

{

tests/util/kms.c +8 -1
-    int fd;
+    int fd, err = 0;
+
+    if (module)
+        printf("trying to open `%s' with `%s'...", device, module);
+    else
+        printf("trying to open `%s'...", device);
+
+    fd = open(device, O_RDWR);

Not sure how much we should care here, but O_CLOEXEC would be nice.

Yes, added.

Quoted 10 lines

tests/util/kms.c const char *util_lookup_connector_type_name(unsigned int type) · line 262

Quoted 6 lines
tests/util/kms.c +4 -0
+int util_open(const char *device, const char *module)
+{
 
 
+    } else {
+        fd = util_open_with_module(device, module);

Nit: one can drop a level of indentation/brackets - I have no strong preference either way.

int util_open(...)

Quoted 8 lines
{
   if (device)
      return util_open_with_module(device, module);

   ...
   get_devices
   ...
}

This looks better indeed. It's also nice how the implementation now very closely matches the description in the doxygen comment introduced in patch 3/3.

Quoted 12 lines

tests/util/kms.h const char *util_lookup_encoder_type_name(unsigned int type); · line 58

Quoted 10 lines
tests/util/kms.h +7 -0
 
+
+static inline char *util_device_get_node(drmDevicePtr device,
+                                         unsigned int type)
+{
+    if (type >= DRM_NODE_MAX)
+        return NULL;
+

IMHO it's better to honour the ::available_nodes bitmask here, since we already check if we're within range.

This was meant to be a very low-level accessor that can be used to implement the iterators rather than be used standalone. If you look at the util_device_for_each_{,available}_node iterators, they make a distinction, though it is admittedly somewhat questionable how useful the iterator over all nodes, available or not, really is.

It's probably best to just drop the util_device_for_each() iterator altogether.

Quoted 2 lines

This the above the series is

Thanks,
Thierry

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel