[Spice-commits] 2 commits - server/tests

Alon Levy alon at kemper.freedesktop.org
Thu Mar 22 02:18:56 PDT 2012


 server/tests/Makefile.am                       |   20 +++-
 server/tests/test_display_base.c               |  110 +++++++++++++++++--------
 server/tests/test_display_base.h               |   36 +++++---
 server/tests/test_display_resolution_changes.c |   66 +++++++++++++++
 4 files changed, 181 insertions(+), 51 deletions(-)

New commits:
commit a7d3f1de82e90da869775e8306e0dba7d95bd597
Author: Alon Levy <alevy at redhat.com>
Date:   Thu Mar 22 00:15:34 2012 +0200

    server/tests: add resolution changes tester

diff --git a/server/tests/Makefile.am b/server/tests/Makefile.am
index 61fad75..52e55a8 100644
--- a/server/tests/Makefile.am
+++ b/server/tests/Makefile.am
@@ -24,13 +24,14 @@ COMMON_BASE =					\
 	test_util.h				\
 	$(NULL)
 
-noinst_PROGRAMS =				\
-	test_display_no_ssl			\
-	test_display_streaming			\
-	test_empty_success			\
+noinst_PROGRAMS =						\
+	test_display_no_ssl					\
+	test_display_streaming				\
+	test_empty_success					\
 	test_fail_on_null_core_interface	\
-	test_just_sockets_no_ssl		\
-	test_playback				\
+	test_just_sockets_no_ssl			\
+	test_playback						\
+	test_display_resolution_changes		\
 	$(NULL)
 
 test_display_streaming_SOURCES =		\
@@ -47,6 +48,13 @@ test_display_no_ssl_SOURCES =			\
 	test_display_no_ssl.c 			\
 	$(NULL)
 
+test_display_resolution_changes_SOURCES = \
+	$(COMMON_BASE)				\
+	test_display_base.c			\
+	test_display_base.h			\
+	test_display_resolution_changes.c	 \
+	$(NULL)
+
 test_just_sockets_no_ssl_SOURCES =		\
 	$(COMMON_BASE)				\
 	test_just_sockets_no_ssl.c		\
diff --git a/server/tests/test_display_resolution_changes.c b/server/tests/test_display_resolution_changes.c
new file mode 100644
index 0000000..edf7fb2
--- /dev/null
+++ b/server/tests/test_display_resolution_changes.c
@@ -0,0 +1,66 @@
+/**
+ * Recreate the primary surface endlessly.
+ */
+
+#include <math.h>
+#include <config.h>
+#include <stdlib.h>
+#include "test_display_base.h"
+
+SpiceServer *server;
+SpiceCoreInterface *core;
+SpiceTimer *ping_timer;
+
+void show_channels(SpiceServer *server);
+
+int ping_ms = 100;
+
+void pinger(void *opaque)
+{
+    // show_channels is not thread safe - fails if disconnections / connections occur
+    //show_channels(server);
+
+    core->timer_start(ping_timer, ping_ms);
+}
+
+void set_primary_params(void *cb_opaque, uint64_t *arg1, uint64_t *arg2)
+{
+#if 0
+    static int toggle = 0;
+
+    if (toggle) {
+        *arg1 = 800;
+        *arg2 = 600;
+    } else {
+        *arg1 = 1024;
+        *arg2 = 768;
+    }
+    toggle = 1 - toggle;
+#endif
+    static int count = 0;
+
+    *arg1 = 800 + sin((float)count / 6) * 200;
+    *arg2 = 600 + cos((float)count / 6) * 200;
+    count++;
+}
+
+static Command commands[] = {
+    {DESTROY_PRIMARY, 0, 0, NULL, NULL},
+    {CREATE_PRIMARY, 0, 0, set_primary_params, NULL},
+};
+
+int main(void)
+{
+    core = basic_event_loop_init();
+    server = test_init(core);
+    //spice_server_set_image_compression(server, SPICE_IMAGE_COMPRESS_OFF);
+    test_add_display_interface(server);
+    test_set_command_list(commands, COUNT(commands));
+
+    ping_timer = core->timer_add(pinger, NULL);
+    core->timer_start(ping_timer, ping_ms);
+
+    basic_event_loop_mainloop();
+
+    return 0;
+}
commit a6f9797c79db969f0fe28ef30691d4c1b1002eac
Author: Alon Levy <alevy at redhat.com>
Date:   Thu Mar 22 00:14:42 2012 +0200

    server/tests/test_display_base: add Command
    
    add parameters to the commands used for display tests.

