[Spice-commits] 5 commits - server/tests

Frediano Ziglio fziglio at kemper.freedesktop.org
Sat Sep 2 07:03:37 UTC 2017


 server/tests/test-display-base.c               |   19 ++++++++++---------
 server/tests/test-display-base.h               |    4 +---
 server/tests/test-display-no-ssl.c             |   15 +++++----------
 server/tests/test-display-resolution-changes.c |   10 +++-------
 server/tests/test-display-width-stride.c       |   10 +++-------
 server/tests/test-playback.c                   |   12 ++++++------
 server/tests/test-two-servers.c                |    8 ++++----
 server/tests/test-vdagent.c                    |    5 -----
 8 files changed, 32 insertions(+), 51 deletions(-)

New commits:
commit de88e4d6b2cedb6ab99c013647f838b4252b672b
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Fri Sep 1 14:43:26 2017 +0100

    tests: Make variables static where possible
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/tests/test-display-base.c b/server/tests/test-display-base.c
index 7d949139..26fe7c8a 100644
--- a/server/tests/test-display-base.c
+++ b/server/tests/test-display-base.c
@@ -404,7 +404,7 @@ static void create_primary_surface(Test *test, uint32_t width,
     spice_qxl_create_primary_surface(&test->qxl_instance, 0, &surface);
 }
 
