summaryrefslogtreecommitdiff
path: root/tests/test-profiler.c
blob: 7204e1a6c03ab61471f51772334e6edc7c025f78 (plain)
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
/*
 * Copyright (C) 2011-2013 Karlsruhe Institute of Technology
 *
 * This file is part of Ufo.
 *
 * 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 3 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/>.
 */

#include <glib.h>
#include <glib/gstdio.h>
#include <stdio.h>
#include <string.h>
#include <ufo/ufo.h>
#include "test-suite.h"

typedef struct {
    UfoProfiler *profiler;
} Fixture;


static void
fixture_setup (Fixture *fixture, gconstpointer data)
{
    fixture->profiler = ufo_profiler_new ();
    g_assert (UFO_IS_PROFILER (fixture->profiler));
}

static void
fixture_teardown (Fixture *fixture, gconstpointer data)
{
    g_object_unref (fixture->profiler);
}

static void
test_timer_elapsed (Fixture *fixture, gconstpointer data)
{
    gulong one_millisecond = G_USEC_PER_SEC / 1000;

    ufo_profiler_start (fixture->profiler,
                        UFO_PROFILER_TIMER_IO);

    g_usleep (one_millisecond);

    ufo_profiler_stop (fixture->profiler,
                       UFO_PROFILER_TIMER_IO);

    g_assert (ufo_profiler_elapsed (fixture->profiler,
                                    UFO_PROFILER_TIMER_CPU) <= 0.0);

    g_assert (ufo_profiler_elapsed (fixture->profiler,
                                    UFO_PROFILER_TIMER_IO) >= 0.001);
}


void
test_add_profiler (void)
{
    g_test_add ("/no-opencl/timer/elapsed",
                Fixture,
                NULL,
                fixture_setup,
                test_timer_elapsed,
                fixture_teardown);
}