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