|
1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <e32test.h> |
|
17 #include "t_framework.h" |
|
18 |
|
19 RTest test(RProcess().FileName()); |
|
20 |
|
21 CTestProgram::CTestProgram(const TDesC& aName) : iName(aName) |
|
22 { |
|
23 iThreadId = RThread().Id(); |
|
24 } |
|
25 |
|
26 void CTestProgram::Panic() |
|
27 { |
|
28 TPtrC8 fd((TUint8*)iFile); |
|
29 TPtrC8 cd((TUint8*)iCond); |
|
30 |
|
31 HBufC* fhb = HBufC::NewMax(fd.Length()); |
|
32 test(fhb != 0); |
|
33 HBufC* chb = HBufC::NewMax(cd.Length()); |
|
34 test(chb != 0); |
|
35 |
|
36 fhb->Des().Copy(fd); |
|
37 chb->Des().Copy(cd); |
|
38 |
|
39 test.Panic(iError, _L("Test '%S' Fails;\nCond: '%S'; File: '%S'; Line %d;\n"), &iName, chb, fhb, iLine); |
|
40 } |
|
41 |
|
42 void CTestProgram::Panic(TInt aError, char* aCond, char* aFile, TInt aLine) |
|
43 { |
|
44 iError = aError; |
|
45 iCond = aCond; |
|
46 iFile = aFile; |
|
47 iLine = aLine; |
|
48 if (iThreadId != RThread().Id()) |
|
49 { |
|
50 RThread thr; |
|
51 thr.Panic(_L("FAIL"), aError); |
|
52 } |
|
53 Panic(); |
|
54 } |
|
55 |
|
56 void CTestProgram::Launch(TUint aCount) |
|
57 { |
|
58 // Remember the number of open handles. Just for a sanity check .... |
|
59 TInt start_thc, start_phc; |
|
60 RThread().HandleCount(start_phc, start_thc); |
|
61 TF_ERROR(RThread().RequestCount(), RThread().RequestCount() == 0); |
|
62 |
|
63 test.Next(iName); |
|
64 Run(aCount); |
|
65 |
|
66 // Sanity check for open handles |
|
67 TInt end_thc, end_phc; |
|
68 RThread().HandleCount(end_phc, end_thc); |
|
69 TF_ERROR(end_thc - start_thc, start_thc == end_thc); |
|
70 TF_ERROR(end_phc - start_phc, start_phc == end_phc); |
|
71 // and also for pending requests ... |
|
72 TF_ERROR(RThread().RequestCount(), RThread().RequestCount() == 0); |
|
73 } |
|
74 |
|
75 void CTestProgram::LaunchGroup(CTestProgram** aGroup, TUint aCount) |
|
76 { |
|
77 for (CTestProgram** progP = aGroup; *progP; ++progP) |
|
78 { |
|
79 CTestProgram* prog = *progP; |
|
80 prog->Launch(aCount); |
|
81 } |
|
82 } |
|
83 |
|
84 TInt CTestProgram::ThreadEntry(TAny* a) |
|
85 { |
|
86 CTestProgram* prog = (CTestProgram*) a; |
|
87 prog->Run(prog->iCount); |
|
88 return KErrNone; |
|
89 } |
|
90 |
|
91 void CTestProgram::Spawn(TUint aCount) |
|
92 { |
|
93 test.Next(iName); |
|
94 iCount = aCount; |
|
95 iStatus = KRequestPending; |
|
96 RThread thr; |
|
97 TInt r = thr.Create(KNullDesC, ThreadEntry, 0x2000, NULL, this); |
|
98 TF_ERROR(r, r == KErrNone); |
|
99 thr.NotifyDestruction(iDestroyStatus); |
|
100 thr.Logon(iStatus); |
|
101 thr.Resume(); |
|
102 thr.Close(); |
|
103 } |
|
104 |
|
105 void CTestProgram::Wait() |
|
106 { |
|
107 User::WaitForRequest(iStatus); |
|
108 if (iStatus.Int() != KErrNone) |
|
109 { |
|
110 Panic(); |
|
111 } |
|
112 User::WaitForRequest(iDestroyStatus); |
|
113 if (iDestroyStatus.Int() != KErrNone) |
|
114 { |
|
115 Panic(); |
|
116 } |
|
117 } |
|
118 |
|
119 void CTestProgram::SpawnGroup(CTestProgram** aGroup, TUint aCount) |
|
120 { |
|
121 test.Start(_L("=== Start Parallel Testing ===")); |
|
122 CTestProgram** progP; |
|
123 for (progP = aGroup; *progP; ++progP) |
|
124 { |
|
125 CTestProgram* prog = *progP; |
|
126 prog->Spawn(aCount); |
|
127 } |
|
128 for (progP = aGroup; *progP; ++progP) |
|
129 { |
|
130 CTestProgram* prog = *progP; |
|
131 prog->Wait(); |
|
132 } |
|
133 test.Next(_L("=== End Parallel Testing ===")); |
|
134 test.End(); |
|
135 } |
|
136 |
|
137 void CTestProgram::Exec(const TDesC& aFile, TAny* args, TInt size) |
|
138 { |
|
139 // |
|
140 // Create the child process and pass args as a UNICODE command line. |
|
141 // (we suppose that the args size is multiple of sizeof(TUint16)) |
|
142 // |
|
143 RProcess proc; |
|
144 TInt r = proc.Create(aFile, TPtrC((TUint16*) args, size/sizeof(TUint16))); |
|
145 TF_ERROR(r, r == KErrNone); |
|
146 TRequestStatus status; |
|
147 proc.Logon(status); |
|
148 proc.Resume(); |
|
149 User::WaitForRequest(status); |
|
150 TF_ERROR(status.Int(), status.Int() == KErrNone); |
|
151 proc.Close(); |
|
152 } |
|
153 |
|
154 void CTestProgram::Start() |
|
155 { |
|
156 test.Title(); |
|
157 test.Start(_L("GO!")); |
|
158 } |
|
159 |
|
160 void CTestProgram::End() |
|
161 { |
|
162 test.End(); |
|
163 } |