a bit of rearranging before adding more tests
authorRob Clark <rob.clark@linaro.org>
Fri, 11 Nov 2011 23:13:08 +0000 (17:13 -0600)
committerRob Clark <rob.clark@linaro.org>
Fri, 2 Dec 2011 15:02:09 +0000 (09:02 -0600)
test/Makefile.am
test/dri2-nouveau.c [moved from test/dri2test-nouveau.c with 99% similarity]
test/dri2-omap.c [moved from test/dri2test-omap.c with 98% similarity]
test/dri2test.c
test/dri2util.c [new file with mode: 0644]
test/dri2util.h [moved from test/dri2test.h with 87% similarity]

index acd559c586778b669c5e5e664c9d1e4315de75ed..8515c6b091d90a136d8741081c5e8d6d38020610 100644 (file)
@@ -1,18 +1,21 @@
 lib_LTLIBRARIES = libdri2test.la
 
-libdri2test_la_SOURCES = dri2test.c
-libdri2test_la_LIBADD = @DRI2_LIBS@ 
-libdri2test_la_CFLAGS = $(CWARNFLAGS) -I$(top_srcdir)/include @DRI2_CFLAGS@
-
+COMMON_SOURCES = dri2util.c
+COMMON_LIBADD  = @DRI2_LIBS@ 
+COMMON_CFLAGS  = -g -O0 $(CWARNFLAGS) -I$(top_srcdir)/include @DRI2_CFLAGS@
 
 if ENABLE_NOUVEAU
-libdri2test_la_SOURCES += dri2test-nouveau.c
-libdri2test_la_LIBADD  += @NOUVEAU_LIBS@
-libdri2test_la_CFLAGS  += @NOUVEAU_CFLAGS@
+COMMON_SOURCES += dri2-nouveau.c
+COMMON_LIBADD  += @NOUVEAU_LIBS@
+COMMON_CFLAGS  += @NOUVEAU_CFLAGS@
 endif
 
 if ENABLE_OMAP
-libdri2test_la_SOURCES += dri2test-omap.c
-libdri2test_la_LIBADD  += @OMAP_LIBS@
-libdri2test_la_CFLAGS  += @OMAP_CFLAGS@
+COMMON_SOURCES += dri2-omap.c
+COMMON_LIBADD  += @OMAP_LIBS@
+COMMON_CFLAGS  += @OMAP_CFLAGS@
 endif
+
+libdri2test_la_SOURCES = dri2test.c $(COMMON_SOURCES)
+libdri2test_la_LIBADD = $(COMMON_LIBADD)
+libdri2test_la_CFLAGS = $(COMMON_CFLAGS)
similarity index 99%
rename from test/dri2test-nouveau.c
rename to test/dri2-nouveau.c
index 561e5e18f0a890a0f9dc6254e00d56f8ac1ea7fd..f91cc4877e86ed59f5e6454764cc97cf68052f1a 100644 (file)
@@ -34,7 +34,7 @@
 #  include "config.h"
 #endif
 
-#include "dri2test.h"
+#include "dri2util.h"
 
 #include <nouveau_bo.h>
 #include <nouveau_drmif.h>
similarity index 98%
rename from test/dri2test-omap.c
rename to test/dri2-omap.c
index 10858af740c3aa8e9288a183a5ed912987841080..181599dd3a783212d6d408ebed74bcae335bef32 100644 (file)
@@ -34,7 +34,7 @@
 #  include "config.h"
 #endif
 
-#include "dri2test.h"
+#include "dri2util.h"
 
 #include <omap_drm.h>
 #include <omap_drmif.h>
index e7b3b83b7cd2302ab02a91aceb7136991dd914d4..1615add06001386c7d78021c66cb0e213553e0f3 100644 (file)
 #  include "config.h"
 #endif
 
-#include "dri2test.h"
+#include "dri2util.h"
 
