|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Name : tclockblocks.cpp |
|
15 // Test cases for blocking signal api's |
|
16 // |
|
17 // |
|
18 |
|
19 #include "tclock.h" |
|
20 |
|
21 // ----------------------------------------------------------------------------- |
|
22 // CTestclock::Testgetclockid1 |
|
23 // Test Case ID: OPENENV-LIBC-CIT-5946 |
|
24 // API tested: clock_getcpuclockid() |
|
25 // Description: To access the clock id of CPU time clock with pid = 0. API tested: clock_getcpuclockid() |
|
26 // ----------------------------------------------------------------------------- |
|
27 |
|
28 TInt CTestclock::Testgetclockid1 ( ) |
|
29 { |
|
30 int ret, ret1 = KErrGeneral; |
|
31 clockid_t clockid; |
|
32 ret = clock_getcpuclockid(0,&clockid); |
|
33 if (ret != 0) |
|
34 { |
|
35 ERR_PRINTF2(_L("Failed to retrieve the clock id of the calling process and errno is %d"),errno); |
|
36 goto close; |
|
37 } |
|
38 if (clockid != CLOCK_REALTIME) |
|
39 { |
|
40 ERR_PRINTF1(_L("Failed to return the right clock id")); |
|
41 goto close; |
|
42 } |
|
43 INFO_PRINTF1(_L("Successfully able to get the calling process's clock id") ); |
|
44 ret1 = KErrNone; |
|
45 |
|
46 close: |
|
47 return ret1; |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CTestclock::Testgetclockid2 |
|
52 // Test Case ID: OPENENV-LIBC-CIT-5946 |
|
53 // API tested: clock_getcpuclockid() |
|
54 // Description: To access the clock id of CPU time clock of self. API tested: clock_getcpuclockid() |
|
55 // ----------------------------------------------------------------------------- |
|
56 |
|
57 TInt CTestclock::Testgetclockid2 ( ) |
|
58 { |
|
59 int ret, ret1 = KErrGeneral; |
|
60 clockid_t clockid; |
|
61 ret = clock_getcpuclockid(getpid(),&clockid); |
|
62 if ((ret != -1) || (errno != ESRCH)) |
|
63 { |
|
64 ERR_PRINTF2(_L("clock_getcpuclockid() failed on negative test and errno is %d"),errno); |
|
65 goto close; |
|
66 } |
|
67 INFO_PRINTF1(_L("clock_getcpuclockid() is successful on negative test") ); |
|
68 ret1 = KErrNone; |
|
69 |
|
70 close: |
|
71 return ret1; |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CTestclock::Testgetclockid3 |
|
76 // Test Case ID: OPENENV-LIBC-CIT-5946 |
|
77 // API tested: clock_getcpuclockid() |
|
78 // Description: To access the clock id of CPU time clock of other process |
|
79 // ----------------------------------------------------------------------------- |
|
80 |
|
81 TInt CTestclock::Testgetclockid3 ( ) |
|
82 { |
|
83 int ret, ret1 = KErrGeneral; |
|
84 pid_t pid; |
|
85 clockid_t clockid; |
|
86 char **argv = (char **)malloc(2*sizeof(char*)); |
|
87 argv[0] = (char *)malloc(30*sizeof(char*)); |
|
88 argv[1] = 0; |
|
89 strcpy(argv[0],"z:\\sys\\bin\\getclockid.exe"); |
|
90 ret = posix_spawn(&pid, "z:\\sys\\bin\\getclockid.exe", NULL, NULL, argv, (char**)NULL); |
|
91 if(ret != 0) |
|
92 { |
|
93 ERR_PRINTF2(_L("Error in posix spawn and errno is set to %d"),errno); |
|
94 goto close; |
|
95 } |
|
96 ret = clock_getcpuclockid(pid,&clockid); |
|
97 if ((ret != -1) || (errno != ESRCH)) |
|
98 { |
|
99 ERR_PRINTF2(_L("clock_getcpuclockid() failed on negative test and errno is %d"),errno); |
|
100 goto close; |
|
101 } |
|
102 INFO_PRINTF1(_L("clock_getcpuclockid() is successful on negative test") ); |
|
103 ret1 = KErrNone; |
|
104 |
|
105 close: |
|
106 free((void*)argv[0]); |
|
107 free((void*)argv); |
|
108 return ret1; |
|
109 } |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // CTestclock::Testgetclockid4 |
|
113 // Test Case ID: OPENENV-LIBC-CIT-5946 |
|
114 // API tested: clock_getcpuclockid() |
|
115 // Description: To access the clock id of CPU time clock of an invalid process. |
|
116 // ----------------------------------------------------------------------------- |
|
117 |
|
118 TInt CTestclock::Testgetclockid4 ( ) |
|
119 { |
|
120 int ret, ret1 = KErrGeneral; |
|
121 clockid_t clockid; |
|
122 ret = clock_getcpuclockid(-1,&clockid); |
|
123 if ((ret != -1) || (errno != ESRCH)) |
|
124 { |
|
125 ERR_PRINTF2(_L("clock_getcpuclockid() failed on negative test and errno is %d"),errno); |
|
126 goto close; |
|
127 } |
|
128 INFO_PRINTF1(_L("clock_getcpuclockid() has successfully returned ESRCH on negative test") ); |
|
129 ret1 = KErrNone; |
|
130 |
|
131 close: |
|
132 return ret1; |
|
133 } |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 // CTestclock::Testgetclockid5 |
|
137 // Test Case ID: OPENENV-LIBC-CIT-5946 |
|
138 // API tested: clock_getcpuclockid() |
|
139 // Description: Trying to access the clock id of an invalid id passing to it. |
|
140 // ----------------------------------------------------------------------------- |
|
141 |
|
142 TInt CTestclock::Testgetclockid5 ( ) |
|
143 { |
|
144 int ret, ret1 = KErrGeneral; |
|
145 ret = clock_getcpuclockid(0,NULL); |
|
146 if ((ret != -1) || (errno != EFAULT)) |
|
147 { |
|
148 ERR_PRINTF2(_L("clock_getcpuclockid() failed on negative test and errno is %d"),errno); |
|
149 goto close; |
|
150 } |
|
151 INFO_PRINTF1(_L("clock_getcpuclockid() has successfully returned EFAULT on negative test") ); |
|
152 ret1 = KErrNone; |
|
153 |
|
154 close: |
|
155 return ret1; |
|
156 } |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // CTestclock::Testclockresolution1 |
|
160 // Test Case ID: OPENENV-LIBC-CIT-5946 |
|
161 // API tested: clock_getres() |
|
162 // Description: To get the clock resolution with valid clock id using clock_getres() |
|
163 // ----------------------------------------------------------------------------- |
|
164 |
|
165 TInt CTestclock::Testclockresolution1 ( ) |
|
166 { |
|
167 int ret, ret1 = KErrGeneral; |
|
168 clockid_t clockid; |
|
169 struct timespec tmspec; |
|
170 ret = clock_getcpuclockid(0,&clockid); |
|
171 if (ret != 0) |
|
172 { |
|
173 ERR_PRINTF2(_L("Failed to retrieve the clock id of the calling process and errno is %d"),errno); |
|
174 goto close; |
|
175 } |
|
176 ret = clock_getres(clockid,&tmspec); |
|
177 if (ret != 0) |
|
178 { |
|
179 ERR_PRINTF2(_L("Failed to retrieve resolution of the clock id specified and errno is %d"),errno); |
|
180 goto close; |
|
181 } |
|
182 if ((tmspec.tv_nsec != 1000) || (tmspec.tv_sec != 0)) |
|
183 { |
|
184 ERR_PRINTF1(_L("Resolution of the clock id is not set properly")); |
|
185 goto close; |
|
186 } |
|
187 INFO_PRINTF1(_L("Successfully able to get the clock resolution of the specified clock id") ); |
|
188 ret1 = KErrNone; |
|
189 |
|
190 close: |
|
191 return ret1; |
|
192 } |
|
193 |
|
194 // ----------------------------------------------------------------------------- |
|
195 // CTestclock::Testclockresolution2 |
|
196 // Test Case ID: OPENENV-LIBC-CIT-5946 |
|
197 // API tested: clock_getres() |
|
198 // Description: Trying to get the clock resolution using clock_getres() for a clockid other than CLOCK_REALTIME |
|
199 // ----------------------------------------------------------------------------- |
|
200 |
|
201 TInt CTestclock::Testclockresolution2 ( ) |
|
202 { |
|
203 int ret, ret1 = KErrGeneral, Clockid, Error; |
|
204 struct timespec tmspec; |
|
205 ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); |
|
206 if(ret == 0) |
|
207 { |
|
208 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ; |
|
209 goto close; |
|
210 } |
|
211 ret = GetIntFromConfig(ConfigSection(), _L("Error"), Error); |
|
212 if(ret == 0) |
|
213 { |
|
214 ERR_PRINTF1(_L("Unable to read expected error num")) ; |
|
215 goto close; |
|
216 } |
|
217 ret = clock_getres(Clockid,&tmspec); |
|
218 if ((ret != -1) || (errno != Error)) |
|
219 { |
|
220 ERR_PRINTF2(_L("The expected and errno are not same and errno is %d"),errno); |
|
221 goto close; |
|
222 } |
|
223 INFO_PRINTF1(_L("The output and expected value are same for clock_getres()") ); |
|
224 ret1 = KErrNone; |
|
225 |
|
226 close: |
|
227 return ret1; |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // CTestclock::Testclockresolution3 |
|
232 // Test Case ID: OPENENV-LIBC-CIT-5946 |
|
233 // API tested: clock_getres() |
|
234 // Description: Negative Test: Trying to get the resolution with res = NULL using clock_getres() |
|
235 // ----------------------------------------------------------------------------- |
|
236 |
|
237 TInt CTestclock::Testclockresolution3 ( ) |
|
238 { |
|
239 int ret, ret1 = KErrGeneral, Clockid; |
|
240 ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); |
|
241 if(ret == 0) |
|
242 { |
|
243 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ; |
|
244 goto close; |
|
245 } |
|
246 ret = clock_getres(Clockid,NULL); |
|
247 if (ret != 0) |
|
248 { |
|
249 ERR_PRINTF2(_L("clock_getres() failed on negative test if timespec argument is NULL and errno is %d"),errno); |
|
250 goto close; |
|
251 } |
|
252 INFO_PRINTF1(_L("clock_getres() successfully returned 0 on negative test") ); |
|
253 ret1 = KErrNone; |
|
254 |
|
255 close: |
|
256 return ret1; |
|
257 } |
|
258 |
|
259 // ----------------------------------------------------------------------------- |
|
260 // CTestclock::Testclocknanosleep1 |
|
261 // Test Case ID: OPENENV-LIBC-CIT-5946 |
|
262 // API tested: clock_nanosleep() |
|
263 // Description: Trying to suspend the process for the specified time using clock_nanosleep() in the absence of TIMER_ABSTIME |
|
264 // Relative timer |
|
265 // ----------------------------------------------------------------------------- |
|
266 |
|
267 TInt CTestclock::Testclocknanosleep1 ( ) |
|
268 { |
|
269 int ret, ret1 = KErrGeneral, Valuesec, Valuenanosec; |
|
270 struct timespec gettmspec, oldtmpsec, sleeptmspec, sleeptmspec1; |
|
271 ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec); |
|
272 if(ret == 0) |
|
273 { |
|
274 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ; |
|
275 goto close; |
|
276 } |
|
277 ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec); |
|
278 if(ret == 0) |
|
279 { |
|
280 ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ; |
|
281 goto close; |
|
282 } |
|
283 sleeptmspec.tv_sec = Valuesec; |
|
284 sleeptmspec.tv_nsec = Valuenanosec; |
|
285 ret = clock_gettime(CLOCK_REALTIME,&gettmspec); |
|
286 if (ret != 0) |
|
287 { |
|
288 ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno); |
|
289 goto close; |
|
290 } |
|
291 oldtmpsec = gettmspec; |
|
292 ret = clock_nanosleep(CLOCK_REALTIME,0,&sleeptmspec,&sleeptmspec1); |
|
293 if (ret != 0) |
|
294 { |
|
295 ERR_PRINTF2(_L("clock_nanosleep() failed and errno is %d"),errno); |
|
296 goto close; |
|
297 } |
|
298 ret = clock_gettime(CLOCK_REALTIME,&gettmspec); |
|
299 if (ret != 0) |
|
300 { |
|
301 ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno); |
|
302 goto close; |
|
303 } |
|
304 if (gettmspec.tv_sec != (oldtmpsec.tv_sec + Valuesec)) |
|
305 { |
|
306 ERR_PRINTF2(_L("clock_nanosleep() has failed to sleep for %d secs"),Valuesec); |
|
307 goto close; |
|
308 } |
|
309 INFO_PRINTF1(_L("Relative timer")); |
|
310 INFO_PRINTF2(_L("clock_nanosleep() successfully able to sleep for %d secs"),Valuesec ); |
|
311 ret1 = KErrNone; |
|
312 |
|
313 close: |
|
314 return ret1; |
|
315 } |
|
316 |
|
317 // ----------------------------------------------------------------------------- |
|
318 // CTestclock::Testclocknanosleep2 |
|
319 // Test Case ID: OPENENV-LIBC-CIT-5946 |
|
320 // API tested: clock_nanosleep() |
|
321 // Description: Trying to suspend the process for the specified time using clock_nanosleep() |
|
322 // Absolute timer |
|
323 // ----------------------------------------------------------------------------- |
|
324 |
|
325 TInt CTestclock::Testclocknanosleep2 ( ) |
|
326 { |
|
327 int ret, ret1 = KErrGeneral, Valuesec, Valuenanosec; |
|
328 struct timespec gettmspec, oldtmpsec, sleeptmspec, sleeptmspec1; |
|
329 ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec); |
|
330 if(ret == 0) |
|
331 { |
|
332 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ; |
|
333 goto close; |
|
334 } |
|
335 ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec); |
|
336 if(ret == 0) |
|
337 { |
|
338 ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ; |
|
339 goto close; |
|
340 } |
|
341 sleeptmspec.tv_sec = Valuesec; |
|
342 sleeptmspec.tv_nsec = Valuenanosec; |
|
343 ret = clock_gettime(CLOCK_REALTIME,&gettmspec); |
|
344 if (ret != 0) |
|
345 { |
|
346 ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno); |
|
347 goto close; |
|
348 } |
|
349 oldtmpsec = gettmspec; |
|
350 sleeptmspec.tv_sec = gettmspec.tv_sec + Valuesec; |
|
351 sleeptmspec.tv_nsec = gettmspec.tv_nsec + Valuenanosec; |
|
352 ret = clock_nanosleep(CLOCK_REALTIME,TIMER_ABSTIME,&sleeptmspec,&sleeptmspec1); |
|
353 if (ret != 0) |
|
354 { |
|
355 ERR_PRINTF2(_L("clock_nanosleep() failed and errno is %d"),errno); |
|
356 goto close; |
|
357 } |
|
358 ret = clock_gettime(CLOCK_REALTIME,&gettmspec); |
|
359 if (ret != 0) |
|
360 { |
|
361 ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno); |
|
362 goto close; |
|
363 } |
|
364 if (gettmspec.tv_sec < (oldtmpsec.tv_sec + Valuesec)) |
|
365 { |
|
366 ERR_PRINTF2(_L("clock_nanosleep() has failed to sleep for %d secs"),Valuesec); |
|
367 goto close; |
|
368 } |
|
369 INFO_PRINTF1(_L("Absolute timer")); |
|
370 INFO_PRINTF2(_L("clock_nanosleep() successfully able to sleep for %d secs"),Valuesec ); |
|
371 ret1 = KErrNone; |
|
372 |
|
373 close: |
|
374 return ret1; |
|
375 } |
|
376 |
|
377 // ----------------------------------------------------------------------------- |
|
378 // CTestclock::Testclocknanosleep3 |
|
379 // Test Case ID: OPENENV-LIBC-CIT-5946 |
|
380 // API tested: clock_nanosleep() |
|
381 // Description: Trying to suspend the process for an invalid time using clock_nanosleep() in the absence of TIMER_ABSTIME |
|
382 // ----------------------------------------------------------------------------- |
|
383 |
|
384 TInt CTestclock::Testclocknanosleep3 ( ) |
|
385 { |
|
386 int ret, ret1 = KErrGeneral, Valuesec, Valuenanosec; |
|
387 struct timespec sleeptmspec; |
|
388 ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec); |
|
389 if(ret == 0) |
|
390 { |
|
391 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ; |
|
392 goto close; |
|
393 } |
|
394 ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec); |
|
395 if(ret == 0) |
|
396 { |
|
397 ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ; |
|
398 goto close; |
|
399 } |
|
400 sleeptmspec.tv_sec = Valuesec; |
|
401 sleeptmspec.tv_nsec = Valuenanosec; |
|
402 ret = clock_nanosleep(CLOCK_REALTIME,0,&sleeptmspec,NULL); |
|
403 if ((ret != -1) || (errno != EINVAL)) |
|
404 { |
|
405 ERR_PRINTF2(_L("clock_nanosleep() failed and errno is %d"),errno); |
|
406 goto close; |
|
407 } |
|
408 INFO_PRINTF1(_L("clock_nanosleep() successfully able to sleep for 2 secs") ); |
|
409 ret1 = KErrNone; |
|
410 |
|
411 close: |
|
412 return ret1; |
|
413 } |
|
414 |
|
415 // ----------------------------------------------------------------------------- |
|
416 // CTestclock::Testclocknanosleep4 |
|
417 // Test Case ID: OPENENV-LIBC-CIT-5946 |
|
418 // API tested: clock_nanosleep() |
|
419 // Description: Trying to suspend the process with an invalid clock id clock_nanosleep() |
|
420 // ----------------------------------------------------------------------------- |
|
421 |
|
422 TInt CTestclock::Testclocknanosleep4 ( ) |
|
423 { |
|
424 int ret, ret1 = KErrGeneral, Invalidid; |
|
425 struct timespec sleeptmspec; |
|
426 ret = GetIntFromConfig(ConfigSection(), _L("Invalidid"), Invalidid); |
|
427 if(ret == 0) |
|
428 { |
|
429 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ; |
|
430 goto close; |
|
431 } |
|
432 sleeptmspec.tv_sec = 2; |
|
433 sleeptmspec.tv_nsec = 0; |
|
434 ret = clock_nanosleep(Invalidid,0,&sleeptmspec,NULL); |
|
435 if ((ret != -1) || (errno != EINVAL)) |
|
436 { |
|
437 ERR_PRINTF2(_L("clock_nanosleep() failed to return EINVAL and errno is %d"),errno); |
|
438 goto close; |
|
439 } |
|
440 INFO_PRINTF1(_L("clock_nanosleep() successfully able to return EINVAL ") ); |
|
441 ret1 = KErrNone; |
|
442 |
|
443 close: |
|
444 return ret1; |
|
445 } |
|
446 |
|
447 // ----------------------------------------------------------------------------- |
|
448 // CTestclock::Testclocknanosleep5 |
|
449 // Test Case ID: OPENENV-LIBC-CIT-5946 |
|
450 // API tested: clock_nanosleep() |
|
451 // Description: clock_nanosleep() with an invalid parameter of timespec |
|
452 // ----------------------------------------------------------------------------- |
|
453 |
|
454 TInt CTestclock::Testclocknanosleep5 ( ) |
|
455 { |
|
456 int ret, ret1 = KErrGeneral; |
|
457 ret = clock_nanosleep(CLOCK_REALTIME,0,NULL,NULL); |
|
458 if ((ret != -1) || (errno != EFAULT)) |
|
459 { |
|
460 ERR_PRINTF2(_L("clock_nanosleep() failed to return EINVAL and errno is %d"),errno); |
|
461 goto close; |
|
462 } |
|
463 INFO_PRINTF1(_L("clock_nanosleep() successfully able to return EINVAL ") ); |
|
464 ret1 = KErrNone; |
|
465 |
|
466 close: |
|
467 return ret1; |
|
468 } |
|
469 |
|
470 // ----------------------------------------------------------------------------- |
|
471 // CTestclock::Testclocknanosleep6 |
|
472 // Test Case ID: OPENENV-LIBC-CIT-5946 |
|
473 // API tested: clock_nanosleep() |
|
474 // Description: clock_nanosleep() with a flag other than Absolute value |
|
475 // ----------------------------------------------------------------------------- |
|
476 |
|
477 TInt CTestclock::Testclocknanosleep6 ( ) |
|
478 { |
|
479 int ret, ret1 = KErrGeneral, Valuesec, Valuenanosec; |
|
480 struct timespec gettmspec, oldtmpsec, sleeptmspec, sleeptmspec1; |
|
481 ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec); |
|
482 if(ret == 0) |
|
483 { |
|
484 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ; |
|
485 goto close; |
|
486 } |
|
487 ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec); |
|
488 if(ret == 0) |
|
489 { |
|
490 ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ; |
|
491 goto close; |
|
492 } |
|
493 sleeptmspec.tv_sec = Valuesec; |
|
494 sleeptmspec.tv_nsec = Valuenanosec; |
|
495 ret = clock_gettime(CLOCK_REALTIME,&gettmspec); |
|
496 if (ret != 0) |
|
497 { |
|
498 ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno); |
|
499 goto close; |
|
500 } |
|
501 oldtmpsec = gettmspec; |
|
502 ret = clock_nanosleep(CLOCK_REALTIME,15,&sleeptmspec,&sleeptmspec1); |
|
503 if (ret != 0) |
|
504 { |
|
505 ERR_PRINTF2(_L("clock_nanosleep() failed and errno is %d"),errno); |
|
506 goto close; |
|
507 } |
|
508 ret = clock_gettime(CLOCK_REALTIME,&gettmspec); |
|
509 if (ret != 0) |
|
510 { |
|
511 ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno); |
|
512 goto close; |
|
513 } |
|
514 if (gettmspec.tv_sec != (oldtmpsec.tv_sec + Valuesec)) |
|
515 { |
|
516 ERR_PRINTF2(_L("clock_nanosleep() has failed to sleep for %d secs"),Valuesec); |
|
517 goto close; |
|
518 } |
|
519 INFO_PRINTF1(_L("Relative timer")); |
|
520 INFO_PRINTF2(_L("clock_nanosleep() successfully able to sleep for %d secs"),Valuesec ); |
|
521 ret1 = KErrNone; |
|
522 |
|
523 close: |
|
524 return ret1; |
|
525 } |
|
526 |
|
527 // ----------------------------------------------------------------------------- |
|
528 // CTestclock::Testclockgettime1 |
|
529 // Test Case ID: OPENENV-LIBC-CIT-5946 |
|
530 // API tested: clock_gettime() |
|
531 // Description: To get the current value for the specified valid clock_id<CLOCK_REALTIME> |
|
532 // ----------------------------------------------------------------------------- |
|
533 |
|
534 TInt CTestclock::Testclockgettime1 ( ) |
|
535 { |
|
536 int ret, ret1 = KErrGeneral; |
|
537 clockid_t clockid; |
|
538 struct timespec tmspec, oldtmspec; |
|
539 ret = clock_getcpuclockid(0,&clockid); |
|
540 if (ret != 0) |
|
541 { |
|
542 ERR_PRINTF2(_L("Failed to retrieve the clock id of the calling process and errno is %d"),errno); |
|
543 goto close; |
|
544 } |
|
545 ret = clock_gettime(clockid,&tmspec); |
|
546 if (ret != 0) |
|
547 { |
|
548 ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno); |
|
549 goto close; |
|
550 } |
|
551 sleep(2); |
|
552 oldtmspec = tmspec; |
|
553 ret = clock_gettime(clockid,&tmspec); |
|
554 if (ret != 0) |
|
555 { |
|
556 ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno); |
|
557 goto close; |
|
558 } |
|
559 if (tmspec.tv_sec != (oldtmspec.tv_sec + 2)) |
|
560 { |
|
561 ERR_PRINTF1(_L("Failed to retrieve resolution of the clock id specified")); |
|
562 goto close; |
|
563 } |
|
564 INFO_PRINTF1(_L("clock_gettime() successfully able to get the time") ); |
|
565 ret1 = KErrNone; |
|
566 |
|
567 close: |
|
568 return ret1; |
|
569 } |
|
570 |
|
571 // ----------------------------------------------------------------------------- |
|
572 // CTestclock::Testclockgettime2 |
|
573 // Test Case ID: OPENENV-LIBC-CIT-5946 |
|
574 // API tested: clock_gettime() |
|
575 // Description: Trying to get the current time value for an invalid clock id using clock_gettime() |
|
576 // ----------------------------------------------------------------------------- |
|
577 |
|
578 TInt CTestclock::Testclockgettime2 ( ) |
|
579 { |
|
580 int ret, ret1 = KErrGeneral, Clockid, Error; |
|
581 struct timespec tmspec; |
|
582 ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); |
|
583 if(ret == 0) |
|
584 { |
|
585 ERR_PRINTF1(_L("Unable to clock id value")) ; |
|
586 goto close; |
|
587 } |
|
588 ret = GetIntFromConfig(ConfigSection(), _L("Error"), Error); |
|
589 if(ret == 0) |
|
590 { |
|
591 ERR_PRINTF1(_L("Unable to read expected error num")) ; |
|
592 goto close; |
|
593 } |
|
594 ret = clock_gettime(Clockid,&tmspec); |
|
595 if ((ret != -1) || (errno != Error)) |
|
596 { |
|
597 ERR_PRINTF2(_L("clock_gettime() failed to return EINVAL for an invalid clock id and errno is %d"),errno); |
|
598 goto close; |
|
599 } |
|
600 INFO_PRINTF1(_L("clock_gettime() successfully returned EINVAL for an invalid clock id") ); |
|
601 ret1 = KErrNone; |
|
602 |
|
603 close: |
|
604 return ret1; |
|
605 } |
|
606 |
|
607 // ----------------------------------------------------------------------------- |
|
608 // CTestclock::Testclockgettime3 |
|
609 // Test Case ID: OPENENV-LIBC-CIT-5946 |
|
610 // API tested: clock_gettime() |
|
611 // Description: Trying to get the current time value for a valid clock id with NULL as the timespec using clock_gettime() |
|
612 // ----------------------------------------------------------------------------- |
|
613 |
|
614 TInt CTestclock::Testclockgettime3 ( ) |
|
615 { |
|
616 int ret, ret1 = KErrGeneral, Clockid; |
|
617 ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); |
|
618 if(ret == 0) |
|
619 { |
|
620 ERR_PRINTF1(_L("Unable to read clock id value")) ; |
|
621 goto close; |
|
622 } |
|
623 ret = clock_gettime(Clockid,NULL); |
|
624 if ((ret != -1) || (errno != EFAULT)) |
|
625 { |
|
626 ERR_PRINTF2(_L("clock_gettime() failed to return EFAULT for NULL timespec parameter and errno is %d"),errno); |
|
627 goto close; |
|
628 } |
|
629 INFO_PRINTF1(_L("clock_gettime() successfully returned EFAULT for NULL timespec parameter ") ); |
|
630 ret1 = KErrNone; |
|
631 |
|
632 close: |
|
633 return ret1; |
|
634 } |
|
635 |
|
636 // ----------------------------------------------------------------------------- |
|
637 // CTestclock::Testclocksettime1 |
|
638 // Test Case ID: OPENENV-LIBC-CIT-5946 |
|
639 // API tested: clock_settime() |
|
640 // Description: Trying to set the current time value for an invalid clock id using clock_settime() |
|
641 // ----------------------------------------------------------------------------- |
|
642 |
|
643 TInt CTestclock::Testclocksettime1 ( ) |
|
644 { |
|
645 int ret, ret1 = KErrGeneral, Clockid, Error; |
|
646 struct timespec tmspec; |
|
647 tmspec.tv_sec = 30; |
|
648 tmspec.tv_nsec = 2000; |
|
649 ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); |
|
650 if(ret == 0) |
|
651 { |
|
652 ERR_PRINTF1(_L("Unable to read clock id value")) ; |
|
653 goto close; |
|
654 } |
|
655 ret = GetIntFromConfig(ConfigSection(), _L("Error"), Error); |
|
656 if(ret == 0) |
|
657 { |
|
658 ERR_PRINTF1(_L("Unable to read expected error num")) ; |
|
659 goto close; |
|
660 } |
|
661 ret = clock_settime(Clockid,&tmspec); |
|
662 if ((ret != -1) || (errno != Error)) |
|
663 { |
|
664 ERR_PRINTF2(_L("clock_settime() failed on negative test and errno is %d"),errno); |
|
665 goto close; |
|
666 } |
|
667 INFO_PRINTF1(_L("clock_settime() is successfull on negative test") ); |
|
668 ret1 = KErrNone; |
|
669 |
|
670 close: |
|
671 return ret1; |
|
672 } |
|
673 |
|
674 // ----------------------------------------------------------------------------- |
|
675 // CTestclock::Testclocksettime2 |
|
676 // Test Case ID: OPENENV-LIBC-CIT-5946 |
|
677 // API tested: clock_settime() |
|
678 // Description: clock_settime() with NULL as the timespec parameter |
|
679 // ----------------------------------------------------------------------------- |
|
680 |
|
681 TInt CTestclock::Testclocksettime2 ( ) |
|
682 { |
|
683 int ret, ret1 = KErrGeneral, Clockid; |
|
684 ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); |
|
685 if(ret == 0) |
|
686 { |
|
687 ERR_PRINTF1(_L("Unable to read clock id value")) ; |
|
688 goto close; |
|
689 } |
|
690 ret = clock_settime(Clockid,NULL); |
|
691 if ((ret != -1) || (errno != EFAULT)) |
|
692 { |
|
693 ERR_PRINTF2(_L("clock_settime() failed to return EFAULT on negative test and errno is %d"),errno); |
|
694 goto close; |
|
695 } |
|
696 INFO_PRINTF1(_L("clock_settime() successfully returned EFAULT on negative test") ); |
|
697 ret1 = KErrNone; |
|
698 |
|
699 close: |
|
700 return ret1; |
|
701 } |
|
702 |
|
703 // ----------------------------------------------------------------------------- |
|
704 // CTestclock::Testclocksettime3 |
|
705 // Test Case ID: OPENENV-LIBC-CIT-5946 |
|
706 // API tested: clock_settime() |
|
707 // Description: Test case added to set the value of clock id current value to an invalid specified value using clock_settime() |
|
708 // ----------------------------------------------------------------------------- |
|
709 |
|
710 TInt CTestclock::Testclocksettime3 ( ) |
|
711 { |
|
712 int ret, ret1 = KErrGeneral, Clockid, Valuesec, Valuenanosec; |
|
713 struct timespec tmspec; |
|
714 ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); |
|
715 if(ret == 0) |
|
716 { |
|
717 ERR_PRINTF1(_L("Unable to read clock id value")) ; |
|
718 goto close; |
|
719 } |
|
720 ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec); |
|
721 if(ret == 0) |
|
722 { |
|
723 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ; |
|
724 goto close; |
|
725 } |
|
726 ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec); |
|
727 if(ret == 0) |
|
728 { |
|
729 ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ; |
|
730 goto close; |
|
731 } |
|
732 tmspec.tv_sec = Valuesec; |
|
733 tmspec.tv_nsec = Valuenanosec; |
|
734 ret = clock_settime(Clockid,&tmspec); |
|
735 if ((ret != -1) || (errno != EINVAL)) |
|
736 { |
|
737 ERR_PRINTF2(_L("clock_settime() failed to return EINVAL on negative test and errno is %d"),errno); |
|
738 goto close; |
|
739 } |
|
740 INFO_PRINTF1(_L("clock_settime() successfully returned EINVAL on negative test") ); |
|
741 ret1 = KErrNone; |
|
742 |
|
743 close: |
|
744 return ret1; |
|
745 } |
|
746 |
|
747 //End of a file |