|
1 // Copyright (c) 2007-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 the License "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 // e32test\power\t_persistrestart.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32hal.h> |
|
19 #include <e32modes.h> |
|
20 #include <e32power.h> |
|
21 #include <e32test.h> |
|
22 #include <hal.h> |
|
23 #include <f32file.h> |
|
24 #include <e32uid.h> |
|
25 |
|
26 #define TEST_STARTUP_MODE |
|
27 #define TEST_RESTART |
|
28 |
|
29 const TInt KStartupModeLess = -1; |
|
30 |
|
31 GLDEF_D RTest test(_L("Persist startup mode test")); |
|
32 |
|
33 void DoTests() |
|
34 { |
|
35 TInt r; |
|
36 TInt startupMode = -1; |
|
37 TInt maxStartupModes = -1; |
|
38 TInt maxCustomRestartReasons = -1; |
|
39 |
|
40 // Read the largest possible persistable value (via HAL Custom Restart) |
|
41 r = HAL::Get( HALData::EMaximumCustomRestartReasons, maxCustomRestartReasons ); |
|
42 test( r == KErrNone ); |
|
43 test.Printf(_L("Fetching largest possible persistable value (via HAL Custom Restart)..\nmaxCustomRestartReasons = %d\n"), maxCustomRestartReasons); |
|
44 |
|
45 // Read the largest possible persistable value |
|
46 r = HAL::Get( HALData::EMaximumRestartStartupModes, maxStartupModes ); |
|
47 test( r == KErrNone ); |
|
48 test.Printf(_L("Fetching largest possible persistable value..\nmaxStartupModes = %d\n"), maxStartupModes); |
|
49 |
|
50 // Read the restart reason |
|
51 r = RProperty::Get(KUidSystemCategory, KSystemStartupModeKey, startupMode); |
|
52 test( r == KErrNone ); |
|
53 test.Printf(_L("Reading the stored restart value..\nstartupMode = %d\n"), startupMode); |
|
54 |
|
55 // If the restart reason is a default value then it means that the board wasn't restarted with a restart reason. |
|
56 if( startupMode == EStartupModeUndefined ) |
|
57 { |
|
58 if ( maxStartupModes != (TInt)0xffffffff ) |
|
59 { |
|
60 // Persist the startup mode |
|
61 #ifdef TEST_STARTUP_MODE |
|
62 // Test erroneous values first |
|
63 r = HAL::Set( HALData::EPersistStartupModeKernel, KStartupModeLess ); |
|
64 test( r == KErrArgument ); |
|
65 |
|
66 TUint StartupModeMore = maxStartupModes + 1; |
|
67 r = HAL::Set( HALData::EPersistStartupModeKernel, StartupModeMore ); |
|
68 test( r == KErrArgument ); |
|
69 #endif |
|
70 } |
|
71 // Then give a proper value |
|
72 r = HAL::Set( HALData::EPersistStartupModeKernel, maxStartupModes ); |
|
73 test( r == KErrNone ); |
|
74 |
|
75 // Persist contents of HAL file via HALSettings.exe |
|
76 RProcess process; |
|
77 r = process.Create(_L("HALSettings.exe"), _L("PERSIST")); |
|
78 test(r == KErrNone); |
|
79 TRequestStatus status; |
|
80 process.Logon(status); |
|
81 process.Resume(); |
|
82 User::WaitForRequest(status); |
|
83 process.Close(); |
|
84 |
|
85 #ifdef TEST_RESTART |
|
86 // Go ahead and restart the board using a restart reason |
|
87 test.Printf(_L("Enabling wake up power events to restart..\n")); |
|
88 r = Power::EnableWakeupEvents(EPwRestart); |
|
89 test( r == KErrNone ); |
|
90 |
|
91 test.Printf(_L("Restarting..\n")); |
|
92 r = Power::PowerDown(); |
|
93 test( r == KErrNone ); |
|
94 #endif |
|
95 } |
|
96 |
|
97 // If the restart reason is within an allowed range it means that the board has indeed been restarted with a restart reason. |
|
98 if( startupMode >= 0 && startupMode <= maxStartupModes ) |
|
99 { |
|
100 // Report the restart reason and check whether it's of the same value with the original restart reason (a constant) |
|
101 if ( startupMode != maxStartupModes ) |
|
102 test.Printf(_L("\nStartup mode was NOT successfully persisted across system restart.\nStored startup mode = %d"), startupMode); |
|
103 else |
|
104 test.Printf(_L("\nStartup mode (%d) was successfully persisted across system restart.\n"), startupMode); |
|
105 // If the comparison is successful, then exit. Otherwise return the error code. |
|
106 return; |
|
107 } |
|
108 } |
|
109 |
|
110 GLDEF_C TInt E32Main() |
|
111 // |
|
112 // Test restarting and persisting a startup mode |
|
113 // |
|
114 { |
|
115 test.Start(_L("Test restarting and persisting a startup mode")); |
|
116 DoTests(); |
|
117 return(KErrNone); |
|
118 } |