kerneltest/e32test/system/t_reason2.cpp
changeset 247 d8d70de2bd36
child 271 dc268b18d709
equal deleted inserted replaced
201:43365a9b78a3 247:d8d70de2bd36
       
     1 // Copyright (c) 2010 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\system\t_reason2.cpp
       
    15 // Overview:
       
    16 // Tests system startup reason HAL functions and exception info functions:
       
    17 // API Information:
       
    18 // UserHal::StartupReason() (deprecated), HAL:.Get(ESystemStartupReason,..),
       
    19 // UserHal::FaultReason, UserHal::ExceptionId and UserHal::ExceptionInfo
       
    20 // Details:
       
    21 // - Asks system startup reason from user hal
       
    22 // - Asks system startup reason with replacing hal::get method
       
    23 // - Asks Exception info
       
    24 // Platforms/Drives/Compatibility:
       
    25 // All.
       
    26 // Assumptions/Requirement/Pre-requisites:
       
    27 // Failures and causes:
       
    28 // Base Port information:
       
    29 // 
       
    30 //
       
    31 #define __E32TEST_EXTENSION__
       
    32 
       
    33 #include <e32hal.h>
       
    34 #include <e32test.h>
       
    35 #include <hal.h>
       
    36 #include <u32hal.h>
       
    37 #include <e32svr.h>
       
    38 
       
    39 LOCAL_D RTest test(_L("T_REASON2"));
       
    40 
       
    41 TInt gSysReason=KErrNotSupported;
       
    42 
       
    43 void GetSysStartupReason()
       
    44 	{
       
    45 	test.Next(_L("Get startup reason using (deprecated) UserHal::StartupReason API"));
       
    46 
       
    47 	TMachineStartupType reason;
       
    48 
       
    49 	test_KErrNone(UserHal::StartupReason(reason));
       
    50 	switch (reason)
       
    51 		{
       
    52 		case EStartupCold:			RDebug::Print(_L("Cold Start    ")); break;
       
    53 		case EStartupColdReset: 	RDebug::Print(_L("Cold Reset    ")); break;
       
    54 		case EStartupNewOs: 		RDebug::Print(_L("New OS        ")); break;
       
    55 		case EStartupPowerFail:		RDebug::Print(_L("Power failed  ")); break;
       
    56 		case EStartupWarmReset:		RDebug::Print(_L("Warm Reset    ")); break;
       
    57 		case EStartupKernelFault:	RDebug::Print(_L("Kernel fault  ")); break;
       
    58 		case EStartupSafeReset:		RDebug::Print(_L("Safe Reset    ")); break;
       
    59 		default:
       
    60 			RDebug::Print(_L("<?reason=%d>  "), reason);
       
    61 			test(EFalse); // fail, unknown reason returned
       
    62 			break;
       
    63 		}
       
    64 
       
    65 	// test the replacing API
       
    66 	TInt r=KErrNone;
       
    67 	test.Next(_L("Get system startup reason using HAL::Get()"));
       
    68 	r=HAL::Get(HAL::ESystemStartupReason,gSysReason);
       
    69 #if defined(__WINS__)
       
    70 	test(r=KErrNotSupported);
       
    71 #else
       
    72 	test_KErrNone(r);
       
    73 	switch (gSysReason)
       
    74 		{
       
    75 		case HAL::ESystemStartupReason_Cold:	RDebug::Print(_L("reason:Cold ")); break;
       
    76 		case HAL::ESystemStartupReason_Warm:	RDebug::Print(_L("reason:Warm ")); break;
       
    77 		case HAL::ESystemStartupReason_Fault: 	RDebug::Print(_L("reason:Fault")); break;
       
    78 		default:
       
    79 			RDebug::Print(_L("<?reason=%d>  "), gSysReason);
       
    80 			test(EFalse); // fail, unknown reason returned
       
    81 			break;
       
    82 		}
       
    83 #endif
       
    84 	}
       
    85 
       
    86 void GetExceptionInfo()
       
    87 	{
       
    88 	test.Next(_L("Get exception ID"));
       
    89 	TInt exceptno;
       
    90 	TInt faultno;
       
    91 
       
    92 	TExcInfo exceptInfo;
       
    93 	test_KErrNone(UserHal::ExceptionId(exceptno));
       
    94 				
       
    95 	test.Next(_L("Get exception info"));
       
    96 	test_KErrNone(UserHal::ExceptionInfo(exceptInfo));
       
    97 
       
    98 	test.Next(_L("Get fault reason"));
       
    99 	test_KErrNone(UserHal::FaultReason(faultno));
       
   100 
       
   101 	if (gSysReason==HAL::ESystemStartupReason_Warm || gSysReason==HAL::ESystemStartupReason_Fault)
       
   102 		{
       
   103 		RDebug::Print(_L("(last exception %d: code %08x data %08x) "), exceptno, exceptInfo.iCodeAddress,exceptInfo.iDataAddress);
       
   104 		}
       
   105 				
       
   106 	if (gSysReason==HAL::ESystemStartupReason_Fault)
       
   107 		{
       
   108 		if (faultno == 0x10000000)
       
   109 			{
       
   110 			RDebug::Print(_L("Kernel Exception  "));
       
   111 			}
       
   112 		else
       
   113 			{
       
   114 			if (faultno >= 0x10000)
       
   115 				{
       
   116 				RDebug::Print(_L("Kernel PANIC: %d  "), faultno-0x10000);
       
   117 				}
       
   118 			else
       
   119 				{
       
   120 				RDebug::Print(_L("Kernel FAULT: %d  "), faultno);
       
   121 				}
       
   122 			}
       
   123 		}
       
   124 	}
       
   125 
       
   126 TInt E32Main()
       
   127 	{
       
   128 	test.Title();
       
   129 
       
   130 	test.Start(_L("Test startup reasons from Hal"));
       
   131 
       
   132 	// test startup reason
       
   133 	GetSysStartupReason();
       
   134 
       
   135 	// test exception and fault info UserHal functions
       
   136 	GetExceptionInfo();
       
   137 
       
   138 	test.End();
       
   139 
       
   140 	return KErrNone;
       
   141 	}