sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\power\t_persistrestart.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #define TEST_STARTUP_MODE sl@0: #define TEST_RESTART sl@0: sl@0: const TInt KStartupModeLess = -1; sl@0: sl@0: GLDEF_D RTest test(_L("Persist startup mode test")); sl@0: sl@0: void DoTests() sl@0: { sl@0: TInt r; sl@0: TInt startupMode = -1; sl@0: TInt maxStartupModes = -1; sl@0: TInt maxCustomRestartReasons = -1; sl@0: sl@0: // Read the largest possible persistable value (via HAL Custom Restart) sl@0: r = HAL::Get( HALData::EMaximumCustomRestartReasons, maxCustomRestartReasons ); sl@0: test( r == KErrNone ); sl@0: test.Printf(_L("Fetching largest possible persistable value (via HAL Custom Restart)..\nmaxCustomRestartReasons = %d\n"), maxCustomRestartReasons); sl@0: sl@0: // Read the largest possible persistable value sl@0: r = HAL::Get( HALData::EMaximumRestartStartupModes, maxStartupModes ); sl@0: test( r == KErrNone ); sl@0: test.Printf(_L("Fetching largest possible persistable value..\nmaxStartupModes = %d\n"), maxStartupModes); sl@0: sl@0: // Read the restart reason sl@0: r = RProperty::Get(KUidSystemCategory, KSystemStartupModeKey, startupMode); sl@0: test( r == KErrNone ); sl@0: test.Printf(_L("Reading the stored restart value..\nstartupMode = %d\n"), startupMode); sl@0: sl@0: // If the restart reason is a default value then it means that the board wasn't restarted with a restart reason. sl@0: if( startupMode == EStartupModeUndefined ) sl@0: { sl@0: if ( maxStartupModes != (TInt)0xffffffff ) sl@0: { sl@0: // Persist the startup mode sl@0: #ifdef TEST_STARTUP_MODE sl@0: // Test erroneous values first sl@0: r = HAL::Set( HALData::EPersistStartupModeKernel, KStartupModeLess ); sl@0: test( r == KErrArgument ); sl@0: sl@0: TUint StartupModeMore = maxStartupModes + 1; sl@0: r = HAL::Set( HALData::EPersistStartupModeKernel, StartupModeMore ); sl@0: test( r == KErrArgument ); sl@0: #endif sl@0: } sl@0: // Then give a proper value sl@0: r = HAL::Set( HALData::EPersistStartupModeKernel, maxStartupModes ); sl@0: test( r == KErrNone ); sl@0: sl@0: // Persist contents of HAL file via HALSettings.exe sl@0: RProcess process; sl@0: r = process.Create(_L("HALSettings.exe"), _L("PERSIST")); sl@0: test(r == KErrNone); sl@0: TRequestStatus status; sl@0: process.Logon(status); sl@0: process.Resume(); sl@0: User::WaitForRequest(status); sl@0: process.Close(); sl@0: sl@0: #ifdef TEST_RESTART sl@0: // Go ahead and restart the board using a restart reason sl@0: test.Printf(_L("Enabling wake up power events to restart..\n")); sl@0: r = Power::EnableWakeupEvents(EPwRestart); sl@0: test( r == KErrNone ); sl@0: sl@0: test.Printf(_L("Restarting..\n")); sl@0: r = Power::PowerDown(); sl@0: test( r == KErrNone ); sl@0: #endif sl@0: } sl@0: sl@0: // If the restart reason is within an allowed range it means that the board has indeed been restarted with a restart reason. sl@0: if( startupMode >= 0 && startupMode <= maxStartupModes ) sl@0: { sl@0: // Report the restart reason and check whether it's of the same value with the original restart reason (a constant) sl@0: if ( startupMode != maxStartupModes ) sl@0: test.Printf(_L("\nStartup mode was NOT successfully persisted across system restart.\nStored startup mode = %d"), startupMode); sl@0: else sl@0: test.Printf(_L("\nStartup mode (%d) was successfully persisted across system restart.\n"), startupMode); sl@0: // If the comparison is successful, then exit. Otherwise return the error code. sl@0: return; sl@0: } sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: // sl@0: // Test restarting and persisting a startup mode sl@0: // sl@0: { sl@0: test.Start(_L("Test restarting and persisting a startup mode")); sl@0: DoTests(); sl@0: return(KErrNone); sl@0: }