[Spice-commits] 10 commits - server/tests

Alon Levy alon at kemper.freedesktop.org
Mon Jan 10 04:23:36 PST 2011


 server/tests/Makefile.am              |    6 
 server/tests/basic_event_loop.c       |    1 
 server/tests/test_display_base.c      |  574 ++++++++++++++++++++++++++++++++++
 server/tests/test_display_base.h      |   23 +
 server/tests/test_display_no_ssl.c    |  282 +---------------
 server/tests/test_display_streaming.c |   27 +
 6 files changed, 651 insertions(+), 262 deletions(-)

New commits:
commit 293f5f0df8b22e93f2358824309cdd0f849d96a6
Author: Alon Levy <alevy at redhat.com>
Date:   Sat Jan 8 16:06:15 2011 +0200

    server/tests: split test_display_no_ssl to test_display_base, add streaming test

diff --git a/server/tests/Makefile.am b/server/tests/Makefile.am
index ddac420..3494e5c 100644
--- a/server/tests/Makefile.am
+++ b/server/tests/Makefile.am
@@ -9,9 +9,11 @@ INCLUDES =                          \
 
 AM_LDFLAGS = -L../.libs -lspice-server
 
-noinst_PROGRAMS = test_just_sockets_no_ssl test_empty_success test_fail_on_null_core_interface test_display_no_ssl
+noinst_PROGRAMS = test_just_sockets_no_ssl test_empty_success test_fail_on_null_core_interface test_display_no_ssl test_display_streaming
 
-test_display_no_ssl_SOURCES = test_display_no_ssl.c basic_event_loop.c basic_event_loop.h test_util.h
+test_display_streaming_SOURCES = test_display_streaming.c test_display_base.c basic_event_loop.c basic_event_loop.h test_util.h
+
+test_display_no_ssl_SOURCES = test_display_no_ssl.c test_display_base.c basic_event_loop.c basic_event_loop.h test_util.h
 
 test_display_no_ssl_LDFLAGS = $(AM_LDFLAGS) $(LDFLAGS)
 
