1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/pccd/t_pccd3.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,343 @@
1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\pccd\t_pccd3.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32test.h>
1.22 +#include <e32svr.h>
1.23 +#include <e32hal.h>
1.24 +#include <e32uid.h>
1.25 +#include <d_pccdif.h>
1.26 +#include <hal.h>
1.27 +#define TEST_NOTIFIER
1.28 +
1.29 +LOCAL_D RTest test(_L("T_PCCD3"));
1.30 +LOCAL_D TBool SimpleCDScheme;
1.31 +LOCAL_D TInt TotalSockets;
1.32 +LOCAL_D RPcCardCntrlIf PccdDrv[KMaxPBusSockets];
1.33 +
1.34 +const TSocket KSocket=0;
1.35 +const TInt KFunc=0;
1.36 +
1.37 +
1.38 +#ifdef TEST_NOTIFIER
1.39 +LOCAL_C void theMediaChangeNotifierTests()
1.40 +//
1.41 +// Test UserSvr::MediaChangeNotify() and UserSvr::ForceRemountMedia().
1.42 +//
1.43 + {
1.44 +
1.45 + test.Next(_L("The media change notifier(s)"));
1.46 +
1.47 + // Test requesting on a non-removable device
1.48 + TRequestStatus rs[KMaxPBusSockets];
1.49 + test(UserSvr::MediaChangeNotify(EFixedMedia0,&rs[0])==KErrNotSupported);
1.50 +
1.51 +#ifndef _DEBUG
1.52 + test(UserSvr::MediaChangeNotify(ERemovableMedia0,&rs[0])==KErrInUse);
1.53 +#else
1.54 + test.Printf( _L("<<<THIS WILL BREAK F32 MEDIA CHANGE NOTIFICATION>>>\r\n"));
1.55 + TInt socket;
1.56 + TMediaDevice md;
1.57 + for (socket=0;socket<TotalSockets;socket++)
1.58 + {
1.59 + // Register the notifier on all sockets here - out of the main loop to
1.60 + // test operation with multiple outstanding requests on different sockets
1.61 + md=(TMediaDevice)(ERemovableMedia0+socket);
1.62 + test(UserSvr::MediaChangeNotify(md,&rs[socket])==KErrNone);
1.63 + }
1.64 +
1.65 + for (socket=0;socket<TotalSockets;socket++)
1.66 + {
1.67 + md=(TMediaDevice)(ERemovableMedia0+socket);
1.68 + // Perform the entire test twice
1.69 + for (TInt cycleCount=1;cycleCount<=2;cycleCount++)
1.70 + {
1.71 + if (cycleCount>1)
1.72 + {
1.73 + // Second time around we need to make a request
1.74 + test(UserSvr::MediaChangeNotify(md,&rs[socket])==KErrNone);
1.75 + }
1.76 + UserSvr::ForceRemountMedia(md); // Generate media change
1.77 + User::WaitForRequest(rs[socket]); // From door open
1.78 + test(rs[socket].Int()==KErrNone);
1.79 + test.Printf( _L("Media change notify on Socket %d\r\n"),socket);
1.80 + if (!SimpleCDScheme)
1.81 + {
1.82 + // For CD scheme, the open/close occur too close together to
1.83 + // detect separately
1.84 + test(UserSvr::MediaChangeNotify(md,&rs[socket])==KErrNone);
1.85 + User::WaitForRequest(rs[socket]); // From door close again
1.86 + test(rs[socket].Int()==KErrNone);
1.87 + test.Printf( _L("Media change notify on Socket %d\r\n"),socket);
1.88 + }
1.89 + }
1.90 + }
1.91 +
1.92 + // Test requesting on an invalid socket for this platform
1.93 + if (TotalSockets<KMaxPBusSockets)
1.94 + test(UserSvr::MediaChangeNotify((TMediaDevice)(ERemovableMedia0+TotalSockets),&rs[0])==KErrGeneral);
1.95 + #endif
1.96 + }
1.97 +
1.98 +#else
1.99 +LOCAL_C void theMediaChangeNotifierTests()
1.100 +//
1.101 +// Test UserSvr::MediaChangeNotify() and UserSvr::ForceRemountMedia().
1.102 +//
1.103 + {
1.104 +
1.105 + test.Next(_L("The media change notifier(s)"));
1.106 +
1.107 + // Test requesting on a non-removable device
1.108 + TRequestStatus rs;
1.109 + test(UserSvr::MediaChangeNotify(EFixedMedia0,&rs)==KErrNotSupported);
1.110 +
1.111 +#ifndef _DEBUG
1.112 + test(UserSvr::MediaChangeNotify(ERemovableMedia0,&rs)==KErrInUse);
1.113 +#else
1.114 + test.Printf( _L("<<<MEDIA CHANGE NOTIFICATION TESTS DISABLED>>>\r\n"),i);
1.115 +#endif
1.116 + }
1.117 +#endif
1.118 +
1.119 +LOCAL_C void thePccdControllerMediaChangeEventTests()
1.120 +//
1.121 +// Test registering on media change events
1.122 +//
1.123 + {
1.124 +
1.125 + test.Next(_L("PC Card Controller - Media change notification"));
1.126 + if (SimpleCDScheme)
1.127 + {
1.128 + TRequestStatus rs[KMaxPBusSockets];
1.129 + TInt i;
1.130 + for (i=0;i<TotalSockets;i++)
1.131 + test(PccdDrv[i].RegisterEvent(EPcCardEvMediaChange,&rs[i])==KErrNone);
1.132 +
1.133 + for (i=0;i<TotalSockets;i++)
1.134 + {
1.135 + test.Printf( _L("<<<Insert the card in socket %d >>>\r\n"),i);
1.136 + User::WaitForRequest(rs[i]);
1.137 + test(rs[i].Int()==KErrNone);
1.138 + }
1.139 + }
1.140 +
1.141 + else
1.142 + {
1.143 + TRequestStatus rs;
1.144 + test(PccdDrv[0].RegisterEvent(EPcCardEvMediaChange,&rs)==KErrNone);
1.145 +
1.146 +#if defined (__WINS__)
1.147 + test.Printf( _L("<<<Hit F5>>>\r\n"));
1.148 +#else
1.149 + test.Printf( _L("<<<Open and close CF card door>>>\r\n"));
1.150 + test.Printf( _L("<<<Machine will turn off as soon as door is opened>>>\r\n"));
1.151 +#endif
1.152 + User::WaitForRequest(rs);
1.153 + test(rs.Int()==KErrNone);
1.154 +#if defined (__WINS__)
1.155 + // Delay power off until after F5 key up event. Key up doesn't occur when in standby.
1.156 + // Without this the power-on test fails because the simulated door state is stuck open.
1.157 + User::After(500000);
1.158 +#endif
1.159 + }
1.160 + }
1.161 +
1.162 +LOCAL_C void thePccdControllerPowerEventTests()
1.163 +//
1.164 +// Test registering on power events
1.165 +//
1.166 + {
1.167 +
1.168 + test.Next(_L("PC Card Controller - Power-off notification."));
1.169 + RTimer timer;
1.170 + TRequestStatus prs, trs;
1.171 + test(timer.CreateLocal()==KErrNone);
1.172 + test(PccdDrv[0].RegisterEvent(EPcCardEvPwrDown,&prs)==KErrNone);
1.173 + TTime tim;
1.174 + tim.HomeTime();
1.175 + tim+=TTimeIntervalSeconds(8);
1.176 + timer.At(trs,tim);
1.177 + UserHal::SwitchOff();
1.178 + User::WaitForRequest(prs);
1.179 + test(prs.Int()==KErrNone);
1.180 + User::WaitForRequest(trs);
1.181 + test(trs.Int()==KErrNone);
1.182 +
1.183 + test.Next(_L("PC Card Controller - Power-on notification."));
1.184 + test(PccdDrv[0].RegisterEvent(EPcCardEvPwrUp,&prs)==KErrNone);
1.185 + tim.HomeTime();
1.186 + tim+=TTimeIntervalSeconds(8);
1.187 + timer.At(trs,tim);
1.188 + UserHal::SwitchOff();
1.189 + User::WaitForRequest(prs);
1.190 + test(prs.Int()==KErrNone);
1.191 + User::WaitForRequest(trs);
1.192 + test(trs.Int()==KErrNone);
1.193 + }
1.194 +
1.195 +LOCAL_C void thePccdControllerStatusChangeEventTests()
1.196 +//
1.197 +// Test registering on status change events
1.198 +//
1.199 + {
1.200 +
1.201 + TRequestStatus rs;
1.202 + if (!SimpleCDScheme)
1.203 + {
1.204 + // We're going to ask tester to remove CF card in order to generate a card status change
1.205 + // notification. However, on P2s this involves opening the CF card door first. Because of
1.206 + // the media notifier (F32), opening door gives us a spurious RegisterEvent() notification.
1.207 + test.Printf( _L("<<<Open (don't close) media door>>>\r\n"));
1.208 + test(PccdDrv[0].RegisterEvent(EPcCardEvMediaChange,&rs)==KErrNone);
1.209 + User::WaitForRequest(rs);
1.210 + test(rs.Int()==KErrNone);
1.211 + }
1.212 +
1.213 + TInt i;
1.214 + for (i=(TotalSockets-1);i>=0;i--)
1.215 + {
1.216 + test.Next(_L("Card status change notification - card removal"));
1.217 + test(PccdDrv[i].RegisterEvent(EPcCardEvIndChange,&rs)==KErrNone);
1.218 + test.Printf( _L("<<<Remove the card from socket %d>>>\r\n"),i);
1.219 + User::WaitForRequest(rs);
1.220 + test(rs.Int()==KErrNone);
1.221 +
1.222 + test.Next(_L("Card status change notification - card insertion"));
1.223 + User::After(200000); // 0.2s
1.224 + TInt j=(i>0)?(i-1):i;
1.225 + test(PccdDrv[j].RegisterEvent(EPcCardEvIndChange,&rs)==KErrNone);
1.226 + test.Printf( _L("<<<Insert the card back into socket %d>>>\r\n"),j);
1.227 + User::WaitForRequest(rs);
1.228 + test(rs.Int()==KErrNone);
1.229 + }
1.230 +
1.231 + if (!SimpleCDScheme)
1.232 + {
1.233 + test.Printf( _L("<<<Close) CF card door>>>\r\n"));
1.234 + test(PccdDrv[0].RegisterEvent(EPcCardEvPwrUp,&rs)==KErrNone);
1.235 + User::WaitForRequest(rs);
1.236 + test(rs.Int()==KErrNone);
1.237 + }
1.238 + }
1.239 +
1.240 +LOCAL_C void thePccdControllerCardReadyEventTests()
1.241 +//
1.242 +// Test registering on ready events (tests 1 socket only!!!!).
1.243 +//
1.244 + {
1.245 +
1.246 + test.Next(_L("Card ready notification"));
1.247 + TRequestStatus rs;
1.248 + TInt r;
1.249 + r=PccdDrv[0].RegisterEvent(EPcCardEvRdyChange,&rs);
1.250 + if (r==KErrNotSupported)
1.251 + {
1.252 + test.Printf( _L("<<<Not supported on this platform>>>\r\n"));
1.253 + return;
1.254 + }
1.255 + test(r==KErrNone);
1.256 +
1.257 + TPcCardStatus s;
1.258 + TSocketSignals ind;
1.259 + test(PccdDrv[0].SocketInfo(s,ind)==KErrNone);
1.260 + test(s==EPcCardNotReady);
1.261 + test(ind.iCardDetected);
1.262 +
1.263 + TRequestStatus prs;
1.264 + PccdDrv[0].PwrUp(&prs);
1.265 + User::WaitForRequest(rs);
1.266 + test(rs.Int()==KErrNone);
1.267 + User::WaitForRequest(prs);
1.268 + test(rs.Int()==KErrNone);
1.269 + }
1.270 +
1.271 +GLDEF_C TInt E32Main()
1.272 + {
1.273 +
1.274 + TInt r;
1.275 +#if defined (__WINS__)
1.276 + // Connect to all the local drives first as will be the case in ARM
1.277 + TBusLocalDrive Drive[KMaxLocalDrives];
1.278 + TBool ChangedFlag[KMaxLocalDrives];
1.279 + TInt j;
1.280 + for (j=0;j<KMaxLocalDrives;j++)
1.281 + Drive[j].Connect(j,ChangedFlag[j]);
1.282 +#endif
1.283 +
1.284 + test.Title();
1.285 +//
1.286 + test.Start(_L("Read machine info."));
1.287 + // Find out what sort of media change architecture we have. How many sockets
1.288 + // there are and whether we have a full blown media door scheme or just a system
1.289 + // using the PC Card CD signals. The later information we can't read from the
1.290 + // machine info, the test program just has to be updated with the machine name of
1.291 + // any machine which employs the CD scheme.
1.292 + SimpleCDScheme=EFalse;
1.293 + TInt muid=0;
1.294 + r=HAL::Get(HAL::EMachineUid, muid);
1.295 + test(r==KErrNone);
1.296 + if (muid==HAL::EMachineUid_Brutus)
1.297 + SimpleCDScheme=ETrue;
1.298 + TDriveInfoV1Buf dinfo;
1.299 + UserHal::DriveInfo(dinfo);
1.300 + TotalSockets=dinfo().iTotalSockets;
1.301 +
1.302 + if (SimpleCDScheme)
1.303 + test.Printf( _L("<<<Remove all PC/CF cards - hit a key>>>\r\n"));
1.304 + else
1.305 + {
1.306 + if (TotalSockets>0)
1.307 + test.Printf( _L("<<<Insert the card in socket %d - hit a key>>>\r\n"),(TotalSockets-1));
1.308 + }
1.309 + test.Getch();
1.310 +
1.311 + test.Next(_L("Load/open logical devices"));
1.312 + r=User::LoadLogicalDevice(_L("D_PCCDIF"));
1.313 + test(r==KErrNone||r==KErrAlreadyExists);
1.314 + TInt i;
1.315 + for (i=0;i<TotalSockets;i++)
1.316 + {
1.317 + r=PccdDrv[i].Open(i,PccdDrv[i].VersionRequired());
1.318 + test(r==KErrNone);
1.319 + }
1.320 +
1.321 + // Test UserSvr::MediaChangeNotify() and UserSvr::ForceRemountMedia().
1.322 + theMediaChangeNotifierTests();
1.323 +
1.324 + // Test registering on PC Card Controller events
1.325 + thePccdControllerMediaChangeEventTests();
1.326 + thePccdControllerPowerEventTests();
1.327 +#if defined(__EPOC32__)
1.328 + thePccdControllerStatusChangeEventTests();
1.329 + thePccdControllerCardReadyEventTests();
1.330 +#endif
1.331 +
1.332 + test.Next(_L("Close/free devices"));
1.333 + for (i=0;i<TotalSockets;i++)
1.334 + PccdDrv[i].Close();
1.335 + r=User::FreeLogicalDevice(_L("PccdIf"));
1.336 + test(r==KErrNone);
1.337 +
1.338 + test.End();
1.339 +
1.340 +#if defined (__WINS__)
1.341 + for (i=0;i<KMaxLocalDrives;i++)
1.342 + Drive[i].Disconnect();
1.343 +#endif
1.344 + return(0);
1.345 + }
1.346 +