os/kernelhwsrv/kerneltest/e32test/pccd/t_pccd2.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1996-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_pccd2.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
sl@0
    24
LOCAL_D RTest test(_L("T_PCCD2"));
sl@0
    25
const TSocket KSocket=0;
sl@0
    26
const TInt KFunc=0;
sl@0
    27
sl@0
    28
GLDEF_C TInt E32Main()
sl@0
    29
	{
sl@0
    30
#if defined (__WINS__)
sl@0
    31
	// Connect to all the local drives first as will be the case in ARM
sl@0
    32
	TBusLocalDrive Drive[KMaxLocalDrives];
sl@0
    33
	TBool ChangedFlag[KMaxLocalDrives];
sl@0
    34
	TInt i;
sl@0
    35
	for (i=0;i<KMaxLocalDrives;i++)
sl@0
    36
		Drive[i].Connect(i,ChangedFlag[i]);
sl@0
    37
#endif
sl@0
    38
sl@0
    39
	test.Title();
sl@0
    40
//
sl@0
    41
	test.Start(_L("Load/open logical device"));
sl@0
    42
	TInt r;
sl@0
    43
	r=User::LoadLogicalDevice(_L("D_PCCDIF"));
sl@0
    44
	test(r==KErrNone||r==KErrAlreadyExists);
sl@0
    45
	RPcCardCntrlIf pccdDrv;
sl@0
    46
	r=pccdDrv.Open(KSocket,pccdDrv.VersionRequired());
sl@0
    47
	test(r==KErrNone);
sl@0
    48
//
sl@0
    49
	test.Next(_L("Power card and configure."));
sl@0
    50
	UserSvr::ForceRemountMedia(ERemovableMedia0); // Media change - ensures test always starts from same state
sl@0
    51
	User::After(300000);	// Allow 0.3s after power down for controller to detect door closed.
sl@0
    52
    pccdDrv.Reset();
sl@0
    53
	TRequestStatus mrs;
sl@0
    54
	test(pccdDrv.RegisterEvent(EPcCardEvMediaChange,&mrs)==KErrNone);
sl@0
    55
	TRequestStatus prs;
sl@0
    56
	pccdDrv.PwrUp(&prs);
sl@0
    57
	User::WaitForRequest(prs);
sl@0
    58
	test(prs.Int()==KErrNone);
sl@0
    59
	TPcCardStatus s;
sl@0
    60
	TSocketSignals ind;
sl@0
    61
	test(pccdDrv.SocketInfo(s,ind)==KErrNone);
sl@0
    62
	test(s==EPcCardReady);
sl@0
    63
sl@0
    64
	TPcCardTypePckg tyBuf;
sl@0
    65
	TPcCardType &ty=tyBuf();
sl@0
    66
	test(pccdDrv.CardInfo(&tyBuf)==KErrNone);
sl@0
    67
	test(ty.iFuncType[0]==EFFixedDiskCard);
sl@0
    68
	test(pccdDrv.ReqConfig(KFunc,1)==KErrNone);
sl@0
    69
sl@0
    70
	// Test we can get the same chunk as the controllers attrib. chunk (its shareable).
sl@0
    71
	test.Next(_L("Request 64K attribute chunk at 0H."));
sl@0
    72
	TPcCardChnk ch;
sl@0
    73
	ch.iMemType=EPcCardAttribMem;
sl@0
    74
	ch.iMemBaseAddr=0;
sl@0
    75
	ch.iMemLen=0x10000;
sl@0
    76
	TInt win0,win1,win2;
sl@0
    77
	test(pccdDrv.ReqMem(ch,EAccSpeed600nS,win0)==KErrNone);
sl@0
    78
	TBuf8<8> rdBuf;
sl@0
    79
	rdBuf.Fill(0,8);
sl@0
    80
	test(pccdDrv.ReadMem(win0,0,8,rdBuf)==KErrNone);
sl@0
    81
//	test(rdBuf.Compare(_L("\x01\xFF\x04\xFF\xDF\xFF\x72\xFF"))==0);
sl@0
    82
	test(rdBuf[0]==0x01&&rdBuf[2]==0x04&&rdBuf[4]==0xDF&&rdBuf[6]==0x72);
sl@0
    83
sl@0
    84
	// Test we can get small chunk within the controllers attrib. chunk (Win0 already allocated).
sl@0
    85
	test.Next(_L("Request 16byte attribute chunk at 10H."));
sl@0
    86
	ch.iMemType=EPcCardAttribMem;
sl@0
    87
	ch.iMemBaseAddr=0x10;
sl@0
    88
	ch.iMemLen=0x10;
sl@0
    89
	test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win1)==KErrAccessDenied); // 1st chunk isn't shared