diff --git a/server/tests/test_display_base.c b/server/tests/test_display_base.c
new file mode 100644
index 0000000..c87d2c7
--- /dev/null
+++ b/server/tests/test_display_base.c
@@ -0,0 +1,574 @@
+#include <stdlib.h>
+#include <math.h>
+#include <string.h>
+#include <stdio.h>
+#include <sys/select.h>
+#include <spice/qxl_dev.h>
+#include "test_display_base.h"
+#include "red_channel.h"
+#include "test_util.h"
+
+#define MEM_SLOT_GROUP_ID 0
+
+/* Parts cribbed from spice-display.h/.c/qxl.c */
+
+typedef struct SimpleSpiceUpdate {
+    QXLCommandExt ext; // first
+    QXLDrawable drawable;
+    QXLImage image;
+    uint8_t *bitmap;
+} SimpleSpiceUpdate;
+
+typedef struct SimpleSurfaceCmd {
+    QXLCommandExt ext; // first
+    QXLSurfaceCmd surface_cmd;
+} SimpleSurfaceCmd;
+
+static void test_spice_destroy_update(SimpleSpiceUpdate *update)
+{
+    if (!update) {
+        return;
+    }
+    if (update->bitmap) {
+        free(update->bitmap);
+    }
+    free(update);
+}
+
+#define WIDTH 320
+#define HEIGHT 320
+
+#define SINGLE_PART 8
+static const int angle_parts = 64 / SINGLE_PART;
+static int angle = 0;
+static int unique = 1;
+static int color = -1;
+static int c_i = 0;
+
+static void set_cmd(QXLCommandExt *ext, uint32_t type, QXLPHYSICAL data)
+{
+    ext->cmd.type = type;
+    ext->cmd.data = data;
+    ext->cmd.padding = 0;
+    ext->group_id = MEM_SLOT_GROUP_ID;
+    ext->flags = 0;
+}
+
+static void simple_set_release_info(QXLReleaseInfo *info, intptr_t ptr)
+{
+    info->id = ptr;
+    //info->group_id = MEM_SLOT_GROUP_ID;
+}
+
+typedef struct Path {
+    int t;
+    int min_t;
+    int max_t;
+} Path;
+
+static void path_init(Path *path, int min, int max)
+{
+    path->t = min;
+    path->min_t = min;
+    path->max_t = max;
+}
+
+static void path_progress(Path *path)
+{
+    path->t = (path->t+1)% (path->max_t - path->min_t) + path->min_t;
+}
+
+Path path;
+
+static void draw_pos(int t, int *x, int *y)
+{
+#ifdef CIRCLE
+    *y = HEIGHT/2 + (HEIGHT/3)*cos(t*2*M_PI/angle_parts);
+    *x = WIDTH/2 + (WIDTH/3)*sin(t*2*M_PI/angle_parts);
+#else
+    *y = HEIGHT*(t % SINGLE_PART)/SINGLE_PART;
+    *x = ((WIDTH/SINGLE_PART)*(t / SINGLE_PART)) % WIDTH;
+#endif
+}
+
+static SimpleSpiceUpdate *test_spice_create_update_draw(uint32_t surface_id, int t)
+{
+    SimpleSpiceUpdate *update;
+    QXLDrawable *drawable;
+    QXLImage *image;
+    int top, left;
+    draw_pos(t, &left, &top);
+    QXLRect bbox = {
+        .top = top,
+        .left = left,
+    };
+    uint8_t *dst;
+    int bw, bh;
+    int i;
+
+    if ((t % angle_parts) == 0) {
+        c_i++;
+    }
+    color = (color + 1) % 2;
+    unique++;
+
+    update   = calloc(sizeof(*update), 1);
+    drawable = &update->drawable;
+    image    = &update->image;
+
+    bw       = WIDTH/SINGLE_PART;
+    bh       = 48;
+    bbox.right = bbox.left + bw;
+    bbox.bottom = bbox.top + bh;
+    update->bitmap = malloc(bw * bh * 4);
+    //printf("allocated %p, %p\n", update, update->bitmap);
+
+    drawable->surface_id      = surface_id;
+
+    drawable->bbox            = bbox;
+    drawable->clip.type       = SPICE_CLIP_TYPE_NONE;
+    drawable->effect          = QXL_EFFECT_OPAQUE;
+    simple_set_release_info(&drawable->release_info, (intptr_t)update);
+    drawable->type            = QXL_DRAW_COPY;
+    drawable->surfaces_dest[0] = -1;
+    drawable->surfaces_dest[1] = -1;
+    drawable->surfaces_dest[2] = -1;
+
+    drawable->u.copy.rop_descriptor  = SPICE_ROPD_OP_PUT;
+    drawable->u.copy.src_bitmap      = (intptr_t)image;
+    drawable->u.copy.src_area.right  = bw;
+    drawable->u.copy.src_area.bottom = bh;
+
+    QXL_SET_IMAGE_ID(image, QXL_IMAGE_GROUP_DEVICE, unique);
+    image->descriptor.type   = SPICE_IMAGE_TYPE_BITMAP;
+    image->bitmap.flags      = QXL_BITMAP_DIRECT | QXL_BITMAP_TOP_DOWN;
+    image->bitmap.stride     = bw * 4;
+    image->descriptor.width  = image->bitmap.x = bw;
+    image->descriptor.height = image->bitmap.y = bh;
+    image->bitmap.data = (intptr_t)(update->bitmap);
+    image->bitmap.palette = 0;
+    image->bitmap.format = SPICE_BITMAP_FMT_32BIT;
+
+    dst = update->bitmap;
+    for (i = 0 ; i < bh * bw ; ++i, dst+=4) {
+        *dst = (color+i % 255);
+        *(dst+((1+c_i)%3)) = 255 - color;
+        *(dst+((2+c_i)%3)) = (color * (color + i)) & 0xff;
+        *(dst+((3+c_i)%3)) = 0;
+    }
+
+    set_cmd(&update->ext, QXL_CMD_DRAW, (intptr_t)drawable);
+
+    return update;
+}
+
+static SimpleSpiceUpdate *test_spice_create_update_copy_bits(uint32_t surface_id)
+{
+    SimpleSpiceUpdate *update;
+    QXLDrawable *drawable;
+    int bw, bh;
+    QXLRect bbox = {
+        .left = 10,
+        .top = 0,
+    };
+
+    update   = calloc(sizeof(*update), 1);
+    drawable = &update->drawable;
+
+    bw       = WIDTH/SINGLE_PART;
+    bh       = 48;
+    bbox.right = bbox.left + bw;
+    bbox.bottom = bbox.top + bh;
+    //printf("allocated %p, %p\n", update, update->bitmap);
+
+    drawable->surface_id      = surface_id;
+
+    drawable->bbox            = bbox;
+    drawable->clip.type       = SPICE_CLIP_TYPE_NONE;
+    drawable->effect          = QXL_EFFECT_OPAQUE;
+    simple_set_release_info(&drawable->release_info, (intptr_t)update);
+    drawable->type            = QXL_COPY_BITS;
+    drawable->surfaces_dest[0] = -1;
+    drawable->surfaces_dest[1] = -1;
+    drawable->surfaces_dest[2] = -1;
+
+    drawable->u.copy_bits.src_pos.x = 0;
+    drawable->u.copy_bits.src_pos.y = 0;
+
+    set_cmd(&update->ext, QXL_CMD_DRAW, (intptr_t)drawable);
+
+    return update;
+}
+
+static SimpleSurfaceCmd *create_surface(int surface_id, int width, int height, uint8_t *data)
+{
+    SimpleSurfaceCmd *simple_cmd = calloc(sizeof(SimpleSurfaceCmd), 1);
+    QXLSurfaceCmd *surface_cmd = &simple_cmd->surface_cmd;
+
+    set_cmd(&simple_cmd->ext, QXL_CMD_SURFACE, (intptr_t)surface_cmd);
+    simple_set_release_info(&surface_cmd->release_info, (intptr_t)simple_cmd);
+    surface_cmd->type = QXL_SURFACE_CMD_CREATE;
+    surface_cmd->flags = 0; // ?
+    surface_cmd->surface_id = surface_id;
+    surface_cmd->u.surface_create.format = SPICE_SURFACE_FMT_32_xRGB;
+    surface_cmd->u.surface_create.width = width;
+    surface_cmd->u.surface_create.height = height;
+    surface_cmd->u.surface_create.stride = -width * 4;
+    surface_cmd->u.surface_create.data = (intptr_t)data;
+    return simple_cmd;
+}
+
+static SimpleSurfaceCmd *destroy_surface(int surface_id)
+{
+    SimpleSurfaceCmd *simple_cmd = calloc(sizeof(SimpleSurfaceCmd), 1);
+    QXLSurfaceCmd *surface_cmd = &simple_cmd->surface_cmd;
+
+    set_cmd(&simple_cmd->ext, QXL_CMD_SURFACE, (intptr_t)surface_cmd);
+    simple_set_release_info(&surface_cmd->release_info, (intptr_t)simple_cmd);
+    surface_cmd->type = QXL_SURFACE_CMD_DESTROY;
+    surface_cmd->flags = 0; // ?
+    surface_cmd->surface_id = surface_id;
+    return simple_cmd;
+}
+
+static QXLWorker *qxl_worker = NULL;
+static uint8_t primary_surface[HEIGHT * WIDTH * 4];
+
+static void create_test_primary_surface(QXLWorker *worker)
+{
+    QXLDevSurfaceCreate surface;
+
+    surface.format     = SPICE_SURFACE_FMT_32_xRGB;
+    surface.width      = WIDTH;
+    surface.height     = HEIGHT;
+    surface.stride     = -WIDTH * 4;
+    surface.mouse_mode = TRUE;
+    surface.flags      = 0;
+    surface.type       = 0;
+    surface.mem        = (intptr_t)&primary_surface;
+    surface.group_id   = MEM_SLOT_GROUP_ID;
+
+    qxl_worker->create_primary_surface(qxl_worker, 0, &surface);
+}
+
+QXLDevMemSlot slot = {
+.slot_group_id = MEM_SLOT_GROUP_ID,
+.slot_id = 0,
+.generation = 0,
+.virt_start = 0,
+.virt_end = ~0,
+.addr_delta = 0,
+.qxl_ram_size = ~0,
+};
+
+static void attache_worker(QXLInstance *qin, QXLWorker *_qxl_worker)
+{
+    static int count = 0;
+    if (++count > 1) {
+        printf("%s ignored\n", __func__);
+        return;
+    }
+    printf("%s\n", __func__);
+    qxl_worker = _qxl_worker;
+    qxl_worker->add_memslot(qxl_worker, &slot);
+    create_test_primary_surface(qxl_worker);
+    qxl_worker->start(qxl_worker);
+}
+
+static void set_compression_level(QXLInstance *qin, int level)
+{
+    printf("%s\n", __func__);
+}
+
+static void set_mm_time(QXLInstance *qin, uint32_t mm_time)
+{
+}
+
+// we now have a secondary surface
+#define MAX_SURFACE_NUM 2
+
+static void get_init_info(QXLInstance *qin, QXLDevInitInfo *info)
+{
+    bzero(info, sizeof(*info));
+    info->num_memslots = 1;
+    info->num_memslots_groups = 1;
+    info->memslot_id_bits = 1;
+    info->memslot_gen_bits = 1;
+    info->n_surfaces = MAX_SURFACE_NUM;
+}
+
+#define NOTIFY_DISPLAY_BATCH (SINGLE_PART/2)
+#define NOTIFY_CURSOR_BATCH 0
+
+int cursor_notify = NOTIFY_CURSOR_BATCH;
+
+#define SURF_WIDTH 320
+#define SURF_HEIGHT 240
+uint8_t secondary_surface[SURF_WIDTH * SURF_HEIGHT * 4];
+
+// We shall now have a ring of commands, so that we can update
+// it from a separate thread - since get_command is called from
+// the worker thread, and we need to sometimes do an update_area,
+// which cannot be done from red_worker context (not via dispatcher,
+// since you get a deadlock, and it isn't designed to be done
+// any other way, so no point testing that).
+int commands_end = 0;
+int commands_start = 0;
+struct QXLCommandExt* commands[1024];
+
+#define COMMANDS_SIZE COUNT(commands)
+
+static void push_command(QXLCommandExt *ext)
+{
+    ASSERT(commands_end - commands_start < COMMANDS_SIZE);
+    commands[commands_end%COMMANDS_SIZE] = ext;
+    commands_end++;
+}
+
+static struct QXLCommandExt *get_simple_command()
+{
+    struct QXLCommandExt *ret = commands[commands_start%COMMANDS_SIZE];
+    ASSERT(commands_start < commands_end);
+    commands_start++;
+    return ret;
+}
+
+static int num_commands()
+{
+    return commands_end - commands_start;
+}
+
+// called from spice_server thread (i.e. red_worker thread)
+static int get_command(QXLInstance *qin, struct QXLCommandExt *ext)
+{
+    if (num_commands() == 0) {
+        return FALSE;
+    }
+    *ext = *get_simple_command();
+    return TRUE;
+}
+
+static int *simple_commands = NULL;
+static int num_simple_commands = 0;
+
+static void produce_command()
+{
+    static int target_surface = 0;
+    static int simple_command_index = 0;
+    static int cmd_index = 0;
+
+    ASSERT(num_simple_commands);
+
+    switch (simple_commands[cmd_index]) {
+        case PATH_PROGRESS:
+            path_progress(&path);
+            break;
+        case SIMPLE_UPDATE: {
+            QXLRect rect = {.left = 0, .right = WIDTH,
+                            .top = 0, .bottom = HEIGHT};
+            qxl_worker->update_area(qxl_worker, 0, &rect, NULL, 0, 1);
+            break;
+        }
+        case SIMPLE_COPY_BITS:
+        case SIMPLE_DRAW: {
+            SimpleSpiceUpdate *update;
+            switch (simple_commands[cmd_index]) {
+                case SIMPLE_COPY_BITS:
+                    update = test_spice_create_update_copy_bits(target_surface);
+                    break;
+                case SIMPLE_DRAW:
+                    update = test_spice_create_update_draw(target_surface, path.t);
+                    break;
+            }
+            push_command(&update->ext);
+            break;
+        }
+        case SIMPLE_CREATE_SURFACE: {
+            SimpleSurfaceCmd *update;
+            target_surface = MAX_SURFACE_NUM - 1;
+            update = create_surface(target_surface, SURF_WIDTH, SURF_HEIGHT,
+                                    secondary_surface);
+            push_command(&update->ext);
+            break;
+        }
+        case SIMPLE_DESTROY_SURFACE: {
+            SimpleSurfaceCmd *update;
+            update = destroy_surface(target_surface);
+            target_surface = 0;
+            push_command(&update->ext);
+            break;
+        }
+    }
+    cmd_index = (cmd_index + 1) % num_simple_commands;
+}
+
+SpiceTimer *wakeup_timer;
+int wakeup_ms = 50;
+
+static int req_cmd_notification(QXLInstance *qin)
+{
+    core->timer_start(wakeup_timer, wakeup_ms);
+    return TRUE;
+}
+
+static void do_wakeup()
+{
+    int notify;
+    cursor_notify = NOTIFY_CURSOR_BATCH;
+
+    for (notify = NOTIFY_DISPLAY_BATCH; notify > 0;--notify) {
+        produce_command();
+    }
+
+    core->timer_start(wakeup_timer, wakeup_ms);
+    qxl_worker->wakeup(qxl_worker);
+}
+
+static void release_resource(QXLInstance *qin, struct QXLReleaseInfoExt release_info)
+{
+    QXLCommandExt *ext = (void*)release_info.info->id;
+    //printf("%s\n", __func__);
+    ASSERT(release_info.group_id == MEM_SLOT_GROUP_ID);
+    switch (ext->cmd.type) {
+        case QXL_CMD_DRAW:
+            test_spice_destroy_update((void*)ext);
+            break;
+        case QXL_CMD_SURFACE:
+            free(ext);
+            break;
+        default:
+            abort();
+    }
+}
+
+#define CURSOR_WIDTH 32
+#define CURSOR_HEIGHT 32
+
+static struct {
+    QXLCursor cursor;
+    uint8_t data[CURSOR_WIDTH * CURSOR_HEIGHT * 4]; // 32bit per pixel
+} cursor;
+
+static void init_cursor()
+{
+    cursor.cursor.header.unique = 0; // TODO ??
+    cursor.cursor.header.type = SPICE_CURSOR_TYPE_COLOR32;
+    cursor.cursor.header.width = CURSOR_WIDTH;
+    cursor.cursor.header.height = CURSOR_HEIGHT;
+    cursor.cursor.header.hot_spot_x = 0;
+    cursor.cursor.header.hot_spot_y = 0;
+    cursor.cursor.data_size = CURSOR_WIDTH * CURSOR_HEIGHT;
+    cursor.cursor.chunk.data_size = cursor.cursor.data_size;
+    cursor.cursor.chunk.prev_chunk = cursor.cursor.chunk.next_chunk = 0;
+}
+
+static int get_cursor_command(QXLInstance *qin, struct QXLCommandExt *ext)
+{
+    static int color = 0;
+    QXLCursorCmd *cursor_cmd;
+    int i, x, y, p;
+    QXLCommandExt cmd;
+
+    if (!cursor_notify) {
+        return FALSE;
+    }
+    cursor_notify--;
+    cursor_cmd = calloc(sizeof(QXLCursorCmd), 1);
+    color = 100 + ((color + 1) % 100);
+    cursor_cmd->type = QXL_CURSOR_SET;
+    cursor_cmd->release_info.id = 0; // TODO: we leak the QXLCommandExt's
+    cursor_cmd->u.set.position.x = 0;
+    cursor_cmd->u.set.position.y = 0;
+    cursor_cmd->u.set.visible = TRUE;
+    cursor_cmd->u.set.shape = (uint64_t)&cursor;
+    for (x = 0 ; x < CURSOR_WIDTH; ++x) {
+        for (y = 0 ; y < CURSOR_HEIGHT; ++y) {
+            p = 0;
+            cursor.data[p] = (y*10 > color) ? color : 0;
+            cursor.data[p+1] = cursor.data[p+2] = cursor.data[p+3] = 0;
+        }
+    }
+    // TODO - shape has the, well, shape. device_data has?
+    for (i = 0 ; i < QXL_CURSUR_DEVICE_DATA_SIZE ; ++i) {
+        cursor_cmd->device_data[i] = color;
+    }
+    cmd.cmd.data = (uint64_t)cursor_cmd;
+    cmd.cmd.type = QXL_CMD_CURSOR;
+    cmd.group_id = MEM_SLOT_GROUP_ID;
+    cmd.flags    = 0; // TODO - cursor flags (qxl->cmdflags in qxl/pointer.c)?
+    *ext = cmd;
+    //printf("%s\n", __func__);
+    return TRUE;
+}
+
+static int req_cursor_notification(QXLInstance *qin)
+{
+    printf("%s\n", __func__);
+    return TRUE;
+}
+
+static void notify_update(QXLInstance *qin, uint32_t update_id)
+{
+    printf("%s\n", __func__);
+}
+
+static int flush_resources(QXLInstance *qin)
+{
+    printf("%s\n", __func__);
+}
+
+QXLInterface display_sif = {
+    .base = {
+        .type = SPICE_INTERFACE_QXL,
+        .description = "test",
+        .major_version = SPICE_INTERFACE_QXL_MAJOR,
+        .minor_version = SPICE_INTERFACE_QXL_MINOR
+    },
+    .attache_worker = attache_worker,
+    .set_compression_level = set_compression_level,
+    .set_mm_time = set_mm_time,
+    .get_init_info = get_init_info,
+    .get_command = get_command,
+    .req_cmd_notification = req_cmd_notification,
+    .release_resource = release_resource,
+    .get_cursor_command = get_cursor_command,
+    .req_cursor_notification = req_cursor_notification,
+    .notify_update = notify_update,
+    .flush_resources = flush_resources,
+};
+
+QXLInstance display_sin = {
+    .base = {
+        .sif = &display_sif.base,
+    },
+    .id = 0,
+};
+
+/* interface for tests */
+void test_add_display_interface(SpiceServer *server)
+{
+    spice_server_add_interface(server, &display_sin.base);
+}
+
+void test_set_simple_command_list(int* commands, int num_commands)
+{
+    simple_commands = commands;
+    num_simple_commands = num_commands;
+}
+
+SpiceServer* test_init(SpiceCoreInterface *core)
+{
+    SpiceServer* server = spice_server_new();
+
+    // some common initialization for all display tests
+    spice_server_set_port(server, 5912);
+    spice_server_set_noauth(server);
+    spice_server_init(server, core);
+
+    path_init(&path, 0, angle_parts);
+    bzero(primary_surface, sizeof(primary_surface));
+    bzero(secondary_surface, sizeof(secondary_surface));
+    wakeup_timer = core->timer_add(do_wakeup, NULL);
+    return server;
+}
+
diff --git a/server/tests/test_display_base.h b/server/tests/test_display_base.h
new file mode 100644
index 0000000..ca94057
--- /dev/null
+++ b/server/tests/test_display_base.h
@@ -0,0 +1,23 @@
+#ifndef __TEST_DISPLAY_BASE_H__
+#define __TEST_DISPLAY_BASE_H__
+
+#include <spice.h>
+#include "basic_event_loop.h"
+
+#define COUNT(x) ((sizeof(x)/sizeof(x[0])))
+
+void test_set_simple_command_list(int* commands, int num_commands);
+void test_add_display_interface(SpiceServer *server);
+SpiceServer* test_init(SpiceCoreInterface* core);
+
+// simple queue for commands
+enum {
+    PATH_PROGRESS,
+    SIMPLE_CREATE_SURFACE,
+    SIMPLE_DRAW,
+    SIMPLE_COPY_BITS,
+    SIMPLE_DESTROY_SURFACE,
+    SIMPLE_UPDATE,
+};
+
+#endif // __TEST_DISPLAY_BASE_H__
diff --git a/server/tests/test_display_no_ssl.c b/server/tests/test_display_no_ssl.c
index 682008b..b72acc9 100644
--- a/server/tests/test_display_no_ssl.c
+++ b/server/tests/test_display_no_ssl.c
@@ -1,580 +1,13 @@
-#include <stdlib.h>
-#include <math.h>
-#include <string.h>
-#include <stdio.h>
-#include <sys/select.h>
-#include <spice.h>
-#include <spice/qxl_dev.h>
-#include "red_channel.h"
-#include "test_util.h"
-#include "basic_event_loop.h"
-
-#define MEM_SLOT_GROUP_ID 0
-
-/* Parts cribbed from spice-display.h/.c/qxl.c */
-
-typedef struct SimpleSpiceUpdate {
-    QXLCommandExt ext; // first
-    QXLDrawable drawable;
-    QXLImage image;
-    uint8_t *bitmap;
-} SimpleSpiceUpdate;
-
-typedef struct SimpleSurfaceCmd {
-    QXLCommandExt ext; // first
-    QXLSurfaceCmd surface_cmd;
-} SimpleSurfaceCmd;
-
-void test_spice_destroy_update(SimpleSpiceUpdate *update)
-{
-    if (!update) {
-        return;
-    }
-    if (update->bitmap) {
-        free(update->bitmap);
-    }
-    free(update);
-}
-
-#define WIDTH 320
-#define HEIGHT 320
-
-#define SINGLE_PART 8
-static const int angle_parts = 64 / SINGLE_PART;
-static int angle = 0;
-static int unique = 1;
-static int color = -1;
-static int c_i = 0;
-
-void set_cmd(QXLCommandExt *ext, uint32_t type, QXLPHYSICAL data)
-{
-    ext->cmd.type = type;
-    ext->cmd.data = data;
-    ext->cmd.padding = 0;
-    ext->group_id = MEM_SLOT_GROUP_ID;
-    ext->flags = 0;
-}
-
-void simple_set_release_info(QXLReleaseInfo *info, intptr_t ptr)
-{
-    info->id = ptr;
-    //info->group_id = MEM_SLOT_GROUP_ID;
-}
-
-typedef struct Path {
-    int t;
-    int min_t;
-    int max_t;
-} Path;
-
-void path_init(Path *path, int min, int max)
-{
-    path->t = min;
-    path->min_t = min;
-    path->max_t = max;
-}
-
-void path_progress(Path *path)
-{
-    path->t = (path->t+1)% (path->max_t - path->min_t) + path->min_t;
-}
-
-Path path;
-
-void draw_pos(int t, int *x, int *y)
-{
-#ifdef CIRCLE
-    *y = HEIGHT/2 + (HEIGHT/3)*cos(t*2*M_PI/angle_parts);
-    *x = WIDTH/2 + (WIDTH/3)*sin(t*2*M_PI/angle_parts);
-#else
-    *y = HEIGHT*(t % SINGLE_PART)/SINGLE_PART;
-    *x = ((WIDTH/SINGLE_PART)*(t / SINGLE_PART)) % WIDTH;
-#endif
-}
-
-SimpleSpiceUpdate *test_spice_create_update_draw(uint32_t surface_id, int t)
-{
-    SimpleSpiceUpdate *update;
-    QXLDrawable *drawable;
-    QXLImage *image;
-    int top, left;
-    draw_pos(t, &left, &top);
-    QXLRect bbox = {
-        .top = top,
-        .left = left,
-    };
-    uint8_t *dst;
-    int bw, bh;
-    int i;
-
-    if ((t % angle_parts) == 0) {
-        c_i++;
-    }
-    color = (color + 1) % 2;
-    unique++;
-
-    update   = calloc(sizeof(*update), 1);
-    drawable = &update->drawable;
-    image    = &update->image;
-
-    bw       = WIDTH/SINGLE_PART;
-    bh       = 48;
-    bbox.right = bbox.left + bw;
-    bbox.bottom = bbox.top + bh;
-    update->bitmap = malloc(bw * bh * 4);
-    //printf("allocated %p, %p\n", update, update->bitmap);
-
-    drawable->surface_id      = surface_id;
-
-    drawable->bbox            = bbox;
-    drawable->clip.type       = SPICE_CLIP_TYPE_NONE;
-    drawable->effect          = QXL_EFFECT_OPAQUE;
-    simple_set_release_info(&drawable->release_info, (intptr_t)update);
-    drawable->type            = QXL_DRAW_COPY;
-    drawable->surfaces_dest[0] = -1;
-    drawable->surfaces_dest[1] = -1;
-    drawable->surfaces_dest[2] = -1;
-
-    drawable->u.copy.rop_descriptor  = SPICE_ROPD_OP_PUT;
-    drawable->u.copy.src_bitmap      = (intptr_t)image;
-    drawable->u.copy.src_area.right  = bw;
-    drawable->u.copy.src_area.bottom = bh;
-
-    QXL_SET_IMAGE_ID(image, QXL_IMAGE_GROUP_DEVICE, unique);
-    image->descriptor.type   = SPICE_IMAGE_TYPE_BITMAP;
-    image->bitmap.flags      = QXL_BITMAP_DIRECT | QXL_BITMAP_TOP_DOWN;
-    image->bitmap.stride     = bw * 4;
-    image->descriptor.width  = image->bitmap.x = bw;
-    image->descriptor.height = image->bitmap.y = bh;
-    image->bitmap.data = (intptr_t)(update->bitmap);
-    image->bitmap.palette = 0;
-    image->bitmap.format = SPICE_BITMAP_FMT_32BIT;
-
-    dst = update->bitmap;
-    for (i = 0 ; i < bh * bw ; ++i, dst+=4) {
-        *dst = (color+i % 255);
-        *(dst+((1+c_i)%3)) = 255 - color;
-        *(dst+((2+c_i)%3)) = (color * (color + i)) & 0xff;
-        *(dst+((3+c_i)%3)) = 0;
-    }
-
-    set_cmd(&update->ext, QXL_CMD_DRAW, (intptr_t)drawable);
-
-    return update;
-}
-
-SimpleSpiceUpdate *test_spice_create_update_copy_bits(uint32_t surface_id)
-{
-    SimpleSpiceUpdate *update;
-    QXLDrawable *drawable;
-    int bw, bh;
-    QXLRect bbox = {
-        .left = 10,
-        .top = 0,
-    };
-
-    update   = calloc(sizeof(*update), 1);
-    drawable = &update->drawable;
-
-    bw       = WIDTH/SINGLE_PART;
-    bh       = 48;
-    bbox.right = bbox.left + bw;
-    bbox.bottom = bbox.top + bh;
-    //printf("allocated %p, %p\n", update, update->bitmap);
-
-    drawable->surface_id      = surface_id;
-
-    drawable->bbox            = bbox;
-    drawable->clip.type       = SPICE_CLIP_TYPE_NONE;
-    drawable->effect          = QXL_EFFECT_OPAQUE;
-    simple_set_release_info(&drawable->release_info, (intptr_t)update);
-    drawable->type            = QXL_COPY_BITS;
-    drawable->surfaces_dest[0] = -1;
-    drawable->surfaces_dest[1] = -1;
-    drawable->surfaces_dest[2] = -1;
-
-    drawable->u.copy_bits.src_pos.x = 0;
-    drawable->u.copy_bits.src_pos.y = 0;
-
-    set_cmd(&update->ext, QXL_CMD_DRAW, (intptr_t)drawable);
-
-    return update;
-}
-
-
-/*
-void dispatch_update_area(QXLWorker *worker)
-{
-    worker->update_area();
-}
-
- update_area()
-{
-    QXL_CMD_UPDATE
-}
-*/
-
-SimpleSurfaceCmd *create_surface(int surface_id, int width, int height, uint8_t *data)
-{
-    SimpleSurfaceCmd *simple_cmd = calloc(sizeof(SimpleSurfaceCmd), 1);
-    QXLSurfaceCmd *surface_cmd = &simple_cmd->surface_cmd;
-
-    set_cmd(&simple_cmd->ext, QXL_CMD_SURFACE, (intptr_t)surface_cmd);
-    simple_set_release_info(&surface_cmd->release_info, (intptr_t)simple_cmd);
-    surface_cmd->type = QXL_SURFACE_CMD_CREATE;
-    surface_cmd->flags = 0; // ?
-    surface_cmd->surface_id = surface_id;
-    surface_cmd->u.surface_create.format = SPICE_SURFACE_FMT_32_xRGB;
-    surface_cmd->u.surface_create.width = width;
-    surface_cmd->u.surface_create.height = height;
-    surface_cmd->u.surface_create.stride = -width * 4;
-    surface_cmd->u.surface_create.data = (intptr_t)data;
-    return simple_cmd;
-}
-
-SimpleSurfaceCmd *destroy_surface(int surface_id)
-{
-    SimpleSurfaceCmd *simple_cmd = calloc(sizeof(SimpleSurfaceCmd), 1);
-    QXLSurfaceCmd *surface_cmd = &simple_cmd->surface_cmd;
-
-    set_cmd(&simple_cmd->ext, QXL_CMD_SURFACE, (intptr_t)surface_cmd);
-    simple_set_release_info(&surface_cmd->release_info, (intptr_t)simple_cmd);
-    surface_cmd->type = QXL_SURFACE_CMD_DESTROY;
-    surface_cmd->flags = 0; // ?
-    surface_cmd->surface_id = surface_id;
-    return simple_cmd;
-}
-
-static QXLWorker *qxl_worker = NULL;
-static uint8_t primary_surface[HEIGHT * WIDTH * 4];
-
-void create_test_primary_surface(QXLWorker *worker)
-{
-    QXLDevSurfaceCreate surface;
-
-    surface.format     = SPICE_SURFACE_FMT_32_xRGB;
-    surface.width      = WIDTH;
-    surface.height     = HEIGHT;
-    surface.stride     = -WIDTH * 4;
-    surface.mouse_mode = TRUE;
-    surface.flags      = 0;
-    surface.type       = 0;
-    surface.mem        = (intptr_t)&primary_surface;
-    surface.group_id   = MEM_SLOT_GROUP_ID;
-
-    qxl_worker->create_primary_surface(qxl_worker, 0, &surface);
-}
-
-QXLDevMemSlot slot = {
-.slot_group_id = MEM_SLOT_GROUP_ID,
-.slot_id = 0,
-.generation = 0,
-.virt_start = 0,
-.virt_end = ~0,
-.addr_delta = 0,
-.qxl_ram_size = ~0,
-};
-
-void attache_worker(QXLInstance *qin, QXLWorker *_qxl_worker)
-{
-    static int count = 0;
-    if (++count > 1) {
-        printf("%s ignored\n", __func__);
-        return;
-    }
-    printf("%s\n", __func__);
-    qxl_worker = _qxl_worker;
-    qxl_worker->add_memslot(qxl_worker, &slot);
-    create_test_primary_surface(qxl_worker);
-    qxl_worker->start(qxl_worker);
-}
-
-void set_compression_level(QXLInstance *qin, int level)
-{
-    printf("%s\n", __func__);
-}
-
-void set_mm_time(QXLInstance *qin, uint32_t mm_time)
-{
-}
+/**
+ * Test ground for developing specific tests.
+ *
+ * Any specific test can start of from here and set the server to the
+ * specific required state, and create specific operations or reuse
+ * existing ones in the test_display_base supplied queue.
+ */
 
