-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c
More file actions
256 lines (225 loc) · 5.25 KB
/
Copy pathtest.c
File metadata and controls
256 lines (225 loc) · 5.25 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#ifdef TEST
#include "test.h"
static int test_is_print = 1;
static int test_isstr(char *s)
{
int inum, pnum;
char *t;
inum = pnum = 0;
for(t = s; *t; t++)
{
switch(*t)
{
case '0' ... '9':
inum++;
break;
case '.':
pnum++;
break;
default:
return TRUE;
}
}
if(pnum)
return FALSE;
if(inum)
return FALSE;
return TRUE;
}
int test_assert_imple(char *s1, char *ss1, char *s2, char *ss2, int type, char *equal, const char *funcname)
{
int test_i;
char test_s[128];
switch(type)
{
case 'f': case 'g':
case 'd': case 'x': case 'p': case 'c':
test_i = s1 == s2;
break;
case 's':
test_i = s1 && s2 ? !strcmp(s1, s2) : s1 == s2 ? 1 : 0;
break;
}
if(test_is_print)
{
sprintf(test_s, "<%s assert %%s %s %%s> : %%s is %%%c, %%s is %%%c\n", funcname, equal, type, type);
switch(type)
{
case 'f': case 'g':
printf(test_s, ss1, ss2, ss1, castdouble(s1), ss2, castdouble(s2));
break;
default:
printf(test_s, ss1, ss2, ss1, s1, ss2, s2);
}
fflush(stdout);
}
if(equal[0] == 'u')
test_i = !test_i;
assert(test_i);
}
__attribute__((constructor)) void test_argv()
{
int argc = 0;
char *argv[1024] = {0};
FILE *fp;
struct timeval g_tv_s, g_tv_e;
double g_tv;
tools_init();
logging_init(NULL);
gettimeofday(&g_tv_s, NULL);
printf("****** auto test begin ******\n\n\n");
setvbuf(stdout, NULL, _IONBF, 0);
#ifdef _WIN32
LPTSTR line;
line = GetCommandLine();
argv[argc++] = line;
line = strstr(line, " ");
while(line)
{
*line++ = 0;
argv[argc++] = line;
line = strstr(line, " ");
}
#else
char name[32];
char result[1024];
char *line;
sprintf(name, "/proc/%d/cmdline", getpid());
fp = fopen(name, "rb");
fgets(result, 1024, fp);
fclose(fp);
line = result;
while(*line)
{
argv[argc++] = line;
line += strlen(line) + 1;
}
#endif
dict *d;
char *state = NULL;
char *value = NULL;
int i;
d = dict_new();
for(i = 1; i < argc; i++)
{
if(argv[i][0] == '-')
{
state = argv[i];
value = NULL;
dict_set(d, argv[i], 1);
}
else
{
if(state)
{
if(value == NULL || test_isstr(argv[i]) == TRUE)
{
value = argv[i];
if(state[1] == '-')
dict_set(d, state, argv[i]);
else
dict_set(d, state, argv[i], 1);
}
else
dict_set(d, state, value, atoi(argv[i]));
}
}
}
if(dict_get(d, "--noprint"))
{
test_is_print = 0;
}
char cmd[1024];
char info[1024];
char wildcard[1024];
char *func;
char *s, *t;
__int64 tmp;
__int64 num;
sprintf(cmd, "nm %s\n", argv[0]);
fp = popen(cmd, "r");
while(fgets(info, 1024, fp))
{
s = strstr(info, " T ");
if(!s) //筛选函数
continue;
*s = 0;
func = s + 3; //定位到函数开始
s = strstr(func, "_test"); //筛选_test结束的函数
if(!s)
continue;
*s = 0;
if(*(s + 6))
continue;
if(dict_get(d, "-f", func))
continue;
tmp = 1;
if(dict_get(d, "-t"))
{
s = wildcard;
t = func;
while(*t)
*s++ = *t++;
while(s >= wildcard)
{
*s = '+';
*(s + 1) = 0;
if(tmp = (__int64)dict_get(d, "-t", wildcard))
break;
s--;
}
if(s < wildcard)
if(!(tmp = (__int64)dict_get(d, "-t", func)))
continue;
}
num = tmp ? tmp : 1;
int interval = num + 1;
tmp = (__int64)dict_get(d, "--interval");
if(tmp)
{
interval = strtol((void *)tmp, NULL, 10);
if(interval == 0)
interval = 1;
}
struct timeval tv_s, tv_e;
double tv;
__int64 m_s, m_e;
__int64 t_s, t_e;
gettimeofday(&tv_s, NULL);
m_s = lib_memory_total();
t_s = lib_memory_time();
printf("****** test begin %s ******\n", func);
for(i = 0; i < num; i++)
{
((void(*)(void))strtol(info, NULL, 16))();
if((i + 1) % interval)
continue;
gettimeofday(&tv_e, NULL);
tv = (tv_e.tv_sec - tv_s.tv_sec) + (tv_e.tv_usec - tv_s.tv_usec) * 1.0 TO(S);
m_e = lib_memory_total();
t_e = lib_memory_time();
if((m_e - m_s) TO(MB))
printf("****** test %s %d %fs %lld %lldMB %lldKB******\n", func, num, tv, t_e - t_s, (m_e - m_s) TO(MB), (m_e - m_s) TO(KB) % 1024);
else if((m_e - m_s) TO(KB))
printf("****** test %s %d %fs %lld %lldKB %lldB******\n", func, num, tv, t_e - t_s, (m_e - m_s) TO(KB), (m_e - m_s) % 1024);
else
printf("****** test %s %d %fs %lld %lldB******\n", func, num, tv, t_e - t_s, m_e - m_s);
}
gettimeofday(&tv_e, NULL);
tv = (tv_e.tv_sec - tv_s.tv_sec) + (tv_e.tv_usec - tv_s.tv_usec) * 1.0 TO(S);
m_e = lib_memory_total();
t_e = lib_memory_time();
if((m_e - m_s) TO(MB))
printf("****** test end %s %d %fs %lld %lldMB %lldKB******\n", func, num, tv, t_e - t_s, (m_e - m_s) TO(MB), (m_e - m_s) TO(KB) % 1024);
else if((m_e - m_s) TO(KB))
printf("****** test end %s %d %fs %lld %lldKB %lldB******\n", func, num, tv, t_e - t_s, (m_e - m_s) TO(KB), (m_e - m_s) % 1024);
else
printf("****** test end %s %d %fs %lld %lldB******\n", func, num, tv, t_e - t_s, m_e - m_s);
}
pclose(fp);
dict_free(d);
gettimeofday(&g_tv_e, NULL);
g_tv = (g_tv_e.tv_sec - g_tv_s.tv_sec) + (g_tv_e.tv_usec - g_tv_s.tv_usec) * 1.0 TO(S);
printf("\n****** auto test end %fs ******\n", g_tv);
}
#endif