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