os/kernelhwsrv/kerneltest/f32test/manager/t_warm.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) 1997-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
// f32test\manager\t_warm.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32test.h>
sl@0
    19
#include <e32svr.h>
sl@0
    20
#include <e32hal.h>
sl@0
    21
#include "u32std.h"
sl@0
    22
#include <f32file.h>
sl@0
    23
sl@0
    24
_LIT(KProgressFileName,"C:\\Progress");
sl@0
    25
sl@0
    26
#define BUF_SIZE	4096
sl@0
    27
sl@0
    28
LOCAL_D RTest test(_L("T_WARM"));
sl@0
    29
GLDEF_D RFs Session;
sl@0
    30
GLDEF_D RFile File;
sl@0
    31
TBuf8<BUF_SIZE> Buffer;
sl@0
    32
TUint Seed[2];
sl@0
    33
sl@0
    34
#if !defined(__WINS__)
sl@0
    35
LOCAL_C TInt Output()
sl@0
    36
	{
sl@0
    37
	TInt err = File.Write(Buffer);
sl@0
    38
	if (err!=KErrNone && err!=KErrDiskFull)
sl@0
    39
		{
sl@0
    40
		File.Close();
sl@0
    41
		Session.Close();
sl@0
    42
		test.Printf(_L("Error writing to file\n"));
sl@0
    43
		test(1==0);
sl@0
    44
		}
sl@0
    45
	return err;
sl@0
    46
	}
sl@0
    47
/*
sl@0
    48
sl@0
    49
LOCAL_C TInt OutputByte(TInt i)
sl@0
    50
	{
sl@0
    51
	TPtrC8 bytePtr( Buffer.Ptr()+i, 1 );
sl@0
    52
	TInt err = File.Write(bytePtr);
sl@0
    53
	if (err!=KErrNone && err!=KErrDiskFull)
sl@0
    54
		{
sl@0
    55
		File.Close();
sl@0
    56
		Session.Close();
sl@0
    57
		test.Printf(_L("Error writing to file\n"));
sl@0
    58
		test(1==0);
sl@0
    59
		}
sl@0
    60
	return err;
sl@0
    61
	}
sl@0
    62
sl@0
    63
  */
sl@0
    64
sl@0
    65
LOCAL_C TInt Input()
sl@0
    66
	{
sl@0
    67
	TInt err = File.Read(Buffer);
sl@0
    68
	if (err!=KErrNone && err!=KErrEof)
sl@0
    69
		{
sl@0
    70
		File.Close();
sl@0
    71
		Session.Close();
sl@0
    72
		test.Printf(_L("Error reading from file\n"));
sl@0
    73
		test(1==0);
sl@0
    74
		}
sl@0
    75
	return err;
sl@0
    76
	}
sl@0
    77
sl@0
    78
LOCAL_C void CreateFile()
sl@0
    79
	{
sl@0
    80
	if ( File.Create(Session, _L("C:\\TESTFILE.BIN"), EFileWrite) == KErrNone )
sl@0
    81
		{
sl@0
    82
		test.Printf(_L("C:\\TESTFILE.BIN created\n"));
sl@0
    83
		}
sl@0
    84
	else
sl@0
    85
		{
sl@0
    86
		File.Close();
sl@0
    87
		Session.Close();
sl@0
    88
		test.Printf(_L("Error opening file\n"));
sl@0
    89
		test(1==0);
sl@0
    90
		}
sl@0
    91
	}
sl@0
    92
sl@0
    93
LOCAL_C void OpenFile()
sl@0
    94
	{
sl@0
    95
	if ( File.Open(Session, _L("C:\\TESTFILE.BIN"), EFileRead) != KErrNone )
sl@0
    96
		{
sl@0
    97
		File.Close();
sl@0
    98
		Session.Close();
sl@0
    99
		test.Printf(_L("Error reading input file\n"));
sl@0
   100
		test(1==0);
sl@0
   101
		}
sl@0
   102
	else
sl@0
   103
		{
sl@0
   104
		test.Printf(_L("C:\\TESTFILE.BIN opened\n"));
sl@0
   105
		}
sl@0
   106
	}
