File: stat-test.c

package info (click to toggle)
spice 0.16.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,460 kB
  • sloc: ansic: 43,305; cpp: 30,185; sh: 5,342; python: 3,040; makefile: 844
file content (88 lines) | stat: -rw-r--r-- 2,396 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* -*- 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 <common/macros.h>

#include "../stat.h"

#ifndef TEST_NAME
#error TEST_NAME must be defined!
#endif

// avoid warning, the function is called by stat-main.c
void TEST_NAME(void);

void TEST_NAME(void)
{
    stat_info_t info;
    stat_start_time_t start_time;

#if !defined(COMPRESS_STAT) && !defined(RED_WORKER_STAT)
    SPICE_VERIFY(sizeof(start_time) == 0);
    SPICE_VERIFY(sizeof(info) == 0);
#endif

    stat_init(&info, "test", CLOCK_MONOTONIC);
    stat_start_time_init(&start_time, &info);
    usleep(2000);
    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, >=, 2000000);
    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(2000);
    stat_compress_add(&info, start_time, 100, 50);
    usleep(1000);
    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, >=, 2000000);
    g_assert_cmpuint(info.min, <, 100000000);
    g_assert_cmpuint(info.total, >=, 5000000);
    g_assert_cmpuint(info.orig_size, ==, 1100);
    g_assert_cmpuint(info.comp_size, ==, 550);
#endif
}