39 _LIT(KTestFile1, "c:\\test\\t_sqloslayer.bin"); |
39 _LIT(KTestFile1, "c:\\test\\t_sqloslayer.bin"); |
40 _LIT(KTestFile3, "c:\\test\\t_sqloslayer.db"); |
40 _LIT(KTestFile3, "c:\\test\\t_sqloslayer.db"); |
41 const char* KTestFile1Z = "c:\\test\\t_sqloslayer.bin"; |
41 const char* KTestFile1Z = "c:\\test\\t_sqloslayer.bin"; |
42 const char* KTestFile2Z = "z:\\test\\TestDb1.db"; |
42 const char* KTestFile2Z = "z:\\test\\TestDb1.db"; |
43 const char* KTestFile3Z = "c:\\test\\t_sqloslayer.db"; |
43 const char* KTestFile3Z = "c:\\test\\t_sqloslayer.db"; |
|
44 _LIT(KPrivateDir, "c:\\private\\21F12127\\"); |
|
45 const char* KTestFile4Z = "c:\\test\\t_sqloslayer2.db"; |
44 |
46 |
45 //In order to be able to compile the test, the following variables are defined (used inside the OS porting layer, when _SQLPROFILER macro is defined) |
47 //In order to be able to compile the test, the following variables are defined (used inside the OS porting layer, when _SQLPROFILER macro is defined) |
46 #ifdef _SQLPROFILER |
48 #ifdef _SQLPROFILER |
47 TInt TheSqlSrvProfilerFileRead = 0; |
49 TInt TheSqlSrvProfilerFileRead = 0; |
48 TInt TheSqlSrvProfilerFileWrite = 0; |
50 TInt TheSqlSrvProfilerFileWrite = 0; |
86 TheTest(EFalse, aLine); |
88 TheTest(EFalse, aLine); |
87 } |
89 } |
88 } |
90 } |
89 #define TEST(arg) ::Check1((arg), __LINE__) |
91 #define TEST(arg) ::Check1((arg), __LINE__) |
90 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__) |
92 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__) |
|
93 |
|
94 /////////////////////////////////////////////////////////////////////////////////////// |
|
95 |
|
96 static TInt TheProcessHandleCount = 0; |
|
97 static TInt TheThreadHandleCount = 0; |
|
98 static TInt TheAllocatedCellsCount = 0; |
|
99 |
|
100 #ifdef _DEBUG |
|
101 static const TInt KBurstRate = 20; |
|
102 #endif |
|
103 |
|
104 static void MarkHandles() |
|
105 { |
|
106 RThread().HandleCount(TheProcessHandleCount, TheThreadHandleCount); |
|
107 } |
|
108 |
|
109 static void MarkAllocatedCells() |
|
110 { |
|
111 TheAllocatedCellsCount = User::CountAllocCells(); |
|
112 } |
|
113 |
|
114 static void CheckAllocatedCells() |
|
115 { |
|
116 TInt allocatedCellsCount = User::CountAllocCells(); |
|
117 TEST2(allocatedCellsCount, TheAllocatedCellsCount); |
|
118 } |
|
119 |
|
120 static void CheckHandles() |
|
121 { |
|
122 TInt endProcessHandleCount; |
|
123 TInt endThreadHandleCount; |
|
124 |
|
125 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); |
|
126 |
|
127 TEST2(TheProcessHandleCount, endProcessHandleCount); |
|
128 TEST2(TheThreadHandleCount, endThreadHandleCount); |
|
129 } |
|
130 |
|
131 static void OomPreStep(TInt |
|
132 #ifdef _DEBUG |
|
133 aFailingAllocationNo |
|
134 #endif |
|
135 ) |
|
136 { |
|
137 MarkHandles(); |
|
138 MarkAllocatedCells(); |
|
139 __UHEAP_MARK; |
|
140 __UHEAP_SETBURSTFAIL(RAllocator::EBurstFailNext, aFailingAllocationNo, KBurstRate); |
|
141 } |
|
142 |
|
143 static void OomPostStep() |
|
144 { |
|
145 __UHEAP_RESET; |
|
146 __UHEAP_MARKEND; |
|
147 CheckAllocatedCells(); |
|
148 CheckHandles(); |
|
149 } |
91 |
150 |
92 /////////////////////////////////////////////////////////////////////////////////////// |
151 /////////////////////////////////////////////////////////////////////////////////////// |
93 |
152 |
94 void TestEnvInit() |
153 void TestEnvInit() |
95 { |
154 { |
403 |
462 |
404 TInt failingAllocNum = 0; |
463 TInt failingAllocNum = 0; |
405 TInt err = KErrNoMemory; |
464 TInt err = KErrNoMemory; |
406 while(err == KErrNoMemory) |
465 while(err == KErrNoMemory) |
407 { |
466 { |
408 TInt processHandleCnt = 0; |
467 OomPreStep(++failingAllocNum); |
409 TInt threadHandleCnt = 0; |
|
410 RThread().HandleCount(processHandleCnt, threadHandleCnt); |
|
411 TInt allocCellsCnt = User::CountAllocCells(); |
|
412 |
|
413 __UHEAP_MARK; |
|
414 |
|
415 __UHEAP_SETBURSTFAIL(RHeap::EDeterministic, ++failingAllocNum, 10); |
|
416 |
|
417 err = sqlite3SymbianLibInit(); |
468 err = sqlite3SymbianLibInit(); |
418 |
469 sqlite3SymbianLibFinalize(); |
419 __UHEAP_SETBURSTFAIL(RHeap::ENone, 0, 0); |
470 OomPostStep(); |
420 |
471 if(err != KErrNoMemory) |
421 if(err != KErrNoMemory) |
472 { |
422 { |
473 TEST2(err, KErrNone); |
423 TEST2(err, KErrNone); |
474 } |
424 sqlite3SymbianLibFinalize(); |
|
425 } |
|
426 |
|
427 __UHEAP_MARKEND; |
|
428 |
|
429 TInt processHandleCnt2 = 0; |
|
430 TInt threadHandleCnt2 = 0; |
|
431 RThread().HandleCount(processHandleCnt2, threadHandleCnt2); |
|
432 TEST2(processHandleCnt2, processHandleCnt); |
|
433 TEST2(threadHandleCnt2, threadHandleCnt); |
|
434 |
|
435 TInt allocCellsCnt2 = User::CountAllocCells(); |
|
436 TEST2(allocCellsCnt2, allocCellsCnt); |
|
437 } |
475 } |
438 TEST2(err, KErrNone); |
476 TEST2(err, KErrNone); |
439 TheTest.Printf(_L("=== sqlite3SymbianLibInit() OOM test succeeded at allcoation %d\r\n"), failingAllocNum); |
477 TheTest.Printf(_L("=== sqlite3SymbianLibInit() OOM test succeeded at allcoation %d\r\n"), failingAllocNum); |
440 } |
478 } |
441 |
479 |
583 TEST2(err, SQLITE_IOERR_ACCESS); |
621 TEST2(err, SQLITE_IOERR_ACCESS); |
584 |
622 |
585 User::Free(osFile); |
623 User::Free(osFile); |
586 } |
624 } |
587 |
625 |
|
626 void VfsOpenTempFileOomTest() |
|
627 { |
|
628 //Delete all temp files in this test private data cage. |
|
629 CFileMan* fm = NULL; |
|
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); |
|
637 |
|
638 sqlite3_vfs* vfs = sqlite3_vfs_find(NULL); |
|
639 TEST(vfs != NULL); |
|
640 |
|
641 sqlite3_file* osFile = (sqlite3_file*)User::Alloc(vfs->szOsFile); |
|
642 TEST(osFile != NULL); |
|
643 |
|
644 TheTest.Printf(_L("Iteration: ")); |
|
645 TInt failingAllocNum = 0; |
|
646 err = SQLITE_IOERR_NOMEM; |
|
647 while(err == SQLITE_IOERR_NOMEM) |
|
648 { |
|
649 ++failingAllocNum; |
|
650 TheTest.Printf(_L("%d "), failingAllocNum); |
|
651 OomPreStep(failingAllocNum); |
|
652 int outFlags = 0; |
|
653 err = sqlite3OsOpen(vfs, NULL, osFile, SQLITE_OPEN_READWRITE, &outFlags); |
|
654 if(err == SQLITE_OK) |
|
655 { |
|
656 err = sqlite3OsClose(osFile); |
|
657 } |
|
658 OomPostStep(); |
|
659 if(err != SQLITE_OK) |
|
660 { |
|
661 TEST2(err, SQLITE_IOERR_NOMEM); |
|
662 } |
|
663 //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. |
|
665 TInt err2 = fm->Delete(path); |
|
666 TEST2(err2, KErrNotFound); |
|
667 } |
|
668 TEST2(err, SQLITE_OK); |
|
669 TheTest.Printf(_L("\r\n=== TVfs::Open(<temp file>) OOM test succeeded at allcoation %d\r\n"), failingAllocNum); |
|
670 |
|
671 User::Free(osFile); |
|
672 delete fm; |
|
673 } |
|
674 |
|
675 void VfsCreateDeleteOnCloseFileOomTest() |
|
676 { |
|
677 sqlite3_vfs* vfs = sqlite3_vfs_find(NULL); |
|
678 TEST(vfs != NULL); |
|
679 |
|
680 sqlite3_file* osFile = (sqlite3_file*)User::Alloc(vfs->szOsFile); |
|
681 TEST(osFile != NULL); |
|
682 |
|
683 TheTest.Printf(_L("Iteration: ")); |
|
684 TInt failingAllocNum = 0; |
|
685 TInt err = SQLITE_IOERR_NOMEM; |
|
686 while(err == SQLITE_IOERR_NOMEM) |
|
687 { |
|
688 ++failingAllocNum; |
|
689 TheTest.Printf(_L("%d "), failingAllocNum); |
|
690 OomPreStep(failingAllocNum); |
|
691 int outFlags = 0; |
|
692 err = sqlite3OsOpen(vfs, KTestFile4Z, osFile, SQLITE_OPEN_CREATE | SQLITE_OPEN_DELETEONCLOSE, &outFlags); |
|
693 if(err == SQLITE_OK) |
|
694 { |
|
695 err = sqlite3OsClose(osFile); |
|
696 } |
|
697 OomPostStep(); |
|
698 if(err != SQLITE_OK) |
|
699 { |
|
700 TEST2(err, SQLITE_IOERR_NOMEM); |
|
701 } |
|
702 //Whether the iteration has failed or succeeded, the file should not exist. |
|
703 TPtrC8 ptrname((const TUint8*)KTestFile4Z); |
|
704 TBuf<50> fname; |
|
705 fname.Copy(ptrname); |
|
706 TInt err2 = TheFs.Delete(fname); |
|
707 TEST2(err2, KErrNotFound); |
|
708 } |
|
709 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); |
|
711 User::Free(osFile); |
|
712 } |
|
713 |
588 /** |
714 /** |
589 @SYMTestCaseID SYSLIB-SQL-CT-1650 |
715 @SYMTestCaseID SYSLIB-SQL-CT-1650 |
590 @SYMTestCaseDesc SQL, OS porting layer tests. |
716 @SYMTestCaseDesc SQL, OS porting layer tests. |
591 @SYMTestPriority High |
717 @SYMTestPriority High |
592 @SYMTestActions SQL, OS porting layer tests. |
718 @SYMTestActions SQL, OS porting layer tests. |
610 sqlite3SymbianLibInitFsErrTest(); |
736 sqlite3SymbianLibInitFsErrTest(); |
611 TheTest.Printf(_L("OS porting layer test - 'profiler disabled' tests\r\n")); |
737 TheTest.Printf(_L("OS porting layer test - 'profiler disabled' tests\r\n")); |
612 ProfilerDisabledTest(); |
738 ProfilerDisabledTest(); |
613 TheTest.Printf(_L("OS porting layer test - negative tests\r\n")); |
739 TheTest.Printf(_L("OS porting layer test - negative tests\r\n")); |
614 NegativeTest(); |
740 NegativeTest(); |
|
741 TheTest.Printf(_L("TVfs::Open(<temp file>) OOM test\r\n")); |
|
742 VfsOpenTempFileOomTest(); |
|
743 TheTest.Printf(_L("TVfs::Open(<'delete on close' file>) OOM test\r\n")); |
|
744 VfsCreateDeleteOnCloseFileOomTest(); |
615 } |
745 } |
616 |
746 |
617 TInt E32Main() |
747 TInt E32Main() |
618 { |
748 { |
619 TheTest.Title(); |
749 TheTest.Title(); |
620 |
750 |
621 CTrapCleanup* tc = CTrapCleanup::New(); |
751 CTrapCleanup* tc = CTrapCleanup::New(); |
|
752 TheTest(tc != NULL); |
622 |
753 |
623 __UHEAP_MARK; |
754 __UHEAP_MARK; |
624 |
755 |
625 TestEnvInit(); |
756 TestEnvInit(); |
626 DeleteTestFiles(); |
757 DeleteTestFiles(); |