819 TDriveName drvName = drvUnit.Name(); |
823 TDriveName drvName = drvUnit.Name(); |
820 TParse parse; |
824 TParse parse; |
821 parse.Set(KTestFile2, &drvName, NULL); |
825 parse.Set(KTestFile2, &drvName, NULL); |
822 TheDbName.Copy(parse.FullName()); |
826 TheDbName.Copy(parse.FullName()); |
823 TRAP(err, BaflUtils::EnsurePathExistsL(TheFs, TheDbName)); |
827 TRAP(err, BaflUtils::EnsurePathExistsL(TheFs, TheDbName)); |
824 TEST(err == KErrNone || err == KErrAlreadyExists); |
828 if(err == KErrNone || err == KErrAlreadyExists) |
825 (void)TheFs.Delete(TheDbName); |
829 { |
826 RFileBuf64 fbuf64(8 * 1024); |
830 (void)TheFs.Delete(TheDbName); |
827 err = fbuf64.Create(TheFs, TheDbName, EFileRead | EFileWrite); |
831 RFileBuf64 fbuf64(8 * 1024); |
828 TEST2(err, KErrNone); |
832 err = fbuf64.Create(TheFs, TheDbName, EFileRead | EFileWrite); |
829 TInt readAhead = fbuf64.SetReadAheadSize(vparam.iBlockSize, vparam.iRecReadBufSize); |
833 TEST2(err, KErrNone); |
830 TheTest.Printf(_L(" Read-ahead size=%d.\r\n"), readAhead); |
834 TInt readAhead = fbuf64.SetReadAheadSize(vparam.iBlockSize, vparam.iRecReadBufSize); |
831 fbuf64.Close(); |
835 TheTest.Printf(_L(" Read-ahead size=%d.\r\n"), readAhead); |
832 (void)TheFs.Delete(TheDbName); |
836 fbuf64.Close(); |
|
837 (void)TheFs.Delete(TheDbName); |
|
838 } |
|
839 else |
|
840 { |
|
841 TheTest.Printf(_L("Drive %C. BaflUtils::EnsurePathExistsL() has failed with err=%d.\r\n"), 'A' + drive, err); |
|
842 } |
833 } |
843 } |
834 } |
844 } |
835 else |
845 else |
836 { |
846 { |
837 TheTest.Printf(_L("Drive %C. RFs::Volume() has failed with err=%d.\r\n"), 'A' + drive, err); |
847 TheTest.Printf(_L("Drive %C. RFs::Volume() has failed with err=%d.\r\n"), 'A' + drive, err); |
1110 TheTest.Printf(_L("\r\n")); |
1120 TheTest.Printf(_L("\r\n")); |
1111 } |
1121 } |
1112 TheTest.Printf(_L("\r\n===File I/O error simulation test succeeded on iteration %d===\r\n"), cnt); |
1122 TheTest.Printf(_L("\r\n===File I/O error simulation test succeeded on iteration %d===\r\n"), cnt); |
1113 } |
1123 } |
1114 |
1124 |
|
1125 /** |
|
1126 @SYMTestCaseID PDS-SQL-UT-4207 |
|
1127 @SYMTestCaseDesc RFileBuf64::Write() OOM test. |
|
1128 The test calls RFileBuf64:Write() in an OOM |
|
1129 simulation loop and verifies that no memory is leaked. |
|
1130 The test also check that RFileBuf::DoSetCapacity() correctly operates in |
|
1131 "out of memory" situation. |
|
1132 @SYMTestActions RFileBuf64::Write() OOM test. |
|
1133 @SYMTestExpectedResults Test must not fail |
|
1134 @SYMTestPriority High |
|
1135 @SYMDEF 380056 |
|
1136 */ |
|
1137 void WriteOomTest() |
|
1138 { |
|
1139 HBufC8* databuf = HBufC8::New(KPageSize); |
|
1140 TEST(databuf != NULL); |
|
1141 TPtr8 dataptr = databuf->Des(); |
|
1142 dataptr.SetLength(KPageSize); |
|
1143 dataptr.Fill(TChar(KChar)); |
|
1144 |
|
1145 TInt err = KErrNoMemory; |
|
1146 TInt failingAllocationNo = 0; |
|
1147 TheTest.Printf(_L("Iteration:\r\n")); |
|
1148 while(err == KErrNoMemory) |
|
1149 { |
|
1150 TheTest.Printf(_L(" %d"), ++failingAllocationNo); |
|
1151 |
|
1152 (void)TheFs.Delete(KTestFile); |
|
1153 |
|
1154 MarkHandles(); |
|
1155 MarkAllocatedCells(); |
|
1156 |
|
1157 __UHEAP_MARK; |
|
1158 __UHEAP_SETBURSTFAIL(RAllocator::EBurstFailNext, failingAllocationNo, KBurstRate); |
|
1159 |
|
1160 const TInt KDefaultBufCapacity = 1024; |
|
1161 RFileBuf64 fbuf(KDefaultBufCapacity); |
|
1162 err = fbuf.Create(TheFs, KTestFile, EFileWrite | EFileRead); |
|
1163 if(err == KErrNone) |
|
1164 { |
|
1165 err = fbuf.Write(0LL, dataptr); |
|
1166 } |
|
1167 fbuf.Close(); |
|
1168 |
|
1169 __UHEAP_RESET; |
|
1170 __UHEAP_MARKEND; |
|
1171 |
|
1172 CheckAllocatedCells(); |
|
1173 CheckHandles(); |
|
1174 } |
|
1175 TEST2(err, KErrNone); |
|
1176 RFile64 file; |
|
1177 err = file.Open(TheFs, KTestFile, EFileRead); |
|
1178 TEST2(err, KErrNone); |
|
1179 dataptr.Zero(); |
|
1180 err = file.Read(dataptr); |
|
1181 TEST2(err, KErrNone); |
|
1182 file.Close(); |
|
1183 TEST2(dataptr.Length(), KPageSize); |
|
1184 for(TInt i=0;i<KPageSize;++i) |
|
1185 { |
|
1186 TEST(dataptr[i] == KChar); |
|
1187 } |
|
1188 TheTest.Printf(_L("\r\n=== OOM Test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo); |
|
1189 |
|
1190 //The file is left undeleted - to be used in ReadOomTest(). |
|
1191 delete databuf; |
|
1192 } |
|
1193 |
|
1194 /** |
|
1195 @SYMTestCaseID PDS-SQL-UT-4208 |
|
1196 @SYMTestCaseDesc RFileBuf64::Read() OOM test. |
|
1197 The test calls RFileBuf64:Read() in an OOM |
|
1198 simulation loop and verifies that no memory is leaked. |
|
1199 The test also check that RFileBuf::DoSetCapacity() correctly operates in |
|
1200 "out of memory" situation. |
|
1201 @SYMTestActions RFileBuf64::Read() OOM test. |
|
1202 @SYMTestExpectedResults Test must not fail |
|
1203 @SYMTestPriority High |
|
1204 @SYMDEF 380056 |
|
1205 */ |
|
1206 void ReadOomTest() |
|
1207 { |
|
1208 HBufC8* databuf = HBufC8::New(KPageSize); |
|
1209 TEST(databuf != NULL); |
|
1210 TPtr8 dataptr = databuf->Des(); |
|
1211 |
|
1212 TInt err = KErrNoMemory; |
|
1213 TInt failingAllocationNo = 0; |
|
1214 TheTest.Printf(_L("Iteration:\r\n")); |
|
1215 while(err == KErrNoMemory) |
|
1216 { |
|
1217 TheTest.Printf(_L(" %d"), ++failingAllocationNo); |
|
1218 |
|
1219 MarkHandles(); |
|
1220 MarkAllocatedCells(); |
|
1221 |
|
1222 __UHEAP_MARK; |
|
1223 __UHEAP_SETBURSTFAIL(RAllocator::EBurstFailNext, failingAllocationNo, KBurstRate); |
|
1224 |
|
1225 const TInt KDefaultBufCapacity = 1024; |
|
1226 RFileBuf64 fbuf(KDefaultBufCapacity); |
|
1227 err = fbuf.Open(TheFs, KTestFile, EFileRead); |
|
1228 if(err == KErrNone) |
|
1229 { |
|
1230 err = fbuf.Read(0LL, dataptr); |
|
1231 } |
|
1232 fbuf.Close(); |
|
1233 |
|
1234 __UHEAP_RESET; |
|
1235 __UHEAP_MARKEND; |
|
1236 |
|
1237 CheckAllocatedCells(); |
|
1238 CheckHandles(); |
|
1239 } |
|
1240 TEST2(err, KErrNone); |
|
1241 RFile64 file; |
|
1242 err = file.Open(TheFs, KTestFile, EFileRead); |
|
1243 TEST2(err, KErrNone); |
|
1244 dataptr.Zero(); |
|
1245 err = file.Read(dataptr); |
|
1246 TEST2(err, KErrNone); |
|
1247 file.Close(); |
|
1248 TEST2(dataptr.Length(), KPageSize); |
|
1249 for(TInt i=0;i<KPageSize;++i) |
|
1250 { |
|
1251 TEST(dataptr[i] == KChar); |
|
1252 } |
|
1253 TheTest.Printf(_L("\r\n=== OOM Test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo); |
|
1254 |
|
1255 (void)TheFs.Delete(KTestFile); |
|
1256 delete databuf; |
|
1257 } |
|
1258 |
1115 void DoTests() |
1259 void DoTests() |
1116 { |
1260 { |
1117 TheTest.Start(_L(" @SYMTestCaseID:PDS-SQL-UT-4132 RFileBuf64 write test 1")); |
1261 TheTest.Start(_L(" @SYMTestCaseID:PDS-SQL-UT-4132 RFileBuf64 write test 1")); |
1118 WriteTest1(); |
1262 WriteTest1(); |
1119 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4133 RFileBuf64 write test 2")); |
1263 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4133 RFileBuf64 write test 2")); |
1144 OomTest(EOomCreateTest); |
1288 OomTest(EOomCreateTest); |
1145 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4142 RFileBuf64::Open() OOM test")); |
1289 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4142 RFileBuf64::Open() OOM test")); |
1146 OomTest(EOomOpenTest); |
1290 OomTest(EOomOpenTest); |
1147 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4142 RFileBuf64::Temp() OOM test")); |
1291 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4142 RFileBuf64::Temp() OOM test")); |
1148 OomTest(EOomTempTest); |
1292 OomTest(EOomTempTest); |
|
1293 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4207 RFileBuf64::Write() OOM test")); |
|
1294 WriteOomTest(); |
|
1295 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4208 RFileBuf64::Read() OOM test")); |
|
1296 ReadOomTest(); |
1149 |
1297 |
1150 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4195 RFileBuf64::Create() file I/O error simulation test")); |
1298 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4195 RFileBuf64::Create() file I/O error simulation test")); |
1151 CreateFileIoErrTest(); |
1299 CreateFileIoErrTest(); |
1152 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4196 RFileBuf64::Open() file I/O error simulation test")); |
1300 TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4196 RFileBuf64::Open() file I/O error simulation test")); |
1153 OpenFileIoErrTest(); |
1301 OpenFileIoErrTest(); |