-QXLDevMemSlot slot = {
+static QXLDevMemSlot slot = {
 .slot_group_id = MEM_SLOT_GROUP_ID,
 .slot_id = 0,
 .generation = 0,
@@ -464,9 +464,9 @@ static void get_init_info(SPICE_GNUC_UNUSED QXLInstance *qin,
 // 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];
+static int commands_end = 0;
+static int commands_start = 0;
+static struct QXLCommandExt* commands[1024];
 
 #define COMMANDS_SIZE G_N_ELEMENTS(commands)
 
@@ -786,7 +786,7 @@ static void set_client_capabilities(QXLInstance *qin,
     }
 }
 
-QXLInterface display_sif = {
+static QXLInterface display_sif = {
     .base = {
         .type = SPICE_INTERFACE_QXL,
         .description = "test",
@@ -852,7 +852,7 @@ static SpiceCharDeviceInterface vdagent_sif = {
 
 };
 
-SpiceCharDeviceInstance vdagent_sin = {
+static SpiceCharDeviceInstance vdagent_sin = {
     .base = {
         .sif = &vdagent_sif.base,
     },
diff --git a/server/tests/test-display-no-ssl.c b/server/tests/test-display-no-ssl.c
index 6555623a..b061d6ed 100644
--- a/server/tests/test-display-no-ssl.c
+++ b/server/tests/test-display-no-ssl.c
@@ -27,10 +27,10 @@
 #include <stdlib.h>
 #include "test-display-base.h"
 
-SpiceCoreInterface *core;
-SpiceTimer *ping_timer;
+static SpiceCoreInterface *core;
+static SpiceTimer *ping_timer;
 
-int ping_ms = 100;
+static int ping_ms = 100;
 
 static void pinger(SPICE_GNUC_UNUSED void *opaque)
 {
diff --git a/server/tests/test-display-resolution-changes.c b/server/tests/test-display-resolution-changes.c
index 14036b8c..7234cf06 100644
--- a/server/tests/test-display-resolution-changes.c
+++ b/server/tests/test-display-resolution-changes.c
@@ -24,9 +24,9 @@
 #include <stdlib.h>
 #include "test-display-base.h"
 
-SpiceTimer *ping_timer;
+static SpiceTimer *ping_timer;
 
-int ping_ms = 100;
+static int ping_ms = 100;
 
 static void pinger(void *opaque)
 {
diff --git a/server/tests/test-display-width-stride.c b/server/tests/test-display-width-stride.c
index fb4bea48..51a225d6 100644
--- a/server/tests/test-display-width-stride.c
+++ b/server/tests/test-display-width-stride.c
@@ -24,9 +24,9 @@
 #include <stdlib.h>
 #include "test-display-base.h"
 
-SpiceTimer *ping_timer;
+static SpiceTimer *ping_timer;
 
-int ping_ms = 100;
+static int ping_ms = 100;
 
 static void pinger(void *opaque)
 {
diff --git a/server/tests/test-playback.c b/server/tests/test-playback.c
index 9e53e322..9b2dcc10 100644
--- a/server/tests/test-playback.c
+++ b/server/tests/test-playback.c
@@ -34,7 +34,7 @@
  * it has actual merit. Also possibly to simulate network effects?)
  * */
 
-SpicePlaybackInstance playback_instance;
+static SpicePlaybackInstance playback_instance;
 
 static const SpicePlaybackInterface playback_sif = {
     .base = {
@@ -45,11 +45,11 @@ static const SpicePlaybackInterface playback_sif = {
     }
 };
 
-uint32_t *frame;
-uint32_t num_samples;
-SpiceTimer *playback_timer;
-int playback_timer_ms;
-SpiceCoreInterface *core;
+static uint32_t *frame;
+static uint32_t num_samples;
+static SpiceTimer *playback_timer;
+static int playback_timer_ms;
+static SpiceCoreInterface *core;
 
 static void get_frame(void)
 {
diff --git a/server/tests/test-two-servers.c b/server/tests/test-two-servers.c
index 8164df57..363238cb 100644
--- a/server/tests/test-two-servers.c
+++ b/server/tests/test-two-servers.c
@@ -23,7 +23,7 @@
 #include <stdlib.h>
 #include "test-display-base.h"
 
-SpiceCoreInterface *core;
+static SpiceCoreInterface *core;
 
 static const int simple_commands[] = {
     //SIMPLE_CREATE_SURFACE,
commit 55bb4f2395e2c819184d622c5bb49b42fbef9d19
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Fri Sep 1 14:42:04 2017 +0100

    tests: Remove unused declarations
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/tests/test-display-no-ssl.c b/server/tests/test-display-no-ssl.c
index 97673c99..6555623a 100644
--- a/server/tests/test-display-no-ssl.c
+++ b/server/tests/test-display-no-ssl.c
@@ -30,15 +30,10 @@
 SpiceCoreInterface *core;
 SpiceTimer *ping_timer;
 
-void show_channels(SpiceServer *server);
-
 int ping_ms = 100;
 
 static void pinger(SPICE_GNUC_UNUSED void *opaque)
 {
-    // show_channels is not thread safe - fails if disconnections / connections occur
-    //show_channels(server);
-
     core->timer_start(ping_timer, ping_ms);
 }
 
diff --git a/server/tests/test-display-resolution-changes.c b/server/tests/test-display-resolution-changes.c
index 2619a1ca..14036b8c 100644
--- a/server/tests/test-display-resolution-changes.c
+++ b/server/tests/test-display-resolution-changes.c
@@ -26,15 +26,11 @@
 
 SpiceTimer *ping_timer;
 
-void show_channels(SpiceServer *server);
-
 int ping_ms = 100;
 
 static void pinger(void *opaque)
 {
     Test *test = opaque;
-    // show_channels is not thread safe - fails if disconnections / connections occur
-    //show_channels(server);
 
     test->core->timer_start(ping_timer, ping_ms);
 }
diff --git a/server/tests/test-display-width-stride.c b/server/tests/test-display-width-stride.c
index 6bf54f1d..fb4bea48 100644
--- a/server/tests/test-display-width-stride.c
+++ b/server/tests/test-display-width-stride.c
@@ -26,15 +26,11 @@
 
 SpiceTimer *ping_timer;
 
-void show_channels(SpiceServer *server);
-
 int ping_ms = 100;
 
 static void pinger(void *opaque)
 {
     Test *test = opaque;
-    // show_channels is not thread safe - fails if disconnections / connections occur
-    //show_channels(server);
 
     test->core->timer_start(ping_timer, ping_ms);
 }
diff --git a/server/tests/test-vdagent.c b/server/tests/test-vdagent.c
index 232e9824..01308d0d 100644
--- a/server/tests/test-vdagent.c
+++ b/server/tests/test-vdagent.c
@@ -29,11 +29,6 @@
 #include "test-display-base.h"
 #include "test-glib-compat.h"
 
-SpiceCoreInterface *core;
-SpiceTimer *ping_timer;
-
-int ping_ms = 100;
-
 #ifndef MIN
 #define MIN(a, b) ((a) > (b) ? (b) : (a))
 #endif
commit 581b289825caa632ecaf7ab753ff82410e170343
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Fri Sep 1 14:41:22 2017 +0100

    tests: Avoid leaking list of commands
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/tests/test-display-base.c b/server/tests/test-display-base.c
index 2321ab05..7d949139 100644
--- a/server/tests/test-display-base.c
+++ b/server/tests/test-display-base.c
@@ -868,7 +868,7 @@ void test_set_simple_command_list(Test *test, const int *simple_commands, int nu
 {
     int i;
 
-    /* FIXME: leaks */
+    free(test->commands);
     test->commands = malloc(sizeof(*test->commands) * num_commands);
     memset(test->commands, 0, sizeof(*test->commands) * num_commands);
     test->num_commands = num_commands;
@@ -914,6 +914,7 @@ void test_destroy(Test *test)
 {
     test->core->timer_remove(test->wakeup_timer);
     spice_server_destroy(test->server);
+    free(test->commands);
     free(test);
 }
 
commit 69356fabcb0c75db013255deee7edda8ec8024e5
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Fri Sep 1 14:40:44 2017 +0100

    tests: Pass command list as constant
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/tests/test-display-base.c b/server/tests/test-display-base.c
index 3a8d592e..2321ab05 100644
--- a/server/tests/test-display-base.c
+++ b/server/tests/test-display-base.c
@@ -864,7 +864,7 @@ void test_add_agent_interface(SpiceServer *server)
     spice_server_add_interface(server, &vdagent_sin.base);
 }
 
-void test_set_simple_command_list(Test *test, int *simple_commands, int num_commands)
+void test_set_simple_command_list(Test *test, const int *simple_commands, int num_commands)
 {
     int i;
 
diff --git a/server/tests/test-display-base.h b/server/tests/test-display-base.h
index f4231359..1a4f20c5 100644
--- a/server/tests/test-display-base.h
+++ b/server/tests/test-display-base.h
@@ -130,7 +130,7 @@ struct Test {
     void (*on_client_disconnected)(Test *test);
 };
 
-void test_set_simple_command_list(Test *test, int *command, int num_commands);
+void test_set_simple_command_list(Test *test, const int *command, int num_commands);
 void test_set_command_list(Test *test, Command *command, int num_commands);
 void test_add_display_interface(Test *test);
 void test_add_agent_interface(SpiceServer *server); // TODO - Test *test
diff --git a/server/tests/test-display-no-ssl.c b/server/tests/test-display-no-ssl.c
index 01d1d03e..97673c99 100644
--- a/server/tests/test-display-no-ssl.c
+++ b/server/tests/test-display-no-ssl.c
@@ -42,7 +42,7 @@ static void pinger(SPICE_GNUC_UNUSED void *opaque)
     core->timer_start(ping_timer, ping_ms);
 }
 
-int simple_commands[] = {
+static const int simple_commands[] = {
     //SIMPLE_CREATE_SURFACE,
     //SIMPLE_DRAW,
     //SIMPLE_DESTROY_SURFACE,
diff --git a/server/tests/test-two-servers.c b/server/tests/test-two-servers.c
index 23cd7acd..8164df57 100644
--- a/server/tests/test-two-servers.c
+++ b/server/tests/test-two-servers.c
@@ -25,7 +25,7 @@
 
 SpiceCoreInterface *core;
 
-int simple_commands[] = {
+static const int simple_commands[] = {
     //SIMPLE_CREATE_SURFACE,
     //SIMPLE_DRAW,
     //SIMPLE_DESTROY_SURFACE,
commit ea58b27aff6479a2efeb85f4615c1870d63b71a9
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Fri Sep 1 14:39:05 2017 +0100

    tests: Reuse G_N_ELEMENTS instead of COUNT
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/tests/test-display-base.c b/server/tests/test-display-base.c
index 88638bde..3a8d592e 100644
--- a/server/tests/test-display-base.c
+++ b/server/tests/test-display-base.c
@@ -468,7 +468,7 @@ int commands_end = 0;
 int commands_start = 0;
 struct QXLCommandExt* commands[1024];
 
-#define COMMANDS_SIZE COUNT(commands)
+#define COMMANDS_SIZE G_N_ELEMENTS(commands)
 
 static void push_command(QXLCommandExt *ext)
 {
diff --git a/server/tests/test-display-base.h b/server/tests/test-display-base.h
index bdf7a11c..f4231359 100644
--- a/server/tests/test-display-base.h
+++ b/server/tests/test-display-base.h
@@ -21,8 +21,6 @@
 #include <spice.h>
 #include "basic-event-loop.h"
 
-#define COUNT(x) ((sizeof(x)/sizeof(x[0])))
-
 /*
  * simple queue for commands.
  * each command can have up to two parameters (grow as needed)
diff --git a/server/tests/test-display-no-ssl.c b/server/tests/test-display-no-ssl.c
index f4a5bea4..01d1d03e 100644
--- a/server/tests/test-display-no-ssl.c
+++ b/server/tests/test-display-no-ssl.c
@@ -61,7 +61,7 @@ int main(void)
     //spice_server_set_image_compression(server, SPICE_IMAGE_COMPRESSION_OFF);
     test_add_display_interface(test);
     test_add_agent_interface(test->server);
-    test_set_simple_command_list(test, simple_commands, COUNT(simple_commands));
+    test_set_simple_command_list(test, simple_commands, G_N_ELEMENTS(simple_commands));
 
     ping_timer = core->timer_add(pinger, NULL);
     core->timer_start(ping_timer, ping_ms);
diff --git a/server/tests/test-display-resolution-changes.c b/server/tests/test-display-resolution-changes.c
index c0aa38ff..2619a1ca 100644
--- a/server/tests/test-display-resolution-changes.c
+++ b/server/tests/test-display-resolution-changes.c
@@ -75,7 +75,7 @@ int main(void)
     test = test_new(core);
     //spice_server_set_image_compression(server, SPICE_IMAGE_COMPRESSION_OFF);
     test_add_display_interface(test);
-    test_set_command_list(test, commands, COUNT(commands));
+    test_set_command_list(test, commands, G_N_ELEMENTS(commands));
 
     ping_timer = core->timer_add(pinger, test);
     core->timer_start(ping_timer, ping_ms);
diff --git a/server/tests/test-display-width-stride.c b/server/tests/test-display-width-stride.c
index 10a55b8c..6bf54f1d 100644
--- a/server/tests/test-display-width-stride.c
+++ b/server/tests/test-display-width-stride.c
@@ -98,7 +98,7 @@ static Command commands[] = {
 
 static void on_client_connected(Test *test)
 {
-    test_set_command_list(test, commands, COUNT(commands));
+    test_set_command_list(test, commands, G_N_ELEMENTS(commands));
 }
 
 int main(void)
diff --git a/server/tests/test-two-servers.c b/server/tests/test-two-servers.c
index 4cf451a4..23cd7acd 100644
--- a/server/tests/test-two-servers.c
+++ b/server/tests/test-two-servers.c
@@ -46,8 +46,8 @@ int main(void)
     //spice_server_set_image_compression(server, SPICE_IMAGE_COMPRESSION_OFF);
     test_add_display_interface(t1);
     test_add_display_interface(t2);
-    test_set_simple_command_list(t1, simple_commands, COUNT(simple_commands));
-    test_set_simple_command_list(t2, simple_commands, COUNT(simple_commands));
+    test_set_simple_command_list(t1, simple_commands, G_N_ELEMENTS(simple_commands));
+    test_set_simple_command_list(t2, simple_commands, G_N_ELEMENTS(simple_commands));
 
     basic_event_loop_mainloop();
     return 0;


More information about the Spice-commits mailing list