summaryrefslogtreecommitdiffstats
path: root/runtime/tests/agg/count.c
blob: 8e674d1e9850ef81b8751e5c75b48a3199047948 (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
#include "runtime.h"

/* test of Counters */
#include "counter.c"

int main ()
{
  int i;
  Counter cnt1 = _stp_counter_init();
  Counter cnt2 = _stp_counter_init();

  /* testing _stp_counter_add().  These will only be correct if _stp_counter_init() */
  /* set all values to 0 and add works properly. */
  for (_processor_number = 0; _processor_number < NR_CPUS; _processor_number++) {
    _stp_counter_add (cnt1, _processor_number + 1);
    _stp_counter_add (cnt2, _processor_number + 10);
  }
  
  /* testing _stp_counter_get_cpu() */
  for (i = 0; i < NR_CPUS; i++) {
    printf ("cnt1[%d] = %lld\n", i, _stp_counter_get_cpu(cnt1, i, 0));
    printf ("cnt2[%d] = %lld\n", i, _stp_counter_get_cpu(cnt2, i, 0));
  }

  /* testing _stp_counter_get() */
  printf ("cnt1 = %d\n", _stp_counter_get(cnt1, 0));
  printf ("cnt2 = %d\n", _stp_counter_get(cnt2, 0));
  printf ("--------------------\n");

  /* testing _stp_counter_add() */
  for (_processor_number = 0; _processor_number < NR_CPUS; _processor_number++) {
    _stp_counter_add (cnt1, _processor_number + 1);
    _stp_counter_add (cnt2, _processor_number + 10);
  }

  for (i = 0; i < NR_CPUS; i++) {
    printf ("cnt1[%d] = %lld\n", i, _stp_counter_get_cpu(cnt1, i, 0));
    printf ("cnt2[%d] = %lld\n", i, _stp_counter_get_cpu(cnt2, i, 0));
  }
  printf ("cnt1 = %d\n", _stp_counter_get(cnt1, 1));
  printf ("cnt2 = %d\n", _stp_counter_get(cnt2, 1));

  printf ("--------------------\n");

  for (_processor_number = 0; _processor_number < NR_CPUS; _processor_number++) {
    _stp_counter_add (cnt1, _processor_number * _processor_number);
    _stp_counter_add (cnt2, _processor_number * _processor_number * _processor_number);
  }

  printf ("cnt1 = %d\n", _stp_counter_get(cnt1, 1));
  printf ("cnt2 = %d\n", _stp_counter_get(cnt2, 1));
  printf ("cnt1 = %d\n", _stp_counter_get(cnt1, 0));
  printf ("cnt2 = %d\n", _stp_counter_get(cnt2, 0));
  printf ("--------------------\n");


  for (_processor_number = 0; _processor_number < NR_CPUS; _processor_number++) {
    _stp_counter_add (cnt1, _processor_number * _processor_number);
    _stp_counter_add (cnt2, _processor_number * _processor_number * _processor_number);
  }

  for (i = 0; i < NR_CPUS; i++) {
    printf ("cnt1[%d] = %lld\n", i, _stp_counter_get_cpu(cnt1, i, 0));
    printf ("cnt2[%d] = %lld\n", i, _stp_counter_get_cpu(cnt2, i, 0));
  }
  printf ("cnt1 = %d\n", _stp_counter_get(cnt1, 0));
  printf ("cnt2 = %d\n", _stp_counter_get(cnt2, 0));

  _stp_counter_free (cnt1);
  _stp_counter_free (cnt2);
  return 0;
}