sl@0
|
1 |
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include "t_sqloom.h"
|
sl@0
|
17 |
#include "SqlResourceTester.h" //TSqlResourceTester
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
TInt TheHandleCount1B = 0;
|
sl@0
|
21 |
TInt TheHandleCount2B = 0;
|
sl@0
|
22 |
TInt TheAllocatedCellsCountB = 0;
|
sl@0
|
23 |
TOomTestType TheOomTestType[2] = {EClientSideTest, EServerSideTest};
|
sl@0
|
24 |
|
sl@0
|
25 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
26 |
/////////////// OOM tests - utility functions //////////////////////////
|
sl@0
|
27 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
28 |
|
sl@0
|
29 |
void DeleteTestFiles()
|
sl@0
|
30 |
{
|
sl@0
|
31 |
(void)RSqlDatabase::Delete(KSecureAttachDb);
|
sl@0
|
32 |
(void)RSqlDatabase::Delete(KAttachDb);
|
sl@0
|
33 |
(void)RSqlDatabase::Delete(KSecureTestDb);
|
sl@0
|
34 |
(void)RSqlDatabase::Delete(KTestDb);
|
sl@0
|
35 |
(void)RSqlDatabase::Delete(KSecureDb2);
|
sl@0
|
36 |
(void)RSqlDatabase::Delete(KTestDb2);
|
sl@0
|
37 |
(void)RSqlDatabase::Delete(KPrivateTestDb);
|
sl@0
|
38 |
}
|
sl@0
|
39 |
|
sl@0
|
40 |
void Check(TInt64 aValue, TInt aLine)
|
sl@0
|
41 |
{
|
sl@0
|
42 |
if(!aValue)
|
sl@0
|
43 |
{
|
sl@0
|
44 |
DeleteTestFiles();
|
sl@0
|
45 |
TheTest(EFalse, aLine);
|
sl@0
|
46 |
}
|
sl@0
|
47 |
}
|
sl@0
|
48 |
|
sl@0
|
49 |
void Check(TInt64 aValue, TInt64 aExpected, TInt aLine)
|
sl@0
|
50 |
{
|
sl@0
|
51 |
if(aValue != aExpected)
|
sl@0
|
52 |
{
|
sl@0
|
53 |
DeleteTestFiles();
|
sl@0
|
54 |
RDebug::Print(_L("*** Expected error: %ld, got: %ld\r\n"), aExpected, aValue);
|
sl@0
|
55 |
TheTest(EFalse, aLine);
|
sl@0
|
56 |
}
|
sl@0
|
57 |
}
|
sl@0
|
58 |
|
sl@0
|
59 |
void CreateTestDir()
|
sl@0
|
60 |
{
|
sl@0
|
61 |
RFs fs;
|
sl@0
|
62 |
TInt err = fs.Connect();
|
sl@0
|
63 |
TEST2(err, KErrNone);
|
sl@0
|
64 |
|
sl@0
|
65 |
err = fs.MkDir(KTestDir);
|
sl@0
|
66 |
TEST(err == KErrNone || err == KErrAlreadyExists);
|
sl@0
|
67 |
|
sl@0
|
68 |
err = fs.CreatePrivatePath(EDriveC);
|
sl@0
|
69 |
TEST(err == KErrNone || err == KErrAlreadyExists);
|
sl@0
|
70 |
|
sl@0
|
71 |
fs.Close();
|
sl@0
|
72 |
}
|
sl@0
|
73 |
|
sl@0
|
74 |
void PrepareAttachFromHandle()
|
sl@0
|
75 |
{
|
sl@0
|
76 |
(void)RSqlDatabase::Delete(KAttachDb);
|
sl@0
|
77 |
(void)RSqlDatabase::Delete(KPrivateTestDb);
|
sl@0
|
78 |
|
sl@0
|
79 |
RSqlDatabase db;
|
sl@0
|
80 |
TInt err = db.Create(KAttachDb);
|
sl@0
|
81 |
db.Close();
|
sl@0
|
82 |
TEST2(err, KErrNone);
|
sl@0
|
83 |
|
sl@0
|
84 |
RFs fs;
|
sl@0
|
85 |
err = fs.Connect();
|
sl@0
|
86 |
TEST2(err, KErrNone);
|
sl@0
|
87 |
|
sl@0
|
88 |
err = BaflUtils::CopyFile(fs, KAttachDb, KPrivateTestDb);
|
sl@0
|
89 |
TEST2(err, KErrNone);
|
sl@0
|
90 |
}
|
sl@0
|
91 |
|
sl@0
|
92 |
void MarkHandles()
|
sl@0
|
93 |
{
|
sl@0
|
94 |
RThread().HandleCount(TheHandleCount1B, TheHandleCount2B);
|
sl@0
|
95 |
}
|
sl@0
|
96 |
|
sl@0
|
97 |
void CheckHandles()
|
sl@0
|
98 |
{
|
sl@0
|
99 |
TInt endHandleCount1E;
|
sl@0
|
100 |
TInt endHandleCount2E;
|
sl@0
|
101 |
|
sl@0
|
102 |
RThread().HandleCount(endHandleCount1E, endHandleCount2E);
|
sl@0
|
103 |
|
sl@0
|
104 |
TEST(TheHandleCount1B == endHandleCount1E);
|
sl@0
|
105 |
TEST(TheHandleCount2B == endHandleCount2E);
|
sl@0
|
106 |
}
|
sl@0
|
107 |
|
sl@0
|
108 |
void MarkAllocatedCells()
|
sl@0
|
109 |
{
|
sl@0
|
110 |
TheAllocatedCellsCountB = User::CountAllocCells();
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
void CheckAllocatedCells()
|
sl@0
|
114 |
{
|
sl@0
|
115 |
TInt allocatedCellsCountE = User::CountAllocCells();
|
sl@0
|
116 |
TEST(allocatedCellsCountE == TheAllocatedCellsCountB);
|
sl@0
|
117 |
}
|
sl@0
|
118 |
|
sl@0
|
119 |
void PrintEndOfOomTest(TOomTestType aOomTestType, TInt aFailingAllocationNo)
|
sl@0
|
120 |
{
|
sl@0
|
121 |
_LIT(KClientSide, "Client side");
|
sl@0
|
122 |
_LIT(KServerSide, "Server side");
|
sl@0
|
123 |
RDebug::Print(_L("=== %S OOM Test succeeded at heap failure rate of %d ===\r\n"),
|
sl@0
|
124 |
aOomTestType == EClientSideTest ? &KClientSide() : &KServerSide(),
|
sl@0
|
125 |
aFailingAllocationNo);
|
sl@0
|
126 |
}
|
sl@0
|
127 |
|
sl@0
|
128 |
//If aDelayed is true, then the SQL server will delay the heap failure simulation until the database is opened.
|
sl@0
|
129 |
void SetDbHeapFailure(TOomTestType aOomTestType, TInt aFailingAllocationNo, TBool aDelayed)
|
sl@0
|
130 |
{
|
sl@0
|
131 |
const TInt KDelayedDbHeapFailureMask = 0x1000;
|
sl@0
|
132 |
if(aOomTestType == EClientSideTest)
|
sl@0
|
133 |
{
|
sl@0
|
134 |
__UHEAP_SETFAIL(RHeap::EDeterministic, aFailingAllocationNo);
|
sl@0
|
135 |
}
|
sl@0
|
136 |
else
|
sl@0
|
137 |
{
|
sl@0
|
138 |
TSqlResourceTester::SetDbHeapFailure(RHeap::EDeterministic | (aDelayed ? KDelayedDbHeapFailureMask : 0), aFailingAllocationNo);
|
sl@0
|
139 |
}
|
sl@0
|
140 |
}
|
sl@0
|
141 |
|
sl@0
|
142 |
void ResetDbHeapFailure(TOomTestType aOomTestType)
|
sl@0
|
143 |
{
|
sl@0
|
144 |
if(aOomTestType == EClientSideTest)
|
sl@0
|
145 |
{
|
sl@0
|
146 |
__UHEAP_SETFAIL(RHeap::ENone, 0);
|
sl@0
|
147 |
}
|
sl@0
|
148 |
else
|
sl@0
|
149 |
{
|
sl@0
|
150 |
TSqlResourceTester::SetDbHeapFailure(RHeap::ENone, 0);
|
sl@0
|
151 |
}
|
sl@0
|
152 |
}
|
sl@0
|
153 |
|
sl@0
|
154 |
void SetHeapFailure(TOomTestType aOomTestType, TInt aFailingAllocationNo)
|
sl@0
|
155 |
{
|
sl@0
|
156 |
if(aOomTestType == EClientSideTest)
|
sl@0
|
157 |
{
|
sl@0
|
158 |
__UHEAP_SETFAIL(RHeap::EDeterministic, aFailingAllocationNo);
|
sl@0
|
159 |
}
|
sl@0
|
160 |
else
|
sl@0
|
161 |
{
|
sl@0
|
162 |
TSqlResourceTester::Mark();
|
sl@0
|
163 |
TSqlResourceTester::SetHeapFailure(RHeap::EDeterministic, aFailingAllocationNo);
|
sl@0
|
164 |
}
|
sl@0
|
165 |
}
|
sl@0
|
166 |
|
sl@0
|
167 |
void ResetHeapFailure(TOomTestType aOomTestType)
|
sl@0
|
168 |
{
|
sl@0
|
169 |
if(aOomTestType == EClientSideTest)
|
sl@0
|
170 |
{
|
sl@0
|
171 |
__UHEAP_SETFAIL(RHeap::ENone, 0);
|
sl@0
|
172 |
}
|
sl@0
|
173 |
else
|
sl@0
|
174 |
{
|
sl@0
|
175 |
TSqlResourceTester::SetHeapFailure(RHeap::ENone, 0);
|
sl@0
|
176 |
TSqlResourceTester::Check();
|
sl@0
|
177 |
}
|
sl@0
|
178 |
}
|
sl@0
|
179 |
|
sl@0
|
180 |
void CreateTestSecurityPolicy(RSqlSecurityPolicy& aSecurityPolicy)
|
sl@0
|
181 |
{
|
sl@0
|
182 |
TInt err = aSecurityPolicy.Create(KDefaultPolicy);
|
sl@0
|
183 |
TEST2(err, KErrNone);
|
sl@0
|
184 |
|
sl@0
|
185 |
err = aSecurityPolicy.SetDbPolicy(RSqlSecurityPolicy::ESchemaPolicy, KPolicy1);
|
sl@0
|
186 |
TEST2(err, KErrNone);
|
sl@0
|
187 |
err = aSecurityPolicy.SetDbPolicy(RSqlSecurityPolicy::EWritePolicy, KPolicy3);
|
sl@0
|
188 |
TEST2(err, KErrNone);
|
sl@0
|
189 |
|
sl@0
|
190 |
err = aSecurityPolicy.SetPolicy(RSqlSecurityPolicy::ETable, KTableName1, RSqlSecurityPolicy::EReadPolicy, KPolicy1);
|
sl@0
|
191 |
TEST2(err, KErrNone);
|
sl@0
|
192 |
err = aSecurityPolicy.SetPolicy(RSqlSecurityPolicy::ETable, KTableName1, RSqlSecurityPolicy::EWritePolicy, KPolicy2);
|
sl@0
|
193 |
TEST2(err, KErrNone);
|
sl@0
|
194 |
|
sl@0
|
195 |
err = aSecurityPolicy.SetPolicy(RSqlSecurityPolicy::ETable, KTableName2, RSqlSecurityPolicy::EReadPolicy, KPolicy1);
|
sl@0
|
196 |
TEST2(err, KErrNone);
|
sl@0
|
197 |
err = aSecurityPolicy.SetPolicy(RSqlSecurityPolicy::ETable, KTableName3, RSqlSecurityPolicy::EReadPolicy, KPolicy2);
|
sl@0
|
198 |
TEST2(err, KErrNone);
|
sl@0
|
199 |
|
sl@0
|
200 |
err = aSecurityPolicy.SetPolicy(RSqlSecurityPolicy::ETable, KTableName2, RSqlSecurityPolicy::EWritePolicy, KPolicy1);
|
sl@0
|
201 |
TEST2(err, KErrNone);
|
sl@0
|
202 |
|
sl@0
|
203 |
err = aSecurityPolicy.SetPolicy(RSqlSecurityPolicy::ETable, KTableName3, RSqlSecurityPolicy::EWritePolicy, KPolicy3);
|
sl@0
|
204 |
TEST2(err, KErrNone);
|
sl@0
|
205 |
}
|
sl@0
|
206 |
|
sl@0
|
207 |
void CreateAttachDb()
|
sl@0
|
208 |
{
|
sl@0
|
209 |
RSqlDatabase db;
|
sl@0
|
210 |
|
sl@0
|
211 |
TInt err = db.Create(KAttachDb);
|
sl@0
|
212 |
TEST2(err, KErrNone);
|
sl@0
|
213 |
err = db.Exec(_L("CREATE TABLE Aab(F1 INTEGER, F2 TEXT)"));
|
sl@0
|
214 |
TEST(err >= 0);
|
sl@0
|
215 |
db.Close();
|
sl@0
|
216 |
|
sl@0
|
217 |
RSqlSecurityPolicy securityPolicy;
|
sl@0
|
218 |
CreateTestSecurityPolicy(securityPolicy);
|
sl@0
|
219 |
|
sl@0
|
220 |
err = db.Create(KSecureAttachDb, securityPolicy);
|
sl@0
|
221 |
TEST2(err, KErrNone);
|
sl@0
|
222 |
err = db.Exec(_L("CREATE TABLE Aab(F1 INTEGER, F2 TEXT)"));
|
sl@0
|
223 |
TEST(err >= 0);
|
sl@0
|
224 |
db.Close();
|
sl@0
|
225 |
|
sl@0
|
226 |
securityPolicy.Close();
|
sl@0
|
227 |
}
|