test: Add a basic line tester

Starting with exercising drawing of a single segment.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
Chris Wilson 2011-11-06 09:43:47 +00:00
parent c1e1e20fe7
commit c76714c29d
18 changed files with 188 additions and 21 deletions

1
test/.gitignore vendored
View File

@ -2,6 +2,7 @@ basic-copyarea
basic-copyarea-size
basic-fillrect
basic-putimage
basic-lines
basic-stress
render-fill
render-trapezoid

View File

@ -3,6 +3,7 @@ stress_TESTS = \
basic-copyarea \
basic-copyarea-size \
basic-putimage \
basic-lines \
basic-stress \
render-fill \
render-trapezoid \

View File

@ -88,11 +88,13 @@ int main(int argc, char **argv)
test_compare(&test,
real.a, real.format,
ref.a, ref.format,
0, 0, size, size);
0, 0, size, size,
"");
test_compare(&test,
real.b, real.format,
ref.b, ref.format,
0, 0, size, size);
0, 0, size, size,
"");
target_fini(&test.real, &real);
target_fini(&test.ref, &ref);

View File

@ -264,7 +264,8 @@ static void rect_tests(struct test *t, int reps, int sets, enum target target, i
test_compare(t,
real.draw, real.format,
ref.draw, ref.format,
0, 0, real.width, real.height);
0, 0, real.width, real.height,
""
}
printf("passed [%d iterations x %d]\n", reps, sets);

View File

@ -228,7 +228,8 @@ static void rect_tests(struct test *t, int reps, int sets, enum target target)
test_compare(t,
real.draw, real.format,
ref.draw, ref.format,
0, 0, real.width, real.height);
0, 0, real.width, real.height,
"");
}
printf("passed [%d iterations x %d]\n", reps, sets);

147
test/basic-lines.c Normal file
View File

@ -0,0 +1,147 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xutil.h> /* for XDestroyImage */
#include <pixman.h> /* for pixman blt functions */
#include "test.h"
static const XPoint points[]= {
/* top */
{ 0, 0},
{ 1, 0},
{ 2, 0},
{ 3, 0},
{ 4, 0},
{ 5, 0},
{ 6, 0},
{ 7, 0},
{ 8, 0},
/* right */
{ 8, 1},
{ 8, 2},
{ 8, 3},
{ 8, 4},
{ 8, 5},
{ 8, 6},
{ 8, 7},
{ 8, 8},
/* bottom */
{ 7, 8},
{ 6, 8},
{ 5, 8},
{ 4, 8},
{ 3, 8},
{ 2, 8},
{ 1, 8},
{ 0, 8},
/* left */
{ 0, 7},
{ 0, 6},
{ 0, 5},
{ 0, 4},
{ 0, 3},
{ 0, 2},
{ 0, 1},
{ 0, 0} /* and origin again for luck */
};
#define NUM_POINTS (sizeof(points)/sizeof(points[0]))
static void clear(struct test_display *dpy, struct test_target *tt)
{
XRenderColor render_color = {0};
XRenderFillRectangle(dpy->dpy, PictOpClear, tt->picture, &render_color,
0, 0, tt->width, tt->height);
}
static void draw_line(struct test_display *dpy, struct test_target *tt,
int alu, int width, int style, int cap,
const XPoint *p1, const XPoint *p2,
int dx, int dy)
{
XGCValues val;
GC gc;
val.function = GXcopy;
val.foreground = WhitePixel(dpy->dpy, 0);
val.line_width = width;
val.line_style = style;
val.cap_style = cap;
gc = XCreateGC(dpy->dpy, tt->draw,
GCForeground |
GCFunction |
GCLineWidth |
GCLineStyle |
GCCapStyle,
&val);
XDrawLine(dpy->dpy, tt->draw, gc,
p1->x + dx, p1->y + dy,
p2->x + dx, p2->y + dy);
XFreeGC(dpy->dpy, gc);
}
static void line_tests(struct test *t, enum target target)
{
char buf[1024];
struct test_target real, ref;
int a, b, alu, lw, style, cap;
printf("Testing drawing of single line segments (%s): ",
test_target_name(target));
fflush(stdout);
test_target_create_render(&t->real, target, &real);
test_target_create_render(&t->ref, target, &ref);
style = LineSolid;
for (alu = 0; alu < 16; alu++) {
for (cap = CapNotLast; cap <= CapProjecting; cap++) {
for (lw = 0; lw <= 4; lw++) {
for (a = 0; a < NUM_POINTS; a++) {
for (b = 0; b < NUM_POINTS; b++) {
sprintf(buf,
"p1=(%d, %d), p2=(%d, %d), width=%d, cap=%d, alu=%d",
points[a].x, points[a].y,
points[b].x, points[b].y,
lw, cap, alu);
clear(&t->real, &real);
clear(&t->ref, &ref);
draw_line(&t->real, &real, alu, lw, style, cap,
&points[a], &points[b], 64, 64);
draw_line(&t->ref, &ref, alu, lw, style, cap,
&points[a], &points[b], 64, 64);
test_compare(t,
real.draw, real.format,
ref.draw, ref.format,
0, 0, real.width, real.height,
buf);
}
}
}
}
}
test_target_destroy_render(&t->real, &real);
test_target_destroy_render(&t->ref, &ref);
printf("\n");
}
int main(int argc, char **argv)
{
struct test test;
enum target t;
test_init(&test, argc, argv);
for (t = TARGET_FIRST; t <= TARGET_LAST; t++)
line_tests(&test, t);
return 0;
}

