Testcase for fix for Xlib 32-bit request number issues

Christian Linhart chris at DemoRecorder.com
Sat Mar 21 07:40:33 PDT 2015


Hi all,

Below is the testcase which I have used for testing my fix for the 32-bit request number issues.

I have tested the patch on a 32-bit and 64-bit system successfully with that testcase.

This testcase is a modified version of the testcase of the bugreport at
https://bugs.freedesktop.org/show_bug.cgi?id=71338

The testcase does not test all code that is changed by the patch.
This will require more elaborate testing.

Cheers,

Chris


=========================================================
#include <X11/Xlib.h> // Every Xlib program must include this
#include <X11/Xlibint.h>
#include <assert.h>   // I include this to test return values the lazy way
#include <unistd.h>   // So we got the profile for 10 seconds
#include <stdio.h>
#include <stdlib.h>
#include <execinfo.h>

#define NIL (0)       // A name for the void pointer

void printBacktrace() {
  int j, nptrs;
#define SIZE 100
  void *buffer[100];
  char **strings;

  nptrs = backtrace(buffer, SIZE);
  printf("backtrace() returned %d addresses\n", nptrs);

   /* The call backtrace_symbols_fd(buffer, nptrs, STDOUT_FILENO)
       would produce similar output to the following: */

  strings = backtrace_symbols(buffer, nptrs);
  if (strings == NULL) {
    perror("backtrace_symbols");
    exit(EXIT_FAILURE);
  }

  for (j = 0; j < nptrs; j++)
    printf("%s\n", strings[j]);

  free(strings);
}

int myIOXError(Display *disp)
{
  printf("ERROR Received a X IO error on display=%x.\n", disp);
  printBacktrace();
  return True;
}

main() {
  Display *dpy = XOpenDisplay(NIL);
  assert(dpy);

  int blackColor = BlackPixel(dpy, DefaultScreen(dpy));
  int whiteColor = WhitePixel(dpy, DefaultScreen(dpy));

  // Create the window
  Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0,
                                 200, 100, 0, blackColor, blackColor);

  // We want to get MapNotify events
  XSelectInput(dpy, w, StructureNotifyMask | ButtonReleaseMask );

  // "Map" the window (that is, make it appear on the screen)
  XMapWindow(dpy, w);

  // Create a "Graphics Context"
  GC gc = XCreateGC(dpy, w, 0, NIL);

  // Tell the GC we draw using the white color
  XSetForeground(dpy, gc, whiteColor);

  // register io error handler
  XSetIOErrorHandler(myIOXError);

  // Wait for the MapNotify event
  for(;;) {
    XEvent e;
    XNextEvent(dpy, &e);
    if (e.type == MapNotify)
      break;
  }

  // Draw the line
  unsigned long count;
  for(count = 0;; count++) {
    XNoOp(dpy);
    //XDrawLine(dpy, w, gc, 10, 60, 180, 20);
    //Send the "DrawLine" request to the server
    //XFlush(dpy);
        if ( ( count % 0x1000000UL ) == 0 ) {
            //XFlush(dpy);
            printf( "nextRequest = %016llx, lastRequestRead = %016llx\n",
                (unsigned long long)(NextRequest(dpy)),
                (unsigned long long)(LastKnownRequestProcessed(dpy))
            );
            printf( "request= %016llx, last_request_read = %016llx\n",
            #ifdef X_DPY_GET_REQUEST
                (unsigned long long)(X_DPY_GET_REQUEST(dpy)),
                (unsigned long long)(X_DPY_GET_LAST_REQUEST_READ(dpy))
            #else
                (unsigned long long)(dpy->request),
                (unsigned long long)(dpy->last_request_read)
            #endif
            );
            XFlush(dpy);
        }
        if ( ( count % 0x100001000UL ) == 0 ) {
            XSync(dpy, False);
            for(;;) {
                XEvent e;
                if ( !XCheckWindowEvent(dpy, w, ButtonReleaseMask, &e) ) {
                break;
                }
            }
        }
  }

  // Wait for 10 seconds
  sleep(10);
}
=========================================================


More information about the xorg-devel mailing list