os/kernelhwsrv/kerneltest/e32test/power/t_persistrestart.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32test\power\t_persistrestart.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32hal.h>
sl@0
    19
#include <e32modes.h>
sl@0
    20
#include <e32power.h>
sl@0
    21
#include <e32test.h>
sl@0
    22
#include <hal.h>
sl@0
    23
#include <f32file.h>
sl@0
    24
#include <e32uid.h>
sl@0
    25
sl@0
    26
#define TEST_STARTUP_MODE
sl@0
    27
#define TEST_RESTART
sl@0
    28
sl@0
    29
const TInt KStartupModeLess = -1;
sl@0
    30
sl@0
    31
GLDEF_D RTest test(_L("Persist startup mode test"));
sl@0
    32
sl@0
    33
void DoTests()
sl@0
    34
	{
sl@0
    35
	TInt r;
sl@0
    36
	TInt startupMode = -1;
sl@0
    37
	TInt maxStartupModes = -1;
sl@0
    38
	TInt maxCustomRestartReasons = -1;
sl@0
    39
sl@0
    40
	// Read the largest possible persistable value (via HAL Custom Restart)
sl@0
    41
	r = HAL::Get( HALData::EMaximumCustomRestartReasons, maxCustomRestartReasons );
sl@0
    42
	test( r == KErrNone );
sl@0
    43
	test.Printf(_L("Fetching largest possible persistable value (via HAL Custom Restart)..\nmaxCustomRestartReasons = %d\n"), maxCustomRestartReasons);
sl@0
    44
sl@0
    45
	// Read the largest possible persistable value
sl@0
    46
	r = HAL::Get( HALData::EMaximumRestartStartupModes, maxStartupModes );
sl@0
    47
	test( r == KErrNone );
sl@0
    48
	test.Printf(_L("Fetching largest possible persistable value..\nmaxStartupModes = %d\n"), maxStartupModes);
sl@0
    49
sl@0
    50
	// Read the restart reason
sl@0
    51
	r = RProperty::Get(KUidSystemCategory, KSystemStartupModeKey, startupMode);
sl@0
    52
	test( r == KErrNone );
sl@0
    53
	test.Printf(_L("Reading the stored restart value..\nstartupMode = %d\n"), startupMode);
sl@0
    54
sl@0
    55
	// If the restart reason is a default value then it means that the board wasn't restarted with a restart reason.
sl@0
    56
	if( startupMode == EStartupModeUndefined )
sl@0
    57
		{
sl@0
    58
		if ( maxStartupModes != (TInt)0xffffffff )
sl@0
    59
			{
sl@0
    60
			// Persist the startup mode
sl@0
    61
#ifdef TEST_STARTUP_MODE
sl@0
    62
			// Test erroneous values first
sl@0
    63
			r = HAL::Set( HALData::EPersistStartupModeKernel, KStartupModeLess );
sl@0
    64
			test( r == KErrArgument );
sl@0
    65
	
sl@0
    66
			TUint StartupModeMore = maxStartupModes + 1;
sl@0
    67
			r = HAL::Set( HALData::EPersistStartupModeKernel, StartupModeMore );
sl@0
    68
			test( r == KErrArgument );		
sl@0
    69
#endif
sl@0
    70
			}
sl@0
    71
		// Then give a proper value
sl@0
    72
		r = HAL::Set( HALData::EPersistStartupModeKernel, maxStartupModes );
sl@0
    73
		test( r == KErrNone );
sl@0
    74
sl@0
    75
		// Persist contents of HAL file via HALSettings.exe
sl@0
    76
		RProcess process;
sl@0
    77
		r = process.Create(_L("HALSettings.exe"), _L("PERSIST"));
sl@0
    78
		test(r == KErrNone);
sl@0
    79
		TRequestStatus status;
sl@0
    80
		process.Logon(status);
sl@0
    81
		process.Resume();
sl@0
    82
		User::WaitForRequest(status);
sl@0
    83
		process.Close();
sl@0
    84
sl@0
    85
#ifdef TEST_RESTART
sl@0
    86
		// Go ahead and restart the board using a restart reason
sl@0
    87
		test.Printf(_L("Enabling wake up power events to restart..\n"));
sl@0
    88
		r = Power::EnableWakeupEvents(EPwRestart);
sl@0
    89
		test( r == KErrNone );
sl@0
    90
sl@0
    91
		test.Printf(_L("Restarting..\n"));
sl@0
    92
		r = Power::PowerDown();
sl@0
    93
		test( r == KErrNone );
sl@0
    94
#endif
sl@0
    95
		}
sl@0
    96
sl@0
    97
	// If the restart reason is within an allowed range it means that the board has indeed been restarted with a restart reason.
sl@0
    98
	if( startupMode >= 0 && startupMode <= maxStartupModes )
sl@0
    99
		{
sl@0
   100
		// Report the restart reason and check whether it's of the same value with the original restart reason (a constant)
sl@0
   101
		if ( startupMode != maxStartupModes )
sl@0
   102
			test.Printf(_L("\nStartup mode was NOT successfully persisted across system restart.\nStored startup mode = %d"), startupMode);
sl@0
   103
		else
sl@0
   104
			test.Printf(_L("\nStartup mode (%d) was successfully persisted across system restart.\n"), startupMode);
sl@0
   105
		// If the comparison is successful, then exit. Otherwise return the error code.
sl@0
   106
		return;
sl@0
   107
		}
sl@0
   108
	}
sl@0
   109
sl@0
   110
GLDEF_C TInt E32Main()
sl@0
   111
//
sl@0
   112
// Test restarting and persisting a startup mode
sl@0
   113
//
sl@0
   114
    {
sl@0
   115
	test.Start(_L("Test restarting and persisting a startup mode"));
sl@0
   116
	DoTests();
sl@0
   117
 	return(KErrNone);
sl@0
   118
    }