[Spice-devel] [PATCH spice-server 5/5] tests: Add a small test for red_record_ APIs

Eduardo Lima (Etrunko) etrunko at redhat.com
Fri Nov 16 17:10:31 UTC 2018


On 11/11/18 7:31 AM, Frediano Ziglio wrote:
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
>  server/tests/.gitignore    |   1 +
>  server/tests/Makefile.am   |   1 +
>  server/tests/meson.build   |   1 +
>  server/tests/test-record.c | 100 +++++++++++++++++++++++++++++++++++++
>  4 files changed, 103 insertions(+)
>  create mode 100644 server/tests/test-record.c
> 
> diff --git a/server/tests/.gitignore b/server/tests/.gitignore
> index db26b3ee..81b604bc 100644
> --- a/server/tests/.gitignore
> +++ b/server/tests/.gitignore
> @@ -27,5 +27,6 @@ test-vdagent
>  test-gst
>  test-leaks
>  test-sasl
> +test-record
>  /test-*.log
>  /test-*.trs
> diff --git a/server/tests/Makefile.am b/server/tests/Makefile.am
> index 46cbe8cf..d7f7af9b 100644
> --- a/server/tests/Makefile.am
> +++ b/server/tests/Makefile.am
> @@ -63,6 +63,7 @@ check_PROGRAMS =				\
>  	test-channel				\
>  	test-stream-device			\
>  	test-listen				\
> +	test-record				\
>  	$(NULL)
>  
>  noinst_PROGRAMS =				\
> diff --git a/server/tests/meson.build b/server/tests/meson.build
> index 23794cc9..b79b1108 100644
> --- a/server/tests/meson.build
> +++ b/server/tests/meson.build
> @@ -47,6 +47,7 @@ tests = [
>    ['test-channel', true],
>    ['test-stream-device', true],
>    ['test-listen', true],
> +  ['test-record', true],
>    ['test-display-no-ssl', false],
>    ['test-display-streaming', false],
>    ['test-playback', false],
> diff --git a/server/tests/test-record.c b/server/tests/test-record.c
> new file mode 100644
> index 00000000..de3c6f5b
> --- /dev/null
> +++ b/server/tests/test-record.c
> @@ -0,0 +1,100 @@
> +/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
> +/*
> +   Copyright (C) 2018 Red Hat, Inc.
> +
> +   This library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   This library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with this library; if not, see <http://www.gnu.org/licenses/>.
> +*/
> +/*
> + * Test some red_record_ APIs.
> + */
> +#include <config.h>
> +
> +#include <unistd.h>
> +#include <string.h>
> +#include <stdbool.h>
> +
> +#include "test-glib-compat.h"
> +#include "red-record-qxl.h"
> +
> +#define OUTPUT_FILENAME "rec1.txt"
> +
> +static void
> +test_record(bool compress)
> +{
> +    RedRecord *rec;
> +    const char *fn = OUTPUT_FILENAME;
> +
> +    unsetenv("SPICE_WORKER_RECORD_FILTER");
> +    if (compress) {
> +        setenv("SPICE_WORKER_RECORD_FILTER", "gzip", 1);
> +    }
> +
> +    // delete possible stale test output
> +    unlink(fn);
> +    g_assert_cmpint(access(fn, F_OK), <, 0);
> +
> +    // create recorder
> +    rec = red_record_new(fn);
> +    g_assert_nonnull(rec);
> +
> +    // check file was created by recorder
> +    g_assert_cmpint(access(fn, F_OK), ==, 0);
> +
> +    g_assert_nonnull(red_record_ref(rec));
> +    red_record_unref(rec);
> +
> +    // record something
> +    red_record_event(rec, 1, 123);
> +
> +    red_record_unref(rec);
> +
> +    // check content of the output file
> +    FILE *f;
> +    if (!compress) {
> +        f = fopen(fn, "r");
> +    } else {
> +        f = popen("gzip -dc < " OUTPUT_FILENAME, "r");
> +    }
> +    g_assert_nonnull(f);
> +
> +    char line[1024];
> +    int version;
> +    g_assert_nonnull(fgets(line, sizeof(line), f));
> +    g_assert_cmpint(sscanf(line, "SPICE_REPLAY %d", &version), ==, 1);
> +
> +    int w, t;
> +    g_assert_nonnull(fgets(line, sizeof(line), f));
> +    g_assert_cmpint(sscanf(line, "event %*d %d %d", &w, &t), ==, 2);
> +    g_assert_cmpint(w, ==, 1);
> +    g_assert_cmpint(t, ==, 123);
> +
> +    g_assert_null(fgets(line, sizeof(line), f));
> +
> +    if (!compress) {
> +        fclose(f);
> +    } else {
> +        pclose(f);
> +    }
> +
> +    // clean test output file
> +    unlink(fn);
> +}
> +
> +int
> +main(void)
> +{
> +    test_record(false);
> +    test_record(true);
> +    return 0;
> +}
> 
Acked-by: Eduardo Lima (Etrunko) <etrunko at redhat.com>

-- 
Eduardo de Barros Lima (Etrunko)
Software Engineer - RedHat
etrunko at redhat.com


More information about the Spice-devel mailing list