os/kernelhwsrv/kerneltest/e32test/system/t_atomic.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/system/t_atomic.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1622 @@
     1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32test\system\t_atomic.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#define	__E32TEST_EXTENSION__
    1.22 +
    1.23 +#include <e32test.h>
    1.24 +#include <e32atomics.h>
    1.25 +#include <u32hal.h>
    1.26 +#include "u32std.h"
    1.27 +#include <e32svr.h>
    1.28 +#include <hal.h>
    1.29 +
    1.30 +RTest test(_L("T_ATOMIC"));
    1.31 +
    1.32 +#include "t_atomic.h"
    1.33 +
    1.34 +#ifdef __EPOC32__
    1.35 +RTestAtomic	DD;
    1.36 +#endif
    1.37 +
    1.38 +extern "C" {
    1.39 +extern const char* FuncName[];
    1.40 +extern const PFV AtomicFuncPtr[];
    1.41 +extern const PFV ControlFuncPtr[];
    1.42 +extern const TUint FuncAttr[];
    1.43 +}
    1.44 +
    1.45 +class TestOverflowTruncate2 : public TDes16Overflow
    1.46 +	{
    1.47 +public:
    1.48 +	virtual void Overflow(TDes16 &aDes);
    1.49 +	};
    1.50 +
    1.51 +void TestOverflowTruncate2::Overflow(TDes16& /*aDes*/)
    1.52 +	{
    1.53 +	}
    1.54 +
    1.55 +void UPrintf(const char* aFmt, ...)
    1.56 +	{
    1.57 +	// Print to a console screen.
    1.58 +	TestOverflowTruncate2 overflow;
    1.59 +	VA_LIST list;
    1.60 +	VA_START(list, aFmt);
    1.61 +	TBuf8<256> fmtBuf8((const TUint8*)aFmt);
    1.62 +	TBuf<256> buf;
    1.63 +	buf.AppendFormatList(fmtBuf8.Expand(), list, &overflow);
    1.64 +	test.Printf(_L("%S\n"),&buf);
    1.65 +	}
    1.66 +
    1.67 +/******************************************************************************
    1.68 + * Single thread normal operation tests
    1.69 + ******************************************************************************/
    1.70 +template<class T>
    1.71 +struct TD
    1.72 +	{
    1.73 +	T		i0;
    1.74 +	T		i1;
    1.75 +	T		i2;
    1.76 +	T		i3;
    1.77 +	TInt	iF;
    1.78 +	TInt	iPadding;
    1.79 +	};
    1.80 +
    1.81 +struct TDG : public TDGBase
    1.82 +	{
    1.83 +	void Set(const TD<TUint8>	aTD8,	TInt aOrd);
    1.84 +	void Set(const TD<TUint16>	aTD16,	TInt aOrd);
    1.85 +	void Set(const TD<TUint32>	aTD32,	TInt aOrd);
    1.86 +	void Set(const TD<TUint64>	aTD64,	TInt aOrd);
    1.87 +
    1.88 +	TInt ExecuteUser();
    1.89 +	TInt ExecuteKernel();
    1.90 +	};
    1.91 +
    1.92 +TInt GetAtomicFuncIndex(TInt aFunc, TInt aSize, TInt aOrd)
    1.93 +	{
    1.94 +	test_NotNegative(aFunc);
    1.95 +	test_Compare(aFunc,<,EAtomicFuncN);
    1.96 +	test_NotNegative(aOrd);
    1.97 +	test_Compare(aOrd,<,4);
    1.98 +	aFunc *= 4;
    1.99 +	switch(aSize)
   1.100 +		{
   1.101 +		case 1:	break;
   1.102 +		case 2:	aFunc += INDEXES_PER_SIZE; break;
   1.103 +		case 4:	aFunc += 2*INDEXES_PER_SIZE; break;
   1.104 +		case 8:	aFunc += 3*INDEXES_PER_SIZE; break;
   1.105 +		default: test_Equal(8,aSize); break;
   1.106 +		}
   1.107 +	aFunc += aOrd;
   1.108 +	if (AtomicFuncPtr[aFunc])
   1.109 +		return aFunc;
   1.110 +	return -1;
   1.111 +	}
   1.112 +
   1.113 +void TDG::Set(const TD<TUint8> aTD8, TInt aOrd)
   1.114 +	{
   1.115 +	i0 = aTD8.i0;
   1.116 +	i1 = aTD8.i1;
   1.117 +	i2 = aTD8.i2;
   1.118 +	i3 = aTD8.i3;
   1.119 +	iIndex = GetAtomicFuncIndex(aTD8.iF, 1, aOrd);
   1.120 +#ifdef __EXTRA_DEBUG__
   1.121 +	DEBUGPRINT(" 8: iF=%2d aOrd=%1d -> %d", aTD8.iF, aOrd, iIndex);
   1.122 +#endif
   1.123 +	}
   1.124 +
   1.125 +void TDG::Set(const TD<TUint16> aTD16, TInt aOrd)
   1.126 +	{
   1.127 +	i0 = aTD16.i0;
   1.128 +	i1 = aTD16.i1;
   1.129 +	i2 = aTD16.i2;
   1.130 +	i3 = aTD16.i3;
   1.131 +	iIndex = GetAtomicFuncIndex(aTD16.iF, 2, aOrd);
   1.132 +#ifdef __EXTRA_DEBUG__
   1.133 +	DEBUGPRINT("16: iF=%2d aOrd=%1d -> %d", aTD16.iF, aOrd, iIndex);
   1.134 +#endif
   1.135 +	}
   1.136 +
   1.137 +void TDG::Set(const TD<TUint32> aTD32, TInt aOrd)
   1.138 +	{
   1.139 +	i0 = aTD32.i0;
   1.140 +	i1 = aTD32.i1;
   1.141 +	i2 = aTD32.i2;
   1.142 +	i3 = aTD32.i3;
   1.143 +	iIndex = GetAtomicFuncIndex(aTD32.iF, 4, aOrd);
   1.144 +#ifdef __EXTRA_DEBUG__
   1.145 +	DEBUGPRINT("32: iF=%2d aOrd=%1d -> %d", aTD32.iF, aOrd, iIndex);
   1.146 +#endif
   1.147 +	}
   1.148 +
   1.149 +void TDG::Set(const TD<TUint64> aTD64, TInt aOrd)
   1.150 +	{
   1.151 +	i0 = aTD64.i0;
   1.152 +	i1 = aTD64.i1;
   1.153 +	i2 = aTD64.i2;
   1.154 +	i3 = aTD64.i3;
   1.155 +	iIndex = GetAtomicFuncIndex(aTD64.iF, 8, aOrd);
   1.156 +#ifdef __EXTRA_DEBUG__
   1.157 +	DEBUGPRINT("64: iF=%2d aOrd=%1d -> %d", aTD64.iF, aOrd, iIndex);
   1.158 +#endif
   1.159 +	}
   1.160 +
   1.161 +TInt TDG::ExecuteUser()
   1.162 +	{
   1.163 +	return Execute();
   1.164 +	}
   1.165 +
   1.166 +#ifdef __EPOC32__
   1.167 +TInt TDG::ExecuteKernel()
   1.168 +	{
   1.169 +	return DD.TDGExecuteK(*this);
   1.170 +	}
   1.171 +#endif
   1.172 +
   1.173 +
   1.174 +#define	DCL_TEST_BLOCK(type,name)			\
   1.175 +	static const TD<type> name[] =
   1.176 +#define	DCL_TEST1(type,func,a0)				\
   1.177 +	{	(type)(a0),	(type)(0),	(type)(0),	(type)(0),	(EAtomicFunc##func),	0	}
   1.178 +#define	DCL_TEST2(type,func,a0,a1)			\
   1.179 +	{	(type)(a0),	(type)(a1),	(type)(0),	(type)(0),	(EAtomicFunc##func),	0	}
   1.180 +#define	DCL_TEST3(type,func,a0,a1,a2)		\
   1.181 +	{	(type)(a0),	(type)(a1),	(type)(a2),	(type)(0),	(EAtomicFunc##func),	0	}
   1.182 +#define	DCL_TEST4(type,func,a0,a1,a2,a3)	\
   1.183 +	{	(type)(a0),	(type)(a1),	(type)(a2),	(type)(a3),	(EAtomicFunc##func),	0	}
   1.184 +
   1.185 +DCL_TEST_BLOCK(TUint8,TestData8)
   1.186 +	{
   1.187 +	DCL_TEST1(TUint8,	LOAD,	0x00),
   1.188 +	DCL_TEST1(TUint8,	LOAD,	0xFF),
   1.189 +
   1.190 +	DCL_TEST2(TUint8,	STORE,	0xBB, 0x00),
   1.191 +	DCL_TEST2(TUint8,	STORE,	0xBB, 0xFF),
   1.192 +
   1.193 +	DCL_TEST2(TUint8,	SWP,	0xBB, 0x00),
   1.194 +	DCL_TEST2(TUint8,	SWP,	0xBB, 0xFF),
   1.195 +	DCL_TEST2(TUint8,	SWP,	0x55, 0x00),
   1.196 +	DCL_TEST2(TUint8,	SWP,	0x55, 0xFF),
   1.197 +
   1.198 +	DCL_TEST2(TUint8,	ADD,	0x00, 0x01),
   1.199 +	DCL_TEST2(TUint8,	ADD,	0xFF, 0x01),
   1.200 +	DCL_TEST2(TUint8,	ADD,	0xFE, 0x01),
   1.201 +	DCL_TEST2(TUint8,	ADD,	0xFE, 0x02),
   1.202 +	DCL_TEST2(TUint8,	ADD,	0xFE, 0x03),
   1.203 +	DCL_TEST2(TUint8,	ADD,	0x12, 0x23),
   1.204 +
   1.205 +	DCL_TEST2(TUint8,	AND,	0x00, 0x01),
   1.206 +	DCL_TEST2(TUint8,	AND,	0xFF, 0x01),
   1.207 +	DCL_TEST2(TUint8,	AND,	0xFE, 0x01),
   1.208 +	DCL_TEST2(TUint8,	AND,	0xFE, 0xFF),
   1.209 +	DCL_TEST2(TUint8,	AND,	0xFE, 0x03),
   1.210 +	DCL_TEST2(TUint8,	AND,	0x5F, 0xAF),
   1.211 +
   1.212 +	DCL_TEST2(TUint8,	IOR,	0x00, 0x01),
   1.213 +	DCL_TEST2(TUint8,	IOR,	0xFF, 0x01),
   1.214 +	DCL_TEST2(TUint8,	IOR,	0xFE, 0x01),
   1.215 +	DCL_TEST2(TUint8,	IOR,	0x0D, 0x5F),
   1.216 +	DCL_TEST2(TUint8,	IOR,	0x30, 0x03),
   1.217 +	DCL_TEST2(TUint8,	IOR,	0x5F, 0xAF),
   1.218 +
   1.219 +	DCL_TEST2(TUint8,	XOR,	0x00, 0x01),
   1.220 +	DCL_TEST2(TUint8,	XOR,	0xFF, 0x01),
   1.221 +	DCL_TEST2(TUint8,	XOR,	0xFE, 0x01),
   1.222 +	DCL_TEST2(TUint8,	XOR,	0xFE, 0xFF),
   1.223 +	DCL_TEST2(TUint8,	XOR,	0xFE, 0x03),
   1.224 +	DCL_TEST2(TUint8,	XOR,	0x5F, 0xAF),
   1.225 +
   1.226 +	DCL_TEST3(TUint8,	AXO,	0x00, 0xFF,	0x00),
   1.227 +	DCL_TEST3(TUint8,	AXO,	0x00, 0xFF,	0x33),
   1.228 +	DCL_TEST3(TUint8,	AXO,	0x00, 0xFF,	0x7D),
   1.229 +	DCL_TEST3(TUint8,	AXO,	0x00, 0xFF,	0xBB),
   1.230 +	DCL_TEST3(TUint8,	AXO,	0xAA, 0x00,	0x00),
   1.231 +	DCL_TEST3(TUint8,	AXO,	0xAA, 0x00,	0x33),
   1.232 +	DCL_TEST3(TUint8,	AXO,	0xAA, 0x00,	0x7D),
   1.233 +	DCL_TEST3(TUint8,	AXO,	0xAA, 0x00,	0xBB),
   1.234 +	DCL_TEST3(TUint8,	AXO,	0xAA, 0x33,	0xF0),
   1.235 +	DCL_TEST3(TUint8,	AXO,	0xAA, 0x33,	0x0F),
   1.236 +	DCL_TEST3(TUint8,	AXO,	0xAA, 0xCC,	0xF0),
   1.237 +	DCL_TEST3(TUint8,	AXO,	0xAA, 0xCC,	0x0F),
   1.238 +
   1.239 +	DCL_TEST3(TUint8,	CAS,	0x00, 0xFF,	0xEE),
   1.240 +	DCL_TEST3(TUint8,	CAS,	0x00, 0x01,	0x11),
   1.241 +	DCL_TEST3(TUint8,	CAS,	0x00, 0x00,	0xEE),
   1.242 +	DCL_TEST3(TUint8,	CAS,	0x00, 0x00,	0x23),
   1.243 +	DCL_TEST3(TUint8,	CAS,	0x2A, 0xFF,	0x2B),
   1.244 +	DCL_TEST3(TUint8,	CAS,	0x2A, 0x01,	0x2B),
   1.245 +	DCL_TEST3(TUint8,	CAS,	0x2A, 0x2A,	0x2B),
   1.246 +	DCL_TEST3(TUint8,	CAS,	0x2A, 0x2A,	0x3B),
   1.247 +
   1.248 +	DCL_TEST4(TUint8,	TAU,	0x00, 0x00,	0x02, 0x03),
   1.249 +	DCL_TEST4(TUint8,	TAU,	0x01, 0x00,	0x02, 0x03),
   1.250 +	DCL_TEST4(TUint8,	TAU,	0xFF, 0x00,	0x02, 0x03),
   1.251 +	DCL_TEST4(TUint8,	TAU,	0x00, 0x01,	0x02, 0x03),
   1.252 +	DCL_TEST4(TUint8,	TAU,	0x01, 0x01,	0x02, 0x03),
   1.253 +	DCL_TEST4(TUint8,	TAU,	0x02, 0x01,	0x02, 0x03),
   1.254 +	DCL_TEST4(TUint8,	TAU,	0xFF, 0x01,	0x02, 0x03),
   1.255 +	DCL_TEST4(TUint8,	TAU,	0xFE, 0xFE,	0x23, 0x0B),
   1.256 +	DCL_TEST4(TUint8,	TAU,	0xEE, 0xFE,	0x23, 0x0B),
   1.257 +	DCL_TEST4(TUint8,	TAU,	0xFF, 0xFE,	0x23, 0x0B),
   1.258 +	DCL_TEST4(TUint8,	TAU,	0x00, 0xFE,	0x23, 0x0B),
   1.259 +	DCL_TEST4(TUint8,	TAU,	0xFE, 0xFE,	0x80, 0x7F),
   1.260 +	DCL_TEST4(TUint8,	TAU,	0xEE, 0xFE,	0x80, 0x7F),
   1.261 +	DCL_TEST4(TUint8,	TAU,	0xFF, 0xFE,	0x80, 0x7F),
   1.262 +	DCL_TEST4(TUint8,	TAU,	0x00, 0xFE,	0x80, 0x7F),
   1.263 +	DCL_TEST4(TUint8,	TAU,	0xFE, 0x80,	0x81, 0x7E),
   1.264 +	DCL_TEST4(TUint8,	TAU,	0x7F, 0x80,	0x81, 0x7E),
   1.265 +	DCL_TEST4(TUint8,	TAU,	0x80, 0x80,	0x81, 0x7E),
   1.266 +	DCL_TEST4(TUint8,	TAU,	0x81, 0x80,	0x81, 0x7E),
   1.267 +	DCL_TEST4(TUint8,	TAU,	0x00, 0x80,	0x81, 0x7E),
   1.268 +	DCL_TEST4(TUint8,	TAU,	0x7E, 0x7F,	0x81, 0x7E),
   1.269 +	DCL_TEST4(TUint8,	TAU,	0x7F, 0x7F,	0x81, 0x7E),
   1.270 +	DCL_TEST4(TUint8,	TAU,	0x80, 0x7F,	0x81, 0x7E),
   1.271 +	DCL_TEST4(TUint8,	TAU,	0x81, 0x7F,	0x81, 0x7E),
   1.272 +	DCL_TEST4(TUint8,	TAU,	0x00, 0x7F,	0x81, 0x7E),
   1.273 +
   1.274 +	DCL_TEST4(TUint8,	TAS,	0x00, 0x00,	0x02, 0x03),
   1.275 +	DCL_TEST4(TUint8,	TAS,	0x01, 0x00,	0x02, 0x03),
   1.276 +	DCL_TEST4(TUint8,	TAS,	0xFF, 0x00,	0x02, 0x03),
   1.277 +	DCL_TEST4(TUint8,	TAS,	0x00, 0x01,	0x02, 0x03),
   1.278 +	DCL_TEST4(TUint8,	TAS,	0x01, 0x01,	0x02, 0x03),
   1.279 +	DCL_TEST4(TUint8,	TAS,	0x02, 0x01,	0x02, 0x03),
   1.280 +	DCL_TEST4(TUint8,	TAS,	0xFF, 0x01,	0x02, 0x03),
   1.281 +	DCL_TEST4(TUint8,	TAS,	0xFE, 0xFE,	0x23, 0x0B),
   1.282 +	DCL_TEST4(TUint8,	TAS,	0xEE, 0xFE,	0x23, 0x0B),
   1.283 +	DCL_TEST4(TUint8,	TAS,	0xFF, 0xFE,	0x23, 0x0B),
   1.284 +	DCL_TEST4(TUint8,	TAS,	0x00, 0xFE,	0x23, 0x0B),
   1.285 +	DCL_TEST4(TUint8,	TAS,	0xFE, 0xFE,	0x80, 0x7F),
   1.286 +	DCL_TEST4(TUint8,	TAS,	0xEE, 0xFE,	0x80, 0x7F),
   1.287 +	DCL_TEST4(TUint8,	TAS,	0xFF, 0xFE,	0x80, 0x7F),
   1.288 +	DCL_TEST4(TUint8,	TAS,	0x00, 0xFE,	0x80, 0x7F),
   1.289 +	DCL_TEST4(TUint8,	TAS,	0xFE, 0x80,	0x81, 0x7E),
   1.290 +	DCL_TEST4(TUint8,	TAS,	0x7F, 0x80,	0x81, 0x7E),
   1.291 +	DCL_TEST4(TUint8,	TAS,	0x80, 0x80,	0x81, 0x7E),
   1.292 +	DCL_TEST4(TUint8,	TAS,	0x81, 0x80,	0x81, 0x7E),
   1.293 +	DCL_TEST4(TUint8,	TAS,	0x00, 0x80,	0x81, 0x7E),
   1.294 +	DCL_TEST4(TUint8,	TAS,	0x7E, 0x7F,	0x81, 0x7E),
   1.295 +	DCL_TEST4(TUint8,	TAS,	0x7F, 0x7F,	0x81, 0x7E),
   1.296 +	DCL_TEST4(TUint8,	TAS,	0x80, 0x7F,	0x81, 0x7E),
   1.297 +	DCL_TEST4(TUint8,	TAS,	0x81, 0x7F,	0x81, 0x7E),
   1.298 +	DCL_TEST4(TUint8,	TAS,	0x00, 0x7F,	0x81, 0x7E)
   1.299 +	};
   1.300 +
   1.301 +DCL_TEST_BLOCK(TUint16,TestData16)
   1.302 +	{
   1.303 +	DCL_TEST1(TUint16,	LOAD,	0x0055),
   1.304 +	DCL_TEST1(TUint16,	LOAD,	0xFFAA),
   1.305 +
   1.306 +	DCL_TEST2(TUint16,	STORE,	0xBBBB, 0x0055),
   1.307 +	DCL_TEST2(TUint16,	STORE,	0xBBBB, 0xFFAA),
   1.308 +
   1.309 +	DCL_TEST2(TUint16,	SWP,	0xBBCC, 0x0055),
   1.310 +	DCL_TEST2(TUint16,	SWP,	0xBBCC, 0xFFAA),
   1.311 +	DCL_TEST2(TUint16,	SWP,	0x55AA, 0x0033),
   1.312 +	DCL_TEST2(TUint16,	SWP,	0x55AA, 0xFFCC),
   1.313 +
   1.314 +	DCL_TEST2(TUint16,	ADD,	0x0000, 0x0001),
   1.315 +	DCL_TEST2(TUint16,	ADD,	0xFFFF, 0x0001),
   1.316 +	DCL_TEST2(TUint16,	ADD,	0xFFFE, 0x0001),
   1.317 +	DCL_TEST2(TUint16,	ADD,	0xFFFE, 0x0002),
   1.318 +	DCL_TEST2(TUint16,	ADD,	0xFFFE, 0x0003),
   1.319 +	DCL_TEST2(TUint16,	ADD,	0x0012, 0x0023),
   1.320 +	DCL_TEST2(TUint16,	ADD,	0x0012, 0xBCFF),
   1.321 +
   1.322 +	DCL_TEST2(TUint16,	AND,	0x0000, 0x0001),
   1.323 +	DCL_TEST2(TUint16,	AND,	0xFFFF, 0x0001),
   1.324 +	DCL_TEST2(TUint16,	AND,	0xFFFE, 0x0001),
   1.325 +	DCL_TEST2(TUint16,	AND,	0xFFFE, 0xFFFF),
   1.326 +	DCL_TEST2(TUint16,	AND,	0xFFFE, 0x0F03),
   1.327 +	DCL_TEST2(TUint16,	AND,	0xBC5F, 0x14AF),
   1.328 +
   1.329 +	DCL_TEST2(TUint16,	IOR,	0x0000, 0x0001),
   1.330 +	DCL_TEST2(TUint16,	IOR,	0xFFFF, 0x0001),
   1.331 +	DCL_TEST2(TUint16,	IOR,	0xFFFE, 0x0001),
   1.332 +	DCL_TEST2(TUint16,	IOR,	0x000D, 0x005F),
   1.333 +	DCL_TEST2(TUint16,	IOR,	0x8030, 0x0803),
   1.334 +	DCL_TEST2(TUint16,	IOR,	0x145F, 0x56AF),
   1.335 +
   1.336 +	DCL_TEST2(TUint16,	XOR,	0x0000, 0x0001),
   1.337 +	DCL_TEST2(TUint16,	XOR,	0xFFFF, 0x0001),
   1.338 +	DCL_TEST2(TUint16,	XOR,	0xFFFE, 0x0001),
   1.339 +	DCL_TEST2(TUint16,	XOR,	0xFFFE, 0xFFFF),
   1.340 +	DCL_TEST2(TUint16,	XOR,	0xFFFE, 0x0003),
   1.341 +	DCL_TEST2(TUint16,	XOR,	0x145F, 0xBCAF),
   1.342 +
   1.343 +	DCL_TEST3(TUint16,	AXO,	0x0000, 0xFFFF,	0x0000),
   1.344 +	DCL_TEST3(TUint16,	AXO,	0x0000, 0xFFFF,	0x6633),
   1.345 +	DCL_TEST3(TUint16,	AXO,	0x0000, 0xFFFF,	0x827D),
   1.346 +	DCL_TEST3(TUint16,	AXO,	0x0000, 0xFFFF,	0xCCBB),
   1.347 +	DCL_TEST3(TUint16,	AXO,	0xAAAA, 0x0000,	0x0000),
   1.348 +	DCL_TEST3(TUint16,	AXO,	0xAAAA, 0x0000,	0x6633),
   1.349 +	DCL_TEST3(TUint16,	AXO,	0xAAAA, 0x0000,	0x827D),
   1.350 +	DCL_TEST3(TUint16,	AXO,	0xAAAA, 0x0000,	0xCCBB),
   1.351 +	DCL_TEST3(TUint16,	AXO,	0xAAAA, 0xCC33,	0x0FF0),
   1.352 +	DCL_TEST3(TUint16,	AXO,	0xAAAA, 0xCC33,	0xF00F),
   1.353 +	DCL_TEST3(TUint16,	AXO,	0xAAAA, 0x33CC,	0x0FF0),
   1.354 +	DCL_TEST3(TUint16,	AXO,	0xAAAA, 0x33CC,	0xF00F),
   1.355 +
   1.356 +	DCL_TEST3(TUint16,	CAS,	0x0000, 0x00FF,	0x99EE),
   1.357 +	DCL_TEST3(TUint16,	CAS,	0x0000, 0x0001,	0x7711),
   1.358 +	DCL_TEST3(TUint16,	CAS,	0x0000, 0x0000,	0x99EE),
   1.359 +	DCL_TEST3(TUint16,	CAS,	0x0000, 0x0000,	0x1123),
   1.360 +	DCL_TEST3(TUint16,	CAS,	0x832A, 0xFFFF,	0x832B),
   1.361 +	DCL_TEST3(TUint16,	CAS,	0x832A, 0x0001,	0x832B),
   1.362 +	DCL_TEST3(TUint16,	CAS,	0x832A, 0x822A,	0x832B),
   1.363 +	DCL_TEST3(TUint16,	CAS,	0x832A, 0x832B,	0x943B),
   1.364 +	DCL_TEST3(TUint16,	CAS,	0x832A, 0x832A,	0x832B),
   1.365 +	DCL_TEST3(TUint16,	CAS,	0x832A, 0x832A,	0x943B),
   1.366 +
   1.367 +	DCL_TEST4(TUint16,	TAU,	0x0000, 0x0000,	0x0002, 0x0003),
   1.368 +	DCL_TEST4(TUint16,	TAU,	0x0001, 0x0000,	0x0002, 0x0003),
   1.369 +	DCL_TEST4(TUint16,	TAU,	0xFFFF, 0x0000,	0x0002, 0x0003),
   1.370 +	DCL_TEST4(TUint16,	TAU,	0x0000, 0x0001,	0x0002, 0x0003),
   1.371 +	DCL_TEST4(TUint16,	TAU,	0x0001, 0x0001,	0x0002, 0x0003),
   1.372 +	DCL_TEST4(TUint16,	TAU,	0x0002, 0x0001,	0x0002, 0x0003),
   1.373 +	DCL_TEST4(TUint16,	TAU,	0xFFFF, 0x0001,	0x0002, 0x0003),
   1.374 +	DCL_TEST4(TUint16,	TAU,	0xFFFE, 0xFFFE,	0x1023, 0x000B),
   1.375 +	DCL_TEST4(TUint16,	TAU,	0xFFEE, 0xFFFE,	0x1423, 0x000B),
   1.376 +	DCL_TEST4(TUint16,	TAU,	0xFFFF, 0xFFFE,	0x1423, 0x000B),
   1.377 +	DCL_TEST4(TUint16,	TAU,	0x0000, 0xFFFE,	0x1423, 0x000B),
   1.378 +	DCL_TEST4(TUint16,	TAU,	0xFFFE, 0xFFFE,	0x8000, 0x7FFF),
   1.379 +	DCL_TEST4(TUint16,	TAU,	0xFFEE, 0xFFFE,	0x8000, 0x7FFF),
   1.380 +	DCL_TEST4(TUint16,	TAU,	0xFFFF, 0xFFFE,	0x8000, 0x7FFF),
   1.381 +	DCL_TEST4(TUint16,	TAU,	0x0000, 0xFFFE,	0x8000, 0x7FFF),
   1.382 +	DCL_TEST4(TUint16,	TAU,	0xFFFE, 0x8000,	0x8001, 0x7FFE),
   1.383 +	DCL_TEST4(TUint16,	TAU,	0x7FFF, 0x8000,	0x8001, 0x7FFE),
   1.384 +	DCL_TEST4(TUint16,	TAU,	0x8000, 0x8000,	0x8001, 0x7FFE),
   1.385 +	DCL_TEST4(TUint16,	TAU,	0x8001, 0x8000,	0x8001, 0x7FFE),
   1.386 +	DCL_TEST4(TUint16,	TAU,	0x0000, 0x8000,	0x8001, 0x7FFE),
   1.387 +	DCL_TEST4(TUint16,	TAU,	0x7FFE, 0x7FFF,	0x8001, 0x7FFE),
   1.388 +	DCL_TEST4(TUint16,	TAU,	0x7FFF, 0x7FFF,	0x8001, 0x7FFE),
   1.389 +	DCL_TEST4(TUint16,	TAU,	0x8000, 0x7FFF,	0x8001, 0x7FFE),
   1.390 +	DCL_TEST4(TUint16,	TAU,	0x8001, 0x7FFF,	0x8001, 0x7FFE),
   1.391 +	DCL_TEST4(TUint16,	TAU,	0x0000, 0x7FFF,	0x8001, 0x7FFE),
   1.392 +
   1.393 +	DCL_TEST4(TUint16,	TAS,	0x0000, 0x0000,	0x0002, 0x0003),
   1.394 +	DCL_TEST4(TUint16,	TAS,	0x0001, 0x0000,	0x0002, 0x0003),
   1.395 +	DCL_TEST4(TUint16,	TAS,	0xFFFF, 0x0000,	0x0002, 0x0003),
   1.396 +	DCL_TEST4(TUint16,	TAS,	0x0000, 0x0001,	0x0002, 0x0003),
   1.397 +	DCL_TEST4(TUint16,	TAS,	0x0001, 0x0001,	0x0002, 0x0003),
   1.398 +	DCL_TEST4(TUint16,	TAS,	0x0002, 0x0001,	0x0002, 0x0003),
   1.399 +	DCL_TEST4(TUint16,	TAS,	0xFFFF, 0x0001,	0x0002, 0x0003),
   1.400 +	DCL_TEST4(TUint16,	TAS,	0xFFFE, 0xFFFE,	0x1023, 0x000B),
   1.401 +	DCL_TEST4(TUint16,	TAS,	0xFFEE, 0xFFFE,	0x1423, 0x000B),
   1.402 +	DCL_TEST4(TUint16,	TAS,	0xFFFF, 0xFFFE,	0x1423, 0x000B),
   1.403 +	DCL_TEST4(TUint16,	TAS,	0x0000, 0xFFFE,	0x1423, 0x000B),
   1.404 +	DCL_TEST4(TUint16,	TAS,	0xFFFE, 0xFFFE,	0x8000, 0x7FFF),
   1.405 +	DCL_TEST4(TUint16,	TAS,	0xFFEE, 0xFFFE,	0x8000, 0x7FFF),
   1.406 +	DCL_TEST4(TUint16,	TAS,	0xFFFF, 0xFFFE,	0x8000, 0x7FFF),
   1.407 +	DCL_TEST4(TUint16,	TAS,	0x0000, 0xFFFE,	0x8000, 0x7FFF),
   1.408 +	DCL_TEST4(TUint16,	TAS,	0xFFFE, 0x8000,	0x8001, 0x7FFE),
   1.409 +	DCL_TEST4(TUint16,	TAS,	0x7FFF, 0x8000,	0x8001, 0x7FFE),
   1.410 +	DCL_TEST4(TUint16,	TAS,	0x8000, 0x8000,	0x8001, 0x7FFE),
   1.411 +	DCL_TEST4(TUint16,	TAS,	0x8001, 0x8000,	0x8001, 0x7FFE),
   1.412 +	DCL_TEST4(TUint16,	TAS,	0x0000, 0x8000,	0x8001, 0x7FFE),
   1.413 +	DCL_TEST4(TUint16,	TAS,	0x7FFE, 0x7FFF,	0x8001, 0x7FFE),
   1.414 +	DCL_TEST4(TUint16,	TAS,	0x7FFF, 0x7FFF,	0x8001, 0x7FFE),
   1.415 +	DCL_TEST4(TUint16,	TAS,	0x8000, 0x7FFF,	0x8001, 0x7FFE),
   1.416 +	DCL_TEST4(TUint16,	TAS,	0x8001, 0x7FFF,	0x8001, 0x7FFE),
   1.417 +	DCL_TEST4(TUint16,	TAS,	0x0000, 0x7FFF,	0x8001, 0x7FFE)
   1.418 +	};
   1.419 +
   1.420 +DCL_TEST_BLOCK(TUint32,TestData32)
   1.421 +	{
   1.422 +	DCL_TEST1(TUint32,	LOAD,	0x00334455),
   1.423 +	DCL_TEST1(TUint32,	LOAD,	0xFFCCBBAA),
   1.424 +
   1.425 +	DCL_TEST2(TUint32,	STORE,	0xBBBBBBBB, 0x00334455),
   1.426 +	DCL_TEST2(TUint32,	STORE,	0xBBBBBBBB, 0xFFCCBBAA),
   1.427 +
   1.428 +	DCL_TEST2(TUint32,	SWP,	0xBB1234CC, 0x00EDCB55),
   1.429 +	DCL_TEST2(TUint32,	SWP,	0xBB1234CC, 0xFF9876AA),
   1.430 +	DCL_TEST2(TUint32,	SWP,	0x551971AA, 0x00112233),
   1.431 +	DCL_TEST2(TUint32,	SWP,	0x551971AA, 0xFFEEDDCC),
   1.432 +
   1.433 +	DCL_TEST2(TUint32,	ADD,	0x00000000, 0x00000001),
   1.434 +	DCL_TEST2(TUint32,	ADD,	0xFFFFFFFF, 0x00000001),
   1.435 +	DCL_TEST2(TUint32,	ADD,	0xFFFFFFFE, 0x00000001),
   1.436 +	DCL_TEST2(TUint32,	ADD,	0xFFFFFFFE, 0x00000002),
   1.437 +	DCL_TEST2(TUint32,	ADD,	0xFFFFFFFE, 0x00000003),
   1.438 +	DCL_TEST2(TUint32,	ADD,	0x00009912, 0x00000023),
   1.439 +	DCL_TEST2(TUint32,	ADD,	0x00009912, 0x4937BCFF),
   1.440 +
   1.441 +	DCL_TEST2(TUint32,	AND,	0x00000000, 0x00000001),
   1.442 +	DCL_TEST2(TUint32,	AND,	0xFFFFFFFF, 0x00000001),
   1.443 +	DCL_TEST2(TUint32,	AND,	0xFFFFFFFE, 0x00000001),
   1.444 +	DCL_TEST2(TUint32,	AND,	0xFFFFFFFE, 0xFFFFFFFF),
   1.445 +	DCL_TEST2(TUint32,	AND,	0xFFFFFFFE, 0x00000F03),
   1.446 +	DCL_TEST2(TUint32,	AND,	0xEDCBBC5F, 0xDCBA14AF),
   1.447 +
   1.448 +	DCL_TEST2(TUint32,	IOR,	0x00000000, 0x00000001),
   1.449 +	DCL_TEST2(TUint32,	IOR,	0xFFFFFFFF, 0x00000001),
   1.450 +	DCL_TEST2(TUint32,	IOR,	0xFFFFFFFE, 0x00000001),
   1.451 +	DCL_TEST2(TUint32,	IOR,	0x0000000D, 0x0000005F),
   1.452 +	DCL_TEST2(TUint32,	IOR,	0x80000030, 0x00000803),
   1.453 +	DCL_TEST2(TUint32,	IOR,	0x89AB145F, 0x415256AF),
   1.454 +
   1.455 +	DCL_TEST2(TUint32,	XOR,	0x00000000, 0x00000001),
   1.456 +	DCL_TEST2(TUint32,	XOR,	0xFFFFFFFF, 0x00000001),
   1.457 +	DCL_TEST2(TUint32,	XOR,	0xFFFFFFFE, 0x00000001),
   1.458 +	DCL_TEST2(TUint32,	XOR,	0xFFFFFFFE, 0xFFFFFFFF),
   1.459 +	DCL_TEST2(TUint32,	XOR,	0xFFFFFFFE, 0x00000003),
   1.460 +	DCL_TEST2(TUint32,	XOR,	0x89AB145F, 0x4152BCAF),
   1.461 +
   1.462 +	DCL_TEST3(TUint32,	AXO,	0x00000000, 0xFFFFFFFF,	0x00000000),
   1.463 +	DCL_TEST3(TUint32,	AXO,	0x00000000, 0xFFFFFFFF,	0x99CC6633),
   1.464 +	DCL_TEST3(TUint32,	AXO,	0x00000000, 0xFFFFFFFF,	0x8000027D),
   1.465 +	DCL_TEST3(TUint32,	AXO,	0x00000000, 0xFFFFFFFF,	0xEEDDCCBB),
   1.466 +	DCL_TEST3(TUint32,	AXO,	0xAAAAAAAA, 0x00000000,	0x00000000),
   1.467 +	DCL_TEST3(TUint32,	AXO,	0xAAAAAAAA, 0x00000000,	0x99CC6633),
   1.468 +	DCL_TEST3(TUint32,	AXO,	0xAAAAAAAA, 0x00000000,	0x8000027D),
   1.469 +	DCL_TEST3(TUint32,	AXO,	0xAAAAAAAA, 0x00000000,	0xEEDDCCBB),
   1.470 +	DCL_TEST3(TUint32,	AXO,	0xAAAAAAAA, 0x9966CC33,	0x0FF00FF0),
   1.471 +	DCL_TEST3(TUint32,	AXO,	0xAAAAAAAA, 0x9966CC33,	0xF00FF00F),
   1.472 +	DCL_TEST3(TUint32,	AXO,	0xAAAAAAAA, 0x669933CC,	0x0FF00FF0),
   1.473 +	DCL_TEST3(TUint32,	AXO,	0xAAAAAAAA, 0x669933CC,	0xF00FF00F),
   1.474 +
   1.475 +	DCL_TEST3(TUint32,	CAS,	0x00000000, 0x000000FF,	0x99ABCDEE),
   1.476 +	DCL_TEST3(TUint32,	CAS,	0x00000000, 0x00000001,	0x7FFFF711),
   1.477 +	DCL_TEST3(TUint32,	CAS,	0x00000000, 0x00000000,	0x99ABCDEE),
   1.478 +	DCL_TEST3(TUint32,	CAS,	0x00000000, 0x00000000,	0x11234567),
   1.479 +	DCL_TEST3(TUint32,	CAS,	0x8000032A, 0xFFFFFFFF,	0x8000032B),
   1.480 +	DCL_TEST3(TUint32,	CAS,	0x8000032A, 0x00000001,	0x8000032B),
   1.481 +	DCL_TEST3(TUint32,	CAS,	0x8000032A, 0x8000022A,	0x8000032B),
   1.482 +	DCL_TEST3(TUint32,	CAS,	0x8000032A, 0x8000032B,	0x943BFCD1),
   1.483 +	DCL_TEST3(TUint32,	CAS,	0x8000032A, 0x8000032A,	0x8000032B),
   1.484 +	DCL_TEST3(TUint32,	CAS,	0x8000032A, 0x8000032A,	0x943BFCD1),
   1.485 +
   1.486 +	DCL_TEST4(TUint32,	TAU,	0x00000000, 0x00000000,	0x00000002, 0x00000003),
   1.487 +	DCL_TEST4(TUint32,	TAU,	0x00000001, 0x00000000,	0x00000002, 0x00000003),
   1.488 +	DCL_TEST4(TUint32,	TAU,	0xFFFFFFFF, 0x00000000,	0x00000002, 0x00000003),
   1.489 +	DCL_TEST4(TUint32,	TAU,	0x00000000, 0x00000001,	0x00000002, 0x00000003),
   1.490 +	DCL_TEST4(TUint32,	TAU,	0x00000001, 0x00000001,	0x00000002, 0x00000003),
   1.491 +	DCL_TEST4(TUint32,	TAU,	0x00000002, 0x00000001,	0x00000002, 0x00000003),
   1.492 +	DCL_TEST4(TUint32,	TAU,	0xFFFFFFFF, 0x00000001,	0x00000002, 0x00000003),
   1.493 +	DCL_TEST4(TUint32,	TAU,	0xFFFFFFFE, 0xFFFFFFFE,	0x1023144F, 0x0000000B),
   1.494 +	DCL_TEST4(TUint32,	TAU,	0xFFFFFFEE, 0xFFFFFFFE,	0x1423144F, 0x0000000B),
   1.495 +	DCL_TEST4(TUint32,	TAU,	0xFFFFFFFF, 0xFFFFFFFE,	0x1423144F, 0x0000000B),
   1.496 +	DCL_TEST4(TUint32,	TAU,	0x00000000, 0xFFFFFFFE,	0x1423144F, 0x0000000B),
   1.497 +	DCL_TEST4(TUint32,	TAU,	0xFFFFFFFE, 0xFFFFFFFE,	0x80000000, 0x7FFFFFFF),
   1.498 +	DCL_TEST4(TUint32,	TAU,	0xFFFFFFEE, 0xFFFFFFFE,	0x80000000, 0x7FFFFFFF),
   1.499 +	DCL_TEST4(TUint32,	TAU,	0xFFFFFFFF, 0xFFFFFFFE,	0x80000000, 0x7FFFFFFF),
   1.500 +	DCL_TEST4(TUint32,	TAU,	0x00000000, 0xFFFFFFFE,	0x80000000, 0x7FFFFFFF),
   1.501 +	DCL_TEST4(TUint32,	TAU,	0xFFFFFFFE, 0x80000000,	0x80000001, 0x7FFFFFFE),
   1.502 +	DCL_TEST4(TUint32,	TAU,	0x7FFFFFFF, 0x80000000,	0x80000001, 0x7FFFFFFE),
   1.503 +	DCL_TEST4(TUint32,	TAU,	0x80000000, 0x80000000,	0x80000001, 0x7FFFFFFE),
   1.504 +	DCL_TEST4(TUint32,	TAU,	0x80000001, 0x80000000,	0x80000001, 0x7FFFFFFE),
   1.505 +	DCL_TEST4(TUint32,	TAU,	0x00000000, 0x80000000,	0x80000001, 0x7FFFFFFE),
   1.506 +	DCL_TEST4(TUint32,	TAU,	0x7FFFFFFE, 0x7FFFFFFF,	0x80000001, 0x7FFFFFFE),
   1.507 +	DCL_TEST4(TUint32,	TAU,	0x7FFFFFFF, 0x7FFFFFFF,	0x80000001, 0x7FFFFFFE),
   1.508 +	DCL_TEST4(TUint32,	TAU,	0x80000000, 0x7FFFFFFF,	0x80000001, 0x7FFFFFFE),
   1.509 +	DCL_TEST4(TUint32,	TAU,	0x80000001, 0x7FFFFFFF,	0x80000001, 0x7FFFFFFE),
   1.510 +	DCL_TEST4(TUint32,	TAU,	0x00000000, 0x7FFFFFFF,	0x80000001, 0x7FFFFFFE),
   1.511 +
   1.512 +	DCL_TEST4(TUint32,	TAS,	0x00000000, 0x00000000,	0x00000002, 0x00000003),
   1.513 +	DCL_TEST4(TUint32,	TAS,	0x00000001, 0x00000000,	0x00000002, 0x00000003),
   1.514 +	DCL_TEST4(TUint32,	TAS,	0xFFFFFFFF, 0x00000000,	0x00000002, 0x00000003),
   1.515 +	DCL_TEST4(TUint32,	TAS,	0x00000000, 0x00000001,	0x00000002, 0x00000003),
   1.516 +	DCL_TEST4(TUint32,	TAS,	0x00000001, 0x00000001,	0x00000002, 0x00000003),
   1.517 +	DCL_TEST4(TUint32,	TAS,	0x00000002, 0x00000001,	0x00000002, 0x00000003),
   1.518 +	DCL_TEST4(TUint32,	TAS,	0xFFFFFFFF, 0x00000001,	0x00000002, 0x00000003),
   1.519 +	DCL_TEST4(TUint32,	TAS,	0xFFFFFFFE, 0xFFFFFFFE,	0x1023144F, 0x0000000B),
   1.520 +	DCL_TEST4(TUint32,	TAS,	0xFFFFFFEE, 0xFFFFFFFE,	0x1423144F, 0x0000000B),
   1.521 +	DCL_TEST4(TUint32,	TAS,	0xFFFFFFFF, 0xFFFFFFFE,	0x1423144F, 0x0000000B),
   1.522 +	DCL_TEST4(TUint32,	TAS,	0x00000000, 0xFFFFFFFE,	0x1423144F, 0x0000000B),
   1.523 +	DCL_TEST4(TUint32,	TAS,	0xFFFFFFFE, 0xFFFFFFFE,	0x80000000, 0x7FFFFFFF),
   1.524 +	DCL_TEST4(TUint32,	TAS,	0xFFFFFFEE, 0xFFFFFFFE,	0x80000000, 0x7FFFFFFF),
   1.525 +	DCL_TEST4(TUint32,	TAS,	0xFFFFFFFF, 0xFFFFFFFE,	0x80000000, 0x7FFFFFFF),
   1.526 +	DCL_TEST4(TUint32,	TAS,	0x00000000, 0xFFFFFFFE,	0x80000000, 0x7FFFFFFF),
   1.527 +	DCL_TEST4(TUint32,	TAS,	0xFFFFFFFE, 0x80000000,	0x80000001, 0x7FFFFFFE),
   1.528 +	DCL_TEST4(TUint32,	TAS,	0x7FFFFFFF, 0x80000000,	0x80000001, 0x7FFFFFFE),
   1.529 +	DCL_TEST4(TUint32,	TAS,	0x80000000, 0x80000000,	0x80000001, 0x7FFFFFFE),
   1.530 +	DCL_TEST4(TUint32,	TAS,	0x80000001, 0x80000000,	0x80000001, 0x7FFFFFFE),
   1.531 +	DCL_TEST4(TUint32,	TAS,	0x00000000, 0x80000000,	0x80000001, 0x7FFFFFFE),
   1.532 +	DCL_TEST4(TUint32,	TAS,	0x7FFFFFFE, 0x7FFFFFFF,	0x80000001, 0x7FFFFFFE),
   1.533 +	DCL_TEST4(TUint32,	TAS,	0x7FFFFFFF, 0x7FFFFFFF,	0x80000001, 0x7FFFFFFE),
   1.534 +	DCL_TEST4(TUint32,	TAS,	0x80000000, 0x7FFFFFFF,	0x80000001, 0x7FFFFFFE),
   1.535 +	DCL_TEST4(TUint32,	TAS,	0x80000001, 0x7FFFFFFF,	0x80000001, 0x7FFFFFFE),
   1.536 +	DCL_TEST4(TUint32,	TAS,	0x00000000, 0x7FFFFFFF,	0x80000001, 0x7FFFFFFE)
   1.537 +	};
   1.538 +
   1.539 +DCL_TEST_BLOCK(TUint64,TestData64)
   1.540 +	{
   1.541 +	DCL_TEST1(TUint64,	LOAD,	MAKE_TUINT64(0x00000000,0x00000000)),
   1.542 +	DCL_TEST1(TUint64,	LOAD,	MAKE_TUINT64(0xFEDCBA98,0x76543210)),
   1.543 +
   1.544 +	DCL_TEST2(TUint64,	STORE,	MAKE_TUINT64(0x00000000,0x00000000), MAKE_TUINT64(0xFCD1CC9F,0xDB27CC8B)),
   1.545 +	DCL_TEST2(TUint64,	STORE,	MAKE_TUINT64(0xFEDCBA98,0x76543210), MAKE_TUINT64(0x06931471,0x80559945)),
   1.546 +
   1.547 +	DCL_TEST2(TUint64,	SWP,	MAKE_TUINT64(0x00000000,0x00000000), MAKE_TUINT64(0xFCD1CC9F,0xDB27CC8B)),
   1.548 +	DCL_TEST2(TUint64,	SWP,	MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xFCD1CC9F,0xDB27CC8B)),
   1.549 +	DCL_TEST2(TUint64,	SWP,	MAKE_TUINT64(0xDEADBEEF,0xBAD0BEEF), MAKE_TUINT64(0x06931471,0x80559945)),
   1.550 +	DCL_TEST2(TUint64,	SWP,	MAKE_TUINT64(0xFEDCBA98,0x76543210), MAKE_TUINT64(0x06931471,0x80559945)),
   1.551 +
   1.552 +	DCL_TEST2(TUint64,	ADD,	MAKE_TUINT64(0x00000000,0x00000000), MAKE_TUINT64(0x00000000,0x00000001)),
   1.553 +	DCL_TEST2(TUint64,	ADD,	MAKE_TUINT64(0x00000000,0xFFFFFFFF), MAKE_TUINT64(0x00000000,0x00000001)),
   1.554 +	DCL_TEST2(TUint64,	ADD,	MAKE_TUINT64(0x00000000,0x00000000), MAKE_TUINT64(0xFCD1CC9F,0xDB27CC8B)),
   1.555 +	DCL_TEST2(TUint64,	ADD,	MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xFCD1CC9F,0xDB27CC8B)),
   1.556 +
   1.557 +	DCL_TEST2(TUint64,	AND,	MAKE_TUINT64(0x00000000,0x00000000), MAKE_TUINT64(0x00000000,0x00000001)),
   1.558 +	DCL_TEST2(TUint64,	AND,	MAKE_TUINT64(0x00000000,0xFFFFFFFF), MAKE_TUINT64(0x00000000,0x00000001)),
   1.559 +	DCL_TEST2(TUint64,	AND,	MAKE_TUINT64(0x00000000,0x00000000), MAKE_TUINT64(0xFCD1CC9F,0xDB27CC8B)),
   1.560 +	DCL_TEST2(TUint64,	AND,	MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xFCD1CC9F,0xDB27CC8B)),
   1.561 +
   1.562 +	DCL_TEST2(TUint64,	IOR,	MAKE_TUINT64(0x00000000,0x00000000), MAKE_TUINT64(0x00000000,0x00000001)),
   1.563 +	DCL_TEST2(TUint64,	IOR,	MAKE_TUINT64(0x00000000,0xFFFFFFFF), MAKE_TUINT64(0x00000000,0x00000001)),
   1.564 +	DCL_TEST2(TUint64,	IOR,	MAKE_TUINT64(0x00000000,0x00000000), MAKE_TUINT64(0xFCD1CC9F,0xDB27CC8B)),
   1.565 +	DCL_TEST2(TUint64,	IOR,	MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xFCD1CC9F,0xDB27CC8B)),
   1.566 +	DCL_TEST2(TUint64,	IOR,	MAKE_TUINT64(0x11111111,0x22222222), MAKE_TUINT64(0x44444444,0x55555555)),
   1.567 +
   1.568 +	DCL_TEST2(TUint64,	XOR,	MAKE_TUINT64(0x00000000,0x00000000), MAKE_TUINT64(0x00000000,0x00000001)),
   1.569 +	DCL_TEST2(TUint64,	XOR,	MAKE_TUINT64(0x00000000,0xFFFFFFFF), MAKE_TUINT64(0x00000000,0x00000001)),
   1.570 +	DCL_TEST2(TUint64,	XOR,	MAKE_TUINT64(0x00000000,0x00000000), MAKE_TUINT64(0xFCD1CC9F,0xDB27CC8B)),
   1.571 +	DCL_TEST2(TUint64,	XOR,	MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xFCD1CC9F,0xDB27CC8B)),
   1.572 +	DCL_TEST2(TUint64,	XOR,	MAKE_TUINT64(0x11111111,0x22222222), MAKE_TUINT64(0x44444444,0x77777777)),
   1.573 +
   1.574 +	DCL_TEST3(TUint64,	AXO,	MAKE_TUINT64(0x00000000,0x00000000), MAKE_TUINT64(0xFFFFFFFF,0xFFFFFFFF), MAKE_TUINT64(0x00000000,0x00000001)),
   1.575 +	DCL_TEST3(TUint64,	AXO,	MAKE_TUINT64(0x00000000,0x00000000), MAKE_TUINT64(0xFFFFFFFF,0xFFFFFFFF), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED)),
   1.576 +	DCL_TEST3(TUint64,	AXO,	MAKE_TUINT64(0xFFFFFFFF,0xFFFFFFFF), MAKE_TUINT64(0xFFFFFFFF,0xFFFFFFFF), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED)),
   1.577 +	DCL_TEST3(TUint64,	AXO,	MAKE_TUINT64(0xFFFFFFFF,0xFFFFFFFF), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED)),
   1.578 +	DCL_TEST3(TUint64,	AXO,	MAKE_TUINT64(0xFFFFFFFF,0xFFFFFFFF), MAKE_TUINT64(0xFACEFEED,0xFEEDFACE), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED)),
   1.579 +	DCL_TEST3(TUint64,	AXO,	MAKE_TUINT64(0xBAD8BEEF,0xDEADDEAD), MAKE_TUINT64(0xFACEFEED,0xFEEDFACE), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED)),
   1.580 +
   1.581 +	DCL_TEST3(TUint64,	CAS,	MAKE_TUINT64(0x00000000,0x00000000), MAKE_TUINT64(0x00000000,0x00000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED)),
   1.582 +	DCL_TEST3(TUint64,	CAS,	MAKE_TUINT64(0x00000000,0x00000000), MAKE_TUINT64(0x00000001,0x00000000), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED)),
   1.583 +	DCL_TEST3(TUint64,	CAS,	MAKE_TUINT64(0x00000000,0x00000001), MAKE_TUINT64(0x00000000,0x00000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED)),
   1.584 +	DCL_TEST3(TUint64,	CAS,	MAKE_TUINT64(0x00000000,0x00000001), MAKE_TUINT64(0x00000001,0x00000000), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED)),
   1.585 +	DCL_TEST3(TUint64,	CAS,	MAKE_TUINT64(0x00000001,0x00000000), MAKE_TUINT64(0x00000000,0x00000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED)),
   1.586 +	DCL_TEST3(TUint64,	CAS,	MAKE_TUINT64(0x00000001,0x00000000), MAKE_TUINT64(0x00000001,0x00000000), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED)),
   1.587 +
   1.588 +	DCL_TEST4(TUint64,	TAU,	MAKE_TUINT64(0x00000000,0x00000000), MAKE_TUINT64(0x00000000,0x00000000), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.589 +	DCL_TEST4(TUint64,	TAU,	MAKE_TUINT64(0x00000000,0x00000001), MAKE_TUINT64(0x00000000,0x00000000), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.590 +	DCL_TEST4(TUint64,	TAU,	MAKE_TUINT64(0xFFFFFFFF,0xFFFFFFFF), MAKE_TUINT64(0x00000000,0x00000000), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.591 +	DCL_TEST4(TUint64,	TAU,	MAKE_TUINT64(0x00000000,0x00000000), MAKE_TUINT64(0x00000000,0x00000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.592 +	DCL_TEST4(TUint64,	TAU,	MAKE_TUINT64(0x00000000,0x00000001), MAKE_TUINT64(0x00000000,0x00000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.593 +	DCL_TEST4(TUint64,	TAU,	MAKE_TUINT64(0x00000000,0x00000002), MAKE_TUINT64(0x00000000,0x00000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.594 +	DCL_TEST4(TUint64,	TAU,	MAKE_TUINT64(0xFFFFFFFF,0xFFFFFFFF), MAKE_TUINT64(0x00000000,0x00000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.595 +	DCL_TEST4(TUint64,	TAU,	MAKE_TUINT64(0xFFFFFFFF,0x00000000), MAKE_TUINT64(0x00000000,0x00000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.596 +	DCL_TEST4(TUint64,	TAU,	MAKE_TUINT64(0x80000000,0x00000000), MAKE_TUINT64(0x80000000,0x00000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.597 +	DCL_TEST4(TUint64,	TAU,	MAKE_TUINT64(0x80000000,0x00000001), MAKE_TUINT64(0x80000000,0x00000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.598 +	DCL_TEST4(TUint64,	TAU,	MAKE_TUINT64(0x80000000,0x00000002), MAKE_TUINT64(0x80000000,0x00000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.599 +	DCL_TEST4(TUint64,	TAU,	MAKE_TUINT64(0x7FFFFFFF,0xFFFFFFFF), MAKE_TUINT64(0x80000000,0x00000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.600 +	DCL_TEST4(TUint64,	TAU,	MAKE_TUINT64(0x7FFFFFFF,0x00000000), MAKE_TUINT64(0x80000000,0x00000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.601 +	DCL_TEST4(TUint64,	TAU,	MAKE_TUINT64(0x7FFFFFFF,0x80000001), MAKE_TUINT64(0x7FFFFFFF,0x80000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.602 +	DCL_TEST4(TUint64,	TAU,	MAKE_TUINT64(0x7FFFFFFF,0x80000000), MAKE_TUINT64(0x7FFFFFFF,0x80000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.603 +	DCL_TEST4(TUint64,	TAU,	MAKE_TUINT64(0x7FFFFFFF,0x80000002), MAKE_TUINT64(0x7FFFFFFF,0x80000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.604 +	DCL_TEST4(TUint64,	TAU,	MAKE_TUINT64(0x7FFFFFFF,0xFFFFFFFF), MAKE_TUINT64(0x7FFFFFFF,0x80000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.605 +	DCL_TEST4(TUint64,	TAU,	MAKE_TUINT64(0x7FFFFFFF,0x7FFFFFFF), MAKE_TUINT64(0x7FFFFFFF,0x80000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.606 +	DCL_TEST4(TUint64,	TAU,	MAKE_TUINT64(0x80000000,0x00000000), MAKE_TUINT64(0x7FFFFFFF,0x80000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.607 +	DCL_TEST4(TUint64,	TAU,	MAKE_TUINT64(0x80000000,0x80000000), MAKE_TUINT64(0x7FFFFFFF,0x80000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.608 +	DCL_TEST4(TUint64,	TAU,	MAKE_TUINT64(0x80000000,0x80000001), MAKE_TUINT64(0x7FFFFFFF,0x80000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.609 +	DCL_TEST4(TUint64,	TAU,	MAKE_TUINT64(0x80000000,0x80000002), MAKE_TUINT64(0x7FFFFFFF,0x80000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.610 +
   1.611 +	DCL_TEST4(TUint64,	TAS,	MAKE_TUINT64(0x00000000,0x00000000), MAKE_TUINT64(0x00000000,0x00000000), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.612 +	DCL_TEST4(TUint64,	TAS,	MAKE_TUINT64(0x00000000,0x00000001), MAKE_TUINT64(0x00000000,0x00000000), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.613 +	DCL_TEST4(TUint64,	TAS,	MAKE_TUINT64(0xFFFFFFFF,0xFFFFFFFF), MAKE_TUINT64(0x00000000,0x00000000), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.614 +	DCL_TEST4(TUint64,	TAS,	MAKE_TUINT64(0x00000000,0x00000000), MAKE_TUINT64(0x00000000,0x00000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.615 +	DCL_TEST4(TUint64,	TAS,	MAKE_TUINT64(0x00000000,0x00000001), MAKE_TUINT64(0x00000000,0x00000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.616 +	DCL_TEST4(TUint64,	TAS,	MAKE_TUINT64(0x00000000,0x00000002), MAKE_TUINT64(0x00000000,0x00000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.617 +	DCL_TEST4(TUint64,	TAS,	MAKE_TUINT64(0xFFFFFFFF,0xFFFFFFFF), MAKE_TUINT64(0x00000000,0x00000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.618 +	DCL_TEST4(TUint64,	TAS,	MAKE_TUINT64(0xFFFFFFFF,0x00000000), MAKE_TUINT64(0x00000000,0x00000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.619 +	DCL_TEST4(TUint64,	TAS,	MAKE_TUINT64(0x80000000,0x00000000), MAKE_TUINT64(0x80000000,0x00000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.620 +	DCL_TEST4(TUint64,	TAS,	MAKE_TUINT64(0x80000000,0x00000001), MAKE_TUINT64(0x80000000,0x00000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.621 +	DCL_TEST4(TUint64,	TAS,	MAKE_TUINT64(0x80000000,0x00000002), MAKE_TUINT64(0x80000000,0x00000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.622 +	DCL_TEST4(TUint64,	TAS,	MAKE_TUINT64(0x7FFFFFFF,0xFFFFFFFF), MAKE_TUINT64(0x80000000,0x00000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.623 +	DCL_TEST4(TUint64,	TAS,	MAKE_TUINT64(0x7FFFFFFF,0x00000000), MAKE_TUINT64(0x80000000,0x00000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.624 +	DCL_TEST4(TUint64,	TAS,	MAKE_TUINT64(0x7FFFFFFF,0x80000001), MAKE_TUINT64(0x7FFFFFFF,0x80000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.625 +	DCL_TEST4(TUint64,	TAS,	MAKE_TUINT64(0x7FFFFFFF,0x80000000), MAKE_TUINT64(0x7FFFFFFF,0x80000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.626 +	DCL_TEST4(TUint64,	TAS,	MAKE_TUINT64(0x7FFFFFFF,0x80000002), MAKE_TUINT64(0x7FFFFFFF,0x80000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.627 +	DCL_TEST4(TUint64,	TAS,	MAKE_TUINT64(0x7FFFFFFF,0xFFFFFFFF), MAKE_TUINT64(0x7FFFFFFF,0x80000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.628 +	DCL_TEST4(TUint64,	TAS,	MAKE_TUINT64(0x7FFFFFFF,0x7FFFFFFF), MAKE_TUINT64(0x7FFFFFFF,0x80000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.629 +	DCL_TEST4(TUint64,	TAS,	MAKE_TUINT64(0x80000000,0x00000000), MAKE_TUINT64(0x7FFFFFFF,0x80000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.630 +	DCL_TEST4(TUint64,	TAS,	MAKE_TUINT64(0x80000000,0x80000000), MAKE_TUINT64(0x7FFFFFFF,0x80000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.631 +	DCL_TEST4(TUint64,	TAS,	MAKE_TUINT64(0x80000000,0x80000001), MAKE_TUINT64(0x7FFFFFFF,0x80000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5)),
   1.632 +	DCL_TEST4(TUint64,	TAS,	MAKE_TUINT64(0x80000000,0x80000002), MAKE_TUINT64(0x7FFFFFFF,0x80000001), MAKE_TUINT64(0xFEEDFACE,0xFACEFEED), MAKE_TUINT64(0xBAD9BEEF,0x00FAECE5))
   1.633 +	};
   1.634 +
   1.635 +
   1.636 +
   1.637 +template<class T>
   1.638 +void DoTestBlock(const TD<T>* aTests, TInt aCount)
   1.639 +	{
   1.640 +	const TD<T>* p = aTests;
   1.641 +	const TD<T>* e = aTests + aCount;
   1.642 +	for (; p<e; ++p)
   1.643 +		{
   1.644 +		TInt ord;
   1.645 +		for (ord=EOrderRelaxed; ord<=EOrderOrdered; ++ord)
   1.646 +			{
   1.647 +			TDG tdg;
   1.648 +			tdg.Set(*p, ord);
   1.649 +			if (tdg.iIndex<0)
   1.650 +				continue;
   1.651 +#ifdef __EXTRA_DEBUG__
   1.652 +			TPtrC8 fname8((const TText8*)FuncName[tdg.iIndex]);
   1.653 +			TBuf<64> fname;
   1.654 +			fname.Copy(fname8);
   1.655 +			test.Printf(_L("%S\n"), &fname);
   1.656 +#endif
   1.657 +			TInt res;
   1.658 +			res = tdg.ExecuteUser();
   1.659 +			if (res!=0)
   1.660 +				{
   1.661 +				tdg.Dump("ExecuteUser");
   1.662 +				test.Printf(_L("FAIL %d\n"),res);
   1.663 +				test(0);
   1.664 +				}
   1.665 +#ifdef __EPOC32__
   1.666 +#ifdef __EXTRA_DEBUG__
   1.667 +			test.Printf(_L("%S K\n"), &fname);
   1.668 +#endif
   1.669 +			res = tdg.ExecuteKernel();
   1.670 +			if (res!=0)
   1.671 +				{
   1.672 +				tdg.Dump("ExecuteKernel");
   1.673 +				test.Printf(_L("FAIL %d\n"),res);
   1.674 +				test(0);
   1.675 +				}
   1.676 +#endif
   1.677 +			}
   1.678 +		}
   1.679 +	}
   1.680 +
   1.681 +#define DO_TEST_BLOCK(type,array)	\
   1.682 +	DoTestBlock<type>(&(array)[0],(TInt)(sizeof(array)/sizeof(TD<type>)))
   1.683 +
   1.684 +void TestSingleThread()
   1.685 +	{
   1.686 +	test.Next(_L("8 bit, single thread"));
   1.687 +	DO_TEST_BLOCK(TUint8, TestData8);
   1.688 +	test.Next(_L("16 bit, single thread"));
   1.689 +	DO_TEST_BLOCK(TUint16, TestData16);
   1.690 +	test.Next(_L("32 bit, single thread"));
   1.691 +	DO_TEST_BLOCK(TUint32, TestData32);
   1.692 +	test.Next(_L("64 bit, single thread"));
   1.693 +	DO_TEST_BLOCK(TUint64, TestData64);
   1.694 +	}
   1.695 +
   1.696 +
   1.697 +
   1.698 +/******************************************************************************
   1.699 + * Test invalid address handling when called from user mode
   1.700 + ******************************************************************************/
   1.701 +const TLinAddr KSpecialAddr = 0x100u;
   1.702 +const TInt KIndexRead = -1;
   1.703 +const TInt KIndexReadWrite = -2;
   1.704 +
   1.705 +struct TE
   1.706 +	{
   1.707 +	static TInt Execute(TInt aIndex, TAny* aPtr1, TAny* aPtr2, TInt aResult);
   1.708 +	TInt DoExecute();
   1.709 +	static TInt ThreadFn(TAny*);
   1.710 +
   1.711 +	TInt	iIndex;
   1.712 +	TAny*	iPtr1;
   1.713 +	TAny*	iPtr2;
   1.714 +	};
   1.715 +
   1.716 +template<class T> TInt DoLoadErrorTest(TInt aIndex, const T* aPtr)
   1.717 +	{
   1.718 +	typename TLoadFn<T>::F atomic = (typename TLoadFn<T>::F)AtomicFuncPtr[aIndex];
   1.719 +	atomic(aPtr);
   1.720 +	return 0;
   1.721 +	}
   1.722 +
   1.723 +template<class T> TInt DoRmw1ErrorTest(TInt aIndex, T* aPtr)
   1.724 +	{
   1.725 +	typename TRmw1Fn<T>::F atomic = (typename TRmw1Fn<T>::F)AtomicFuncPtr[aIndex];
   1.726 +	T a1 = 0;
   1.727 +	atomic(aPtr, a1);
   1.728 +	return 0;
   1.729 +	}
   1.730 +
   1.731 +template<class T> TInt DoRmw2ErrorTest(TInt aIndex, T* aPtr)
   1.732 +	{
   1.733 +	typename TRmw2Fn<T>::F atomic = (typename TRmw2Fn<T>::F)AtomicFuncPtr[aIndex];
   1.734 +	T a1 = 0;
   1.735 +	T a2 = 0;
   1.736 +	atomic(aPtr, a1, a2);
   1.737 +	return 0;
   1.738 +	}
   1.739 +
   1.740 +template<class T> TInt DoRmw3ErrorTest(TInt aIndex, T* aPtr)
   1.741 +	{
   1.742 +	typename TRmw3Fn<T>::F atomic = (typename TRmw3Fn<T>::F)AtomicFuncPtr[aIndex];
   1.743 +	T a1 = 0;
   1.744 +	T a2 = 0;
   1.745 +	T a3 = 0;
   1.746 +	atomic(aPtr, a1, a2, a3);
   1.747 +	return 0;
   1.748 +	}
   1.749 +
   1.750 +template<class T> TInt DoCasErrorTest(TInt aIndex, T* aPtr1, T* aPtr2)
   1.751 +	{
   1.752 +	typename TCasFn<T>::F atomic = (typename TCasFn<T>::F)AtomicFuncPtr[aIndex];
   1.753 +	TLinAddr a1 = (TLinAddr)aPtr1;
   1.754 +	TLinAddr a2 = (TLinAddr)aPtr2;
   1.755 +	T reg;
   1.756 +	T exp;
   1.757 +	T f;
   1.758 +	memset(&f, 0xbb, sizeof(T));
   1.759 +	if ((a1&~0xff)==KSpecialAddr)
   1.760 +		{
   1.761 +		memset(&reg, (a1&0xff), sizeof(T));
   1.762 +		aPtr1 = &reg;
   1.763 +		}
   1.764 +	if ((a2&~0xff)==KSpecialAddr)
   1.765 +		{
   1.766 +		memset(&exp, (a2&0xff), sizeof(T));
   1.767 +		aPtr2 = &exp;
   1.768 +		}
   1.769 +	TInt r = atomic(aPtr1, aPtr2, f);
   1.770 +	return r ? 1 : 0;
   1.771 +	}
   1.772 +
   1.773 +TInt TE::DoExecute()
   1.774 +	{
   1.775 +	if (iIndex == KIndexRead)
   1.776 +		{
   1.777 +		return *(volatile TUint8*)iPtr1;
   1.778 +		}
   1.779 +	if (iIndex == KIndexReadWrite)
   1.780 +		{
   1.781 +		volatile TUint8* p = (volatile TUint8*)iPtr1;
   1.782 +		TUint8 x = *p;
   1.783 +		*p = x;
   1.784 +		return 0;
   1.785 +		}
   1.786 +	TUint attr = FuncAttr[iIndex];
   1.787 +	TInt type = ATTR_TO_TYPE(attr);
   1.788 +	TInt size = ATTR_TO_SIZE(attr);
   1.789 +	if (type==EFuncTypeInvalid)
   1.790 +		return KErrNotSupported;
   1.791 +	TInt res;
   1.792 +	switch (type)
   1.793 +		{
   1.794 +		case EFuncTypeLoad:
   1.795 +			{
   1.796 +			switch (size)
   1.797 +				{
   1.798 +				case 1:	res = DoLoadErrorTest<TUint8>(iIndex, (TUint8*)iPtr1); break;
   1.799 +				case 2:	res = DoLoadErrorTest<TUint16>(iIndex, (TUint16*)iPtr1); break;
   1.800 +				case 4:	res = DoLoadErrorTest<TUint32>(iIndex, (TUint32*)iPtr1); break;
   1.801 +				case 8:	res = DoLoadErrorTest<TUint64>(iIndex, (TUint64*)iPtr1); break;
   1.802 +				default: res = KErrNotSupported; break;
   1.803 +				}
   1.804 +			break;
   1.805 +			}
   1.806 +		case EFuncTypeRmw1:
   1.807 +			{
   1.808 +			switch (size)
   1.809 +				{
   1.810 +				case 1:	res = DoRmw1ErrorTest<TUint8>(iIndex, (TUint8*)iPtr1); break;
   1.811 +				case 2:	res = DoRmw1ErrorTest<TUint16>(iIndex, (TUint16*)iPtr1); break;
   1.812 +				case 4:	res = DoRmw1ErrorTest<TUint32>(iIndex, (TUint32*)iPtr1); break;
   1.813 +				case 8:	res = DoRmw1ErrorTest<TUint64>(iIndex, (TUint64*)iPtr1); break;
   1.814 +				default: res = KErrNotSupported; break;
   1.815 +				}
   1.816 +			break;
   1.817 +			}
   1.818 +		case EFuncTypeRmw2:
   1.819 +			{
   1.820 +			switch (size)
   1.821 +				{
   1.822 +				case 1:	res = DoRmw2ErrorTest<TUint8>(iIndex, (TUint8*)iPtr1); break;
   1.823 +				case 2:	res = DoRmw2ErrorTest<TUint16>(iIndex, (TUint16*)iPtr1); break;
   1.824 +				case 4:	res = DoRmw2ErrorTest<TUint32>(iIndex, (TUint32*)iPtr1); break;
   1.825 +				case 8:	res = DoRmw2ErrorTest<TUint64>(iIndex, (TUint64*)iPtr1); break;
   1.826 +				default: res = KErrNotSupported; break;
   1.827 +				}
   1.828 +			break;
   1.829 +			}
   1.830 +		case EFuncTypeRmw3:
   1.831 +			{
   1.832 +			switch (size)
   1.833 +				{
   1.834 +				case 1:	res = DoRmw3ErrorTest<TUint8>(iIndex, (TUint8*)iPtr1); break;
   1.835 +				case 2:	res = DoRmw3ErrorTest<TUint16>(iIndex, (TUint16*)iPtr1); break;
   1.836 +				case 4:	res = DoRmw3ErrorTest<TUint32>(iIndex, (TUint32*)iPtr1); break;
   1.837 +				case 8:	res = DoRmw3ErrorTest<TUint64>(iIndex, (TUint64*)iPtr1); break;
   1.838 +				default: res = KErrNotSupported; break;
   1.839 +				}
   1.840 +			break;
   1.841 +			}
   1.842 +		case EFuncTypeCas:
   1.843 +			{
   1.844 +			switch (size)
   1.845 +				{
   1.846 +				case 1:	res = DoCasErrorTest<TUint8>(iIndex, (TUint8*)iPtr1, (TUint8*)iPtr2); break;
   1.847 +				case 2:	res = DoCasErrorTest<TUint16>(iIndex, (TUint16*)iPtr1, (TUint16*)iPtr2); break;
   1.848 +				case 4:	res = DoCasErrorTest<TUint32>(iIndex, (TUint32*)iPtr1, (TUint32*)iPtr2); break;
   1.849 +				case 8:	res = DoCasErrorTest<TUint64>(iIndex, (TUint64*)iPtr1, (TUint64*)iPtr2); break;
   1.850 +				default: res = KErrNotSupported; break;
   1.851 +				}
   1.852 +			break;
   1.853 +			}
   1.854 +		default:
   1.855 +			res = KErrNotSupported;
   1.856 +			break;
   1.857 +		}
   1.858 +	return res;
   1.859 +	}
   1.860 +
   1.861 +TInt TE::ThreadFn(TAny* aPtr)
   1.862 +	{
   1.863 +	return ((TE*)aPtr)->DoExecute();
   1.864 +	}
   1.865 +
   1.866 +_LIT(KLitKERNEXEC,"KERN-EXEC");
   1.867 +TInt TE::Execute(TInt aIndex, TAny* aPtr1, TAny* aPtr2, TInt aResult)
   1.868 +	{
   1.869 +	DEBUGPRINT("I=%3d P1=%08x P2=%08x R=%d", aIndex, aPtr1, aPtr2, aResult);
   1.870 +	TE te;
   1.871 +	te.iIndex = aIndex;
   1.872 +	te.iPtr1 = aPtr1;
   1.873 +	te.iPtr2 = aPtr2;
   1.874 +	RThread t;
   1.875 +	TInt r = t.Create(KNullDesC, &ThreadFn, 0x1000, 0, &te);
   1.876 +	test_KErrNone(r);
   1.877 +	TRequestStatus s;
   1.878 +	t.Logon(s);
   1.879 +	test_Equal(KRequestPending, s.Int());
   1.880 +	TBool jit = User::JustInTime();
   1.881 +	User::SetJustInTime(EFalse);
   1.882 +	t.Resume();
   1.883 +	User::WaitForRequest(s);
   1.884 +	User::SetJustInTime(jit);
   1.885 +	TInt xt = t.ExitType();
   1.886 +	TInt xr = t.ExitReason();
   1.887 +	const TDesC& xc = t.ExitCategory();
   1.888 +	DEBUGPRINT("Exit type: %d,%d,%S", xt, xr, &xc);
   1.889 +	TInt res = KErrNone;
   1.890 +	if (aResult == KErrUnknown)
   1.891 +		{
   1.892 +		if (xt==EExitPanic)
   1.893 +			{
   1.894 +			test_Equal(ECausedException, xr);
   1.895 +			test(xc==KLitKERNEXEC);
   1.896 +			res = KErrDied;
   1.897 +			}
   1.898 +		else
   1.899 +			test_Equal(EExitKill, xt);
   1.900 +		}
   1.901 +	else if (aResult == KErrDied)
   1.902 +		{
   1.903 +		test_Equal(EExitPanic, xt);
   1.904 +		test_Equal(ECausedException, xr);
   1.905 +		test(xc==KLitKERNEXEC);
   1.906 +		}
   1.907 +	else
   1.908 +		{
   1.909 +		test_Equal(EExitKill, xt);
   1.910 +		test_Equal(aResult, xr);
   1.911 +		}
   1.912 +	CLOSE_AND_WAIT(t);
   1.913 +	return res;
   1.914 +	}
   1.915 +
   1.916 +TInt ThreadAlign(TAny*)
   1.917 +	{
   1.918 +	TUint32 array[2];
   1.919 +	TUint32* p = (TUint32*)(((TLinAddr)array)+1);
   1.920 +	*p = 5;
   1.921 +	return KErrNone;
   1.922 +	}
   1.923 +
   1.924 +const TUint64 Zero = UI64LIT(0);
   1.925 +const TUint64 BFBF = UI64LIT(0xbfbfbfbfbfbfbfbf);
   1.926 +
   1.927 +void TestInvalidAddresses()
   1.928 +	{
   1.929 +	TAny* bad_addr[11];
   1.930 +	TInt c = 0;
   1.931 +	TInt read_only = 0;
   1.932 +	TInt alignmentEnd = 0;
   1.933 +	TInt mminfo = UserSvr::HalFunction(EHalGroupKernel, EKernelHalMemModelInfo, 0, 0);
   1.934 +//	TInt mmtype = mminfo & EMemModelTypeMask;
   1.935 +#ifdef __EPOC32__
   1.936 +	if (mminfo & EMemModelAttrWriteProt)
   1.937 +		{
   1.938 +		bad_addr[c++] = (TAny*)UserSvr::RomHeaderAddress();
   1.939 +		bad_addr[c++] = (TAny*)&Zero;
   1.940 +		bad_addr[c++] = (TAny*)&BFBF;
   1.941 +		read_only = c;
   1.942 +		}
   1.943 +#endif
   1.944 +	if (mminfo & EMemModelAttrNonExProt)
   1.945 +		{
   1.946 +		bad_addr[c++] = 0;	// address 0 is read only on ARM7 cores, nonexistent on others
   1.947 +		if (TE::Execute(KIndexRead, 0, 0, KErrUnknown)==KErrNone)
   1.948 +			read_only = c;	// address 0 is readable
   1.949 +		TLinAddr nonex = 0;
   1.950 +		do	{
   1.951 +			nonex += 0x1000;
   1.952 +			} while (TE::Execute(KIndexRead, (TAny*)nonex, 0, KErrUnknown)==KErrNone);
   1.953 +		bad_addr[c++] = (TAny*)nonex;
   1.954 +		}
   1.955 +#ifdef __EPOC32__
   1.956 +	if (mminfo & EMemModelAttrKernProt)
   1.957 +		{
   1.958 +		bad_addr[c++] = DD.KernelMemoryAddress();
   1.959 +		}
   1.960 +	// If alignment checking is enabled add alignment tests for 64 bit.
   1.961 +	TUint64A alignArray[2];
   1.962 +	RThread t;
   1.963 +	TInt r = t.Create(KNullDesC, &ThreadAlign, 0x1000, 0, NULL);
   1.964 +	test_KErrNone(r);
   1.965 +	TRequestStatus s;
   1.966 +	t.Logon(s);
   1.967 +	test_Equal(KRequestPending, s.Int());
   1.968 +	TBool jit = User::JustInTime();
   1.969 +	User::SetJustInTime(EFalse);
   1.970 +	t.Resume();
   1.971 +	User::WaitForRequest(s);
   1.972 +	User::SetJustInTime(jit);
   1.973 +	TInt xt = t.ExitType();
   1.974 +	TInt xr = t.ExitReason();
   1.975 +	const TDesC& xc = t.ExitCategory();
   1.976 +	if (EExitPanic == xt)
   1.977 +		{// Took an alignment fault so add alignment test.
   1.978 +		test_Equal(ECausedException, xr);
   1.979 +		test(xc==KLitKERNEXEC);
   1.980 +		alignmentEnd = c;
   1.981 +		bad_addr[alignmentEnd++] = (TAny*)(((TUint)&alignArray[0]) + 1);
   1.982 +		bad_addr[alignmentEnd++] = (TAny*)(((TUint)&alignArray[0]) + 2);
   1.983 +		bad_addr[alignmentEnd++] = (TAny*)(((TUint)&alignArray[0]) + 4);
   1.984 +		}
   1.985 +	
   1.986 +#endif
   1.987 +	TInt i;
   1.988 +	TInt allBadAddr = (alignmentEnd)? c+3 : c;
   1.989 +	DEBUGPRINT("%d invalid addresses", allBadAddr);
   1.990 +	for (i=0; i < allBadAddr; ++i)
   1.991 +		{
   1.992 +		if (i<read_only)
   1.993 +			{
   1.994 +			DEBUGPRINT("bad_addr[%d]=%08x (RO)", i, bad_addr[i]);
   1.995 +			}
   1.996 +		else
   1.997 +			{
   1.998 +			DEBUGPRINT("bad_addr[%d]=%08x", i, bad_addr[i]);
   1.999 +			}
  1.1000 +		}
  1.1001 +	if (c==0)
  1.1002 +		return;
  1.1003 +	TInt ix;
  1.1004 +	for (ix=0; ix<TOTAL_INDEXES; ++ix)
  1.1005 +		{
  1.1006 +		TUint attr = FuncAttr[ix];
  1.1007 +		TUint func = ATTR_TO_FUNC(attr);
  1.1008 +		TUint type = ATTR_TO_TYPE(attr);
  1.1009 +		if (type==EFuncTypeInvalid)
  1.1010 +			continue;
  1.1011 +		if (func==TUint(EAtomicFuncCAS))
  1.1012 +			{
  1.1013 +			// both addresses OK
  1.1014 +			TE::Execute(ix, (TAny*)(KSpecialAddr+0), (TAny*)(KSpecialAddr+0), 1);	// should do the swap
  1.1015 +			TE::Execute(ix, (TAny*)(KSpecialAddr+0), (TAny*)(KSpecialAddr+1), 0);	// should not do the swap
  1.1016 +
  1.1017 +			// RMW address OK, expected bad
  1.1018 +			for (i=0; i<c; ++i)
  1.1019 +				{
  1.1020 +				TAny* p = bad_addr[i];
  1.1021 +				TInt res = (bad_addr[i]==(TAny*)&BFBF) ? 1 : KErrDied;
  1.1022 +				TE::Execute(ix, (TAny*)(KSpecialAddr+0xbf), p, res);
  1.1023 +				}
  1.1024 +
  1.1025 +			// RMW address bad, expected OK
  1.1026 +			for (i=0; i<c; ++i)
  1.1027 +				{
  1.1028 +				TAny* p = bad_addr[i];
  1.1029 +#if defined(__CPU_X86)
  1.1030 +				TInt res = KErrDied;	// on X86 location must be writeable
  1.1031 +#elif defined(__CPU_ARM)
  1.1032 +				TInt res = (i<read_only && bad_addr[i]!=(TAny*)&BFBF) ? 0 : KErrDied;
  1.1033 +				// 64-bit operations on platforms that use a slow exec for 64 bit 
  1.1034 +				// will always write to bad_addr[i] but other platforms won't.
  1.1035 +				if (ATTR_TO_SIZE(attr) == 8)
  1.1036 +					res = KErrUnknown;
  1.1037 +#else
  1.1038 +#error CPU?
  1.1039 +#endif
  1.1040 +				TE::Execute(ix, p, (TAny*)(KSpecialAddr+0xbf), res);
  1.1041 +				}
  1.1042 +
  1.1043 +			// Both addresses bad
  1.1044 +			TInt j;
  1.1045 +			for (i=0; i<c; ++i)
  1.1046 +				{
  1.1047 +				for (j=0; j<c; ++j)
  1.1048 +					{
  1.1049 +					TE::Execute(ix, bad_addr[i], bad_addr[j], KErrDied);
  1.1050 +					}
  1.1051 +				}
  1.1052 +			}
  1.1053 +		else
  1.1054 +			{
  1.1055 +			// just run through all the bad addresses
  1.1056 +			for (i=0; i<c; ++i)
  1.1057 +				{
  1.1058 +				TAny* p = bad_addr[i];
  1.1059 +				TBool ro = (i<read_only);
  1.1060 +				TInt res = ((func == TUint(EAtomicFuncLOAD)) && ro) ? KErrNone : KErrDied;
  1.1061 +				if (func==TUint(EAtomicFuncLOAD) && ATTR_TO_SIZE(attr)==8)
  1.1062 +					res = KErrUnknown;	// 64-bit atomic loads may or may not write as well
  1.1063 +				TE::Execute(ix, p, 0, res);
  1.1064 +				}
  1.1065 +			}
  1.1066 +// Checks for 8 byte alignment not enabled on old gcc (arm4) as it is not eabi compliant.
  1.1067 +#if (defined(__GNUC__) && (__GNUC__ >= 3)) || defined(__EABI__)
  1.1068 +		if (ATTR_TO_SIZE(attr) == 8)
  1.1069 +			{
  1.1070 +			for (i = c; i < alignmentEnd; i++)
  1.1071 +				{// 64 bit unaligned accesses should cause exceptions if 
  1.1072 +				// alignment checking is enabled.
  1.1073 +				TE::Execute(ix, bad_addr[i], 0, KErrDied);
  1.1074 +				}
  1.1075 +			}
  1.1076 +#endif
  1.1077 +		}
  1.1078 +	}
  1.1079 +
  1.1080 +
  1.1081 +
  1.1082 +/******************************************************************************
  1.1083 + * Multiple thread normal operation tests
  1.1084 + ******************************************************************************/
  1.1085 +class CThread;
  1.1086 +class CThreads : public CBase
  1.1087 +	{
  1.1088 +public:
  1.1089 +	static CThreads* New();
  1.1090 +	CThreads();
  1.1091 +	~CThreads();
  1.1092 +	CThread* NewThread(TInt aId);
  1.1093 +	void StartTest(TInt aIndex, TBool aKernel);
  1.1094 +	void StopTest();
  1.1095 +	void Finish();
  1.1096 +	TUint32 DoCasTest(TInt aIndex, TBool aKernel, TUint32 aFailLimit);
  1.1097 +	void DoRmwTest(TInt aIndex, TBool aKernel, TInt aTime);
  1.1098 +	inline TInt NumCpus() const {return iNumCpus;}
  1.1099 +private:
  1.1100 +	TInt			iNumCpus;
  1.1101 +	TInt			iNumThreads;
  1.1102 +	CThread*		iThreads[KMaxThreads];
  1.1103 +	RSemaphore		iSem;
  1.1104 +	volatile TInt	iIndex;
  1.1105 +	volatile TBool	iKernel;
  1.1106 +	volatile TBool	iStop;
  1.1107 +	volatile TUint64 iReg;
  1.1108 +	TInt			iFailCount;
  1.1109 +	TInt			iTimeslice;
  1.1110 +private:
  1.1111 +	friend class CThread;
  1.1112 +	};
  1.1113 +
  1.1114 +class CThread : public CBase
  1.1115 +	{
  1.1116 +private:
  1.1117 +	CThread();
  1.1118 +	~CThread();
  1.1119 +	static TInt ThreadFunction(TAny*);
  1.1120 +	TInt Run();
  1.1121 +	TInt Create();
  1.1122 +	void Start();
  1.1123 +	void DoTest();
  1.1124 +	TUint64 Random();
  1.1125 +	void Kick();
  1.1126 +private:
  1.1127 +	RThread			iThread;
  1.1128 +	TInt			iId;
  1.1129 +	CThreads*		iThreads;
  1.1130 +	TRequestStatus	iStatus;
  1.1131 +	TBool			iStarted;
  1.1132 +	TPerThread		iPerThread;
  1.1133 +	TUint64			iSeed;
  1.1134 +private:
  1.1135 +	friend class CThreads;
  1.1136 +	};
  1.1137 +
  1.1138 +CThreads::CThreads()
  1.1139 +	{
  1.1140 +	iNumCpus = UserSvr::HalFunction(EHalGroupKernel, EKernelHalNumLogicalCpus, 0, 0);
  1.1141 +	iNumThreads = iNumCpus;
  1.1142 +	if (iNumThreads<2)
  1.1143 +		iNumThreads=2;
  1.1144 +	TInt khz;
  1.1145 +	TInt r = HAL::Get(HAL::ECPUSpeed, khz);
  1.1146 +	if (r==KErrNone)
  1.1147 +		iTimeslice = Max(10000000/khz, 100);
  1.1148 +	else if (r==KErrNotSupported)
  1.1149 +		iTimeslice = 227;
  1.1150 +	else
  1.1151 +		User::Panic(_L("TIMESLICE"),r);
  1.1152 +	}
  1.1153 +
  1.1154 +CThreads::~CThreads()
  1.1155 +	{
  1.1156 +	TInt i;
  1.1157 +	for (i=0; i<iNumThreads; ++i)
  1.1158 +		delete iThreads[i];
  1.1159 +	iSem.Close();
  1.1160 +	}
  1.1161 +
  1.1162 +CThreads* CThreads::New()
  1.1163 +	{
  1.1164 +	CThreads* p = new CThreads;
  1.1165 +	if (p)
  1.1166 +		{
  1.1167 +		TInt r;
  1.1168 +		r = p->iSem.CreateLocal(0);
  1.1169 +		TInt i;
  1.1170 +		for (i=0; i<p->iNumThreads && r==KErrNone; ++i)
  1.1171 +			{
  1.1172 +			p->iThreads[i] = p->NewThread(i);
  1.1173 +			if (!p->iThreads[i])
  1.1174 +				r = KErrNoMemory;
  1.1175 +			}
  1.1176 +		if (r!=KErrNone)
  1.1177 +			{
  1.1178 +			delete p;
  1.1179 +			return 0;
  1.1180 +			}
  1.1181 +		p->iStop = ETrue;
  1.1182 +		for (i=0; i<p->iNumThreads; ++i)
  1.1183 +			p->iThreads[i]->Start();
  1.1184 +		}
  1.1185 +	return p;
  1.1186 +	}
  1.1187 +
  1.1188 +CThread* CThreads::NewThread(TInt aId)
  1.1189 +	{
  1.1190 +	CThread* t = new CThread;
  1.1191 +	if (t)
  1.1192 +		{
  1.1193 +		t->iId = aId;
  1.1194 +		t->iThreads = this;
  1.1195 +		TInt r = t->Create();
  1.1196 +		if (r!=KErrNone)
  1.1197 +			{
  1.1198 +			delete t;
  1.1199 +			t = 0;
  1.1200 +			}
  1.1201 +		}
  1.1202 +	return t;
  1.1203 +	}
  1.1204 +
  1.1205 +void CThreads::StartTest(TInt aIndex, TBool aKernel)
  1.1206 +	{
  1.1207 +	iIndex = aIndex;
  1.1208 +	iKernel = aKernel;
  1.1209 +	iReg = 0;
  1.1210 +	iStop = EFalse;
  1.1211 +#ifdef __EPOC32__
  1.1212 +	if (iKernel)
  1.1213 +		DD.Initialise(iReg);
  1.1214 +#endif
  1.1215 +	TInt i;
  1.1216 +	for (i=0; i<iNumThreads; ++i)
  1.1217 +		iThreads[i]->Kick();
  1.1218 +	}
  1.1219 +
  1.1220 +void CThreads::StopTest()
  1.1221 +	{
  1.1222 +	iStop = ETrue;
  1.1223 +	TInt i;
  1.1224 +	for (i=0; i<iNumThreads; ++i)
  1.1225 +		iSem.Wait();
  1.1226 +#ifdef __EPOC32__
  1.1227 +	if (iKernel)
  1.1228 +		iReg = DD.Retrieve();
  1.1229 +#endif
  1.1230 +	}
  1.1231 +
  1.1232 +void CThreads::Finish()
  1.1233 +	{
  1.1234 +	iStop = EFalse;
  1.1235 +	iIndex = -1;
  1.1236 +	TInt i;
  1.1237 +	for (i=0; i<iNumThreads; ++i)
  1.1238 +		{
  1.1239 +		iThreads[i]->Kick();
  1.1240 +		iSem.Wait();
  1.1241 +		}
  1.1242 +	test(iFailCount==0);
  1.1243 +	}
  1.1244 +
  1.1245 +TUint32 CThreads::DoCasTest(TInt aIndex, TBool aKernel, TUint32 aFailLimit)
  1.1246 +	{
  1.1247 +	TInt i;
  1.1248 +	test.Printf(_L("DoCasTest I=%d K=%1d F=%d\n"), aIndex, aKernel, aFailLimit);
  1.1249 +	TUint32 initial = User::FastCounter();
  1.1250 +	StartTest(aIndex, aKernel);
  1.1251 +	FOREVER
  1.1252 +		{
  1.1253 +		User::AfterHighRes(1000000);
  1.1254 +		TUint64 minf = 0;
  1.1255 +		--minf;
  1.1256 +		for (i=0; i<iNumThreads; ++i)
  1.1257 +			{
  1.1258 +			CThread* t = iThreads[i];
  1.1259 +			test.Printf(_L("T%1d: C=%lu R=%lu\n"), i, t->iPerThread.iDiff, t->iPerThread.iFailCount);
  1.1260 +			TUint64 f = t->iPerThread.iFailCount;
  1.1261 +			if (f<minf)
  1.1262 +				minf=f;
  1.1263 +			}
  1.1264 +		if (minf>=TUint64(aFailLimit))
  1.1265 +			break;
  1.1266 +		if (iNumCpus>1)	// 1 second is enough for SMP, except on VMPlayer
  1.1267 +			break;
  1.1268 +		}
  1.1269 +	StopTest();
  1.1270 +	TUint32 final = User::FastCounter();
  1.1271 +	TUint32 time = final - initial;
  1.1272 +	test.Printf(_L("Time %d\n"), time);
  1.1273 +	TUint64 total = 0;
  1.1274 +	TUint64 txor = 0;
  1.1275 +	for (i=0; i<iNumThreads; ++i)
  1.1276 +		{
  1.1277 +		CThread* t = iThreads[i];
  1.1278 +		test.Printf(_L("T%1d: %lu completed %lu retries\n"), i, t->iPerThread.iDiff, t->iPerThread.iFailCount);
  1.1279 +		total += t->iPerThread.iDiff;
  1.1280 +		txor ^= t->iPerThread.iXor;
  1.1281 +		}
  1.1282 +	TUint size = ATTR_TO_SIZE(FuncAttr[aIndex]);
  1.1283 +	TUint64 expected = 0;
  1.1284 +	switch (size)
  1.1285 +		{
  1.1286 +		case 1:	expected = Transform<TUint8>::F_iter(0, total); break;
  1.1287 +		case 2:	expected = Transform<TUint16>::F_iter(0, total); break;
  1.1288 +		case 4:	expected = Transform<TUint32>::F_iter(0, total); break;
  1.1289 +		case 8:	expected = Transform<TUint64>::F_iter(0, total); break;
  1.1290 +		}
  1.1291 +	test.Printf(_L("Total iterations %lu\n"), total);
  1.1292 +	test.Printf(_L("Expected result %08x %08x\n"), I64HIGH(expected), I64LOW(expected));
  1.1293 +	test.Printf(_L("Actual   result %08x %08x\n"), I64HIGH(iReg), I64LOW(iReg));
  1.1294 +	test.Printf(_L("Tot. XOR result %08x %08x\n"), I64HIGH(txor), I64LOW(txor));
  1.1295 +//	test(expected==iReg);
  1.1296 +//	test(expected==txor);
  1.1297 +	if (expected!=iReg || expected!=txor)
  1.1298 +		{
  1.1299 +		test.Printf(_L("***FAIL***\n"));
  1.1300 +		++iFailCount;
  1.1301 +		}
  1.1302 +	return time;
  1.1303 +	}
  1.1304 +
  1.1305 +void CThreads::DoRmwTest(TInt aIndex, TBool aKernel, TInt aTime)
  1.1306 +	{
  1.1307 +	TInt i;
  1.1308 +	test.Printf(_L("DoRmwTest I=%d K=%1d T=%d\n"), aIndex, aKernel, aTime);
  1.1309 +	StartTest(aIndex, aKernel);
  1.1310 +	User::AfterHighRes(aTime);
  1.1311 +	StopTest();
  1.1312 +	TUint64 total = 0;
  1.1313 +	TUint64 txor = 0;
  1.1314 +	for (i=0; i<iNumThreads; ++i)
  1.1315 +		{
  1.1316 +		CThread* t = iThreads[i];
  1.1317 +		test.Printf(_L("T%1d: C=%10lu D=%lx X=%lx\n"), i, t->iPerThread.iCount, t->iPerThread.iDiff, t->iPerThread.iXor);
  1.1318 +		total += t->iPerThread.iDiff;
  1.1319 +		txor ^= t->iPerThread.iXor;
  1.1320 +		}
  1.1321 +	TUint size = ATTR_TO_SIZE(FuncAttr[aIndex]);
  1.1322 +	switch (size)
  1.1323 +		{
  1.1324 +		case 1:
  1.1325 +			{
  1.1326 +			TUint8 expected = (TUint8)total;
  1.1327 +			TUint8 exor = (TUint8)txor;
  1.1328 +			TUint8 got = (TUint8)iReg;
  1.1329 +			test.Printf(_L("Expected %02x Got %02x XOR %02x\n"), expected, got, exor);
  1.1330 +//			test(expected==got && exor==got);
  1.1331 +			if (expected!=got || exor!=got)
  1.1332 +				{
  1.1333 +				test.Printf(_L("***FAIL***\n"));
  1.1334 +				++iFailCount;
  1.1335 +				}
  1.1336 +			break;
  1.1337 +			}
  1.1338 +		case 2:
  1.1339 +			{
  1.1340 +			TUint16 expected = (TUint16)total;
  1.1341 +			TUint16 exor = (TUint16)txor;
  1.1342 +			TUint16 got = (TUint16)iReg;
  1.1343 +			test.Printf(_L("Expected %04x Got %04x XOR %04x\n"), expected, got, exor);
  1.1344 +//			test(expected==got && exor==got);
  1.1345 +			if (expected!=got || exor!=got)
  1.1346 +				{
  1.1347 +				test.Printf(_L("***FAIL***\n"));
  1.1348 +				++iFailCount;
  1.1349 +				}
  1.1350 +			break;
  1.1351 +			}
  1.1352 +		case 4:
  1.1353 +			{
  1.1354 +			TUint32 expected = (TUint32)total;
  1.1355 +			TUint32 exor = (TUint32)txor;
  1.1356 +			TUint32 got = (TUint32)iReg;
  1.1357 +			test.Printf(_L("Expected %08x Got %08x XOR %08x\n"), expected, got, exor);
  1.1358 +//			test(expected==got && exor==got);
  1.1359 +			if (expected!=got || exor!=got)
  1.1360 +				{
  1.1361 +				test.Printf(_L("***FAIL***\n"));
  1.1362 +				++iFailCount;
  1.1363 +				}
  1.1364 +			break;
  1.1365 +			}
  1.1366 +		case 8:
  1.1367 +			{
  1.1368 +			TUint64 expected = total;
  1.1369 +			test.Printf(_L("Expected result %08x %08x\n"), I64HIGH(expected), I64LOW(expected));
  1.1370 +			test.Printf(_L("Actual   result %08x %08x\n"), I64HIGH(iReg), I64LOW(iReg));
  1.1371 +			test.Printf(_L("Tot. XOR result %08x %08x\n"), I64HIGH(txor), I64LOW(txor));
  1.1372 +//			test(expected==iReg && expected==txor);
  1.1373 +			if (expected!=iReg || expected!=txor)
  1.1374 +				{
  1.1375 +				test.Printf(_L("***FAIL***\n"));
  1.1376 +				++iFailCount;
  1.1377 +				}
  1.1378 +			break;
  1.1379 +			}
  1.1380 +		}
  1.1381 +	}
  1.1382 +
  1.1383 +CThread::CThread()
  1.1384 +	{
  1.1385 +	}
  1.1386 +
  1.1387 +CThread::~CThread()
  1.1388 +	{
  1.1389 +	TInt h = iThread.Handle();
  1.1390 +	if (h && h!=KCurrentThreadHandle)
  1.1391 +		{
  1.1392 +		if (!iStarted)
  1.1393 +			iThread.Kill(0);
  1.1394 +		User::WaitForRequest(iStatus);
  1.1395 +		}
  1.1396 +	iThread.Close();
  1.1397 +	}
  1.1398 +
  1.1399 +TInt CThread::Create()
  1.1400 +	{
  1.1401 +	TInt r = iThread.Create(KNullDesC, &ThreadFunction, 0x2000, 0, this);
  1.1402 +	if (r==KErrNone)
  1.1403 +		{
  1.1404 +		iThread.Logon(iStatus);
  1.1405 +		if (iStatus.Int() != KRequestPending)
  1.1406 +			r = iStatus.Int();
  1.1407 +		}
  1.1408 +	return r;
  1.1409 +	}
  1.1410 +
  1.1411 +void CThread::Start()
  1.1412 +	{
  1.1413 +	iThread.Resume();
  1.1414 +	iThreads->iSem.Wait();
  1.1415 +	}
  1.1416 +
  1.1417 +void CThread::Kick()
  1.1418 +	{
  1.1419 +	TRequestStatus s;
  1.1420 +	TRequestStatus* pS = &s;
  1.1421 +	iThread.RequestComplete(pS,0);
  1.1422 +	}
  1.1423 +
  1.1424 +TInt CThread::ThreadFunction(TAny* aPtr)
  1.1425 +	{
  1.1426 +	return ((CThread*)aPtr)->Run();
  1.1427 +	}
  1.1428 +
  1.1429 +TInt CThread::Run()
  1.1430 +	{
  1.1431 +#ifdef __EPOC32__
  1.1432 +	DD.SetCurrentThreadTimeslice(iThreads->iTimeslice);
  1.1433 +#endif
  1.1434 +	RThread().SetPriority(EPriorityLess);
  1.1435 +	FOREVER
  1.1436 +		{
  1.1437 +		if (iThreads->iStop)
  1.1438 +			{
  1.1439 +			iThreads->iSem.Signal();
  1.1440 +			if (iThreads->iNumCpus > 1)
  1.1441 +				RThread().SetPriority(EPriorityAbsoluteHigh);	// encourage spreading out of threads between CPUs
  1.1442 +			User::WaitForAnyRequest();
  1.1443 +			if (iThreads->iIndex<0)
  1.1444 +				break;
  1.1445 +			if (iThreads->iNumCpus > 1)
  1.1446 +				{
  1.1447 +				TUint32 tick = User::NTickCount();
  1.1448 +				while(User::NTickCount()-tick < 2) {}	// spin to discourage putting other threads on this CPU
  1.1449 +				RThread().SetPriority(EPriorityLess);
  1.1450 +				}
  1.1451 +			}
  1.1452 +		DoTest();
  1.1453 +		}
  1.1454 +	iThreads->iSem.Signal();
  1.1455 +	return 0;
  1.1456 +	}
  1.1457 +
  1.1458 +TUint64 CThread::Random()
  1.1459 +	{
  1.1460 +	iSeed = Transform<TUint64>::F(iSeed);
  1.1461 +	return iSeed;
  1.1462 +	}
  1.1463 +
  1.1464 +void CThread::DoTest()
  1.1465 +	{
  1.1466 +	iPerThread.iDiff = 0;
  1.1467 +	iPerThread.iXor = 0;
  1.1468 +	iPerThread.iFailCount = 0;
  1.1469 +	iPerThread.iCount = 0;
  1.1470 +	TInt index = iThreads->iIndex;
  1.1471 +	TAny* p = (TAny*)&iThreads->iReg;
  1.1472 +#ifdef __EPOC32__
  1.1473 +	TBool kernel = iThreads->iKernel;
  1.1474 +	if (kernel)
  1.1475 +		{
  1.1476 +		DD.SwitchExecTables(iId);
  1.1477 +		RTestAtomic::SetThreadInfo(iPerThread);
  1.1478 +		}
  1.1479 +	TInt iter = 0;
  1.1480 +#endif
  1.1481 +	iSeed = iId;
  1.1482 +	while (!iThreads->iStop)
  1.1483 +		{
  1.1484 +		TAtomicAction action;
  1.1485 +		action.i0 = Random();
  1.1486 +		action.i1 = Random();
  1.1487 +		action.i2 = Random();
  1.1488 +		action.iIndex = index;
  1.1489 +		action.iThread = iId;
  1.1490 +#ifdef __EPOC32__
  1.1491 +		if (kernel)
  1.1492 +			{
  1.1493 +			RTestAtomic::AtomicAction(action);
  1.1494 +			}
  1.1495 +		else
  1.1496 +#endif
  1.1497 +			DoAtomicAction(p, &iPerThread, action);
  1.1498 +#ifdef __EPOC32__
  1.1499 +		if (kernel && ++iter==1024)
  1.1500 +			{
  1.1501 +			iter = 0;
  1.1502 +			RTestAtomic::GetThreadInfo(iPerThread);
  1.1503 +			}
  1.1504 +#endif
  1.1505 +		}
  1.1506 +#ifdef __EPOC32__
  1.1507 +	if (kernel)
  1.1508 +		{
  1.1509 +		RTestAtomic::GetThreadInfo(iPerThread);
  1.1510 +		RTestAtomic::RestoreExecTable();
  1.1511 +		}
  1.1512 +#endif
  1.1513 +	}
  1.1514 +
  1.1515 +void TestMultipleThreads()
  1.1516 +	{
  1.1517 +	CThreads* p = CThreads::New();
  1.1518 +	test(p!=0);
  1.1519 +
  1.1520 +	TInt KRequiredRetries = 1000;
  1.1521 +	if (p->NumCpus()==1)
  1.1522 +		KRequiredRetries = 10;
  1.1523 +
  1.1524 +	TUint32 time;
  1.1525 +	TUint32 total_time = 0;
  1.1526 +	TUint32 total_time_k = 0;
  1.1527 +	TUint32 count = 0;
  1.1528 +	TInt ix;
  1.1529 +	for (ix=0; ix<TOTAL_INDEXES; ++ix)
  1.1530 +		{
  1.1531 +		TUint attr = FuncAttr[ix];
  1.1532 +		TUint func = ATTR_TO_FUNC(attr);
  1.1533 +		TUint type = ATTR_TO_TYPE(attr);
  1.1534 +		if (p->NumCpus()==1)
  1.1535 +			{
  1.1536 +			TUint ord = ATTR_TO_ORD(attr);
  1.1537 +			if (ord != EOrderOrdered)
  1.1538 +				continue;
  1.1539 +			}
  1.1540 +		if (type==EFuncTypeInvalid)
  1.1541 +			continue;
  1.1542 +		if (func!=TUint(EAtomicFuncCAS))
  1.1543 +			continue;
  1.1544 +		time = p->DoCasTest(ix, EFalse, KRequiredRetries);
  1.1545 +		total_time += time;
  1.1546 +		++count;
  1.1547 +		time = p->DoCasTest(ix, ETrue, KRequiredRetries);
  1.1548 +		total_time_k += time;
  1.1549 +		}
  1.1550 +	TUint32 avg_time = total_time / count;
  1.1551 +	TUint32 avg_time_k = total_time_k / count;
  1.1552 +	TUint32 fcf=0;
  1.1553 +	TInt r = HAL::Get(HAL::EFastCounterFrequency, (TInt&)fcf);
  1.1554 +	test_KErrNone(r);
  1.1555 +	test.Printf(_L("FastCounterFrequency = %u\n"), fcf);
  1.1556 +	TUint64 avg_time_us64(avg_time);
  1.1557 +	avg_time_us64*=UI64LIT(1000000);
  1.1558 +	avg_time_us64/=TUint64(fcf);
  1.1559 +	TInt avg_time_us = KMaxTInt;
  1.1560 +	TInt avg_time_k_us = KMaxTInt;
  1.1561 +	if (avg_time_us64<TUint64(KMaxTInt))
  1.1562 +		avg_time_us = (TInt)avg_time_us64;
  1.1563 +	TUint64 avg_time_k_us64(avg_time);
  1.1564 +	avg_time_k_us64*=UI64LIT(1000000);
  1.1565 +	avg_time_k_us64/=TUint64(fcf);
  1.1566 +	if (avg_time_k_us64<TUint64(KMaxTInt))
  1.1567 +		avg_time_k_us = (TInt)avg_time_k_us64;
  1.1568 +
  1.1569 +	test.Printf(_L("Average time (user) %u (%dus)\n"), avg_time, avg_time_us);
  1.1570 +	test.Printf(_L("Average time (kernel) %u (%dus)\n"), avg_time_k, avg_time_k_us);
  1.1571 +
  1.1572 +	TInt limit_us = (p->NumCpus()==1) ? 15*1000*1000 : 4*1000*1000;
  1.1573 +
  1.1574 +	for (ix=0; ix<TOTAL_INDEXES; ++ix)
  1.1575 +		{
  1.1576 +		TUint attr = FuncAttr[ix];
  1.1577 +		TUint func = ATTR_TO_FUNC(attr);
  1.1578 +		TUint type = ATTR_TO_TYPE(attr);
  1.1579 +		if (p->NumCpus()==1)
  1.1580 +			{
  1.1581 +			TUint ord = ATTR_TO_ORD(attr);
  1.1582 +			if (ord != EOrderOrdered)
  1.1583 +				continue;
  1.1584 +			}
  1.1585 +		if (type==EFuncTypeInvalid)
  1.1586 +			continue;
  1.1587 +		if (func<TUint(EAtomicFuncSWP) || func>=TUint(EAtomicFuncCAS))
  1.1588 +			continue;
  1.1589 +		if (func==TUint(EAtomicFuncIOR))	// can only test AND and IOR together
  1.1590 +			continue;
  1.1591 +		p->DoRmwTest(ix, EFalse, Min(avg_time_us,limit_us));
  1.1592 +		p->DoRmwTest(ix, ETrue, Min(avg_time_k_us,limit_us));
  1.1593 +		}
  1.1594 +
  1.1595 +	p->Finish();
  1.1596 +	delete p;
  1.1597 +	}
  1.1598 +
  1.1599 +
  1.1600 +
  1.1601 +/******************************************************************************
  1.1602 + * Main
  1.1603 + ******************************************************************************/
  1.1604 +TInt E32Main()
  1.1605 +	{
  1.1606 +	test.Title();
  1.1607 +	test.Start(_L("Opening device driver"));
  1.1608 +#ifdef __EPOC32__
  1.1609 +	TInt r;
  1.1610 +	r = User::LoadLogicalDevice(KAtomicTestLddName);
  1.1611 +	test(r==KErrNone||r==KErrAlreadyExists);
  1.1612 +	r = DD.Open();
  1.1613 +	test_KErrNone(r);
  1.1614 +#endif
  1.1615 +	test.Next(_L("Testing atomic operations ..."));
  1.1616 +	test.Next(_L("Single thread, normal operation"));
  1.1617 +	TestSingleThread();
  1.1618 +	test.Next(_L("Single thread, bad addresses"));
  1.1619 +	TestInvalidAddresses();
  1.1620 +	test.Next(_L("Multiple threads"));
  1.1621 +	TestMultipleThreads();
  1.1622 +	test.End();
  1.1623 +	return 0;
  1.1624 +	}
  1.1625 +