-// we now have a secondary surface
-#define MAX_SURFACE_NUM 2
-
-void get_init_info(QXLInstance *qin, QXLDevInitInfo *info)
-{
-    bzero(info, sizeof(*info));
-    info->num_memslots = 1;
-    info->num_memslots_groups = 1;
-    info->memslot_id_bits = 1;
-    info->memslot_gen_bits = 1;
-    info->n_surfaces = MAX_SURFACE_NUM;
-}
-
-#define NOTIFY_DISPLAY_BATCH (SINGLE_PART/2)
-#define NOTIFY_CURSOR_BATCH 0
-
-int cursor_notify = NOTIFY_CURSOR_BATCH;
-
-// simple queue for commands
-enum {
-    PATH_PROGRESS,
-    SIMPLE_CREATE_SURFACE,
-    SIMPLE_DRAW,
-    SIMPLE_COPY_BITS,
-    SIMPLE_DESTROY_SURFACE,
-    SIMPLE_UPDATE,
-};
-
-int simple_commands[] = {
-    //SIMPLE_CREATE_SURFACE,
-    //SIMPLE_DRAW,
-    //SIMPLE_DESTROY_SURFACE,
-    SIMPLE_DRAW,
-    SIMPLE_COPY_BITS,
-    SIMPLE_UPDATE,
-};
-
-
-#define COUNT(x) ((sizeof(x)/sizeof(x[0])))
-#define NUM_SIMPLE_COMMANDS COUNT(simple_commands)
-
-#define SURF_WIDTH 320
-#define SURF_HEIGHT 240
-uint8_t secondary_surface[SURF_WIDTH * SURF_HEIGHT * 4];
-
-// We shall now have a ring of commands, so that we can update
-// it from a separate thread - since get_command is called from
-// the worker thread, and we need to sometimes do an update_area,
-// which cannot be done from red_worker context (not via dispatcher,
-// since you get a deadlock, and it isn't designed to be done
-// any other way, so no point testing that).
-int commands_end = 0;
-int commands_start = 0;
-struct QXLCommandExt* commands[1024];
-
-#define COMMANDS_SIZE COUNT(commands)
-
-void push_command(QXLCommandExt *ext)
-{
-    ASSERT(commands_end - commands_start < COMMANDS_SIZE);
-    commands[commands_end%COMMANDS_SIZE] = ext;
-    commands_end++;
-}
-
-struct QXLCommandExt *get_simple_command()
-{
-    struct QXLCommandExt *ret = commands[commands_start%COMMANDS_SIZE];
-    ASSERT(commands_start < commands_end);
-    commands_start++;
-    return ret;
-}
-
-int num_commands()
-{
-    return commands_end - commands_start;
-}
-
-// called from spice_server thread (i.e. red_worker thread)
-int get_command(QXLInstance *qin, struct QXLCommandExt *ext)
-{
-    if (num_commands() == 0) {
-        return FALSE;
-    }
-    *ext = *get_simple_command();
-    return TRUE;
-}
-
-void produce_command()
-{
-    static int target_surface = 0;
-    static int simple_command_index = 0;
-    static int cmd_index = 0;
-
-    switch (simple_commands[cmd_index]) {
-        case PATH_PROGRESS:
-            path_progress(&path);
-            break;
-        case SIMPLE_UPDATE: {
-            QXLRect rect = {.left = 0, .right = WIDTH,
-                            .top = 0, .bottom = HEIGHT};
-            qxl_worker->update_area(qxl_worker, 0, &rect, NULL, 0, 1);
-            break;
-        }
-        case SIMPLE_COPY_BITS:
-        case SIMPLE_DRAW: {
-            SimpleSpiceUpdate *update;
-            switch (simple_commands[cmd_index]) {
-                case SIMPLE_COPY_BITS:
-                    update = test_spice_create_update_copy_bits(target_surface);
-                    break;
-                case SIMPLE_DRAW:
-                    update = test_spice_create_update_draw(target_surface, path.t);
-                    break;
-            }
-            push_command(&update->ext);
-            break;
-        }
-        case SIMPLE_CREATE_SURFACE: {
-            SimpleSurfaceCmd *update;
-            target_surface = MAX_SURFACE_NUM - 1;
-            update = create_surface(target_surface, SURF_WIDTH, SURF_HEIGHT,
-                                    secondary_surface);
-            push_command(&update->ext);
-            break;
-        }
-        case SIMPLE_DESTROY_SURFACE: {
-            SimpleSurfaceCmd *update;
-            update = destroy_surface(target_surface);
-            target_surface = 0;
-            push_command(&update->ext);
-            break;
-        }
-    }
-    cmd_index = (cmd_index + 1) % NUM_SIMPLE_COMMANDS;
-}
-
-SpiceTimer *wakeup_timer;
-int wakeup_ms = 500;
-
-int req_cmd_notification(QXLInstance *qin)
-{
-    core->timer_start(wakeup_timer, wakeup_ms);
-    return TRUE;
-}
-
-void do_wakeup()
-{
-    int notify;
-    cursor_notify = NOTIFY_CURSOR_BATCH;
-
-    for (notify = NOTIFY_DISPLAY_BATCH; notify > 0;--notify) {
-        produce_command();
-    }
-
-    core->timer_start(wakeup_timer, wakeup_ms);
-    qxl_worker->wakeup(qxl_worker);
-}
-
-void release_resource(QXLInstance *qin, struct QXLReleaseInfoExt release_info)
-{
-    QXLCommandExt *ext = (void*)release_info.info->id;
-    //printf("%s\n", __func__);
-    ASSERT(release_info.group_id == MEM_SLOT_GROUP_ID);
-    switch (ext->cmd.type) {
-        case QXL_CMD_DRAW:
-            test_spice_destroy_update((void*)ext);
-            break;
-        case QXL_CMD_SURFACE:
-            free(ext);
-            break;
-        default:
-            abort();
-    }
-}
-
-#define CURSOR_WIDTH 32
-#define CURSOR_HEIGHT 32
-
-static struct {
-    QXLCursor cursor;
-    uint8_t data[CURSOR_WIDTH * CURSOR_HEIGHT * 4]; // 32bit per pixel
-} cursor;
-
-void init_cursor()
-{
-    cursor.cursor.header.unique = 0; // TODO ??
-    cursor.cursor.header.type = SPICE_CURSOR_TYPE_COLOR32;
-    cursor.cursor.header.width = CURSOR_WIDTH;
-    cursor.cursor.header.height = CURSOR_HEIGHT;
-    cursor.cursor.header.hot_spot_x = 0;
-    cursor.cursor.header.hot_spot_y = 0;
-    cursor.cursor.data_size = CURSOR_WIDTH * CURSOR_HEIGHT;
-    cursor.cursor.chunk.data_size = cursor.cursor.data_size;
-    cursor.cursor.chunk.prev_chunk = cursor.cursor.chunk.next_chunk = 0;
-}
-
-int get_cursor_command(QXLInstance *qin, struct QXLCommandExt *ext)
-{
-    static int color = 0;
-    QXLCursorCmd *cursor_cmd;
-    int i, x, y, p;
-    QXLCommandExt cmd;
-
-    if (!cursor_notify) {
-        return FALSE;
-    }
-    cursor_notify--;
-    cursor_cmd = calloc(sizeof(QXLCursorCmd), 1);
-    color = 100 + ((color + 1) % 100);
-    cursor_cmd->type = QXL_CURSOR_SET;
-    cursor_cmd->release_info.id = 0; // TODO: we leak the QXLCommandExt's
-    cursor_cmd->u.set.position.x = 0;
-    cursor_cmd->u.set.position.y = 0;
-    cursor_cmd->u.set.visible = TRUE;
-    cursor_cmd->u.set.shape = (uint64_t)&cursor;
-    for (x = 0 ; x < CURSOR_WIDTH; ++x) {
-        for (y = 0 ; y < CURSOR_HEIGHT; ++y) {
-            p = 0;
-            cursor.data[p] = (y*10 > color) ? color : 0;
-            cursor.data[p+1] = cursor.data[p+2] = cursor.data[p+3] = 0;
-        }
-    }
-    // TODO - shape has the, well, shape. device_data has?
-    for (i = 0 ; i < QXL_CURSUR_DEVICE_DATA_SIZE ; ++i) {
-        cursor_cmd->device_data[i] = color;
-    }
-    cmd.cmd.data = (uint64_t)cursor_cmd;
-    cmd.cmd.type = QXL_CMD_CURSOR;
-    cmd.group_id = MEM_SLOT_GROUP_ID;
-    cmd.flags    = 0; // TODO - cursor flags (qxl->cmdflags in qxl/pointer.c)?
-    *ext = cmd;
-    //printf("%s\n", __func__);
-    return TRUE;
-}
-
-int req_cursor_notification(QXLInstance *qin)
-{
-    printf("%s\n", __func__);
-    return TRUE;
-}
-
-void notify_update(QXLInstance *qin, uint32_t update_id)
-{
-    printf("%s\n", __func__);
-}
-
-int flush_resources(QXLInstance *qin)
-{
-    printf("%s\n", __func__);
-}
-
-QXLInterface display_sif = {
-    .base = {
-        .type = SPICE_INTERFACE_QXL,
-        .description = "test",
-        .major_version = SPICE_INTERFACE_QXL_MAJOR,
-        .minor_version = SPICE_INTERFACE_QXL_MINOR
-    },
-    .attache_worker = attache_worker,
-    .set_compression_level = set_compression_level,
-    .set_mm_time = set_mm_time,
-    .get_init_info = get_init_info,
-    .get_command = get_command,
-    .req_cmd_notification = req_cmd_notification,
-    .release_resource = release_resource,
-    .get_cursor_command = get_cursor_command,
-    .req_cursor_notification = req_cursor_notification,
-    .notify_update = notify_update,
-    .flush_resources = flush_resources,
-};
-
-QXLInstance display_sin = {
-    .base = {
-        .sif = &display_sif.base,
-    },
-    .id = 0,
-};
+#include <stdlib.h>
+#include "test_display_base.h"
 
 SpiceServer *server;
 SpiceCoreInterface *core;
