Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\power\t_persistrestart.cpp
26 #define TEST_STARTUP_MODE
29 const TInt KStartupModeLess = -1;
31 GLDEF_D RTest test(_L("Persist startup mode test"));
36 TInt startupMode = -1;
37 TInt maxStartupModes = -1;
38 TInt maxCustomRestartReasons = -1;
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);
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);
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);
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 )
58 if ( maxStartupModes != (TInt)0xffffffff )
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 );
66 TUint StartupModeMore = maxStartupModes + 1;
67 r = HAL::Set( HALData::EPersistStartupModeKernel, StartupModeMore );
68 test( r == KErrArgument );
71 // Then give a proper value
72 r = HAL::Set( HALData::EPersistStartupModeKernel, maxStartupModes );
73 test( r == KErrNone );
75 // Persist contents of HAL file via HALSettings.exe
77 r = process.Create(_L("HALSettings.exe"), _L("PERSIST"));
79 TRequestStatus status;
80 process.Logon(status);
82 User::WaitForRequest(status);
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 );
91 test.Printf(_L("Restarting..\n"));
92 r = Power::PowerDown();
93 test( r == KErrNone );
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 )
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);
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.
110 GLDEF_C TInt E32Main()
112 // Test restarting and persisting a startup mode
115 test.Start(_L("Test restarting and persisting a startup mode"));