1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/mmu/t_btb.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,236 @@
1.4 +// Copyright (c) 1995-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\mmu\t_btb.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +//! @SYMTestCaseID KBASE/T_BTB
1.22 +//! @SYMTestType UT
1.23 +//! @SYMTestCaseDesc Make sure processes can't interfere with each other via the BTB. Make sure the BTB is turned on.
1.24 +//! @SYMREQ REQ4095
1.25 +//! @SYMTestActions Make concurent processes with code areas and thrash them.
1.26 +//! @SYMTestExpectedResults They shouldn't interfere. The BTB should be enabled.
1.27 +//! @SYMTestPriority Low
1.28 +//! @SYMTestStatus Defined
1.29 +
1.30 +#include <e32test.h>
1.31 +#include "u32std.h"
1.32 +
1.33 +#ifdef __CPU_ARM
1.34 +
1.35 +extern TInt BranchTest1();
1.36 +extern TInt BranchTest2();
1.37 +extern TInt BranchTest3();
1.38 +void BranchTest4(TInt);
1.39 +extern void BranchTest1End();
1.40 +extern void BranchTest2End();
1.41 +extern void BranchTest3End();
1.42 +extern void BranchTest4End();
1.43 +
1.44 +typedef TInt (*PFI)(void);
1.45 +typedef void (*PFV)(TInt);
1.46 +
1.47 +void SecondaryProcess(const TDesC& aCmd, RTest& test)
1.48 + {
1.49 + test.Start(_L("Secondary Process"));
1.50 + TLex lex(aCmd);
1.51 + TUint32 addr;
1.52 + TInt r=lex.Val(addr,EHex);
1.53 + test(r==KErrNone);
1.54 + test.Printf(_L("Primary process says: RAM code at %08x\n"),addr);
1.55 + TInt pageSize;
1.56 + r=UserHal::PageSizeInBytes(pageSize);
1.57 + test(r==KErrNone);
1.58 + RChunk c;
1.59 + r=c.CreateLocalCode(pageSize,0x100000);
1.60 + test(r==KErrNone);
1.61 + PFI pBranchTest2=(PFI)c.Base();
1.62 + test.Printf(_L("Secondary test loop function at %08x\n"),pBranchTest2);
1.63 +
1.64 + test((TUint32)pBranchTest2==addr);
1.65 +
1.66 + TInt fnLength = (TInt)&BranchTest2End-(TInt)&BranchTest2;
1.67 +
1.68 + test.Printf(_L("SecProc: Copying %d bytes from %08x...\n"), (TInt)&BranchTest2End-(TInt)&BranchTest2, (TAny*)&BranchTest2 );
1.69 + Mem::Copy((TAny*)pBranchTest2, (TAny*)&BranchTest2, fnLength);
1.70 + User::IMB_Range((TAny*)pBranchTest2, fnLength+(TUint8*)pBranchTest2);
1.71 +
1.72 + TTime begin;
1.73 + begin.HomeTime();
1.74 +
1.75 + test.Printf(_L("Running secondary loop...\n"));
1.76 +
1.77 + TInt n=0;
1.78 + FOREVER
1.79 + {
1.80 + n=pBranchTest2();
1.81 +
1.82 + if (n)
1.83 + break;
1.84 +
1.85 + TTime now;
1.86 + now.HomeTime();
1.87 + if (now.MicroSecondsFrom(begin).Int64()>20000000) // ten seconds for each test ought to be long enough
1.88 + break;
1.89 + }
1.90 + test.Printf(_L("Ending secondary loop.\n"));
1.91 + test(n==0);
1.92 + //test.End();
1.93 + }
1.94 +
1.95 +
1.96 +GLREF_C TInt E32Main()
1.97 + {
1.98 + RTest test(_L("T_BTB"));
1.99 + test.Title();
1.100 +
1.101 + TBuf<16> cmd;
1.102 + User::CommandLine(cmd);
1.103 + if (cmd.Length()!=0) // if we get a command line, we're the secondary process
1.104 + {
1.105 + SecondaryProcess(cmd,test);
1.106 + return 0;
1.107 + }
1.108 +
1.109 + test.Start(_L("Create primary process code chunk"));
1.110 + TInt pageSize;
1.111 + TInt r=UserHal::PageSizeInBytes(pageSize);
1.112 + test(r==KErrNone);
1.113 +
1.114 + RChunk c;
1.115 + r=c.CreateLocalCode(pageSize,0x100000);
1.116 + test(r==KErrNone);
1.117 + TUint8* pCode=c.Base();
1.118 + test.Printf(_L("Primary process code chunk at %08x\n"),pCode);
1.119 +
1.120 + // Spawn a secondary process
1.121 + RProcess p;
1.122 + TRequestStatus s;
1.123 + TBuf<16> codeBaseHex;
1.124 + codeBaseHex.Format(_L("%08x"),pCode);
1.125 + r=p.Create(RProcess().FileName(),codeBaseHex);
1.126 + test(r==KErrNone);
1.127 + p.Logon(s);
1.128 + p.Resume();
1.129 +
1.130 +
1.131 + TTime begin, now;
1.132 + TInt n=0, m=0, q=0, fnLength;
1.133 +
1.134 + PFI pBranchTest1=(PFI)pCode;
1.135 + test.Printf(_L("Primary test loop function at %08x\n"),pBranchTest1);
1.136 +
1.137 + fnLength = (TInt)&BranchTest1End-(TInt)&BranchTest1;
1.138 +
1.139 + //test.Printf(_L("PriProc: Copying %d bytes from 0x%08x to 0x%08x for forward-branching test...\n"), fnLength, &BranchTest1, pBranchTest1);
1.140 + Mem::Copy((TAny *)pBranchTest1, (const TAny*)&BranchTest1, fnLength); // copy in the asm test code
1.141 + User::IMB_Range((TAny*)pBranchTest1, fnLength+(TUint8*)pBranchTest1);
1.142 +
1.143 + test.Printf(_L("Running primary loop...\n"));
1.144 + begin.HomeTime();
1.145 + FOREVER
1.146 + {
1.147 + m++;
1.148 + n=pBranchTest1();
1.149 + if (n)
1.150 + break;
1.151 + now.HomeTime();
1.152 + if (now.MicroSecondsFrom(begin).Int64()>10000000) // ten seconds ought to be long enough
1.153 + break;
1.154 + }
1.155 + test(n==0);
1.156 + test.Printf(_L("Ending primary loop. Ran %d times in 10s.\n"), m);
1.157 +
1.158 + // run the second test
1.159 +
1.160 + PFI pBranchTest3=(PFI)pCode;
1.161 +
1.162 + fnLength = (TInt)&BranchTest3End-(TInt)&BranchTest3;
1.163 + //test.Printf(_L("PriProc: Copying %d bytes from 0x%08x to 0x%08x for back-branching test...\n"), fnLength, &BranchTest3, pBranchTest3);
1.164 + Mem::Copy((TAny *)pBranchTest3, (const TAny*)&BranchTest3, fnLength); // copy in the asm test code
1.165 + User::IMB_Range((TAny*)pBranchTest3, fnLength+(TUint8*)pBranchTest3);
1.166 +
1.167 + test.Printf(_L("PriProc: Starting back-branch test loop.\n"));
1.168 + m=0;
1.169 + begin.HomeTime();
1.170 + FOREVER
1.171 + {
1.172 + m++;
1.173 + n=pBranchTest3();
1.174 + if (n)
1.175 + break;
1.176 + now.HomeTime();
1.177 + if (now.MicroSecondsFrom(begin).Int64()>10000000) // ten seconds ought to be long enough
1.178 + break;
1.179 + }
1.180 + test(n==0);
1.181 + test.Printf(_L("Ending primary back-branching loop. Ran %d times in 10s.\n"), m);
1.182 +
1.183 + p.Kill(0);
1.184 + User::WaitForRequest(s);
1.185 + TInt exitType=p.ExitType();
1.186 + TInt exitReason=p.ExitReason();
1.187 + TExitCategoryName exitCat=p.ExitCategory();
1.188 + CLOSE_AND_WAIT(p);
1.189 + test.Printf(_L("SecProc: %d,%d,%S\n"),exitType,exitReason,&exitCat);
1.190 + test(exitType==EExitKill);
1.191 + test(exitReason==KErrNone);
1.192 +
1.193 + // speed test
1.194 +
1.195 + PFV pBranchTest4 = (PFV)pCode;
1.196 + fnLength = (TInt)&BranchTest4End-(TInt)&BranchTest4;
1.197 + //test.Printf(_L("PriProc: Copying %d bytes from 0x%08x to 0x%08x for forward-branching speed test...\n"), fnLength, &BranchTest4, pBranchTest1);
1.198 + Mem::Copy((TAny *)pBranchTest4, (const TAny*)&BranchTest4, fnLength); // copy in the asm test code
1.199 + User::IMB_Range((TAny*)pBranchTest4, fnLength+(TUint8*)pBranchTest4);
1.200 +
1.201 + test.Printf(_L("Speed test running with f(0)...\n"));
1.202 + m=0;
1.203 + begin.HomeTime();
1.204 + FOREVER
1.205 + {
1.206 + m++;
1.207 + pBranchTest4(0);
1.208 + now.HomeTime();
1.209 + if (now.MicroSecondsFrom(begin).Int64()>10000000) // ten seconds ought to be long enough
1.210 + break;
1.211 + }
1.212 + test.Printf(_L("Ending f(0) test. Ran %d times in 10s.\n"), m);
1.213 +
1.214 + test.Printf(_L("PriProc: Starting f(1) run.\n"));
1.215 + q=0;
1.216 + begin.HomeTime();
1.217 + FOREVER
1.218 + {
1.219 + q++;
1.220 + pBranchTest4(1);
1.221 + now.HomeTime();
1.222 + if (now.MicroSecondsFrom(begin).Int64()>10000000) // ten seconds ought to be long enough
1.223 + break;
1.224 + }
1.225 + test.Printf(_L("Ending test loop with f(1). Ran %d times in 10s.\n"), q);
1.226 +
1.227 + test(m-q>m/4); // the difference between m and q should be large, indicating successful prediction
1.228 +
1.229 + c.Close();
1.230 +
1.231 + test.End();
1.232 + return 0;
1.233 + }
1.234 +#else
1.235 +GLREF_C TInt E32Main()
1.236 + {
1.237 + return 0;
1.238 + }
1.239 +#endif