432 test((aSize%aBlockSize) == 0); // Ensure the size of the file is a multiple of the block size |
432 test((aSize%aBlockSize) == 0); // Ensure the size of the file is a multiple of the block size |
433 |
433 |
434 |
434 |
435 // delete file first to ensure it's contents are not in the cache (file may be be on the closed file queue) |
435 // delete file first to ensure it's contents are not in the cache (file may be be on the closed file queue) |
436 r = fs.Delete(aFile); |
436 r = fs.Delete(aFile); |
437 test(r == KErrNone || r == KErrNotFound); |
437 test_Value(r, r == KErrNone || r == KErrNotFound); |
438 |
438 |
439 r = aFileWrite.Replace(fs,aFile,EFileShareAny|EFileWrite|EFileReadDirectIO|EFileWriteDirectIO); |
439 r = aFileWrite.Replace(fs,aFile,EFileShareAny|EFileWrite|EFileReadDirectIO|EFileWriteDirectIO); |
440 test_KErrNone(r); |
440 test_KErrNone(r); |
441 |
441 |
442 TInt j = 0, i = 0; |
442 TInt j = 0, i = 0; |
554 TRequestStatus status[KWaitRequestsTableSize]; |
554 TRequestStatus status[KWaitRequestsTableSize]; |
555 RFs fs; |
555 RFs fs; |
556 RFile file; |
556 RFile file; |
557 |
557 |
558 TInt r = fs.Connect(); |
558 TInt r = fs.Connect(); |
559 test (r == KErrNone); |
559 test_KErrNone(r); |
560 |
560 |
561 startTime.HomeTime(); |
561 startTime.HomeTime(); |
562 |
562 |
563 ReadFileAsync(fs, file, aFile, KBlockSize, status, aSize); |
563 ReadFileAsync(fs, file, aFile, KBlockSize, status, aSize); |
564 WaitForAll(status, aSize/KBlockSize); |
564 WaitForAll(status, aSize/KBlockSize); |
693 else |
693 else |
694 test((time2 <= time) && (time3 < time)); |
694 test((time2 <= time) && (time3 < time)); |
695 #endif |
695 #endif |
696 |
696 |
697 r = DeleteAll(gSessionPath); |
697 r = DeleteAll(gSessionPath); |
698 test(r == KErrNone || r == KErrInUse); |
698 test_Value(r, r == KErrNone || r == KErrInUse); |
699 |
699 |
700 // Simple case filling/reading the cache from different threads |
700 // Simple case filling/reading the cache from different threads |
701 test.Next(_L("File fits in: read sync (another thread) + read sync + read async\n")); |
701 test.Next(_L("File fits in: read sync (another thread) + read sync + read async\n")); |
702 gCurrentFile = gSecondFile; |
702 gCurrentFile = gSecondFile; |
703 gCurrentFileSize = gSecondFileSize; |
703 gCurrentFileSize = gSecondFileSize; |
713 |
713 |
714 test.Printf(_L("Time to create the file from a thread: %d ms\n"),tcreate); |
714 test.Printf(_L("Time to create the file from a thread: %d ms\n"),tcreate); |
715 |
715 |
716 buf = _L("Read File"); |
716 buf = _L("Read File"); |
717 r = gThread2.Create(buf,ReadFileT,KDefaultStackSize,KHeapSize,KMaxHeapSize,NULL); |
717 r = gThread2.Create(buf,ReadFileT,KDefaultStackSize,KHeapSize,KMaxHeapSize,NULL); |
718 test(r == KErrNone); |
718 test_KErrNone(r); |
719 |
719 |
720 gThread2.Resume(); |
720 gThread2.Resume(); |
721 client.Wait(); |
721 client.Wait(); |
722 |
722 |
723 gThread1.Close(); |
723 gThread1.Close(); |
735 else |
735 else |
736 test((time2<=time) && (time3<time)); |
736 test((time2<=time) && (time3<time)); |
737 #endif |
737 #endif |
738 |
738 |
739 r = DeleteAll(gSessionPath); |
739 r = DeleteAll(gSessionPath); |
740 test(r == KErrNone || r == KErrInUse); |
740 test_Value(r, r == KErrNone || r == KErrInUse); |
741 |
741 |
742 |
742 |
743 test.Next(_L("File doesn't fit in: read sync + read sync + read async\n")); |
743 test.Next(_L("File doesn't fit in: read sync + read sync + read async\n")); |
744 |
744 |
745 tcreate = WriteTestFile(gFirstFile,gFirstFileSize); |
745 tcreate = WriteTestFile(gFirstFile,gFirstFileSize); |
758 // test((time2 <= time) && (time3 < time)); |
758 // test((time2 <= time) && (time3 < time)); |
759 #endif |
759 #endif |
760 |
760 |
761 |
761 |
762 r = DeleteAll(gSessionPath); |
762 r = DeleteAll(gSessionPath); |
763 test(r == KErrNone || r == KErrInUse); |
763 test_Value(r, r == KErrNone || r == KErrInUse); |
764 |
764 |
765 |
765 |
766 test.Next(_L("File doesn't fit in: read sync (another thread) + read sync + read async\n")); |
766 test.Next(_L("File doesn't fit in: read sync (another thread) + read sync + read async\n")); |
767 gCurrentFile = gFirstFile; |
767 gCurrentFile = gFirstFile; |
768 gCurrentFileSize = gFirstFileSize; |
768 gCurrentFileSize = gFirstFileSize; |
778 |
778 |
779 test.Printf(_L("Time to create the file from a thread: %d ms\n"),tcreate); |
779 test.Printf(_L("Time to create the file from a thread: %d ms\n"),tcreate); |
780 |
780 |
781 buf = _L("Read Big File"); |
781 buf = _L("Read Big File"); |
782 r = gThread2.Create(buf,ReadFileT,KDefaultStackSize,KHeapSize,KMaxHeapSize,NULL); |
782 r = gThread2.Create(buf,ReadFileT,KDefaultStackSize,KHeapSize,KMaxHeapSize,NULL); |
783 test(r == KErrNone); |
783 test_KErrNone(r); |
784 |
784 |
785 gThread2.Resume(); |
785 gThread2.Resume(); |
786 client.Wait(); |
786 client.Wait(); |
787 |
787 |
788 gThread1.Close(); |
788 gThread1.Close(); |
821 |
821 |
822 TRAPD(res2,lBufSec = HBufC8::NewL(KBlockSize+1)); |
822 TRAPD(res2,lBufSec = HBufC8::NewL(KBlockSize+1)); |
823 test(res2 == KErrNone && lBufSec != NULL); |
823 test(res2 == KErrNone && lBufSec != NULL); |
824 lBufReadPtr.Set(lBufSec->Des()); |
824 lBufReadPtr.Set(lBufSec->Des()); |
825 |
825 |
826 test(r == KErrNone); |
826 test_KErrNone(r); |
827 r = fs.SetSessionPath(gSessionPath); |
827 r = fs.SetSessionPath(gSessionPath); |
828 |
828 |
829 |
829 |
830 // delete file first to ensure it's contents are not in the cache (file may be be on the closed file queue) |
830 // delete file first to ensure it's contents are not in the cache (file may be be on the closed file queue) |
831 r = fs.Delete(gFirstFile); |
831 r = fs.Delete(gFirstFile); |
832 test(r == KErrNone || r == KErrNotFound); |
832 test_Value(r, r == KErrNone || r == KErrNotFound); |
833 |
833 |
834 r = file.Create(fs,gFirstFile,EFileShareAny|EFileWrite|EFileReadDirectIO|EFileWriteDirectIO); |
834 r = file.Create(fs,gFirstFile,EFileShareAny|EFileWrite|EFileReadDirectIO|EFileWriteDirectIO); |
835 |
835 |
836 if(r == KErrAlreadyExists) |
836 if(r == KErrAlreadyExists) |
837 { |
837 { |
942 r = gThread1.Create(buf,WriteFileT,KDefaultStackSize,KHeapSize,KMaxHeapSize,NULL); |
942 r = gThread1.Create(buf,WriteFileT,KDefaultStackSize,KHeapSize,KMaxHeapSize,NULL); |
943 test_KErrNone(r); |
943 test_KErrNone(r); |
944 |
944 |
945 TBuf<20> buf2 = _L("Write Two Files 2"); |
945 TBuf<20> buf2 = _L("Write Two Files 2"); |
946 r = gThread2.Create(buf2,WriteFileT2,KDefaultStackSize*2,KHeapSize,KMaxHeapSize,NULL); |
946 r = gThread2.Create(buf2,WriteFileT2,KDefaultStackSize*2,KHeapSize,KMaxHeapSize,NULL); |
947 test(r == KErrNone); |
947 test_KErrNone(r); |
948 |
948 |
949 gThread1.Resume(); |
949 gThread1.Resume(); |
950 gThread2.Resume(); |
950 gThread2.Resume(); |
951 client.Wait(); |
951 client.Wait(); |
952 client.Wait(); |
952 client.Wait(); |
982 LOCAL_C TInt CreateFile(TAny* ) |
982 LOCAL_C TInt CreateFile(TAny* ) |
983 { |
983 { |
984 RTest test(_L("T_RCACHE")); |
984 RTest test(_L("T_RCACHE")); |
985 RFs fs; |
985 RFs fs; |
986 TInt r = fs.Connect(); |
986 TInt r = fs.Connect(); |
987 test(r == KErrNone); |
987 test_KErrNone(r); |
988 |
988 |
989 r = fs.SetSessionPath(gSessionPath); |
989 r = fs.SetSessionPath(gSessionPath); |
990 test(r == KErrNone); |
990 test_KErrNone(r); |
991 |
991 |
992 r = WriteFile(fs, gSecondFile, gSecondFileSize, KBlockSize, gBufWritePtr, EThreadSignal); |
992 r = WriteFile(fs, gSecondFile, gSecondFileSize, KBlockSize, gBufWritePtr, EThreadSignal); |
993 test_KErrNone(r); |
993 test_KErrNone(r); |
994 |
994 |
995 return KErrNone; |
995 return KErrNone; |
1067 RFile fileWrite; |
1067 RFile fileWrite; |
1068 HBufC8* dummy = NULL; |
1068 HBufC8* dummy = NULL; |
1069 TPtr8 dummyPtr(NULL, 0); |
1069 TPtr8 dummyPtr(NULL, 0); |
1070 |
1070 |
1071 TRAPD(res,dummy = HBufC8::NewL(4)); |
1071 TRAPD(res,dummy = HBufC8::NewL(4)); |
1072 test(res == KErrNone && dummy != NULL); |
1072 test_Value(res, res== KErrNone && dummy != NULL); |
1073 |
1073 |
1074 dummyPtr.Set(dummy->Des()); |
1074 dummyPtr.Set(dummy->Des()); |
1075 FillBuffer(dummyPtr, 4, '1'); |
1075 FillBuffer(dummyPtr, 4, '1'); |
1076 |
1076 |
1077 r = fileWrite.Open(TheFs,gSecondFile,EFileShareAny|EFileWrite|EFileReadDirectIO|EFileWriteDirectIO); |
1077 r = fileWrite.Open(TheFs,gSecondFile,EFileShareAny|EFileWrite|EFileReadDirectIO|EFileWriteDirectIO); |
1295 |
1295 |
1296 // create a big buffer to speed things up |
1296 // create a big buffer to speed things up |
1297 HBufC8* bigBuf = NULL; |
1297 HBufC8* bigBuf = NULL; |
1298 const TInt KBigBifferSize = 32 * 1024; |
1298 const TInt KBigBifferSize = 32 * 1024; |
1299 TRAPD(res,bigBuf = HBufC8::NewL(KBigBifferSize)); |
1299 TRAPD(res,bigBuf = HBufC8::NewL(KBigBifferSize)); |
1300 test(res == KErrNone && bigBuf != NULL); |
1300 test_Value(res, res== KErrNone && bigBuf != NULL); |
1301 |
1301 |
1302 TPtr8 bigBufWritePtr(NULL, 0); |
1302 TPtr8 bigBufWritePtr(NULL, 0); |
1303 bigBufWritePtr.Set(bigBuf->Des()); |
1303 bigBufWritePtr.Set(bigBuf->Des()); |
1304 FillBuffer(bigBufWritePtr, KBigBifferSize, 'A'); |
1304 FillBuffer(bigBufWritePtr, KBigBifferSize, 'A'); |
1305 |
1305 |
1313 path = directory; |
1313 path = directory; |
1314 path.Append(buffer); |
1314 path.Append(buffer); |
1315 |
1315 |
1316 // delete file first to ensure it's contents are not in the cache (file may be on the closed file queue) |
1316 // delete file first to ensure it's contents are not in the cache (file may be on the closed file queue) |
1317 r = TheFs.Delete(path); |
1317 r = TheFs.Delete(path); |
1318 test(r == KErrNone || r == KErrNotFound); |
1318 test_Value(r, r == KErrNone || r == KErrNotFound); |
1319 |
1319 |
1320 r = file.Create(TheFs,path,EFileShareAny|EFileWrite|EFileReadDirectIO|EFileWriteDirectIO); |
1320 r = file.Create(TheFs,path,EFileShareAny|EFileWrite|EFileReadDirectIO|EFileWriteDirectIO); |
1321 if(r == KErrAlreadyExists) |
1321 if(r == KErrAlreadyExists) |
1322 r = file.Open(TheFs,path,EFileShareAny|EFileWrite|EFileReadDirectIO|EFileWriteDirectIO); |
1322 r = file.Open(TheFs,path,EFileShareAny|EFileWrite|EFileReadDirectIO|EFileWriteDirectIO); |
1323 TInt j = 0; |
1323 TInt j = 0; |
1351 TBuf16<50> buffer(50); |
1351 TBuf16<50> buffer(50); |
1352 HBufC8* buf = NULL; |
1352 HBufC8* buf = NULL; |
1353 TPtr8 bufPtr(NULL, 0); |
1353 TPtr8 bufPtr(NULL, 0); |
1354 |
1354 |
1355 TRAPD(res,buf = HBufC8::NewL(2)); |
1355 TRAPD(res,buf = HBufC8::NewL(2)); |
1356 test(res == KErrNone && buf != NULL); |
1356 test_Value(res, res== KErrNone && buf != NULL); |
1357 bufPtr.Set(buf->Des()); |
1357 bufPtr.Set(buf->Des()); |
1358 |
1358 |
1359 directory = gSessionPath; |
1359 directory = gSessionPath; |
1360 |
1360 |
1361 i = 0; |
1361 i = 0; |
1397 CreateFiles(nFiles,fSize); |
1397 CreateFiles(nFiles,fSize); |
1398 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
1398 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
1399 // get number of items on Page Cache |
1399 // get number of items on Page Cache |
1400 TFileCacheStats startPageCacheStats; |
1400 TFileCacheStats startPageCacheStats; |
1401 TInt r = controlIo(TheFs,gDrive, KControlIoFileCacheStats, startPageCacheStats); |
1401 TInt r = controlIo(TheFs,gDrive, KControlIoFileCacheStats, startPageCacheStats); |
1402 test(r==KErrNone || r == KErrNotSupported); |
1402 test_Value(r, r == KErrNone || r == KErrNotSupported); |
1403 test.Printf(_L("Number of page cache lines on free list at beginning=%d\n"),startPageCacheStats.iFreeCount); |
1403 test.Printf(_L("Number of page cache lines on free list at beginning=%d\n"),startPageCacheStats.iFreeCount); |
1404 test.Printf(_L("Number of page cache lines on used list at beginning=%d\n"),startPageCacheStats.iUsedCount); |
1404 test.Printf(_L("Number of page cache lines on used list at beginning=%d\n"),startPageCacheStats.iUsedCount); |
1405 test.Printf(_L("Number of files on closed queue=%d\n"),startPageCacheStats.iFilesOnClosedQueue); |
1405 test.Printf(_L("Number of files on closed queue=%d\n"),startPageCacheStats.iFilesOnClosedQueue); |
1406 #endif |
1406 #endif |
1407 FillCache(file,nFiles,fSize); |
1407 FillCache(file,nFiles,fSize); |
1408 |
1408 |
1409 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
1409 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
1410 // get number of items on Page Cache |
1410 // get number of items on Page Cache |
1411 r = controlIo(TheFs,gDrive, KControlIoFileCacheStats, startPageCacheStats); |
1411 r = controlIo(TheFs,gDrive, KControlIoFileCacheStats, startPageCacheStats); |
1412 test(r==KErrNone || r == KErrNotSupported); |
1412 test_Value(r, r == KErrNone || r == KErrNotSupported); |
1413 test.Printf(_L("Number of page cache lines on free list at end=%d\n"),startPageCacheStats.iFreeCount); |
1413 test.Printf(_L("Number of page cache lines on free list at end=%d\n"),startPageCacheStats.iFreeCount); |
1414 test.Printf(_L("Number of page cache lines on used list at end=%d\n"),startPageCacheStats.iUsedCount); |
1414 test.Printf(_L("Number of page cache lines on used list at end=%d\n"),startPageCacheStats.iUsedCount); |
1415 test.Printf(_L("Number of files on closed queue=%d\n"),startPageCacheStats.iFilesOnClosedQueue); |
1415 test.Printf(_L("Number of files on closed queue=%d\n"),startPageCacheStats.iFilesOnClosedQueue); |
1416 #endif |
1416 #endif |
1417 TestSimpleRead(); |
1417 TestSimpleRead(); |
1456 TUint32 finalTicks = 0; |
1456 TUint32 finalTicks = 0; |
1457 |
1457 |
1458 //--Find out if the drive is sync/async at this point and print information |
1458 //--Find out if the drive is sync/async at this point and print information |
1459 TPckgBuf<TBool> drvSyncBuf; |
1459 TPckgBuf<TBool> drvSyncBuf; |
1460 r = TheFs.QueryVolumeInfoExt(gDrive, EIsDriveSync, drvSyncBuf); |
1460 r = TheFs.QueryVolumeInfoExt(gDrive, EIsDriveSync, drvSyncBuf); |
1461 test(r == KErrNone); |
1461 test_KErrNone(r); |
1462 const TBool bDrvSync = drvSyncBuf(); |
1462 const TBool bDrvSync = drvSyncBuf(); |
1463 if(bDrvSync) |
1463 if(bDrvSync) |
1464 test.Printf(_L("Drive D: is synchronous\n")); |
1464 test.Printf(_L("Drive D: is synchronous\n")); |
1465 else |
1465 else |
1466 test.Printf(_L("Drive D: is asynchronous\n")); |
1466 test.Printf(_L("Drive D: is asynchronous\n")); |
1467 |
1467 |
1468 // use a fast counter as this is more accurate than using TTime |
1468 // use a fast counter as this is more accurate than using TTime |
1469 TInt fastCounterFreq; |
1469 TInt fastCounterFreq; |
1470 r = HAL::Get(HAL::EFastCounterFrequency, fastCounterFreq); |
1470 r = HAL::Get(HAL::EFastCounterFrequency, fastCounterFreq); |
1471 test(r == KErrNone); |
1471 test_KErrNone(r); |
1472 test.Printf(_L("HAL::EFastCounterFrequency %d\n"), fastCounterFreq); |
1472 test.Printf(_L("HAL::EFastCounterFrequency %d\n"), fastCounterFreq); |
1473 |
1473 |
1474 // Bind this thread to CPU 0. This is so that timer deltas don't drift from |
1474 // Bind this thread to CPU 0. This is so that timer deltas don't drift from |
1475 // scheduling - else, it causes spurious failures. |
1475 // scheduling - else, it causes spurious failures. |
1476 if (UserSvr::HalFunction(EHalGroupKernel, EKernelHalNumLogicalCpus, 0, 0) > 1) |
1476 if (UserSvr::HalFunction(EHalGroupKernel, EKernelHalNumLogicalCpus, 0, 0) > 1) |
1477 (void)UserSvr::HalFunction(EHalGroupKernel, EKernelHalLockThreadToCpu, (TAny *)0, 0); |
1477 (void)UserSvr::HalFunction(EHalGroupKernel, EKernelHalLockThreadToCpu, (TAny *)0, 0); |
1478 |
1478 |
1479 const TInt KReadLen = 28 * KOneK; |
1479 const TInt KReadLen = 28 * KOneK; |
1480 |
1480 |
1481 TRAPD(res,dummy = HBufC8::NewL(KReadLen)); |
1481 TRAPD(res,dummy = HBufC8::NewL(KReadLen)); |
1482 test(res == KErrNone && dummy != NULL); |
1482 test_Value(res, res== KErrNone && dummy != NULL); |
1483 |
1483 |
1484 dummyPtr.Set(dummy->Des()); |
1484 dummyPtr.Set(dummy->Des()); |
1485 |
1485 |
1486 test.Start(_L("Creating test file...")); |
1486 test.Start(_L("Creating test file...")); |
1487 |
1487 |
1583 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
1583 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
1584 test.Printf(_L("Disabling Lock Fail simulation ...\n")); |
1584 test.Printf(_L("Disabling Lock Fail simulation ...\n")); |
1585 // turn OFF lock failure mode |
1585 // turn OFF lock failure mode |
1586 TBool simulatelockFailureMode = EFalse; |
1586 TBool simulatelockFailureMode = EFalse; |
1587 TInt r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode); |
1587 TInt r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode); |
1588 test (r == KErrNone); |
1588 test_KErrNone(r); |
1589 #endif |
1589 #endif |
1590 |
1590 |
1591 TBuf16<45> dir; |
1591 TBuf16<45> dir; |
1592 |
1592 |
1593 RProcess().SetPriority(EPriorityBackground); |
1593 RProcess().SetPriority(EPriorityBackground); |
1603 dir.Append(gSecondFile); |
1603 dir.Append(gSecondFile); |
1604 gSecondFile = dir; |
1604 gSecondFile = dir; |
1605 |
1605 |
1606 |
1606 |
1607 TRAPD(res,gBuf = HBufC8::NewL(KBlockSize+1)); |
1607 TRAPD(res,gBuf = HBufC8::NewL(KBlockSize+1)); |
1608 test(res == KErrNone && gBuf != NULL); |
1608 test_Value(res, res== KErrNone && gBuf != NULL); |
1609 |
1609 |
1610 gBufWritePtr.Set(gBuf->Des()); |
1610 gBufWritePtr.Set(gBuf->Des()); |
1611 FillBuffer(gBufWritePtr, KBlockSize, 'A'); |
1611 FillBuffer(gBufWritePtr, KBlockSize, 'A'); |
1612 |
1612 |
1613 TRAPD(res2,gBufSec = HBufC8::NewL(KBlockSize+1)); |
1613 TRAPD(res2,gBufSec = HBufC8::NewL(KBlockSize+1)); |
1638 |
1638 |
1639 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
1639 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
1640 // turn lock failure mode back ON (if enabled) |
1640 // turn lock failure mode back ON (if enabled) |
1641 simulatelockFailureMode = ETrue; |
1641 simulatelockFailureMode = ETrue; |
1642 r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode); |
1642 r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode); |
1643 test (r == KErrNone); |
1643 test_KErrNone(r); |
1644 #endif |
1644 #endif |
1645 |
1645 |
1646 } |
1646 } |
1647 |
1647 |
1648 /** Initialises semaphores and call the tests |
1648 /** Initialises semaphores and call the tests |