79
|
1 |
/*
|
|
2 |
* ==============================================================================
|
|
3 |
* Name : gcce-validate.c
|
|
4 |
* Part of : internal/gcce
|
|
5 |
* Description : This is a test program to test the cross linking of openc libraries with
|
|
6 |
* programs compiled using the gcce compiler
|
|
7 |
Copyright © 2006 Nokia Corporation
|
|
8 |
All rights reserved.
|
|
9 |
Redistribution and use in source and binary forms, with or without
|
|
10 |
modification, are permitted provided that the following conditions are met:
|
|
11 |
* Redistributions of source code must retain the above copyright notice, this
|
|
12 |
list of conditions and the following disclaimer.
|
|
13 |
* Redistributions in binary form must reproduce the above copyright notice,
|
|
14 |
this list of conditions and the following disclaimer in the documentation
|
|
15 |
and/or other materials provided with the distribution.
|
|
16 |
* Neither the name of the <ORGANIZATION> nor the names of its contributors
|
|
17 |
may be used to endorse or promote products derived from this software
|
|
18 |
without specific prior written permission.
|
|
19 |
|
|
20 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21 |
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22 |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23 |
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
|
24 |
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25 |
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26 |
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27 |
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28 |
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29 |
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
30 |
* ==============================================================================
|
|
31 |
*/
|
|
32 |
|
|
33 |
#include <stdio.h>
|
|
34 |
#include <string.h>
|
|
35 |
#include <stdlib.h>
|
|
36 |
#include <dlfcn.h>
|
|
37 |
#include <pthread.h>
|
|
38 |
#include <zlib.h>
|
|
39 |
#include <math.h>
|
|
40 |
#include <float.h>
|
|
41 |
#include <errno.h>
|
|
42 |
#include <grp.h>
|
|
43 |
#include <pwd.h>
|
|
44 |
#include <stdlib.h>
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
#include <testharness.h>
|
|
49 |
#include "result_log.h"
|
|
50 |
|
|
51 |
int TestCond688()
|
|
52 |
|
|
53 |
{
|
|
54 |
struct timespec abstime;
|
|
55 |
struct timeval now;
|
|
56 |
gettimeofday(&now,NULL);
|
|
57 |
abstime.tv_sec = now.tv_sec + 5;
|
|
58 |
abstime.tv_nsec = now.tv_usec * 1000;
|
|
59 |
|
|
60 |
TRACE("+TestCond688\n");
|
|
61 |
HarnessCommand lCommandArr[255] =
|
|
62 |
{
|
|
63 |
{EThreadMain, EMutexInitStaticErrorCheck},
|
|
64 |
{EThreadMain, ECondInit},
|
|
65 |
|
|
66 |
{EThreadMain, EThreadCreate, (void*) EThread1},
|
|
67 |
{EThreadMain, EThreadCreate, (void*) EThread2},
|
|
68 |
{EThreadMain, EThreadCreate, (void*) EThread3},
|
|
69 |
{EThreadMain, EThreadCreate, (void*) EThread4},
|
|
70 |
|
|
71 |
{EThread1, EMutexLock},
|
|
72 |
{EThread1, EPostSignal},
|
|
73 |
{EThread1, ECondTimedWait,&abstime},
|
|
74 |
|
|
75 |
{EThread2, EMutexLock},
|
|
76 |
{EThread2, EPostSignal},
|
|
77 |
{EThread2, ECondTimedWait,&abstime},
|
|
78 |
|
|
79 |
{EThread3, EMutexLock},
|
|
80 |
{EThread3, EPostSignal},
|
|
81 |
{EThread3, ECondTimedWait,&abstime},
|
|
82 |
|
|
83 |
{EThread4, EMutexLock},
|
|
84 |
{EThread4, EPostSignal},
|
|
85 |
{EThread4, ECondTimedWait,&abstime},
|
|
86 |
|
|
87 |
{EThreadMain, EWaitForSignal},
|
|
88 |
{EThreadMain, EWaitForSignal},
|
|
89 |
{EThreadMain, EWaitForSignal},
|
|
90 |
{EThreadMain, EWaitForSignal},
|
|
91 |
|
|
92 |
{EThreadMain, EWaitTillSuspended, (void*) EThread1},
|
|
93 |
{EThreadMain, EWaitTillSuspended, (void*) EThread2},
|
|
94 |
{EThreadMain, EWaitTillSuspended, (void*) EThread3},
|
|
95 |
{EThreadMain, EWaitTillSuspended, (void*) EThread4},
|
|
96 |
|
|
97 |
{EThreadMain, EMutexLock},
|
|
98 |
{EThreadMain, ECondBroadcast},
|
|
99 |
{EThreadMain, EMutexUnlock},
|
|
100 |
|
|
101 |
{EThread1, EVerifyResult, (void*) 0},
|
|
102 |
{EThread2, EVerifyResult, (void*) 0},
|
|
103 |
{EThread3, EVerifyResult, (void*) 0},
|
|
104 |
{EThread4, EVerifyResult, (void*) 0},
|
|
105 |
|
|
106 |
{EThread1, EMutexUnlock},
|
|
107 |
{EThread2, EMutexUnlock},
|
|
108 |
{EThread3, EMutexUnlock},
|
|
109 |
{EThread4, EMutexUnlock},
|
|
110 |
|
|
111 |
{EThread1, EStop},
|
|
112 |
{EThread2, EStop},
|
|
113 |
{EThread3, EStop},
|
|
114 |
{EThread4, EStop},
|
|
115 |
|
|
116 |
|
|
117 |
{EThreadMain, EThreadDestroy, (void*) EThread1},
|
|
118 |
{EThreadMain, EThreadDestroy, (void*) EThread2},
|
|
119 |
{EThreadMain, EThreadDestroy, (void*) EThread3},
|
|
120 |
{EThreadMain, EThreadDestroy, (void*) EThread4},
|
|
121 |
|
|
122 |
{EThreadMain, ECondDestroy},
|
|
123 |
{EThreadMain, EMutexDestroy},
|
|
124 |
|
|
125 |
{EThreadMain, EStop},
|
|
126 |
{ENoThread, ELastCommand},
|
|
127 |
};
|
|
128 |
|
|
129 |
TRACE("-TestCond688\n");
|
|
130 |
return LoadHarness(lCommandArr);
|
|
131 |
}
|
|
132 |
|
|
133 |
|
|
134 |
//sem_getvalue on a semaphore posted n times
|
|
135 |
int TestSem316()
|
|
136 |
{
|
|
137 |
TRACE("+TestSem316\n");
|
|
138 |
|
|
139 |
HarnessCommand lCommandArr[255] =
|
|
140 |
{
|
|
141 |
{EThreadMain, ESemInit, (void*) NULL},
|
|
142 |
{EThreadMain, ESemPost},
|
|
143 |
{EThreadMain, ESemPost},
|
|
144 |
{EThreadMain, ESemPost},
|
|
145 |
{EThreadMain, ESemPost},
|
|
146 |
{EThreadMain, ESemWait},
|
|
147 |
{EThreadMain, ESemWait},
|
|
148 |
|
|
149 |
{EThreadMain, ESemGetValue},
|
|
150 |
{EThreadMain, ECheckValue, (void*) 2},
|
|
151 |
{EThreadMain, ESemDestroy},
|
|
152 |
|
|
153 |
{EThreadMain, EStop},
|
|
154 |
{ENoThread, ELastCommand},
|
|
155 |
};
|
|
156 |
|
|
157 |
TRACE("-TestSem316\n");
|
|
158 |
return LoadHarness(lCommandArr);
|
|
159 |
}
|
|
160 |
|
|
161 |
//sem_trywait called on a non posted semaphore
|
|
162 |
int TestSem390()
|
|
163 |
{
|
|
164 |
TRACE("+TestSem390\n");
|
|
165 |
HarnessCommand lCommandArr[255] =
|
|
166 |
{
|
|
167 |
{EThreadMain, ESemInit},
|
|
168 |
|
|
169 |
{EThreadMain, EThreadCreate, (void*) EThread1},
|
|
170 |
|
|
171 |
{EThread1, ESemTryWait},
|
|
172 |
{EThread1, EVerifyErrno, (void*) EAGAIN},
|
|
173 |
{EThread1, EPostSignal},
|
|
174 |
{EThreadMain, EWaitForSignal},
|
|
175 |
{EThread1, EStop},
|
|
176 |
|
|
177 |
{EThreadMain, ESemDestroy},
|
|
178 |
{EThreadMain, EThreadDestroy, (void*) EThread1},
|
|
179 |
{EThreadMain, EStop},
|
|
180 |
{ENoThread, ELastCommand},
|
|
181 |
};
|
|
182 |
|
|
183 |
TRACE("-TestSem390\n");
|
|
184 |
return LoadHarness(lCommandArr);
|
|
185 |
}
|
|
186 |
|
|
187 |
|
|
188 |
#define FLOAT float
|
|
189 |
#define CHOOSE(Clongdouble,Cdouble,Cfloat,Cinlinelongdouble,Cinlinedouble,Cinlinefloat) Cfloat
|
|
190 |
#define IGNORE_ZERO_INF_SIGN 0x10
|
|
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
|
196 |
#define MANT_DIG CHOOSE ((LDBL_MANT_DIG-1), (DBL_MANT_DIG-1), (FLT_MANT_DIG-1), \
|
|
197 |
(LDBL_MANT_DIG-1), (DBL_MANT_DIG-1), (FLT_MANT_DIG-1))
|
|
198 |
|
|
199 |
#define KErrNone 0
|
|
200 |
#define KErrGeneral -1
|
|
201 |
|
|
202 |
|
|
203 |
int check_float (FLOAT computed, FLOAT expected,FLOAT max_ulp, FLOAT &gen_ulp)
|
|
204 |
{
|
|
205 |
int ok = 0;
|
|
206 |
FLOAT diff = 0;
|
|
207 |
FLOAT ulp = 0;
|
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
if (isnan (computed) && isnan (expected))
|
|
212 |
ok = 1;
|
|
213 |
|
|
214 |
else if (isinf (computed) && isinf (expected))
|
|
215 |
{
|
|
216 |
/* Test for sign of infinities. */
|
|
217 |
if ((IGNORE_ZERO_INF_SIGN) == 0
|
|
218 |
&& signbit (computed) != signbit (expected))
|
|
219 |
{
|
|
220 |
ok = 0;
|
|
221 |
}
|
|
222 |
else
|
|
223 |
ok = 1;
|
|
224 |
}
|
|
225 |
/* Don't calc ulp for NaNs or infinities. */
|
|
226 |
else if (isinf (computed) || isnan (computed) || isinf (expected) || isnan (expected))
|
|
227 |
ok = 0;
|
|
228 |
else
|
|
229 |
{
|
|
230 |
diff = fabsf(computed - expected);
|
|
231 |
/* ilogb (0) isn't allowed. */
|
|
232 |
if (expected == 0.0)
|
|
233 |
ulp = diff / ldexpf (1.0, - MANT_DIG);
|
|
234 |
else
|
|
235 |
ulp = diff / ldexpf (1.0, ilogbf (expected) - MANT_DIG);
|
|
236 |
|
|
237 |
if ((IGNORE_ZERO_INF_SIGN) == 0
|
|
238 |
&& computed == 0.0 && expected == 0.0
|
|
239 |
&& signbit(computed) != signbit (expected))
|
|
240 |
ok = 0;
|
|
241 |
else if (ulp == 0.0 || (ulp <= max_ulp ))
|
|
242 |
ok = 1;
|
|
243 |
else
|
|
244 |
{
|
|
245 |
ok = 0;
|
|
246 |
}
|
|
247 |
|
|
248 |
}
|
|
249 |
gen_ulp = ulp ;
|
|
250 |
|
|
251 |
return ok;
|
|
252 |
}
|
|
253 |
|
|
254 |
|
|
255 |
int atan2_testL()
|
|
256 |
{
|
|
257 |
// Create temporary variables in stack
|
|
258 |
//char Tname[] = "atan2l_test_0_0_0_1";
|
|
259 |
FLOAT input1 = 0;
|
|
260 |
FLOAT input2 = 1;
|
|
261 |
FLOAT expected = 0;
|
|
262 |
FLOAT max_ulp = 0;
|
|
263 |
FLOAT gen_ulp;
|
|
264 |
|
|
265 |
// Read parameters
|
|
266 |
|
|
267 |
|
|
268 |
// Do some testing
|
|
269 |
FLOAT res = atan2f(input1, input2);
|
|
270 |
|
|
271 |
if(check_float(res, expected, max_ulp, gen_ulp))
|
|
272 |
{
|
|
273 |
return 0;
|
|
274 |
}
|
|
275 |
else
|
|
276 |
{
|
|
277 |
return -1;
|
|
278 |
}
|
|
279 |
|
|
280 |
}
|
|
281 |
|
|
282 |
|
|
283 |
#define TESTFILE "c:\\foo.gz"
|
|
284 |
int Gzprintf()
|
|
285 |
{
|
|
286 |
int res = KErrNone ;
|
|
287 |
gzFile file;
|
|
288 |
const char * fname = TESTFILE ;
|
|
289 |
file = gzopen(fname, "wb");
|
|
290 |
if (file == NULL)
|
|
291 |
{
|
|
292 |
res = KErrGeneral;
|
|
293 |
return res;
|
|
294 |
}
|
|
295 |
if (gzprintf(file, ", %s!", "hello") != 8)
|
|
296 |
{
|
|
297 |
return KErrNone;
|
|
298 |
}
|
|
299 |
|
|
300 |
int err = gzclose(file);
|
|
301 |
if(err == 0)
|
|
302 |
{
|
|
303 |
res = KErrNone ;
|
|
304 |
}
|
|
305 |
else
|
|
306 |
{
|
|
307 |
res =res= KErrGeneral;
|
|
308 |
}
|
|
309 |
return res;
|
|
310 |
}
|
|
311 |
|
|
312 |
|
|
313 |
int getpwnam_negL( )
|
|
314 |
{
|
|
315 |
//__UHEAP_MARK;
|
|
316 |
// Create temporary variables in stack
|
|
317 |
struct passwd* pwd;
|
|
318 |
char pw_nam[]="abc";
|
|
319 |
|
|
320 |
pwd=getpwnam(pw_nam);
|
|
321 |
|
|
322 |
// Set test result
|
|
323 |
if(pwd==NULL)
|
|
324 |
{
|
|
325 |
return 0;
|
|
326 |
}
|
|
327 |
else
|
|
328 |
{
|
|
329 |
return -1;
|
|
330 |
}
|
|
331 |
|
|
332 |
//__UHEAP_MARKEND;
|
|
333 |
}
|
|
334 |
|
|
335 |
int check (int thing, int number)
|
|
336 |
{
|
|
337 |
if (!thing)
|
|
338 |
{
|
|
339 |
return -1;
|
|
340 |
}
|
|
341 |
else
|
|
342 |
return KErrNone;
|
|
343 |
}
|
|
344 |
|
|
345 |
/* Complain if first two args don't strcmp as equal. */
|
|
346 |
int equal (const char *a, const char *b, int number)
|
|
347 |
{
|
|
348 |
return check(a != NULL && b != NULL && (strcmp((a), (b)) == 0), number);
|
|
349 |
}
|
|
350 |
|
|
351 |
|
|
352 |
int memcpy2()
|
|
353 |
{
|
|
354 |
char one[50];
|
|
355 |
(void) strcpy(one, "abc");
|
|
356 |
(void) memcpy(one, "xyz", 0);
|
|
357 |
return equal(one, "abc", 4); /* Zero-length copy. */
|
|
358 |
}
|
|
359 |
|
|
360 |
int strcmp1()
|
|
361 |
{
|
|
362 |
|
|
363 |
int retval;
|
|
364 |
//STEP 1
|
|
365 |
retval = check (strcmp ("a", "a") == 0, 2); /* Identity. */
|
|
366 |
if (retval == KErrNone)
|
|
367 |
retval = check (strcmp ("abc", "abc") == 0, 3); /* Multicharacter. */
|
|
368 |
|
|
369 |
return retval;
|
|
370 |
}
|
|
371 |
|
|
372 |
int strcat2()
|
|
373 |
{
|
|
374 |
|
|
375 |
char one[50];
|
|
376 |
int retval;
|
|
377 |
|
|
378 |
//STEP 2
|
|
379 |
(void) strcpy (one, "");
|
|
380 |
(void) strcat (one, "");
|
|
381 |
retval = equal (one, "", 7); /* Boundary conditions. */
|
|
382 |
if (retval == KErrNone)
|
|
383 |
{
|
|
384 |
(void) strcpy (one, "ab");
|
|
385 |
(void) strcat (one, "");
|
|
386 |
retval = equal (one, "ab", 8);
|
|
387 |
if (retval == KErrNone)
|
|
388 |
{
|
|
389 |
(void) strcpy (one, "");
|
|
390 |
(void) strcat (one, "cd");
|
|
391 |
retval = equal (one, "cd", 9);
|
|
392 |
}
|
|
393 |
}
|
|
394 |
return retval;
|
|
395 |
}
|
|
396 |
|
|
397 |
|
|
398 |
|
|
399 |
static int
|
|
400 |
do_test ()
|
|
401 |
{
|
|
402 |
int nfns;
|
|
403 |
int retval =0;
|
|
404 |
int i;
|
|
405 |
int (*pfnArray[])() =
|
|
406 |
{
|
|
407 |
strcat2,
|
|
408 |
strcmp1,
|
|
409 |
memcpy2,
|
|
410 |
getpwnam_negL,
|
|
411 |
Gzprintf,
|
|
412 |
atan2_testL,
|
|
413 |
TestSem390,
|
|
414 |
TestSem316,
|
|
415 |
TestCond688,
|
|
416 |
};
|
|
417 |
|
|
418 |
nfns = (sizeof pfnArray)/(sizeof (int (*)()));
|
|
419 |
for(i=0; i<nfns; i++)
|
|
420 |
{
|
|
421 |
retval += pfnArray[i]();
|
|
422 |
}
|
|
423 |
return retval;
|
|
424 |
}
|
|
425 |
|
|
426 |
int
|
|
427 |
main (int argc, char *argv[])
|
|
428 |
{
|
|
429 |
int retval = 0;
|
|
430 |
retval = do_test();
|
|
431 |
testResultXml("gcce-validate",retval);
|
|
432 |
}
|