@@ -592,21 +25,25 @@ void pinger(void *opaque)
     core->timer_start(ping_timer, ping_ms);
 }
 
+int simple_commands[] = {
+    //SIMPLE_CREATE_SURFACE,
+    //SIMPLE_DRAW,
+    //SIMPLE_DESTROY_SURFACE,
+    //PATH_PROGRESS,
+    SIMPLE_DRAW,
+    //SIMPLE_COPY_BITS,
+    SIMPLE_UPDATE,
+};
+
 int main()
 {
     core = basic_event_loop_init();
-    server = spice_server_new();
-    path_init(&path, 0, angle_parts);
-    bzero(primary_surface, sizeof(primary_surface));
-    bzero(secondary_surface, sizeof(secondary_surface));
-    spice_server_set_port(server, 5912);
-    spice_server_set_noauth(server);
-    spice_server_init(server, core);
+    server = test_init(core);
     //spice_server_set_image_compression(server, SPICE_IMAGE_COMPRESS_OFF);
-    spice_server_add_interface(server, &display_sin.base);
+    test_add_display_interface(server);
+    test_set_simple_command_list(simple_commands, COUNT(simple_commands));
 
     ping_timer = core->timer_add(pinger, NULL);
-    wakeup_timer = core->timer_add(do_wakeup, NULL);
     core->timer_start(ping_timer, ping_ms);
 
     basic_event_loop_mainloop();
diff --git a/server/tests/test_display_streaming.c b/server/tests/test_display_streaming.c
new file mode 100644
index 0000000..fdb1206
--- /dev/null
+++ b/server/tests/test_display_streaming.c
@@ -0,0 +1,27 @@
+/* Do repeated updates to the same rectangle to trigger stream creation.
+ *
+ * TODO: check that stream actually starts programatically (maybe stap?)
+ * TODO: stop updating same rect, check (prog) that stream stops
+ */
+
+#include "test_display_base.h"
+
+int simple_commands[] = {
+    SIMPLE_DRAW,
+    SIMPLE_UPDATE,
+};
+
+SpiceCoreInterface *core;
+SpiceServer *server;
+
+int main()
+{
+    core = basic_event_loop_init();
+    server = test_init(core);
+    spice_server_set_streaming_video(server, SPICE_STREAM_VIDEO_ALL);
+    test_add_display_interface(server);
+    test_set_simple_command_list(simple_commands, COUNT(simple_commands));
+    basic_event_loop_mainloop();
+    return 0;
+}
+
commit 2c16ef8f267c7f9f53901cb6dd477e0b63429143
Author: Alon Levy <alevy at redhat.com>
Date:   Sun Jan 2 12:22:44 2011 +0200

    server/tests/test_display_no_ssl: add update_area, COPY_BITS to tested functions, make a queue of QXLCommandExt waiting (cursor still with production at get_command)

diff --git a/server/tests/test_display_no_ssl.c b/server/tests/test_display_no_ssl.c
index de89949..682008b 100644
--- a/server/tests/test_display_no_ssl.c
+++ b/server/tests/test_display_no_ssl.c
@@ -30,7 +30,9 @@ void test_spice_destroy_update(SimpleSpiceUpdate *update)
     if (!update) {
         return;
     }
-    free(update->bitmap);
+    if (update->bitmap) {
+        free(update->bitmap);
+    }
     free(update);
 }
 
