basic-stress.c revision 42542f5f
1#include <stdint.h> 2#include <stdio.h> 3#include <stdlib.h> 4 5#include <X11/Xutil.h> /* for XDestroyImage */ 6#include <pixman.h> 7 8#include "test.h" 9 10static void fill_rect(struct test_target *tt, 11 int alu, int color, 12 int x, int y, int w, int h) 13{ 14 XGCValues val; 15 16 val.function = alu; 17 val.foreground = color; 18 XChangeGC(tt->dpy->dpy, tt->gc, GCFunction | GCForeground, &val); 19 20 XFillRectangle(tt->dpy->dpy, tt->draw, tt->gc, x, y, w, h); 21} 22 23static void clear(struct test_target *tt) 24{ 25 fill_rect(tt, 26 GXcopy, 0, 27 0, 0, tt->width, tt->height); 28} 29 30static void fill(struct test_target *out, 31 struct test_target *ref) 32{ 33 int x = rand() % (2*out->width) - out->width; 34 int y = rand() % (2*out->height) - out->height; 35 int w = rand() % (2*out->width); 36 int h = rand() % (2*out->height); 37 int color = rand(); 38 int alu = rand() % 16; 39 40 fill_rect(out, alu, color, x, y, w, h); 41 fill_rect(ref, alu, color, x, y, w, h); 42} 43 44static void copy(struct test_target *out, 45 struct test_target *ref) 46{ 47 int sx = rand() % (2*out->width) - ref->width; 48 int sy = rand() % (2*out->height) - ref->height; 49 int dx = rand() % (2*out->width) - ref->width; 50 int dy = rand() % (2*out->height) - ref->height; 51 int w = rand() % (2*out->width); 52 int h = rand() % (2*out->height); 53 XGCValues val; 54 55 val.function = rand() % 16; 56 57 XChangeGC(out->dpy->dpy, out->gc, GCFunction, &val); 58 XCopyArea(out->dpy->dpy, 59 out->draw, out->draw, out->gc, 60 sx, sy, w, h, dx, dy); 61 62 XChangeGC(ref->dpy->dpy, ref->gc, GCFunction, &val); 63 XCopyArea(ref->dpy->dpy, 64 ref->draw, ref->draw, ref->gc, 65 sx, sy, w, h, dx, dy); 66} 67 68static void _put(struct test_target *tt, 69 int x, int y, int w,int h, int color, int alu) 70{ 71 XImage image; 72 XGCValues val; 73 74 val.function = alu; 75 76 test_init_image(&image, &tt->dpy->shm, tt->format, w, h); 77 pixman_fill((uint32_t*)image.data, 78 image.bytes_per_line/sizeof(uint32_t), 79 image.bits_per_pixel, 80 0, 0, w, h, color); 81 82 XChangeGC(tt->dpy->dpy, tt->gc, GCFunction, &val); 83 if (rand() & 1) { 84 XShmPutImage(tt->dpy->dpy, tt->draw, tt->gc, &image, 85 0, 0, x, y, w, h, 0); 86 XSync(tt->dpy->dpy, 1); 87 } else { 88 XPutImage(tt->dpy->dpy, tt->draw, tt->gc, &image, 89 0, 0, x, y, w, h); 90 } 91} 92 93static void put(struct test_target *out, 94 struct test_target *ref) 95{ 96 int x = rand() % (2*out->width) - out->width; 97 int y = rand() % (2*out->height) - out->height; 98 int w = rand() % out->width; 99 int h = rand() % out->height; 100 int color = rand(); 101 int alu = rand() % 16; 102 103 _put(out, x, y, w, h, color, alu); 104 _put(ref, x, y, w, h, color, alu); 105} 106 107static void rect_tests(struct test *test, int iterations, enum target target) 108{ 109 struct test_target out, ref; 110 void (* const ops[])(struct test_target *, struct test_target *) = { 111 copy, 112 fill, 113 put, 114 }; 115 int n; 116 117 printf("Running mixed ops stress against %s: ", 118 test_target_name(target)); 119 fflush(stdout); 120 121 test_target_create_render(&test->out, target, &out); 122 test_target_create_render(&test->ref, target, &ref); 123 124 clear(&out); 125 clear(&ref); 126 127 for (n = 0; n < iterations; n++) 128 ops[rand() % ARRAY_SIZE(ops)](&out, &ref); 129 130 test_compare(test, 131 out.draw, out.format, 132 ref.draw, ref.format, 133 0, 0, out.width, out.height, 134 ""); 135 136 printf("passed [%d iterations]\n", n); 137 138 test_target_destroy_render(&test->out, &out); 139 test_target_destroy_render(&test->ref, &ref); 140} 141 142int main(int argc, char **argv) 143{ 144 struct test test; 145 int i; 146 147 test_init(&test, argc, argv); 148 149 for (i = 0; i <= DEFAULT_ITERATIONS; i++) { 150 int iterations = REPS(i); 151 rect_tests(&test, iterations, 0); 152 rect_tests(&test, iterations, 1); 153 } 154 155 return 0; 156} 157