-static Bool WireToEvent(Display *dpy, XExtDisplayInfo *info,
-               XEvent *event, xEvent *wire)
-{
-       switch ((wire->u.u.type & 0x7f) - info->codes->first_event) {
-
-       case DRI2_BufferSwapComplete:
-       {
-//             xDRI2BufferSwapComplete *awire = (xDRI2BufferSwapComplete *)wire;
-               MSG("BufferSwapComplete");
-               return True;
-       }
-       case DRI2_InvalidateBuffers:
-       {
-//             xDRI2InvalidateBuffers *awire = (xDRI2InvalidateBuffers *)wire;
-               MSG("InvalidateBuffers");
-//             dri2InvalidateBuffers(dpy, awire->drawable);
-               return False;
-       }
-       default:
-               /* client doesn't support server event */
-               break;
-       }
-
-       return False;
-}
-
-static Status EventToWire(Display *dpy, XExtDisplayInfo *info,
-               XEvent *event, xEvent *wire)
-{
-   switch (event->type) {
-   default:
-      /* client doesn't support server event */
-      break;
-   }
-
-   return Success;
-}
-
-static const DRI2EventOps ops = {
-               .WireToEvent = WireToEvent,
-               .EventToWire = EventToWire,
-};
-
-static int dri2_connect(Display *dpy, char **driver)
-{
-       int eventBase, errorBase, major, minor;
-       char *device;
-       drm_magic_t magic;
-       Window root;
-       int fd;
-
-       if (!DRI2InitDisplay(dpy, &ops)) {
-               ERROR_MSG("DRI2InitDisplay failed");
-               return -1;
-       }
-
-       if (!DRI2QueryExtension(dpy, &eventBase, &errorBase)) {
-               ERROR_MSG("DRI2QueryExtension failed");
-               return -1;
-       }
-
-       MSG("DRI2QueryExtension: eventBase=%d, errorBase=%d", eventBase, errorBase);
-
-       if (!DRI2QueryVersion(dpy, &major, &minor)) {
-               ERROR_MSG("DRI2QueryVersion failed");
-               return -1;
-       }
-
-       MSG("DRI2QueryVersion: major=%d, minor=%d", major, minor);
-
-       root = RootWindow(dpy, DefaultScreen(dpy));
-
-       if (!DRI2Connect(dpy, root, driver, &device)) {
-               ERROR_MSG("DRI2Connect failed");
-               return -1;
-       }
-
-       MSG("DRI2Connect: driver=%s, device=%s", *driver, device);
-
-       fd = open(device, O_RDWR);
-       if (fd < 0) {
-               ERROR_MSG("open failed");
-               return fd;
-       }
-
-       if (drmGetMagic(fd, &magic)) {
-               ERROR_MSG("drmGetMagic failed");
-               return -1;
-       }
-
-       if (!DRI2Authenticate(dpy, root, magic)) {
-               ERROR_MSG("DRI2Authenticate failed");
-               return -1;
-       }
-
-       return fd;
-}
-
-#ifdef HAVE_NOUVEAU
-extern Backend nouveau_backend;
-#endif
-
-#ifdef HAVE_OMAP
-extern Backend omap_backend;
-#endif
+#define WIDTH  500
+#define HEIGHT 500
+#define NFRAMES 300
 
 /* stolen from modetest.c */
 static void fill(char *virtual, int n, int width, int height, int stride)
@@ -183,20 +81,8 @@ int main(int argc, char **argv)
                return -1;
        }
 
-#ifdef HAVE_NOUVEAU
-       if (!strcmp(driver, "nouveau")) {
-               backend = &nouveau_backend;
-       }
-#endif
-
-#ifdef HAVE_OMAP
-       if (!strcmp(driver, "omap")) {
-               backend = &omap_backend;
-       }
-#endif
-
+       backend = get_backend(driver);
        if (!backend) {
-               ERROR_MSG("no suitable backend DRM driver found");
                return -1;
        }
 