@@ -59,25 +61,53 @@ void simple_set_release_info(QXLReleaseInfo *info, intptr_t ptr)
     //info->group_id = MEM_SLOT_GROUP_ID;
 }
 
-SimpleSpiceUpdate *test_spice_create_update(uint32_t surface_id)
+typedef struct Path {
+    int t;
+    int min_t;
+    int max_t;
+} Path;
+
+void path_init(Path *path, int min, int max)
+{
+    path->t = min;
+    path->min_t = min;
+    path->max_t = max;
+}
+
+void path_progress(Path *path)
+{
+    path->t = (path->t+1)% (path->max_t - path->min_t) + path->min_t;
+}
+
+Path path;
+
+void draw_pos(int t, int *x, int *y)
+{
+#ifdef CIRCLE
+    *y = HEIGHT/2 + (HEIGHT/3)*cos(t*2*M_PI/angle_parts);
+    *x = WIDTH/2 + (WIDTH/3)*sin(t*2*M_PI/angle_parts);
+#else
+    *y = HEIGHT*(t % SINGLE_PART)/SINGLE_PART;
+    *x = ((WIDTH/SINGLE_PART)*(t / SINGLE_PART)) % WIDTH;
+#endif
+}
+
+SimpleSpiceUpdate *test_spice_create_update_draw(uint32_t surface_id, int t)
 {
     SimpleSpiceUpdate *update;
     QXLDrawable *drawable;
     QXLImage *image;
+    int top, left;
+    draw_pos(t, &left, &top);
     QXLRect bbox = {
-#ifdef CIRCLE
-        .top = HEIGHT/2 + (HEIGHT/3)*cos(angle*2*M_PI/angle_parts),
-        .left = WIDTH/2 + (WIDTH/3)*sin(angle*2*M_PI/angle_parts),
-#else
-        .top = HEIGHT*(angle % SINGLE_PART)/SINGLE_PART,
-        .left = ((WIDTH/SINGLE_PART)*(angle / SINGLE_PART)) % WIDTH,
-#endif
+        .top = top,
+        .left = left,
     };
     uint8_t *dst;
     int bw, bh;
     int i;
 
-    if ((angle++ % angle_parts) == 0) {
+    if ((t % angle_parts) == 0) {
         c_i++;
     }
     color = (color + 1) % 2;
@@ -133,6 +163,45 @@ SimpleSpiceUpdate *test_spice_create_update(uint32_t surface_id)
     return update;
 }
 
+SimpleSpiceUpdate *test_spice_create_update_copy_bits(uint32_t surface_id)
+{
+    SimpleSpiceUpdate *update;
+    QXLDrawable *drawable;
+    int bw, bh;
+    QXLRect bbox = {
+        .left = 10,
+        .top = 0,
+    };
+
+    update   = calloc(sizeof(*update), 1);
+    drawable = &update->drawable;
+
+    bw       = WIDTH/SINGLE_PART;
+    bh       = 48;
+    bbox.right = bbox.left + bw;
+    bbox.bottom = bbox.top + bh;
+    //printf("allocated %p, %p\n", update, update->bitmap);
+
+    drawable->surface_id      = surface_id;
+
+    drawable->bbox            = bbox;
+    drawable->clip.type       = SPICE_CLIP_TYPE_NONE;
+    drawable->effect          = QXL_EFFECT_OPAQUE;
+    simple_set_release_info(&drawable->release_info, (intptr_t)update);
+    drawable->type            = QXL_COPY_BITS;
+    drawable->surfaces_dest[0] = -1;
+    drawable->surfaces_dest[1] = -1;
+    drawable->surfaces_dest[2] = -1;
+
+    drawable->u.copy_bits.src_pos.x = 0;
+    drawable->u.copy_bits.src_pos.y = 0;
+
+    set_cmd(&update->ext, QXL_CMD_DRAW, (intptr_t)drawable);
+
+    return update;
+}
+
+
 /*
 void dispatch_update_area(QXLWorker *worker)
 {
@@ -242,47 +311,108 @@ void get_init_info(QXLInstance *qin, QXLDevInitInfo *info)
     info->n_surfaces = MAX_SURFACE_NUM;
 }
 
-#define NOTIFY_DISPLAY_BATCH (SINGLE_PART*2)
+#define NOTIFY_DISPLAY_BATCH (SINGLE_PART/2)
 #define NOTIFY_CURSOR_BATCH 0
 
-int notify = NOTIFY_DISPLAY_BATCH;
 int cursor_notify = NOTIFY_CURSOR_BATCH;
 
 // simple queue for commands
 enum {
+    PATH_PROGRESS,
     SIMPLE_CREATE_SURFACE,
     SIMPLE_DRAW,
-    SIMPLE_DESTROY_SURFACE
+    SIMPLE_COPY_BITS,
+    SIMPLE_DESTROY_SURFACE,
+    SIMPLE_UPDATE,
 };
 
-int commands[] = {
+int simple_commands[] = {
     //SIMPLE_CREATE_SURFACE,
     //SIMPLE_DRAW,
     //SIMPLE_DESTROY_SURFACE,
     SIMPLE_DRAW,
+    SIMPLE_COPY_BITS,
+    SIMPLE_UPDATE,
 };
 
-#define NUM_COMMANDS (sizeof(commands)/sizeof(commands[0]))
+
+#define COUNT(x) ((sizeof(x)/sizeof(x[0])))
+#define NUM_SIMPLE_COMMANDS COUNT(simple_commands)
 
 #define SURF_WIDTH 320
 #define SURF_HEIGHT 240
 uint8_t secondary_surface[SURF_WIDTH * SURF_HEIGHT * 4];
 
+// We shall now have a ring of commands, so that we can update
+// it from a separate thread - since get_command is called from
+// the worker thread, and we need to sometimes do an update_area,
+// which cannot be done from red_worker context (not via dispatcher,
+// since you get a deadlock, and it isn't designed to be done
+// any other way, so no point testing that).
+int commands_end = 0;
+int commands_start = 0;
+struct QXLCommandExt* commands[1024];
+
+#define COMMANDS_SIZE COUNT(commands)
+
+void push_command(QXLCommandExt *ext)
+{
+    ASSERT(commands_end - commands_start < COMMANDS_SIZE);
+    commands[commands_end%COMMANDS_SIZE] = ext;
+    commands_end++;
+}
+
+struct QXLCommandExt *get_simple_command()
+{
+    struct QXLCommandExt *ret = commands[commands_start%COMMANDS_SIZE];
+    ASSERT(commands_start < commands_end);
+    commands_start++;
+    return ret;
+}
+
+int num_commands()
+{
+    return commands_end - commands_start;
+}
+
 // called from spice_server thread (i.e. red_worker thread)
 int get_command(QXLInstance *qin, struct QXLCommandExt *ext)
 {
-    static int cmd_index = 0;
-    static uint32_t target_surface = 0;
-
-    if (!notify) {
+    if (num_commands() == 0) {
         return FALSE;
     }
-    notify--;
-    switch (commands[cmd_index]) {
+    *ext = *get_simple_command();
+    return TRUE;
+}
+
+void produce_command()
+{
+    static int target_surface = 0;
+    static int simple_command_index = 0;
+    static int cmd_index = 0;
+
+    switch (simple_commands[cmd_index]) {
+        case PATH_PROGRESS:
+            path_progress(&path);
+            break;
+        case SIMPLE_UPDATE: {
+            QXLRect rect = {.left = 0, .right = WIDTH,
+                            .top = 0, .bottom = HEIGHT};
+            qxl_worker->update_area(qxl_worker, 0, &rect, NULL, 0, 1);
+            break;
+        }
+        case SIMPLE_COPY_BITS:
         case SIMPLE_DRAW: {
             SimpleSpiceUpdate *update;
-            update = test_spice_create_update(target_surface);
-            *ext = update->ext;
+            switch (simple_commands[cmd_index]) {
+                case SIMPLE_COPY_BITS:
+                    update = test_spice_create_update_copy_bits(target_surface);
+                    break;
+                case SIMPLE_DRAW:
+                    update = test_spice_create_update_draw(target_surface, path.t);
+                    break;
+            }
+            push_command(&update->ext);
             break;
         }
         case SIMPLE_CREATE_SURFACE: {
@@ -290,22 +420,20 @@ int get_command(QXLInstance *qin, struct QXLCommandExt *ext)
             target_surface = MAX_SURFACE_NUM - 1;
             update = create_surface(target_surface, SURF_WIDTH, SURF_HEIGHT,
                                     secondary_surface);
-            *ext = update->ext;
+            push_command(&update->ext);
             break;
         }
         case SIMPLE_DESTROY_SURFACE: {
             SimpleSurfaceCmd *update;
             update = destroy_surface(target_surface);
             target_surface = 0;
-            *ext = update->ext;
+            push_command(&update->ext);
             break;
         }
     }
-    cmd_index = (cmd_index + 1) % NUM_COMMANDS;
-    return TRUE;
+    cmd_index = (cmd_index + 1) % NUM_SIMPLE_COMMANDS;
 }
 
-
 SpiceTimer *wakeup_timer;
 int wakeup_ms = 500;
 
@@ -317,8 +445,13 @@ int req_cmd_notification(QXLInstance *qin)
 
 void do_wakeup()
 {
-    notify = NOTIFY_DISPLAY_BATCH;
+    int notify;
     cursor_notify = NOTIFY_CURSOR_BATCH;
+
+    for (notify = NOTIFY_DISPLAY_BATCH; notify > 0;--notify) {
+        produce_command();
+    }
+
     core->timer_start(wakeup_timer, wakeup_ms);
     qxl_worker->wakeup(qxl_worker);
 }
@@ -463,6 +596,7 @@ int main()
 {
     core = basic_event_loop_init();
     server = spice_server_new();
+    path_init(&path, 0, angle_parts);
     bzero(primary_surface, sizeof(primary_surface));
     bzero(secondary_surface, sizeof(secondary_surface));
     spice_server_set_port(server, 5912);
commit 92e4ab6d68bae178c32f01413c9db993aa1755f2
Author: Alon Levy <alevy at redhat.com>
Date:   Mon Dec 20 17:18:44 2010 +0200

    server/tests/test_display_no_ssl: add surface create/destroy test (commented out), and square mode (default)

diff --git a/server/tests/test_display_no_ssl.c b/server/tests/test_display_no_ssl.c
index 54e9949..de89949 100644
--- a/server/tests/test_display_no_ssl.c
+++ b/server/tests/test_display_no_ssl.c
@@ -9,15 +9,22 @@
 #include "test_util.h"
 #include "basic_event_loop.h"
 
+#define MEM_SLOT_GROUP_ID 0
+
 /* Parts cribbed from spice-display.h/.c/qxl.c */
 
 typedef struct SimpleSpiceUpdate {
+    QXLCommandExt ext; // first
     QXLDrawable drawable;
     QXLImage image;
-    QXLCommandExt ext;
     uint8_t *bitmap;
 } SimpleSpiceUpdate;
 
+typedef struct SimpleSurfaceCmd {
+    QXLCommandExt ext; // first
+    QXLSurfaceCmd surface_cmd;
+} SimpleSurfaceCmd;
+
 void test_spice_destroy_update(SimpleSpiceUpdate *update)
 {
     if (!update) {
@@ -30,28 +37,47 @@ void test_spice_destroy_update(SimpleSpiceUpdate *update)
 #define WIDTH 320
 #define HEIGHT 320
 
-static int angle_parts = 64;
+#define SINGLE_PART 8
+static const int angle_parts = 64 / SINGLE_PART;
 static int angle = 0;
 static int unique = 1;
-static int color = 0;
+static int color = -1;
 static int c_i = 0;
 
-SimpleSpiceUpdate *test_spice_create_update()
+void set_cmd(QXLCommandExt *ext, uint32_t type, QXLPHYSICAL data)
+{
+    ext->cmd.type = type;
+    ext->cmd.data = data;
+    ext->cmd.padding = 0;
+    ext->group_id = MEM_SLOT_GROUP_ID;
+    ext->flags = 0;
+}
+
+void simple_set_release_info(QXLReleaseInfo *info, intptr_t ptr)
+{
+    info->id = ptr;
+    //info->group_id = MEM_SLOT_GROUP_ID;
+}
+
+SimpleSpiceUpdate *test_spice_create_update(uint32_t surface_id)
 {
     SimpleSpiceUpdate *update;
     QXLDrawable *drawable;
     QXLImage *image;
-    QXLCommand *cmd;
     QXLRect bbox = {
+#ifdef CIRCLE
         .top = HEIGHT/2 + (HEIGHT/3)*cos(angle*2*M_PI/angle_parts),
         .left = WIDTH/2 + (WIDTH/3)*sin(angle*2*M_PI/angle_parts),
+#else
+        .top = HEIGHT*(angle % SINGLE_PART)/SINGLE_PART,
+        .left = ((WIDTH/SINGLE_PART)*(angle / SINGLE_PART)) % WIDTH,
+#endif
     };
     uint8_t *dst;
     int bw, bh;
     int i;
 
-    angle++;
-    if ((angle % angle_parts) == 0) {
+    if ((angle++ % angle_parts) == 0) {
         c_i++;
     }
     color = (color + 1) % 2;
@@ -60,19 +86,20 @@ SimpleSpiceUpdate *test_spice_create_update()
     update   = calloc(sizeof(*update), 1);
     drawable = &update->drawable;
     image    = &update->image;
-    cmd      = &update->ext.cmd;
 
-    bw       = 64;
+    bw       = WIDTH/SINGLE_PART;
     bh       = 48;
     bbox.right = bbox.left + bw;
     bbox.bottom = bbox.top + bh;
     update->bitmap = malloc(bw * bh * 4);
     //printf("allocated %p, %p\n", update, update->bitmap);
 
+    drawable->surface_id      = surface_id;
+
     drawable->bbox            = bbox;
     drawable->clip.type       = SPICE_CLIP_TYPE_NONE;
     drawable->effect          = QXL_EFFECT_OPAQUE;
-    drawable->release_info.id = (intptr_t)update;
+    simple_set_release_info(&drawable->release_info, (intptr_t)update);
     drawable->type            = QXL_DRAW_COPY;
     drawable->surfaces_dest[0] = -1;
     drawable->surfaces_dest[1] = -1;
@@ -101,13 +128,53 @@ SimpleSpiceUpdate *test_spice_create_update()
         *(dst+((3+c_i)%3)) = 0;
     }
 
-    cmd->type = QXL_CMD_DRAW;
-    cmd->data = (intptr_t)drawable;
+    set_cmd(&update->ext, QXL_CMD_DRAW, (intptr_t)drawable);
 
     return update;
 }
 
-#define MEM_SLOT_GROUP_ID 0
+/*
+void dispatch_update_area(QXLWorker *worker)
+{
+    worker->update_area();
+}
+
+ update_area()
+{
+    QXL_CMD_UPDATE
+}
+*/
+
+SimpleSurfaceCmd *create_surface(int surface_id, int width, int height, uint8_t *data)
+{
+    SimpleSurfaceCmd *simple_cmd = calloc(sizeof(SimpleSurfaceCmd), 1);
+    QXLSurfaceCmd *surface_cmd = &simple_cmd->surface_cmd;
+
+    set_cmd(&simple_cmd->ext, QXL_CMD_SURFACE, (intptr_t)surface_cmd);
+    simple_set_release_info(&surface_cmd->release_info, (intptr_t)simple_cmd);
+    surface_cmd->type = QXL_SURFACE_CMD_CREATE;
+    surface_cmd->flags = 0; // ?
+    surface_cmd->surface_id = surface_id;
+    surface_cmd->u.surface_create.format = SPICE_SURFACE_FMT_32_xRGB;
+    surface_cmd->u.surface_create.width = width;
+    surface_cmd->u.surface_create.height = height;
+    surface_cmd->u.surface_create.stride = -width * 4;
+    surface_cmd->u.surface_create.data = (intptr_t)data;
+    return simple_cmd;
+}
+
+SimpleSurfaceCmd *destroy_surface(int surface_id)
+{
+    SimpleSurfaceCmd *simple_cmd = calloc(sizeof(SimpleSurfaceCmd), 1);
+    QXLSurfaceCmd *surface_cmd = &simple_cmd->surface_cmd;
+
+    set_cmd(&simple_cmd->ext, QXL_CMD_SURFACE, (intptr_t)surface_cmd);
+    simple_set_release_info(&surface_cmd->release_info, (intptr_t)simple_cmd);
+    surface_cmd->type = QXL_SURFACE_CMD_DESTROY;
+    surface_cmd->flags = 0; // ?
+    surface_cmd->surface_id = surface_id;
+    return simple_cmd;
+}
 
 static QXLWorker *qxl_worker = NULL;
 static uint8_t primary_surface[HEIGHT * WIDTH * 4];
@@ -162,6 +229,9 @@ void set_mm_time(QXLInstance *qin, uint32_t mm_time)
 {
 }
 
+// we now have a secondary surface
+#define MAX_SURFACE_NUM 2
+
 void get_init_info(QXLInstance *qin, QXLDevInitInfo *info)
 {
     bzero(info, sizeof(*info));
@@ -169,31 +239,75 @@ void get_init_info(QXLInstance *qin, QXLDevInitInfo *info)
     info->num_memslots_groups = 1;
     info->memslot_id_bits = 1;
     info->memslot_gen_bits = 1;
-    info->n_surfaces = 1;
+    info->n_surfaces = MAX_SURFACE_NUM;
 }
 
-#define NOTIFY_DISPLAY_BATCH 10
+#define NOTIFY_DISPLAY_BATCH (SINGLE_PART*2)
 #define NOTIFY_CURSOR_BATCH 0
 
 int notify = NOTIFY_DISPLAY_BATCH;
 int cursor_notify = NOTIFY_CURSOR_BATCH;
 
+// simple queue for commands
+enum {
+    SIMPLE_CREATE_SURFACE,
+    SIMPLE_DRAW,
+    SIMPLE_DESTROY_SURFACE
+};
+
+int commands[] = {
+    //SIMPLE_CREATE_SURFACE,
+    //SIMPLE_DRAW,
+    //SIMPLE_DESTROY_SURFACE,
+    SIMPLE_DRAW,
+};
+
+#define NUM_COMMANDS (sizeof(commands)/sizeof(commands[0]))
+
+#define SURF_WIDTH 320
+#define SURF_HEIGHT 240
+uint8_t secondary_surface[SURF_WIDTH * SURF_HEIGHT * 4];
+
+// called from spice_server thread (i.e. red_worker thread)
 int get_command(QXLInstance *qin, struct QXLCommandExt *ext)
 {
-    SimpleSpiceUpdate *update;
+    static int cmd_index = 0;
+    static uint32_t target_surface = 0;
 
     if (!notify) {
         return FALSE;
     }
     notify--;
-    update = test_spice_create_update();
-    *ext = update->ext;
+    switch (commands[cmd_index]) {
+        case SIMPLE_DRAW: {
+            SimpleSpiceUpdate *update;
+            update = test_spice_create_update(target_surface);
+            *ext = update->ext;
+            break;
+        }
+        case SIMPLE_CREATE_SURFACE: {
+            SimpleSurfaceCmd *update;
+            target_surface = MAX_SURFACE_NUM - 1;
+            update = create_surface(target_surface, SURF_WIDTH, SURF_HEIGHT,
+                                    secondary_surface);
+            *ext = update->ext;
+            break;
+        }
+        case SIMPLE_DESTROY_SURFACE: {
+            SimpleSurfaceCmd *update;
+            update = destroy_surface(target_surface);
+            target_surface = 0;
+            *ext = update->ext;
+            break;
+        }
+    }
+    cmd_index = (cmd_index + 1) % NUM_COMMANDS;
     return TRUE;
 }
 
 
 SpiceTimer *wakeup_timer;
-int wakeup_ms = 100;
+int wakeup_ms = 500;
 
 int req_cmd_notification(QXLInstance *qin)
 {
@@ -211,9 +325,19 @@ void do_wakeup()
 
 void release_resource(QXLInstance *qin, struct QXLReleaseInfoExt release_info)
 {
+    QXLCommandExt *ext = (void*)release_info.info->id;
     //printf("%s\n", __func__);
     ASSERT(release_info.group_id == MEM_SLOT_GROUP_ID);
-    test_spice_destroy_update((void*)release_info.info->id);
+    switch (ext->cmd.type) {
+        case QXL_CMD_DRAW:
+            test_spice_destroy_update((void*)ext);
+            break;
+        case QXL_CMD_SURFACE:
+            free(ext);
+            break;
+        default:
+            abort();
+    }
 }
 
 #define CURSOR_WIDTH 32
@@ -340,6 +464,7 @@ int main()
     core = basic_event_loop_init();
     server = spice_server_new();
     bzero(primary_surface, sizeof(primary_surface));
+    bzero(secondary_surface, sizeof(secondary_surface));
     spice_server_set_port(server, 5912);
     spice_server_set_noauth(server);
     spice_server_init(server, core);
commit 212481878827ce2436355f4d92274d6ec34cc57b
Author: Alon Levy <alevy at redhat.com>
Date:   Mon Dec 20 11:56:12 2010 +0200

    server/tests: fix timer reset to allow setting next call during callback

diff --git a/server/tests/basic_event_loop.c b/server/tests/basic_event_loop.c
index a50a916..99c086c 100644
--- a/server/tests/basic_event_loop.c
+++ b/server/tests/basic_event_loop.c
@@ -277,8 +277,8 @@ void timeout_timers()
         if (next->ms && left.tv_usec == 0 && left.tv_sec == 0) {
             count++;
             DPRINTF(1, "calling timer");
-            next->func(next->opaque);
             next->ms = 0;
+            next->func(next->opaque);
         }
         next = (SpiceTimer*)ring_next(&timers, &next->link);
     }
commit c1846506deda818d00a078c482b094bbd3e3f29f
Author: Alon Levy <alevy at redhat.com>
Date:   Sun Dec 19 22:57:42 2010 +0200

    server/tests/test_display_no_ssl: change color every circle

diff --git a/server/tests/test_display_no_ssl.c b/server/tests/test_display_no_ssl.c
index 8d72dfd..54e9949 100644
--- a/server/tests/test_display_no_ssl.c
+++ b/server/tests/test_display_no_ssl.c
@@ -30,9 +30,11 @@ void test_spice_destroy_update(SimpleSpiceUpdate *update)
 #define WIDTH 320
 #define HEIGHT 320
 
-static float angle = 0;
+static int angle_parts = 64;
+static int angle = 0;
 static int unique = 1;
 static int color = 0;
+static int c_i = 0;
 
 SimpleSpiceUpdate *test_spice_create_update()
 {
@@ -41,14 +43,17 @@ SimpleSpiceUpdate *test_spice_create_update()
     QXLImage *image;
     QXLCommand *cmd;
     QXLRect bbox = {
-        .top = HEIGHT/2 + (HEIGHT/3)*cos(angle),
-        .left = WIDTH/2 + (WIDTH/3)*sin(angle),
+        .top = HEIGHT/2 + (HEIGHT/3)*cos(angle*2*M_PI/angle_parts),
+        .left = WIDTH/2 + (WIDTH/3)*sin(angle*2*M_PI/angle_parts),
     };
     uint8_t *dst;
     int bw, bh;
     int i;
 
-    angle += 0.2;
+    angle++;
+    if ((angle % angle_parts) == 0) {
+        c_i++;
+    }
     color = (color + 1) % 2;
     unique++;
 
@@ -91,9 +96,9 @@ SimpleSpiceUpdate *test_spice_create_update()
     dst = update->bitmap;
     for (i = 0 ; i < bh * bw ; ++i, dst+=4) {
         *dst = (color+i % 255);
-        *(dst+1) = 255 - color;
-        *(dst+2) = (color * (color + i)) & 0xff;
-        *(dst+3) = 0;
+        *(dst+((1+c_i)%3)) = 255 - color;
+        *(dst+((2+c_i)%3)) = (color * (color + i)) & 0xff;
+        *(dst+((3+c_i)%3)) = 0;
     }
 
     cmd->type = QXL_CMD_DRAW;
@@ -167,7 +172,7 @@ void get_init_info(QXLInstance *qin, QXLDevInitInfo *info)
     info->n_surfaces = 1;
 }
 
-#define NOTIFY_DISPLAY_BATCH 1
+#define NOTIFY_DISPLAY_BATCH 10
 #define NOTIFY_CURSOR_BATCH 0
 
 int notify = NOTIFY_DISPLAY_BATCH;
@@ -188,7 +193,7 @@ int get_command(QXLInstance *qin, struct QXLCommandExt *ext)
 
 
 SpiceTimer *wakeup_timer;
-int wakeup_ms = 500;
+int wakeup_ms = 100;
 
 int req_cmd_notification(QXLInstance *qin)
 {
commit 618d13d4d1fd8b493ec1e2035c538837a038c5c5
Author: Alon Levy <alevy at redhat.com>
Date:   Tue Dec 14 10:24:51 2010 +0200

    server/tests/test_display_no_ssl: restart notify timer

diff --git a/server/tests/test_display_no_ssl.c b/server/tests/test_display_no_ssl.c
index be1c000..8d72dfd 100644
--- a/server/tests/test_display_no_ssl.c
+++ b/server/tests/test_display_no_ssl.c
@@ -183,7 +183,6 @@ int get_command(QXLInstance *qin, struct QXLCommandExt *ext)
     notify--;
     update = test_spice_create_update();
     *ext = update->ext;
-    notify = FALSE;
     return TRUE;
 }
 
@@ -201,6 +200,7 @@ void do_wakeup()
 {
     notify = NOTIFY_DISPLAY_BATCH;
     cursor_notify = NOTIFY_CURSOR_BATCH;
+    core->timer_start(wakeup_timer, wakeup_ms);
     qxl_worker->wakeup(qxl_worker);
 }
 
commit 0707feca4351585fb1d54cdc27f7c7838fd16386
Author: Alon Levy <alevy at redhat.com>
Date:   Tue Dec 14 10:24:33 2010 +0200

    server/tests: basic_event_loop: reset timer after firing it

diff --git a/server/tests/basic_event_loop.c b/server/tests/basic_event_loop.c
index f6570ff..a50a916 100644
--- a/server/tests/basic_event_loop.c
+++ b/server/tests/basic_event_loop.c
@@ -278,6 +278,7 @@ void timeout_timers()
             count++;
             DPRINTF(1, "calling timer");
             next->func(next->opaque);
+            next->ms = 0;
         }
         next = (SpiceTimer*)ring_next(&timers, &next->link);
     }
commit 9cdeac5da59b6f695c14cc315c8593160d04ca9d
Author: Alon Levy <alevy at redhat.com>
Date:   Sun Dec 5 19:59:55 2010 +0200

    server/tests/test_display_no_ssl: disable cursor test until it works correctly

diff --git a/server/tests/test_display_no_ssl.c b/server/tests/test_display_no_ssl.c
index d531fb7..be1c000 100644
--- a/server/tests/test_display_no_ssl.c
+++ b/server/tests/test_display_no_ssl.c
@@ -167,8 +167,8 @@ void get_init_info(QXLInstance *qin, QXLDevInitInfo *info)
     info->n_surfaces = 1;
 }
 
