aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/gcov-info-to-gcda.c
blob: ca9b3e831fe7db720e7443d994b95f298ba35a58 (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
77
78
79
80
81
/* { dg-do run { target *-*-linux* *-*-gnu* } } */
/* { dg-options "-fprofile-arcs -fprofile-info-section" } */

#define assert(expr)                                            \
  ((expr)                                                       \
   ? (void)0                                                    \
   : (__builtin_printf ("%s:%i: Assertion `%s' failed.\n",      \
                        __FILE__, __LINE__, #expr),             \
      __builtin_abort ()))

struct gcov_info;

extern void
__gcov_info_to_gcda (const struct gcov_info *__info,
		     void (*__filename_fn) (const char *, void *),
		     void (*__dump_fn) (const void *, unsigned, void *),
		     void *(*__allocate_fn) (unsigned, void *),
		     void *__arg);

extern void
__gcov_filename_to_gcfn (const char *__filename,
			 void (*__dump_fn) (const void *, unsigned, void *),
			 void *__arg);

extern const struct gcov_info *my_info;

static unsigned counter;

static unsigned counter_after_filename;

static int check_zero;

static int check_after_filename;

static void
dump (const void *d, unsigned n, void *arg)
{
  unsigned *m = (unsigned *)arg;
  assert (arg == &counter);

  if (*m == 0)
  {
    const unsigned *u = d;
    assert (*u == 0x6763666e);
    check_zero = 1;
  }
  else if (*m == counter_after_filename)
  {
    const unsigned *u = d;
    assert (*u == 0x67636461);
    check_after_filename = 1;
  }

  *m += n;
}

static void
filename (const char *f, void *arg)
{
  assert (arg == &counter);
  assert (__builtin_strstr (f, "gcov-info-to-gcda.c") == 0);
  __gcov_filename_to_gcfn (f, dump, arg);
  counter_after_filename = counter;
}

static void *
allocate (unsigned length, void *arg)
{
  assert (arg == &counter);
  return __builtin_malloc (length);
}

int main()
{
  __asm__ volatile (".set my_info, .LPBX2");
  __gcov_info_to_gcda (my_info, filename, dump, allocate, &counter);
  assert (counter > 8);
  assert (check_zero);
  assert (check_after_filename);
  return 0;
}