On Wed, 2015-12-09 at 15:59 +0000, Frediano Ziglio wrote: > Make sure code compile with and without statistics enabled (beside > printing functions). > > Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx> > --- > server/tests/.gitignore | 5 +++ > server/tests/Makefile.am | 35 ++++++++++++++++++++ > server/tests/stat-main.c | 49 ++++++++++++++++++++++++++++ > server/tests/stat-test.c | 83 > ++++++++++++++++++++++++++++++++++++++++++++++++ > 4 files changed, 172 insertions(+) > create mode 100644 server/tests/stat-main.c > create mode 100644 server/tests/stat-test.c > > diff --git a/server/tests/.gitignore b/server/tests/.gitignore > index 1059247..17ffa2c 100644 > --- a/server/tests/.gitignore > +++ b/server/tests/.gitignore > @@ -9,3 +9,8 @@ spice-server-replay > test_display_width_stride > test_two_servers > test_vdagent > +stat_test > +libstat_test1.a > +libstat_test2.a > +libstat_test3.a > +libstat_test4.a > diff --git a/server/tests/Makefile.am b/server/tests/Makefile.am > index b398fe4..fd7e26d 100644 > --- a/server/tests/Makefile.am > +++ b/server/tests/Makefile.am > @@ -44,6 +44,20 @@ noinst_PROGRAMS = \ > test_vdagent \ > test_display_width_stride \ > spice-server-replay \ > + stat_test \ > + $(NULL) > + > +TESTS = \ > + stat_test \ > + $(NULL) > + > +check_PROGRAMS = $(TESTS) > + > +noinst_LIBRARIES = \ > + libstat_test1.a \ > + libstat_test2.a \ > + libstat_test3.a \ > + libstat_test4.a \ > $(NULL) > > test_vdagent_SOURCES = \ > @@ -113,3 +127,24 @@ spice_server_replay_SOURCES = \ > basic_event_loop.h \ > test_util.h \ > $(NULL) > + > +stat_test_SOURCES = stat-main.c > +stat_test_LDADD = \ > + $(LDADD) \ > + libstat_test1.a \ > + libstat_test2.a \ > + libstat_test3.a \ > + libstat_test4.a \ > + $(NULL) > + > +libstat_test1_a_SOURCES = stat-test.c > +libstat_test1_a_CPPFLAGS = $(AM_CPPFLAGS) -DTEST_COMPRESS_STAT=0 > -DTEST_RED_WORKER_STAT=0 -DTEST_NAME=stat_test1 > + > +libstat_test2_a_SOURCES = stat-test.c > +libstat_test2_a_CPPFLAGS = $(AM_CPPFLAGS) -DTEST_COMPRESS_STAT=0 > -DTEST_RED_WORKER_STAT=1 -DTEST_NAME=stat_test2 > + > +libstat_test3_a_SOURCES = stat-test.c > +libstat_test3_a_CPPFLAGS = $(AM_CPPFLAGS) -DTEST_COMPRESS_STAT=1 > -DTEST_RED_WORKER_STAT=0 -DTEST_NAME=stat_test3 > + > +libstat_test4_a_SOURCES = stat-test.c > +libstat_test4_a_CPPFLAGS = $(AM_CPPFLAGS) -DTEST_COMPRESS_STAT=1 > -DTEST_RED_WORKER_STAT=1 -DTEST_NAME=stat_test4 > diff --git a/server/tests/stat-main.c b/server/tests/stat-main.c > new file mode 100644 > index 0000000..3d2e48a > --- /dev/null > +++ b/server/tests/stat-main.c > @@ -0,0 +1,49 @@ > +/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */ > +/* > + Copyright (C) 2015 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/ > >. > +*/ > + > +/* check statistics > + */ > + > +#include <config.h> > +#include <glib.h> > + > +typedef void test_func_t(void); > + > +test_func_t stat_test1; > +test_func_t stat_test2; > +test_func_t stat_test3; > +test_func_t stat_test4; > + > +static test_func_t *test_funcs[] = { > + stat_test1, > + stat_test2, > + stat_test3, > + stat_test4, > + NULL > +}; > + > +int main(void) > +{ > + test_func_t **func_p; > + > + for (func_p = test_funcs; *func_p; ++func_p) { > + (*func_p)(); > + } > + return 0; > +} > + > diff --git a/server/tests/stat-test.c b/server/tests/stat-test.c > new file mode 100644 > index 0000000..b2b2136 > --- /dev/null > +++ b/server/tests/stat-test.c > @@ -0,0 +1,83 @@ > +/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */ > +/* > + Copyright (C) 2015 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/ > >. > +*/ > + > +/* check statistics > + */ > + > +#include <config.h> > + > +#undef COMPRESS_STAT > +#undef RED_WORKER_STAT > + > +#if TEST_COMPRESS_STAT > +#define COMPRESS_STAT > +#endif > + > +#if TEST_RED_WORKER_STAT > +#define RED_WORKER_STAT > +#endif > + > +#include <unistd.h> > +#include <glib.h> > +#include "../stat.h" > + > +#ifndef TEST_NAME > +#error TEST_NAME must be defined! > +#endif > + > +void TEST_NAME(void) > +{ > + stat_info_t info; > + stat_start_time_t start_time; > + > +#if !defined(COMPRESS_STAT) && !defined(RED_WORKER_STAT) > + G_STATIC_ASSERT(sizeof(start_time) == 0); > + G_STATIC_ASSERT(sizeof(info) == 0); > +#endif > + > + stat_init(&info, "test", CLOCK_MONOTONIC); > + stat_start_time_init(&start_time, &info); > + usleep(2); > + stat_add(&info, start_time); > + > +#ifdef RED_WORKER_STAT > + g_assert_cmpuint(info.count, ==, 1); > + g_assert_cmpuint(info.min, ==, info.max); > + g_assert_cmpuint(info.min, >=, 2000); > + g_assert_cmpuint(info.min, <, 100000000); > +#endif > + > + stat_reset(&info); > + > + stat_compress_init(&info, "test", CLOCK_MONOTONIC); > + stat_start_time_init(&start_time, &info); > + usleep(2); > + stat_compress_add(&info, start_time, 100, 50); > + usleep(1); > + stat_compress_add(&info, start_time, 1000, 500); > + > +#ifdef COMPRESS_STAT > + g_assert_cmpuint(info.count, ==, 2); > + g_assert_cmpuint(info.min, !=, info.max); > + g_assert_cmpuint(info.min, >=, 2000); > + g_assert_cmpuint(info.min, <, 100000000); > + g_assert_cmpuint(info.total, >=, 5000); > + g_assert_cmpuint(info.orig_size, ==, 1100); > + g_assert_cmpuint(info.comp_size, ==, 550); > +#endif > +} Acked-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx> _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/spice-devel