diff --git a/server/tests/test_display_base.c b/server/tests/test_display_base.c
index 3c08b0f..f6c3f6b 100644
--- a/server/tests/test_display_base.c
+++ b/server/tests/test_display_base.c
@@ -18,6 +18,12 @@
 
 #define MEM_SLOT_GROUP_ID 0
 
+#define MAX_HEIGHT 2048
+#define MAX_WIDTH 2048
+static uint8_t g_primary_surface[MAX_HEIGHT * MAX_WIDTH * 4];
+int g_primary_height;
+int g_primary_width;
+
 /* Parts cribbed from spice-display.h/.c/qxl.c */
 
 typedef struct SimpleSpiceUpdate {
@@ -41,8 +47,8 @@ static void test_spice_destroy_update(SimpleSpiceUpdate *update)
     free(update);
 }
 
-#define WIDTH 640
-#define HEIGHT 320
+#define DEFAULT_WIDTH 640
+#define DEFAULT_HEIGHT 320
 
 #define SINGLE_PART 4
 static const int angle_parts = 64 / SINGLE_PART;
@@ -126,11 +132,11 @@ 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);
+    *y = g_primary_height/2 + (g_primary_height/3)*cos(t*2*M_PI/angle_parts);
+    *x = g_primary_width/2 + (g_primary_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;
+    *y = g_primary_height*(t % SINGLE_PART)/SINGLE_PART;
+    *x = ((g_primary_width/SINGLE_PART)*(t / SINGLE_PART)) % g_primary_width;
 #endif
 }
 
