|
1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32math.h> |
|
22 #include <StartupDomainPSKeys.h> |
|
23 #include "daemonmt.h" |
|
24 |
|
25 |
|
26 |
|
27 // ============================ MEMBER FUNCTIONS =============================== |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // Cdaemonmt::Case |
|
31 // Returns a test case by number. |
|
32 // |
|
33 // This function contains an array of all available test cases |
|
34 // i.e pair of case name and test function. If case specified by parameter |
|
35 // aCaseNumber is found from array, then that item is returned. |
|
36 // |
|
37 // The reason for this rather complicated function is to specify all the |
|
38 // test cases only in one place. It is not necessary to understand how |
|
39 // function pointers to class member functions works when adding new test |
|
40 // cases. See function body for instructions how to add new test case. |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 const TCaseInfo Cdaemonmt::Case ( |
|
44 const TInt aCaseNumber ) const |
|
45 { |
|
46 |
|
47 /** |
|
48 * To add new test cases, implement new test case function and add new |
|
49 * line to KCases array specify the name of the case and the function |
|
50 * doing the test case |
|
51 * In practice, do following |
|
52 * 1) Make copy of existing test case function and change its name |
|
53 * and functionality. Note that the function must be added to |
|
54 * daemonmt.cpp file and to daemonmt.h |
|
55 * header file. |
|
56 * |
|
57 * 2) Add entry to following KCases array either by using: |
|
58 * |
|
59 * 2.1: FUNCENTRY or ENTRY macro |
|
60 * ENTRY macro takes two parameters: test case name and test case |
|
61 * function name. |
|
62 * |
|
63 * FUNCENTRY macro takes only test case function name as a parameter and |
|
64 * uses that as a test case name and test case function name. |
|
65 * |
|
66 * Or |
|
67 * |
|
68 * 2.2: OOM_FUNCENTRY or OOM_ENTRY macro. Note that these macros are used |
|
69 * only with OOM (Out-Of-Memory) testing! |
|
70 * |
|
71 * OOM_ENTRY macro takes five parameters: test case name, test case |
|
72 * function name, TBool which specifies is method supposed to be run using |
|
73 * OOM conditions, TInt value for first heap memory allocation failure and |
|
74 * TInt value for last heap memory allocation failure. |
|
75 * |
|
76 * OOM_FUNCENTRY macro takes test case function name as a parameter and uses |
|
77 * that as a test case name, TBool which specifies is method supposed to be |
|
78 * run using OOM conditions, TInt value for first heap memory allocation |
|
79 * failure and TInt value for last heap memory allocation failure. |
|
80 */ |
|
81 |
|
82 static TCaseInfoInternal const KCases[] = |
|
83 { |
|
84 // To add new test cases, add new items to this array |
|
85 ENTRY( "StartDaemon test", Cdaemonmt::StartDaemon ) |
|
86 }; |
|
87 |
|
88 // Verify that case number is valid |
|
89 if( (TUint) aCaseNumber >= sizeof( KCases ) / |
|
90 sizeof( TCaseInfoInternal ) ) |
|
91 { |
|
92 // Invalid case, construct empty object |
|
93 TCaseInfo null( (const TText*) L"" ); |
|
94 null.iMethod = NULL; |
|
95 null.iIsOOMTest = EFalse; |
|
96 null.iFirstMemoryAllocation = 0; |
|
97 null.iLastMemoryAllocation = 0; |
|
98 return null; |
|
99 } |
|
100 |
|
101 // Construct TCaseInfo object and return it |
|
102 TCaseInfo tmp ( KCases[ aCaseNumber ].iCaseName ); |
|
103 tmp.iMethod = KCases[ aCaseNumber ].iMethod; |
|
104 tmp.iIsOOMTest = KCases[ aCaseNumber ].iIsOOMTest; |
|
105 tmp.iFirstMemoryAllocation = KCases[ aCaseNumber ].iFirstMemoryAllocation; |
|
106 tmp.iLastMemoryAllocation = KCases[ aCaseNumber ].iLastMemoryAllocation; |
|
107 return tmp; |
|
108 } |
|
109 |
|
110 |
|
111 TInt Cdaemonmt::StartDaemon( TTestResult& aResult ) |
|
112 { |
|
113 iBtSettings = CBtSettings::NewL(); |
|
114 iLog->Log( _L( "Starting test and setting BT Power ON" ) ); |
|
115 TInt error = iBtSettings->SetPowerState( EBTPowerOn ); |
|
116 if( error ) |
|
117 { |
|
118 iLog->Log( _L( "Error %d when setting BT power state" ), error ); |
|
119 aResult.SetResult( KErrGeneral, _L( "StartDaemon failed" ) ); |
|
120 return KErrNone; |
|
121 } |
|
122 |
|
123 TInt systemState = KErrNone; |
|
124 error = iProperty.Get( KPSUidStartup, KPSGlobalSystemState, systemState ); |
|
125 if( error ) |
|
126 { |
|
127 iLog->Log( _L( "Failed to get GlobalSystemState" ) ); |
|
128 } |
|
129 |
|
130 // Switching GlobalSystemState to ESwStateShuttingDown causes locod |
|
131 // not to load bearer plugins immediately after its starts. |
|
132 iLog->Log( _L( "Changing GlobalSystemState to ESwStateShuttingDown" ) ); |
|
133 error = iProperty.Set( KPSUidStartup, KPSGlobalSystemState, ESwStateShuttingDown ); |
|
134 if( error ) |
|
135 { |
|
136 iLog->Log( _L( "Failed to switch GlobalSystemState to ESwStateShuttingDown with error: %d" ), error ); |
|
137 aResult.SetResult( KErrGeneral, _L( "StartDaemon failed" ) ); |
|
138 return KErrNone; |
|
139 } |
|
140 |
|
141 _LIT(KDaemonExe, "locod.exe"); |
|
142 // Starts Daemon in a new process. |
|
143 const TUidType exeUid(KNullUid, KNullUid, TUid::Uid(0x2000276D)); |
|
144 RProcess daemon; |
|
145 TInt r = daemon.Create(KDaemonExe, KNullDesC, exeUid); |
|
146 TBuf<256> err; |
|
147 if (r != KErrNone) |
|
148 { |
|
149 _LIT( KDescription, "StartDaemon failed: daemon.Create() %d" ); |
|
150 aResult.SetResult( r, KDescription ); |
|
151 err.Format( KDescription, r); |
|
152 iLog->Log( err ); |
|
153 return r; |
|
154 } |
|
155 daemon.Resume(); |
|
156 |
|
157 // Switching GlobalSystemState to ESwStateNormalRfOn causes locod |
|
158 // to load bearer plugins. |
|
159 iLog->Log( _L( "Changing GlobalSystemState to ESwStateNormalRfOn" ) ); |
|
160 error = iProperty.Set( KPSUidStartup, KPSGlobalSystemState, ESwStateNormalRfOn ); |
|
161 if( error ) |
|
162 { |
|
163 iLog->Log( _L( "Failed to switch GlobalSystemState to ESwStateNormalRfOn with error: %d" ), error ); |
|
164 aResult.SetResult( KErrGeneral, _L( "StartDaemon failed" ) ); |
|
165 return KErrNone; |
|
166 } |
|
167 |
|
168 User::After( 2000000 ); |
|
169 |
|
170 // Switching GlobalSystemState to ESwStateShuttingDown causes locod |
|
171 // to unload bearer plugins. |
|
172 iLog->Log( _L( "Changing GlobalSystemState to ESwStateShuttingDown" ) ); |
|
173 error = iProperty.Set( KPSUidStartup, KPSGlobalSystemState, ESwStateShuttingDown ); |
|
174 if( error ) |
|
175 { |
|
176 iLog->Log( _L( "Failed to switch GlobalSystemState to ESwStateShuttingDown with error: %d" ), error ); |
|
177 aResult.SetResult( KErrGeneral, _L( "StartDaemon failed" ) ); |
|
178 return KErrNone; |
|
179 } |
|
180 |
|
181 User::After( 2000000 ); |
|
182 daemon.Close(); |
|
183 |
|
184 // Switching GlobalSystemState to the state forom the start of the test to leave the LC stack |
|
185 // working after the test. |
|
186 if( systemState != KErrNone ) |
|
187 { |
|
188 iLog->Log( _L( "Changing GlobalSystemState to %d" ), systemState ); |
|
189 error = iProperty.Set( KPSUidStartup, KPSGlobalSystemState, systemState ); |
|
190 } |
|
191 else |
|
192 { |
|
193 iLog->Log( _L( "Changing GlobalSystemState to ESwStateNormalRfOn" ) ); |
|
194 error = iProperty.Set( KPSUidStartup, KPSGlobalSystemState, ESwStateNormalRfOn ); |
|
195 } |
|
196 |
|
197 if( error ) |
|
198 { |
|
199 iLog->Log( _L( "Failed to switch GlobalSystemState to ESwStateNormalRfOn with error: %d" ), error ); |
|
200 aResult.SetResult( KErrGeneral, _L( "StartDaemon failed" ) ); |
|
201 return KErrNone; |
|
202 } |
|
203 |
|
204 User::After( 2000000 ); |
|
205 |
|
206 iLog->Log( _L( "Ending test and setting BT Power ON" ) ); |
|
207 error = iBtSettings->SetPowerState( EBTPowerOn ); |
|
208 if( error ) |
|
209 { |
|
210 iLog->Log( _L( "Error %d when setting BT power state" ), error ); |
|
211 aResult.SetResult( KErrGeneral, _L( "StartDaemon failed" ) ); |
|
212 return KErrNone; |
|
213 } |
|
214 |
|
215 User::After( 2000000 ); |
|
216 |
|
217 delete iBtSettings; |
|
218 iBtSettings = NULL; |
|
219 |
|
220 aResult.SetResult( KErrNone, _L( "StartDaemon passed" ) ); |
|
221 return KErrNone; |
|
222 } |
|
223 |
|
224 // End of File |