sl@0
    90
	pccdDrv.RelMem(win0);
sl@0
    91
	test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win1)==KErrNone);
sl@0
    92
	rdBuf.Fill(0,8);
sl@0
    93
	test(pccdDrv.ReadMem(win1,0,8,rdBuf)==KErrNone);
sl@0
    94
//	test(rdBuf.Compare(_L("\x03\xFF\xD9\xFF\x01\xFF\xFF\xFF"))==0);
sl@0
    95
	test(rdBuf[0]==0x03&&rdBuf[2]==0xD9&&rdBuf[4]==0x01&&rdBuf[6]==0xFF);
sl@0
    96
sl@0
    97
	// Test we can get a second small chunk, also within the controllers attrib. chunk but
sl@0
    98
	// not clashing with previous chunk (Win1 already allocated).
sl@0
    99
	test.Next(_L("Request 16byte attribute chunk at 20H."));
sl@0
   100
	ch.iMemType=EPcCardAttribMem;
sl@0
   101
	ch.iMemBaseAddr=0x20;
sl@0
   102
	ch.iMemLen=0x10;
sl@0
   103
	test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win0)==KErrNone);
sl@0
   104
	rdBuf.Fill(0,8);	
sl@0
   105
	test(pccdDrv.ReadMem(win0,0,8,rdBuf)==KErrNone);
sl@0
   106
//	test(rdBuf.Compare(_L("\x20\xFF\x06\xFF\x45\xFF"))==2&&rdBuf[6]==0x00&&rdBuf[7]==0xFF); // 'Null causes problems with compare
sl@0
   107
	test(rdBuf[0]==0x20&&rdBuf[2]==0x06&&rdBuf[4]==0x45&&rdBuf[6]==0x00);
sl@0
   108
sl@0
   109
	// Test that requesting a chunk which lies partly but not entirely within the controllers
sl@0
   110
	// chunk fails (Win0/Win1 already allocated).
sl@0
   111
	test.Next(_L("Request 64K attribute chunk at 800H."));
sl@0
   112
	test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win2)==KErrInUse);
sl@0
   113
	pccdDrv.RelMem(win1);
sl@0
   114
	ch.iMemType=EPcCardAttribMem;
sl@0
   115
	ch.iMemBaseAddr=0x800;
sl@0
   116
	ch.iMemLen=0x10000;
sl@0
   117
	test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win1)==KErrAccessDenied);
sl@0
   118
sl@0
   119
	// Test we can get a small chunk beyond the controllers chunk (Win0 already allocated).
sl@0
   120
	test.Next(_L("Request 16byte attribute chunk at 10800H."));
sl@0
   121
	ch.iMemType=EPcCardAttribMem;
sl@0
   122
	ch.iMemBaseAddr=0x10800;
sl@0
   123
	ch.iMemLen=0x10;
sl@0
   124
	test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win1)==KErrNone);
sl@0
   125
	pccdDrv.RelMem(win1);
sl@0
   126
sl@0
   127
	// Test we can get a large chunk beyond the controllers chunk (Win0 already allocated).
sl@0
   128
	test.Next(_L("Request 4K attribute chunk at 10800H."));
sl@0
   129
	ch.iMemType=EPcCardAttribMem;
sl@0
   130
	ch.iMemBaseAddr=0x10800;
sl@0
   131
	ch.iMemLen=0x1000;
sl@0
   132
	test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win1)==KErrNone);
sl@0
   133
	pccdDrv.RelMem(win1);
sl@0
   134
sl@0
   135
	// Test we can get a chunk in a different memory type (Win0 already allocated).
sl@0
   136
	test.Next(_L("Request 16byte IO chunk at 0H."));
sl@0
   137
	ch.iMemType=EPcCardIo8Mem;
sl@0
   138
	ch.iMemBaseAddr=0;
sl@0
   139
	ch.iMemLen=0x10;
sl@0
   140
//	test(pccdDrv.ReqMem(ch,EAccSpeed200nS,win1)==KErrNone); // ???
sl@0
   141
	test(pccdDrv.ReqMem(ch,EAccSpeed250nS,win1)==KErrNone);
sl@0
   142
sl@0
   143
	// Win0/Win1 allocated
sl@0
   144
	TBuf8<8> wrBuf;
sl@0
   145
	TInt reg=0;
sl@0
   146
	test.Next(_L("Write/Read from ATA registers."));
sl@0
   147
	test(pccdDrv.ReadConfigReg(KFunc,0,reg)==KErrNone); // Check its still configured
sl@0
   148
	test(reg==1);
