28 RTest test(_L("t_falsespace")); |
28 RTest test(_L("t_falsespace")); |
29 |
29 |
30 const TInt KNumberThreads=2; |
30 const TInt KNumberThreads=2; |
31 const TInt KHeapSize=0x2000; |
31 const TInt KHeapSize=0x2000; |
32 |
32 |
|
33 //-- this is taken from the file server. Hardcoded constant that specifies session limits on reserving the drive space |
|
34 const TInt KMaxSessionDriveReserved =0x10000; |
|
35 |
33 static TInt RsrvSpaceThread(TAny* aArg); |
36 static TInt RsrvSpaceThread(TAny* aArg); |
34 static TInt SessCloseThread(TAny* aArg); |
37 static TInt SessCloseThread(TAny* aArg); |
35 static void GetFreeDiskSpace(TInt64 &aFree); |
38 static void GetFreeDiskSpace(TInt64 &aFree); |
36 |
39 |
37 |
40 |
78 test(s.Int()==KRequestPending); |
81 test(s.Int()==KRequestPending); |
79 aSession.Close(); |
82 aSession.Close(); |
80 User::WaitForRequest(s); |
83 User::WaitForRequest(s); |
81 } |
84 } |
82 |
85 |
|
86 //----------------------------------------------------------------------------- |
|
87 /** |
|
88 Get a cluster size for the currently mounted FS (if it supports clusters). |
|
89 @return 0 if there was an error (e.g. cluster size query is not supported), otherwise a cluster size |
|
90 */ |
|
91 static TUint32 FsClusterSize() |
|
92 { |
|
93 TVolumeIOParamInfo volIop; |
|
94 TInt nRes = TheFs.VolumeIOParam(gTestDrive, volIop); |
|
95 |
|
96 if(nRes != KErrNone || volIop.iClusterSize < 512 || !IsPowerOf2(volIop.iClusterSize)) |
|
97 { |
|
98 test.Printf(_L("FsClusterSize() The FS hasn't reported a cluster size\n")); |
|
99 return 0; |
|
100 } |
|
101 |
|
102 return volIop.iClusterSize; |
|
103 } |
83 |
104 |
84 static TInt CreateFileX(const TDesC& aBaseName,TInt aX, TInt aFileSize) |
105 static TInt CreateFileX(const TDesC& aBaseName,TInt aX, TInt aFileSize) |
85 // |
106 // |
86 // Create a large file. Return KErrEof or KErrNone |
107 // Create a large file. Return KErrEof or KErrNone |
87 // |
108 // |
145 static void FillUpDisk() |
166 static void FillUpDisk() |
146 // |
167 // |
147 // Test that a full disk is ok |
168 // Test that a full disk is ok |
148 // |
169 // |
149 { |
170 { |
150 |
171 test.Next(_L("Fill disk to capacity\n")); |
151 test.Start(_L("Fill disk to capacity")); |
|
152 TInt r=TheFs.MkDirAll(KBasePath); |
172 TInt r=TheFs.MkDirAll(KBasePath); |
153 test_Value(r, r == KErrNone || r==KErrAlreadyExists); |
173 test_Value(r, r == KErrNone || r==KErrAlreadyExists); |
154 gCount=0; |
174 gCount=0; |
155 TFileName sessionPath; |
175 TFileName sessionPath; |
156 r=TheFs.SessionPath(sessionPath); |
176 r=TheFs.SessionPath(sessionPath); |
317 { |
335 { |
318 r = sessions[i].Connect(); |
336 r = sessions[i].Connect(); |
319 test_KErrNone(r); |
337 test_KErrNone(r); |
320 } |
338 } |
321 |
339 |
322 test.Next(_L("Test breaching sesson reserve limit")); |
340 test.Next(_L("Test breaching sesson reserve limit\n")); |
323 r=sessions[0].ReserveDriveSpace(gTestDrive,0x10001); |
341 r=sessions[0].ReserveDriveSpace(gTestDrive,0x10001); |
324 test_Value(r, r == KErrArgument); |
342 test_Value(r, r == KErrArgument); |
325 |
343 |
326 //Get Volume Free Space |
344 //Get Volume Free Space |
327 r = sessions[0].Volume(v, gTestDrive); |
345 r = sessions[0].Volume(v, gTestDrive); |
328 |
346 |
329 if(v.iFree > 0x100000) |
347 if(v.iFree > 0x100000) |
330 { |
348 { |
331 test.Next(_L("Test breaching drive reserve limit")); |
349 test.Next(_L("Test breaching drive reserve limit\n")); |
332 |
350 |
333 for (i=0; i<16; i++) |
351 for (i=0; i<16; i++) |
334 { |
352 { |
335 r=sessions[i].ReserveDriveSpace(gTestDrive,0x10000); |
353 r=sessions[i].ReserveDriveSpace(gTestDrive,0x10000); |
336 test_KErrNone(r); |
354 test_KErrNone(r); |
341 test_Value(r, r == KErrTooBig); |
359 test_Value(r, r == KErrTooBig); |
342 } |
360 } |
343 else |
361 else |
344 { |
362 { |
345 test.Printf(_L("Drive too small: breaching drive reserve limit test skipped\n")); |
363 test.Printf(_L("Drive too small: breaching drive reserve limit test skipped\n")); |
346 test.Next(_L("Testing exhausting available drive free space instead")); |
364 test.Next(_L("Testing exhausting available drive free space instead\n")); |
347 |
365 |
348 for(i=0; (v.iFree -= 0x10000) >= 0; i++) |
366 for(i=0; (v.iFree -= 0x10000) >= 0; i++) |
349 { |
367 { |
350 r=sessions[i].ReserveDriveSpace(gTestDrive,0x10000); |
368 r=sessions[i].ReserveDriveSpace(gTestDrive,0x10000); |
351 test_KErrNone(r); |
369 test_KErrNone(r); |
437 // |
455 // |
438 // Test real out of disk space conditions i.e. properly run out of disk space and try to |
456 // Test real out of disk space conditions i.e. properly run out of disk space and try to |
439 // reserve an area etc |
457 // reserve an area etc |
440 // |
458 // |
441 { |
459 { |
442 test.Next(_L("Test Filling disk and using APIs")); |
460 test.Next(_L("Test Filling disk and using APIs\n")); |
443 |
461 |
444 if(IsTestingLFFS()) |
462 if(IsTestingLFFS()) |
445 { |
463 { |
446 //-- This test is not valid for LFFS, because free space on this FS can change itself because of some |
464 //-- This test is not valid for LFFS, because free space on this FS can change itself because of some internal FS activities |
447 //-- internal FS activities |
|
448 test.Printf(_L("This test is inconsistent on LFFS\n")); |
465 test.Printf(_L("This test is inconsistent on LFFS\n")); |
|
466 return; |
|
467 } |
|
468 |
|
469 |
|
470 const TInt KThreshold = 0x10000; |
|
471 |
|
472 //-- check that the cluster size doesn't exceed the max. limit |
|
473 const TInt KClusterSz = FsClusterSize(); |
|
474 if(KClusterSz > KThreshold) |
|
475 { |
|
476 test.Printf(_L("The cluster size(%d) is bigger than threshold to test (%d)! Skipping the test!\n"), KClusterSz, KThreshold); |
449 return; |
477 return; |
450 } |
478 } |
451 |
479 |
452 FormatDrive(); |
480 FormatDrive(); |
453 |
481 |
491 freeB=v.iFree; |
519 freeB=v.iFree; |
492 |
520 |
493 r=fs.ReleaseReserveAccess(gTestDrive); //release reserve space |
521 r=fs.ReleaseReserveAccess(gTestDrive); //release reserve space |
494 test_KErrNone(r); |
522 test_KErrNone(r); |
495 |
523 |
496 test(freeA == (freeB - 0x10000)); //test difference in space is equal to the amount reserved |
524 test(freeA == (freeB - KThreshold)); //test difference in space is equal to the amount reserved |
497 |
525 |
498 r=fs.Volume(v,gTestDrive); //get disk space |
526 r=fs.Volume(v,gTestDrive); //get disk space |
499 test_KErrNone(r); |
527 test_KErrNone(r); |
500 freeB=v.iFree; |
528 freeB=v.iFree; |
501 test(freeA == freeB); //check reading is still correct |
529 test(freeA == freeB); //check reading is still correct |
785 static void Test7() |
813 static void Test7() |
786 // |
814 // |
787 // Tests notifier events for sessions with and without reserved access |
815 // Tests notifier events for sessions with and without reserved access |
788 // |
816 // |
789 { |
817 { |
|
818 test.Next(_L("Test reserved access notification\n")); |
|
819 |
790 if(IsTestingLFFS()) |
820 if(IsTestingLFFS()) |
791 { |
821 { |
792 // This test is not valid for LFFS... |
822 // This test is not valid for LFFS... |
793 test.Printf(_L("Test reserved access notification not run for LFFS\n")); |
823 test.Printf(_L("Test reserved access notification not run for LFFS\n")); |
794 return; |
824 return; |
795 } |
825 } |
796 |
826 |
797 |
|
798 test.Next(_L("Test reserved access notification")); |
|
799 |
|
800 FormatDrive(); |
827 FormatDrive(); |
|
828 |
|
829 //-- find out the cluster size |
|
830 const TInt KClusterSz = FsClusterSize(); |
|
831 if(!IsPowerOf2(KClusterSz)) |
|
832 { |
|
833 test.Printf(_L("The FS hasn't reported a cluster size. The test is inconsistent, skipping\n")); |
|
834 return; |
|
835 } |
|
836 |
|
837 //-- check that the cluster size doesn't exceed the max. limit |
|
838 if(KClusterSz > KMaxSessionDriveReserved) |
|
839 { |
|
840 test.Printf(_L("The cluster size(%d) is bigger than reserve limit (%d)! Skipping the test!\n"), KClusterSz, KMaxSessionDriveReserved); |
|
841 return; |
|
842 } |
|
843 |
|
844 |
|
845 const TInt resSpace = Max(0x1000, KClusterSz); |
801 |
846 |
802 RFs theNrm; |
847 RFs theNrm; |
803 RFs theRes; |
848 RFs theRes; |
804 |
849 |
805 TInt err = theNrm.Connect(); |
850 TInt err = theNrm.Connect(); |
821 fileName[0] = (TUint16)gCh; |
866 fileName[0] = (TUint16)gCh; |
822 |
867 |
823 err = theTestSession.Connect(); |
868 err = theTestSession.Connect(); |
824 test_KErrNone(err); |
869 test_KErrNone(err); |
825 |
870 |
826 // determine the cluster size |
|
827 RFile theFile; |
|
828 err=theFile.Replace(theTestSession, fileName, EFileShareAny | EFileWrite); |
|
829 test_KErrNone(err); |
|
830 |
|
831 // Neither notifier should be triggered here |
|
832 err = theFile.SetSize(1); |
|
833 test(KErrNone == err); |
|
834 theFile.Close(); |
|
835 |
|
836 TInt64 newFreeSpace; |
|
837 GetFreeDiskSpace(newFreeSpace); |
|
838 TInt clusterSize = TInt(freeSpace - newFreeSpace); |
|
839 theTestSession.Delete(fileName); |
|
840 GetFreeDiskSpace(newFreeSpace); |
|
841 test (newFreeSpace == freeSpace); |
|
842 |
|
843 TInt resSpace = Max(0x1000, clusterSize); |
|
844 |
|
845 TVolumeInfo volInfo; |
871 TVolumeInfo volInfo; |
846 theNrm.Volume(volInfo, gTestDrive); |
872 theNrm.Volume(volInfo, gTestDrive); |
847 test(volInfo.iFree == freeSpace); |
873 test(volInfo.iFree == freeSpace); |
848 |
874 |
849 err = theRes.ReserveDriveSpace(gTestDrive, resSpace); |
875 err = theRes.ReserveDriveSpace(gTestDrive, resSpace); |
855 test(volInfo.iFree == freeSpace); |
881 test(volInfo.iFree == freeSpace); |
856 |
882 |
857 theNrm.Volume(volInfo, gTestDrive); |
883 theNrm.Volume(volInfo, gTestDrive); |
858 test(volInfo.iFree == freeSpace - resSpace); |
884 test(volInfo.iFree == freeSpace - resSpace); |
859 |
885 |
|
886 |
|
887 RFile theFile; |
860 |
888 |
861 // |
889 // |
862 // Register the notifiers and verify that the only the "Normal" |
890 // Register the notifiers and verify that the only the "Normal" |
863 // and not the "Reserved" session is triggered. |
891 // and not the "Reserved" session is triggered. |
864 // |
892 // |
988 */ |
1016 */ |
989 static void TestFAT4G_Boundary() |
1017 static void TestFAT4G_Boundary() |
990 { |
1018 { |
991 const TInt64 K4Gig = 4*(TInt64)K1GigaByte; |
1019 const TInt64 K4Gig = 4*(TInt64)K1GigaByte; |
992 |
1020 |
993 test.Next(_L("Test files crossing 4G boundary on FAT")); |
1021 test.Next(_L("Test files crossing 4G boundary on FAT\n")); |
994 |
1022 |
995 if(!Is_Fat32(TheFs, gTestDrive)) |
1023 if(!Is_Fat32(TheFs, gTestDrive)) |
996 { |
1024 { |
997 test.Printf(_L("This test requires FAT32. Skipping.\n")); |
1025 test.Printf(_L("This test requires FAT32. Skipping.\n")); |
998 return; |
1026 return; |
1054 } |
1082 } |
1055 } |
1083 } |
1056 |
1084 |
1057 void TestRAMDriveNotification() |
1085 void TestRAMDriveNotification() |
1058 { |
1086 { |
1059 test.Next(_L("Verifying RFs::ReserveDriveSpace() triggers RFs::NotifyDiskSpace() events")); |
1087 test.Next(_L("Verifying RFs::ReserveDriveSpace() triggers RFs::NotifyDiskSpace() events\n")); |
1060 |
1088 |
1061 TInt64 freeSpace; |
1089 TInt64 freeSpace; |
1062 GetFreeDiskSpace(freeSpace); |
1090 GetFreeDiskSpace(freeSpace); |
1063 test.Printf(_L("free space: 0x%Lx bytes\n"), freeSpace); |
1091 test.Printf(_L("free space: 0x%Lx bytes\n"), freeSpace); |
1064 |
1092 |
1065 // set a notification on half the amount we plan to reserve |
1093 // set a notification on half the amount we plan to reserve |
1066 TInt reserve = 4096; |
1094 TInt reserve = 4096; |
1067 TInt64 trigger = freeSpace - 2048; |
1095 TInt64 trigger = freeSpace - 2048; |
1068 test.Printf(_L("setting notification for space to fall below: 0x%Lx bytes ... "), trigger); |
1096 test.Printf(_L("setting notification for space to fall below: 0x%Lx bytes ... \n"), trigger); |
1069 TRequestStatus stat; |
1097 TRequestStatus stat; |
1070 TheFs.NotifyDiskSpace(trigger, gTestDrive, stat); |
1098 TheFs.NotifyDiskSpace(trigger, gTestDrive, stat); |
1071 test_Value(stat.Int(), stat == KRequestPending); |
1099 test_Value(stat.Int(), stat == KRequestPending); |
1072 test.Printf(_L("ok\n")); |
1100 test.Printf(_L("ok\n")); |
1073 |
1101 |
1074 // reserve the space and validate that this triggers the notification |
1102 // reserve the space and validate that this triggers the notification |
1075 test.Printf(_L("reserving 0x%x bytes ..."), reserve); |
1103 test.Printf(_L("reserving 0x%x bytes ...\n"), reserve); |
1076 TInt r = TheFs.ReserveDriveSpace(gTestDrive, reserve); |
1104 TInt r = TheFs.ReserveDriveSpace(gTestDrive, reserve); |
1077 test_KErrNone(r); |
1105 test_KErrNone(r); |
1078 test.Printf(_L("ok\n")); |
1106 test.Printf(_L("ok\n")); |
1079 |
1107 |
1080 test.Printf(_L("validating that the disk space notification triggered ... ")); |
1108 test.Printf(_L("validating that the disk space notification triggered ...\n")); |
1081 User::After(2000000); // 2 seconds should be enough to cause the trigger |
1109 User::After(2000000); // 2 seconds should be enough to cause the trigger |
1082 test_Value(stat.Int(), stat == KErrNone); |
1110 test_Value(stat.Int(), stat == KErrNone); |
1083 test.Printf(_L("ok\n")); |
1111 test.Printf(_L("ok\n")); |
1084 } |
1112 } |
1085 |
1113 |
1088 /** |
1116 /** |
1089 Test that the reserving some drive space does not takes more space than required. |
1117 Test that the reserving some drive space does not takes more space than required. |
1090 */ |
1118 */ |
1091 void Test0() |
1119 void Test0() |
1092 { |
1120 { |
1093 test.Next(_L("test ReserveDriveSpace threshold")); |
1121 test.Next(_L("test ReserveDriveSpace threshold\n")); |
1094 |
1122 |
1095 TInt nRes; |
1123 TInt nRes; |
1096 TVolumeIOParamInfo volIop; |
|
1097 TInt64 freespace=0; |
1124 TInt64 freespace=0; |
1098 |
1125 |
1099 //-- 1. format the volume |
1126 //-- 1. format the volume |
1100 FormatDrive(); |
1127 FormatDrive(); |
1101 |
1128 |
1102 GetFreeDiskSpace(freespace); |
1129 GetFreeDiskSpace(freespace); |
1103 const TInt64 freeSpace1 = freespace; //-- initial amount of free space on the volume |
1130 const TInt64 freeSpace1 = freespace; //-- initial amount of free space on the volume |
1104 |
1131 |
1105 nRes = TheFs.VolumeIOParam(gTestDrive, volIop); |
1132 const TInt KClusterSz = FsClusterSize(); |
1106 test_KErrNone(nRes); |
|
1107 const TInt KClusterSz = volIop.iClusterSize; |
|
1108 if(!IsPowerOf2(KClusterSz)) |
1133 if(!IsPowerOf2(KClusterSz)) |
1109 { |
1134 { |
1110 test.Next(_L("The FS hasn't reported a cluster size. The test is inconsistent, skipping")); |
1135 test.Printf(_L("The FS hasn't reported a cluster size. The test is inconsistent, skipping\n")); |
1111 return; |
1136 return; |
1112 } |
1137 } |
|
1138 |
|
1139 //-- check that the cluster size doesn't exceed the max. limit |
|
1140 if(KClusterSz > KMaxSessionDriveReserved) |
|
1141 { |
|
1142 test.Printf(_L("The cluster size(%d) is bigger than reserve limit (%d)! Skipping the test!\n"), KClusterSz, KMaxSessionDriveReserved); |
|
1143 return; |
|
1144 } |
|
1145 |
1113 |
1146 |
1114 //-- reserve exactly 1 cluster worth drive space. |
1147 //-- reserve exactly 1 cluster worth drive space. |
1115 nRes = TheFs.ReserveDriveSpace(gTestDrive, KClusterSz); |
1148 nRes = TheFs.ReserveDriveSpace(gTestDrive, KClusterSz); |
1116 test_KErrNone(nRes); |
1149 test_KErrNone(nRes); |
1117 |
1150 |
1160 Fat_Test_Utils::SetConsole(test.Console()); |
1193 Fat_Test_Utils::SetConsole(test.Console()); |
1161 |
1194 |
1162 // If TESTFAST mode (for automated test builds) is set, don't run LFFS tests. |
1195 // If TESTFAST mode (for automated test builds) is set, don't run LFFS tests. |
1163 if ((UserSvr::DebugMask(2) & 0x00000002) && IsTestingLFFS()) |
1196 if ((UserSvr::DebugMask(2) & 0x00000002) && IsTestingLFFS()) |
1164 { |
1197 { |
1165 test.Printf(_L("TEST NOT RUN FOR LFFS DRIVE")); |
1198 test.Printf(_L("TEST NOT RUN FOR LFFS DRIVE\n")); |
1166 return; |
1199 return; |
1167 } |
1200 } |
1168 |
1201 |
1169 //get the number of the drive we are currently testing |
1202 //get the number of the drive we are currently testing |
1170 TInt r=0; |
1203 TInt r=0; |