sl@0
|
1 |
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// Name : ttimerblocks.cpp
|
sl@0
|
15 |
// Test cases for blocking signal api's
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
#include "ttimer.h"
|
sl@0
|
21 |
#include "ttimerthread.h"
|
sl@0
|
22 |
#define Maxtimerid 512
|
sl@0
|
23 |
int timer_value = 0;
|
sl@0
|
24 |
|
sl@0
|
25 |
RSemaphore iLock;
|
sl@0
|
26 |
void CreateLock()
|
sl@0
|
27 |
{
|
sl@0
|
28 |
iLock.CreateLocal(0);
|
sl@0
|
29 |
}
|
sl@0
|
30 |
void ReleaseLock()
|
sl@0
|
31 |
{
|
sl@0
|
32 |
iLock.Signal();
|
sl@0
|
33 |
}
|
sl@0
|
34 |
void AcquireLock()
|
sl@0
|
35 |
{
|
sl@0
|
36 |
iLock.Wait();
|
sl@0
|
37 |
}
|
sl@0
|
38 |
|
sl@0
|
39 |
//signal handler
|
sl@0
|
40 |
void sig_handler(int sig)
|
sl@0
|
41 |
{
|
sl@0
|
42 |
timer_value = sig;
|
sl@0
|
43 |
ReleaseLock();
|
sl@0
|
44 |
}
|
sl@0
|
45 |
|
sl@0
|
46 |
//overrun signal handler
|
sl@0
|
47 |
void overrun_handler(int sig)
|
sl@0
|
48 |
{
|
sl@0
|
49 |
timer_value = sig;
|
sl@0
|
50 |
sleep(1);
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
//notification function
|
sl@0
|
54 |
void notifyfunc(union sigval val)
|
sl@0
|
55 |
{
|
sl@0
|
56 |
timer_value = val.sival_int;
|
sl@0
|
57 |
}
|
sl@0
|
58 |
|
sl@0
|
59 |
void alarm_handler(int sig)
|
sl@0
|
60 |
{
|
sl@0
|
61 |
timer_value = sig;
|
sl@0
|
62 |
}
|
sl@0
|
63 |
|
sl@0
|
64 |
// -----------------------------------------------------------------------------
|
sl@0
|
65 |
// CTesttimer::Testtimerapi1
|
sl@0
|
66 |
// Test Case ID: OPENENV-LIBC-CIT-5946
|
sl@0
|
67 |
// API tested: timer_create(), timer_delete()
|
sl@0
|
68 |
// Description: Test case to create a timer with NONE as sigev_notify parameter
|
sl@0
|
69 |
// TIMER_ABSTIME not set
|
sl@0
|
70 |
// -----------------------------------------------------------------------------
|
sl@0
|
71 |
|
sl@0
|
72 |
TInt CTesttimer::Testtimerapi1 ( )
|
sl@0
|
73 |
{
|
sl@0
|
74 |
int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
|
sl@0
|
75 |
struct sigevent sigev;
|
sl@0
|
76 |
struct itimerspec timerspec;
|
sl@0
|
77 |
timer_value = 0;
|
sl@0
|
78 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
|
sl@0
|
79 |
if(ret == 0)
|
sl@0
|
80 |
{
|
sl@0
|
81 |
ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
|
sl@0
|
82 |
return ret1;
|
sl@0
|
83 |
}
|
sl@0
|
84 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
|
sl@0
|
85 |
if(ret == 0)
|
sl@0
|
86 |
{
|
sl@0
|
87 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
|
sl@0
|
88 |
return ret1;
|
sl@0
|
89 |
}
|
sl@0
|
90 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
|
sl@0
|
91 |
if(ret == 0)
|
sl@0
|
92 |
{
|
sl@0
|
93 |
ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
|
sl@0
|
94 |
return ret1;
|
sl@0
|
95 |
}
|
sl@0
|
96 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
|
sl@0
|
97 |
if(ret == 0)
|
sl@0
|
98 |
{
|
sl@0
|
99 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
|
sl@0
|
100 |
return ret1;
|
sl@0
|
101 |
}
|
sl@0
|
102 |
sigev.sigev_notify = SIGEV_NONE;
|
sl@0
|
103 |
timer_t timerid;
|
sl@0
|
104 |
ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
|
sl@0
|
105 |
|
sl@0
|
106 |
if(ret != 0)
|
sl@0
|
107 |
{
|
sl@0
|
108 |
ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
|
sl@0
|
109 |
return -1;
|
sl@0
|
110 |
}
|
sl@0
|
111 |
INFO_PRINTF1(_L("Successfully able to create a timer") );
|
sl@0
|
112 |
timerspec.it_value.tv_sec = Valuesec;
|
sl@0
|
113 |
timerspec.it_value.tv_nsec = Valuenanosec;
|
sl@0
|
114 |
timerspec.it_interval.tv_sec = Intervalsec;
|
sl@0
|
115 |
timerspec.it_interval.tv_nsec = Intervalnanosec;
|
sl@0
|
116 |
ret = timer_settime(timerid,0,&timerspec,NULL);
|
sl@0
|
117 |
if(ret != 0)
|
sl@0
|
118 |
{
|
sl@0
|
119 |
ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
|
sl@0
|
120 |
ret1 = -1;
|
sl@0
|
121 |
goto close;
|
sl@0
|
122 |
}
|
sl@0
|
123 |
sleep(2);
|
sl@0
|
124 |
INFO_PRINTF1(_L("Successfully able to set the timer") );
|
sl@0
|
125 |
ret = timer_delete(timerid);
|
sl@0
|
126 |
if(ret != 0)
|
sl@0
|
127 |
{
|
sl@0
|
128 |
ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
|
sl@0
|
129 |
return -1;
|
sl@0
|
130 |
}
|
sl@0
|
131 |
INFO_PRINTF1(_L("Successfully able to delete the timer") );
|
sl@0
|
132 |
ret1 = KErrNone;
|
sl@0
|
133 |
return ret1;
|
sl@0
|
134 |
close:
|
sl@0
|
135 |
timer_delete(timerid);
|
sl@0
|
136 |
return ret1;
|
sl@0
|
137 |
}
|
sl@0
|
138 |
|
sl@0
|
139 |
// -----------------------------------------------------------------------------
|
sl@0
|
140 |
// CTesttimer::Testtimerapi2
|
sl@0
|
141 |
// Test Case ID: OPENENV-LIBC-CIT-5946
|
sl@0
|
142 |
// API tested: timer_create(), timer_delete()
|
sl@0
|
143 |
// Description: Test case to create a timer with NONE as sigev_notify parameter
|
sl@0
|
144 |
// TIMER_ABSTIME set
|
sl@0
|
145 |
// -----------------------------------------------------------------------------
|
sl@0
|
146 |
|
sl@0
|
147 |
TInt CTesttimer::Testtimerapi2 ( )
|
sl@0
|
148 |
{
|
sl@0
|
149 |
int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
|
sl@0
|
150 |
struct sigevent sigev;
|
sl@0
|
151 |
struct itimerspec timerspec;
|
sl@0
|
152 |
struct timespec curtmspec;
|
sl@0
|
153 |
timer_value = 0;
|
sl@0
|
154 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
|
sl@0
|
155 |
if(ret == 0)
|
sl@0
|
156 |
{
|
sl@0
|
157 |
ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
|
sl@0
|
158 |
return ret1;
|
sl@0
|
159 |
}
|
sl@0
|
160 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
|
sl@0
|
161 |
if(ret == 0)
|
sl@0
|
162 |
{
|
sl@0
|
163 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
|
sl@0
|
164 |
return ret1;
|
sl@0
|
165 |
}
|
sl@0
|
166 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
|
sl@0
|
167 |
if(ret == 0)
|
sl@0
|
168 |
{
|
sl@0
|
169 |
ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
|
sl@0
|
170 |
return ret1;
|
sl@0
|
171 |
}
|
sl@0
|
172 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
|
sl@0
|
173 |
if(ret == 0)
|
sl@0
|
174 |
{
|
sl@0
|
175 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
|
sl@0
|
176 |
return ret1;
|
sl@0
|
177 |
}
|
sl@0
|
178 |
sigev.sigev_notify = SIGEV_NONE;
|
sl@0
|
179 |
timer_t timerid;
|
sl@0
|
180 |
ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
|
sl@0
|
181 |
if(ret != 0)
|
sl@0
|
182 |
{
|
sl@0
|
183 |
ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
|
sl@0
|
184 |
return -1;
|
sl@0
|
185 |
}
|
sl@0
|
186 |
INFO_PRINTF1(_L("Successfully able to create a timer") );
|
sl@0
|
187 |
ret = clock_gettime(CLOCK_REALTIME,&curtmspec);
|
sl@0
|
188 |
if (ret != 0)
|
sl@0
|
189 |
{
|
sl@0
|
190 |
ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
|
sl@0
|
191 |
goto close;
|
sl@0
|
192 |
}
|
sl@0
|
193 |
timerspec.it_value.tv_sec = curtmspec.tv_sec + Valuesec;
|
sl@0
|
194 |
timerspec.it_value.tv_nsec = curtmspec.tv_nsec + Valuenanosec;
|
sl@0
|
195 |
timerspec.it_interval.tv_sec = Intervalsec;
|
sl@0
|
196 |
timerspec.it_interval.tv_nsec = Intervalnanosec;
|
sl@0
|
197 |
ret = timer_settime(timerid,TIMER_ABSTIME,&timerspec,NULL);
|
sl@0
|
198 |
if(ret != 0)
|
sl@0
|
199 |
{
|
sl@0
|
200 |
ERR_PRINTF2(_L("Failed to set the timer and errno is %d"), errno);
|
sl@0
|
201 |
ret1 = -1;
|
sl@0
|
202 |
goto close;
|
sl@0
|
203 |
}
|
sl@0
|
204 |
sleep(2);
|
sl@0
|
205 |
INFO_PRINTF1(_L("Successfully able to set the timer") );
|
sl@0
|
206 |
ret = timer_delete(timerid);
|
sl@0
|
207 |
if(ret != 0)
|
sl@0
|
208 |
{
|
sl@0
|
209 |
ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
|
sl@0
|
210 |
return -1;
|
sl@0
|
211 |
}
|
sl@0
|
212 |
INFO_PRINTF1(_L("Successfully able to delete the timer") );
|
sl@0
|
213 |
ret1 = KErrNone;
|
sl@0
|
214 |
return ret1;
|
sl@0
|
215 |
close:
|
sl@0
|
216 |
timer_delete(timerid);
|
sl@0
|
217 |
return ret1;
|
sl@0
|
218 |
}
|
sl@0
|
219 |
|
sl@0
|
220 |
// -----------------------------------------------------------------------------
|
sl@0
|
221 |
// CTesttimer::Testtimerapi3
|
sl@0
|
222 |
// Test Case ID: OPENENV-LIBC-CIT-5946
|
sl@0
|
223 |
// API tested: timer_create(), timer_delete()
|
sl@0
|
224 |
// Description: To create a timer with SIGEV_SIGNAL as sigev_notify parameter
|
sl@0
|
225 |
// TIMER_ABSTIME not set
|
sl@0
|
226 |
// -----------------------------------------------------------------------------
|
sl@0
|
227 |
|
sl@0
|
228 |
TInt CTesttimer::Testtimerapi3 ( )
|
sl@0
|
229 |
{
|
sl@0
|
230 |
int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec, Signum, Maxsig, Sigval;
|
sl@0
|
231 |
struct sigevent sigev;
|
sl@0
|
232 |
struct itimerspec timerspec;
|
sl@0
|
233 |
timer_t timerid;
|
sl@0
|
234 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
|
sl@0
|
235 |
if(ret == 0)
|
sl@0
|
236 |
{
|
sl@0
|
237 |
ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
|
sl@0
|
238 |
return -1;
|
sl@0
|
239 |
}
|
sl@0
|
240 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
|
sl@0
|
241 |
if(ret == 0)
|
sl@0
|
242 |
{
|
sl@0
|
243 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
|
sl@0
|
244 |
return -1;
|
sl@0
|
245 |
}
|
sl@0
|
246 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
|
sl@0
|
247 |
if(ret == 0)
|
sl@0
|
248 |
{
|
sl@0
|
249 |
ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
|
sl@0
|
250 |
return -1;
|
sl@0
|
251 |
}
|
sl@0
|
252 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
|
sl@0
|
253 |
if(ret == 0)
|
sl@0
|
254 |
{
|
sl@0
|
255 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
|
sl@0
|
256 |
return -1;
|
sl@0
|
257 |
}
|
sl@0
|
258 |
ret = GetIntFromConfig(ConfigSection(), _L("Sigval"), Sigval);
|
sl@0
|
259 |
if(ret == 0)
|
sl@0
|
260 |
{
|
sl@0
|
261 |
ERR_PRINTF1(_L("Unable to read signal number")) ;
|
sl@0
|
262 |
return -1;
|
sl@0
|
263 |
}
|
sl@0
|
264 |
ret = GetIntFromConfig(ConfigSection(), _L("Maxsig"), Maxsig);
|
sl@0
|
265 |
if(ret == 0)
|
sl@0
|
266 |
{
|
sl@0
|
267 |
ERR_PRINTF1(_L("Unable to read maximum signal number")) ;
|
sl@0
|
268 |
return -1;
|
sl@0
|
269 |
}
|
sl@0
|
270 |
for(Signum=Sigval; Signum <= Maxsig; Signum++)
|
sl@0
|
271 |
{
|
sl@0
|
272 |
if((Signum == SIGSTOP) || (Signum == SIGKILL))
|
sl@0
|
273 |
{
|
sl@0
|
274 |
continue;
|
sl@0
|
275 |
}
|
sl@0
|
276 |
timer_value = 0;
|
sl@0
|
277 |
if(signal(Signum,sig_handler) == SIG_ERR)
|
sl@0
|
278 |
{
|
sl@0
|
279 |
ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"), errno) ;
|
sl@0
|
280 |
return ret1;
|
sl@0
|
281 |
}
|
sl@0
|
282 |
sigev.sigev_notify = SIGEV_SIGNAL;
|
sl@0
|
283 |
sigev.sigev_signo = Signum;
|
sl@0
|
284 |
|
sl@0
|
285 |
ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
|
sl@0
|
286 |
if(ret != 0)
|
sl@0
|
287 |
{
|
sl@0
|
288 |
ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
|
sl@0
|
289 |
return -1;
|
sl@0
|
290 |
}
|
sl@0
|
291 |
timerspec.it_value.tv_sec = Valuesec;
|
sl@0
|
292 |
timerspec.it_value.tv_nsec = Valuenanosec;
|
sl@0
|
293 |
timerspec.it_interval.tv_sec = Intervalsec;
|
sl@0
|
294 |
timerspec.it_interval.tv_nsec = Intervalnanosec;
|
sl@0
|
295 |
timer_value = 0;
|
sl@0
|
296 |
CreateLock();
|
sl@0
|
297 |
ret = timer_settime(timerid,0,&timerspec,NULL);
|
sl@0
|
298 |
if(ret != 0)
|
sl@0
|
299 |
{
|
sl@0
|
300 |
ERR_PRINTF3(_L("Failed to set the timer for signal %d and errno is %d"),Signum,errno);
|
sl@0
|
301 |
ret1 = -1;
|
sl@0
|
302 |
goto close;
|
sl@0
|
303 |
}
|
sl@0
|
304 |
// sleep(2);
|
sl@0
|
305 |
|
sl@0
|
306 |
AcquireLock();
|
sl@0
|
307 |
if(timer_value != Signum)
|
sl@0
|
308 |
{
|
sl@0
|
309 |
ERR_PRINTF2(_L("The expected and timer_value are not same for signal %d"),Signum);
|
sl@0
|
310 |
goto close;
|
sl@0
|
311 |
}
|
sl@0
|
312 |
ret = timer_delete(timerid);
|
sl@0
|
313 |
if(ret != 0)
|
sl@0
|
314 |
{
|
sl@0
|
315 |
ERR_PRINTF3(_L("Failed to delete the timer for signal %d and errno is %d"),Signum, errno);
|
sl@0
|
316 |
return -1;
|
sl@0
|
317 |
}
|
sl@0
|
318 |
}
|
sl@0
|
319 |
INFO_PRINTF1(_L("Relative time"));
|
sl@0
|
320 |
INFO_PRINTF1(_L("Successfully able to create a timer with SIGEV_SIGNAL as sigev_notify parameter validated for all signals"));
|
sl@0
|
321 |
ret1 = KErrNone;
|
sl@0
|
322 |
return ret1;
|
sl@0
|
323 |
close:
|
sl@0
|
324 |
timer_delete(timerid);
|
sl@0
|
325 |
return ret1;
|
sl@0
|
326 |
}
|
sl@0
|
327 |
|
sl@0
|
328 |
// -----------------------------------------------------------------------------
|
sl@0
|
329 |
// CTesttimer::Testtimerapi4
|
sl@0
|
330 |
// Test Case ID: OPENENV-LIBC-CIT-5946
|
sl@0
|
331 |
// API tested: timer_create(), timer_delete()
|
sl@0
|
332 |
// Description: To create a timer with SIGEV_SIGNAL as sigev_notify parameter
|
sl@0
|
333 |
// TIMER_ABSTIME set
|
sl@0
|
334 |
// -----------------------------------------------------------------------------
|
sl@0
|
335 |
|
sl@0
|
336 |
TInt CTesttimer::Testtimerapi4 ( )
|
sl@0
|
337 |
{
|
sl@0
|
338 |
int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec, Signum, Maxsig, Sigval;
|
sl@0
|
339 |
struct sigevent sigev;
|
sl@0
|
340 |
struct itimerspec timerspec;
|
sl@0
|
341 |
struct timespec curtmspec;
|
sl@0
|
342 |
timer_t timerid;
|
sl@0
|
343 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
|
sl@0
|
344 |
if(ret == 0)
|
sl@0
|
345 |
{
|
sl@0
|
346 |
ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
|
sl@0
|
347 |
return ret1;
|
sl@0
|
348 |
}
|
sl@0
|
349 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
|
sl@0
|
350 |
if(ret == 0)
|
sl@0
|
351 |
{
|
sl@0
|
352 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
|
sl@0
|
353 |
return ret1;
|
sl@0
|
354 |
}
|
sl@0
|
355 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
|
sl@0
|
356 |
if(ret == 0)
|
sl@0
|
357 |
{
|
sl@0
|
358 |
ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
|
sl@0
|
359 |
return ret1;
|
sl@0
|
360 |
}
|
sl@0
|
361 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
|
sl@0
|
362 |
if(ret == 0)
|
sl@0
|
363 |
{
|
sl@0
|
364 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
|
sl@0
|
365 |
return ret1;
|
sl@0
|
366 |
}
|
sl@0
|
367 |
ret = GetIntFromConfig(ConfigSection(), _L("Sigval"), Sigval);
|
sl@0
|
368 |
if(ret == 0)
|
sl@0
|
369 |
{
|
sl@0
|
370 |
ERR_PRINTF1(_L("Unable to read signal number")) ;
|
sl@0
|
371 |
return ret1;
|
sl@0
|
372 |
}
|
sl@0
|
373 |
ret = GetIntFromConfig(ConfigSection(), _L("Maxsig"), Maxsig);
|
sl@0
|
374 |
if(ret == 0)
|
sl@0
|
375 |
{
|
sl@0
|
376 |
ERR_PRINTF1(_L("Unable to read maximum signal number")) ;
|
sl@0
|
377 |
return ret1;
|
sl@0
|
378 |
}
|
sl@0
|
379 |
for(Signum=Sigval; Signum <= Maxsig; Signum++)
|
sl@0
|
380 |
{
|
sl@0
|
381 |
if((Signum == SIGSTOP) || (Signum == SIGKILL))
|
sl@0
|
382 |
{
|
sl@0
|
383 |
continue;
|
sl@0
|
384 |
}
|
sl@0
|
385 |
timer_value = 0;
|
sl@0
|
386 |
if(signal(Signum,sig_handler) == SIG_ERR)
|
sl@0
|
387 |
{
|
sl@0
|
388 |
ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"), errno) ;
|
sl@0
|
389 |
return ret1;
|
sl@0
|
390 |
}
|
sl@0
|
391 |
sigev.sigev_notify = SIGEV_SIGNAL;
|
sl@0
|
392 |
sigev.sigev_signo = Signum;
|
sl@0
|
393 |
|
sl@0
|
394 |
ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
|
sl@0
|
395 |
if(ret != 0)
|
sl@0
|
396 |
{
|
sl@0
|
397 |
ERR_PRINTF3(_L("Failed to create a timer for signal %d and errno is %d"),Signum,errno);
|
sl@0
|
398 |
return -1;
|
sl@0
|
399 |
}
|
sl@0
|
400 |
ret = clock_gettime(CLOCK_REALTIME,&curtmspec);
|
sl@0
|
401 |
if (ret != 0)
|
sl@0
|
402 |
{
|
sl@0
|
403 |
ERR_PRINTF3(_L("Failed to get the time of specified clock id for signal %d and errno is %d"),Signum,errno);
|
sl@0
|
404 |
goto close;
|
sl@0
|
405 |
}
|
sl@0
|
406 |
timerspec.it_value.tv_sec = curtmspec.tv_sec + Valuesec;
|
sl@0
|
407 |
timerspec.it_value.tv_nsec = curtmspec.tv_nsec + Valuenanosec;
|
sl@0
|
408 |
timerspec.it_interval.tv_sec = Intervalsec;
|
sl@0
|
409 |
timerspec.it_interval.tv_nsec = Intervalnanosec;
|
sl@0
|
410 |
timer_value = 0;
|
sl@0
|
411 |
ret = timer_settime(timerid,TIMER_ABSTIME,&timerspec,NULL);
|
sl@0
|
412 |
//sleep(2);
|
sl@0
|
413 |
AcquireLock();
|
sl@0
|
414 |
if(ret != 0)
|
sl@0
|
415 |
{
|
sl@0
|
416 |
ERR_PRINTF3(_L("Failed to set the timer for signal %d and errno is %d"),Signum,errno);
|
sl@0
|
417 |
ret1 = -1;
|
sl@0
|
418 |
goto close;
|
sl@0
|
419 |
}
|
sl@0
|
420 |
if(timer_value != Signum)
|
sl@0
|
421 |
{
|
sl@0
|
422 |
ERR_PRINTF2(_L("The expected and timer_value are not same for signal %d"),Signum);
|
sl@0
|
423 |
goto close;
|
sl@0
|
424 |
}
|
sl@0
|
425 |
ret = timer_delete(timerid);
|
sl@0
|
426 |
if(ret != 0)
|
sl@0
|
427 |
{
|
sl@0
|
428 |
ERR_PRINTF3(_L("Failed to delete the timer for signal %d and errno is %d"),Signum, errno);
|
sl@0
|
429 |
return -1;
|
sl@0
|
430 |
}
|
sl@0
|
431 |
}
|
sl@0
|
432 |
INFO_PRINTF1(_L("Absolute time"));
|
sl@0
|
433 |
INFO_PRINTF1(_L("Successfully able to create a timer with SIGEV_SIGNAL as sigev_notify parameter validated for all signals"));
|
sl@0
|
434 |
ret1 = KErrNone;
|
sl@0
|
435 |
return ret1;
|
sl@0
|
436 |
close:
|
sl@0
|
437 |
timer_delete(timerid);
|
sl@0
|
438 |
return ret1;
|
sl@0
|
439 |
}
|
sl@0
|
440 |
|
sl@0
|
441 |
|
sl@0
|
442 |
// -----------------------------------------------------------------------------
|
sl@0
|
443 |
// CTesttimer::Testtimerapi5
|
sl@0
|
444 |
// Test Case ID: OPENENV-LIBC-CIT-5946
|
sl@0
|
445 |
// API tested: timer_create(), timer_delete()
|
sl@0
|
446 |
// Description: To create a timer with SIGEV_THREAD as sigev_notify parameter
|
sl@0
|
447 |
// TIMER_ABSTIME not set
|
sl@0
|
448 |
// -----------------------------------------------------------------------------
|
sl@0
|
449 |
|
sl@0
|
450 |
TInt CTesttimer::Testtimerapi5 ( )
|
sl@0
|
451 |
{
|
sl@0
|
452 |
int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
|
sl@0
|
453 |
struct sigevent sigev;
|
sl@0
|
454 |
struct sched_param parm;
|
sl@0
|
455 |
pthread_attr_t attr;
|
sl@0
|
456 |
struct itimerspec timerspec;
|
sl@0
|
457 |
timer_t timerid;
|
sl@0
|
458 |
pthread_attr_init( &attr );
|
sl@0
|
459 |
parm.sched_priority = 255; //raise the priority..
|
sl@0
|
460 |
pthread_attr_setschedparam(&attr, &parm);
|
sl@0
|
461 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
|
sl@0
|
462 |
if(ret == 0)
|
sl@0
|
463 |
{
|
sl@0
|
464 |
ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
|
sl@0
|
465 |
return ret1;
|
sl@0
|
466 |
}
|
sl@0
|
467 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
|
sl@0
|
468 |
if(ret == 0)
|
sl@0
|
469 |
{
|
sl@0
|
470 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
|
sl@0
|
471 |
return ret1;
|
sl@0
|
472 |
}
|
sl@0
|
473 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
|
sl@0
|
474 |
if(ret == 0)
|
sl@0
|
475 |
{
|
sl@0
|
476 |
ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
|
sl@0
|
477 |
return ret1;
|
sl@0
|
478 |
}
|
sl@0
|
479 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
|
sl@0
|
480 |
if(ret == 0)
|
sl@0
|
481 |
{
|
sl@0
|
482 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
|
sl@0
|
483 |
return ret1;
|
sl@0
|
484 |
}
|
sl@0
|
485 |
timer_value = 0;
|
sl@0
|
486 |
sigev.sigev_notify = SIGEV_THREAD;
|
sl@0
|
487 |
sigev.sigev_value.sival_int = 100;
|
sl@0
|
488 |
sigev.sigev_notify_function = notifyfunc ;
|
sl@0
|
489 |
sigev.sigev_notify_attributes = &attr;
|
sl@0
|
490 |
ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
|
sl@0
|
491 |
if(ret != 0)
|
sl@0
|
492 |
{
|
sl@0
|
493 |
ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
|
sl@0
|
494 |
return -1;
|
sl@0
|
495 |
}
|
sl@0
|
496 |
INFO_PRINTF1(_L("Successfully able to create a timer") );
|
sl@0
|
497 |
timerspec.it_value.tv_sec = Valuesec;
|
sl@0
|
498 |
timerspec.it_value.tv_nsec = Valuenanosec;
|
sl@0
|
499 |
timerspec.it_interval.tv_sec = Intervalsec;
|
sl@0
|
500 |
timerspec.it_interval.tv_nsec = Intervalnanosec;
|
sl@0
|
501 |
ret = timer_settime(timerid,0,&timerspec,NULL);
|
sl@0
|
502 |
if(ret != 0)
|
sl@0
|
503 |
{
|
sl@0
|
504 |
ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
|
sl@0
|
505 |
ret1 = -1;
|
sl@0
|
506 |
goto close;
|
sl@0
|
507 |
}
|
sl@0
|
508 |
sleep(2);
|
sl@0
|
509 |
if(timer_value != 100)
|
sl@0
|
510 |
{
|
sl@0
|
511 |
ERR_PRINTF1(_L("The expected and timer_value are not same"));
|
sl@0
|
512 |
goto close;
|
sl@0
|
513 |
}
|
sl@0
|
514 |
INFO_PRINTF1(_L("Successfully able to set the timer") );
|
sl@0
|
515 |
ret = timer_delete(timerid);
|
sl@0
|
516 |
if(ret != 0)
|
sl@0
|
517 |
{
|
sl@0
|
518 |
ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
|
sl@0
|
519 |
return -1;
|
sl@0
|
520 |
}
|
sl@0
|
521 |
INFO_PRINTF1(_L("Successfully able to delete the timer") );
|
sl@0
|
522 |
ret1 = KErrNone;
|
sl@0
|
523 |
return ret1;
|
sl@0
|
524 |
close:
|
sl@0
|
525 |
timer_delete(timerid);
|
sl@0
|
526 |
return ret1;
|
sl@0
|
527 |
}
|
sl@0
|
528 |
|
sl@0
|
529 |
// -----------------------------------------------------------------------------
|
sl@0
|
530 |
// CTesttimer::Testtimerapi6
|
sl@0
|
531 |
// Test Case ID: OPENENV-LIBC-CIT-5946
|
sl@0
|
532 |
// API tested: timer_create(), timer_delete()
|
sl@0
|
533 |
// Description: To create a timer with SIGEV_THREAD as sigev_notify parameter
|
sl@0
|
534 |
// TIMER_ABSTIME set
|
sl@0
|
535 |
// -----------------------------------------------------------------------------
|
sl@0
|
536 |
|
sl@0
|
537 |
TInt CTesttimer::Testtimerapi6 ( )
|
sl@0
|
538 |
{
|
sl@0
|
539 |
int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
|
sl@0
|
540 |
struct sigevent sigev;
|
sl@0
|
541 |
struct itimerspec timerspec;
|
sl@0
|
542 |
struct timespec curtmspec;
|
sl@0
|
543 |
timer_t timerid;
|
sl@0
|
544 |
struct sched_param parm;
|
sl@0
|
545 |
pthread_attr_t attr;
|
sl@0
|
546 |
pthread_attr_init( &attr );
|
sl@0
|
547 |
parm.sched_priority = 255;
|
sl@0
|
548 |
pthread_attr_setschedparam(&attr, &parm);
|
sl@0
|
549 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
|
sl@0
|
550 |
if(ret == 0)
|
sl@0
|
551 |
{
|
sl@0
|
552 |
ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
|
sl@0
|
553 |
return ret1;
|
sl@0
|
554 |
}
|
sl@0
|
555 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
|
sl@0
|
556 |
if(ret == 0)
|
sl@0
|
557 |
{
|
sl@0
|
558 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
|
sl@0
|
559 |
return ret1;
|
sl@0
|
560 |
}
|
sl@0
|
561 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
|
sl@0
|
562 |
if(ret == 0)
|
sl@0
|
563 |
{
|
sl@0
|
564 |
ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
|
sl@0
|
565 |
return ret1;
|
sl@0
|
566 |
}
|
sl@0
|
567 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
|
sl@0
|
568 |
if(ret == 0)
|
sl@0
|
569 |
{
|
sl@0
|
570 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
|
sl@0
|
571 |
return ret1;
|
sl@0
|
572 |
}
|
sl@0
|
573 |
timer_value = 0;
|
sl@0
|
574 |
sigev.sigev_notify = SIGEV_THREAD;
|
sl@0
|
575 |
sigev.sigev_value.sival_int = 100;
|
sl@0
|
576 |
sigev.sigev_notify_function = notifyfunc ;
|
sl@0
|
577 |
sigev.sigev_notify_attributes = &attr;
|
sl@0
|
578 |
ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
|
sl@0
|
579 |
if(ret != 0)
|
sl@0
|
580 |
{
|
sl@0
|
581 |
ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
|
sl@0
|
582 |
return -1;
|
sl@0
|
583 |
}
|
sl@0
|
584 |
INFO_PRINTF1(_L("Successfully able to create a timer") );
|
sl@0
|
585 |
ret = clock_gettime(CLOCK_REALTIME,&curtmspec);
|
sl@0
|
586 |
if (ret != 0)
|
sl@0
|
587 |
{
|
sl@0
|
588 |
ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
|
sl@0
|
589 |
goto close;
|
sl@0
|
590 |
}
|
sl@0
|
591 |
timerspec.it_value.tv_sec = curtmspec.tv_sec + Valuesec;
|
sl@0
|
592 |
timerspec.it_value.tv_nsec = curtmspec.tv_nsec + Valuenanosec;
|
sl@0
|
593 |
timerspec.it_interval.tv_sec = Intervalsec;
|
sl@0
|
594 |
timerspec.it_interval.tv_nsec = Intervalnanosec;
|
sl@0
|
595 |
ret = timer_settime(timerid,TIMER_ABSTIME,&timerspec,NULL);
|
sl@0
|
596 |
if(ret != 0)
|
sl@0
|
597 |
{
|
sl@0
|
598 |
ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
|
sl@0
|
599 |
ret1 = -1;
|
sl@0
|
600 |
goto close;
|
sl@0
|
601 |
}
|
sl@0
|
602 |
sleep(2);
|
sl@0
|
603 |
if(timer_value != 100)
|
sl@0
|
604 |
{
|
sl@0
|
605 |
ERR_PRINTF1(_L("The expected and timer_value are not same"));
|
sl@0
|
606 |
goto close;
|
sl@0
|
607 |
}
|
sl@0
|
608 |
INFO_PRINTF1(_L("Successfully able to set the timer") );
|
sl@0
|
609 |
ret = timer_delete(timerid);
|
sl@0
|
610 |
if(ret != 0)
|
sl@0
|
611 |
{
|
sl@0
|
612 |
ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
|
sl@0
|
613 |
return -1;
|
sl@0
|
614 |
}
|
sl@0
|
615 |
INFO_PRINTF1(_L("Successfully able to delete the timer") );
|
sl@0
|
616 |
ret1 = KErrNone;
|
sl@0
|
617 |
return ret1;
|
sl@0
|
618 |
close:
|
sl@0
|
619 |
timer_delete(timerid);
|
sl@0
|
620 |
return ret1;
|
sl@0
|
621 |
}
|
sl@0
|
622 |
|
sl@0
|
623 |
// -----------------------------------------------------------------------------
|
sl@0
|
624 |
// CTesttimer::Testtimerapi7
|
sl@0
|
625 |
// Test Case ID: OPENENV-LIBC-CIT-5946
|
sl@0
|
626 |
// API tested: timer_create(), timer_delete()
|
sl@0
|
627 |
// Description: To create a timer for CLOCK_REALTIME id using timer_create() with sigevent argument as NULL
|
sl@0
|
628 |
// TIMER_ABSTIME not set
|
sl@0
|
629 |
// -----------------------------------------------------------------------------
|
sl@0
|
630 |
|
sl@0
|
631 |
TInt CTesttimer::Testtimerapi7 ( )
|
sl@0
|
632 |
{
|
sl@0
|
633 |
int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
|
sl@0
|
634 |
timer_t timerid;
|
sl@0
|
635 |
struct itimerspec timerspec;
|
sl@0
|
636 |
timer_value = 0;
|
sl@0
|
637 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
|
sl@0
|
638 |
if(ret == 0)
|
sl@0
|
639 |
{
|
sl@0
|
640 |
ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
|
sl@0
|
641 |
return -1;
|
sl@0
|
642 |
}
|
sl@0
|
643 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
|
sl@0
|
644 |
if(ret == 0)
|
sl@0
|
645 |
{
|
sl@0
|
646 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
|
sl@0
|
647 |
return -1;
|
sl@0
|
648 |
}
|
sl@0
|
649 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
|
sl@0
|
650 |
if(ret == 0)
|
sl@0
|
651 |
{
|
sl@0
|
652 |
ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
|
sl@0
|
653 |
return -1;
|
sl@0
|
654 |
}
|
sl@0
|
655 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
|
sl@0
|
656 |
if(ret == 0)
|
sl@0
|
657 |
{
|
sl@0
|
658 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
|
sl@0
|
659 |
return -1;
|
sl@0
|
660 |
}
|
sl@0
|
661 |
if(signal(SIGALRM, alarm_handler) == SIG_ERR)
|
sl@0
|
662 |
{
|
sl@0
|
663 |
ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"), errno) ;
|
sl@0
|
664 |
return ret1;
|
sl@0
|
665 |
}
|
sl@0
|
666 |
ret = timer_create(CLOCK_REALTIME,NULL,&timerid);
|
sl@0
|
667 |
if(ret != 0)
|
sl@0
|
668 |
{
|
sl@0
|
669 |
ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
|
sl@0
|
670 |
return -1;
|
sl@0
|
671 |
}
|
sl@0
|
672 |
INFO_PRINTF1(_L("Successfully able to create a timer") );
|
sl@0
|
673 |
timerspec.it_value.tv_sec = Valuesec;
|
sl@0
|
674 |
timerspec.it_value.tv_nsec = Valuenanosec;
|
sl@0
|
675 |
timerspec.it_interval.tv_sec = Intervalsec;
|
sl@0
|
676 |
timerspec.it_interval.tv_nsec = Intervalnanosec;
|
sl@0
|
677 |
ret = timer_settime(timerid,0,&timerspec,NULL);
|
sl@0
|
678 |
if(ret != 0)
|
sl@0
|
679 |
{
|
sl@0
|
680 |
ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
|
sl@0
|
681 |
ret1 = -1;
|
sl@0
|
682 |
goto close;
|
sl@0
|
683 |
}
|
sl@0
|
684 |
sleep(2);
|
sl@0
|
685 |
if(timer_value != SIGALRM)
|
sl@0
|
686 |
{
|
sl@0
|
687 |
ERR_PRINTF1(_L("Error in raising the signal after timer expire"));
|
sl@0
|
688 |
goto close;
|
sl@0
|
689 |
}
|
sl@0
|
690 |
INFO_PRINTF1(_L("Successfully able to set the timer with the default signal as SIGALRM") );
|
sl@0
|
691 |
ret = timer_delete(timerid);
|
sl@0
|
692 |
if(ret != 0)
|
sl@0
|
693 |
{
|
sl@0
|
694 |
ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
|
sl@0
|
695 |
return -1;
|
sl@0
|
696 |
}
|
sl@0
|
697 |
INFO_PRINTF1(_L("Successfully able to delete the timer") );
|
sl@0
|
698 |
ret1 = KErrNone;
|
sl@0
|
699 |
return ret1;
|
sl@0
|
700 |
close:
|
sl@0
|
701 |
timer_delete(timerid);
|
sl@0
|
702 |
return ret1;
|
sl@0
|
703 |
}
|
sl@0
|
704 |
|
sl@0
|
705 |
// -----------------------------------------------------------------------------
|
sl@0
|
706 |
// CTesttimer::Testtimerapi8
|
sl@0
|
707 |
// Test Case ID: OPENENV-LIBC-CIT-5946
|
sl@0
|
708 |
// API tested: timer_create(), timer_delete()
|
sl@0
|
709 |
// Description: To create a timer for CLOCK_REALTIME id using timer_create() with sigevent argument as NULL
|
sl@0
|
710 |
// TIMER_ABSTIME set
|
sl@0
|
711 |
// -----------------------------------------------------------------------------
|
sl@0
|
712 |
|
sl@0
|
713 |
TInt CTesttimer::Testtimerapi8 ( )
|
sl@0
|
714 |
{
|
sl@0
|
715 |
int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
|
sl@0
|
716 |
timer_t timerid;
|
sl@0
|
717 |
struct itimerspec timerspec;
|
sl@0
|
718 |
struct timespec curtmspec;
|
sl@0
|
719 |
timer_value = 0;
|
sl@0
|
720 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
|
sl@0
|
721 |
if(ret == 0)
|
sl@0
|
722 |
{
|
sl@0
|
723 |
ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
|
sl@0
|
724 |
return ret1;
|
sl@0
|
725 |
}
|
sl@0
|
726 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
|
sl@0
|
727 |
if(ret == 0)
|
sl@0
|
728 |
{
|
sl@0
|
729 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
|
sl@0
|
730 |
return ret1;
|
sl@0
|
731 |
}
|
sl@0
|
732 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
|
sl@0
|
733 |
if(ret == 0)
|
sl@0
|
734 |
{
|
sl@0
|
735 |
ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
|
sl@0
|
736 |
return ret1;
|
sl@0
|
737 |
}
|
sl@0
|
738 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
|
sl@0
|
739 |
if(ret == 0)
|
sl@0
|
740 |
{
|
sl@0
|
741 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
|
sl@0
|
742 |
return ret1;
|
sl@0
|
743 |
}
|
sl@0
|
744 |
if(signal(SIGALRM, alarm_handler) == SIG_ERR)
|
sl@0
|
745 |
{
|
sl@0
|
746 |
ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"),errno) ;
|
sl@0
|
747 |
return ret1;
|
sl@0
|
748 |
}
|
sl@0
|
749 |
ret = timer_create(CLOCK_REALTIME,NULL,&timerid);
|
sl@0
|
750 |
if(ret != 0)
|
sl@0
|
751 |
{
|
sl@0
|
752 |
ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
|
sl@0
|
753 |
return -1;
|
sl@0
|
754 |
}
|
sl@0
|
755 |
INFO_PRINTF1(_L("Successfully able to create a timer") );
|
sl@0
|
756 |
ret = clock_gettime(CLOCK_REALTIME,&curtmspec);
|
sl@0
|
757 |
if (ret != 0)
|
sl@0
|
758 |
{
|
sl@0
|
759 |
ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
|
sl@0
|
760 |
goto close;
|
sl@0
|
761 |
}
|
sl@0
|
762 |
timerspec.it_value.tv_sec = curtmspec.tv_sec + Valuesec;
|
sl@0
|
763 |
timerspec.it_value.tv_nsec = curtmspec.tv_nsec + Valuenanosec;
|
sl@0
|
764 |
timerspec.it_interval.tv_sec = Intervalsec;
|
sl@0
|
765 |
timerspec.it_interval.tv_nsec = Intervalnanosec;
|
sl@0
|
766 |
ret = timer_settime(timerid,TIMER_ABSTIME,&timerspec,NULL);
|
sl@0
|
767 |
if(ret != 0)
|
sl@0
|
768 |
{
|
sl@0
|
769 |
ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
|
sl@0
|
770 |
ret1 = -1;
|
sl@0
|
771 |
goto close;
|
sl@0
|
772 |
}
|
sl@0
|
773 |
sleep(2);
|
sl@0
|
774 |
if(timer_value != SIGALRM)
|
sl@0
|
775 |
{
|
sl@0
|
776 |
ERR_PRINTF1(_L("Error in raising the signal after timer expire"));
|
sl@0
|
777 |
goto close;
|
sl@0
|
778 |
}
|
sl@0
|
779 |
INFO_PRINTF1(_L("Successfully able to set the timer with the default signal as SIGALRM") );
|
sl@0
|
780 |
ret = timer_delete(timerid);
|
sl@0
|
781 |
if(ret != 0)
|
sl@0
|
782 |
{
|
sl@0
|
783 |
ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
|
sl@0
|
784 |
return -1;
|
sl@0
|
785 |
}
|
sl@0
|
786 |
INFO_PRINTF1(_L("Successfully able to delete the timer") );
|
sl@0
|
787 |
ret1 = KErrNone;
|
sl@0
|
788 |
return ret1;
|
sl@0
|
789 |
close:
|
sl@0
|
790 |
timer_delete(timerid);
|
sl@0
|
791 |
return ret1;
|
sl@0
|
792 |
}
|
sl@0
|
793 |
|
sl@0
|
794 |
// -----------------------------------------------------------------------------
|
sl@0
|
795 |
// CTesttimer::Testtimerapi9
|
sl@0
|
796 |
// Test Case ID: OPENENV-LIBC-CIT-5946
|
sl@0
|
797 |
// API tested: timer_create()
|
sl@0
|
798 |
// Description: Negative Test-Trying to create the timer for an invalid clock id using timer_create()
|
sl@0
|
799 |
// -----------------------------------------------------------------------------
|
sl@0
|
800 |
|
sl@0
|
801 |
TInt CTesttimer::Testtimerapi9 ( )
|
sl@0
|
802 |
{
|
sl@0
|
803 |
int ret, ret1 = KErrGeneral, Invalidclockid;
|
sl@0
|
804 |
timer_t timerid;
|
sl@0
|
805 |
ret = GetIntFromConfig(ConfigSection(), _L("Invalidclockid"), Invalidclockid);
|
sl@0
|
806 |
if(ret == 0)
|
sl@0
|
807 |
{
|
sl@0
|
808 |
ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
|
sl@0
|
809 |
return ret1;
|
sl@0
|
810 |
}
|
sl@0
|
811 |
ret = timer_create(Invalidclockid,NULL,&timerid);
|
sl@0
|
812 |
if((ret != -1) || (errno != EINVAL))
|
sl@0
|
813 |
{
|
sl@0
|
814 |
ERR_PRINTF2(_L("timer_create() failed to return EINVAL on negative test and errno is %d"),errno);
|
sl@0
|
815 |
goto close;
|
sl@0
|
816 |
}
|
sl@0
|
817 |
INFO_PRINTF1(_L("timer_create() successfully returned EINVAL on negative test") );
|
sl@0
|
818 |
ret1 = KErrNone;
|
sl@0
|
819 |
|
sl@0
|
820 |
close:
|
sl@0
|
821 |
return ret1;
|
sl@0
|
822 |
}
|
sl@0
|
823 |
|
sl@0
|
824 |
// -----------------------------------------------------------------------------
|
sl@0
|
825 |
// CTesttimer::Testtimerapi10
|
sl@0
|
826 |
// Test Case ID: OPENENV-LIBC-CIT-5946
|
sl@0
|
827 |
// API tested: timer_create()
|
sl@0
|
828 |
// Description: Timer id as NULL in timer_create()
|
sl@0
|
829 |
// -----------------------------------------------------------------------------
|
sl@0
|
830 |
|
sl@0
|
831 |
TInt CTesttimer::Testtimerapi10 ( )
|
sl@0
|
832 |
{
|
sl@0
|
833 |
int ret, ret1 = KErrGeneral;
|
sl@0
|
834 |
ret = timer_create(CLOCK_REALTIME,NULL,NULL);
|
sl@0
|
835 |
if((ret != -1) || (errno != EFAULT))
|
sl@0
|
836 |
{
|
sl@0
|
837 |
ERR_PRINTF2(_L("timer_create() failed to return EFAULT on negative test and errno is %d"),errno);
|
sl@0
|
838 |
goto close;
|
sl@0
|
839 |
}
|
sl@0
|
840 |
INFO_PRINTF1(_L("timer_create() successfully returned EFAULT on negative test") );
|
sl@0
|
841 |
ret1 = KErrNone;
|
sl@0
|
842 |
|
sl@0
|
843 |
close:
|
sl@0
|
844 |
return ret1;
|
sl@0
|
845 |
}
|
sl@0
|
846 |
|
sl@0
|
847 |
// -----------------------------------------------------------------------------
|
sl@0
|
848 |
// CTesttimer::Testtimerapi11
|
sl@0
|
849 |
// Test Case ID: OPENENV-LIBC-CIT-5946
|
sl@0
|
850 |
// API tested: timer_create()
|
sl@0
|
851 |
// Description: Timer id as NULL & an invalid clockid in timer_create()
|
sl@0
|
852 |
// -----------------------------------------------------------------------------
|
sl@0
|
853 |
|
sl@0
|
854 |
TInt CTesttimer::Testtimerapi11 ( )
|
sl@0
|
855 |
{
|
sl@0
|
856 |
int ret, ret1 = KErrGeneral;
|
sl@0
|
857 |
ret = timer_create(CLOCK_MONOTONIC,NULL,NULL);
|
sl@0
|
858 |
if((ret != -1) || (errno != EFAULT))
|
sl@0
|
859 |
{
|
sl@0
|
860 |
ERR_PRINTF2(_L("timer_create() failed to return EFAULT on negative test and errno is %d"),errno);
|
sl@0
|
861 |
goto close;
|
sl@0
|
862 |
}
|
sl@0
|
863 |
INFO_PRINTF1(_L("timer_create() successfully returned EFAULT on negative test") );
|
sl@0
|
864 |
ret1 = KErrNone;
|
sl@0
|
865 |
|
sl@0
|
866 |
close:
|
sl@0
|
867 |
return ret1;
|
sl@0
|
868 |
}
|
sl@0
|
869 |
|
sl@0
|
870 |
// -----------------------------------------------------------------------------
|
sl@0
|
871 |
// CTesttimer::Testtimerapi12
|
sl@0
|
872 |
// Test Case ID: OPENENV-LIBC-CIT-5946
|
sl@0
|
873 |
// API tested: timer_create()
|
sl@0
|
874 |
// Description: Trying to create more than maximum no. of timer's possible per process using timer_create()
|
sl@0
|
875 |
// -----------------------------------------------------------------------------
|
sl@0
|
876 |
|
sl@0
|
877 |
TInt CTesttimer::Testtimerapi12 ( )
|
sl@0
|
878 |
{
|
sl@0
|
879 |
int ret, ret1 = KErrGeneral, i, j;
|
sl@0
|
880 |
timer_t timerid[Maxtimerid + 1];
|
sl@0
|
881 |
for (i = 0; i <= Maxtimerid ; i++)
|
sl@0
|
882 |
{
|
sl@0
|
883 |
ret = timer_create(CLOCK_REALTIME,NULL,&timerid[i]);
|
sl@0
|
884 |
if((ret == -1) && (errno == EAGAIN) && (i == Maxtimerid) )
|
sl@0
|
885 |
{
|
sl@0
|
886 |
INFO_PRINTF3(_L("timer_create() has successfully returned EAGAIN on negative test %d %d"),errno,i);
|
sl@0
|
887 |
ret1 = KErrNone;
|
sl@0
|
888 |
break;
|
sl@0
|
889 |
}
|
sl@0
|
890 |
else if(ret < 0)
|
sl@0
|
891 |
{
|
sl@0
|
892 |
INFO_PRINTF3(_L("timer_create() has failed with error %d %d"),errno,i);
|
sl@0
|
893 |
}
|
sl@0
|
894 |
}
|
sl@0
|
895 |
for(j = 0; j <= Maxtimerid-1; j++)
|
sl@0
|
896 |
{
|
sl@0
|
897 |
ret = timer_delete(timerid[j]);
|
sl@0
|
898 |
if(ret != 0)
|
sl@0
|
899 |
{
|
sl@0
|
900 |
ERR_PRINTF3(_L("Failed to delete the timer and errno is %d %d"),errno, j);
|
sl@0
|
901 |
ret1 = KErrGeneral;
|
sl@0
|
902 |
break;
|
sl@0
|
903 |
}
|
sl@0
|
904 |
}
|
sl@0
|
905 |
INFO_PRINTF1(_L("timer_delete() has successfully deleted all the timers negative test"));
|
sl@0
|
906 |
return ret1;
|
sl@0
|
907 |
}
|
sl@0
|
908 |
|
sl@0
|
909 |
// -----------------------------------------------------------------------------
|
sl@0
|
910 |
// CTesttimer::Testtimerapi13
|
sl@0
|
911 |
// Test Case ID: OPENENV-LIBC-CIT-5946
|
sl@0
|
912 |
// API tested: timer_delete()
|
sl@0
|
913 |
// Description: To delete the timer with an invalid timer id using timer_delete()
|
sl@0
|
914 |
// -----------------------------------------------------------------------------
|
sl@0
|
915 |
|
sl@0
|
916 |
TInt CTesttimer::Testtimerapi13 ( )
|
sl@0
|
917 |
{
|
sl@0
|
918 |
timer_t timerid;
|
sl@0
|
919 |
int ret, ret1 = KErrGeneral;
|
sl@0
|
920 |
ret = timer_create(CLOCK_REALTIME,NULL,&timerid);
|
sl@0
|
921 |
if(ret != 0)
|
sl@0
|
922 |
{
|
sl@0
|
923 |
ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
|
sl@0
|
924 |
return -1;
|
sl@0
|
925 |
}
|
sl@0
|
926 |
INFO_PRINTF1(_L("Able to create the timer") );
|
sl@0
|
927 |
ret = timer_delete(timerid);
|
sl@0
|
928 |
if(ret != 0)
|
sl@0
|
929 |
{
|
sl@0
|
930 |
ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
|
sl@0
|
931 |
return -1;
|
sl@0
|
932 |
}
|
sl@0
|
933 |
INFO_PRINTF1(_L("Successfully able to delete the timer") );
|
sl@0
|
934 |
/*Deleting a timer id again expected result = -1 and errno = EINVAL */
|
sl@0
|
935 |
ret = timer_delete(timerid);
|
sl@0
|
936 |
if((ret != -1) || (errno != EINVAL))
|
sl@0
|
937 |
{
|
sl@0
|
938 |
ERR_PRINTF2(_L("timer_delete() failed to return EINVAL on negative test and errno is %d"),errno);
|
sl@0
|
939 |
goto close;
|
sl@0
|
940 |
}
|
sl@0
|
941 |
INFO_PRINTF1(_L("timer_delete() successfully returned EINVAL on negative test") );
|
sl@0
|
942 |
ret1 = KErrNone;
|
sl@0
|
943 |
|
sl@0
|
944 |
close:
|
sl@0
|
945 |
return ret1;
|
sl@0
|
946 |
}
|
sl@0
|
947 |
|
sl@0
|
948 |
// -----------------------------------------------------------------------------
|
sl@0
|
949 |
// CTesttimer::Testtimerapi14
|
sl@0
|
950 |
// Test Case ID: OPENENV-LIBC-CIT-5946
|
sl@0
|
951 |
// API tested: timer_delete()
|
sl@0
|
952 |
// Description: To delete the timer with NULL using timer_delete()
|
sl@0
|
953 |
// -----------------------------------------------------------------------------
|
sl@0
|
954 |
|
sl@0
|
955 |
TInt CTesttimer::Testtimerapi14 ( )
|
sl@0
|
956 |
{
|
sl@0
|
957 |
int ret, ret1 = KErrGeneral;
|
sl@0
|
958 |
ret = timer_delete(NULL);
|
sl@0
|
959 |
if((ret != -1) || (errno != EINVAL))
|
sl@0
|
960 |
{
|
sl@0
|
961 |
ERR_PRINTF2(_L("timer_delete() failed to return EFAULT on negative test and errno is %d"),errno);
|
sl@0
|
962 |
goto close;
|
sl@0
|
963 |
}
|
sl@0
|
964 |
INFO_PRINTF1(_L("timer_delete() successfully returned EFAULT on negative test") );
|
sl@0
|
965 |
ret1 = KErrNone;
|
sl@0
|
966 |
|
sl@0
|
967 |
close:
|
sl@0
|
968 |
return ret1;
|
sl@0
|
969 |
}
|
sl@0
|
970 |
|
sl@0
|
971 |
// -----------------------------------------------------------------------------
|
sl@0
|
972 |
// CTesttimer::Testtimerapi15
|
sl@0
|
973 |
// Test Case ID: OPENENV-LIBC-CIT-5946
|
sl@0
|
974 |
// API tested: timer_settime()
|
sl@0
|
975 |
// Description: Trying to set the timer for an invalid timer id using timer_settime()
|
sl@0
|
976 |
// -----------------------------------------------------------------------------
|
sl@0
|
977 |
|
sl@0
|
978 |
TInt CTesttimer::Testtimerapi15 ( )
|
sl@0
|
979 |
{
|
sl@0
|
980 |
int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec, Timerflag;
|
sl@0
|
981 |
timer_t timerid;
|
sl@0
|
982 |
struct itimerspec timerspec;
|
sl@0
|
983 |
timer_value = 0;
|
sl@0
|
984 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
|
sl@0
|
985 |
if(ret == 0)
|
sl@0
|
986 |
{
|
sl@0
|
987 |
ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
|
sl@0
|
988 |
return ret1;
|
sl@0
|
989 |
}
|
sl@0
|
990 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
|
sl@0
|
991 |
if(ret == 0)
|
sl@0
|
992 |
{
|
sl@0
|
993 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
|
sl@0
|
994 |
return ret1;
|
sl@0
|
995 |
}
|
sl@0
|
996 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
|
sl@0
|
997 |
if(ret == 0)
|
sl@0
|
998 |
{
|
sl@0
|
999 |
ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
|
sl@0
|
1000 |
return ret1;
|
sl@0
|
1001 |
}
|
sl@0
|
1002 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
|
sl@0
|
1003 |
if(ret == 0)
|
sl@0
|
1004 |
{
|
sl@0
|
1005 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
|
sl@0
|
1006 |
return ret1;
|
sl@0
|
1007 |
}
|
sl@0
|
1008 |
ret = GetIntFromConfig(ConfigSection(), _L("Timerflag"), Timerflag);
|
sl@0
|
1009 |
if(ret == 0)
|
sl@0
|
1010 |
{
|
sl@0
|
1011 |
ERR_PRINTF1(_L("Unable to read the timer flag")) ;
|
sl@0
|
1012 |
return ret1;
|
sl@0
|
1013 |
}
|
sl@0
|
1014 |
if(signal(SIGALRM, alarm_handler) == SIG_ERR)
|
sl@0
|
1015 |
{
|
sl@0
|
1016 |
ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"), errno) ;
|
sl@0
|
1017 |
return ret1;
|
sl@0
|
1018 |
}
|
sl@0
|
1019 |
ret = timer_create(CLOCK_REALTIME,NULL,&timerid);
|
sl@0
|
1020 |
if(ret != 0)
|
sl@0
|
1021 |
{
|
sl@0
|
1022 |
ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
|
sl@0
|
1023 |
return -1;
|
sl@0
|
1024 |
}
|
sl@0
|
1025 |
INFO_PRINTF1(_L("Successfully able to create a timer") );
|
sl@0
|
1026 |
ret = timer_delete(timerid);
|
sl@0
|
1027 |
if(ret != 0)
|
sl@0
|
1028 |
{
|
sl@0
|
1029 |
ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
|
sl@0
|
1030 |
return -1;
|
sl@0
|
1031 |
}
|
sl@0
|
1032 |
INFO_PRINTF1(_L("Successfully able to delete the timer") );
|
sl@0
|
1033 |
timerspec.it_value.tv_sec = Valuesec;
|
sl@0
|
1034 |
timerspec.it_value.tv_nsec = Valuenanosec;
|
sl@0
|
1035 |
timerspec.it_interval.tv_sec = Intervalsec;
|
sl@0
|
1036 |
timerspec.it_interval.tv_nsec = Intervalnanosec;
|
sl@0
|
1037 |
ret = timer_settime(timerid,Timerflag,&timerspec,NULL);
|
sl@0
|
1038 |
if((ret != -1) || (errno != EINVAL))
|
sl@0
|
1039 |
{
|
sl@0
|
1040 |
ERR_PRINTF2(_L("timer_settime() failed to return EINVAL on negative test and errno is %d"),errno);
|
sl@0
|
1041 |
goto close;
|
sl@0
|
1042 |
}
|
sl@0
|
1043 |
INFO_PRINTF1(_L("timer_settime() successfully able to return EINVAL on negative test") );
|
sl@0
|
1044 |
ret1 = KErrNone;
|
sl@0
|
1045 |
|
sl@0
|
1046 |
close:
|
sl@0
|
1047 |
RThread athr;
|
sl@0
|
1048 |
if(athr.Open(_L("LibrtTimerServ")) == KErrNone)
|
sl@0
|
1049 |
{
|
sl@0
|
1050 |
athr.Close();
|
sl@0
|
1051 |
}
|
sl@0
|
1052 |
|
sl@0
|
1053 |
return ret1;
|
sl@0
|
1054 |
}
|
sl@0
|
1055 |
|
sl@0
|
1056 |
// -----------------------------------------------------------------------------
|
sl@0
|
1057 |
// CTesttimer::Testtimerapi16
|
sl@0
|
1058 |
// Test Case ID: OPENENV-LIBC-CIT-5946
|
sl@0
|
1059 |
// API tested: timer_settime()
|
sl@0
|
1060 |
// Description: Trying to set the timer with an invalid tv_nsec parameter using timer_settime()
|
sl@0
|
1061 |
// -----------------------------------------------------------------------------
|
sl@0
|
1062 |
|
sl@0
|
1063 |
TInt CTesttimer::Testtimerapi16 ( )
|
sl@0
|
1064 |
{
|
sl@0
|
1065 |
int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec, Signum, Maxsig, Timerflag, Sigval;
|
sl@0
|
1066 |
struct sigevent sigev;
|
sl@0
|
1067 |
struct itimerspec timerspec;
|
sl@0
|
1068 |
timer_t timerid;
|
sl@0
|
1069 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
|
sl@0
|
1070 |
if(ret == 0)
|
sl@0
|
1071 |
{
|
sl@0
|
1072 |
ERR_PRINTF1(_L("Unable to read seconds value of it_value"));
|
sl@0
|
1073 |
return ret1;
|
sl@0
|
1074 |
}
|
sl@0
|
1075 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
|
sl@0
|
1076 |
if(ret == 0)
|
sl@0
|
1077 |
{
|
sl@0
|
1078 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
|
sl@0
|
1079 |
return ret1;
|
sl@0
|
1080 |
}
|
sl@0
|
1081 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
|
sl@0
|
1082 |
if(ret == 0)
|
sl@0
|
1083 |
{
|
sl@0
|
1084 |
ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
|
sl@0
|
1085 |
return ret1;
|
sl@0
|
1086 |
}
|
sl@0
|
1087 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
|
sl@0
|
1088 |
if(ret == 0)
|
sl@0
|
1089 |
{
|
sl@0
|
1090 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
|
sl@0
|
1091 |
return ret1;
|
sl@0
|
1092 |
}
|
sl@0
|
1093 |
ret = GetIntFromConfig(ConfigSection(), _L("Sigval"), Sigval);
|
sl@0
|
1094 |
if(ret == 0)
|
sl@0
|
1095 |
{
|
sl@0
|
1096 |
ERR_PRINTF1(_L("Unable to read signal number")) ;
|
sl@0
|
1097 |
return ret1;
|
sl@0
|
1098 |
}
|
sl@0
|
1099 |
ret = GetIntFromConfig(ConfigSection(), _L("Maxsig"), Maxsig);
|
sl@0
|
1100 |
if(ret == 0)
|
sl@0
|
1101 |
{
|
sl@0
|
1102 |
ERR_PRINTF1(_L("Unable to read maximum signal number")) ;
|
sl@0
|
1103 |
return ret1;
|
sl@0
|
1104 |
}
|
sl@0
|
1105 |
ret = GetIntFromConfig(ConfigSection(), _L("Timerflag"), Timerflag);
|
sl@0
|
1106 |
if(ret == 0)
|
sl@0
|
1107 |
{
|
sl@0
|
1108 |
ERR_PRINTF1(_L("Unable to read the timer flag")) ;
|
sl@0
|
1109 |
return ret1;
|
sl@0
|
1110 |
}
|
sl@0
|
1111 |
for(Signum=Sigval; Signum <= Maxsig; Signum++)
|
sl@0
|
1112 |
{
|
sl@0
|
1113 |
if((Signum == SIGSTOP) || (Signum == SIGKILL))
|
sl@0
|
1114 |
{
|
sl@0
|
1115 |
continue;
|
sl@0
|
1116 |
}
|
sl@0
|
1117 |
timer_value = 0;
|
sl@0
|
1118 |
if(signal(Signum,sig_handler) == SIG_ERR)
|
sl@0
|
1119 |
{
|
sl@0
|
1120 |
ERR_PRINTF3(_L("Error in signal trapping function for signal is %d and errno is %d"),Signum, errno) ;
|
sl@0
|
1121 |
return ret1;
|
sl@0
|
1122 |
}
|
sl@0
|
1123 |
sigev.sigev_notify = SIGEV_SIGNAL;
|
sl@0
|
1124 |
sigev.sigev_signo = Signum;
|
sl@0
|
1125 |
ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
|
sl@0
|
1126 |
if(ret != 0)
|
sl@0
|
1127 |
{
|
sl@0
|
1128 |
ERR_PRINTF3(_L("Failed to create a timer %d and errno is %d"),Signum, errno);
|
sl@0
|
1129 |
return -1;
|
sl@0
|
1130 |
}
|
sl@0
|
1131 |
timerspec.it_value.tv_sec = Valuesec;
|
sl@0
|
1132 |
timerspec.it_value.tv_nsec = Valuenanosec;
|
sl@0
|
1133 |
timerspec.it_interval.tv_sec = Intervalsec;
|
sl@0
|
1134 |
timerspec.it_interval.tv_nsec = Intervalnanosec;
|
sl@0
|
1135 |
ret = timer_settime(timerid,Timerflag,&timerspec,NULL);
|
sl@0
|
1136 |
if((ret != -1) || (errno != EINVAL))
|
sl@0
|
1137 |
{
|
sl@0
|
1138 |
ERR_PRINTF2(_L("timer_settime() failed to return EINVAL on negative test and errno is %d"),errno);
|
sl@0
|
1139 |
goto close;
|
sl@0
|
1140 |
}
|
sl@0
|
1141 |
ret = timer_delete(timerid);
|
sl@0
|
1142 |
if(ret != 0)
|
sl@0
|
1143 |
{
|
sl@0
|
1144 |
ERR_PRINTF3(_L("Failed to delete the timer %d and errno is %d"),Signum,errno);
|
sl@0
|
1145 |
return -1;
|
sl@0
|
1146 |
}
|
sl@0
|
1147 |
}
|
sl@0
|
1148 |
INFO_PRINTF1(_L("timer_settime() successfully able to return EINVAL on negative test") );
|
sl@0
|
1149 |
ret1 = KErrNone;
|
sl@0
|
1150 |
return ret1;
|
sl@0
|
1151 |
close:
|
sl@0
|
1152 |
timer_delete(timerid);
|
sl@0
|
1153 |
return ret1;
|
sl@0
|
1154 |
}
|
sl@0
|
1155 |
|
sl@0
|
1156 |
// -----------------------------------------------------------------------------
|
sl@0
|
1157 |
// CTesttimer::Testtimerapi17
|
sl@0
|
1158 |
// Test Case ID: OPENENV-LIBC-CIT-5946
|
sl@0
|
1159 |
// API tested: timer_create(), timer_delete()
|
sl@0
|
1160 |
// Description: To create a timer with SIGEV_SIGNAL as sigev_notify parameter
|
sl@0
|
1161 |
// TIMER_ABSTIME not set
|
sl@0
|
1162 |
// -----------------------------------------------------------------------------
|
sl@0
|
1163 |
|
sl@0
|
1164 |
TInt CTesttimer::Testtimerapi17 ( )
|
sl@0
|
1165 |
{
|
sl@0
|
1166 |
int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
|
sl@0
|
1167 |
struct sigevent sigev;
|
sl@0
|
1168 |
struct itimerspec timerspec;
|
sl@0
|
1169 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
|
sl@0
|
1170 |
if(ret == 0)
|
sl@0
|
1171 |
{
|
sl@0
|
1172 |
ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
|
sl@0
|
1173 |
return ret1;
|
sl@0
|
1174 |
}
|
sl@0
|
1175 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
|
sl@0
|
1176 |
if(ret == 0)
|
sl@0
|
1177 |
{
|
sl@0
|
1178 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
|
sl@0
|
1179 |
return ret1;
|
sl@0
|
1180 |
}
|
sl@0
|
1181 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
|
sl@0
|
1182 |
if(ret == 0)
|
sl@0
|
1183 |
{
|
sl@0
|
1184 |
ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
|
sl@0
|
1185 |
return ret1;
|
sl@0
|
1186 |
}
|
sl@0
|
1187 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
|
sl@0
|
1188 |
if(ret == 0)
|
sl@0
|
1189 |
{
|
sl@0
|
1190 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
|
sl@0
|
1191 |
return ret1;
|
sl@0
|
1192 |
}
|
sl@0
|
1193 |
timer_value = 0;
|
sl@0
|
1194 |
if(signal(SIGUSR1,overrun_handler) == SIG_ERR)
|
sl@0
|
1195 |
{
|
sl@0
|
1196 |
ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"), errno) ;
|
sl@0
|
1197 |
return ret1;
|
sl@0
|
1198 |
}
|
sl@0
|
1199 |
sigev.sigev_notify = SIGEV_SIGNAL;
|
sl@0
|
1200 |
sigev.sigev_signo = SIGUSR1;
|
sl@0
|
1201 |
timer_t timerid;
|
sl@0
|
1202 |
ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
|
sl@0
|
1203 |
if(ret != 0)
|
sl@0
|
1204 |
{
|
sl@0
|
1205 |
ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
|
sl@0
|
1206 |
return -1;
|
sl@0
|
1207 |
}
|
sl@0
|
1208 |
timerspec.it_value.tv_sec = Valuesec;
|
sl@0
|
1209 |
timerspec.it_value.tv_nsec = Valuenanosec;
|
sl@0
|
1210 |
timerspec.it_interval.tv_sec = Intervalsec;
|
sl@0
|
1211 |
timerspec.it_interval.tv_nsec = Intervalnanosec;
|
sl@0
|
1212 |
timer_value = 0;
|
sl@0
|
1213 |
ret = timer_settime(timerid,0,&timerspec,NULL);
|
sl@0
|
1214 |
if(ret != 0)
|
sl@0
|
1215 |
{
|
sl@0
|
1216 |
ERR_PRINTF2(_L("Failed to set the time of specified clock id and errno is %d "),errno);
|
sl@0
|
1217 |
ret1 = -1;
|
sl@0
|
1218 |
goto close;
|
sl@0
|
1219 |
}
|
sl@0
|
1220 |
sleep(2);
|
sl@0
|
1221 |
if(timer_value != SIGUSR1)
|
sl@0
|
1222 |
{
|
sl@0
|
1223 |
ERR_PRINTF1(_L("The expected and timer_value are not same for signal"));
|
sl@0
|
1224 |
ret1 = -1;
|
sl@0
|
1225 |
goto close;
|
sl@0
|
1226 |
}
|
sl@0
|
1227 |
ret = timer_getoverrun(timerid);
|
sl@0
|
1228 |
if (ret != 0)
|
sl@0
|
1229 |
{
|
sl@0
|
1230 |
ERR_PRINTF2(_L("Error in timer_getoverrun() and errno is %d"),errno);
|
sl@0
|
1231 |
ret1 = -1;
|
sl@0
|
1232 |
goto close;
|
sl@0
|
1233 |
}
|
sl@0
|
1234 |
ret = timer_delete(timerid);
|
sl@0
|
1235 |
if(ret != 0)
|
sl@0
|
1236 |
{
|
sl@0
|
1237 |
ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
|
sl@0
|
1238 |
return -1;
|
sl@0
|
1239 |
}
|
sl@0
|
1240 |
INFO_PRINTF1(_L("Relative Timer") );
|
sl@0
|
1241 |
INFO_PRINTF1(_L("Successfully able to create a timer with SIGEV_SIGNAL as sigev_notify parameter") );
|
sl@0
|
1242 |
ret1 = KErrNone;
|
sl@0
|
1243 |
return ret1;
|
sl@0
|
1244 |
close:
|
sl@0
|
1245 |
timer_delete(timerid);
|
sl@0
|
1246 |
return ret1;
|
sl@0
|
1247 |
}
|
sl@0
|
1248 |
|
sl@0
|
1249 |
// -----------------------------------------------------------------------------
|
sl@0
|
1250 |
// CTesttimer::Testtimerapi18
|
sl@0
|
1251 |
// Test Case ID: OPENENV-LIBC-CIT-5946
|
sl@0
|
1252 |
// API tested: timer_create(), timer_delete()
|
sl@0
|
1253 |
// Description: To create a timer with SIGEV_SIGNAL as sigev_notify parameter
|
sl@0
|
1254 |
// TIMER_ABSTIME set
|
sl@0
|
1255 |
// -----------------------------------------------------------------------------
|
sl@0
|
1256 |
|
sl@0
|
1257 |
TInt CTesttimer::Testtimerapi18 ( )
|
sl@0
|
1258 |
{
|
sl@0
|
1259 |
int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
|
sl@0
|
1260 |
struct sigevent sigev;
|
sl@0
|
1261 |
struct itimerspec timerspec, oldtimerspec;
|
sl@0
|
1262 |
struct timespec curtmspec;
|
sl@0
|
1263 |
timer_t timerid;
|
sl@0
|
1264 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
|
sl@0
|
1265 |
if(ret == 0)
|
sl@0
|
1266 |
{
|
sl@0
|
1267 |
ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
|
sl@0
|
1268 |
return ret1;
|
sl@0
|
1269 |
}
|
sl@0
|
1270 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
|
sl@0
|
1271 |
if(ret == 0)
|
sl@0
|
1272 |
{
|
sl@0
|
1273 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
|
sl@0
|
1274 |
return ret1;
|
sl@0
|
1275 |
}
|
sl@0
|
1276 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
|
sl@0
|
1277 |
if(ret == 0)
|
sl@0
|
1278 |
{
|
sl@0
|
1279 |
ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
|
sl@0
|
1280 |
return ret1;
|
sl@0
|
1281 |
}
|
sl@0
|
1282 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
|
sl@0
|
1283 |
if(ret == 0)
|
sl@0
|
1284 |
{
|
sl@0
|
1285 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
|
sl@0
|
1286 |
return ret1;
|
sl@0
|
1287 |
}
|
sl@0
|
1288 |
timer_value = 0;
|
sl@0
|
1289 |
if(signal(SIGUSR1,overrun_handler) == SIG_ERR)
|
sl@0
|
1290 |
{
|
sl@0
|
1291 |
ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"), errno) ;
|
sl@0
|
1292 |
return ret1;
|
sl@0
|
1293 |
}
|
sl@0
|
1294 |
sigev.sigev_notify = SIGEV_SIGNAL;
|
sl@0
|
1295 |
sigev.sigev_signo = SIGUSR1;
|
sl@0
|
1296 |
ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
|
sl@0
|
1297 |
if(ret != 0)
|
sl@0
|
1298 |
{
|
sl@0
|
1299 |
ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
|
sl@0
|
1300 |
return -1;
|
sl@0
|
1301 |
}
|
sl@0
|
1302 |
ret = clock_gettime(CLOCK_REALTIME,&curtmspec);
|
sl@0
|
1303 |
if (ret != 0)
|
sl@0
|
1304 |
{
|
sl@0
|
1305 |
ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
|
sl@0
|
1306 |
ret1 = -1;
|
sl@0
|
1307 |
goto close;
|
sl@0
|
1308 |
}
|
sl@0
|
1309 |
timerspec.it_value.tv_sec = curtmspec.tv_sec + Valuesec;
|
sl@0
|
1310 |
timerspec.it_value.tv_nsec = curtmspec.tv_nsec + Valuenanosec;
|
sl@0
|
1311 |
timerspec.it_interval.tv_sec = Intervalsec;
|
sl@0
|
1312 |
timerspec.it_interval.tv_nsec = Intervalnanosec;
|
sl@0
|
1313 |
timer_value = 0;
|
sl@0
|
1314 |
ret = timer_settime(timerid,TIMER_ABSTIME,&timerspec,&oldtimerspec);
|
sl@0
|
1315 |
if(ret != 0)
|
sl@0
|
1316 |
{
|
sl@0
|
1317 |
ERR_PRINTF2(_L("Failed to set the timer for signal and errno is %d"),errno);
|
sl@0
|
1318 |
ret1 = -1;
|
sl@0
|
1319 |
goto close;
|
sl@0
|
1320 |
}
|
sl@0
|
1321 |
sleep(2);
|
sl@0
|
1322 |
if(timer_value != SIGUSR1)
|
sl@0
|
1323 |
{
|
sl@0
|
1324 |
ERR_PRINTF2(_L("The expected and timer_value are not same for signal %d"),errno);
|
sl@0
|
1325 |
goto close;
|
sl@0
|
1326 |
}
|
sl@0
|
1327 |
ret = timer_getoverrun(timerid);
|
sl@0
|
1328 |
if (ret != 0)
|
sl@0
|
1329 |
{
|
sl@0
|
1330 |
ERR_PRINTF2(_L("Error in timer_getoverrun() and errno is %d"),errno);
|
sl@0
|
1331 |
ret1 = -1;
|
sl@0
|
1332 |
goto close;
|
sl@0
|
1333 |
}
|
sl@0
|
1334 |
ret = timer_delete(timerid);
|
sl@0
|
1335 |
if(ret != 0)
|
sl@0
|
1336 |
{
|
sl@0
|
1337 |
ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
|
sl@0
|
1338 |
ret1 = -1;
|
sl@0
|
1339 |
}
|
sl@0
|
1340 |
INFO_PRINTF1(_L("Absolute Timer") );
|
sl@0
|
1341 |
INFO_PRINTF1(_L("Successfully able to create a timer with SIGEV_SIGNAL as sigev_notify parameter") );
|
sl@0
|
1342 |
ret1 = KErrNone;
|
sl@0
|
1343 |
return ret1;
|
sl@0
|
1344 |
close:
|
sl@0
|
1345 |
timer_delete(timerid);
|
sl@0
|
1346 |
return ret1;
|
sl@0
|
1347 |
}
|
sl@0
|
1348 |
|
sl@0
|
1349 |
// -----------------------------------------------------------------------------
|
sl@0
|
1350 |
// CTesttimer::Testtimerapi19
|
sl@0
|
1351 |
// Test Case ID: OPENENV-LIBC-CIT-5946
|
sl@0
|
1352 |
// API tested: timer_overrun(), timer_gettime()
|
sl@0
|
1353 |
// Description: Negative test: timer_overrun(), timer_gettime() with an invalid timerid
|
sl@0
|
1354 |
// -----------------------------------------------------------------------------
|
sl@0
|
1355 |
|
sl@0
|
1356 |
TInt CTesttimer::Testtimerapi19 ( )
|
sl@0
|
1357 |
{
|
sl@0
|
1358 |
timer_t timerid;
|
sl@0
|
1359 |
int ret, ret1 = KErrGeneral;
|
sl@0
|
1360 |
struct itimerspec timerspec;
|
sl@0
|
1361 |
ret = timer_create(CLOCK_REALTIME,NULL,&timerid);
|
sl@0
|
1362 |
if(ret != 0)
|
sl@0
|
1363 |
{
|
sl@0
|
1364 |
ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
|
sl@0
|
1365 |
return -1;
|
sl@0
|
1366 |
}
|
sl@0
|
1367 |
INFO_PRINTF1(_L("successfully able to create the timer") );
|
sl@0
|
1368 |
ret = timer_delete(timerid);
|
sl@0
|
1369 |
if(ret != 0)
|
sl@0
|
1370 |
{
|
sl@0
|
1371 |
ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
|
sl@0
|
1372 |
return -1;
|
sl@0
|
1373 |
}
|
sl@0
|
1374 |
INFO_PRINTF1(_L("Successfully able to delete the timer") );
|
sl@0
|
1375 |
ret = timer_gettime(timerid,&timerspec);
|
sl@0
|
1376 |
if((ret != -1) || (errno != EINVAL))
|
sl@0
|
1377 |
{
|
sl@0
|
1378 |
ERR_PRINTF2(_L("timer_gettime() failed to return EINVAL on negative test and errno is %d"),errno);
|
sl@0
|
1379 |
goto close;
|
sl@0
|
1380 |
}
|
sl@0
|
1381 |
INFO_PRINTF1(_L("timer_gettime() successfully returned EINVAL on negative test") );
|
sl@0
|
1382 |
ret = timer_getoverrun(timerid);
|
sl@0
|
1383 |
if((ret != -1) || (errno != EINVAL))
|
sl@0
|
1384 |
{
|
sl@0
|
1385 |
ERR_PRINTF2(_L("timer_getoverrun() failed to return EINVAL on negative test and errno is %d"),errno);
|
sl@0
|
1386 |
goto close;
|
sl@0
|
1387 |
}
|
sl@0
|
1388 |
INFO_PRINTF1(_L("timer_getoverrun() successfully returned EINVAL on negative test") );
|
sl@0
|
1389 |
ret1 = KErrNone;
|
sl@0
|
1390 |
return ret1;
|
sl@0
|
1391 |
close:
|
sl@0
|
1392 |
timer_delete(timerid);
|
sl@0
|
1393 |
return ret1;
|
sl@0
|
1394 |
}
|
sl@0
|
1395 |
|
sl@0
|
1396 |
// -----------------------------------------------------------------------------
|
sl@0
|
1397 |
// CTesttimer::Testtimerapi20
|
sl@0
|
1398 |
// Test Case ID: OPENENV-LIBC-CIT-5946
|
sl@0
|
1399 |
// API tested: timer_create()
|
sl@0
|
1400 |
// Description: Negative test: timer_create() with an invalid signal
|
sl@0
|
1401 |
// -----------------------------------------------------------------------------
|
sl@0
|
1402 |
|
sl@0
|
1403 |
TInt CTesttimer::Testtimerapi20 ( )
|
sl@0
|
1404 |
{
|
sl@0
|
1405 |
timer_t timerid;
|
sl@0
|
1406 |
int ret, ret1 = KErrGeneral, Sigval;
|
sl@0
|
1407 |
struct sigevent sigev;
|
sl@0
|
1408 |
ret = GetIntFromConfig(ConfigSection(), _L("Sigval"), Sigval);
|
sl@0
|
1409 |
if(ret == 0)
|
sl@0
|
1410 |
{
|
sl@0
|
1411 |
ERR_PRINTF1(_L("Unable to read signal number")) ;
|
sl@0
|
1412 |
return -1;
|
sl@0
|
1413 |
}
|
sl@0
|
1414 |
sigev.sigev_notify = SIGEV_SIGNAL;
|
sl@0
|
1415 |
sigev.sigev_signo = Sigval;
|
sl@0
|
1416 |
ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
|
sl@0
|
1417 |
if((ret != -1) || (errno != EINVAL))
|
sl@0
|
1418 |
{
|
sl@0
|
1419 |
ERR_PRINTF2(_L("timer_create() failed to return EINVAL on negative test and errno is %d"),errno);
|
sl@0
|
1420 |
goto close;
|
sl@0
|
1421 |
}
|
sl@0
|
1422 |
INFO_PRINTF1(_L("timer_create() with an invalid sigev_signo member") );
|
sl@0
|
1423 |
INFO_PRINTF1(_L("timer_create() successfully returned EINVAL on negative test") );
|
sl@0
|
1424 |
ret1 = KErrNone;
|
sl@0
|
1425 |
|
sl@0
|
1426 |
close:
|
sl@0
|
1427 |
return ret1;
|
sl@0
|
1428 |
}
|
sl@0
|
1429 |
|
sl@0
|
1430 |
// -----------------------------------------------------------------------------
|
sl@0
|
1431 |
// CTesttimer::Testtimerapi21
|
sl@0
|
1432 |
// Test Case ID: OPENENV-LIBC-CIT-5946
|
sl@0
|
1433 |
// API tested: timer_create()
|
sl@0
|
1434 |
// Description: Negative test: timer_create() with an invalid sigev_notify member
|
sl@0
|
1435 |
// -----------------------------------------------------------------------------
|
sl@0
|
1436 |
|
sl@0
|
1437 |
TInt CTesttimer::Testtimerapi21 ( )
|
sl@0
|
1438 |
{
|
sl@0
|
1439 |
timer_t timerid;
|
sl@0
|
1440 |
int ret, ret1 = KErrGeneral, Sigval, Signum, Maxsig, Notify;
|
sl@0
|
1441 |
struct sigevent sigev;
|
sl@0
|
1442 |
ret = GetIntFromConfig(ConfigSection(), _L("Sigval"), Sigval);
|
sl@0
|
1443 |
if(ret == 0)
|
sl@0
|
1444 |
{
|
sl@0
|
1445 |
ERR_PRINTF1(_L("Unable to read signal number")) ;
|
sl@0
|
1446 |
return ret1;
|
sl@0
|
1447 |
}
|
sl@0
|
1448 |
ret = GetIntFromConfig(ConfigSection(), _L("Maxsig"), Maxsig);
|
sl@0
|
1449 |
if(ret == 0)
|
sl@0
|
1450 |
{
|
sl@0
|
1451 |
ERR_PRINTF1(_L("Unable to read maximum signal number")) ;
|
sl@0
|
1452 |
return ret1;
|
sl@0
|
1453 |
}
|
sl@0
|
1454 |
ret = GetIntFromConfig(ConfigSection(), _L("Notify"), Notify);
|
sl@0
|
1455 |
if(ret == 0)
|
sl@0
|
1456 |
{
|
sl@0
|
1457 |
ERR_PRINTF1(_L("Unable to read an invalid notify value")) ;
|
sl@0
|
1458 |
return ret1;
|
sl@0
|
1459 |
}
|
sl@0
|
1460 |
for(Signum=Sigval; Signum <= Maxsig; Signum++)
|
sl@0
|
1461 |
{
|
sl@0
|
1462 |
if((Signum == SIGSTOP) || (Signum == SIGKILL))
|
sl@0
|
1463 |
{
|
sl@0
|
1464 |
continue;
|
sl@0
|
1465 |
}
|
sl@0
|
1466 |
sigev.sigev_notify = Notify;
|
sl@0
|
1467 |
sigev.sigev_signo = Signum;
|
sl@0
|
1468 |
ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
|
sl@0
|
1469 |
if((ret != -1) || (errno != EINVAL))
|
sl@0
|
1470 |
{
|
sl@0
|
1471 |
ERR_PRINTF2(_L("timer_create() failed to return EINVAL on negative test and errno is %d"),errno);
|
sl@0
|
1472 |
goto close;
|
sl@0
|
1473 |
}
|
sl@0
|
1474 |
}
|
sl@0
|
1475 |
INFO_PRINTF1(_L("timer_create() with an invalid sigev_notify member") );
|
sl@0
|
1476 |
INFO_PRINTF1(_L("timer_create() successfully returned EINVAL on negative test") );
|
sl@0
|
1477 |
ret1 = KErrNone;
|
sl@0
|
1478 |
|
sl@0
|
1479 |
close:
|
sl@0
|
1480 |
return ret1;
|
sl@0
|
1481 |
}
|
sl@0
|
1482 |
|
sl@0
|
1483 |
// -----------------------------------------------------------------------------
|
sl@0
|
1484 |
// CTesttimer::Testtimerapi22
|
sl@0
|
1485 |
// Test Case ID: OPENENV-LIBC-CIT-5946
|
sl@0
|
1486 |
// API tested: timer_settime()
|
sl@0
|
1487 |
// Description: Negative test: timer_settime() with an input itimerspec value as NULL
|
sl@0
|
1488 |
// -----------------------------------------------------------------------------
|
sl@0
|
1489 |
|
sl@0
|
1490 |
TInt CTesttimer::Testtimerapi22 ( )
|
sl@0
|
1491 |
{
|
sl@0
|
1492 |
int ret, ret1 = KErrGeneral;
|
sl@0
|
1493 |
struct sigevent sigev;
|
sl@0
|
1494 |
struct itimerspec timerspec;
|
sl@0
|
1495 |
timer_t timerid;
|
sl@0
|
1496 |
sigev.sigev_notify = SIGEV_NONE;
|
sl@0
|
1497 |
ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
|
sl@0
|
1498 |
if(ret != 0)
|
sl@0
|
1499 |
{
|
sl@0
|
1500 |
ERR_PRINTF2(_L("Failed to create a timer and errno is %d"), errno );
|
sl@0
|
1501 |
return -1;
|
sl@0
|
1502 |
}
|
sl@0
|
1503 |
INFO_PRINTF1(_L("Successfully able to create a timer") );
|
sl@0
|
1504 |
ret = timer_settime(timerid,0,NULL,&timerspec);
|
sl@0
|
1505 |
if((ret != -1) || (errno != EINVAL))
|
sl@0
|
1506 |
{
|
sl@0
|
1507 |
ERR_PRINTF2(_L("timer_settime() failed to return EINVAL on negative test and errno is %d"),errno);
|
sl@0
|
1508 |
goto close;
|
sl@0
|
1509 |
}
|
sl@0
|
1510 |
INFO_PRINTF1(_L("Successfully able to set the timer") );
|
sl@0
|
1511 |
sleep(2);
|
sl@0
|
1512 |
ret = timer_delete(timerid);
|
sl@0
|
1513 |
if(ret != 0)
|
sl@0
|
1514 |
{
|
sl@0
|
1515 |
ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
|
sl@0
|
1516 |
return -1;
|
sl@0
|
1517 |
}
|
sl@0
|
1518 |
INFO_PRINTF1(_L("timer_settime() with itimerspec input as NULL") );
|
sl@0
|
1519 |
INFO_PRINTF1(_L("timer_settime() successfully returned EINVAL on negative test") );
|
sl@0
|
1520 |
ret1 = KErrNone;
|
sl@0
|
1521 |
return ret1;
|
sl@0
|
1522 |
close:
|
sl@0
|
1523 |
timer_delete(timerid);
|
sl@0
|
1524 |
return ret1;
|
sl@0
|
1525 |
}
|
sl@0
|
1526 |
|
sl@0
|
1527 |
// -----------------------------------------------------------------------------
|
sl@0
|
1528 |
// CTesttimer::Testtimerapi23
|
sl@0
|
1529 |
// Test Case ID: OPENENV-LIBC-CIT-5946
|
sl@0
|
1530 |
// API tested: timer_settime()
|
sl@0
|
1531 |
// Description: Negative test: timer_settime() with an invalid flag member
|
sl@0
|
1532 |
// -----------------------------------------------------------------------------
|
sl@0
|
1533 |
|
sl@0
|
1534 |
TInt CTesttimer::Testtimerapi23 ( )
|
sl@0
|
1535 |
{
|
sl@0
|
1536 |
int ret, ret1 = KErrGeneral;
|
sl@0
|
1537 |
struct sigevent sigev;
|
sl@0
|
1538 |
struct itimerspec timerspec;
|
sl@0
|
1539 |
timer_t timerid;
|
sl@0
|
1540 |
sigev.sigev_notify = SIGEV_NONE;
|
sl@0
|
1541 |
ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
|
sl@0
|
1542 |
if(ret != 0)
|
sl@0
|
1543 |
{
|
sl@0
|
1544 |
ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno );
|
sl@0
|
1545 |
return -1;
|
sl@0
|
1546 |
}
|
sl@0
|
1547 |
INFO_PRINTF1(_L("Successfully able to create a timer") );
|
sl@0
|
1548 |
timerspec.it_value.tv_sec = 1;
|
sl@0
|
1549 |
timerspec.it_value.tv_nsec = 0;
|
sl@0
|
1550 |
timerspec.it_interval.tv_sec = 0;
|
sl@0
|
1551 |
timerspec.it_interval.tv_nsec = 0;
|
sl@0
|
1552 |
ret = timer_settime(timerid,-1,NULL,&timerspec);
|
sl@0
|
1553 |
if((ret != -1) || (errno != EINVAL))
|
sl@0
|
1554 |
{
|
sl@0
|
1555 |
ERR_PRINTF2(_L("timer_settime() failed to return EINVAL on negative test and errno is %d"),errno);
|
sl@0
|
1556 |
goto close;
|
sl@0
|
1557 |
}
|
sl@0
|
1558 |
INFO_PRINTF1(_L("Successfully able to set the timer") );
|
sl@0
|
1559 |
sleep(3);
|
sl@0
|
1560 |
ret = timer_delete(timerid);
|
sl@0
|
1561 |
if(ret != 0)
|
sl@0
|
1562 |
{
|
sl@0
|
1563 |
ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
|
sl@0
|
1564 |
return -1;
|
sl@0
|
1565 |
}
|
sl@0
|
1566 |
INFO_PRINTF1(_L("timer_settime() with an invalid flag value") );
|
sl@0
|
1567 |
INFO_PRINTF1(_L("timer_settime() successfully returned EINVAL on negative test") );
|
sl@0
|
1568 |
ret1 = KErrNone;
|
sl@0
|
1569 |
return ret1;
|
sl@0
|
1570 |
close:
|
sl@0
|
1571 |
timer_delete(timerid);
|
sl@0
|
1572 |
return ret1;
|
sl@0
|
1573 |
}
|
sl@0
|
1574 |
|
sl@0
|
1575 |
// -----------------------------------------------------------------------------
|
sl@0
|
1576 |
// CTesttimer::Testtimerapi24
|
sl@0
|
1577 |
// Test Case ID: OPENENV-LIBC-CIT-5946
|
sl@0
|
1578 |
// API tested: timer_gettime()
|
sl@0
|
1579 |
// Description: Negative test: timer_gettime() with an input itimerspec value as NULL
|
sl@0
|
1580 |
// -----------------------------------------------------------------------------
|
sl@0
|
1581 |
|
sl@0
|
1582 |
TInt CTesttimer::Testtimerapi24 ( )
|
sl@0
|
1583 |
{
|
sl@0
|
1584 |
int ret, ret1 = KErrGeneral;
|
sl@0
|
1585 |
struct sigevent sigev;
|
sl@0
|
1586 |
struct itimerspec timerspec;
|
sl@0
|
1587 |
timer_t timerid;
|
sl@0
|
1588 |
timer_value = 0;
|
sl@0
|
1589 |
sigev.sigev_notify = SIGEV_NONE;
|
sl@0
|
1590 |
ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
|
sl@0
|
1591 |
if(ret != 0)
|
sl@0
|
1592 |
{
|
sl@0
|
1593 |
ERR_PRINTF1(_L("Failed to create a timer") );
|
sl@0
|
1594 |
return -1;
|
sl@0
|
1595 |
}
|
sl@0
|
1596 |
INFO_PRINTF1(_L("Successfully able to create a timer") );
|
sl@0
|
1597 |
timerspec.it_value.tv_sec = 1;
|
sl@0
|
1598 |
timerspec.it_value.tv_nsec = 0;
|
sl@0
|
1599 |
timerspec.it_interval.tv_sec = 1;
|
sl@0
|
1600 |
timerspec.it_interval.tv_nsec = 0;
|
sl@0
|
1601 |
ret = timer_settime(timerid,0,&timerspec,NULL);
|
sl@0
|
1602 |
if(ret != 0)
|
sl@0
|
1603 |
{
|
sl@0
|
1604 |
ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
|
sl@0
|
1605 |
ret1 = -1;
|
sl@0
|
1606 |
goto close;
|
sl@0
|
1607 |
}
|
sl@0
|
1608 |
INFO_PRINTF1(_L("Successfully able to set the timer") );
|
sl@0
|
1609 |
ret = timer_gettime(timerid,NULL);
|
sl@0
|
1610 |
if((ret != -1) || (errno != EFAULT))
|
sl@0
|
1611 |
{
|
sl@0
|
1612 |
ERR_PRINTF2(_L("timer_gettime() failed to return EFAULT on negative test and errno is %d"),errno);
|
sl@0
|
1613 |
goto close;
|
sl@0
|
1614 |
}
|
sl@0
|
1615 |
ret = timer_delete(timerid);
|
sl@0
|
1616 |
if(ret != 0)
|
sl@0
|
1617 |
{
|
sl@0
|
1618 |
ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
|
sl@0
|
1619 |
ret1 = -1;
|
sl@0
|
1620 |
}
|
sl@0
|
1621 |
INFO_PRINTF1(_L("Successfully able to delete the timer") );
|
sl@0
|
1622 |
INFO_PRINTF1(_L("timer_gettime() with an input itimerspec value as NULL") );
|
sl@0
|
1623 |
INFO_PRINTF1(_L("timer_gettime() successfully returned EFAULT on negative test") );
|
sl@0
|
1624 |
ret1 = KErrNone;
|
sl@0
|
1625 |
return ret1;
|
sl@0
|
1626 |
close:
|
sl@0
|
1627 |
timer_delete(timerid);
|
sl@0
|
1628 |
return ret1;
|
sl@0
|
1629 |
}
|
sl@0
|
1630 |
|
sl@0
|
1631 |
// -----------------------------------------------------------------------------
|
sl@0
|
1632 |
// CTesttimer::Testtimerapi25
|
sl@0
|
1633 |
// Test Case ID: OPENENV-LIBC-CIT-5946
|
sl@0
|
1634 |
// API tested: timer_settime(),timer_gettime()
|
sl@0
|
1635 |
// Description: To retreive the amount of time until the timer expires
|
sl@0
|
1636 |
// Relative timer
|
sl@0
|
1637 |
// -----------------------------------------------------------------------------
|
sl@0
|
1638 |
|
sl@0
|
1639 |
TInt CTesttimer::Testtimerapi25 ( )
|
sl@0
|
1640 |
{
|
sl@0
|
1641 |
int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
|
sl@0
|
1642 |
struct sigevent sigev;
|
sl@0
|
1643 |
struct itimerspec timerspec, gettime, oldtimerspec;
|
sl@0
|
1644 |
timer_value = 0;
|
sl@0
|
1645 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
|
sl@0
|
1646 |
if(ret == 0)
|
sl@0
|
1647 |
{
|
sl@0
|
1648 |
ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
|
sl@0
|
1649 |
return ret1;
|
sl@0
|
1650 |
}
|
sl@0
|
1651 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
|
sl@0
|
1652 |
if(ret == 0)
|
sl@0
|
1653 |
{
|
sl@0
|
1654 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
|
sl@0
|
1655 |
return ret1;
|
sl@0
|
1656 |
}
|
sl@0
|
1657 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
|
sl@0
|
1658 |
if(ret == 0)
|
sl@0
|
1659 |
{
|
sl@0
|
1660 |
ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
|
sl@0
|
1661 |
return ret1;
|
sl@0
|
1662 |
}
|
sl@0
|
1663 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
|
sl@0
|
1664 |
if(ret == 0)
|
sl@0
|
1665 |
{
|
sl@0
|
1666 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
|
sl@0
|
1667 |
return ret1;
|
sl@0
|
1668 |
}
|
sl@0
|
1669 |
sigev.sigev_notify = SIGEV_NONE;
|
sl@0
|
1670 |
timer_t timerid;
|
sl@0
|
1671 |
ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
|
sl@0
|
1672 |
if(ret != 0)
|
sl@0
|
1673 |
{
|
sl@0
|
1674 |
ERR_PRINTF2(_L("Failed to create a timer and errno is %d"), errno );
|
sl@0
|
1675 |
return -1;
|
sl@0
|
1676 |
}
|
sl@0
|
1677 |
INFO_PRINTF1(_L("Successfully able to create a timer") );
|
sl@0
|
1678 |
timerspec.it_value.tv_sec = Valuesec;
|
sl@0
|
1679 |
timerspec.it_value.tv_nsec = Valuenanosec;
|
sl@0
|
1680 |
timerspec.it_interval.tv_sec = Intervalsec;
|
sl@0
|
1681 |
timerspec.it_interval.tv_nsec = Intervalnanosec;
|
sl@0
|
1682 |
ret = timer_settime(timerid,0,&timerspec,&oldtimerspec);
|
sl@0
|
1683 |
if(ret != 0)
|
sl@0
|
1684 |
{
|
sl@0
|
1685 |
ERR_PRINTF2(_L("Failed to set the timer and errno is %d"), errno );
|
sl@0
|
1686 |
ret1 = -1;
|
sl@0
|
1687 |
goto close;
|
sl@0
|
1688 |
}
|
sl@0
|
1689 |
sleep(1);
|
sl@0
|
1690 |
INFO_PRINTF1(_L("Successfully able to set the timer") );
|
sl@0
|
1691 |
ret = timer_gettime(timerid,&gettime);
|
sl@0
|
1692 |
if(ret != 0)
|
sl@0
|
1693 |
{
|
sl@0
|
1694 |
ERR_PRINTF2(_L("Failed to get the timer and the errno is %d"),errno );
|
sl@0
|
1695 |
ret1 = -1;
|
sl@0
|
1696 |
goto close;
|
sl@0
|
1697 |
}
|
sl@0
|
1698 |
if((gettime.it_value.tv_sec > (timerspec.it_value.tv_sec-1)) || (gettime.it_value.tv_nsec > (timerspec.it_value.tv_nsec))|| (gettime.it_interval.tv_sec != timerspec.it_interval.tv_sec) || (gettime.it_interval.tv_nsec != timerspec.it_interval.tv_nsec))
|
sl@0
|
1699 |
{
|
sl@0
|
1700 |
ERR_PRINTF1(_L("Failed to get the timer value") );
|
sl@0
|
1701 |
ret1 = -1;
|
sl@0
|
1702 |
goto close;
|
sl@0
|
1703 |
}
|
sl@0
|
1704 |
INFO_PRINTF1(_L("Successfully able to get the timer") );
|
sl@0
|
1705 |
ret = timer_delete(timerid);
|
sl@0
|
1706 |
if(ret != 0)
|
sl@0
|
1707 |
{
|
sl@0
|
1708 |
ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
|
sl@0
|
1709 |
return -1;;
|
sl@0
|
1710 |
}
|
sl@0
|
1711 |
INFO_PRINTF1(_L("Successfully able to delete the timer") );
|
sl@0
|
1712 |
ret1 = KErrNone;
|
sl@0
|
1713 |
return ret1;
|
sl@0
|
1714 |
close:
|
sl@0
|
1715 |
timer_delete(timerid);
|
sl@0
|
1716 |
return ret1;
|
sl@0
|
1717 |
}
|
sl@0
|
1718 |
|
sl@0
|
1719 |
// -----------------------------------------------------------------------------
|
sl@0
|
1720 |
// CTesttimer::Testtimerapi26
|
sl@0
|
1721 |
// Test Case ID: OPENENV-LIBC-CIT-5946
|
sl@0
|
1722 |
// API tested: timer_settime(),timer_gettime()
|
sl@0
|
1723 |
// Description: To retreive the amount of time until the timer expires
|
sl@0
|
1724 |
// Absolute timer
|
sl@0
|
1725 |
// -----------------------------------------------------------------------------
|
sl@0
|
1726 |
|
sl@0
|
1727 |
TInt CTesttimer::Testtimerapi26 ( )
|
sl@0
|
1728 |
{
|
sl@0
|
1729 |
int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
|
sl@0
|
1730 |
struct sigevent sigev;
|
sl@0
|
1731 |
struct itimerspec timerspec, gettime, oldtimerspec;
|
sl@0
|
1732 |
struct timespec curtmspec;
|
sl@0
|
1733 |
timer_value = 0;
|
sl@0
|
1734 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
|
sl@0
|
1735 |
if(ret == 0)
|
sl@0
|
1736 |
{
|
sl@0
|
1737 |
ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
|
sl@0
|
1738 |
return ret1;
|
sl@0
|
1739 |
}
|
sl@0
|
1740 |
ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
|
sl@0
|
1741 |
if(ret == 0)
|
sl@0
|
1742 |
{
|
sl@0
|
1743 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
|
sl@0
|
1744 |
return ret1;
|
sl@0
|
1745 |
}
|
sl@0
|
1746 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
|
sl@0
|
1747 |
if(ret == 0)
|
sl@0
|
1748 |
{
|
sl@0
|
1749 |
ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
|
sl@0
|
1750 |
return ret1;
|
sl@0
|
1751 |
}
|
sl@0
|
1752 |
ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
|
sl@0
|
1753 |
if(ret == 0)
|
sl@0
|
1754 |
{
|
sl@0
|
1755 |
ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
|
sl@0
|
1756 |
return ret1;
|
sl@0
|
1757 |
}
|
sl@0
|
1758 |
sigev.sigev_notify = SIGEV_NONE;
|
sl@0
|
1759 |
timer_t timerid;
|
sl@0
|
1760 |
ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
|
sl@0
|
1761 |
if(ret != 0)
|
sl@0
|
1762 |
{
|
sl@0
|
1763 |
ERR_PRINTF2(_L("Failed to create a timer and errno is %d"), errno );
|
sl@0
|
1764 |
return -1;
|
sl@0
|
1765 |
}
|
sl@0
|
1766 |
INFO_PRINTF1(_L("Successfully able to create a timer") );
|
sl@0
|
1767 |
ret = clock_gettime(CLOCK_REALTIME,&curtmspec);
|
sl@0
|
1768 |
if (ret != 0)
|
sl@0
|
1769 |
{
|
sl@0
|
1770 |
ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
|
sl@0
|
1771 |
ret1 = -1;
|
sl@0
|
1772 |
goto close;
|
sl@0
|
1773 |
}
|
sl@0
|
1774 |
timerspec.it_value.tv_sec = curtmspec.tv_sec + Valuesec;
|
sl@0
|
1775 |
timerspec.it_value.tv_nsec = curtmspec.tv_nsec + Valuenanosec;
|
sl@0
|
1776 |
timerspec.it_interval.tv_sec = Intervalsec;
|
sl@0
|
1777 |
timerspec.it_interval.tv_nsec = Intervalnanosec;
|
sl@0
|
1778 |
ret = timer_settime(timerid,TIMER_ABSTIME,&timerspec,&oldtimerspec);
|
sl@0
|
1779 |
if(ret != 0)
|
sl@0
|
1780 |
{
|
sl@0
|
1781 |
ERR_PRINTF2(_L("Failed to set the timer and errno is %d"), errno );
|
sl@0
|
1782 |
ret1 = -1;
|
sl@0
|
1783 |
goto close;
|
sl@0
|
1784 |
}
|
sl@0
|
1785 |
sleep(1);
|
sl@0
|
1786 |
INFO_PRINTF1(_L("Successfully able to set the timer") );
|
sl@0
|
1787 |
ret = timer_gettime(timerid,&gettime);
|
sl@0
|
1788 |
if(ret != 0)
|
sl@0
|
1789 |
{
|
sl@0
|
1790 |
ERR_PRINTF2(_L("Failed to get the timer and errno is %d"), errno );
|
sl@0
|
1791 |
ret1 = -1;
|
sl@0
|
1792 |
goto close;
|
sl@0
|
1793 |
}
|
sl@0
|
1794 |
if((gettime.it_value.tv_sec > (Valuesec-1)) || (gettime.it_value.tv_nsec > (Valuenanosec))|| (gettime.it_interval.tv_sec != Intervalsec) || (gettime.it_interval.tv_nsec != Intervalnanosec))
|
sl@0
|
1795 |
{
|
sl@0
|
1796 |
ERR_PRINTF1(_L("Failed to get the timer value") );
|
sl@0
|
1797 |
ret1 = -1;
|
sl@0
|
1798 |
goto close;
|
sl@0
|
1799 |
}
|
sl@0
|
1800 |
INFO_PRINTF1(_L("Successfully able to get the timer") );
|
sl@0
|
1801 |
ret = timer_delete(timerid);
|
sl@0
|
1802 |
if(ret != 0)
|
sl@0
|
1803 |
{
|
sl@0
|
1804 |
ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
|
sl@0
|
1805 |
return -1;
|
sl@0
|
1806 |
}
|
sl@0
|
1807 |
INFO_PRINTF1(_L("Successfully able to delete the timer") );
|
sl@0
|
1808 |
ret1 = KErrNone;
|
sl@0
|
1809 |
return ret1;
|
sl@0
|
1810 |
close:
|
sl@0
|
1811 |
timer_delete(timerid);
|
sl@0
|
1812 |
return ret1;
|
sl@0
|
1813 |
}
|
sl@0
|
1814 |
|
sl@0
|
1815 |
// -----------------------------------------------------------------------------
|
sl@0
|
1816 |
// CTesttimer::Testtimerapi27
|
sl@0
|
1817 |
// Test Case ID: OPENENV-LIBC-CIT-5946
|
sl@0
|
1818 |
// API tested: timer_settime(),timer_gettime()
|
sl@0
|
1819 |
// Description: To retreive the amount of time until the timer expires using timer_settime()
|
sl@0
|
1820 |
// Absolute timer
|
sl@0
|
1821 |
// -----------------------------------------------------------------------------
|
sl@0
|
1822 |
|
sl@0
|
1823 |
TInt CTesttimer::Testtimerapi27 ( )
|
sl@0
|
1824 |
{
|
sl@0
|
1825 |
int ret, ret1 = KErrGeneral;
|
sl@0
|
1826 |
struct sigevent sigev;
|
sl@0
|
1827 |
struct itimerspec timerspec1, gettime, oldtimerspec;
|
sl@0
|
1828 |
timer_value = 0;
|
sl@0
|
1829 |
sigev.sigev_notify = SIGEV_NONE;
|
sl@0
|
1830 |
timer_t timerid;
|
sl@0
|
1831 |
ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
|
sl@0
|
1832 |
if(ret != 0)
|
sl@0
|
1833 |
{
|
sl@0
|
1834 |
ERR_PRINTF2(_L("Failed to create a timer and errno is %d"), errno );
|
sl@0
|
1835 |
return -1;
|
sl@0
|
1836 |
}
|
sl@0
|
1837 |
INFO_PRINTF1(_L("Successfully able to create a timer") );
|
sl@0
|
1838 |
timerspec1.it_value.tv_sec = 5;
|
sl@0
|
1839 |
timerspec1.it_value.tv_nsec = 0;
|
sl@0
|
1840 |
timerspec1.it_interval.tv_sec = 0;
|
sl@0
|
1841 |
timerspec1.it_interval.tv_nsec = 0;
|
sl@0
|
1842 |
ret = timer_settime(timerid,0,&timerspec1,NULL);
|
sl@0
|
1843 |
if(ret != 0)
|
sl@0
|
1844 |
{
|
sl@0
|
1845 |
ERR_PRINTF2(_L("Failed to set the timer and errno is %d"), errno );
|
sl@0
|
1846 |
ret1 = -1;
|
sl@0
|
1847 |
goto close;
|
sl@0
|
1848 |
}
|
sl@0
|
1849 |
INFO_PRINTF1(_L("Successfully able to set the timer for the first time") );
|
sl@0
|
1850 |
sleep(1);
|
sl@0
|
1851 |
timerspec1.it_value.tv_sec = 3;
|
sl@0
|
1852 |
timerspec1.it_value.tv_nsec = 0;
|
sl@0
|
1853 |
timerspec1.it_interval.tv_sec = 0;
|
sl@0
|
1854 |
timerspec1.it_interval.tv_nsec = 0;
|
sl@0
|
1855 |
ret = timer_settime(timerid,0,&timerspec1,&oldtimerspec);
|
sl@0
|
1856 |
if(ret != 0)
|
sl@0
|
1857 |
{
|
sl@0
|
1858 |
ERR_PRINTF2(_L("Failed to set the timer and errno is %d"), errno );
|
sl@0
|
1859 |
ret1 = -1;
|
sl@0
|
1860 |
goto close;
|
sl@0
|
1861 |
}
|
sl@0
|
1862 |
INFO_PRINTF1(_L("Successfully able to set the timer for the second time") );
|
sl@0
|
1863 |
if(oldtimerspec.it_value.tv_sec > 4)
|
sl@0
|
1864 |
{
|
sl@0
|
1865 |
ERR_PRINTF1(_L("Failed to set the timer value") );
|
sl@0
|
1866 |
goto close;
|
sl@0
|
1867 |
}
|
sl@0
|
1868 |
sleep(1);
|
sl@0
|
1869 |
timerspec1.it_value.tv_sec = 0;
|
sl@0
|
1870 |
timerspec1.it_value.tv_nsec = 0;
|
sl@0
|
1871 |
timerspec1.it_interval.tv_sec = 0;
|
sl@0
|
1872 |
timerspec1.it_interval.tv_nsec = 0;
|
sl@0
|
1873 |
ret = timer_settime(timerid,0,&timerspec1,&oldtimerspec);
|
sl@0
|
1874 |
if(ret != 0)
|
sl@0
|
1875 |
{
|
sl@0
|
1876 |
ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
|
sl@0
|
1877 |
goto close;
|
sl@0
|
1878 |
}
|
sl@0
|
1879 |
if(oldtimerspec.it_value.tv_sec > 2)
|
sl@0
|
1880 |
{
|
sl@0
|
1881 |
ERR_PRINTF1(_L("Failed to set the timer value") );
|
sl@0
|
1882 |
goto close;
|
sl@0
|
1883 |
}
|
sl@0
|
1884 |
timerspec1.it_value.tv_sec = 2;
|
sl@0
|
1885 |
timerspec1.it_value.tv_nsec = 0;
|
sl@0
|
1886 |
timerspec1.it_interval.tv_sec = 5;
|
sl@0
|
1887 |
timerspec1.it_interval.tv_nsec = 0;
|
sl@0
|
1888 |
ret = timer_settime(timerid,0,&timerspec1,&oldtimerspec);
|
sl@0
|
1889 |
if(ret != 0)
|
sl@0
|
1890 |
{
|
sl@0
|
1891 |
ERR_PRINTF2(_L("Failed to set the timer and errno is %d"), errno);
|
sl@0
|
1892 |
ret1 = -1;
|
sl@0
|
1893 |
goto close;
|
sl@0
|
1894 |
}
|
sl@0
|
1895 |
if(oldtimerspec.it_value.tv_sec != 0)
|
sl@0
|
1896 |
{
|
sl@0
|
1897 |
ERR_PRINTF1(_L("Failed to set the timer value") );
|
sl@0
|
1898 |
goto close;
|
sl@0
|
1899 |
}
|
sl@0
|
1900 |
ret = timer_gettime(timerid,&gettime);
|
sl@0
|
1901 |
if(ret != 0)
|
sl@0
|
1902 |
{
|
sl@0
|
1903 |
ERR_PRINTF2(_L("Failed to get the timer and errno is %d"),errno);
|
sl@0
|
1904 |
ret1 = -1;
|
sl@0
|
1905 |
goto close;
|
sl@0
|
1906 |
}
|
sl@0
|
1907 |
|
sl@0
|
1908 |
if((gettime.it_value.tv_sec > 2) || (gettime.it_interval.tv_sec != timerspec1.it_interval.tv_sec) || (gettime.it_interval.tv_nsec != timerspec1.it_interval.tv_nsec))
|
sl@0
|
1909 |
{
|
sl@0
|
1910 |
ERR_PRINTF1(_L("Failed to get the timer value") );
|
sl@0
|
1911 |
goto close;
|
sl@0
|
1912 |
}
|
sl@0
|
1913 |
INFO_PRINTF1(_L("Successfully able to get the timer") );
|
sl@0
|
1914 |
ret = timer_delete(timerid);
|
sl@0
|
1915 |
if(ret != 0)
|
sl@0
|
1916 |
{
|
sl@0
|
1917 |
ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
|
sl@0
|
1918 |
return -1;
|
sl@0
|
1919 |
}
|
sl@0
|
1920 |
INFO_PRINTF1(_L("Successfully able to delete the timer") );
|
sl@0
|
1921 |
ret1 = KErrNone;
|
sl@0
|
1922 |
return ret1;
|
sl@0
|
1923 |
close:
|
sl@0
|
1924 |
timer_delete(timerid);
|
sl@0
|
1925 |
return ret1;
|
sl@0
|
1926 |
}
|
sl@0
|
1927 |
TInt CTesttimer::Testtimerapi28( )
|
sl@0
|
1928 |
{
|
sl@0
|
1929 |
TInt err;
|
sl@0
|
1930 |
|
sl@0
|
1931 |
TRequestStatus timerThreadStatus1;
|
sl@0
|
1932 |
RThread timerThread1;
|
sl@0
|
1933 |
TTimerTestThreadParams paramsTimerThread1(*this);
|
sl@0
|
1934 |
|
sl@0
|
1935 |
TRequestStatus timerThreadStatus2;
|
sl@0
|
1936 |
RThread timerThread2;
|
sl@0
|
1937 |
TTimerTestThreadParams paramsTimerThread2(*this);
|
sl@0
|
1938 |
|
sl@0
|
1939 |
Logger().ShareAuto();
|
sl@0
|
1940 |
//Create the Thread to create shared mem and write to it.
|
sl@0
|
1941 |
err = timerThread1.Create(_L("TimerThread1"), (TThreadFunction)CTimerTestThread::OEEntry, KDefaultStackSize, KMinHeapSize, 1024*1024,¶msTimerThread1);
|
sl@0
|
1942 |
if(err != KErrNone)
|
sl@0
|
1943 |
{
|
sl@0
|
1944 |
ERR_PRINTF2(_L("Timer Thread1 Not created - %d"), err);
|
sl@0
|
1945 |
SetTestStepResult(EFail);
|
sl@0
|
1946 |
return EFail;
|
sl@0
|
1947 |
|
sl@0
|
1948 |
}
|
sl@0
|
1949 |
INFO_PRINTF1(_L("Timer Thread1 created "));
|
sl@0
|
1950 |
//Create the thread to open shared mem and read from it.
|
sl@0
|
1951 |
err = timerThread2.Create(_L("TimerThread2"), (TThreadFunction)CTimerTestThread::OEEntry, KDefaultStackSize, KMinHeapSize, 1024*1024,¶msTimerThread2);
|
sl@0
|
1952 |
if(err != KErrNone)
|
sl@0
|
1953 |
{
|
sl@0
|
1954 |
ERR_PRINTF2(_L("Timer Thread 2 Not created - %d"), err);
|
sl@0
|
1955 |
SetTestStepResult(EFail);
|
sl@0
|
1956 |
//Close the Write Thread created previously
|
sl@0
|
1957 |
timerThread1.Close();
|
sl@0
|
1958 |
return EFail;
|
sl@0
|
1959 |
|
sl@0
|
1960 |
}
|
sl@0
|
1961 |
INFO_PRINTF1(_L("Timer Thread created "));
|
sl@0
|
1962 |
|
sl@0
|
1963 |
timerThread1.SetPriority(EPriorityNormal);
|
sl@0
|
1964 |
timerThread2.SetPriority(EPriorityNormal);
|
sl@0
|
1965 |
|
sl@0
|
1966 |
timerThread1.Logon(timerThreadStatus1);
|
sl@0
|
1967 |
timerThread2.Logon(timerThreadStatus2);
|
sl@0
|
1968 |
|
sl@0
|
1969 |
timerThread1.Resume();
|
sl@0
|
1970 |
timerThread2.Resume();
|
sl@0
|
1971 |
|
sl@0
|
1972 |
User::WaitForRequest(timerThreadStatus1);
|
sl@0
|
1973 |
User::WaitForRequest(timerThreadStatus2);
|
sl@0
|
1974 |
|
sl@0
|
1975 |
timerThread1.Close();
|
sl@0
|
1976 |
timerThread2.Close();
|
sl@0
|
1977 |
|
sl@0
|
1978 |
//Check the status of the threads..
|
sl@0
|
1979 |
if(!paramsTimerThread1.iTestResult )
|
sl@0
|
1980 |
{
|
sl@0
|
1981 |
ERR_PRINTF1(_L("Timer Thread 1 Not successful"));
|
sl@0
|
1982 |
SetTestStepResult(EFail);
|
sl@0
|
1983 |
}
|
sl@0
|
1984 |
if(!paramsTimerThread2.iTestResult )
|
sl@0
|
1985 |
{
|
sl@0
|
1986 |
ERR_PRINTF1(_L("Timer Thread 2 Not successful"));
|
sl@0
|
1987 |
SetTestStepResult(EFail);
|
sl@0
|
1988 |
}
|
sl@0
|
1989 |
|
sl@0
|
1990 |
return TestStepResult();
|
sl@0
|
1991 |
|
sl@0
|
1992 |
|
sl@0
|
1993 |
}
|
sl@0
|
1994 |
//End of a file
|
sl@0
|
1995 |
|
sl@0
|
1996 |
|
sl@0
|
1997 |
|
sl@0
|
1998 |
|