680 (void)RSqlDatabase::Delete(KTestDbName1); |
682 (void)RSqlDatabase::Delete(KTestDbName1); |
681 GetHomeTimeAsString(time); |
683 GetHomeTimeAsString(time); |
682 TheTest.Printf(_L("=== %S: Test case end\r\n"), &time); |
684 TheTest.Printf(_L("=== %S: Test case end\r\n"), &time); |
683 } |
685 } |
684 |
686 |
|
687 TInt CreateFileSessions(TInt& aIdx, RFs aFs[], TInt aMaxFsSessCount) |
|
688 { |
|
689 TBuf<30> time; |
|
690 TTime startTime; |
|
691 startTime.HomeTime(); |
|
692 //Create as many file session objects as possible |
|
693 TInt err = KErrNone; |
|
694 for(;aIdx<aMaxFsSessCount;++aIdx) |
|
695 { |
|
696 err = aFs[aIdx].Connect(); |
|
697 if(err != KErrNone) |
|
698 { |
|
699 break; |
|
700 } |
|
701 TTimeIntervalSeconds s = ExecutionTimeSeconds(startTime); |
|
702 if((aIdx % 500) == 0) |
|
703 { |
|
704 GetHomeTimeAsString(time); |
|
705 TheTest.Printf(_L("=== %S: Create % 5d file sessions. %d seconds.\r\n"), &time, aIdx + 1, s.Int()); |
|
706 } |
|
707 if(s.Int() > KTestTimeLimit) |
|
708 { |
|
709 GetHomeTimeAsString(time); |
|
710 TheTest.Printf(_L("=== %S: The time limit reached.\r\n"), &time); |
|
711 ++aIdx;//The idx-th file session object is valid, the file session count is idx + 1. |
|
712 break; |
|
713 } |
|
714 } |
|
715 return err; |
|
716 } |
|
717 |
|
718 /** |
|
719 @SYMTestCaseID PDS-SQL-CT-4237 |
|
720 @SYMTestCaseDesc Max file session number test. |
|
721 @SYMTestPriority High |
|
722 @SYMTestActions The test creates as many as possible file session objects. The expected result is |
|
723 that either the file session creation process will fail with KErrNoMemory or |
|
724 the max number of file sessions to be created is reached (100000). |
|
725 Then the test attempts to create a database. If there is no memory, the test |
|
726 closes some of the file session objects. The test also attempts to copy |
|
727 the created database and to delete it after that, both operations performed |
|
728 with all file session objects still open. The expectation is that the test |
|
729 will not crash the SQL server or the client side SQL dll. |
|
730 Note that the test has a time limit of 120 seconds. Otherwise on some platforms |
|
731 with WDP feature switched on the test may timeout. |
|
732 @SYMTestExpectedResults Test must not fail |
|
733 */ |
|
734 void FileSessionMaxNumberTest() |
|
735 { |
|
736 TBuf<30> time; |
|
737 GetHomeTimeAsString(time); |
|
738 TheTest.Printf(_L("=== %S: Create file sessions\r\n"), &time); |
|
739 |
|
740 const TInt KMaxFsCount = 100000; |
|
741 RFs* fs = new RFs[KMaxFsCount]; |
|
742 TEST(fs != NULL); |
|
743 |
|
744 //Create as many file session objects as possible |
|
745 TInt idx = 0; |
|
746 TInt err = CreateFileSessions(idx, fs, KMaxFsCount); |
|
747 TheTest.Printf(_L("%d created file session objects. Last error: %d.\r\n"), idx, err); |
|
748 TEST(err == KErrNone || err == KErrNoMemory); |
|
749 |
|
750 TBool dbCreated = EFalse; |
|
751 RSqlDatabase db; |
|
752 |
|
753 //An attempt to create a database |
|
754 while(idx > 0 && err == KErrNoMemory) |
|
755 { |
|
756 (void)RSqlDatabase::Delete(KTestDbName1); |
|
757 err = db.Create(KTestDbName1); |
|
758 if(err == KErrNone) |
|
759 { |
|
760 err = db.Exec(_L("CREATE TABLE A(I INTEGER); INSERT INTO A(I) VALUES(1); INSERT INTO A(I) VALUES(2);")); |
|
761 } |
|
762 TheTest.Printf(_L("Database creation. Last error: %d.\r\n"), err); |
|
763 TEST(err == KErrNoMemory || err >= 0); |
|
764 if(err == KErrNoMemory) |
|
765 { |
|
766 fs[--idx].Close(); |
|
767 } |
|
768 else |
|
769 { |
|
770 dbCreated = ETrue; |
|
771 } |
|
772 db.Close(); |
|
773 } |
|
774 |
|
775 if(dbCreated) |
|
776 { |
|
777 //Create again file session objects - as many as possible |
|
778 err = CreateFileSessions(idx, fs, KMaxFsCount); |
|
779 TEST(err == KErrNone || err == KErrNoMemory); |
|
780 //Try to copy the database |
|
781 err = RSqlDatabase::Copy(KTestDbName1, KTestDbName4); |
|
782 TheTest.Printf(_L("Copy database. Last error: %d.\r\n"), err); |
|
783 TEST(err == KErrNone || err == KErrNoMemory); |
|
784 //Try to delete the databases |
|
785 if(err == KErrNone) |
|
786 { |
|
787 err = RSqlDatabase::Delete(KTestDbName4); |
|
788 TheTest.Printf(_L("Delete database copy. Last error: %d.\r\n"), err); |
|
789 TEST(err == KErrNone || err == KErrNoMemory); |
|
790 } |
|
791 err = RSqlDatabase::Delete(KTestDbName1); |
|
792 TheTest.Printf(_L("Delete database. Last error: %d.\r\n"), err); |
|
793 TEST(err == KErrNone || err == KErrNoMemory); |
|
794 } |
|
795 |
|
796 //Cleanup |
|
797 for(TInt i=0;i<idx;++i) |
|
798 { |
|
799 fs[i].Close(); |
|
800 if((i % 500) == 0) |
|
801 { |
|
802 GetHomeTimeAsString(time); |
|
803 TheTest.Printf(_L("=== %S: % 5d file sessions closed\r\n"), &time, i + 1); |
|
804 } |
|
805 } |
|
806 delete [] fs; |
|
807 err = RSqlDatabase::Delete(KTestDbName4); |
|
808 TEST(err == KErrNone || err == KErrNotFound); |
|
809 err = RSqlDatabase::Delete(KTestDbName1); |
|
810 TEST(err == KErrNone || err == KErrNotFound); |
|
811 } |
|
812 |
|
813 TInt CreateSqlConnections(TInt& aIdx, RSqlDatabase aDb[], TInt aMaxSqlConnCount) |
|
814 { |
|
815 TBuf<30> time; |
|
816 TTime startTime; |
|
817 startTime.HomeTime(); |
|
818 //Create as many file session objects as possible |
|
819 TInt err = KErrNone; |
|
820 for(;aIdx<aMaxSqlConnCount;++aIdx) |
|
821 { |
|
822 err = aDb[aIdx].Open(KTestDbName1); |
|
823 if(err != KErrNone) |
|
824 { |
|
825 break; |
|
826 } |
|
827 TTimeIntervalSeconds s = ExecutionTimeSeconds(startTime); |
|
828 if((aIdx % 100) == 0) |
|
829 { |
|
830 GetHomeTimeAsString(time); |
|
831 TheTest.Printf(_L("=== %S: Create % 5d sql connections. %d seconds.\r\n"), &time, aIdx + 1, s.Int()); |
|
832 } |
|
833 if(s.Int() > KTestTimeLimit) |
|
834 { |
|
835 GetHomeTimeAsString(time); |
|
836 TheTest.Printf(_L("=== %S: The time limit reached.\r\n"), &time); |
|
837 ++aIdx;//The idx-th sql connection is valid, the sql connection count is idx + 1. |
|
838 break; |
|
839 } |
|
840 } |
|
841 return err; |
|
842 } |
|
843 |
|
844 /** |
|
845 @SYMTestCaseID PDS-SQL-CT-4238 |
|
846 @SYMTestCaseDesc Max sql connection number test. |
|
847 @SYMTestPriority High |
|
848 @SYMTestActions The test creates as many as possible sql connection objects. The expected result is |
|
849 that either the sql connection creation process will fail with KErrNoMemory or |
|
850 the max number of sql connection to be created is reached (100000). |
|
851 Then the test attempts to create a database. If there is no memory, the test |
|
852 closes some of the sql connection objects. The test also attempts to copy |
|
853 the created database and to delete it after that, both operations performed |
|
854 with all sql connection objects still open. The expectation is that the test |
|
855 will not crash the SQL server or the client side SQL dll. |
|
856 Note that the test has a time limit of 120 seconds. Otherwise on some platforms |
|
857 with WDP feature switched on the test may timeout. |
|
858 @SYMTestExpectedResults Test must not fail |
|
859 */ |
|
860 void SqlConnectionMaxNumberTest() |
|
861 { |
|
862 TBuf<30> time; |
|
863 GetHomeTimeAsString(time); |
|
864 TheTest.Printf(_L("=== %S: Create sql connections\r\n"), &time); |
|
865 |
|
866 (void)RSqlDatabase::Delete(KTestDbName1); |
|
867 RSqlDatabase db1; |
|
868 TInt err = db1.Create(KTestDbName1);//CreateSqlConnections() opens the already existing KTestDbName1 database |
|
869 TEST2(err, KErrNone); |
|
870 |
|
871 const TInt KMaxConnCount = 100000; |
|
872 RSqlDatabase* db = new RSqlDatabase[KMaxConnCount]; |
|
873 TEST(db != NULL); |
|
874 |
|
875 //Create as many sql connection objects as possible |
|
876 TInt idx = 0; |
|
877 err = CreateSqlConnections(idx, db, KMaxConnCount); |
|
878 TheTest.Printf(_L("%d created sql connection objects. Last error: %d.\r\n"), idx, err); |
|
879 TEST(err == KErrNone || err == KErrNoMemory); |
|
880 |
|
881 TBool dbCreated = EFalse; |
|
882 RSqlDatabase db2; |
|
883 |
|
884 //An attempt to create a database |
|
885 while(idx > 0 && err == KErrNoMemory) |
|
886 { |
|
887 (void)RSqlDatabase::Delete(KTestDbName4); |
|
888 err = db2.Create(KTestDbName4); |
|
889 if(err == KErrNone) |
|
890 { |
|
891 err = db2.Exec(_L("CREATE TABLE A(I INTEGER); INSERT INTO A(I) VALUES(1); INSERT INTO A(I) VALUES(2);")); |
|
892 } |
|
893 TheTest.Printf(_L("Database creation. Last error: %d.\r\n"), err); |
|
894 TEST(err == KErrNoMemory || err >= 0); |
|
895 if(err == KErrNoMemory) |
|
896 { |
|
897 db[--idx].Close(); |
|
898 } |
|
899 else |
|
900 { |
|
901 dbCreated = ETrue; |
|
902 } |
|
903 db2.Close(); |
|
904 } |
|
905 |
|
906 if(dbCreated) |
|
907 { |
|
908 //Create again sql connection objects - as many as possible |
|
909 err = CreateSqlConnections(idx, db, KMaxConnCount); |
|
910 TEST(err == KErrNone || err == KErrNoMemory); |
|
911 //Try to copy the database |
|
912 err = RSqlDatabase::Copy(KTestDbName4, KTestDbName5); |
|
913 TheTest.Printf(_L("Copy database. Last error: %d.\r\n"), err); |
|
914 TEST(err == KErrNone || err == KErrNoMemory); |
|
915 //Try to delete the databases |
|
916 if(err == KErrNone) |
|
917 { |
|
918 err = RSqlDatabase::Delete(KTestDbName5); |
|
919 TheTest.Printf(_L("Delete database copy. Last error: %d.\r\n"), err); |
|
920 TEST(err == KErrNone || err == KErrNoMemory); |
|
921 } |
|
922 err = RSqlDatabase::Delete(KTestDbName4); |
|
923 TheTest.Printf(_L("Delete database. Last error: %d.\r\n"), err); |
|
924 TEST(err == KErrNone || err == KErrNoMemory); |
|
925 } |
|
926 |
|
927 //Cleanup |
|
928 for(TInt i=0;i<idx;++i) |
|
929 { |
|
930 db[i].Close(); |
|
931 if((i % 100) == 0) |
|
932 { |
|
933 GetHomeTimeAsString(time); |
|
934 TheTest.Printf(_L("=== %S: % 5d sql connections closed\r\n"), &time, i + 1); |
|
935 } |
|
936 } |
|
937 delete [] db; |
|
938 db1.Close(); |
|
939 err = RSqlDatabase::Delete(KTestDbName5); |
|
940 TEST(err == KErrNone || err == KErrNotFound); |
|
941 err = RSqlDatabase::Delete(KTestDbName4); |
|
942 TEST(err == KErrNone || err == KErrNotFound); |
|
943 err = RSqlDatabase::Delete(KTestDbName1); |
|
944 TEST(err == KErrNone || err == KErrNotFound); |
|
945 } |
|
946 |
685 void DoTests() |
947 void DoTests() |
686 { |
948 { |
687 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1627-0001 SQL server load test ")); |
949 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1627-0001 SQL server load test ")); |
688 SqlLoadTest(); |
950 SqlLoadTest(); |
689 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4201 Statement max number test")); |
951 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4201 Statement max number test")); |
690 StatementMaxNumberTest(); |
952 StatementMaxNumberTest(); |
|
953 #if defined __WINS__ || defined __WINSCW__ |
|
954 //The next two tests are likely to timeout on hardware because they create a lot of file sessions and sql connections. |
|
955 //The SQL server heap is 32Mb on hardware but only 6Mb on the Emulator. |
|
956 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4237 File session max number test")); |
|
957 FileSessionMaxNumberTest(); |
|
958 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4238 Sql connection max number test")); |
|
959 SqlConnectionMaxNumberTest(); |
|
960 #endif |
691 } |
961 } |
692 |
962 |
693 TInt E32Main() |
963 TInt E32Main() |
694 { |
964 { |
695 TheTest.Title(); |
965 TheTest.Title(); |