|
1 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <e32test.h> |
|
17 #include <e32debug.h> |
|
18 #include <bautils.h> |
|
19 #include <featurecontrol.h> |
|
20 #include "t_fmgrbursim.h" |
|
21 |
|
22 /////////////////////////////////////////////////////////////////////////////////////// |
|
23 |
|
24 RTest TheTest(_L("t_fmgrbackupresponse")); |
|
25 |
|
26 const TUint threadTimeout = 2000000; // thread timeout = 2 seconds |
|
27 |
|
28 static RSemaphore MainThreadCrS; |
|
29 static TBool featMgrIsResponsive = EFalse; |
|
30 |
|
31 /////////////////////////////////////////////////////////////////////////////////////// |
|
32 /////////////////////////////////////////////////////////////////////////////////////// |
|
33 //Test macros and functions |
|
34 void Check1(TInt aValue, TInt aLine, TBool aPrintThreadName = EFalse) |
|
35 { |
|
36 if(!aValue) |
|
37 { |
|
38 //DeleteTestFiles(); |
|
39 if(aPrintThreadName) |
|
40 { |
|
41 RThread th; |
|
42 TName name = th.Name(); |
|
43 RDebug::Print(_L("*** Thread %S, Line %d\r\n"), &name, aLine); |
|
44 } |
|
45 else |
|
46 { |
|
47 RDebug::Print(_L("*** Line %d\r\n"), aLine); |
|
48 } |
|
49 TheTest(EFalse, aLine); |
|
50 } |
|
51 } |
|
52 |
|
53 void Check2(TInt aValue, TInt aExpected, TInt aLine, TBool aPrintThreadName = EFalse) |
|
54 { |
|
55 if(aValue != aExpected) |
|
56 { |
|
57 //DeleteTestFiles(); |
|
58 if(aPrintThreadName) |
|
59 { |
|
60 RThread th; |
|
61 TName name = th.Name(); |
|
62 RDebug::Print(_L("*** Thread %S, Line %d Expected error: %d, got: %d\r\n"), &name, aLine, aExpected, aValue); |
|
63 } |
|
64 else |
|
65 { |
|
66 RDebug::Print(_L("*** Line %d, Expected error: %d, got: %d\r\n"), aLine, aExpected, aValue); |
|
67 } |
|
68 TheTest(EFalse, aLine); |
|
69 } |
|
70 } |
|
71 #define TEST(arg) ::Check1((arg), __LINE__) |
|
72 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__) |
|
73 #define TTEST(arg) ::Check1((arg), __LINE__, ETrue) |
|
74 #define TTEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__, ETrue) |
|
75 |
|
76 // ------------------------- ------------------------- |
|
77 // setup and cleanup functions |
|
78 |
|
79 TInt TestThreadL(void*) |
|
80 { |
|
81 __UHEAP_MARK; |
|
82 |
|
83 CTrapCleanup* tc = CTrapCleanup::New(); |
|
84 RFeatureControl rfc; |
|
85 TTEST2( rfc.Connect(), KErrNone ); |
|
86 |
|
87 // During backup, feature manager server should be responsive and return KErrServerBusy for write request |
|
88 TInt err = rfc.EnableFeature( TUid::Uid(0x00000001) ); |
|
89 TTEST2(err, KErrServerBusy); |
|
90 |
|
91 // During backup, feature manager server should be responsive and NOT return KErrServerBusy for read request |
|
92 err = rfc.FeatureSupported( TUid::Uid(0x00000001) ); |
|
93 TTEST(err != KErrServerBusy); |
|
94 |
|
95 rfc.Close(); |
|
96 featMgrIsResponsive = ETrue; |
|
97 RDebug::Print(_L("+++:TestThread: Query and Modification completed\r\n")); |
|
98 MainThreadCrS.Signal(); |
|
99 delete tc; |
|
100 |
|
101 __UHEAP_MARKEND; |
|
102 |
|
103 return KErrNone; |
|
104 } |
|
105 /** |
|
106 @SYMTestCaseID PDS-EFM-CT-4057 |
|
107 @SYMTestCaseDesc Querying and modifying a feature during backup operation. |
|
108 Verify that a response is returned from the server during backup. |
|
109 @SYMTestPriority High |
|
110 @SYMTestActions Start simulating backup operation |
|
111 Create a thread that will: |
|
112 Modify a feature and verify that a response (KErrServerBusy) is received |
|
113 Query a feature and verify that a response is received (doesn't matter what the result is) |
|
114 The thread should finished in less than 2 seconds. |
|
115 Otherwise the test fail. |
|
116 @SYMTestExpectedResults Test must not fail |
|
117 @SYMREQ |
|
118 */ |
|
119 void TestBackupResponseL() |
|
120 { |
|
121 _LIT(KThreadName, "BakTh"); |
|
122 featMgrIsResponsive = EFalse; |
|
123 |
|
124 CFeatMgrBURSim* simulate = CFeatMgrBURSim::NewLC(); |
|
125 RThread testThread; |
|
126 TRequestStatus testStatus; |
|
127 CleanupClosePushL( testThread ); |
|
128 |
|
129 simulate->Simulate_CheckRegFileL(); |
|
130 |
|
131 // Simulate a backup |
|
132 RDebug::Print(_L("Simulating Backup of FeatMgr\r\n")); |
|
133 simulate->Simulate_StartBackupL(); |
|
134 |
|
135 TEST2( testThread.Create(KThreadName, &TestThreadL, 0x2000, 0x1000, 0x10000, NULL, EOwnerProcess), KErrNone ); |
|
136 testThread.Logon(testStatus); |
|
137 TEST2( testStatus.Int(), KRequestPending ); |
|
138 testThread.Resume(); |
|
139 // Wait for 1.5 second for the query thread to finish. |
|
140 RDebug::Print(_L("+++:MainThread: Wait for query and modification completion...\r\n")); |
|
141 MainThreadCrS.Wait(threadTimeout); |
|
142 // If query is responsive within the 1.5 second frame the following check should pass. |
|
143 TEST (featMgrIsResponsive); |
|
144 simulate->Simulate_EndBackupL(); |
|
145 |
|
146 CleanupStack::PopAndDestroy(&testThread); |
|
147 CleanupStack::PopAndDestroy(simulate); |
|
148 } |
|
149 |
|
150 //////////////////////////////////////////////////////////////////////////////////// |
|
151 void DoTestsL() |
|
152 { |
|
153 MainThreadCrS.CreateLocal(0); |
|
154 |
|
155 TheTest.Start(_L(" @SYMTestCaseID:PDS-EFM-CT-4057 Backup Query and Modification Response")); |
|
156 TestBackupResponseL(); |
|
157 |
|
158 MainThreadCrS.Close(); |
|
159 |
|
160 } |
|
161 |
|
162 TInt E32Main() |
|
163 { |
|
164 TheTest.Title(); |
|
165 |
|
166 CTrapCleanup* tc = CTrapCleanup::New(); |
|
167 |
|
168 __UHEAP_MARK; |
|
169 |
|
170 TRAPD(err, DoTestsL()); |
|
171 TEST2(err, KErrNone); |
|
172 |
|
173 __UHEAP_MARKEND; |
|
174 |
|
175 TheTest.End(); |
|
176 TheTest.Close(); |
|
177 |
|
178 delete tc; |
|
179 |
|
180 User::Heap().Check(); |
|
181 return KErrNone; |
|
182 } |