|
1 // Copyright (c) 2006-2009 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 // trestartsys_stepwithmode.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @test |
|
21 @internalComponent - Internal Symbian test code |
|
22 */ |
|
23 |
|
24 #include <hal.h> |
|
25 #include <e32uid.h> |
|
26 #include <e32property.h> |
|
27 #include <s32file.h> |
|
28 #include "restartsys.h" |
|
29 #include "trestartsys_withmode.h" |
|
30 |
|
31 _LIT(KDataFile, "c:\\trestartsys.dat"); |
|
32 |
|
33 CRestartSysWithMode::CRestartSysWithMode(const TDesC& aStepName) |
|
34 { |
|
35 SetTestStepName(aStepName); |
|
36 } |
|
37 |
|
38 CRestartSysWithMode::~CRestartSysWithMode() |
|
39 { |
|
40 delete iScheduler; |
|
41 delete iNotifier; |
|
42 } |
|
43 |
|
44 TVerdict CRestartSysWithMode::doTestStepPreambleL() |
|
45 { |
|
46 // Assert that the test was initialised with a restartmode supported by the hardware |
|
47 TInt KMaxStartupModeSupportedByHardware = 0; |
|
48 HAL::Get(HALData::EMaximumRestartStartupModes, KMaxStartupModeSupportedByHardware); |
|
49 TESTE(KNonDefaultBootMode <= KMaxStartupModeSupportedByHardware, KMaxStartupModeSupportedByHardware); |
|
50 |
|
51 return TestStepResult(); |
|
52 } |
|
53 |
|
54 /** |
|
55 Old Test CaseID APPFWK-RESTARTSYS-0002 |
|
56 New Test CaseID DEVSRVS-SYSSTART-RESTARTSYS-0002 |
|
57 */ |
|
58 |
|
59 TVerdict CRestartSysWithMode::doTestStepL() |
|
60 { |
|
61 INFO_PRINTF1(_L("APPFWK-RESTARTSYS-0002 ---- Restarting system in a specified mode.")); |
|
62 |
|
63 TInt usedBootMode; |
|
64 TEST(KErrNone == RProperty::Get(KUidSystemCategory, KSystemStartupModeKey, usedBootMode)); |
|
65 |
|
66 switch(usedBootMode) |
|
67 { |
|
68 case KDefaultBootMode: |
|
69 { |
|
70 // Test part 1 (prereboot) |
|
71 InitRebootL(); |
|
72 SaveVariablesToFileL(); |
|
73 AssertRestartIsPreemptiveL(); |
|
74 INFO_PRINTF1(_L("End of part 1")); |
|
75 break; |
|
76 } |
|
77 case KNonDefaultBootMode: |
|
78 { |
|
79 // Test part 2 (postreboot) |
|
80 INFO_PRINTF2(_L("Test PASS - Bootmode used for this startup was: %d"), usedBootMode); |
|
81 AssertExpectationsL(); |
|
82 break; |
|
83 } |
|
84 default: |
|
85 { |
|
86 ERR_PRINTF3(_L("Used bootMode = %d, but we were expecting: %d"), usedBootMode, KNonDefaultBootMode); |
|
87 TEST(EFalse); // fail test-step |
|
88 break; |
|
89 } |
|
90 } |
|
91 |
|
92 return TestStepResult(); |
|
93 } |
|
94 |
|
95 /** |
|
96 Initiate a restart in KNonDefaultBootMode |
|
97 */ |
|
98 void CRestartSysWithMode::InitRebootL() |
|
99 { |
|
100 iScheduler = new(ELeave) CActiveScheduler; |
|
101 CActiveScheduler::Install(iScheduler); |
|
102 iNotifier = CSaveNotifier::NewL(*this); |
|
103 |
|
104 // Initiate shutdown sequence |
|
105 INFO_PRINTF1(_L("Requesting restart")); |
|
106 iShutdownInitiated.UniversalTime(); |
|
107 TESTL(KErrNone == RestartSys::RestartSystem(KNonDefaultBootMode)); // leaving TESTL to avoid starting the ActiveScheduler on error |
|
108 |
|
109 // Now expect CRestartTestStepPreReboot::SaveL() to be called to indicate restart event was sent successfully |
|
110 CActiveScheduler::Start(); |
|
111 } |
|
112 |
|
113 /** |
|
114 Log results from this pre-reboot part of the test to a temporary file. |
|
115 Because the Tef-logfile will be overwritten when this test is re-run after the reboot, |
|
116 there is no point in logging to Tef before we reach the post-reboot phase. |
|
117 */ |
|
118 void CRestartSysWithMode::SaveVariablesToFileL() |
|
119 { |
|
120 INFO_PRINTF1(_L("Saving variables to file.")); |
|
121 RFs fs; |
|
122 User::LeaveIfError(fs.Connect()); |
|
123 CleanupClosePushL(fs); |
|
124 RFileWriteStream writeStream; |
|
125 CleanupClosePushL(writeStream); |
|
126 User::LeaveIfError(writeStream.Replace(fs, KDataFile, EFileWrite)); |
|
127 writeStream.WriteInt32L(iShutdownInitiated.Int64()); |
|
128 writeStream.WriteInt32L(iShutdownPerformed.Int64()); |
|
129 writeStream.WriteInt8L(iSaveType); |
|
130 writeStream.CommitL(); |
|
131 CleanupStack::PopAndDestroy(&writeStream); |
|
132 CleanupStack::PopAndDestroy(&fs); |
|
133 } |
|
134 |
|
135 /** |
|
136 If the restart-sequence works as is should, a forced restart will now take place |
|
137 aborting this test while our thread is suspended by the User::After call. |
|
138 |
|
139 But a defect in the initial design of the GT0328 changes to the shutdown-server/client |
|
140 made it possible for a shutdownserver-client to indefinitely delay a restart. |
|
141 |
|
142 This function will try to delay the restart for 5 seconds and then update the temporary |
|
143 file with a new shutdown time. |
|
144 */ |
|
145 void CRestartSysWithMode::AssertRestartIsPreemptiveL() |
|
146 { |
|
147 INFO_PRINTF1(_L("Going to sleep for 5 seconds, waiting for restart...")); |
|
148 User::After(5000000); |
|
149 #ifndef SYSLIBS_TEST |
|
150 INFO_PRINTF1(_L("Woke up, no restart took place. Fail the test...")); |
|
151 TEST(EFalse); |
|
152 #else |
|
153 WARN_PRINTF1(_L("SYSLIBS_TEST Macro is defined, so restart is not possible.")); |
|
154 SetTestStepResult(EPass); //Does not shutdown when SYSLIBS_TEST is defined, we have to look into this later when syslibs/pwrcli will be moved to AFSS. |
|
155 #endif |
|
156 //Log new shutdown-time |
|
157 INFO_PRINTF1(_L("Update the logged time for shutdown.")); |
|
158 iShutdownPerformed.UniversalTime(); |
|
159 SaveVariablesToFileL(); |
|
160 |
|
161 INFO_PRINTF1(_L("Requeue shutdown-server client.")); |
|
162 ASSERT(iNotifier); |
|
163 iNotifier->Queue(); //This will cause the restart-sequence to continue |
|
164 } |
|
165 |
|
166 /** |
|
167 Asserts expectations against details saved in a logfile prior to the restart. |
|
168 */ |
|
169 void CRestartSysWithMode::AssertExpectationsL() |
|
170 { |
|
171 RFs fs; |
|
172 User::LeaveIfError(fs.Connect()); |
|
173 CleanupClosePushL(fs); |
|
174 RFileReadStream readStream; |
|
175 CleanupClosePushL(readStream); |
|
176 INFO_PRINTF1(_L("Will open the datafile containg the pre-reboot results.")); |
|
177 const TInt err = readStream.Open(fs,KDataFile, EFileRead); |
|
178 TESTE(KErrNone == err, err); //fail test fs logfile is missing |
|
179 if(KErrNone == err) |
|
180 { |
|
181 iShutdownInitiated = readStream.ReadInt32L(); |
|
182 iShutdownPerformed = readStream.ReadInt32L(); |
|
183 iSaveType = (TSaveType)readStream.ReadInt8L(); |
|
184 |
|
185 // Log when test was initiated |
|
186 TDateTime init = iShutdownInitiated.DateTime(); |
|
187 INFO_PRINTF5(_L("Shutdown sequence using RestartSys::RestartSystem(%d) was initiated at time %d:%d.%d"), KNonDefaultBootMode, init.Minute(), init.Second(), init.MicroSecond()); |
|
188 |
|
189 // Log when shutdown notification was received |
|
190 const TDateTime exec = iShutdownPerformed.DateTime(); |
|
191 const TTimeIntervalMicroSeconds elapsedTime = iShutdownPerformed.MicroSecondsFrom(iShutdownInitiated); |
|
192 const TInt64 execValue = elapsedTime.Int64(); |
|
193 //Make sure the shutdown was initiated close in time to our request |
|
194 INFO_PRINTF1(_L("Asserting that our shutdownserver client failed to delay the restart for 5 seconds.")); // see AssertRestartIsPreemptiveL |
|
195 TEST((execValue >= 0) && (execValue < 1000000)); // within 1 second |
|
196 INFO_PRINTF5(_L("Shutdown callback occured at time %d:%d.%d (after %d microseconds)"), exec.Minute(), exec.Second(), exec.MicroSecond(), execValue); |
|
197 |
|
198 TESTE(iSaveType == ESaveAll, iSaveType);// ESaveAll is expected from laf shutdown server |
|
199 } |
|
200 CleanupStack::PopAndDestroy(&readStream); |
|
201 TEST(KErrNone == fs.Delete(KDataFile)); |
|
202 CleanupStack::PopAndDestroy(&fs); |
|
203 } |
|
204 |
|
205 /** |
|
206 Called by the shutdown server in syslib/pwrcli when device is initiating a shut down. |
|
207 Logs the aSaveType parameter and the time the restart notification arrives. |
|
208 */ |
|
209 void CRestartSysWithMode::SaveL(TSaveType aSaveType) |
|
210 { |
|
211 iSaveType = aSaveType; |
|
212 iShutdownPerformed.UniversalTime(); |
|
213 |
|
214 //Make sure the shutdown was initiated close in time to our request |
|
215 const TTimeIntervalMicroSeconds elapsedTime = iShutdownPerformed.MicroSecondsFrom(iShutdownInitiated); |
|
216 const TDateTime now = iShutdownPerformed.DateTime(); |
|
217 const TInt64 value = elapsedTime.Int64(); |
|
218 |
|
219 INFO_PRINTF5(_L("Shutdown callback occured at time %d:%d.%d (after %d microseconds)"), now.Minute(), now.Second(), now.MicroSecond(), value); |
|
220 |
|
221 iNotifier->DelayRequeue(); |
|
222 CActiveScheduler::Stop(); |
|
223 } |