|
1 // Copyright (c) 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 // |
|
15 |
|
16 |
|
17 #include <e32def.h> |
|
18 #include <e32cmn.h> |
|
19 #include <e32base.h> |
|
20 #include <f32file.h> |
|
21 #include <e32cons.h> |
|
22 #include <e32debug.h> |
|
23 #define __E32TEST_EXTENSION__ |
|
24 #include <e32test.h> |
|
25 #include <e32property.h> |
|
26 |
|
27 #include "f32_test_utils.h" |
|
28 |
|
29 #include "cblockdevicetester.h" |
|
30 #include "cmsdrive.h" |
|
31 #include "tmsprintdrive.h" |
|
32 #include "ttestutils.h" |
|
33 #include "tmslog.h" |
|
34 |
|
35 using namespace F32_Test_Utils; |
|
36 |
|
37 extern CMsDrive* msDrive; |
|
38 |
|
39 RTest test(_L("T_MSBLOCK")); |
|
40 RFs fsSession; |
|
41 |
|
42 |
|
43 class TTestMsBlock |
|
44 { |
|
45 public: |
|
46 void tFileAccess(); |
|
47 void tBlockAccessL(); |
|
48 void tRawAccessL(); |
|
49 void tLastLbaAccessL(); |
|
50 }; |
|
51 |
|
52 |
|
53 void TTestMsBlock::tFileAccess() |
|
54 { |
|
55 test.Start(_L("tFileAccess\n")); |
|
56 |
|
57 test.Next(_L("DriveInfo")); |
|
58 PrintDrvInfo(fsSession, msDrive->DriveNumber()); |
|
59 |
|
60 TVolumeInfo volInfo; |
|
61 TInt err = fsSession.Volume(volInfo); |
|
62 test(err == KErrNone); |
|
63 |
|
64 test.Printf(_L("Memory 'in use' = %lx\n"), (volInfo.iSize - volInfo.iFree)); |
|
65 test.Printf(_L("volInfo.iSize = %lx\n"), volInfo.iSize); |
|
66 test.Printf(_L("volInfo.iFree = %lx\n"), volInfo.iFree); |
|
67 |
|
68 //-- 1. create a file |
|
69 _LIT(KFile, "\\test_file.file"); |
|
70 const TUint KFileSz = 54321; |
|
71 |
|
72 test.Next(_L("Write file\n")); |
|
73 err = CreateCheckableStuffedFile(fsSession, KFile, KFileSz); |
|
74 test_KErrNone(err); |
|
75 |
|
76 //-- 2. verify the file, just in case. |
|
77 test.Next(_L("Verify file\n")); |
|
78 err = VerifyCheckableFile(fsSession, KFile); |
|
79 test_KErrNone(err); |
|
80 |
|
81 //-- 3. delete the file |
|
82 test.Next(_L("Delete file\n")); |
|
83 fsSession.Delete(KFile); |
|
84 test.End(); |
|
85 } |
|
86 |
|
87 void TTestMsBlock::tBlockAccessL() |
|
88 { |
|
89 test.Start(_L("tBlockAccess\n")); |
|
90 |
|
91 test.Next(_L("Create Test drive\n")); |
|
92 TInt driveNumber = msDrive->DriveNumber(); |
|
93 CBlockDeviceTester* blockDeviceTester = CBlockDeviceTester::NewL(driveNumber); |
|
94 |
|
95 test.Next(_L("Verify Test area on drive\n")); |
|
96 TInt res = blockDeviceTester->VerifyDrive(); |
|
97 test_KErrNone(res); |
|
98 |
|
99 test.Next(_L("Test Single Block access\n")); |
|
100 TLba lba = 1; |
|
101 TLba blocks = 1; |
|
102 |
|
103 test.Printf(_L("write block LBA=0x%x Blocks=0x%x\n"),lba, blocks); |
|
104 res = blockDeviceTester->UpdateBlock(lba, blocks); |
|
105 test_KErrNone(res); |
|
106 |
|
107 test.Printf(_L("read block LBA=0x%x Blocks=0x%x\n"),lba, blocks); |
|
108 res = blockDeviceTester->VerifyBlock(lba, blocks); |
|
109 test_KErrNone(res); |
|
110 |
|
111 test.Printf(_L("Verify drive\n")); |
|
112 res = blockDeviceTester->VerifyDrive(); |
|
113 test_KErrNone(res); |
|
114 |
|
115 test.Next(_L("Test Multiple Block access\n")); |
|
116 lba = 6; |
|
117 blocks = 7; |
|
118 res = blockDeviceTester->UpdateBlock(lba, blocks); |
|
119 test_KErrNone(res); |
|
120 res = blockDeviceTester->VerifyBlock(lba, blocks); |
|
121 test_KErrNone(res); |
|
122 res = blockDeviceTester->VerifyDrive(); |
|
123 test_KErrNone(res); |
|
124 |
|
125 delete blockDeviceTester; |
|
126 test.End(); |
|
127 } |
|
128 |
|
129 void TTestMsBlock::tRawAccessL() |
|
130 { |
|
131 test.Start(_L("tRawAccess\n")); |
|
132 |
|
133 // Head |
|
134 const TPos KPos_H = (KBlockSize * 5) + 0x7; |
|
135 const TUint KLen_H = 0x123; |
|
136 |
|
137 // Head + Tail |
|
138 const TPos KPos_HT = (KBlockSize * 7) + 0x180; |
|
139 const TUint KLen_HT = 0x100; |
|
140 |
|
141 // Head + Body + Tail |
|
142 const TPos KPos_HBT = (KBlockSize * 9) + 0x190; |
|
143 const TUint KLen_HBT = (KBlockSize * 4) + 0x110; |
|
144 |
|
145 |
|
146 test.Next(_L("Create Test drive\n")); |
|
147 TInt driveNumber = msDrive->DriveNumber(); |
|
148 CBlockDeviceTester* blockDeviceTester = CBlockDeviceTester::NewL(driveNumber); |
|
149 |
|
150 test.Next(_L("Verify Test area on drive\n")); |
|
151 TInt res = blockDeviceTester->VerifyDrive(); |
|
152 test_KErrNone(res); |
|
153 |
|
154 |
|
155 TPos pos = KPos_H; |
|
156 TUint len = KLen_H; |
|
157 test.Next(_L("Test head access\n")); |
|
158 test.Printf(_L("Pos=0x%lx Len=0x%x\n"), pos, len); |
|
159 res = blockDeviceTester->Update(pos, len); |
|
160 test_KErrNone(res); |
|
161 res = blockDeviceTester->Verify(pos, len); |
|
162 test_KErrNone(res); |
|
163 res = blockDeviceTester->VerifyDrive(); |
|
164 test_KErrNone(res); |
|
165 |
|
166 pos = KPos_HT; |
|
167 len = KLen_HT; |
|
168 test.Next(_L("Test head + tail access\n")); |
|
169 test.Printf(_L("Pos=0x%lx Len=0x%x\n"), pos, len); |
|
170 res = blockDeviceTester->Update(pos, len); |
|
171 test_KErrNone(res); |
|
172 res = blockDeviceTester->Verify(pos, len); |
|
173 test_KErrNone(res); |
|
174 res = blockDeviceTester->VerifyDrive(); |
|
175 test_KErrNone(res); |
|
176 |
|
177 pos = KPos_HBT; |
|
178 len = KLen_HBT; |
|
179 test.Next(_L("Test head + body+ tail access\n")); |
|
180 test.Printf(_L("Pos=0x%lx Len=0x%x\n"), pos, len); |
|
181 res = blockDeviceTester->Update(pos, len); |
|
182 test_KErrNone(res); |
|
183 res = blockDeviceTester->Verify(pos, len); |
|
184 test_KErrNone(res); |
|
185 res = blockDeviceTester->VerifyDrive(); |
|
186 test_KErrNone(res); |
|
187 |
|
188 delete blockDeviceTester; |
|
189 test.End(); |
|
190 } |
|
191 |
|
192 |
|
193 void TTestMsBlock::tLastLbaAccessL() |
|
194 { |
|
195 test.Start(_L("tLastLbaAccess\n")); |
|
196 test.Next(_L("tLastLbaAccess\n")); |
|
197 |
|
198 TInt driveNumber = msDrive->DriveNumber(); |
|
199 |
|
200 TVolumeInfo volInfo; |
|
201 TInt err = fsSession.Volume(volInfo); |
|
202 test(err == KErrNone); |
|
203 |
|
204 test.Printf(_L("Memory 'in use' = 0x%lx (0x%x)\n"), |
|
205 (volInfo.iSize - volInfo.iFree), (volInfo.iSize - volInfo.iFree)/KBlockSize); |
|
206 test.Printf(_L("volInfo.iSize = 0x%lx (0x%x)\n"), |
|
207 volInfo.iSize, volInfo.iSize/KBlockSize); |
|
208 test.Printf(_L("volInfo.iFree = 0x%lx (0x%x)\n"), |
|
209 volInfo.iFree, volInfo.iFree/KBlockSize); |
|
210 |
|
211 TLba lba = volInfo.iSize/KBlockSize; |
|
212 RBlockTargetMedia media(driveNumber); |
|
213 media.OpenL(); |
|
214 |
|
215 TInt writeRes = KErrNone; |
|
216 TInt readRes = KErrNone; |
|
217 test.Printf(_L("LBA=%x\n"), lba); |
|
218 for (;writeRes == KErrNone && readRes == KErrNone; lba++) |
|
219 { |
|
220 writeRes = media.WriteBlock(lba); |
|
221 readRes = media.ReadBlock(lba); |
|
222 } |
|
223 |
|
224 test.Printf(_L("LBA=%x ERR Write=%d Read=%d\n"), lba, writeRes, readRes); |
|
225 |
|
226 media.Close(); |
|
227 test.End(); |
|
228 } |
|
229 |
|
230 void CallTestsL() |
|
231 { |
|
232 TTestMsBlock t; |
|
233 t.tFileAccess(); |
|
234 t.tBlockAccessL(); |
|
235 t.tRawAccessL(); |
|
236 t.tLastLbaAccessL(); |
|
237 } |