View File

@ -245,7 +245,8 @@ static void rect_tests(struct test *t, int reps, int sets, enum target target, i
test_compare(t,
real.draw, real.format,
ref.draw, ref.format,
0, 0, real.width, real.height);
0, 0, real.width, real.height,
"");
}
printf("passed [%d iterations x %d]\n", reps, sets);

View File

@ -130,7 +130,8 @@ static void rect_tests(struct test *test, int iterations, enum target target)
test_compare(test,
real.draw, real.format,
ref.draw, ref.format,
0, 0, real.width, real.height);
0, 0, real.width, real.height,
"");
printf("passed [%d iterations]\n", n);

View File

@ -183,7 +183,8 @@ static void rect_tests(struct test *test, int iterations, enum target target)
test_compare(test,
real.draw, real.format,
ref.draw, ref.format,
0, 0, real.width, real.height);
0, 0, real.width, real.height,
"");
printf("passed [%d iterations]\n", n);

View File

@ -220,7 +220,8 @@ static void rect_tests(struct test *t, int reps, int sets, enum target target)
test_compare(t,
real.draw, real.format,
ref.draw, ref.format,
0, 0, real.width, real.height);
0, 0, real.width, real.height,
"");
}
printf("passed [%d iterations x %d]\n", reps, sets);

View File

@ -101,11 +101,13 @@ int main(int argc, char **argv)
test_compare(&test,
real.a, real.format,
ref.a, ref.format,
0, 0, size, size);
0, 0, size, size,
"");
test_compare(&test,
real.b, real.format,
ref.b, ref.format,
0, 0, size, size);
0, 0, size, size,
"");
target_fini(&test.real, &real);
target_fini(&test.ref, &ref);

View File

@ -287,7 +287,8 @@ static void rect_tests(struct test *t, int reps, int sets, enum target target, i
test_compare(t,
real.draw, real.format,
ref.draw, ref.format,
0, 0, real.width, real.height);
0, 0, real.width, real.height,
"");
}
printf("passed [%d iterations x %d]\n", reps, sets);

View File

@ -244,7 +244,8 @@ static void rect_tests(struct test *t, int reps, int sets, enum target target)
test_compare(t,
real.draw, real.format,
ref.draw, ref.format,
0, 0, real.width, real.height);
0, 0, real.width, real.height,
"");
}
printf("passed [%d iterations x %d]\n", reps, sets);

View File

@ -212,7 +212,8 @@ static void rect_tests(struct test *t, int reps, int sets, enum target target)
test_compare(t,
real.draw, real.format,
ref.draw, ref.format,
0, 0, real.width, real.height);
0, 0, real.width, real.height,
"");
}
printf("passed [%d iterations x %d]\n", reps, sets);

View File

@ -418,7 +418,8 @@ static void rect_tests(struct test *t,
test_compare(t,
real.draw, real.format,
ref.draw, ref.format,
0, 0, real.width, real.height);
0, 0, real.width, real.height,
"");
}
printf("passed [%d iterations x %d]\n", reps, sets);
@ -562,7 +563,8 @@ static void trap_tests(struct test *t,
test_compare(t,
real.draw, real.format,
ref.draw, ref.format,
0, 0, real.width, real.height);
0, 0, real.width, real.height,
"");
}
printf("passed [%d iterations x %d]\n", reps, sets);

View File

@ -267,7 +267,8 @@ static void rect_tests(struct test *t,
test_compare(t,
real.draw, real.format,
ref.draw, ref.format,
0, 0, real.width, real.height);
0, 0, real.width, real.height,
"");
}
printf("passed [%d iterations x %d]\n", reps, sets);
@ -391,7 +392,8 @@ static void trap_tests(struct test *t,
test_compare(t,
real.draw, real.format,
ref.draw, ref.format,
0, 0, real.width, real.height);
0, 0, real.width, real.height,
"");
}
printf("passed [%d iterations x %d]\n", reps, sets);

View File

@ -43,7 +43,7 @@ void test_init(struct test *test, int argc, char **argv);
void test_compare(struct test *real,
Drawable real_draw, XRenderPictFormat *real_format,
Drawable ref_draw, XRenderPictFormat *ref_format,
int x, int y, int w, int h);
int x, int y, int w, int h, const char *info);
#define MAX_DELTA 3
int pixel_difference(uint32_t a, uint32_t b);

View File

@ -117,7 +117,8 @@ static void test_compare_fallback(struct test *t,
void test_compare(struct test *t,
Drawable real_draw, XRenderPictFormat *real_format,
Drawable ref_draw, XRenderPictFormat *ref_format,
int x, int y, int w, int h)
int x, int y, int w, int h,
const char *info)
{
XImage real_image, ref_image;
Pixmap tmp;
@ -172,8 +173,8 @@ void test_compare(struct test *t,
show_pixels(buf,
&real_image, &ref_image,
i, j, w, h);
die("discrepancy found at (%d+%d, %d+%d): found %08x, expected %08x (delta: %d)\n%s",
x,i, y,j, a, b, pixel_difference(a, b), buf);
die("discrepancy found at (%d+%d, %d+%d): found %08x, expected %08x (delta: %d)\n%s%s\n",
x,i, y,j, a, b, pixel_difference(a, b), buf, info);
}
}
real += real_image.bytes_per_line;