1// Indirectly call a bunch of functions.
2
3#include <assert.h>
4
5extern int cnt;
6
7typedef int (*F)(int, int);
8
9// A function in the same object.
10int f_local(int x, int y) {
11  return x + y;
12}
13
14// A function in another object.
15int f_other_object(int x, int y);
16
17// A function in another DSO.
18int f_dso(int x, int y);
19
20// A function in another DSO that is replaced by the wrapper.
21int f_replaced(int x, int y);
22
23void run_test(void) {
24  int x;
25  int expected_cnt = 0;
26  volatile F f;
27
28  if (SLOW) ++expected_cnt;
29  f = &f_local;
30  x = f(1, 2);
31  assert(x == 3);
32  assert(cnt == expected_cnt);
33
34  if (SLOW) ++expected_cnt;
35  f = &f_other_object;
36  x = f(2, 3);
37  assert(x == 6);
38  assert(cnt == expected_cnt);
39
40  ++expected_cnt;
41  f = &f_dso;
42  x = f(2, 3);
43  assert(x == 7);
44  assert(cnt == expected_cnt);
45
46  ++expected_cnt;
47  f = &f_replaced;
48  x = f(2, 3);
49  assert(x == 11);
50  assert(cnt == expected_cnt);
51}
52