0
|
1 |
// Copyright (c) 1997-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\pccd\t_pccd3.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include <e32test.h>
|
|
19 |
#include <e32svr.h>
|
|
20 |
#include <e32hal.h>
|
|
21 |
#include <e32uid.h>
|
|
22 |
#include <d_pccdif.h>
|
|
23 |
#include <hal.h>
|
|
24 |
#define TEST_NOTIFIER
|
|
25 |
|
|
26 |
LOCAL_D RTest test(_L("T_PCCD3"));
|
|
27 |
LOCAL_D TBool SimpleCDScheme;
|
|
28 |
LOCAL_D TInt TotalSockets;
|
|
29 |
LOCAL_D RPcCardCntrlIf PccdDrv[KMaxPBusSockets];
|
|
30 |
|
|
31 |
const TSocket KSocket=0;
|
|
32 |
const TInt KFunc=0;
|
|
33 |
|
|
34 |
|
|
35 |
#ifdef TEST_NOTIFIER
|
|
36 |
LOCAL_C void theMediaChangeNotifierTests()
|
|
37 |
//
|
|
38 |
// Test UserSvr::MediaChangeNotify() and UserSvr::ForceRemountMedia().
|
|
39 |
//
|
|
40 |
{
|
|
41 |
|
|
42 |
test.Next(_L("The media change notifier(s)"));
|
|
43 |
|
|
44 |
// Test requesting on a non-removable device
|
|
45 |
TRequestStatus rs[KMaxPBusSockets];
|
|
46 |
test(UserSvr::MediaChangeNotify(EFixedMedia0,&rs[0])==KErrNotSupported);
|
|
47 |
|
|
48 |
#ifndef _DEBUG
|
|
49 |
test(UserSvr::MediaChangeNotify(ERemovableMedia0,&rs[0])==KErrInUse);
|
|
50 |
#else
|
|
51 |
test.Printf( _L("<<<THIS WILL BREAK F32 MEDIA CHANGE NOTIFICATION>>>\r\n"));
|
|
52 |
TInt socket;
|
|
53 |
TMediaDevice md;
|
|
54 |
for (socket=0;socket<TotalSockets;socket++)
|
|
55 |
{
|
|
56 |
// Register the notifier on all sockets here - out of the main loop to
|
|
57 |
// test operation with multiple outstanding requests on different sockets
|
|
58 |
md=(TMediaDevice)(ERemovableMedia0+socket);
|
|
59 |
test(UserSvr::MediaChangeNotify(md,&rs[socket])==KErrNone);
|
|
60 |
}
|
|
61 |
|
|
62 |
for (socket=0;socket<TotalSockets;socket++)
|
|
63 |
{
|
|
64 |
md=(TMediaDevice)(ERemovableMedia0+socket);
|
|
65 |
// Perform the entire test twice
|
|
66 |
for (TInt cycleCount=1;cycleCount<=2;cycleCount++)
|
|
67 |
{
|
|
68 |
if (cycleCount>1)
|
|
69 |
{
|
|
70 |
// Second time around we need to make a request
|
|
71 |
test(UserSvr::MediaChangeNotify(md,&rs[socket])==KErrNone);
|
|
72 |
}
|
|
73 |
UserSvr::ForceRemountMedia(md); // Generate media change
|
|
74 |
User::WaitForRequest(rs[socket]); // From door open
|
|
75 |
test(rs[socket].Int()==KErrNone);
|
|
76 |
test.Printf( _L("Media change notify on Socket %d\r\n"),socket);
|
|
77 |
if (!SimpleCDScheme)
|
|
78 |
{
|
|
79 |
// For CD scheme, the open/close occur too close together to
|
|
80 |
// detect separately
|
|
81 |
test(UserSvr::MediaChangeNotify(md,&rs[socket])==KErrNone);
|
|
82 |
User::WaitForRequest(rs[socket]); // From door close again
|
|
83 |
test(rs[socket].Int()==KErrNone);
|
|
84 |
test.Printf( _L("Media change notify on Socket %d\r\n"),socket);
|
|
85 |
}
|
|
86 |
}
|
|
87 |
}
|
|
88 |
|
|
89 |
// Test requesting on an invalid socket for this platform
|
|
90 |
if (TotalSockets<KMaxPBusSockets)
|
|
91 |
test(UserSvr::MediaChangeNotify((TMediaDevice)(ERemovableMedia0+TotalSockets),&rs[0])==KErrGeneral);
|
|
92 |
#endif
|
|
93 |
}
|
|
94 |
|
|
95 |
#else
|
|
96 |
LOCAL_C void theMediaChangeNotifierTests()
|
|
97 |
//
|
|
98 |
// Test UserSvr::MediaChangeNotify() and UserSvr::ForceRemountMedia().
|
|
99 |
//
|
|
100 |
{
|
|
101 |
|
|
102 |
test.Next(_L("The media change notifier(s)"));
|
|
103 |
|
|
104 |
// Test requesting on a non-removable device
|
|
105 |
TRequestStatus rs;
|
|
106 |
test(UserSvr::MediaChangeNotify(EFixedMedia0,&rs)==KErrNotSupported);
|
|
107 |
|
|
108 |
#ifndef _DEBUG
|
|
109 |
test(UserSvr::MediaChangeNotify(ERemovableMedia0,&rs)==KErrInUse);
|
|
110 |
#else
|
|
111 |
test.Printf( _L("<<<MEDIA CHANGE NOTIFICATION TESTS DISABLED>>>\r\n"),i);
|
|
112 |
#endif
|
|
113 |
}
|
|
114 |
#endif
|
|
115 |
|
|
116 |
LOCAL_C void thePccdControllerMediaChangeEventTests()
|
|
117 |
//
|
|
118 |
// Test registering on media change events
|
|
119 |
//
|
|
120 |
{
|
|
121 |
|
|
122 |
test.Next(_L("PC Card Controller - Media change notification"));
|
|
123 |
if (SimpleCDScheme)
|
|
124 |
{
|
|
125 |
TRequestStatus rs[KMaxPBusSockets];
|
|
126 |
TInt i;
|
|
127 |
for (i=0;i<TotalSockets;i++)
|
|
128 |
test(PccdDrv[i].RegisterEvent(EPcCardEvMediaChange,&rs[i])==KErrNone);
|
|
129 |
|
|
130 |
for (i=0;i<TotalSockets;i++)
|
|
131 |
{
|
|
132 |
test.Printf( _L("<<<Insert the card in socket %d >>>\r\n"),i);
|
|
133 |
User::WaitForRequest(rs[i]);
|
|
134 |
test(rs[i].Int()==KErrNone);
|
|
135 |
}
|
|
136 |
}
|
|
137 |
|
|
138 |
else
|
|
139 |
{
|
|
140 |
TRequestStatus rs;
|
|
141 |
test(PccdDrv[0].RegisterEvent(EPcCardEvMediaChange,&rs)==KErrNone);
|
|
142 |
|
|
143 |
#if defined (__WINS__)
|
|
144 |
test.Printf( _L("<<<Hit F5>>>\r\n"));
|
|
145 |
#else
|
|
146 |
test.Printf( _L("<<<Open and close CF card door>>>\r\n"));
|
|
147 |
test.Printf( _L("<<<Machine will turn off as soon as door is opened>>>\r\n"));
|
|
148 |
#endif
|
|
149 |
User::WaitForRequest(rs);
|
|
150 |
test(rs.Int()==KErrNone);
|
|
151 |
#if defined (__WINS__)
|
|
152 |
// Delay power off until after F5 key up event. Key up doesn't occur when in standby.
|
|
153 |
// Without this the power-on test fails because the simulated door state is stuck open.
|
|
154 |
User::After(500000);
|
|
155 |
#endif
|
|
156 |
}
|
|
157 |
}
|
|
158 |
|
|
159 |
LOCAL_C void thePccdControllerPowerEventTests()
|
|
160 |
//
|
|
161 |
// Test registering on power events
|
|
162 |
//
|
|
163 |
{
|
|
164 |
|
|
165 |
test.Next(_L("PC Card Controller - Power-off notification."));
|
|
166 |
RTimer timer;
|
|
167 |
TRequestStatus prs, trs;
|
|
168 |
test(timer.CreateLocal()==KErrNone);
|
|
169 |
test(PccdDrv[0].RegisterEvent(EPcCardEvPwrDown,&prs)==KErrNone);
|
|
170 |
TTime tim;
|
|
171 |
tim.HomeTime();
|
|
172 |
tim+=TTimeIntervalSeconds(8);
|
|
173 |
timer.At(trs,tim);
|
|
174 |
UserHal::SwitchOff();
|
|
175 |
User::WaitForRequest(prs);
|
|
176 |
test(prs.Int()==KErrNone);
|
|
177 |
User::WaitForRequest(trs);
|
|
178 |
test(trs.Int()==KErrNone);
|
|
179 |
|
|
180 |
test.Next(_L("PC Card Controller - Power-on notification."));
|
|
181 |
test(PccdDrv[0].RegisterEvent(EPcCardEvPwrUp,&prs)==KErrNone);
|
|
182 |
tim.HomeTime();
|
|
183 |
tim+=TTimeIntervalSeconds(8);
|
|
184 |
timer.At(trs,tim);
|
|
185 |
UserHal::SwitchOff();
|
|
186 |
User::WaitForRequest(prs);
|
|
187 |
test(prs.Int()==KErrNone);
|
|
188 |
User::WaitForRequest(trs);
|
|
189 |
test(trs.Int()==KErrNone);
|
|
190 |
}
|
|
191 |
|
|
192 |
LOCAL_C void thePccdControllerStatusChangeEventTests()
|
|
193 |
//
|
|
194 |
// Test registering on status change events
|
|
195 |
//
|
|
196 |
{
|
|
197 |
|
|
198 |
TRequestStatus rs;
|
|
199 |
if (!SimpleCDScheme)
|
|
200 |
{
|
|
201 |
// We're going to ask tester to remove CF card in order to generate a card status change
|
|
202 |
// notification. However, on P2s this involves opening the CF card door first. Because of
|
|
203 |
// the media notifier (F32), opening door gives us a spurious RegisterEvent() notification.
|
|
204 |
test.Printf( _L("<<<Open (don't close) media door>>>\r\n"));
|
|
205 |
test(PccdDrv[0].RegisterEvent(EPcCardEvMediaChange,&rs)==KErrNone);
|
|
206 |
User::WaitForRequest(rs);
|
|
207 |
test(rs.Int()==KErrNone);
|
|
208 |
}
|
|
209 |
|
|
210 |
TInt i;
|
|
211 |
for (i=(TotalSockets-1);i>=0;i--)
|
|
212 |
{
|
|
213 |
test.Next(_L("Card status change notification - card removal"));
|
|
214 |
test(PccdDrv[i].RegisterEvent(EPcCardEvIndChange,&rs)==KErrNone);
|
|
215 |
test.Printf( _L("<<<Remove the card from socket %d>>>\r\n"),i);
|
|
216 |
User::WaitForRequest(rs);
|
|
217 |
test(rs.Int()==KErrNone);
|
|
218 |
|
|
219 |
test.Next(_L("Card status change notification - card insertion"));
|
|
220 |
User::After(200000); // 0.2s
|
|
221 |
TInt j=(i>0)?(i-1):i;
|
|
222 |
test(PccdDrv[j].RegisterEvent(EPcCardEvIndChange,&rs)==KErrNone);
|
|
223 |
test.Printf( _L("<<<Insert the card back into socket %d>>>\r\n"),j);
|
|
224 |
User::WaitForRequest(rs);
|
|
225 |
test(rs.Int()==KErrNone);
|
|
226 |
}
|
|
227 |
|
|
228 |
if (!SimpleCDScheme)
|
|
229 |
{
|
|
230 |
test.Printf( _L("<<<Close) CF card door>>>\r\n"));
|
|
231 |
test(PccdDrv[0].RegisterEvent(EPcCardEvPwrUp,&rs)==KErrNone);
|
|
232 |
User::WaitForRequest(rs);
|
|
233 |
test(rs.Int()==KErrNone);
|
|
234 |
}
|
|
235 |
}
|
|
236 |
|
|
237 |
LOCAL_C void thePccdControllerCardReadyEventTests()
|
|
238 |
//
|
|
239 |
// Test registering on ready events (tests 1 socket only!!!!).
|
|
240 |
//
|
|
241 |
{
|
|
242 |
|
|
243 |
test.Next(_L("Card ready notification"));
|
|
244 |
TRequestStatus rs;
|
|
245 |
TInt r;
|
|
246 |
r=PccdDrv[0].RegisterEvent(EPcCardEvRdyChange,&rs);
|
|
247 |
if (r==KErrNotSupported)
|
|
248 |
{
|
|
249 |
test.Printf( _L("<<<Not supported on this platform>>>\r\n"));
|
|
250 |
return;
|
|
251 |
}
|
|
252 |
test(r==KErrNone);
|
|
253 |
|
|
254 |
TPcCardStatus s;
|
|
255 |
TSocketSignals ind;
|
|
256 |
test(PccdDrv[0].SocketInfo(s,ind)==KErrNone);
|
|
257 |
test(s==EPcCardNotReady);
|
|
258 |
test(ind.iCardDetected);
|
|
259 |
|
|
260 |
TRequestStatus prs;
|
|
261 |
PccdDrv[0].PwrUp(&prs);
|
|
262 |
User::WaitForRequest(rs);
|
|
263 |
test(rs.Int()==KErrNone);
|
|
264 |
User::WaitForRequest(prs);
|
|
265 |
test(rs.Int()==KErrNone);
|
|
266 |
}
|
|
267 |
|
|
268 |
GLDEF_C TInt E32Main()
|
|
269 |
{
|
|
270 |
|
|
271 |
TInt r;
|
|
272 |
#if defined (__WINS__)
|
|
273 |
// Connect to all the local drives first as will be the case in ARM
|
|
274 |
TBusLocalDrive Drive[KMaxLocalDrives];
|
|
275 |
TBool ChangedFlag[KMaxLocalDrives];
|
|
276 |
TInt j;
|
|
277 |
for (j=0;j<KMaxLocalDrives;j++)
|
|
278 |
Drive[j].Connect(j,ChangedFlag[j]);
|
|
279 |
#endif
|
|
280 |
|
|
281 |
test.Title();
|
|
282 |
//
|
|
283 |
test.Start(_L("Read machine info."));
|
|
284 |
// Find out what sort of media change architecture we have. How many sockets
|
|
285 |
// there are and whether we have a full blown media door scheme or just a system
|
|
286 |
// using the PC Card CD signals. The later information we can't read from the
|
|
287 |
// machine info, the test program just has to be updated with the machine name of
|
|
288 |
// any machine which employs the CD scheme.
|
|
289 |
SimpleCDScheme=EFalse;
|
|
290 |
TInt muid=0;
|
|
291 |
r=HAL::Get(HAL::EMachineUid, muid);
|
|
292 |
test(r==KErrNone);
|
|
293 |
if (muid==HAL::EMachineUid_Brutus)
|
|
294 |
SimpleCDScheme=ETrue;
|
|
295 |
TDriveInfoV1Buf dinfo;
|
|
296 |
UserHal::DriveInfo(dinfo);
|
|
297 |
TotalSockets=dinfo().iTotalSockets;
|
|
298 |
|
|
299 |
if (SimpleCDScheme)
|
|
300 |
test.Printf( _L("<<<Remove all PC/CF cards - hit a key>>>\r\n"));
|
|
301 |
else
|
|
302 |
{
|
|
303 |
if (TotalSockets>0)
|
|
304 |
test.Printf( _L("<<<Insert the card in socket %d - hit a key>>>\r\n"),(TotalSockets-1));
|
|
305 |
}
|
|
306 |
test.Getch();
|
|
307 |
|
|
308 |
test.Next(_L("Load/open logical devices"));
|
|
309 |
r=User::LoadLogicalDevice(_L("D_PCCDIF"));
|
|
310 |
test(r==KErrNone||r==KErrAlreadyExists);
|
|
311 |
TInt i;
|
|
312 |
for (i=0;i<TotalSockets;i++)
|
|
313 |
{
|
|
314 |
r=PccdDrv[i].Open(i,PccdDrv[i].VersionRequired());
|
|
315 |
test(r==KErrNone);
|
|
316 |
}
|
|
317 |
|
|
318 |
// Test UserSvr::MediaChangeNotify() and UserSvr::ForceRemountMedia().
|
|
319 |
theMediaChangeNotifierTests();
|
|
320 |
|
|
321 |
// Test registering on PC Card Controller events
|
|
322 |
thePccdControllerMediaChangeEventTests();
|
|
323 |
thePccdControllerPowerEventTests();
|
|
324 |
#if defined(__EPOC32__)
|
|
325 |
thePccdControllerStatusChangeEventTests();
|
|
326 |
thePccdControllerCardReadyEventTests();
|
|
327 |
#endif
|
|
328 |
|
|
329 |
test.Next(_L("Close/free devices"));
|
|
330 |
for (i=0;i<TotalSockets;i++)
|
|
331 |
PccdDrv[i].Close();
|
|
332 |
r=User::FreeLogicalDevice(_L("PccdIf"));
|
|
333 |
test(r==KErrNone);
|
|
334 |
|
|
335 |
test.End();
|
|
336 |
|
|
337 |
#if defined (__WINS__)
|
|
338 |
for (i=0;i<KMaxLocalDrives;i++)
|
|
339 |
Drive[i].Disconnect();
|
|
340 |
#endif
|
|
341 |
return(0);
|
|
342 |
}
|
|
343 |
|