sl@0
   107
sl@0
   108
__NAKED__ TUint Random( TUint * /*aSeed*/ )
sl@0
   109
	{
sl@0
   110
#ifdef __MARM__
sl@0
   111
	// Random number generator
sl@0
   112
	//
sl@0
   113
	// This uses a 33-bit feedback shift register to generate a pseudo-randomly
sl@0
   114
	// ordered sequence of numbers which repeats in a cycle of length 2^33 - 1
sl@0
   115
	//
sl@0
   116
	__SWITCH_TO_ARM;
sl@0
   117
	asm("LDMIA	r0, {r1, r2} ");		// get seed value
sl@0
   118
	asm("MOV	r3, r1, LSR#1 ");		// 33-bit rotate right
sl@0
   119
	asm("ORR	r3, r3, r2, LSL#31 ");	// LSB of r2 into MSB of r3
sl@0
   120
	asm("AND	r2, r1, #1 ");			// LSB of r1 into LSB of r2
sl@0
   121
	asm("EOR	r3, r3, r1, LSL#12 ");	// (involved!)
sl@0
   122
	asm("EOR	r1, r3, r3, LSR#20 ");	// (similarly involved!)
sl@0
   123
	asm("STMIA	r0, {r1, r2} ");		// store new seed
sl@0
   124
	asm("MOV	r0, r1 ");				// return low word of new seed
sl@0
   125
	__JUMP(,lr);
sl@0
   126
	__END_ARM;
sl@0
   127
#endif
sl@0
   128
#if defined(__WINS__) || defined(__X86__)
sl@0
   129
	_asm push ebx
sl@0
   130
	_asm mov ecx, [esp+8]				// get seed pointer
sl@0
   131
	_asm mov eax, [ecx]					// get seed value into edx:eax
sl@0
   132
	_asm mov edx, [ecx+4]
sl@0
   133
	_asm mov ebx, eax					// original eax into ebx
sl@0
   134
	_asm shr edx, 1						// edx lsb into CF
sl@0
   135
	_asm rcr eax, 1						// rotate into eax
sl@0
   136
	_asm adc edx, edx					// LSB into edx lsb
sl@0
   137
	_asm shl ebx, 12
sl@0
   138
	_asm xor eax, ebx					// first involved step
sl@0
   139
	_asm mov ebx, eax
sl@0
   140
	_asm shr ebx, 20
sl@0
   141
	_asm xor eax, ebx					// second involved step
sl@0
   142
	_asm mov [ecx+4], edx				// store top bit of result
sl@0
   143
	_asm mov [ecx], eax					// store bottom 32 bits of result
sl@0
   144
	_asm pop ebx
sl@0
   145
	_asm ret							// return with low word of result in eax
sl@0
   146
#endif
sl@0
   147
	}
sl@0
   148
sl@0
   149
LOCAL_C void GenerateBuffer()
sl@0
   150
	{
sl@0
   151
	TInt i;
sl@0
   152
	TUint *p = (TUint*)Buffer.Ptr();
sl@0
   153
	for (i=0; i<BUF_SIZE/4; i++)
sl@0
   154
		{
sl@0
   155
		*p++ = Random(Seed);
sl@0
   156
		}
sl@0
   157
	Buffer.SetLength(BUF_SIZE);
sl@0
   158
	}
sl@0
   159
sl@0
   160
LOCAL_C TInt VerifyBuffer()
sl@0
   161
	{
sl@0
   162
	TInt i;
sl@0
   163
	TUint *p = (TUint*)Buffer.Ptr();
sl@0
   164
	for (i=0; i<Buffer.Length()/4; i++)
sl@0
   165
		{
sl@0
   166
		if (*p++ != Random(Seed))
sl@0
   167
			{
sl@0
   168
			return(i*4);
sl@0
   169
			}
sl@0
   170
		}
sl@0
   171
	return -1;
sl@0
   172
	}
