1 // Copyright (c) 2006-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 // Perofrms the filling of the disk to its maximum capacity |
|
15 // |
|
16 // |
|
17 |
|
18 |
|
19 #include <e32def.h> |
|
20 #include "basetestfat32filldisk.h" |
|
21 |
|
22 /** |
|
23 Class Constructor |
|
24 */ |
|
25 CBaseTestFat32FillDisk::CBaseTestFat32FillDisk() |
|
26 { |
|
27 SetTestStepName(KTestStepFillDisk); |
|
28 } |
|
29 |
|
30 /** |
|
31 Class Destructor |
|
32 */ |
|
33 CBaseTestFat32FillDisk::~CBaseTestFat32FillDisk() |
|
34 { |
|
35 } |
|
36 |
|
37 /** |
|
38 Thread that sends a signal along the serial port so that it is not assumed |
|
39 that the board has hung. |
|
40 */ |
|
41 TInt Thread1Func(TAny* /*aPtr*/) |
|
42 { |
|
43 for(;;) |
|
44 { |
|
45 RDebug::Printf("Filling the disk..."); |
|
46 User::After(600000000); |
|
47 } |
|
48 } |
|
49 |
|
50 /** |
|
51 Filling the disk to its maximum capacity by writing 1 file. |
|
52 If the disk is greater than 2GB in size, 2 files are created. |
|
53 |
|
54 @return EPass if test passes and EFail if test fails |
|
55 */ |
|
56 TVerdict CBaseTestFat32FillDisk::doTestStepL() |
|
57 { |
|
58 SetTestStepResult(EFail); |
|
59 TVolumeInfo iInfo; |
|
60 RFile rFile; |
|
61 TInt filesize = 0; |
|
62 RFile rFile2; |
|
63 TInt filesize2 = 0; |
|
64 RFile rFile3; |
|
65 TInt filesize3 = 0; |
|
66 TInt r = KErrNone; |
|
67 r = iTheFs.Volume(iInfo, CurrentDrive()); |
|
68 if (r != KErrNone) |
|
69 INFO_PRINTF2(_L("volume info for %C:"), (TUint)iDriveToTest); |
|
70 _LIT(KFileReplace, "RFile::Replace, epecting KErrNone"); |
|
71 r = rFile.Replace(iTheFs, _L("\\TEST.txt"), EFileWrite); |
|
72 FAT_TEST_VAL(r==KErrNone, KFileReplace, r); |
|
73 |
|
74 TBuf<20> threadName1 =_L("Thread1"); |
|
75 RThread thread1; |
|
76 r = thread1.Create(threadName1,Thread1Func,KDefaultStackSize,0x1000,0x1000,NULL); |
|
77 if (r != KErrNone) |
|
78 { |
|
79 INFO_PRINTF2(_L("Could not create thread1 - r=%d"),r); |
|
80 } |
|
81 thread1.Resume(); |
|
82 |
|
83 TInt64 count = 0; |
|
84 TBuf8<4096> buffer(4096); |
|
85 r = KErrNone; |
|
86 while ((count < iInfo.iSize) && (r == KErrNone)) |
|
87 { |
|
88 r=rFile.Write(buffer,4096); |
|
89 count = count + 4096; |
|
90 } ; |
|
91 rFile.Size(filesize); |
|
92 INFO_PRINTF2(_L("after filling r = %d"),r); |
|
93 if (r == KErrTooBig) |
|
94 { |
|
95 r = rFile2.Replace(iTheFs, _L("\\TEST2.txt"), EFileWrite); |
|
96 FAT_TEST_VAL(r == KErrNone, KFileReplace, r); |
|
97 TInt64 count2 = 0; |
|
98 TBuf8<4096> buffer2(4096); |
|
99 r = KErrNone; |
|
100 while ((count2 < (iInfo.iSize - filesize)) && (r == KErrNone)) |
|
101 { |
|
102 r=rFile2.Write(buffer2,4096); |
|
103 count2 = count2 + 4096; |
|
104 } ; |
|
105 rFile2.Size(filesize2); |
|
106 } |
|
107 |
|
108 if (r == KErrDiskFull) |
|
109 { |
|
110 INFO_PRINTF2(_L("Disk full on %c:\n"), (TUint)iDriveToTest); |
|
111 SetTestStepResult(EPass); |
|
112 } |
|
113 |
|
114 |
|
115 if(r != KErrNone && r != KErrDiskFull && r != KErrTooBig) |
|
116 { |
|
117 INFO_PRINTF4(_L("Write Failed:%d FileSize:%d DiskFreeSize:%d"), r, filesize,I64INT(iInfo.iFree)); |
|
118 SetTestStepResult(EFail); |
|
119 thread1.Kill(r); |
|
120 thread1.Close(); |
|
121 return TestStepResult(); |
|
122 } |
|
123 |
|
124 if (r == KErrNone && r != KErrDiskFull) |
|
125 { |
|
126 r = rFile3.Replace(iTheFs, _L("\\TEST3.txt"), EFileWrite); |
|
127 r = iTheFs.Volume(iInfo, CurrentDrive()); |
|
128 TInt extra = iInfo.iFree; |
|
129 INFO_PRINTF2(_L("extra = %d:\n"), extra); |
|
130 rFile3.SetSize(extra); |
|
131 rFile3.Size(filesize3); |
|
132 } |
|
133 |
|
134 r = iTheFs.Volume(iInfo, CurrentDrive()); |
|
135 if (iInfo.iSize - iInfo.iFree == iInfo.iSize) |
|
136 { |
|
137 SetTestStepResult(EPass); |
|
138 } |
|
139 |
|
140 rFile.Close(); |
|
141 rFile2.Close(); |
|
142 rFile3.Close(); |
|
143 TInt64 totalFileSize = filesize + filesize2 + filesize3; |
|
144 |
|
145 r = iTheFs.Volume(iInfo, CurrentDrive()); |
|
146 INFO_PRINTF2(_L("File size1 = %d"),filesize); |
|
147 INFO_PRINTF2(_L("File size2 = %d"),filesize2); |
|
148 INFO_PRINTF2(_L("File size3 = %d"),filesize3); |
|
149 INFO_PRINTF2(_L("Total File size = %Ld"),totalFileSize); |
|
150 INFO_PRINTF4(_L("Free space on %c: %Ld KB (out of %Ld KB)\n"), |
|
151 (TUint)iDriveToTest,((iInfo.iFree) / 1024),((iInfo.iSize) / 1024)); |
|
152 |
|
153 |
|
154 thread1.Kill(r); |
|
155 thread1.Close(); |
|
156 return TestStepResult(); |
|
157 |
|
158 } |
|
159 |
|