@@ -165,7 +171,7 @@ static SimpleSpiceUpdate *test_spice_create_update_draw(uint32_t surface_id, int
     drawable = &update->drawable;
     image    = &update->image;
 
-    bw       = WIDTH/SINGLE_PART;
+    bw       = g_primary_width/SINGLE_PART;
     bh       = 48;
 
     bbox.right = bbox.left + bw;
@@ -225,7 +231,7 @@ static SimpleSpiceUpdate *test_spice_create_update_copy_bits(uint32_t surface_id
     update   = calloc(sizeof(*update), 1);
     drawable = &update->drawable;
 
-    bw       = WIDTH/SINGLE_PART;
+    bw       = g_primary_width/SINGLE_PART;
     bh       = 48;
     bbox.right = bbox.left + bw;
     bbox.bottom = bbox.top + bh;
@@ -282,20 +288,26 @@ static SimpleSurfaceCmd *destroy_surface(int surface_id)
 }
 
 static QXLWorker *qxl_worker = NULL;
-static uint8_t primary_surface[HEIGHT * WIDTH * 4];
 
-static void create_test_primary_surface(QXLWorker *worker)
+static void create_primary_surface(QXLWorker *worker, uint32_t width,
+                                   uint32_t height)
 {
     QXLDevSurfaceCreate surface = { 0, };
 
+    ASSERT(height <= MAX_HEIGHT);
+    ASSERT(width <= MAX_WIDTH);
+    ASSERT(height > 0);
+    ASSERT(width > 0);
+
     surface.format     = SPICE_SURFACE_FMT_32_xRGB;
-    surface.width      = WIDTH;
-    surface.height     = HEIGHT;
-    surface.stride     = -WIDTH * 4;
-    surface.mouse_mode = TRUE;
+    surface.width      = g_primary_width = width;
+    surface.height     = g_primary_height = height;
+    surface.stride     = -width * 4; /* negative? */
+    surface.mouse_mode = TRUE; /* unused by red_worker */
     surface.flags      = 0;
-    surface.type       = 0;
-    surface.mem        = (intptr_t)&primary_surface;
+    surface.type       = 0;    /* unused by red_worker */
+    surface.position   = 0;    /* unused by red_worker */
+    surface.mem        = (uint64_t)&g_primary_surface;
     surface.group_id   = MEM_SLOT_GROUP_ID;
 
     qxl_worker->create_primary_surface(qxl_worker, 0, &surface);
@@ -321,7 +333,7 @@ static void attache_worker(QXLInstance *qin, QXLWorker *_qxl_worker)
     printf("%s\n", __func__);
     qxl_worker = _qxl_worker;
     qxl_worker->add_memslot(qxl_worker, &slot);
-    create_test_primary_surface(qxl_worker);
+    create_primary_surface(qxl_worker, DEFAULT_WIDTH, DEFAULT_HEIGHT);
     qxl_worker->start(qxl_worker);
 }
 
@@ -354,7 +366,7 @@ int cursor_notify = NOTIFY_CURSOR_BATCH;
 
 #define SURF_WIDTH 320
 #define SURF_HEIGHT 240
-uint8_t secondary_surface[SURF_WIDTH * SURF_HEIGHT * 4];
+uint8_t g_secondary_surface[SURF_WIDTH * SURF_HEIGHT * 4];
 int has_secondary;
 
 // We shall now have a ring of commands, so that we can update
@@ -384,7 +396,7 @@ static struct QXLCommandExt *get_simple_command(void)
     return ret;
 }
 
-static int num_commands(void)
+static int get_num_commands(void)
 {
     return commands_end - commands_start;
 }
@@ -392,28 +404,32 @@ static int num_commands(void)
 // called from spice_server thread (i.e. red_worker thread)
 static int get_command(QXLInstance *qin, struct QXLCommandExt *ext)
 {
-    if (num_commands() == 0) {
+    if (get_num_commands() == 0) {
         return FALSE;
     }
     *ext = *get_simple_command();
     return TRUE;
 }
 
-static int *simple_commands = NULL;
-static int num_simple_commands = 0;
+static Command *g_commands = NULL;
+static int g_num_commands = 0;
 
 static void produce_command(void)
 {
     static int target_surface = 0;
     static int cmd_index = 0;
-
+    Command *command;
 
     if (has_secondary)
         target_surface = 1;
 
-    ASSERT(num_simple_commands);
+    ASSERT(g_num_commands);
 
-    switch (simple_commands[cmd_index]) {
+    command = &g_commands[cmd_index];
+    if (command->cb) {
+        command->cb(command->cb_opaque, &command->arg1, &command->arg2);
+    }
+    switch (command->command) {
         case PATH_PROGRESS:
             path_progress(&path);
             break;
@@ -437,7 +453,7 @@ static void produce_command(void)
                 regression_test();
             }
 
-            switch (simple_commands[cmd_index]) {
+            switch (command->command) {
                 case SIMPLE_COPY_BITS:
                     update = test_spice_create_update_copy_bits(0);
                     break;
@@ -453,7 +469,7 @@ static void produce_command(void)
             SimpleSurfaceCmd *update;
             target_surface = MAX_SURFACE_NUM - 1;
             update = create_surface(target_surface, SURF_WIDTH, SURF_HEIGHT,
-                                    secondary_surface);
+                                    g_secondary_surface);
             push_command(&update->ext);
             has_secondary = 1;
             break;
@@ -467,8 +483,18 @@ static void produce_command(void)
             push_command(&update->ext);
             break;
         }
+
+        case DESTROY_PRIMARY: {
+            qxl_worker->destroy_primary_surface(qxl_worker, 0);
+            break;
+        }
+
+        case CREATE_PRIMARY: {
+            create_primary_surface(qxl_worker, command->arg1, command->arg2);
+            break;
+        }
     }
-    cmd_index = (cmd_index + 1) % num_simple_commands;
+    cmd_index = (cmd_index + 1) % g_num_commands;
 }
 
 SpiceTimer *wakeup_timer;
@@ -576,8 +602,8 @@ static int get_cursor_command(QXLInstance *qin, struct QXLCommandExt *ext)
         set = 0;
     } else {
         cursor_cmd->type = QXL_CURSOR_MOVE;
-        cursor_cmd->u.position.x = x++ % WIDTH;
-        cursor_cmd->u.position.y = y++ % HEIGHT;
+        cursor_cmd->u.position.x = x++ % g_primary_width;
+        cursor_cmd->u.position.y = y++ % g_primary_height;
     }
 
     cmd->cmd.data = (unsigned long)cursor_cmd;
