1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/power/t_persistrestart.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,118 @@
1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\power\t_persistrestart.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32hal.h>
1.22 +#include <e32modes.h>
1.23 +#include <e32power.h>
1.24 +#include <e32test.h>
1.25 +#include <hal.h>
1.26 +#include <f32file.h>
1.27 +#include <e32uid.h>
1.28 +
1.29 +#define TEST_STARTUP_MODE
1.30 +#define TEST_RESTART
1.31 +
1.32 +const TInt KStartupModeLess = -1;
1.33 +
1.34 +GLDEF_D RTest test(_L("Persist startup mode test"));
1.35 +
1.36 +void DoTests()
1.37 + {
1.38 + TInt r;
1.39 + TInt startupMode = -1;
1.40 + TInt maxStartupModes = -1;
1.41 + TInt maxCustomRestartReasons = -1;
1.42 +
1.43 + // Read the largest possible persistable value (via HAL Custom Restart)
1.44 + r = HAL::Get( HALData::EMaximumCustomRestartReasons, maxCustomRestartReasons );
1.45 + test( r == KErrNone );
1.46 + test.Printf(_L("Fetching largest possible persistable value (via HAL Custom Restart)..\nmaxCustomRestartReasons = %d\n"), maxCustomRestartReasons);
1.47 +
1.48 + // Read the largest possible persistable value
1.49 + r = HAL::Get( HALData::EMaximumRestartStartupModes, maxStartupModes );
1.50 + test( r == KErrNone );
1.51 + test.Printf(_L("Fetching largest possible persistable value..\nmaxStartupModes = %d\n"), maxStartupModes);
1.52 +
1.53 + // Read the restart reason
1.54 + r = RProperty::Get(KUidSystemCategory, KSystemStartupModeKey, startupMode);
1.55 + test( r == KErrNone );
1.56 + test.Printf(_L("Reading the stored restart value..\nstartupMode = %d\n"), startupMode);
1.57 +
1.58 + // If the restart reason is a default value then it means that the board wasn't restarted with a restart reason.
1.59 + if( startupMode == EStartupModeUndefined )
1.60 + {
1.61 + if ( maxStartupModes != (TInt)0xffffffff )
1.62 + {
1.63 + // Persist the startup mode
1.64 +#ifdef TEST_STARTUP_MODE
1.65 + // Test erroneous values first
1.66 + r = HAL::Set( HALData::EPersistStartupModeKernel, KStartupModeLess );
1.67 + test( r == KErrArgument );
1.68 +
1.69 + TUint StartupModeMore = maxStartupModes + 1;
1.70 + r = HAL::Set( HALData::EPersistStartupModeKernel, StartupModeMore );
1.71 + test( r == KErrArgument );
1.72 +#endif
1.73 + }
1.74 + // Then give a proper value
1.75 + r = HAL::Set( HALData::EPersistStartupModeKernel, maxStartupModes );
1.76 + test( r == KErrNone );
1.77 +
1.78 + // Persist contents of HAL file via HALSettings.exe
1.79 + RProcess process;
1.80 + r = process.Create(_L("HALSettings.exe"), _L("PERSIST"));
1.81 + test(r == KErrNone);
1.82 + TRequestStatus status;
1.83 + process.Logon(status);
1.84 + process.Resume();
1.85 + User::WaitForRequest(status);
1.86 + process.Close();
1.87 +
1.88 +#ifdef TEST_RESTART
1.89 + // Go ahead and restart the board using a restart reason
1.90 + test.Printf(_L("Enabling wake up power events to restart..\n"));
1.91 + r = Power::EnableWakeupEvents(EPwRestart);
1.92 + test( r == KErrNone );
1.93 +
1.94 + test.Printf(_L("Restarting..\n"));
1.95 + r = Power::PowerDown();
1.96 + test( r == KErrNone );
1.97 +#endif
1.98 + }
1.99 +
1.100 + // If the restart reason is within an allowed range it means that the board has indeed been restarted with a restart reason.
1.101 + if( startupMode >= 0 && startupMode <= maxStartupModes )
1.102 + {
1.103 + // Report the restart reason and check whether it's of the same value with the original restart reason (a constant)
1.104 + if ( startupMode != maxStartupModes )
1.105 + test.Printf(_L("\nStartup mode was NOT successfully persisted across system restart.\nStored startup mode = %d"), startupMode);
1.106 + else
1.107 + test.Printf(_L("\nStartup mode (%d) was successfully persisted across system restart.\n"), startupMode);
1.108 + // If the comparison is successful, then exit. Otherwise return the error code.
1.109 + return;
1.110 + }
1.111 + }
1.112 +
1.113 +GLDEF_C TInt E32Main()
1.114 +//
1.115 +// Test restarting and persisting a startup mode
1.116 +//
1.117 + {
1.118 + test.Start(_L("Test restarting and persisting a startup mode"));
1.119 + DoTests();
1.120 + return(KErrNone);
1.121 + }