-#define NOTIFY_DISPLAY_BATCH 0
-#define NOTIFY_CURSOR_BATCH 1
+#define NOTIFY_DISPLAY_BATCH 1
+#define NOTIFY_CURSOR_BATCH 0
 
 int notify = NOTIFY_DISPLAY_BATCH;
 int cursor_notify = NOTIFY_CURSOR_BATCH;
commit 4dcacefb06eb41f0a4f1c7ae3a33b9259415dcbb
Author: Alon Levy <alevy at redhat.com>
Date:   Thu Dec 2 22:01:59 2010 +0200

    server/test/test_display_no_ssl: add beginning of basic cursor item test. doesn't actually show anything on client. also, leaks.

diff --git a/server/tests/test_display_no_ssl.c b/server/tests/test_display_no_ssl.c
index 5198926..d531fb7 100644
--- a/server/tests/test_display_no_ssl.c
+++ b/server/tests/test_display_no_ssl.c
@@ -20,6 +20,9 @@ typedef struct SimpleSpiceUpdate {
 
 void test_spice_destroy_update(SimpleSpiceUpdate *update)
 {
+    if (!update) {
+        return;
+    }
     free(update->bitmap);
     free(update);
 }
@@ -164,17 +167,20 @@ void get_init_info(QXLInstance *qin, QXLDevInitInfo *info)
     info->n_surfaces = 1;
 }
 