sl@0
   173
sl@0
   174
LOCAL_C void GenerateFile()
sl@0
   175
	{
sl@0
   176
	TInt size=0;
sl@0
   177
	TInt err = KErrNone;
sl@0
   178
	test.Next(_L("Creating large file containing pseudo-random sequence"));
sl@0
   179
	test( Session.Connect()==KErrNone );
sl@0
   180
	Seed[0] = 0xB504F334;
sl@0
   181
	Seed[1] = 0;
sl@0
   182
sl@0
   183
	// write PRBS sequence to file
sl@0
   184
	CreateFile();
sl@0
   185
	while(err==KErrNone)
sl@0
   186
		{
sl@0
   187
		GenerateBuffer();
sl@0
   188
		err=Output();
sl@0
   189
		if (err==KErrNone)
sl@0
   190
			size+=BUF_SIZE;
sl@0
   191
		}
sl@0
   192
/*
sl@0
   193
//	Fill RAM Drive to last byte
sl@0
   194
	err=KErrNone;
sl@0
   195
	TInt i=0;
sl@0
   196
	while(err==KErrNone)
sl@0
   197
		{
sl@0
   198
		err=OutputByte(i++);
sl@0
   199
		if (err==KErrNone)
sl@0
   200
			size++;
sl@0
   201
		}
sl@0
   202
*/
sl@0
   203
	File.Close();
sl@0
   204
	Session.Close();
sl@0
   205
	test.Printf(_L("Total bytes written %d\n"), size);
sl@0
   206
	User::After(2000000);
sl@0
   207
	}
sl@0
   208
sl@0
   209
LOCAL_C void VerifyFile()
sl@0
   210
	{
sl@0
   211
	TInt err = KErrNone;
sl@0
   212
	TInt i,j;
sl@0
   213
	test.Next(_L("Verifying file containing pseudo-random sequence"));
sl@0
   214
	test( Session.Connect()==KErrNone );
sl@0
   215
	Seed[0] = 0xB504F334;
sl@0
   216
	Seed[1] = 0;
sl@0
   217
sl@0
   218
	// read and verify contents of file
sl@0
   219
	OpenFile();
sl@0
   220
	i=0;
sl@0
   221
	FOREVER
sl@0
   222
		{
sl@0
   223
		err=Input();
sl@0
   224
		if (err==KErrNone && Buffer.Length()!=0)
sl@0
   225
			{
sl@0
   226
			j = VerifyBuffer();
sl@0
   227
			if (j>=0)
sl@0
   228
				{
sl@0
   229
				File.Close();
sl@0
   230
				Session.Close();
sl@0
   231
				test.Printf(_L("Verify error at 0x%08X\n"), j+i );
sl@0
   232
				test(1==0);
sl@0
   233
				}
sl@0
   234
			i+=Buffer.Length();
sl@0
   235
			}
sl@0
   236
		else
sl@0
   237
			break;
sl@0
   238
		}
sl@0
   239
	test.Printf(_L("File verified OK\n"));
sl@0
   240
	test.Printf(_L("Total bytes read %d\n"), i);
sl@0
   241
	File.Close();
sl@0
   242
	Session.Close();
sl@0
   243
	}
sl@0
   244
sl@0
   245
void CauseKernelException()
sl@0
   246
	{
sl@0
   247
	RThread().SetSystem(ETrue);
sl@0
   248
	*((TUint*)0x58000900)=0xDEADDEAD;
sl@0
   249
	}
sl@0
   250
#endif
sl@0
   251
sl@0
   252
#if defined(__WINS__)
sl@0
   253
sl@0
   254
TInt E32Main()
sl@0
   255
//
sl@0
   256
// This test doesn't make sense under WINS
sl@0
   257
