Commit 03dc319c authored by Jeremy White's avatar Jeremy White

Update the tests directory to follow spice coding style.

parent a27a5fff
......@@ -56,7 +56,11 @@ indent "$1" \
-T xcb_damage_notify_event_t \
-T xcb_damage_notify_event_t \
-T xcb_configure_notify_event_t \
-T xcb_screen_t \
-T display_t \
-T gui_t \
-T GKeyFile \
-T gchar \
-T xdummy_t \
-T x11spice_server_t \
-T test_t \
......@@ -27,15 +27,14 @@
int main(int argc, char *argv[])
{
setlocale (LC_ALL, "");
setlocale(LC_ALL, "");
g_test_init (&argc, &argv, NULL);
g_test_init(&argc, &argv, NULL);
// FIXME - g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=");
g_test_add("/x11spice/basic", xdummy_t, "basic",
start_server, test_basic, stop_server);
g_test_add("/x11spice/basic", xdummy_t, "basic", start_server, test_basic, stop_server);
g_log_set_always_fatal(G_LOG_LEVEL_ERROR);
return g_test_run ();
return g_test_run();
}
......@@ -25,23 +25,21 @@
#include "xcb.h"
#include "x11spice_test.h"
static int test_common_start(test_t *test, x11spice_server_t *server,
xdummy_t *xserver, gconstpointer user_data)
static int test_common_start(test_t * test, x11spice_server_t * server,
xdummy_t *xserver, gconstpointer user_data)
{
int rc;
if (! xserver->running)
{
if (!xserver->running) {
g_test_skip("No server");
return -1;
}
test->xserver = xserver;
test->name = user_data;
test->name = user_data;
test->logfile = g_test_build_filename(G_TEST_BUILT, "run", test->name, "test.log", NULL);
if (! test->logfile)
{
if (!test->logfile) {
g_warning("Failed to create logfile");
g_test_fail();
return -1;
......@@ -49,8 +47,7 @@ static int test_common_start(test_t *test, x11spice_server_t *server,
memset(server, 0, sizeof(*server));
rc = x11spice_start(server, test);
if (rc)
{
if (rc) {
g_warning("Failed to start x11spice");
g_test_fail();
return rc;
......@@ -59,7 +56,7 @@ static int test_common_start(test_t *test, x11spice_server_t *server,
return 0;
}
static void test_common_stop(test_t *test, x11spice_server_t *server)
static void test_common_stop(test_t * test, x11spice_server_t * server)
{
x11spice_stop(server);
}
......@@ -81,7 +78,8 @@ void test_basic(xdummy_t *xserver, gconstpointer user_data)
if (xcb_draw_grid(buf)) {
g_warning("Could not draw the grid");
g_test_fail();
} else {
}
else {
screencap = g_test_build_filename(G_TEST_BUILT, "run", test.name, "screencap.ppm", NULL);
needs_prefix = 1;
......@@ -89,12 +87,11 @@ void test_basic(xdummy_t *xserver, gconstpointer user_data)
needs_prefix = 0;
snprintf(buf, sizeof(buf), "spicy-screenshot --uri=%s%s --out-file=%s",
needs_prefix ? "spice://" : "", server.uri, screencap);
needs_prefix ? "spice://" : "", server.uri, screencap);
system(buf);
snprintf(buf, sizeof(buf), "md5sum basic.expected.ppm | "
"sed -e 's!basic.expected.ppm!%s!' |"
"md5sum -c", screencap);
"sed -e 's!basic.expected.ppm!%s!' |" "md5sum -c", screencap);
if (system(buf)) {
snprintf(buf, sizeof(buf), "xwd -display :%s -root -out %s.xwd",
xserver->display, screencap);
......
......@@ -41,9 +41,11 @@ static int exec_x11spice(x11spice_server_t *server, gchar *display)
dup2(server->pipe, fileno(stderr));
if (valgrind)
snprintf(buf, sizeof(buf), "%s ../x11spice --display :%s --auto localhost:5900-5999 --hide", valgrind, display);
snprintf(buf, sizeof(buf), "%s ../x11spice --display :%s --auto localhost:5900-5999 --hide",
valgrind, display);
else
snprintf(buf, sizeof(buf), "../x11spice --display :%s --auto localhost:5900-5999 --hide", display);
snprintf(buf, sizeof(buf), "../x11spice --display :%s --auto localhost:5900-5999 --hide",
display);
return execl("/bin/sh", "sh", "-c", buf, NULL);
......@@ -51,18 +53,17 @@ static int exec_x11spice(x11spice_server_t *server, gchar *display)
}
static void * flush_output(void *opaque)
static void *flush_output(void *opaque)
{
x11spice_server_t *server = (x11spice_server_t *) opaque;
int rc;
char buf[4096];
while (1)
{
while (1) {
rc = read(server->pipe, buf, sizeof(buf));
if (rc == -1 && errno == EINTR)
continue;
if (rc <= 0)
break;
......@@ -80,10 +81,8 @@ static int get_a_line(char *buf, int len, x11spice_server_t *server)
char *p;
for (p = buf; p < buf + len; p++)
if (*p == '\n')
{
if (p - buf > 4 && memcmp(buf, "URI=", 4) == 0)
{
if (*p == '\n') {
if (p - buf > 4 && memcmp(buf, "URI=", 4) == 0) {
server->uri = g_memdup(buf + 4, p - buf - 4 + 1);
server->uri[p - buf - 4] = '\0';
return len;
......@@ -108,16 +107,14 @@ int x11spice_start(x11spice_server_t *server, test_t *test)
return -1;
server->pid = fork();
if (server->pid == 0)
{
if (server->pid == 0) {
close(fd[0]);
server->pipe = fd[1];
exec_x11spice(server, test->xserver->display);
g_warning("x11spice server exec failed.");
return -1;
}
else
{
else {
server->pipe = fd[0];
close(fd[1]);
......@@ -125,30 +122,26 @@ int x11spice_start(x11spice_server_t *server, test_t *test)
return -1;
}
server->logfd = open(test->logfile, O_CREAT | O_WRONLY, S_IRUSR |S_IWUSR | S_IRGRP | S_IROTH);
if (server->logfd <= 0)
{
server->logfd = open(test->logfile, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (server->logfd <= 0) {
x11spice_stop(server);
return -1;
}
memset(buf, 0, sizeof(buf));
while (! server->uri)
{
while (!server->uri) {
rc = read(server->pipe, buf + pos, sizeof(buf) - pos);
if (rc == -1 && errno == EINTR)
continue;
if (rc <= 0)
{
if (rc <= 0) {
g_warning("x11spice server failed to send signal line. rc %d, errno %d", rc, errno);
return -1;
}
pos += rc;
while ((flush = get_a_line(buf, pos, server)))
{
while ((flush = get_a_line(buf, pos, server))) {
write(server->logfd, buf, flush);
if (flush < pos)
memmove(buf, buf + flush, pos - flush);
......@@ -175,19 +168,16 @@ static void stop_valgrind_children(x11spice_server_t *server)
void x11spice_stop(x11spice_server_t *server)
{
g_message("server stopping; pid %d", server->pid);
if (server->running)
{
if (server->running) {
if (getenv("VALGRIND"))
stop_valgrind_children(server);
if (still_alive(server->pid))
{
if (still_alive(server->pid)) {
kill(server->pid, SIGTERM);
usleep(50 * 1000);
}
if (still_alive(server->pid))
{
if (still_alive(server->pid)) {
sleep(1);
kill(server->pid, SIGKILL);
}
......
......@@ -31,8 +31,7 @@
/*----------------------------------------------------------------------------
** Structure definitions
**--------------------------------------------------------------------------*/
typedef struct
{
typedef struct {
int pid;
int pipe;
int logfd;
......
......@@ -26,17 +26,19 @@
#include <xcb/xcb.h>
static void lookup_color(xcb_connection_t *c, xcb_screen_t *screen, const char *color, uint32_t *pixel)
static void lookup_color(xcb_connection_t *c, xcb_screen_t *screen, const char *color,
uint32_t *pixel)
{
xcb_lookup_color_cookie_t cookie;
xcb_lookup_color_reply_t *r;
xcb_alloc_color_cookie_t acookie;
xcb_alloc_color_reply_t *ar;
cookie = xcb_lookup_color(c, screen->default_colormap, strlen(color), color);
r = xcb_lookup_color_reply(c, cookie, NULL);
acookie = xcb_alloc_color(c, screen->default_colormap, r->exact_red, r->exact_green, r->exact_blue);
acookie =
xcb_alloc_color(c, screen->default_colormap, r->exact_red, r->exact_green, r->exact_blue);
free(r);
ar = xcb_alloc_color_reply(c, acookie, NULL);
......@@ -44,30 +46,26 @@ static void lookup_color(xcb_connection_t *c, xcb_screen_t *screen, const char *
free(ar);
}
static void create_rectangles(xcb_rectangle_t *red, xcb_rectangle_t *green, int w, int h)
static void create_rectangles(xcb_rectangle_t * red, xcb_rectangle_t * green, int w, int h)
{
int x, y;
int r, g;
int i;
for (i = 0; i < 32; i++)
{
for (i = 0; i < 32; i++) {
red[i].width = green[i].width = w / 8;
red[i].height = green[i].height = h / 8;
}
r = g = 0;
for (x = 0; x < 8; x++)
for (y = 0; y < 8; y++)
{
if (((y * 8) + x) % 2 == y % 2)
{
for (y = 0; y < 8; y++) {
if (((y * 8) + x) % 2 == y % 2) {
red[r].x = x * (w / 8);
red[r].y = y * (h / 8);
r++;
}
else
{
else {
green[g].x = x * (w / 8);
green[g].y = y * (h / 8);
g++;
......@@ -79,10 +77,10 @@ int xcb_draw_grid(const char *display)
{
uint32_t pixels[2];
xcb_connection_t *c;
xcb_screen_t *screen;
xcb_gcontext_t red_fg;
xcb_gcontext_t green_fg;
xcb_connection_t *c;
xcb_screen_t *screen;
xcb_gcontext_t red_fg;
xcb_gcontext_t green_fg;
xcb_rectangle_t red_rectangles[32];
xcb_rectangle_t green_rectangles[32];
......@@ -105,14 +103,15 @@ int xcb_draw_grid(const char *display)
pixels[1] = 0;
xcb_create_gc(c, green_fg, screen->root, XCB_GC_FOREGROUND, pixels);
create_rectangles(red_rectangles, green_rectangles, screen->width_in_pixels, screen->height_in_pixels);
create_rectangles(red_rectangles, green_rectangles, screen->width_in_pixels,
screen->height_in_pixels);
/* We draw the rectangles */
xcb_poly_fill_rectangle_checked(c, screen->root, red_fg, 32, red_rectangles);
xcb_poly_fill_rectangle_checked(c, screen->root, green_fg, 32, green_rectangles);
/* We flush the request */
xcb_flush (c);
xcb_flush(c);
xcb_disconnect(c);
......
......@@ -33,52 +33,52 @@
#include "xdummy.h"
static void write_xorg_conf(FILE *fp, xdummy_t *server, long vram)
static void write_xorg_conf(FILE * fp, xdummy_t *server, long vram)
{
fprintf(fp,
"# This xorg configuration file is meant to be used by x11spice\n"
"# to start a dummy X11 server.\n"
"\n"
"Section \"ServerFlags\"\n"
" Option \"DontVTSwitch\" \"true\"\n"
" Option \"AllowMouseOpenFail\" \"true\"\n"
" Option \"PciForceNone\" \"true\"\n"
" Option \"AutoEnableDevices\" \"false\"\n"
" Option \"AutoAddDevices\" \"false\"\n"
"EndSection\n"
"\n"
"Section \"InputDevice\"\n"
" Identifier \"dummy_mouse\"\n"
" Option \"CorePointer\" \"true\"\n"
" Driver \"void\"\n"
"EndSection\n"
"\n"
"Section \"InputDevice\"\n"
" Identifier \"dummy_keyboard\"\n"
" Option \"CoreKeyboard\" \"true\"\n"
" Driver \"void\"\n"
"EndSection\n"
"\n"
"Section \"Device\"\n"
" Identifier \"dummy_videocard\"\n"
" Driver \"dummy\"\n"
" VideoRam %ld\n"
"EndSection\n"
"\n"
"Section \"Screen\"\n"
" Identifier \"dummy_screen\"\n"
" Device \"dummy_videocard\"\n"
" Monitor \"dummy_monitor\"\n"
" DefaultDepth 24\n"
"EndSection\n"
"\n"
"Section \"ServerLayout\"\n"
" Identifier \"dummy_layout\"\n"
" Screen \"dummy_screen\"\n"
" InputDevice \"dummy_mouse\"\n"
" InputDevice \"dummy_keyboard\"\n"
"EndSection\n", vram);
"# This xorg configuration file is meant to be used by x11spice\n"
"# to start a dummy X11 server.\n"
"\n"
"Section \"ServerFlags\"\n"
" Option \"DontVTSwitch\" \"true\"\n"
" Option \"AllowMouseOpenFail\" \"true\"\n"
" Option \"PciForceNone\" \"true\"\n"
" Option \"AutoEnableDevices\" \"false\"\n"
" Option \"AutoAddDevices\" \"false\"\n"
"EndSection\n"
"\n"
"Section \"InputDevice\"\n"
" Identifier \"dummy_mouse\"\n"
" Option \"CorePointer\" \"true\"\n"
" Driver \"void\"\n"
"EndSection\n"
"\n"
"Section \"InputDevice\"\n"
" Identifier \"dummy_keyboard\"\n"
" Option \"CoreKeyboard\" \"true\"\n"
" Driver \"void\"\n"
"EndSection\n"
"\n"
"Section \"Device\"\n"
" Identifier \"dummy_videocard\"\n"
" Driver \"dummy\"\n"
" VideoRam %ld\n"
"EndSection\n"
"\n"
"Section \"Screen\"\n"
" Identifier \"dummy_screen\"\n"
" Device \"dummy_videocard\"\n"
" Monitor \"dummy_monitor\"\n"
" DefaultDepth 24\n"
"EndSection\n"
"\n"
"Section \"ServerLayout\"\n"
" Identifier \"dummy_layout\"\n"
" Screen \"dummy_screen\"\n"
" InputDevice \"dummy_mouse\"\n"
" InputDevice \"dummy_keyboard\"\n"
"EndSection\n", vram);
}
static int generate_paths(xdummy_t *server, gconstpointer user_data)
......@@ -101,19 +101,19 @@ static int generate_paths(xdummy_t *server, gconstpointer user_data)
server->xorg_fname = g_test_build_filename(G_TEST_BUILT, "run", user_data, "xorg.conf", NULL);
if (! server->xorg_fname)
if (!server->xorg_fname)
return -1;
server->logfile = g_test_build_filename(G_TEST_BUILT, "run", user_data, "xorg.log", NULL);
if (! server->logfile)
if (!server->logfile)
return -1;
server->outfile = g_test_build_filename(G_TEST_BUILT, "run", user_data, "xorg.out", NULL);
if (! server->outfile)
if (!server->outfile)
return -1;
server->spicefile = g_test_build_filename(G_TEST_BUILT, "run", user_data, "spice.log", NULL);
if (! server->outfile)
if (!server->outfile)
return -1;
return 0;
......@@ -125,7 +125,7 @@ static int exec_xorg(xdummy_t *server, gconstpointer user_data)
char fdbuf[100];
fp = fopen(server->xorg_fname, "w");
if (! fp)
if (!fp)
return -1;
write_xorg_conf(fp, server, 192000L);
......@@ -137,18 +137,17 @@ static int exec_xorg(xdummy_t *server, gconstpointer user_data)
snprintf(fdbuf, sizeof(fdbuf), "%d", server->pipe);
return execlp("Xorg", "Xorg", "-ac",
"-config", server->xorg_fname,
"-logfile", server->logfile,
"-displayfd", fdbuf, NULL);
"-config", server->xorg_fname,
"-logfile", server->logfile, "-displayfd", fdbuf, NULL);
}
int redirect(gchar *fname)
{
int fd;
fd = open(fname, O_CREAT | O_WRONLY, S_IRUSR |S_IWUSR | S_IRGRP | S_IROTH);
fd = open(fname, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (fd <= 0)
return -1;
dup2(fd, fileno(stdout));
dup2(fd, fileno(stderr));
......@@ -172,8 +171,7 @@ void start_server(xdummy_t *server, gconstpointer user_data)
return;
server->pid = fork();
if (server->pid == 0)
{
if (server->pid == 0) {
close(fd[0]);
server->pipe = fd[1];
exec_xorg(server, user_data);
......@@ -188,14 +186,12 @@ void start_server(xdummy_t *server, gconstpointer user_data)
return;
}
while (1)
{
while (1) {
rc = read(server->pipe, buf + pos, sizeof(buf) - pos);
if (rc == -1 && errno == EINTR)
continue;
if (rc <= 0)
{
if (rc <= 0) {
g_warning("server failed to start.");
return;
}
......@@ -228,16 +224,13 @@ int still_alive(int pid)
void stop_server(xdummy_t *server, gconstpointer user_data)
{
g_message("server stopping; display %s", server->display);
if (server->running)
{
if (still_alive(server->pid))
{
if (server->running) {
if (still_alive(server->pid)) {
kill(server->pid, SIGTERM);
usleep(50 * 1000);
}
if (still_alive(server->pid))
{
if (still_alive(server->pid)) {
sleep(1);
kill(server->pid, SIGKILL);
}
......
......@@ -26,8 +26,7 @@
/*----------------------------------------------------------------------------
** Structure definitions
**--------------------------------------------------------------------------*/
typedef struct
{
typedef struct {
int pid;
int pipe;
gboolean running;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment