os/kernelhwsrv/kerneltest/e32test/nkernsa/utils.h
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) 2006-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\nkernsa\utils.h
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#ifndef __UTILS_H__
sl@0
    19
#define __UTILS_H__
sl@0
    20
#include <e32err.h>
sl@0
    21
#include <nkern.h>
sl@0
    22
sl@0
    23
extern "C" {
sl@0
    24
sl@0
    25
extern TBool InitialThreadDefined;
sl@0
    26
sl@0
    27
extern void SetupMemoryAllocator();
sl@0
    28
extern TAny* malloc(TUint32 aSize);
sl@0
    29
extern void free(TAny* aCell);
sl@0
    30
extern TAny* realloc(TAny* aCell, TUint32 aSize);
sl@0
    31
sl@0
    32
extern TUint32 round_to_page(TUint32 x);
sl@0
    33
sl@0
    34
extern void SpinWait(TUint32 aTicks);
sl@0
    35
extern void nfcfspin(TUint32 aTicks);
sl@0
    36
extern void fcfspin(TUint64 aTicks);
sl@0
    37
extern void DebugPrint(const char*, int);
sl@0
    38
sl@0
    39
extern void __cpu_idle();
sl@0
    40
extern void __cpu_yield();
sl@0
    41
extern TLinAddr __stack_pointer();
sl@0
    42
extern TUint32 __cpu_status_reg();
sl@0
    43
extern TUint32 __cpu_id();
sl@0
    44
extern TUint32 __trace_cpu_num();
sl@0
    45
extern void __finish();
sl@0
    46
sl@0
    47
extern void* memcpy(void*, const void*, unsigned);
sl@0
    48
extern void* memset(void*, int, unsigned);
sl@0
    49
extern void* memclr(void*, unsigned);
sl@0
    50
extern void* wordmove(void*, const void*, unsigned);
sl@0
    51
sl@0
    52
extern TUint32 random(TUint32* aSeed);
sl@0
    53
extern void setup_block(TUint32* aBlock, TInt aNumWords);
sl@0
    54
extern TBool verify_block(const TUint32* aBlock, TInt aNumWords);
sl@0
    55
extern TBool verify_block_no_trace(const TUint32* aBlock, TInt aNumWords);
sl@0
    56
extern void setup_block_cpu(TUint32* aBlock, TInt aNumWords);
sl@0
    57
extern TInt verify_block_cpu_no_trace(const TUint32* aBlock, TInt aNumWords);
sl@0
    58
sl@0
    59
extern TUint64 fast_counter();
sl@0
    60
extern TUint64 fast_counter_freq();
sl@0
    61
extern TUint32 norm_fast_counter();			// normalised to count between 1-2MHz
sl@0
    62
extern TUint32 norm_fast_counter_freq();	// normalised to count between 1-2MHz
sl@0
    63
extern void init_fast_counter();
sl@0
    64
extern TInt __microseconds_to_fast_counter(TInt us);
sl@0
    65
extern TInt __microseconds_to_norm_fast_counter(TInt us);
sl@0
    66
sl@0
    67
extern void DumpMemory(const char* msg, const void* data, int length);
sl@0
    68
}
sl@0
    69
sl@0
    70
#define TEST_PRINT(s)	\
sl@0
    71
	DEBUGPRINT("NKTEST: " s)
sl@0
    72
#define TEST_PRINT1(s, a)	\
sl@0
    73
	DEBUGPRINT("NKTEST: " s, a)
sl@0
    74
#define TEST_PRINT2(s, a, b)	\
sl@0
    75
	DEBUGPRINT("NKTEST: " s, a, b)
sl@0
    76
#define TEST_PRINT3(s, a, b, c)	\
sl@0
    77
	DEBUGPRINT("NKTEST: " s, a, b, c)
sl@0
    78
#define TEST_PRINT4(s, a, b, c, d)	\
sl@0
    79
	DEBUGPRINT("NKTEST: " s, a, b, c, d)