sl@0
   149
	wrBuf.Copy(_L("\x04\x03\x02\x01"));
sl@0
   150
	wrBuf.SetLength(4);
sl@0
   151
	test(pccdDrv.WriteMem(win1,2,wrBuf)==KErrNone); // 4 bytes starting at Sector count
sl@0
   152
	rdBuf.Fill(0,4);	
sl@0
   153
	test(pccdDrv.ReadMem(win1,2,4,rdBuf)==KErrNone);
sl@0
   154
	test(rdBuf.Compare(_L8("\x04\x03\x02\x01"))==0);
sl@0
   155
sl@0
   156
	// Win0/Win1 allocated
sl@0
   157
	test.Next(_L("Attempt to access window after power down."));
sl@0
   158
	RTimer timer;
sl@0
   159
	TRequestStatus trs;
sl@0
   160
	test(timer.CreateLocal()==KErrNone);
sl@0
   161
	TTime tim;
sl@0
   162
	tim.HomeTime();
sl@0
   163
	tim+=TTimeIntervalSeconds(8);
sl@0
   164
	timer.At(trs,tim);
sl@0
   165
	UserHal::SwitchOff();
sl@0
   166
	User::WaitForRequest(trs);
sl@0
   167
	test(trs.Int()==KErrNone);
sl@0
   168
	pccdDrv.PwrUp(&prs);
sl@0
   169
	User::WaitForRequest(prs);
sl@0
   170
	test(prs.Int()==KErrNone);
sl@0
   171
	// Check its been re-configured
sl@0
   172
	reg=0;
sl@0
   173
	test(pccdDrv.ReadConfigReg(KFunc,0,reg)==KErrNone);
sl@0
   174
	test(reg==1);
sl@0
   175
	// Check that window still OK after power down
sl@0
   176
	test(pccdDrv.WriteMem(win1,2,wrBuf)==KErrNone); // 4 bytes starting at Sector count
sl@0
   177
	rdBuf.Fill(0,4);	
sl@0
   178
	test(pccdDrv.ReadMem(win1,2,4,rdBuf)==KErrNone);
sl@0
   179
	test(rdBuf.Compare(_L8("\x04\x03\x02\x01"))==0);
sl@0
   180
sl@0
   181
	// Win0/Win1 allocated
sl@0
   182
	test.Next(_L("Attempt to access window after media change."));
sl@0
   183
	UserSvr::ForceRemountMedia(ERemovableMedia0); // Generate media change
sl@0
   184
	User::WaitForRequest(mrs);
sl@0
   185
	if (mrs.Int()!=KErrNone)
sl@0
   186
		{
sl@0
   187
	    pccdDrv.Close();
sl@0
   188
		test(0);
sl@0
   189
		} 
sl@0
   190
	User::After(300000);	// Allow 0.3s after power down for controller to detect door closed.
sl@0
   191
	pccdDrv.PwrUp(&prs);
sl@0
   192
	User::WaitForRequest(prs);
sl@0
   193
	if (prs.Int()!=KErrNone)
sl@0
   194
		{
sl@0
   195
	    pccdDrv.Close();
sl@0
   196
		test(0);
sl@0
   197
		}
sl@0
   198
	// First access following media change must be supervisor call
sl@0
   199
	if (pccdDrv.CardInfo(&tyBuf)!=KErrNone)
sl@0
   200
		{
sl@0
   201
	    pccdDrv.Close();
sl@0
   202
		test(0);
sl@0
   203
		}
sl@0
   204
	// Check its not been re-configured
sl@0
   205
	if (pccdDrv.ReadConfigReg(KFunc,0,reg)!=KErrGeneral) 
sl@0
   206
		{
sl@0
   207
	    pccdDrv.Close();
sl@0
   208
		test(0);
sl@0
   209
		} 
sl@0
   210
	if (pccdDrv.ReadMem(win1,2,4,rdBuf)!=KErrNotReady)
sl@0
   211
		{
sl@0
   212
	    pccdDrv.Close();
sl@0
   213
		test(0);
sl@0
   214
		}
sl@0
   215
sl@0
   216
	pccdDrv.Close();
sl@0
   217
	r=User::FreeLogicalDevice(_L("PccdIf"));
sl@0
   218
	test(r==KErrNone);
sl@0
   219
sl@0
   220
	test.End();
sl@0
   221
sl@0
   222
#if defined (__WINS__)
sl@0
   223
	for (i=0;i<KMaxLocalDrives;i++)
sl@0
   224
		Drive[i].Disconnect();
sl@0
   225
#endif
sl@0
   226
	return(0);
sl@0
   227
	}
sl@0
   228