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