"Fossies" - the Fresh Open Source Software Archive 
Member "FunctionCheck-3.2.0/test/simple_test_lib.c" (26 May 2012, 2200 Bytes) of package /linux/privat/old/FunctionCheck-3.2.0.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <math.h>
4 #include <sys/time.h>
5 #include <unistd.h>
6
7 /* function from an other .c, not compiled
8 with -finstrument-functions */
9 void _f4();
10
11 /* just spend 1 sec */
12 void s1(void)
13 {
14 sleep(1);
15 }
16
17 /* simple functions */
18 void f1(int a)
19 {
20 int i, j = 0;
21
22 for (i = 0; i < a; i++)
23 {
24 j += 1;
25 }
26 }
27
28 void f2(int b)
29 {
30 int i, j = 0;
31
32 for (i = 0; i < b; i++)
33 {
34 j -= 1;
35 }
36 }
37
38 void f3()
39 {
40 f1(10);
41 f1(20);
42 f1(30);
43 }
44
45 /* simple recursive function */
46 void recurs(int n)
47 {
48 if (n <= 1)
49 return;
50 recurs(n - 1);
51 }
52
53 /* recursive function which takes 1s */
54 void recurs_1s(int n)
55 {
56 sleep(1);
57 s1();
58 if (n <= 1)
59 return;
60 recurs_1s(n - 1);
61 }
62
63 /* cross-recursive function */
64 void recurs_b(int n);
65
66 void recurs_a(int n)
67 {
68 int i, j = 0;
69 for (i = 0; i < 10000000; i++)
70 {
71 j = j + 1;
72 j = j * 2;
73 j = j / 3;
74 }
75 //sleep(1);
76 //s1();
77 recurs_b(n);
78 }
79
80 void recurs_b(int n)
81 {
82 int i, j = 0;
83 for (i = 0; i < 10000000; i++)
84 {
85 j = j + 1;
86 j = j * 2;
87 j = j / 3;
88 }
89 //sleep(1);
90 //s1();
91 if (n <= 1)
92 return;
93 recurs_a(n - 1);
94 }
95
96 /* heavy function */
97 void f4()
98 {
99 int i;
100 double j = 0., w;
101
102 for (i = 0; i < 100; i++)
103 {
104 j += sin(cos(sin(cos((double) i))));
105 w = pow(j, cos(j));
106 j = cos(cos(j));
107 }
108 }
109
110 /* small function */
111 void small()
112 {
113 int i;
114
115 i = 0;
116 }
117
118 /* call to a not-profiled function */
119 void test()
120 {
121 _f4();
122 }
123
124 void alloc4()
125 {
126 void* ptr = malloc(32);
127 }
128
129 void alloc3()
130 {
131 alloc4();
132 }
133
134 void alloc2()
135 {
136 alloc3();
137 }
138
139 void alloc1()
140 {
141 alloc2();
142 }
143
144 /* calls to functions */
145 int main(int argc, char *argv[])
146 {
147 char *p1, *p2, *p3;
148
149 p1 = malloc(sizeof (char) *32);
150 p2 = malloc(sizeof (char) *32);
151 p3 = malloc(sizeof (char) *32);
152
153 recurs(32);
154
155 recurs_a(4);
156
157 recurs_1s(4);
158
159 p2 = realloc(p2, sizeof (char) *64);
160 p3 = realloc(p3, sizeof (char) *64);
161
162 //recurs_1s(4);
163
164 test();
165 f3();
166 small();
167
168 p2 = realloc(p2, sizeof (char) *128);
169
170 free(p2);
171
172 alloc1();
173
174 return 0;
175 }