621 TEST2(err, SQLITE_IOERR_ACCESS); |
625 TEST2(err, SQLITE_IOERR_ACCESS); |
622 |
626 |
623 User::Free(osFile); |
627 User::Free(osFile); |
624 } |
628 } |
625 |
629 |
|
630 TInt DoDeleteTempFiles() |
|
631 { |
|
632 CFileMan* fm = NULL; |
|
633 TRAPD(err, fm = CFileMan::NewL(TheFs)); |
|
634 TEST2(err, KErrNone); |
|
635 TFileName path; |
|
636 path.Copy(KPrivateDir); |
|
637 path.Append(_L("temp\\")); |
|
638 path.Append(_L("*.$$$")); |
|
639 err = fm->Delete(path); |
|
640 delete fm; |
|
641 return err; |
|
642 } |
|
643 |
626 void VfsOpenTempFileOomTest() |
644 void VfsOpenTempFileOomTest() |
627 { |
645 { |
628 //Delete all temp files in this test private data cage. |
646 //Delete all temp files in this test private data cage. |
629 CFileMan* fm = NULL; |
647 TInt err = DoDeleteTempFiles(); |
630 TRAPD(err, fm = CFileMan::NewL(TheFs)); |
|
631 TEST2(err, KErrNone); |
|
632 TBuf<50> path; |
|
633 path.Copy(KPrivateDir); |
|
634 path.Append(_L("*.$$$")); |
|
635 err = fm->Delete(path); |
|
636 TEST(err == KErrNone || err == KErrNotFound); |
648 TEST(err == KErrNone || err == KErrNotFound); |
637 |
649 |
638 sqlite3_vfs* vfs = sqlite3_vfs_find(NULL); |
650 sqlite3_vfs* vfs = sqlite3_vfs_find(NULL); |
639 TEST(vfs != NULL); |
651 TEST(vfs != NULL); |
640 |
652 |
651 OomPreStep(failingAllocNum); |
663 OomPreStep(failingAllocNum); |
652 int outFlags = 0; |
664 int outFlags = 0; |
653 err = sqlite3OsOpen(vfs, NULL, osFile, SQLITE_OPEN_READWRITE, &outFlags); |
665 err = sqlite3OsOpen(vfs, NULL, osFile, SQLITE_OPEN_READWRITE, &outFlags); |
654 if(err == SQLITE_OK) |
666 if(err == SQLITE_OK) |
655 { |
667 { |
656 err = sqlite3OsClose(osFile); |
668 //Since this is a temp file, its creation will be delayed till the first file write operation. |
|
669 err = sqlite3OsWrite(osFile, "1234", 4, 0); |
|
670 (void)sqlite3OsClose(osFile); |
657 } |
671 } |
658 OomPostStep(); |
672 OomPostStep(); |
659 if(err != SQLITE_OK) |
673 if(err != SQLITE_OK) |
660 { |
674 { |
661 TEST2(err, SQLITE_IOERR_NOMEM); |
675 TEST2(err, SQLITE_IOERR_NOMEM); |
662 } |
676 } |
663 //If the iteration has failed, then no temp file should exist in the test private data cage. |
677 //If the iteration has failed, then no temp file should exist in the test private data cage. |
664 //If the iteration has succeeded, then sqlite3OsClose() should have deleted the temp file. |
678 //If the iteration has succeeded, then sqlite3OsClose() should have deleted the temp file. |
665 TInt err2 = fm->Delete(path); |
679 TInt err2 = DoDeleteTempFiles(); |
666 TEST2(err2, KErrNotFound); |
680 TEST2(err2, KErrNotFound); |
667 } |
681 } |
668 TEST2(err, SQLITE_OK); |
682 TEST2(err, SQLITE_OK); |
669 TheTest.Printf(_L("\r\n=== TVfs::Open(<temp file>) OOM test succeeded at allcoation %d\r\n"), failingAllocNum); |
683 TheTest.Printf(_L("\r\n=== TVfs::Open(<temp file>) OOM test succeeded at allcoation %d\r\n"), failingAllocNum); |
670 |
684 |
671 User::Free(osFile); |
685 User::Free(osFile); |
672 delete fm; |
|
673 } |
686 } |
|
687 |
|
688 void VfsOpenTempFileFileIoErrTest() |
|
689 { |
|
690 //Delete all temp files in this test private data cage. |
|
691 TInt err = DoDeleteTempFiles(); |
|
692 TEST(err == KErrNone || err == KErrNotFound); |
|
693 |
|
694 sqlite3_vfs* vfs = sqlite3_vfs_find(NULL); |
|
695 TEST(vfs != NULL); |
|
696 |
|
697 sqlite3_file* osFile = (sqlite3_file*)User::Alloc(vfs->szOsFile); |
|
698 TEST(osFile != NULL); |
|
699 |
|
700 err = SQLITE_ERROR; |
|
701 TInt cnt = 1; |
|
702 while(err != SQLITE_OK) |
|
703 { |
|
704 TInt processHandleCnt = 0; |
|
705 TInt threadHandleCnt = 0; |
|
706 RThread().HandleCount(processHandleCnt, threadHandleCnt); |
|
707 TInt allocCellsCnt = User::CountAllocCells(); |
|
708 |
|
709 TheTest.Printf(_L("%d "), cnt); |
|
710 (void)TheFs.SetErrorCondition(KErrGeneral, cnt); |
|
711 int outFlags = 0; |
|
712 err = sqlite3OsOpen(vfs, NULL, osFile, SQLITE_OPEN_READWRITE, &outFlags); |
|
713 if(err == SQLITE_OK) |
|
714 { |
|
715 //Since this is a temp file, its creation will be delayed till the first file write operation. |
|
716 err = sqlite3OsWrite(osFile, "1234", 4, 0); |
|
717 (void)sqlite3OsClose(osFile); |
|
718 } |
|
719 (void)TheFs.SetErrorCondition(KErrNone); |
|
720 if(err != SQLITE_OK) |
|
721 { |
|
722 TInt processHandleCnt2 = 0; |
|
723 TInt threadHandleCnt2 = 0; |
|
724 RThread().HandleCount(processHandleCnt2, threadHandleCnt2); |
|
725 TEST2(processHandleCnt2, processHandleCnt); |
|
726 TEST2(threadHandleCnt2, threadHandleCnt); |
|
727 TInt allocCellsCnt2 = User::CountAllocCells(); |
|
728 TEST2(allocCellsCnt2, allocCellsCnt); |
|
729 ++cnt; |
|
730 } |
|
731 //If the iteration has failed, then no temp file should exist in the test private data cage. |
|
732 //If the iteration has succeeded, then sqlite3OsClose() should have deleted the temp file. |
|
733 TInt err2 = DoDeleteTempFiles(); |
|
734 TEST2(err2, KErrNotFound); |
|
735 } |
|
736 TEST2(err, SQLITE_OK); |
|
737 TheTest.Printf(_L("\r\n=== TVfs::Open(<temp file>) file I/O error simulation test succeeded at iteration %d\r\n"), cnt); |
|
738 User::Free(osFile); |
|
739 } |
674 |
740 |
675 void VfsCreateDeleteOnCloseFileOomTest() |
741 void VfsCreateDeleteOnCloseFileOomTest() |
676 { |
742 { |
677 sqlite3_vfs* vfs = sqlite3_vfs_find(NULL); |
743 sqlite3_vfs* vfs = sqlite3_vfs_find(NULL); |
678 TEST(vfs != NULL); |
744 TEST(vfs != NULL); |
709 TEST2(err, SQLITE_OK); |
775 TEST2(err, SQLITE_OK); |
710 TheTest.Printf(_L("\r\n=== TVfs::Open(<delete on close file>) OOM test succeeded at allcoation %d\r\n"), failingAllocNum); |
776 TheTest.Printf(_L("\r\n=== TVfs::Open(<delete on close file>) OOM test succeeded at allcoation %d\r\n"), failingAllocNum); |
711 User::Free(osFile); |
777 User::Free(osFile); |
712 } |
778 } |
713 |
779 |
|
780 /////////////////////////////////////////////////////////////////////////////////////// |
|
781 |
|
782 //Panic thread function. |
|
783 //It will cast aData parameter to a TFunctor pointer and call it. |
|
784 //The expectation is that the called function will panic and kill the panic thread. |
|
785 TInt ThreadFunc(void* aData) |
|
786 { |
|
787 CTrapCleanup* tc = CTrapCleanup::New(); |
|
788 TEST(tc != NULL); |
|
789 |
|
790 User::SetJustInTime(EFalse); // disable debugger panic handling |
|
791 |
|
792 TFunctor* obj = reinterpret_cast<TFunctor*> (aData); |
|
793 TEST(obj != NULL); |
|
794 (*obj)();//call the panic function |
|
795 |
|
796 delete tc; |
|
797 |
|
798 return KErrNone; |
|
799 } |
|
800 |
|
801 //Panic test. |
|
802 //PanicTest function will create a new thread - panic thread, giving it a pointer to the function which has to |
|
803 //be executed and the expectation is that the function will panic and kill the panic thread. |
|
804 //PanicTest function will check the panic thread exit code, exit category and the panic code. |
|
805 void PanicTest(TFunctor& aFunctor, TExitType aExpectedExitType, const TDesC& aExpectedCategory, TInt aExpectedPanicCode) |
|
806 { |
|
807 RThread thread; |
|
808 _LIT(KThreadName,"OsLayerPanicThread"); |
|
809 TEST2(thread.Create(KThreadName, &ThreadFunc, 0x2000, 0x1000, 0x10000, (void*)&aFunctor, EOwnerThread), KErrNone); |
|
810 |
|
811 TRequestStatus status; |
|
812 thread.Logon(status); |
|
813 TEST2(status.Int(), KRequestPending); |
|
814 thread.Resume(); |
|
815 User::WaitForRequest(status); |
|
816 User::SetJustInTime(ETrue); // enable debugger panic handling |
|
817 |
|
818 TEST2(thread.ExitType(), aExpectedExitType); |
|
819 TEST(thread.ExitCategory() == aExpectedCategory); |
|
820 TEST2(thread.ExitReason(), aExpectedPanicCode); |
|
821 |
|
822 CLOSE_AND_WAIT(thread); |
|
823 } |
|
824 |
|
825 //////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
826 ////////////////////////////// Panic test functions ///////////////////////////////////////////////// |
|
827 //////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
828 |
|
829 #ifdef _DEBUG |
|
830 |
|
831 //Panic when calling COsLayerData::Create() is called and the OS layer data has been already created. |
|
832 class TOsLayerDataDuplicated : public TFunctor |
|
833 { |
|
834 private: |
|
835 virtual void operator()() |
|
836 { |
|
837 (void)sqlite3SymbianLibInit();//This should crash the thread in debug mode (because the Os layer |
|
838 //data was created already in TestEnvInit()). |
|
839 } |
|
840 }; |
|
841 static TOsLayerDataDuplicated TheOsLayerDataDuplicated; |
|
842 |
|
843 #endif //_DEBUG |
|
844 |
714 /** |
845 /** |
715 @SYMTestCaseID SYSLIB-SQL-CT-1650 |
846 @SYMTestCaseID SYSLIB-SQL-CT-1650 |
716 @SYMTestCaseDesc SQL, OS porting layer tests. |
847 @SYMTestCaseDesc SQL, OS porting layer tests. |
717 @SYMTestPriority High |
848 @SYMTestPriority High |
718 @SYMTestActions SQL, OS porting layer tests. |
849 @SYMTestActions SQL, OS porting layer tests. |
738 ProfilerDisabledTest(); |
869 ProfilerDisabledTest(); |
739 TheTest.Printf(_L("OS porting layer test - negative tests\r\n")); |
870 TheTest.Printf(_L("OS porting layer test - negative tests\r\n")); |
740 NegativeTest(); |
871 NegativeTest(); |
741 TheTest.Printf(_L("TVfs::Open(<temp file>) OOM test\r\n")); |
872 TheTest.Printf(_L("TVfs::Open(<temp file>) OOM test\r\n")); |
742 VfsOpenTempFileOomTest(); |
873 VfsOpenTempFileOomTest(); |
|
874 TheTest.Printf(_L("TVfs::Open(<temp file>) file I/O error simulation test\r\n")); |
|
875 VfsOpenTempFileFileIoErrTest(); |
743 TheTest.Printf(_L("TVfs::Open(<'delete on close' file>) OOM test\r\n")); |
876 TheTest.Printf(_L("TVfs::Open(<'delete on close' file>) OOM test\r\n")); |
744 VfsCreateDeleteOnCloseFileOomTest(); |
877 VfsCreateDeleteOnCloseFileOomTest(); |
|
878 #ifdef _DEBUG |
|
879 TheTest.Printf(_L("'An attempt to create the OS layer data again' panic\r\n")); |
|
880 PanicTest(TheOsLayerDataDuplicated, EExitPanic, KSqlitePanicCategory, ESqliteOsPanicOsLayerDataExists); |
|
881 #endif //_DEBUG |
745 } |
882 } |
746 |
883 |
747 TInt E32Main() |
884 TInt E32Main() |
748 { |
885 { |
749 TheTest.Title(); |
886 TheTest.Title(); |