|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of 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 // e32test\thread\t_smpsafe.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #define __E32TEST_EXTENSION__ |
|
19 #include <e32test.h> |
|
20 #include <e32ldr.h> |
|
21 #include <e32svr.h> |
|
22 #include "u32std.h" |
|
23 #include <u32hal.h> |
|
24 #include <d_ldrtst.h> |
|
25 |
|
26 RTest test(_L("T_SMPSAFE")); |
|
27 RLdrTest ldd; |
|
28 |
|
29 RProcess pLoaded; |
|
30 TBool SMPPlatform; |
|
31 TBool CompatMode; |
|
32 |
|
33 extern TInt CheckAffinity(); |
|
34 |
|
35 void DoStartExe(RProcess& p, const TDesC &aFilename, TInt aExpectedUnsafe) |
|
36 { |
|
37 test_KErrNone(p.Create(aFilename, KNullDesC)); |
|
38 test_Equal(aExpectedUnsafe, ldd.ProcessSMPUnsafeCount(p.Handle())); |
|
39 } |
|
40 |
|
41 void DoStopExe(RProcess& p, TInt aExpectedUnsafe) |
|
42 { |
|
43 TRequestStatus s; |
|
44 p.Logon(s); |
|
45 p.Resume(); |
|
46 User::WaitForRequest(s); |
|
47 if (CompatMode) |
|
48 test_Equal(aExpectedUnsafe ? 1 : 0, s.Int()); |
|
49 test_Equal(EExitKill, p.ExitType()); |
|
50 p.NotifyDestruction(s); |
|
51 p.Close(); |
|
52 User::WaitForRequest(s); |
|
53 } |
|
54 |
|
55 void StartExe(const TDesC &aFilename, TInt aExpectedUnsafe) |
|
56 { |
|
57 DoStartExe(pLoaded, aFilename, aExpectedUnsafe); |
|
58 } |
|
59 |
|
60 void StopExe(TInt aExpectedUnsafe) |
|
61 { |
|
62 DoStopExe(pLoaded, aExpectedUnsafe); |
|
63 } |
|
64 |
|
65 void TryExe(const TDesC &aFilename, TInt aExpectedUnsafe) |
|
66 { |
|
67 RProcess p; |
|
68 DoStartExe(p, aFilename, aExpectedUnsafe); |
|
69 DoStopExe(p, aExpectedUnsafe); |
|
70 } |
|
71 |
|
72 void CheckSelf(TInt aExpectedUnsafe) |
|
73 { |
|
74 test_Equal(aExpectedUnsafe, ldd.ProcessSMPUnsafeCount(RProcess().Handle())); |
|
75 if (CompatMode) |
|
76 test_Equal(aExpectedUnsafe ? 1 : 0, CheckAffinity()); |
|
77 } |
|
78 |
|
79 GLDEF_C TInt E32Main() |
|
80 { |
|
81 RLibrary l, l2; |
|
82 |
|
83 // Turn off evil lazy dll unloading |
|
84 RLoader ldr; |
|
85 test(ldr.Connect()==KErrNone); |
|
86 test(ldr.CancelLazyDllUnload()==KErrNone); |
|
87 ldr.Close(); |
|
88 |
|
89 test.Title(); |
|
90 test.Start(_L("Test SMP safe binary flag")); |
|
91 |
|
92 test.Next(_L("Get number of CPUs")); |
|
93 TInt cpus = UserSvr::HalFunction(EHalGroupKernel, EKernelHalNumLogicalCpus, 0, 0); |
|
94 test_Compare(cpus, >, 0); |
|
95 SMPPlatform = cpus > 1; |
|
96 |
|
97 test.Next(_L("Get compatibility mode setting")); |
|
98 TInt flags = UserSvr::HalFunction(EHalGroupKernel, EKernelHalConfigFlags, 0, 0); |
|
99 test_Compare(flags, >=, 0); |
|
100 CompatMode = flags & (EKernelConfigSMPUnsafeCompat | EKernelConfigSMPUnsafeCPU0); |
|
101 if (SMPPlatform && !CompatMode) |
|
102 { |
|
103 test.Printf(_L("*************************************************\n")); |
|
104 test.Printf(_L("Compatibility mode is not enabled, not testing it\n")); |
|
105 test.Printf(_L("*************************************************\n")); |
|
106 } |
|
107 |
|
108 test.Next(_L("Load test LDD")); |
|
109 TInt r = User::LoadLogicalDevice(_L("d_ldrtst.ldd")); |
|
110 test(r==KErrNone || r==KErrAlreadyExists); |
|
111 test_KErrNone(ldd.Open()); |
|
112 |
|
113 test.Next(_L("Check we are safe ourselves")); |
|
114 CheckSelf(0); |
|
115 |
|
116 test.Next(_L("Check safe exe")); |
|
117 StartExe(_L("smpsafe0.exe"), 0); |
|
118 test.Next(_L("Load already loaded safe exe (self)")); |
|
119 TryExe(_L("smpsafe0.exe"), 0); |
|
120 StopExe(0); |
|
121 |
|
122 test.Next(_L("Check safe XIP exe")); |
|
123 StartExe(_L("smpsafex0.exe"), 0); |
|
124 test.Next(_L("Load already loaded safe XIP exe (self)")); |
|
125 TryExe(_L("smpsafex0.exe"), 0); |
|
126 StopExe(0); |
|
127 |
|
128 test.Next(_L("Load unsafe exe")); |
|
129 StartExe(_L("smpsafe1.exe"), 1); |
|
130 test.Next(_L("Load already loaded unsafe exe")); |
|
131 TryExe(_L("smpsafe1.exe"), 1); |
|
132 StopExe(1); |
|
133 |
|
134 test.Next(_L("Load safe exe directly linked to unsafe dll")); |
|
135 TryExe(_L("smpsafe2.exe"), 1); |
|
136 |
|
137 test.Next(_L("Dynamically load unsafe dll")); |
|
138 test_KErrNone(l.Load(_L("smpsafea.dll"))); |
|
139 CheckSelf(1); |
|
140 test.Next(_L("Load safe exe directly linked to loaded unsafe dll")); |
|
141 TryExe(_L("smpsafe2.exe"), 1); |
|
142 test.Next(_L("Dynamically unload unsafe dll")); |
|
143 l.Close(); |
|
144 CheckSelf(0); |
|
145 |
|
146 test.Next(_L("Load safe XIP exe directly linked to unsafe XIP dll")); |
|
147 TryExe(_L("smpsafex2.exe"), 1); |
|
148 |
|
149 test.Next(_L("Dynamically load unsafe XIP dll")); |
|
150 test_KErrNone(l.Load(_L("smpsafexa.dll"))); |
|
151 CheckSelf(1); |
|
152 test.Next(_L("Load safe XIP exe directly linked to loaded unsafe XIP dll")); |
|
153 TryExe(_L("smpsafex2.exe"), 1); |
|
154 test.Next(_L("Dynamically unload unsafe XIP dll")); |
|
155 l.Close(); |
|
156 CheckSelf(0); |
|
157 |
|
158 test.Next(_L("Load safe exe indirectly linked to unsafe dll")); |
|
159 TryExe(_L("smpsafe3.exe"), 1); |
|
160 |
|
161 test.Next(_L("Dynamically load unsafe dll")); |
|
162 test_KErrNone(l.Load(_L("smpsafea.dll"))); |
|
163 CheckSelf(1); |
|
164 test.Next(_L("Load safe exe indirectly linked to loaded unsafe dll")); |
|
165 TryExe(_L("smpsafe3.exe"), 1); |
|
166 test.Next(_L("Dynamically unload unsafe dll")); |
|
167 l.Close(); |
|
168 CheckSelf(0); |
|
169 |
|
170 test.Next(_L("Dynamically load safe dll linked to unsafe dll")); |
|
171 test_KErrNone(l.Load(_L("smpsafeb.dll"))); |
|
172 CheckSelf(1); |
|
173 test.Next(_L("Load safe exe indirectly linked to unsafe dll, inbetween loaded")); |
|
174 TryExe(_L("smpsafe3.exe"), 1); |
|
175 test.Next(_L("Dynamically load unsafe dll as well")); |
|
176 test_KErrNone(l2.Load(_L("smpsafea.dll"))); |
|
177 CheckSelf(2); |
|
178 test.Next(_L("Dynamically unload safe dll linked to unsafe dll")); |
|
179 l.Close(); |
|
180 CheckSelf(1); |
|
181 test.Next(_L("Dynamically unload unsafe dll as well")); |
|
182 l2.Close(); |
|
183 CheckSelf(0); |
|
184 |
|
185 test.Next(_L("Load safe exe directly linked to unsafe XIP dll")); |
|
186 TryExe(_L("smpsafe4.exe"), 1); |
|
187 |
|
188 test.Next(_L("Dynamically load unsafe XIP dll")); |
|
189 test_KErrNone(l.Load(_L("smpsafexa.dll"))); |
|
190 CheckSelf(1); |
|
191 test.Next(_L("Load safe exe directly linked to loaded unsafe XIP dll")); |
|
192 TryExe(_L("smpsafe4.exe"), 1); |
|
193 test.Next(_L("Dynamically unload unsafe XIP dll")); |
|
194 l.Close(); |
|
195 CheckSelf(0); |
|
196 |
|
197 test.Next(_L("Dynamically load figure-eight dll cycle")); |
|
198 test_KErrNone(l.Load(_L("smpsafec.dll"))); |
|
199 CheckSelf(1); |
|
200 test.Next(_L("Load figure-eight from a different point")); |
|
201 test_KErrNone(l2.Load(_L("smpsafed.dll"))); |
|
202 CheckSelf(2); |
|
203 test.Next(_L("Unload original point")); |
|
204 l.Close(); |
|
205 CheckSelf(1); |
|
206 test.Next(_L("Unload second point")); |
|
207 l2.Close(); |
|
208 CheckSelf(0); |
|
209 |
|
210 test.Next(_L("Close test LDD")); |
|
211 ldd.Close(); |
|
212 test_KErrNone(User::FreeLogicalDevice(KLdrTestLddName)); |
|
213 |
|
214 test.End(); |
|
215 return KErrNone; |
|
216 } |