Update contrib.
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\nkernsa\testutils.cpp
18 #include <nktest/nkutils.h>
21 TUint32 random(TUint32* aSeed)
25 r3 |= (aSeed[1] << 31);
33 void setup_block(TUint32* aBlock, TInt aNumWords)
39 for (i=1; i<aNumWords; ++i)
40 *++aBlock = random(seed);
43 void setup_block_cpu(TUint32* aBlock, TInt aNumWords)
48 aBlock[1] = NKern::CurrentCpu();
50 for (i=2; i<aNumWords; ++i)
51 aBlock[i] = random(seed) ^ NKern::CurrentCpu();
54 TBool verify_block(const TUint32* aBlock, TInt aNumWords)
60 for (i=1; i<aNumWords; ++i)
62 TUint32 x = random(seed);
65 KPrintf("Verify block failed: expected %08x got %08x", x, aBlock[i]);
72 TBool verify_block_no_trace(const TUint32* aBlock, TInt aNumWords)
78 for (i=1; i<aNumWords; ++i)
80 TUint32 x = random(seed);
87 TInt verify_block_cpu(const TUint32* aBlock, TInt aNumWords)
92 TUint32 cpu = aBlock[1];
94 for (i=2; i<aNumWords; ++i)
96 TUint32 x = random(seed);
97 TUint32 y = aBlock[i] ^ x;
100 KPrintf("Verify block with CPU failed: expected %08x got %08x (XOR %08x)", x, aBlock[i], y);
107 TInt verify_block_cpu_no_trace(const TUint32* aBlock, TInt aNumWords)
112 TUint32 cpu = aBlock[1];
114 for (i=2; i<aNumWords; ++i)
116 TUint32 x = random(seed);
117 TUint32 y = aBlock[i] ^ x;
126 CircBuf* CircBuf::New(TInt aSlots)
128 CircBuf* p = new CircBuf();
129 p->iSlotCount = aSlots;
132 p->iBufBase = (TUint32*)malloc(aSlots*sizeof(TUint32));
142 : iLock(TSpinLock::EOrderGenericIrqLow1)
151 TInt CircBuf::TryGet(TUint32& aOut)
153 TInt r = KErrUnderflow;
154 TInt irq = __SPIN_LOCK_IRQSAVE(iLock);
155 if (iGetIndex != iPutIndex)
157 aOut = iBufBase[iGetIndex++];
158 if (iGetIndex == iSlotCount)
162 __SPIN_UNLOCK_IRQRESTORE(iLock,irq);
166 TInt CircBuf::TryPut(TUint32 aIn)
168 TInt r = KErrOverflow;
169 TInt irq = __SPIN_LOCK_IRQSAVE(iLock);
170 TInt nextPut = iPutIndex + 1;
171 if (nextPut == iSlotCount)
173 if (iGetIndex != nextPut)
175 iBufBase[iPutIndex] = aIn;
179 __SPIN_UNLOCK_IRQRESTORE(iLock,irq);
183 TUint32 CircBuf::Get()
186 while(TryGet(x)!=KErrNone)
191 void CircBuf::Put(TUint32 aIn)
193 while(TryPut(aIn)!=KErrNone)
197 void CircBuf::Reset()
199 TInt irq = __SPIN_LOCK_IRQSAVE(iLock);
200 iPutIndex = iGetIndex = 0;
201 __SPIN_UNLOCK_IRQRESTORE(iLock,irq);
204 TInt CircBuf::Count()
206 TInt irq = __SPIN_LOCK_IRQSAVE(iLock);
207 TInt r = iPutIndex - iGetIndex;
210 __SPIN_UNLOCK_IRQRESTORE(iLock,irq);