sl@0
    80
#define TEST_PRINT5(s, a, b, c, d, e)	\
sl@0
    81
	DEBUGPRINT("NKTEST: " s, a, b, c, d, e)
sl@0
    82
#define TEST_PRINT6(s, a, b, c, d, e, f)	\
sl@0
    83
	DEBUGPRINT("NKTEST: " s, a, b, c, d, e, f)
sl@0
    84
#define TEST_PRINT7(s, a, b, c, d, e, f, g)	\
sl@0
    85
	DEBUGPRINT("NKTEST: " s, a, b, c, d, e, f, g)
sl@0
    86
#define TRACE_LINE()	\
sl@0
    87
	DEBUGPRINT("NKTEST: line %d", __LINE__)
sl@0
    88
sl@0
    89
#define	TEST_RESULT(x, s)	\
sl@0
    90
	do { if (!(x)) {DEBUGPRINT("NKTEST: " s); DEBUGPRINT("Line %d File %s", __LINE__, __FILE__);}} while(0)
sl@0
    91
#define	TEST_RESULT1(x, s, a)	\
sl@0
    92
	do { if (!(x)) {DEBUGPRINT("NKTEST: " s, a); DEBUGPRINT("Line %d File %s", __LINE__, __FILE__);}} while(0)
sl@0
    93
#define	TEST_RESULT2(x, s, a, b)	\
sl@0
    94
	do { if (!(x)) {DEBUGPRINT("NKTEST: " s, a, b); DEBUGPRINT("Line %d File %s", __LINE__, __FILE__);}} while(0)
sl@0
    95
#define	TEST_RESULT3(x, s, a, b, c)	\
sl@0
    96
	do { if (!(x)) {DEBUGPRINT("NKTEST: " s, a, b, c); DEBUGPRINT("Line %d File %s", __LINE__, __FILE__);}} while(0)
sl@0
    97
#define	TEST_RESULT4(x, s, a, b, c, d)	\
sl@0
    98
	do { if (!(x)) {DEBUGPRINT("NKTEST: " s, a, b, c, d); DEBUGPRINT("Line %d File %s", __LINE__, __FILE__);}} while(0)
sl@0
    99
sl@0
   100
#define TEST_OOM(p)	TEST_RESULT(p, "Out of memory");
sl@0
   101
sl@0
   102
#define RANGE_CHECK(l,x,h)	((l)<=(x) && (x)<=(h))
sl@0
   103
sl@0
   104
#ifdef __SMP__
sl@0
   105
#define	for_each_cpu(cpu)	\
sl@0
   106
for((cpu)=0; (cpu)<NKern::NumberOfCpus(); ++(cpu))
sl@0
   107
#else
sl@0
   108
#define	for_each_cpu(cpu)	\
sl@0
   109
	for((cpu)=0; (cpu)<1; ++(cpu))
sl@0
   110
#endif
sl@0
   111
sl@0
   112
class CircBuf
sl@0
   113
	{
sl@0
   114
public:
sl@0
   115
	static CircBuf* New(TInt aSlots);
sl@0
   116
	CircBuf();
sl@0
   117
	~CircBuf();
sl@0
   118
	TInt TryGet(TUint32& aOut);
sl@0
   119
	TInt TryPut(TUint32 aIn);
sl@0
   120
	TUint32 Get();
sl@0
   121
	void Put(TUint32 aIn);
sl@0
   122
	void Reset();
sl@0
   123
	TInt Count();
sl@0
   124
public:
sl@0
   125
	TUint32* iBufBase;
sl@0
   126
	TInt iSlotCount;
sl@0
   127
	TInt iGetIndex;
sl@0
   128
	TInt iPutIndex;
sl@0
   129
	TSpinLock iLock;
sl@0
   130
	};
sl@0
   131
sl@0
   132
#endif
sl@0
   133
sl@0
   134