diff --git a/test/dri2util.c b/test/dri2util.c
new file mode 100644 (file)
index 0000000..4c41f5b
--- /dev/null
@@ -0,0 +1,162 @@
+/*
+ * Copyright © 2011 Texas Instruments, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Soft-
+ * ware"), to deal in the Software without restriction, including without
+ * limitation the rights to use, copy, modify, merge, publish, distribute,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, provided that the above copyright
+ * notice(s) and this permission notice appear in all copies of the Soft-
+ * ware and that both the above copyright notice(s) and this permission
+ * notice appear in supporting documentation.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
+ * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
+ * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN
+ * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE-
+ * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR-
+ * MANCE OF THIS SOFTWARE.
+ *
+ * Except as contained in this notice, the name of a copyright holder shall
+ * not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization of
+ * the copyright holder.
+ *
+ * Authors:
+ *   Rob Clark (rob@ti.com)
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include "dri2util.h"
+
+static Bool WireToEvent(Display *dpy, XExtDisplayInfo *info,
+               XEvent *event, xEvent *wire)
+{
+       switch ((wire->u.u.type & 0x7f) - info->codes->first_event) {
+
+       case DRI2_BufferSwapComplete:
+       {
+//             xDRI2BufferSwapComplete *awire = (xDRI2BufferSwapComplete *)wire;
+               MSG("BufferSwapComplete");
+               return True;
+       }
+       case DRI2_InvalidateBuffers:
+       {
+//             xDRI2InvalidateBuffers *awire = (xDRI2InvalidateBuffers *)wire;
+               MSG("InvalidateBuffers");
+//             dri2InvalidateBuffers(dpy, awire->drawable);
+               return False;
+       }
+       default:
+               /* client doesn't support server event */
+               break;
+       }
+
+       return False;
+}
+
+static Status EventToWire(Display *dpy, XExtDisplayInfo *info,
+               XEvent *event, xEvent *wire)
+{
+   switch (event->type) {
+   default:
+      /* client doesn't support server event */
+      break;
+   }
+
+   return Success;
+}
+
+static const DRI2EventOps ops = {
+               .WireToEvent = WireToEvent,
+               .EventToWire = EventToWire,
+};
+
+int dri2_connect(Display *dpy, char **driver)
+{
+       int eventBase, errorBase, major, minor;
+       char *device;
+       drm_magic_t magic;
+       Window root;
+       int fd;
+
+       if (!DRI2InitDisplay(dpy, &ops)) {
+               ERROR_MSG("DRI2InitDisplay failed");
+               return -1;
+       }
+
+       if (!DRI2QueryExtension(dpy, &eventBase, &errorBase)) {
+               ERROR_MSG("DRI2QueryExtension failed");
+               return -1;
+       }
+
+       MSG("DRI2QueryExtension: eventBase=%d, errorBase=%d", eventBase, errorBase);
+
+       if (!DRI2QueryVersion(dpy, &major, &minor)) {
+               ERROR_MSG("DRI2QueryVersion failed");
+               return -1;
+       }
+
+       MSG("DRI2QueryVersion: major=%d, minor=%d", major, minor);
+
+       root = RootWindow(dpy, DefaultScreen(dpy));
+
+       if (!DRI2Connect(dpy, root, driver, &device)) {
+               ERROR_MSG("DRI2Connect failed");
+               return -1;
+       }
+
+       MSG("DRI2Connect: driver=%s, device=%s", *driver, device);
+
+       fd = open(device, O_RDWR);
+       if (fd < 0) {
+               ERROR_MSG("open failed");
+               return fd;
+       }
+
+       if (drmGetMagic(fd, &magic)) {
+               ERROR_MSG("drmGetMagic failed");
+               return -1;
+       }
+
+       if (!DRI2Authenticate(dpy, root, magic)) {
+               ERROR_MSG("DRI2Authenticate failed");
+               return -1;
+       }
+
+       return fd;
+}
+
+#ifdef HAVE_NOUVEAU
+extern Backend nouveau_backend;
+#endif
+
+#ifdef HAVE_OMAP
+extern Backend omap_backend;
+#endif
+
+Backend * get_backend(const char *driver)
+{
+#ifdef HAVE_NOUVEAU
+       if (!strcmp(driver, "nouveau")) {
+               return &nouveau_backend;
+       }
+#endif
+
+#ifdef HAVE_OMAP
+       if (!strcmp(driver, "omap")) {
+               return &omap_backend;
+       }
+#endif
+
+       ERROR_MSG("no suitable backend DRM driver found");
+
+       return NULL;
+}
similarity index 87%
rename from test/dri2test.h
rename to test/dri2util.h
index b4bac99f937c4f6792a16bb1525fa4007174c863..d30460d34e2d9246b688d5d5fdfc73077b056390 100644 (file)
 #define ERROR_MSG(fmt, ...) \
                do { fprintf(stderr, "ERROR: " fmt "\n", ##__VA_ARGS__); } while (0)
 
+static inline void print_hex(int len, const unsigned char *val)
+{
+       char buf[33];
+       int i, j;
+       for (i = 0; i < len; i += j) {
+               for (j = 0; (j < 16) && ((i + j) < len); ++j)
+                       sprintf(&buf[j * 2], "%02x", val[i + j]);
+               fprintf(stderr, "\t%s\n", buf);
+       }
+}
 
-#define WIDTH  500
-#define HEIGHT 500
-#define NFRAMES 300
 
 typedef struct {
        DRI2Buffer *dri2buf;
@@ -67,4 +74,7 @@ typedef struct {
        void   (*fini)(void *hdl);
 } Backend;
 
+int dri2_connect(Display *dpy, char **driver);
+Backend * get_backend(const char *driver);
+
 #endif /* _DRI2TEST_H_ */