1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/pccd/t_pccd2.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,228 @@
1.4 +// Copyright (c) 1996-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_pccd2.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 +
1.27 +LOCAL_D RTest test(_L("T_PCCD2"));
1.28 +const TSocket KSocket=0;
1.29 +const TInt KFunc=0;
1.30 +
1.31 +GLDEF_C TInt E32Main()
1.32 + {
1.33 +#if defined (__WINS__)
1.34 + // Connect to all the local drives first as will be the case in ARM
1.35 + TBusLocalDrive Drive[KMaxLocalDrives];
1.36 + TBool ChangedFlag[KMaxLocalDrives];
1.37 + TInt i;
1.38 + for (i=0;i<KMaxLocalDrives;i++)
1.39 + Drive[i].Connect(i,ChangedFlag[i]);
1.40 +#endif
1.41 +
1.42 + test.Title();
1.43 +//
1.44 + test.Start(_L("Load/open logical device"));
1.45 + TInt r;
1.46 + r=User::LoadLogicalDevice(_L("D_PCCDIF"));
1.47 + test(r==KErrNone||r==KErrAlreadyExists);
1.48 + RPcCardCntrlIf pccdDrv;
1.49 + r=pccdDrv.Open(KSocket,pccdDrv.VersionRequired());
1.50 + test(r==KErrNone);
1.51 +//
1.52 + test.Next(_L("Power card and configure."));
1.53 + UserSvr::ForceRemountMedia(ERemovableMedia0); // Media change - ensures test always starts from same state
1.54 + User::After(300000); // Allow 0.3s after power down for controller to detect door closed.
1.55 + pccdDrv.Reset();
1.56 + TRequestStatus mrs;
1.57 + test(pccdDrv.RegisterEvent(EPcCardEvMediaChange,&mrs)==KErrNone);
1.58 + TRequestStatus prs;
1.59 + pccdDrv.PwrUp(&prs);
1.60 + User::WaitForRequest(prs);
1.61 + test(prs.Int()==KErrNone);
1.62 + TPcCardStatus s;
1.63 + TSocketSignals ind;
1.64 + test(pccdDrv.SocketInfo(s,ind)==KErrNone);
1.65 + test(s==EPcCardReady);
1.66 +
1.67 + TPcCardTypePckg tyBuf;
1.68 + TPcCardType &ty=tyBuf();
1.69 + test(pccdDrv.CardInfo(&tyBuf)==KErrNone);
1.70 + test(ty.iFuncType[0]==EFFixedDiskCard);
1.71 + test(pccdDrv.ReqConfig(KFunc,1)==KErrNone);
1.72 +
1.73 + // Test we can get the same chunk as the controllers attrib. chunk (its shareable).
1.74 + test.Next(_L("Request 64K attribute chunk at 0H."));
1.75 + TPcCardChnk ch;
1.76 + ch.iMemType=EPcCardAttribMem;
1.77 + ch.iMemBaseAddr=0;
1.78 + ch.iMemLen=0x10000;
1.79 + TInt win0,win1,win2;
1.80 + test(pccdDrv.ReqMem(ch,EAccSpeed600nS,win0)==KErrNone);
1.81 + TBuf8<8> rdBuf;
1.82 + rdBuf.Fill(0,8);
1.83 + test(pccdDrv.ReadMem(win0,0,8,rdBuf)==KErrNone);
1.84 +// test(rdBuf.Compare(_L("\x01\xFF\x04\xFF\xDF\xFF\x72\xFF"))==0);
1.85 + test(rdBuf[0]==0x01&&rdBuf[2]==0x04&&rdBuf[4]==0xDF&&rdBuf[6]==0x72);
1.86 +
1.87 + // Test we can get small chunk within the controllers attrib. chunk (Win0 already allocated).
1.88 + test.Next(_L("Request 16byte attribute chunk at 10H."));
1.89 + ch.iMemType=EPcCardAttribMem;
1.90 + ch.iMemBaseAddr=0x10;
1.91 + ch.iMemLen=0x10;
1.92 + test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win1)==KErrAccessDenied); // 1st chunk isn't shared
1.93 + pccdDrv.RelMem(win0);
1.94 + test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win1)==KErrNone);
1.95 + rdBuf.Fill(0,8);
1.96 + test(pccdDrv.ReadMem(win1,0,8,rdBuf)==KErrNone);
1.97 +// test(rdBuf.Compare(_L("\x03\xFF\xD9\xFF\x01\xFF\xFF\xFF"))==0);
1.98 + test(rdBuf[0]==0x03&&rdBuf[2]==0xD9&&rdBuf[4]==0x01&&rdBuf[6]==0xFF);
1.99 +
1.100 + // Test we can get a second small chunk, also within the controllers attrib. chunk but
1.101 + // not clashing with previous chunk (Win1 already allocated).
1.102 + test.Next(_L("Request 16byte attribute chunk at 20H."));
1.103 + ch.iMemType=EPcCardAttribMem;
1.104 + ch.iMemBaseAddr=0x20;
1.105 + ch.iMemLen=0x10;
1.106 + test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win0)==KErrNone);
1.107 + rdBuf.Fill(0,8);
1.108 + test(pccdDrv.ReadMem(win0,0,8,rdBuf)==KErrNone);
1.109 +// test(rdBuf.Compare(_L("\x20\xFF\x06\xFF\x45\xFF"))==2&&rdBuf[6]==0x00&&rdBuf[7]==0xFF); // 'Null causes problems with compare
1.110 + test(rdBuf[0]==0x20&&rdBuf[2]==0x06&&rdBuf[4]==0x45&&rdBuf[6]==0x00);
1.111 +
1.112 + // Test that requesting a chunk which lies partly but not entirely within the controllers
1.113 + // chunk fails (Win0/Win1 already allocated).
1.114 + test.Next(_L("Request 64K attribute chunk at 800H."));
1.115 + test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win2)==KErrInUse);
1.116 + pccdDrv.RelMem(win1);
1.117 + ch.iMemType=EPcCardAttribMem;
1.118 + ch.iMemBaseAddr=0x800;
1.119 + ch.iMemLen=0x10000;
1.120 + test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win1)==KErrAccessDenied);
1.121 +
1.122 + // Test we can get a small chunk beyond the controllers chunk (Win0 already allocated).
1.123 + test.Next(_L("Request 16byte attribute chunk at 10800H."));
1.124 + ch.iMemType=EPcCardAttribMem;
1.125 + ch.iMemBaseAddr=0x10800;
1.126 + ch.iMemLen=0x10;
1.127 + test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win1)==KErrNone);
1.128 + pccdDrv.RelMem(win1);
1.129 +
1.130 + // Test we can get a large chunk beyond the controllers chunk (Win0 already allocated).
1.131 + test.Next(_L("Request 4K attribute chunk at 10800H."));
1.132 + ch.iMemType=EPcCardAttribMem;
1.133 + ch.iMemBaseAddr=0x10800;
1.134 + ch.iMemLen=0x1000;
1.135 + test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win1)==KErrNone);
1.136 + pccdDrv.RelMem(win1);
1.137 +
1.138 + // Test we can get a chunk in a different memory type (Win0 already allocated).
1.139 + test.Next(_L("Request 16byte IO chunk at 0H."));
1.140 + ch.iMemType=EPcCardIo8Mem;
1.141 + ch.iMemBaseAddr=0;
1.142 + ch.iMemLen=0x10;
1.143 +// test(pccdDrv.ReqMem(ch,EAccSpeed200nS,win1)==KErrNone); // ???
1.144 + test(pccdDrv.ReqMem(ch,EAccSpeed250nS,win1)==KErrNone);
1.145 +
1.146 + // Win0/Win1 allocated
1.147 + TBuf8<8> wrBuf;
1.148 + TInt reg=0;
1.149 + test.Next(_L("Write/Read from ATA registers."));
1.150 + test(pccdDrv.ReadConfigReg(KFunc,0,reg)==KErrNone); // Check its still configured
1.151 + test(reg==1);
1.152 + wrBuf.Copy(_L("\x04\x03\x02\x01"));
1.153 + wrBuf.SetLength(4);
1.154 + test(pccdDrv.WriteMem(win1,2,wrBuf)==KErrNone); // 4 bytes starting at Sector count
1.155 + rdBuf.Fill(0,4);
1.156 + test(pccdDrv.ReadMem(win1,2,4,rdBuf)==KErrNone);
1.157 + test(rdBuf.Compare(_L8("\x04\x03\x02\x01"))==0);
1.158 +
1.159 + // Win0/Win1 allocated
1.160 + test.Next(_L("Attempt to access window after power down."));
1.161 + RTimer timer;
1.162 + TRequestStatus trs;
1.163 + test(timer.CreateLocal()==KErrNone);
1.164 + TTime tim;
1.165 + tim.HomeTime();
1.166 + tim+=TTimeIntervalSeconds(8);
1.167 + timer.At(trs,tim);
1.168 + UserHal::SwitchOff();
1.169 + User::WaitForRequest(trs);
1.170 + test(trs.Int()==KErrNone);
1.171 + pccdDrv.PwrUp(&prs);
1.172 + User::WaitForRequest(prs);
1.173 + test(prs.Int()==KErrNone);
1.174 + // Check its been re-configured
1.175 + reg=0;
1.176 + test(pccdDrv.ReadConfigReg(KFunc,0,reg)==KErrNone);
1.177 + test(reg==1);
1.178 + // Check that window still OK after power down
1.179 + test(pccdDrv.WriteMem(win1,2,wrBuf)==KErrNone); // 4 bytes starting at Sector count
1.180 + rdBuf.Fill(0,4);
1.181 + test(pccdDrv.ReadMem(win1,2,4,rdBuf)==KErrNone);
1.182 + test(rdBuf.Compare(_L8("\x04\x03\x02\x01"))==0);
1.183 +
1.184 + // Win0/Win1 allocated
1.185 + test.Next(_L("Attempt to access window after media change."));
1.186 + UserSvr::ForceRemountMedia(ERemovableMedia0); // Generate media change
1.187 + User::WaitForRequest(mrs);
1.188 + if (mrs.Int()!=KErrNone)
1.189 + {
1.190 + pccdDrv.Close();
1.191 + test(0);
1.192 + }
1.193 + User::After(300000); // Allow 0.3s after power down for controller to detect door closed.
1.194 + pccdDrv.PwrUp(&prs);
1.195 + User::WaitForRequest(prs);
1.196 + if (prs.Int()!=KErrNone)
1.197 + {
1.198 + pccdDrv.Close();
1.199 + test(0);
1.200 + }
1.201 + // First access following media change must be supervisor call
1.202 + if (pccdDrv.CardInfo(&tyBuf)!=KErrNone)
1.203 + {
1.204 + pccdDrv.Close();
1.205 + test(0);
1.206 + }
1.207 + // Check its not been re-configured
1.208 + if (pccdDrv.ReadConfigReg(KFunc,0,reg)!=KErrGeneral)
1.209 + {
1.210 + pccdDrv.Close();
1.211 + test(0);
1.212 + }
1.213 + if (pccdDrv.ReadMem(win1,2,4,rdBuf)!=KErrNotReady)
1.214 + {
1.215 + pccdDrv.Close();
1.216 + test(0);
1.217 + }
1.218 +
1.219 + pccdDrv.Close();
1.220 + r=User::FreeLogicalDevice(_L("PccdIf"));
1.221 + test(r==KErrNone);
1.222 +
1.223 + test.End();
1.224 +
1.225 +#if defined (__WINS__)
1.226 + for (i=0;i<KMaxLocalDrives;i++)
1.227 + Drive[i].Disconnect();
1.228 +#endif
1.229 + return(0);
1.230 + }
1.231 +