//
sl@0
   258
	{
sl@0
   259
	test.Start(_L("No tests under WINS"));
sl@0
   260
	test.End();
sl@0
   261
	return KErrNone;
sl@0
   262
	}
sl@0
   263
sl@0
   264
#else
sl@0
   265
sl@0
   266
GLDEF_C TInt E32Main()
sl@0
   267
//
sl@0
   268
// T_WARM should be run by
sl@0
   269
// copying to RAM as C:\System\libs\eshell.exe and pressing the User Reset button
sl@0
   270
//
sl@0
   271
	{	 
sl@0
   272
sl@0
   273
	test.Title();
sl@0
   274
	if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
sl@0
   275
		test.Start(_L("Test T_WARM is running from RAM as C:\\Sys\\Bin\\ESHELL.EXE"));
sl@0
   276
	else
sl@0
   277
		test.Start(_L("Test T_WARM is running from RAM as C:\\System\\Bin\\ESHELL.EXE"));
sl@0
   278
	RProcess p;
sl@0
   279
	if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
sl@0
   280
		test(p.FileName().CompareF(_L("C:\\Sys\\Bin\\ESHELL.EXE"))==0);
sl@0
   281
	else
sl@0
   282
		test(p.FileName().CompareF(_L("C:\\System\\Bin\\ESHELL.EXE"))==0);
sl@0
   283
	TBuf8<0x100> peaches=_L8("");
sl@0
   284
	TInt i;
sl@0
   285
	for (i=0; i<16; i++)
sl@0
   286
		peaches.Append(_L8("PeachesAndCream_"));
sl@0
   287
sl@0
   288
	test.Next(_L("Check test progress"));
sl@0
   289
	RFs fs;
sl@0
   290
	TInt r=fs.Connect();
sl@0
   291
	test(r==KErrNone);
sl@0
   292
	RFile progress;
sl@0
   293
	TBuf8<0x80> buf;
sl@0
   294
	r=progress.Open(fs,KProgressFileName(),EFileRead|EFileWrite);
sl@0
   295
	if (r==KErrNotFound)
sl@0
   296
		{
sl@0
   297
		test.Next(_L("Setting progress to first test"));
sl@0
   298
		r=progress.Create(fs,KProgressFileName(),EFileRead|EFileWrite);
sl@0
   299
		test(r==KErrNone);
sl@0
   300
		buf=_L8("Warm Reset");
sl@0
   301
		r=progress.Write(buf);
sl@0
   302
		test(r==KErrNone);
sl@0
   303
		}
sl@0
   304
	else
sl@0
   305
		{
sl@0
   306
		r=progress.Read(buf);
sl@0
   307
		test(r==KErrNone);
sl@0
   308
		}
sl@0
   309
sl@0
   310
sl@0
   311
	TBuf<0x10> bufU;
sl@0
   312
	bufU.Copy(buf);
sl@0
   313
	test.Printf(_L("Performing %S test\n"), &bufU);
sl@0
   314
sl@0
   315
	test.Next(_L("Get startup reason"));
sl@0
   316
	TMachineStartupType reason;
sl@0
   317
	UserHal::StartupReason(reason);
sl@0
   318
sl@0
   319
	if (buf==_L8("Warm Reset"))
sl@0
   320
		{
sl@0
   321
		test.Next(_L("Test reason"));
sl@0
   322
		test(reason==EStartupWarmReset);
sl@0
   323
		TInt fault;
sl@0
   324
		test(UserHal::FaultReason(fault)==KErrGeneral);
sl@0
   325
		GenerateFile();
sl@0
   326
		}
sl@0
   327
	else if (buf==_L8("Kernel Fault"))
sl@0
   328
		{
sl@0
   329
		test.Next(_L("Test reason"));
sl@0
   330
		test(reason==EStartupKernelFault);
sl@0
   331
		TInt fault;
sl@0
   332
		test(UserHal::FaultReason(fault)==KErrNone);
sl@0
   333
		test(fault==0x1234);
sl@0
   334
		VerifyFile();
sl@0
   335
		}
sl@0
   336
	else if (buf==_L8("Kernel Exception"))
sl@0
   337
		{
sl@0
   338
		test.Next(_L("Test reason"));
sl@0
   339
		test(reason==EStartupKernelFault);
sl@0
   340
#if defined(__MARM__)
sl@0
   341
		TExcInfo excInfo;
sl@0
   342
		test(UserHal::ExceptionInfo(excInfo)==KErrNone);
sl@0
   343
		test(((TUint) excInfo.iCodeAddress & 0xf0000000)==0x20000000);
sl@0
   344
		test((TUint)excInfo.iDataAddress==0x58000900);
sl@0
   345
		TInt id;
sl@0
   346
		test(UserHal::ExceptionId(id)==KErrNone);
sl@0
   347
		test(id==EExcAccessViolation);
sl@0
   348
#endif
sl@0
   349
		VerifyFile();
sl@0
   350
		}
sl@0
   351
	else if (buf==_L8("Finalise"))
sl@0
   352
		{
sl@0
   353
		test.Next(_L("Test reason"));
sl@0
   354
		test(reason==EStartupWarmReset);
sl@0
   355
		TInt fault;
sl@0
   356
		test(UserHal::FaultReason(fault)==KErrGeneral);
sl@0
   357
		VerifyFile();
sl@0
   358
		}
sl@0
   359
	else
sl@0
   360
		{
sl@0
   361
		test.Next(_L("It's all gone horribly wrong"));
sl@0
   362
		test(EFalse);
sl@0
   363
		}
sl@0
   364
sl@0
   365
sl@0
   366
	//
sl@0
   367
	test.Next(_L("Move on to the next test"));
sl@0
   368
	if (buf==_L8("Warm Reset"))
sl@0
   369
		{
sl@0
   370
		test(progress.Write(0,_L8("Kernel Fault"))==KErrNone);
sl@0
   371
		test.Next(_L("Cause Kernel fault"));
sl@0
   372
		RDebug::Fault(0x1234);
sl@0
   373
		test(EFalse);
sl@0
   374
		}
sl@0
   375
	else if (buf==_L8("Kernel Fault"))
sl@0
   376
		{
sl@0
   377
		test(progress.Write(0,_L8("Kernel Exception"))==KErrNone);
sl@0
   378
		test.Next(_L("Cause Kernel exception"));
sl@0
   379
		CauseKernelException();
sl@0
   380
		test(EFalse);
sl@0
   381
		}
sl@0
   382
	else if (buf==_L8("Kernel Exception"))
sl@0
   383
		{
sl@0
   384
		test(progress.Write(0,_L8("Finalise"))==KErrNone);
sl@0
   385
		test.Next(_L("Press the user reset button..."));
sl@0
   386
		FOREVER ;
sl@0
   387
		}
sl@0
   388
	else if (buf==_L8("Finalise"))
sl@0
   389
		{
sl@0
   390
		test.Next(_L("Removing progress file"));
sl@0
   391
		progress.Close();
sl@0
   392
		r=fs.Delete(KProgressFileName());
sl@0
   393
		test(r==KErrNone);
sl@0
   394
		}
sl@0
   395
	else
sl@0
   396
		{
sl@0
   397
		test.Next(_L("It's all gone horribly wrong"));
sl@0
   398
		test(EFalse);
sl@0
   399
		}
sl@0
   400
sl@0
   401
	test.Printf(_L("\n\nTest completed O.K.\nPress LEFT SHIFT, RIGHT SHIFT and USER RESET to test hard reset\n"));
sl@0
   402
	test.Getch();
sl@0
   403
	test.End();
sl@0
   404
	return(KErrNone);
sl@0
   405
	}
sl@0
   406
sl@0
   407
#endif