@@ -641,12 +667,26 @@ 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)
+void test_set_simple_command_list(int *simple_commands, int num_commands)
+{
+    int i;
+
+    /* FIXME: leaks */
+    g_commands = malloc(sizeof(*g_commands) * num_commands);
+    memset(g_commands, 0, sizeof(*g_commands) * num_commands);
+    g_num_commands = num_commands;
+    for (i = 0 ; i < num_commands; ++i) {
+        g_commands[i].command = simple_commands[i];
+    }
+}
+
+void test_set_command_list(Command *commands, int num_commands)
 {
-    simple_commands = commands;
-    num_simple_commands = num_commands;
+    g_commands = commands;
+    g_num_commands = num_commands;
 }
 
+
 SpiceServer* test_init(SpiceCoreInterface *core)
 {
     int port = 5912;
@@ -661,8 +701,8 @@ SpiceServer* test_init(SpiceCoreInterface *core)
 
     cursor_init();
     path_init(&path, 0, angle_parts);
-    memset(primary_surface, 0, sizeof(primary_surface));
-    memset(secondary_surface, 0, sizeof(secondary_surface));
+    memset(g_primary_surface, 0, sizeof(g_primary_surface));
+    memset(g_secondary_surface, 0, sizeof(g_secondary_surface));
     has_secondary = 0;
     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
index 0ed41cb..fa9fd18 100644
--- a/server/tests/test_display_base.h
+++ b/server/tests/test_display_base.h
@@ -6,20 +6,36 @@
 
 #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);
-
-void spice_test_config_parse_args(int argc, char **argv);
-
-// simple queue for commands
-enum {
+/*
+ * simple queue for commands.
+ * each command can have up to two parameters (grow as needed)
+ *
+ * TODO: switch to gtk main loop. Then add gobject-introspection. then
+ * write tests in python/guile/whatever.
+ */
+typedef enum {
     PATH_PROGRESS,
     SIMPLE_CREATE_SURFACE,
     SIMPLE_DRAW,
     SIMPLE_COPY_BITS,
     SIMPLE_DESTROY_SURFACE,
     SIMPLE_UPDATE,
-};
+    DESTROY_PRIMARY,
+    CREATE_PRIMARY,
+} CommandType;
+typedef struct Command {
+    CommandType command;
+    uint64_t arg1;
+    uint64_t arg2;
+    void (*cb)(void *cb_opaque, uint64_t *arg1, uint64_t *arg2);
+    void *cb_opaque;
+} Command;
+
+void test_set_simple_command_list(int *command, int num_commands);
+void test_set_command_list(Command *command, int num_commands);
+void test_add_display_interface(SpiceServer *server);
+SpiceServer* test_init(SpiceCoreInterface* core);
+
+void spice_test_config_parse_args(int argc, char **argv);
 
-#endif // __TEST_DISPLAY_BASE_H__
+#endif /* __TEST_DISPLAY_BASE_H__ */


More information about the Spice-commits mailing list