sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:test cases for concurrency test for timer_settime ,timer_gettime
|
sl@0
|
15 |
* Name : ttimerthread.cpp
|
sl@0
|
16 |
*
|
sl@0
|
17 |
*
|
sl@0
|
18 |
*/
|
sl@0
|
19 |
|
sl@0
|
20 |
#include "ttimerthread.h"
|
sl@0
|
21 |
#include <stdapis/errno.h>
|
sl@0
|
22 |
|
sl@0
|
23 |
CTimerTestThread* CTimerTestThread::NewL(TTimerTestThreadParams& aParams)
|
sl@0
|
24 |
{
|
sl@0
|
25 |
CTimerTestThread* self = new (ELeave) CTimerTestThread(aParams);
|
sl@0
|
26 |
return self;
|
sl@0
|
27 |
}
|
sl@0
|
28 |
CTimerTestThread::CTimerTestThread(TTimerTestThreadParams& aParams)
|
sl@0
|
29 |
:iParentStep(aParams.iTestStep),iParams(aParams)
|
sl@0
|
30 |
{
|
sl@0
|
31 |
}
|
sl@0
|
32 |
|
sl@0
|
33 |
CTimerTestThread::~CTimerTestThread()
|
sl@0
|
34 |
{
|
sl@0
|
35 |
}
|
sl@0
|
36 |
|
sl@0
|
37 |
TInt CTimerTestThread::OEEntry(TAny* aData)
|
sl@0
|
38 |
{
|
sl@0
|
39 |
TTimerTestThreadParams* params = static_cast<TTimerTestThreadParams*>(aData);
|
sl@0
|
40 |
CTrapCleanup* cleanup = CTrapCleanup::New();
|
sl@0
|
41 |
if (!cleanup)
|
sl@0
|
42 |
{
|
sl@0
|
43 |
return KErrNoMemory;
|
sl@0
|
44 |
}
|
sl@0
|
45 |
|
sl@0
|
46 |
TRAPD(err, OEMainL(*params));
|
sl@0
|
47 |
delete cleanup;
|
sl@0
|
48 |
return err;
|
sl@0
|
49 |
}
|
sl@0
|
50 |
void CTimerTestThread::OEMainL(TTimerTestThreadParams& aParams)
|
sl@0
|
51 |
{
|
sl@0
|
52 |
|
sl@0
|
53 |
CTimerTestThread* timerThread = CTimerTestThread::NewL(aParams);
|
sl@0
|
54 |
timerThread->doOperation();
|
sl@0
|
55 |
delete timerThread;
|
sl@0
|
56 |
}
|
sl@0
|
57 |
void CTimerTestThread::doOperation()
|
sl@0
|
58 |
{
|
sl@0
|
59 |
timer_t timerid;
|
sl@0
|
60 |
struct itimerspec timeSpec1;
|
sl@0
|
61 |
struct itimerspec timeSpec2;
|
sl@0
|
62 |
|
sl@0
|
63 |
iParams.iTestResult=EFalse;
|
sl@0
|
64 |
|
sl@0
|
65 |
int ret = timer_create(CLOCK_REALTIME, NULL, &timerid);
|
sl@0
|
66 |
if(ret != -1)
|
sl@0
|
67 |
{
|
sl@0
|
68 |
iParams.iTestStep.INFO_PRINTF1(_L("Timer Created"));
|
sl@0
|
69 |
|
sl@0
|
70 |
timeSpec1.it_value.tv_sec = 10;
|
sl@0
|
71 |
/* 500 million nsecs = .5 secs */
|
sl@0
|
72 |
timeSpec1.it_value.tv_nsec = 500000000;
|
sl@0
|
73 |
|
sl@0
|
74 |
timeSpec1.it_interval.tv_sec = 10;
|
sl@0
|
75 |
/* 500 million nsecs = .5 secs */
|
sl@0
|
76 |
timeSpec1.it_interval.tv_nsec = 500000000;
|
sl@0
|
77 |
|
sl@0
|
78 |
ret = timer_settime(timerid, 0, &timeSpec1, NULL);
|
sl@0
|
79 |
if (ret == -1)
|
sl@0
|
80 |
{
|
sl@0
|
81 |
|
sl@0
|
82 |
iParams.iTestStep.ERR_PRINTF2(_L("Timer Set Time Failed - %d"), errno);
|
sl@0
|
83 |
return;
|
sl@0
|
84 |
}
|
sl@0
|
85 |
iParams.iTestStep.INFO_PRINTF1(_L("Set Timer Success"));
|
sl@0
|
86 |
|
sl@0
|
87 |
// get_timer()
|
sl@0
|
88 |
ret = timer_gettime(timerid, &timeSpec2);
|
sl@0
|
89 |
|
sl@0
|
90 |
if(ret == -1)
|
sl@0
|
91 |
{
|
sl@0
|
92 |
iParams.iTestStep.ERR_PRINTF2(_L("Timer Get Time Failed - %d"), errno);
|
sl@0
|
93 |
return;
|
sl@0
|
94 |
|
sl@0
|
95 |
}
|
sl@0
|
96 |
iParams.iTestStep.INFO_PRINTF1(_L("Get Timer Success"));
|
sl@0
|
97 |
|
sl@0
|
98 |
compareTimeSpec(timeSpec1, timeSpec2);
|
sl@0
|
99 |
|
sl@0
|
100 |
ret = timer_delete(timerid);
|
sl@0
|
101 |
|
sl@0
|
102 |
if(ret == -1)
|
sl@0
|
103 |
{
|
sl@0
|
104 |
iParams.iTestStep.ERR_PRINTF2(_L("Timer Get Time Failed - %d"), errno);
|
sl@0
|
105 |
return;
|
sl@0
|
106 |
|
sl@0
|
107 |
}
|
sl@0
|
108 |
iParams.iTestStep.INFO_PRINTF1(_L("Timer Deleted"));
|
sl@0
|
109 |
|
sl@0
|
110 |
|
sl@0
|
111 |
}
|
sl@0
|
112 |
else
|
sl@0
|
113 |
{
|
sl@0
|
114 |
iParams.iTestStep.ERR_PRINTF2(_L("Timer Create Failed - %d"), errno);
|
sl@0
|
115 |
return;
|
sl@0
|
116 |
|
sl@0
|
117 |
}
|
sl@0
|
118 |
iParams.iTestResult=ETrue;
|
sl@0
|
119 |
return;
|
sl@0
|
120 |
|
sl@0
|
121 |
}
|
sl@0
|
122 |
|
sl@0
|
123 |
TBool CTimerTestThread::compareTimeSpec(struct itimerspec timeSpec1, struct itimerspec timeSpec2)
|
sl@0
|
124 |
{
|
sl@0
|
125 |
|
sl@0
|
126 |
if((timeSpec1.it_value.tv_sec == timeSpec2.it_value.tv_sec )
|
sl@0
|
127 |
&& (timeSpec1.it_value.tv_nsec == timeSpec2.it_value.tv_nsec )
|
sl@0
|
128 |
&& (timeSpec1.it_interval.tv_sec == timeSpec2.it_interval.tv_sec )
|
sl@0
|
129 |
&& (timeSpec1.it_interval.tv_nsec == timeSpec2.it_interval.tv_nsec ))
|
sl@0
|
130 |
{
|
sl@0
|
131 |
iParams.iTestStep.INFO_PRINTF1(_L("Timer Spec Matched"));
|
sl@0
|
132 |
return ETrue;
|
sl@0
|
133 |
|
sl@0
|
134 |
}
|
sl@0
|
135 |
else
|
sl@0
|
136 |
{
|
sl@0
|
137 |
iParams.iTestStep.INFO_PRINTF1(_L("Timer spec Not Matched"));
|
sl@0
|
138 |
return EFalse;
|
sl@0
|
139 |
}
|
sl@0
|
140 |
|
sl@0
|
141 |
|
sl@0
|
142 |
}
|