kerneltest/e32test/misc/t_cp0.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1998-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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32test\misc\t_cp0.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32test.h>
       
    19 #include <cpudefs.h>
       
    20 #include "nk_cpu.h"
       
    21 #include "../misc/prbs.h"
       
    22 
       
    23 RTest test(_L("T_CP0"));
       
    24 
       
    25 extern void GetAcc0(TInt64&);
       
    26 extern void SetAcc0(const TInt64&);
       
    27 extern void InnerProduct(TInt64& /*aResult*/, const TInt16* /*aVec1*/, const TInt16* /*aVec2*/, TInt /*aLength*/);
       
    28 extern void InnerProduct2(TInt64& /*aResult*/, const TInt16* /*aVec1*/, const TInt16* /*aVec2*/, TInt /*aLength*/);
       
    29 
       
    30 
       
    31 TInt DoCP0Test(TAny* aPtr)
       
    32 	{
       
    33 	TUint seed[2];
       
    34 	seed[0]=(TUint)aPtr;
       
    35 	seed[1]=0;
       
    36 	TInt16 vec1[128];
       
    37 	TInt16 vec2[128];
       
    38 	TInt run;
       
    39 	for (run=0; run<100000; ++run)
       
    40 		{
       
    41 		TInt n=(Random(seed)&63)+64;		// vector length
       
    42 		TInt i;
       
    43 		for (i=0; i<n; ++i)
       
    44 			{
       
    45 			vec1[i]=(TInt16)(Random(seed)&0xffff);
       
    46 			vec2[i]=(TInt16)(Random(seed)&0xffff);
       
    47 			TInt64 result, result2;
       
    48 			InnerProduct(result,vec1,vec2,n);
       
    49 			InnerProduct2(result2,vec1,vec2,n);
       
    50 			if (result != result2)
       
    51 				{
       
    52 				User::Panic(_L("ERROR"),run);
       
    53 				}
       
    54 			}
       
    55 		}
       
    56 	return 0;
       
    57 	}
       
    58 
       
    59 void CheckExit(TInt aThreadNum, RThread aThread)
       
    60 	{
       
    61 	TInt exitType=aThread.ExitType();
       
    62 	TInt exitReason=aThread.ExitReason();
       
    63 	TBuf<32> exitCat=aThread.ExitCategory();
       
    64 	test.Printf(_L("Thread %d: %d,%d,%S\n"),aThreadNum,exitType,exitReason,&exitCat);
       
    65 	test(exitType==EExitKill);
       
    66 	test(exitReason==KErrNone);
       
    67 	}
       
    68 
       
    69 TInt E32Main()
       
    70 	{
       
    71 	test.Title();
       
    72 	test.Start(_L("Testing XScale DSP Coprocessor"));
       
    73 
       
    74 	TInt64 acc0;
       
    75 	GetAcc0(acc0);
       
    76 	test.Printf(_L("acc0=%lx\n"),acc0);
       
    77 
       
    78 	SetAcc0(0);
       
    79 	GetAcc0(acc0);
       
    80 	test.Printf(_L("acc0=%lx\n"),acc0);
       
    81 
       
    82 	test.Next(_L("Test CP0 in single thread"));
       
    83 	DoCP0Test((TAny*)487);
       
    84 
       
    85 	test.Next(_L("Test CP0 in multiple threads"));
       
    86 	RThread t1, t2;
       
    87 	TRequestStatus s1, s2;
       
    88 	TInt r=t1.Create(KNullDesC(),DoCP0Test,0x1000,NULL,(TAny*)0xddb3d743);
       
    89 	test(r==KErrNone);
       
    90 	r=t2.Create(KNullDesC(),DoCP0Test,0x1000,NULL,(TAny*)0xb504f334);
       
    91 	test(r==KErrNone);
       
    92 	t1.Logon(s1);
       
    93 	t2.Logon(s2);
       
    94 	t1.Resume();
       
    95 	t2.Resume();
       
    96 	User::WaitForRequest(s1);
       
    97 	User::WaitForRequest(s2);
       
    98 	CheckExit(1,t1);
       
    99 	CheckExit(2,t2);
       
   100 	CLOSE_AND_WAIT(t1);
       
   101 	CLOSE_AND_WAIT(t2);
       
   102 
       
   103 	test.End();
       
   104 	return 0;
       
   105 	}
       
   106