History

new subdirs: include, lib, tests

grischka committed 17 years ago

Commit ea5e81b1 parent e8a52a816 files · +0 −6Browse files

Showing the changes to tests/boundtest.c (1 of 16 files). Show all

Unified · Split

tests/boundtest.c+214−0
@@ -0,0 +1,214 @@
1#include <stdlib.h>
2#include <stdio.h>
3
4#define NB_ITS 1000000
5//#define NB_ITS 1
6#define TAB_SIZE 100
7
8int tab[TAB_SIZE];
9int ret_sum;
10char tab3[256];
11
12int test1(void)
13{
14 int i, sum = 0;
15 for(i=0;i<TAB_SIZE;i++) {
16 sum += tab[i];
17 }
18 return sum;
19}
20
21/* error */
22int test2(void)
23{
24 int i, sum = 0;
25 for(i=0;i<TAB_SIZE + 1;i++) {
26 sum += tab[i];
27 }
28 return sum;
29}
30
31/* actually, profiling test */
32int test3(void)
33{
34 int sum;
35 int i, it;
36
37 sum = 0;
38 for(it=0;it<NB_ITS;it++) {
39 for(i=0;i<TAB_SIZE;i++) {
40 sum += tab[i];
41 }
42 }
43 return sum;
44}
45
46/* ok */
47int test4(void)
48{
49 int i, sum = 0;
50 int *tab4;
51
52 tab4 = malloc(20 * sizeof(int));
53 for(i=0;i<20;i++) {
54 sum += tab4[i];
55 }
56 free(tab4);
57
58 return sum;
59}
60
61/* error */
62int test5(void)
63{
64 int i, sum = 0;
65 int *tab4;
66
67 tab4 = malloc(20 * sizeof(int));
68 for(i=0;i<21;i++) {
69 sum += tab4[i];
70 }
71 free(tab4);
72
73 return sum;
74}
75
76/* error */
77/* XXX: currently: bug */
78int test6(void)
79{
80 int i, sum = 0;
81 int *tab4;
82
83 tab4 = malloc(20 * sizeof(int));
84 free(tab4);
85 for(i=0;i<21;i++) {
86 sum += tab4[i];
87 }
88
89 return sum;
90}
91
92/* error */
93int test7(void)
94{
95 int i, sum = 0;
96 int *p;
97
98 for(i=0;i<TAB_SIZE + 1;i++) {
99 p = &tab[i];
100 if (i == TAB_SIZE)
101 printf("i=%d %x\n", i, p);
102 sum += *p;
103 }
104 return sum;
105}
106
107/* ok */
108int test8(void)
109{
110 int i, sum = 0;
111 int tab[10];
112
113 for(i=0;i<10;i++) {
114 sum += tab[i];
115 }
116 return sum;
117}
118
119/* error */
120int test9(void)
121{
122 int i, sum = 0;
123 char tab[10];
124
125 for(i=0;i<11;i++) {
126 sum += tab[i];
127 }
128 return sum;
129}
130
131/* ok */
132int test10(void)
133{
134 char tab[10];
135 char tab1[10];
136
137 memset(tab, 0, 10);
138 memcpy(tab, tab1, 10);
139 memmove(tab, tab1, 10);
140 return 0;
141}
142
143/* error */
144int test11(void)
145{
146 char tab[10];
147
148 memset(tab, 0, 11);
149 return 0;
150}
151
152/* error */
153int test12(void)
154{
155 void *ptr;
156 ptr = malloc(10);
157 free(ptr);
158 free(ptr);
159 return 0;
160}
161
162/* error */
163int test13(void)
164{
165 char pad1 = 0;
166 char tab[10];
167 char pad2 = 0;
168 memset(tab, 'a', sizeof(tab));
169 return strlen(tab);
170}
171
172int (*table_test[])(void) = {
173 test1,
174 test1,
175 test2,
176 test3,
177 test4,
178 test5,
179 test6,
180 test7,
181 test8,
182 test9,
183 test10,
184 test11,
185 test12,
186 test13,
187};
188
189int main(int argc, char **argv)
190{
191 int index;
192 int (*ftest)(void);
193
194 if (argc < 2) {
195 printf("usage: boundtest n\n"
196 "test TCC bound checking system\n"
197 );
198 exit(1);
199 }
200
201 index = 0;
202 if (argc >= 2)
203 index = atoi(argv[1]);
204 /* well, we also use bounds on this ! */
205 ftest = table_test[index];
206 ftest();
207
208 return 0;
209}
210
211/*
212 * without bound 0.77 s
213 * with bounds 4.73
214 */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t