| author | sl |
| Tue, 10 Jun 2014 14:32:02 +0200 | |
| changeset 1 | 260cb5ec6c19 |
| permissions | -rw-r--r-- |
1 /*
2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
3 * All rights reserved.
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 *
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
11 *
12 * Contributors:
13 *
14 * Description:
15 * Name : tsemwait.h
16 * Part of : testsemwait
17 * This material, including documentation and any related
18 * computer programs, is protected by copyright controlled by
19 * Nokia Corporation. All rights are reserved. Copying,
20 * including reproducing, storing, adapting or translating, any
21 * or all of this material requires the prior written consent of
22 * Nokia Corporation. This material also contains confidential
23 * information which may not be disclosed to others without the
24 * prior written consent of Nokia Corporation.
25 *
26 */
30 #ifndef __TESTSEMWAIT_H__
31 #define __TESTSEMWAIT_H__
33 #include <test/testexecutestepbase.h>
34 #include <errno.h>
35 #include <e32svr.h>
36 #include <stddef.h>
37 #include <limits.h>
38 #include <e32def.h>
39 #include <e32std.h>
40 #include <stdlib.h>
41 #include <errno.h>
42 #include <e32base.h>
43 #include <stdio.h>
44 #include <string.h>
45 #include <pthread.h>
46 #include <sys/time.h>
47 #include <semaphore.h>
48 #include <sys/stat.h>
49 #include <dirent.h>
50 #include <unistd.h>
51 #include <stdio.h>
52 #include <string.h>
54 _LIT(KTestSem285, "TestSem285");
55 _LIT(KTestSem286, "TestSem286");
56 _LIT(KTestSem287, "TestSem287");
57 _LIT(KTestSem288, "TestSem288");
58 _LIT(KTestSem289, "TestSem289");
59 _LIT(KTestSem290, "TestSem290");
60 _LIT(KTestSem699, "TestSem699");
63 class CTestSemwait : public CTestStep
64 {
65 public:
66 ~CTestSemwait();
67 CTestSemwait(const TDesC& aStepName);
68 TVerdict doTestStepL();
69 TVerdict doTestStepPreambleL();
70 TVerdict doTestStepPostambleL();
71 private:
72 TInt TestSem285();
73 TInt TestSem286();
74 TInt TestSem287();
75 TInt TestSem288();
76 TInt TestSem289();
77 TInt TestSem290();
78 TInt TestSem699();
80 };
81 #if 0
83 #define TRACE(n) \
84 { \
85 TBuf<255> msg; \
86 msg.Format(_L(n)); \
87 TestModuleIf().Printf( 0, _L(""),msg); \
88 }
90 #else
91 #define MSG(n)
92 #define TRACE(n)
93 #endif
95 enum ThreadCommand
96 {
97 ELastCommand,
98 EThreadCreate,
99 EThreadDestroy,
100 EVerifyResult,
101 ESetErrno,
102 EVerifyErrno,
103 ECheckValue,
105 EVerifyTimeOutOrPostSignal,
107 EStartLog,
108 EStopLog,
109 ENoOp,
111 ELoop,
113 EWaitForSignal,
114 EPostSignal,
115 EWaitTillSuspended,
117 EBusySpin,
118 EVerifySpin,
119 EVerifyNoSpin,
120 EWaitTillSpin,
121 EStopSpin,
123 ESemClose,
124 ESemDestroy,
125 ESemGetValue,
126 ESemInit,
127 ESemOpen,
128 ESemPost,
129 ESemTimedWait,
130 ESemMicroSleepWait,
131 ESemTryWait,
132 ESemUnlink,
133 ESemWait,
135 EMutexDestroy,
137 EMutexInitNULL,
138 EMutexInitDefault,
139 EMutexInitErrorCheck,
140 EMutexInitRecursive,
142 EMutexInitStaticDefault,
143 EMutexInitStaticErrorCheck,
144 EMutexInitStaticRecursive,
146 EMutexLock,
147 EMutexTimedLock,
148 EMutexTryLock,
149 EMutexUnlock,
151 EMutexAttrDestroy,
152 EMutexAttrGetType,
153 EMutexAttrGetPShared,
154 EMutexAttrSetType,
155 EMutexAttrSetPShared,
156 EMutexAttrInit,
158 EOnceInit,
159 ECallOnce,
160 EMicroSleepTime,
161 EErrno,
163 ECondBroadcast,
164 ECondDestroy,
165 ECondInit,
166 ECondInitStatic,
167 ECondSignal,
168 ECondWait,
169 ECondTimedWait,
170 ECondAttrDestroy,
171 ECondAttrInit,
173 ESem274Init,
174 ESem274Destroy,
175 ESem282,
176 ESem284B,
177 ESem697B,
178 ESem698B,
179 ESemPostAsNeeded,
180 ESem701A,
181 ESem701B,
183 EMutex330,
184 ECond403Init,
185 ECond403Destroy,
186 ECond452A,
187 ECond452B,
188 ECond453A,
189 ECond453B,
190 ECond676A,
191 ECond676B,
192 ECond677A,
193 ECond677B,
194 ECond679A,
195 ECond679B,
196 ECond680A,
197 ECond680B,
198 ECond681A,
199 ECond681B,
200 ECond683A,
201 ECond683B,
205 EPrintSuspendedStatus,
206 EFStat,
207 EStat,
208 EWStat,
209 EWriteName,
210 EWriteWName,
211 EWriteFd,
212 EStop,
213 ESemPost284
214 };
216 enum HarnessThread
217 {
218 EThread1,
219 EThread2,
220 EThread3,
221 EThread4,
222 EThread5,
223 EThreadMain,
224 ENoThread,
225 };
227 static bool g_spinFlag[EThreadMain] =
228 {
229 true,
230 true,
231 true,
232 true,
233 true
234 };
236 struct HarnessCommand
237 {
238 HarnessThread iThread;
239 ThreadCommand iAction;
240 void* iArgument;
241 };
243 class CTestModuleBase;
245 #ifdef HARNESS_LOG
246 struct HarnessBuffer
247 {
248 bool before;
249 struct HarnessCommand iCommand;
250 struct HarnessBuffer* iNext;
251 };
252 #endif
255 struct CommonData
256 {
257 pthread_mutex_t* iStaticMutex;
258 pthread_mutex_t* iErrorCheckMutex;
259 pthread_mutex_t* iRecursiveMutex;
260 pthread_cond_t* iStaticCondVar;
261 pthread_once_t iOnceControl;
263 #ifdef HARNESS_LOG
264 FILE* iFile;
265 pthread_mutex_t iFileMutex;
266 HarnessBuffer* iHead;
267 #endif
268 CommonData()
269 :iStaticMutex(NULL)
270 ,iErrorCheckMutex(NULL)
271 ,iRecursiveMutex(NULL)
272 ,iStaticCondVar(NULL)
274 #ifdef HARNESS_LOG
275 ,iHead(NULL)
276 #endif
277 {
278 #ifdef HARNESS_LOG
279 int ret;
280 iFile = fopen("C:\\Logs\\testframework\\P_Alone.txt","w");
281 if(!iFile)
282 {
283 printf("Unable to open log file!\n");
284 }
285 ret = pthread_mutex_init(&iFileMutex,NULL);
286 if(ret != 0)
287 {
288 printf("Unable to init file mutex!\n");
289 }
290 #endif
291 }
293 ~CommonData()
294 {
295 #ifdef HARNESS_LOG
296 char buff[255];
297 HarnessBuffer* node = iHead;
298 HarnessBuffer* temp;
299 while(node)
300 {
302 sprintf(buff,"thread %d command %d\n",node->iCommand.iThread,node->iCommand.iAction);
303 if(node->before)
304 {
305 if(iFile)
306 {
307 fprintf(iFile,"+");
308 }
309 }
310 else
311 {
312 if(iFile)
313 {
314 fprintf(iFile,"-");
315 }
316 }
317 if(iFile)
318 {
319 fprintf(iFile,buff);
320 }
322 temp = node;
323 node = node->iNext;
324 delete temp;
325 }
326 pthread_mutex_destroy(&iFileMutex);
327 if(iFile)
328 {
329 fclose(iFile);
330 }
331 #endif
332 }
334 };
338 struct ThreadData
339 {
340 sem_t* iSignalSemaphore;
341 sem_t* iSuspendSemaphore;
343 sem_t* iTestSemaphore;
344 pthread_mutex_t* iTestMutex;
345 pthread_mutexattr_t* iTestMutexAttr;
346 pthread_cond_t* iTestCondVar;
347 pthread_mutexattr_t* iDefaultAttr;
348 pthread_mutexattr_t* iErrorcheckAttr;
349 pthread_mutexattr_t* iRecursiveAttr;
351 pthread_condattr_t* iCondAttr;
352 bool iSuspending;
353 int iSpinCounter;
354 int iCurrentCommand;
355 HarnessThread iSelf;
356 int iValue;
357 int iRetValue;
358 int ierrno;
359 int iExpectederrno;
360 int iTimes;
361 bool iStopped;
363 CommonData* iCommonData;
364 void* iInitTwiceData;
366 ThreadData* iTDArr[EThreadMain];
367 pthread_t iIdArr[EThreadMain];
369 };
371 void* StartFn(void* arg);
374 int NewThread(ThreadData* aThreadData, HarnessThread aThreadId);
375 int DeleteThread(ThreadData* aThreadData, HarnessThread aThreadId);
377 enum TestReturn
378 {
379 KUnexpectedResult = 1,
380 KPrematureError,
381 KNoPermission,
382 KNoArgument,
383 KNotSupported,
384 KIllegalCommand,
385 KValueMismatch,
386 KNoMemory,
387 KSpinChanged,
388 KSpinNotChanged,
389 };
391 struct semParam_t
392 {
393 int pshared;
394 int value;
395 };
398 #endif