summaryrefslogtreecommitdiff
path: root/src/tests/eina/eina_test_benchmark.c
blob: 4352c1622bec6e75a2f168ebfa9a3ff579f0365d (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
76
/* EINA - EFL data type library
 * Copyright (C) 2008 Cedric Bail
 *
 * 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/>.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <unistd.h>

#include "eina_suite.h"
#include "eina_benchmark.h"

static int global_test = 0;

static void
_eina_benchmark_specimens(int request)
{
   int i;
   int a = 0;

   for (i = 0; i < request; ++i)
      a += i;

   global_test = a;
}

START_TEST(eina_benchmark_simple)
{
   Eina_Benchmark *eb;
   Eina_Array_Iterator it;
   Eina_Array *ea;
   char *tmp;
   unsigned int i;

   eb = eina_benchmark_new("benchmark", "test");
   fail_if(!eb);

   eina_benchmark_register(eb, "specimens_check",
                           EINA_BENCHMARK(_eina_benchmark_specimens),
			   1000, 1100, 100);

   ea = eina_benchmark_run(eb);
   fail_if(!ea);

   EINA_ARRAY_ITER_NEXT(ea, i, tmp, it)
     {
        fail_if(!tmp);
        fail_if(unlink(tmp));
     }

   fail_if(global_test != 499500);

   eina_benchmark_free(eb);
}
END_TEST

void
eina_test_benchmark(TCase *tc)
{
   tcase_add_test(tc, eina_benchmark_simple);
}