author | Mike Kinghan <mikek@symbian.org> |
Mon, 19 Jul 2010 08:40:05 +0100 | |
branch | GCC_SURGE |
changeset 209 | 6035754ebf88 |
parent 109 | b3a1d9898418 |
child 257 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1998-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 |
// f32test\server\t_resize.cpp |
|
15 |
// This program is designed to test the CFatFileCB::ResizeIndex() method, |
|
16 |
// especially wrt defect EDNMDON-4J2EWK, which occured when the index was |
|
17 |
// resized by an extreme amount. |
|
18 |
// This program must be run on a FAT formatted disk with at least 10Mb free. |
|
19 |
// RFile::SetSize(TInt aSize) |
|
20 |
// |
|
21 |
// |
|
22 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
23 |
#define __E32TEST_EXTENSION__ |
0 | 24 |
#include <e32test.h> |
25 |
#include <f32file.h> |
|
26 |
#include <hal.h> |
|
27 |
#include "t_server.h" |
|
28 |
||
29 |
GLDEF_D RTest test(_L("T_RESIZE")); |
|
30 |
||
31 |
// const TInt KBrutusUidValue=0x09080001; /* Never used */ |
|
32 |
// const TInt KWinsUidValue=0x00000001; /* Never used */ |
|
33 |
const TInt K1K = 1 << 10; // 1K |
|
34 |
const TInt K4K = 4 * K1K; |
|
35 |
const TInt K1Mb = 1 << 20; |
|
36 |
const TInt KBigFileSize = 10 * K1Mb; // 10Mb |
|
37 |
const TInt KSmallFileSize = 10 * K1K; |
|
38 |
const TInt KFillBufLength = K1K; |
|
39 |
const TInt KNumberLength = 8; |
|
40 |
const TInt KNumbersPerFillBuf = KFillBufLength / KNumberLength; |
|
41 |
||
42 |
LOCAL_C TBool IsDiskValid(TInt aDrive); |
|
43 |
LOCAL_C void FillBuf(TDes8 &aBuf, TInt aStart); |
|
44 |
||
45 |
GLDEF_C void CallTestsL() |
|
46 |
{ |
|
47 |
// |
|
48 |
// Test with drive nearly full |
|
49 |
// |
|
50 |
CTrapCleanup* cleanup; // create cleanup stack |
|
51 |
cleanup = CTrapCleanup::New(); |
|
52 |
__UHEAP_MARK; |
|
53 |
||
54 |
test.Title(); |
|
55 |
test.Start(_L("Starting tests")); |
|
56 |
||
57 |
test.Next(_L("Connecting to file server.")); |
|
58 |
TInt r; |
|
59 |
r = TheFs.Connect(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
60 |
test_KErrNone(r); |
0 | 61 |
|
62 |
if ( !gDriveToTest.IsLower() ) |
|
63 |
{ |
|
64 |
gDriveToTest.LowerCase(); |
|
65 |
} |
|
66 |
||
67 |
TInt gDriveNumber; // current drive number |
|
68 |
test((r = RFs::CharToDrive(gDriveToTest, gDriveNumber)) == KErrNone); |
|
69 |
||
70 |
if (IsDiskValid(gDriveNumber)) |
|
71 |
{ |
|
72 |
// Overflows occur because iSeekIndex is 128 elements long. |
|
73 |
||
74 |
// ASSUMES CLUSTER SIZE IS 512 BYTES |
|
75 |
||
76 |
// 1: Create a 10Mb file and resize it to 10k. |
|
77 |
||
78 |
// A 10Mb file will create force each member of CFatFileCB::iSeekIndex to |
|
79 |
// mark the start of 2^8 blocks (512 * 128 * 2^8 = 2^9 * 2^7 * 2^8 = 2^24 = 16777216) |
|
80 |
// A 10K file has an iSeekIndex with granularity 2^0 = 1 cluster. |
|
81 |
// skip half-words = (1<<(iSeekIndexSize-aNewMult))-1 = (1 << (8 - 0)) - 1 = 255. |
|
82 |
||
83 |
test.Next(_L("Creating file.")); |
|
84 |
test.Printf(_L("Writing %08x file.\n"), KBigFileSize); |
|
85 |
RFile f; |
|
86 |
TFileName fn; |
|
87 |
fn.Format(_L("%c:\\resize.tst"), TUint(gDriveToTest)); |
|
88 |
test((r = f.Create(TheFs, fn, EFileShareExclusive | EFileStream | EFileWrite)) == KErrNone); |
|
89 |
TInt i; // bad for scope under VC |
|
90 |
TBuf8<KFillBufLength> buf; // don't reconstruct for each iteration |
|
91 |
for (i = 0; i < KBigFileSize / KNumberLength; i += KNumbersPerFillBuf) |
|
92 |
{ |
|
93 |
if (((i * KNumberLength) % (KBigFileSize / 32)) == 0) |
|
94 |
test.Printf(_L("writing to file posn %08x.\n"), i * 8); |
|
95 |
||
96 |
FillBuf(buf, i); |
|
97 |
test(f.Write(buf) == KErrNone); |
|
98 |
} |
|
99 |
||
100 |
// Resize the file to 10k. This should cause CFatFileCB::iSeekIndex to be filled |
|
101 |
// with zeroes and not cause a Des16PanicDesIndexOutOfRange. |
|
102 |
test.Next(_L("Resizing file downwards.\n")); |
|
103 |
test.Printf(_L("Resizing %08x file to %08x.\n"), KBigFileSize, KSmallFileSize); |
|
104 |
f.SetSize(KSmallFileSize); |
|
105 |
||
106 |
// Re-read the file up to 10k to make sure it is navigated properly. |
|
107 |
test.Printf(_L("Checking first %08x bytes are maintained.\n"), KSmallFileSize); |
|
108 |
TInt startPos = 0; |
|
109 |
f.Seek(ESeekStart, startPos); |
|
110 |
TBuf8<KFillBufLength> buf2; // don't reconstruct for each iteration |
|
111 |
for (i = 0; i < KSmallFileSize / KNumberLength; i += KNumbersPerFillBuf) |
|
112 |
{ |
|
113 |
test(f.Read(buf) == KErrNone); |
|
114 |
test(buf.Length() == KFillBufLength); |
|
115 |
FillBuf(buf2, i); |
|
116 |
test(buf2.Compare(buf) == 0); |
|
117 |
} |
|
118 |
||
119 |
// 2: Resize the 10K file to 10Mb. |
|
120 |
// |
|
121 |
// iSeekIndex will be cleared because the resize loop is never executed. |
|
122 |
||
123 |
// TUint16* newVal=(TUint16*)ptr; |
|
124 |
// TInt step=1<<(aNewMult-iSeekIndexSize); // 256 |
|
125 |
// ptr+=step-1; // ptr := &(*iSeekIndex[255]) |
|
126 |
// while(ptr<ptrEnd && newVal<newValEnd) // ptr > ptrEnd on first iteration |
|
127 |
// { |
|
128 |
// *newVal=*ptr; |
|
129 |
// newVal++; |
|
130 |
// ptr+=step; |
|
131 |
// } |
|
132 |
// while(newVal<ptrEnd) // newVal == ptr on first iteration |
|
133 |
// *newVal++=0; // just zero entire array |
|
134 |
||
135 |
test.Next(_L("Resizing file upwards.\n")); |
|
136 |
test.Printf(_L("Resizing %08x file to %08x."), KSmallFileSize, KBigFileSize); |
|
137 |
test(f.SetSize(KBigFileSize) == KErrNone); |
|
138 |
f.Seek(ESeekStart, startPos); |
|
139 |
for (i = 0; i < KBigFileSize / KNumberLength; i += KNumbersPerFillBuf) |
|
140 |
{ |
|
141 |
if (((i * KNumberLength) % (KBigFileSize / 32)) == 0) |
|
142 |
test.Printf(_L("reading from file posn %08x.\n"), i * 8); |
|
143 |
||
144 |
test(f.Read(buf) == KErrNone); |
|
145 |
test(buf.Length() == KFillBufLength); |
|
146 |
||
147 |
if (i < (K4K / KNumberLength)) |
|
148 |
{ |
|
149 |
FillBuf(buf2, i); |
|
150 |
test(buf.Compare(buf2) == 0); |
|
151 |
} |
|
152 |
} |
|
153 |
f.Close(); |
|
154 |
test( TheFs.Delete(fn) == KErrNone ); |
|
155 |
} // if (IsDiskValid(gDriveNumber)) |
|
156 |
||
157 |
// TheFs.Close(); /* TheFs is being accessed by t_main's E32MAIN() after the test is complete. */ |
|
158 |
||
159 |
test.End(); |
|
160 |
test.Close(); |
|
161 |
||
162 |
__UHEAP_MARKEND; |
|
163 |
delete cleanup; |
|
164 |
} |
|
165 |
||
166 |
LOCAL_C TBool IsDiskValid(TInt aDrive) |
|
167 |
// Returns ETrue if aDrive is a FAT formatted disk with KBigFileSize bytes free, |
|
168 |
// EFalse otherwise. |
|
169 |
{ |
|
170 |
TInt r; |
|
171 |
||
172 |
TInt isFat, isValid; |
|
173 |
TInt machUid; |
|
174 |
r=HAL::Get(HAL::EMachineUid,machUid); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
175 |
test_KErrNone(r); |
0 | 176 |
// test.Printf(_L("machUid = %08x.\n"), machUid); |
177 |
||
178 |
TBuf<16> fsName; // _?_ length |
|
179 |
||
180 |
r = TheFs.FileSystemName(fsName, aDrive); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
181 |
test_Value(r, r == KErrNone || r == KErrNotFound); |
0 | 182 |
test.Printf(_L("fsName = \"%S\".\n"), &fsName); |
183 |
||
184 |
if (machUid == HAL::EMachineUid_Brutus) |
|
185 |
{ |
|
186 |
isFat = (fsName.CompareF(_L("Local")) == 0); |
|
187 |
} |
|
188 |
else |
|
189 |
{ |
|
190 |
isFat = (fsName.CompareF(_L("Fat")) == 0); |
|
191 |
} |
|
192 |
||
193 |
test.Printf(_L("isFat = %x.\n"), isFat); |
|
194 |
if (! isFat) |
|
195 |
{ |
|
196 |
isValid = EFalse; |
|
197 |
} |
|
198 |
else |
|
199 |
{ |
|
200 |
TVolumeInfo vi; |
|
201 |
test((r = TheFs.Volume(vi, aDrive)) == KErrNone); |
|
202 |
test.Printf(_L("vi.iFree = %ld\n"), vi.iFree); |
|
203 |
isValid = (vi.iFree >= TInt64(KBigFileSize)); |
|
204 |
} |
|
205 |
||
206 |
if (! isValid) |
|
207 |
{ |
|
208 |
test.Printf(_L("IsDiskValid: Skipped because drive %d is not a valid FAT volume (with 10Mb free).\n"), aDrive); |
|
209 |
} |
|
210 |
||
211 |
return isValid; |
|
212 |
} |
|
213 |
||
214 |
LOCAL_C void FillBuf(TDes8 &aBuf, TInt aStart) |
|
215 |
// Fills aBuf with a list of ascending 8 digit numbers. |
|
216 |
// Assumes aBuf.MaxLength() is divisible by 8. |
|
217 |
{ |
|
218 |
aBuf.Zero(); |
|
219 |
while (aBuf.Length() < aBuf.MaxLength()) |
|
220 |
{ |
|
221 |
aBuf.AppendFormat(_L8("%08x"), aStart++); |
|
222 |
} |
|
223 |
} |