os/kernelhwsrv/kerneltest/e32test/system/t_nanowait.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
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
// e32test\system\t_nanowait.cpp
sl@0
    15
// Overview:
sl@0
    16
// Test Kernal::NanoWait() against the FastCounter.
sl@0
    17
// API Information:
sl@0
    18
// NTimer
sl@0
    19
// Details:
sl@0
    20
// - Start one 100 msec NanoWait delay and verify that the 
sl@0
    21
// delay time is correct.
sl@0
    22
// Platforms/Drives/Compatibility:
sl@0
    23
// All.
sl@0
    24
// Assumptions/Requirement/Pre-requisites:
sl@0
    25
// Failures and causes:
sl@0
    26
// Base Port information:
sl@0
    27
// 
sl@0
    28
//
sl@0
    29
sl@0
    30
#include <e32test.h>
sl@0
    31
#include <e32uid.h>
sl@0
    32
#include <e32hal.h>
sl@0
    33
#include <hal.h>
sl@0
    34
#include "d_nanowait.h"
sl@0
    35
sl@0
    36
RTest test(_L("t_nanowait"));
sl@0
    37
RNanoWait nanowait;
sl@0
    38
sl@0
    39
TBool PauseOnError = 0;
sl@0
    40
#define GETCH()		(PauseOnError&&test.Getch())
sl@0
    41
sl@0
    42
#define TEST(c)		((void)((c)||(test.Printf(_L("Failed at line %d\n"),__LINE__),GETCH(),test(0),0)))
sl@0
    43
#define CHECK(c)	((void)(((c)==0)||(test.Printf(_L("Error %d at line %d\n"),(c),__LINE__),GETCH(),test(0),0)))
sl@0
    44
#ifdef __WINS__
sl@0
    45
#define TESTTIME(v,min,max) test.Printf(_L("Expected range [%d,%d]\n"),min,max+1)
sl@0
    46
#else
sl@0
    47
#define TESTTIME(v,min,max) TEST(v>=min && v<max)
sl@0
    48
#endif
sl@0
    49
sl@0
    50
const TPtrC KLddFileName=_L("D_NANOWAIT.LDD");
sl@0
    51
sl@0
    52
GLDEF_C TInt E32Main()
sl@0
    53
//
sl@0
    54
// Test NanoWait() delays
sl@0
    55
//
sl@0
    56
    {
sl@0
    57
sl@0
    58
    
sl@0
    59
    // To use in command line
sl@0
    60
    	TBool pause = EFalse;
sl@0
    61
    TBuf<256> cmdline;
sl@0
    62
	User::CommandLine(cmdline);
sl@0
    63
	if( cmdline == _L("-p"))
sl@0
    64
		{
sl@0
    65
			pause = ETrue;			
sl@0
    66
		}
sl@0
    67
sl@0
    68
    
sl@0
    69
	test.Title();
sl@0
    70
sl@0
    71
	test.Start(_L("Load D_NanoWait.LDD"));
sl@0
    72
	TInt r=User::LoadLogicalDevice(KLddFileName);
sl@0
    73
	TEST(r==KErrNone || r==KErrAlreadyExists);
sl@0
    74
	
sl@0
    75
	test.Next(_L("Test NanoWait delay"));
sl@0
    76
	r=nanowait.Open();
sl@0
    77
	CHECK(r);
sl@0
    78
sl@0
    79
	TInt requested = 100000000;  // nsec = 100 msec
sl@0
    80
	TUint32 startTick;
sl@0
    81
	TUint32 endTick;
sl@0
    82
	
sl@0
    83
	TInt nanokernel_tick_period;
sl@0
    84
	HAL::Get(HAL::ENanoTickPeriod, nanokernel_tick_period );
sl@0
    85
	nanokernel_tick_period *= 1000; 	// convert from micro sec to nsec
sl@0
    86
sl@0
    87
	
sl@0
    88
	test.Printf(_L("Test parameters: total requested:%d nsec\n"), requested);
sl@0
    89
	
sl@0
    90
	startTick = User::NTickCount();
sl@0
    91
	r=nanowait.StartNanoWait(1, requested);
sl@0
    92
	endTick = User::NTickCount();
sl@0
    93
	
sl@0
    94
	startTick *= nanokernel_tick_period;	// in nsec
sl@0
    95
	endTick   *= nanokernel_tick_period;	// in nsec
sl@0
    96
	
sl@0
    97
	TInt measured  = endTick-startTick;
sl@0
    98
	TInt diff = measured - requested;
sl@0
    99
	test.Printf(_L("Requested delay:%10d nsec\n"), requested);
sl@0
   100
	test.Printf(_L("Measured delay :%10d nsec\n"), measured);
sl@0
   101
	test.Printf(_L("Difference     :%10d nsec\n"), diff);
sl@0
   102
	
sl@0
   103
	
sl@0
   104
	test.End();
sl@0
   105
	if( pause )
sl@0
   106
		{
sl@0
   107
		test.Printf(_L("Press any key\n"));
sl@0
   108
		test.Getch();	
sl@0
   109
		}
sl@0
   110
	
sl@0
   111
	return(KErrNone);
sl@0
   112
    }
sl@0
   113