-#define NOTIFY_BATCH 1
+#define NOTIFY_DISPLAY_BATCH 0
+#define NOTIFY_CURSOR_BATCH 1
 
-int notify = NOTIFY_BATCH;
+int notify = NOTIFY_DISPLAY_BATCH;
+int cursor_notify = NOTIFY_CURSOR_BATCH;
 
 int get_command(QXLInstance *qin, struct QXLCommandExt *ext)
 {
     SimpleSpiceUpdate *update;
 
-    if (!notify--) {
+    if (!notify) {
         return FALSE;
     }
+    notify--;
     update = test_spice_create_update();
     *ext = update->ext;
     notify = FALSE;
@@ -193,7 +199,8 @@ int req_cmd_notification(QXLInstance *qin)
 
 void do_wakeup()
 {
-    notify = NOTIFY_BATCH;
+    notify = NOTIFY_DISPLAY_BATCH;
+    cursor_notify = NOTIFY_CURSOR_BATCH;
     qxl_worker->wakeup(qxl_worker);
 }
 
@@ -204,10 +211,64 @@ void release_resource(QXLInstance *qin, struct QXLReleaseInfoExt release_info)
     test_spice_destroy_update((void*)release_info.info->id);
 }
 
-int get_cursor_command(QXLInstance *qin, struct QXLCommandExt *cmd)
+#define CURSOR_WIDTH 32
+#define CURSOR_HEIGHT 32
+
+static struct {
+    QXLCursor cursor;
+    uint8_t data[CURSOR_WIDTH * CURSOR_HEIGHT * 4]; // 32bit per pixel
+} cursor;
+
+void init_cursor()
+{
+    cursor.cursor.header.unique = 0; // TODO ??
+    cursor.cursor.header.type = SPICE_CURSOR_TYPE_COLOR32;
+    cursor.cursor.header.width = CURSOR_WIDTH;
+    cursor.cursor.header.height = CURSOR_HEIGHT;
+    cursor.cursor.header.hot_spot_x = 0;
+    cursor.cursor.header.hot_spot_y = 0;
+    cursor.cursor.data_size = CURSOR_WIDTH * CURSOR_HEIGHT;
+    cursor.cursor.chunk.data_size = cursor.cursor.data_size;
+    cursor.cursor.chunk.prev_chunk = cursor.cursor.chunk.next_chunk = 0;
+}
+
+int get_cursor_command(QXLInstance *qin, struct QXLCommandExt *ext)
 {
+    static int color = 0;
+    QXLCursorCmd *cursor_cmd;
+    int i, x, y, p;
+    QXLCommandExt cmd;
+
+    if (!cursor_notify) {
+        return FALSE;
+    }
+    cursor_notify--;
+    cursor_cmd = calloc(sizeof(QXLCursorCmd), 1);
+    color = 100 + ((color + 1) % 100);
+    cursor_cmd->type = QXL_CURSOR_SET;
+    cursor_cmd->release_info.id = 0; // TODO: we leak the QXLCommandExt's
+    cursor_cmd->u.set.position.x = 0;
+    cursor_cmd->u.set.position.y = 0;
+    cursor_cmd->u.set.visible = TRUE;
+    cursor_cmd->u.set.shape = (uint64_t)&cursor;
+    for (x = 0 ; x < CURSOR_WIDTH; ++x) {
+        for (y = 0 ; y < CURSOR_HEIGHT; ++y) {
+            p = 0;
+            cursor.data[p] = (y*10 > color) ? color : 0;
+            cursor.data[p+1] = cursor.data[p+2] = cursor.data[p+3] = 0;
+        }
+    }
+    // TODO - shape has the, well, shape. device_data has?
+    for (i = 0 ; i < QXL_CURSUR_DEVICE_DATA_SIZE ; ++i) {
+        cursor_cmd->device_data[i] = color;
+    }
+    cmd.cmd.data = (uint64_t)cursor_cmd;
+    cmd.cmd.type = QXL_CMD_CURSOR;
+    cmd.group_id = MEM_SLOT_GROUP_ID;
+    cmd.flags    = 0; // TODO - cursor flags (qxl->cmdflags in qxl/pointer.c)?
+    *ext = cmd;
     //printf("%s\n", __func__);
-    return FALSE;
+    return TRUE;
 }
 
 int req_cursor_notification(QXLInstance *qin)
commit e62f4b6fc7e6962ed1c664f380c24dd9e35bca34
Author: Alon Levy <alevy at redhat.com>
Date:   Wed Nov 24 17:39:30 2010 +0200

    server/tests/test_display_no_ssl: make window 320x320, two colored updates, one in notify batch

diff --git a/server/tests/test_display_no_ssl.c b/server/tests/test_display_no_ssl.c
index 7edc8dc..5198926 100644
--- a/server/tests/test_display_no_ssl.c
+++ b/server/tests/test_display_no_ssl.c
@@ -24,8 +24,8 @@ void test_spice_destroy_update(SimpleSpiceUpdate *update)
     free(update);
 }
 
-#define WIDTH 800
-#define HEIGHT 600
+#define WIDTH 320
+#define HEIGHT 320
 
 static float angle = 0;
 static int unique = 1;
@@ -45,8 +45,8 @@ SimpleSpiceUpdate *test_spice_create_update()
     int bw, bh;
     int i;
 
-    angle += 0.1;
-    color = (color + 1) % 10;
+    angle += 0.2;
+    color = (color + 1) % 2;
     unique++;
 
     update   = calloc(sizeof(*update), 1);
@@ -164,7 +164,7 @@ void get_init_info(QXLInstance *qin, QXLDevInitInfo *info)
     info->n_surfaces = 1;
 }
 
-#define NOTIFY_BATCH 5
+#define NOTIFY_BATCH 1
 
 int notify = NOTIFY_BATCH;
 


More information about the Spice-commits mailing list