[Spice-commits] server/reds.c server/tests

Frediano Ziglio fziglio at kemper.freedesktop.org
Fri Mar 31 10:06:47 UTC 2017


 server/reds.c                 |    4 ++++
 server/tests/test-stat-file.c |   19 +++++++++++++++++++
 2 files changed, 23 insertions(+)

New commits:
commit 5d046d9b2de1ac283d677965fc5b097085df86a1
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Thu Mar 30 13:42:25 2017 +0100

    red-channel: Initialize statistic node correctly
    
    Doing a memset(0) on a SpiceStatNode does not create an empty/unattached
    node, but instead creates a node '0'. This node could be non-existing,
    or totally unrelated.
    This patch creates a default '0' node as soon as the file is created.
    This will make the behaviour of 0-filled nodes more in line with what
    one would expect.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/reds.c b/server/reds.c
index 0b6ca124..839ffe7d 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -3500,6 +3500,10 @@ SPICE_GNUC_VISIBLE SpiceServer *spice_server_new(void)
     reds->config->exit_on_disconnect = FALSE;
 #ifdef RED_STATISTICS
     reds->stat_file = stat_file_new(REDS_MAX_STAT_NODES);
+    /* Create an initial node. This will be the 0 node making easier
+     * to initialize node references.
+     */
+    stat_file_add_node(reds->stat_file, INVALID_STAT_REF, "default_channel", TRUE);
 #endif
     reds->listen_socket = -1;
     reds->secure_listen_socket = -1;
diff --git a/server/tests/test-stat-file.c b/server/tests/test-stat-file.c
index 63a2a2b5..901985a7 100644
--- a/server/tests/test-stat-file.c
+++ b/server/tests/test-stat-file.c
@@ -89,11 +89,30 @@ static void stat_file(void)
     stat_file_free(stat_file);
 }
 
+/* make sure first node is node 0 */
+static void stat_file_start(void)
+{
+    RedStatFile *stat_file;
+    StatNodeRef ref;
+
+    /* create */
+    stat_file = stat_file_new(10);
+    g_assert_nonnull(stat_file);
+
+    ref = stat_file_add_node(stat_file, INVALID_STAT_REF, "ZERO", TRUE);
+    g_assert_cmpuint(ref,==,0);
+
+    stat_file_unlink(stat_file);
+    stat_file_free(stat_file);
+}
+
+
 int main(int argc, char *argv[])
 {
     g_test_init(&argc, &argv, NULL);
 
     g_test_add_func("/server/stat-file", stat_file);
+    g_test_add_func("/server/stat-file-start", stat_file_start);
 
     return g_test_run();
 }


More information about the Spice-commits mailing list