Update contrib.
1 // Copyright (c) 1995-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\mmu\t_btb.cpp
18 //! @SYMTestCaseID KBASE/T_BTB
20 //! @SYMTestCaseDesc Make sure processes can't interfere with each other via the BTB. Make sure the BTB is turned on.
22 //! @SYMTestActions Make concurent processes with code areas and thrash them.
23 //! @SYMTestExpectedResults They shouldn't interfere. The BTB should be enabled.
24 //! @SYMTestPriority Low
25 //! @SYMTestStatus Defined
32 extern TInt BranchTest1();
33 extern TInt BranchTest2();
34 extern TInt BranchTest3();
35 void BranchTest4(TInt);
36 extern void BranchTest1End();
37 extern void BranchTest2End();
38 extern void BranchTest3End();
39 extern void BranchTest4End();
41 typedef TInt (*PFI)(void);
42 typedef void (*PFV)(TInt);
44 void SecondaryProcess(const TDesC& aCmd, RTest& test)
46 test.Start(_L("Secondary Process"));
49 TInt r=lex.Val(addr,EHex);
51 test.Printf(_L("Primary process says: RAM code at %08x\n"),addr);
53 r=UserHal::PageSizeInBytes(pageSize);
56 r=c.CreateLocalCode(pageSize,0x100000);
58 PFI pBranchTest2=(PFI)c.Base();
59 test.Printf(_L("Secondary test loop function at %08x\n"),pBranchTest2);
61 test((TUint32)pBranchTest2==addr);
63 TInt fnLength = (TInt)&BranchTest2End-(TInt)&BranchTest2;
65 test.Printf(_L("SecProc: Copying %d bytes from %08x...\n"), (TInt)&BranchTest2End-(TInt)&BranchTest2, (TAny*)&BranchTest2 );
66 Mem::Copy((TAny*)pBranchTest2, (TAny*)&BranchTest2, fnLength);
67 User::IMB_Range((TAny*)pBranchTest2, fnLength+(TUint8*)pBranchTest2);
72 test.Printf(_L("Running secondary loop...\n"));
84 if (now.MicroSecondsFrom(begin).Int64()>20000000) // ten seconds for each test ought to be long enough
87 test.Printf(_L("Ending secondary loop.\n"));
93 GLREF_C TInt E32Main()
95 RTest test(_L("T_BTB"));
99 User::CommandLine(cmd);
100 if (cmd.Length()!=0) // if we get a command line, we're the secondary process
102 SecondaryProcess(cmd,test);
106 test.Start(_L("Create primary process code chunk"));
108 TInt r=UserHal::PageSizeInBytes(pageSize);
112 r=c.CreateLocalCode(pageSize,0x100000);
114 TUint8* pCode=c.Base();
115 test.Printf(_L("Primary process code chunk at %08x\n"),pCode);
117 // Spawn a secondary process
120 TBuf<16> codeBaseHex;
121 codeBaseHex.Format(_L("%08x"),pCode);
122 r=p.Create(RProcess().FileName(),codeBaseHex);
129 TInt n=0, m=0, q=0, fnLength;
131 PFI pBranchTest1=(PFI)pCode;
132 test.Printf(_L("Primary test loop function at %08x\n"),pBranchTest1);
134 fnLength = (TInt)&BranchTest1End-(TInt)&BranchTest1;
136 //test.Printf(_L("PriProc: Copying %d bytes from 0x%08x to 0x%08x for forward-branching test...\n"), fnLength, &BranchTest1, pBranchTest1);
137 Mem::Copy((TAny *)pBranchTest1, (const TAny*)&BranchTest1, fnLength); // copy in the asm test code
138 User::IMB_Range((TAny*)pBranchTest1, fnLength+(TUint8*)pBranchTest1);
140 test.Printf(_L("Running primary loop...\n"));
149 if (now.MicroSecondsFrom(begin).Int64()>10000000) // ten seconds ought to be long enough
153 test.Printf(_L("Ending primary loop. Ran %d times in 10s.\n"), m);
155 // run the second test
157 PFI pBranchTest3=(PFI)pCode;
159 fnLength = (TInt)&BranchTest3End-(TInt)&BranchTest3;
160 //test.Printf(_L("PriProc: Copying %d bytes from 0x%08x to 0x%08x for back-branching test...\n"), fnLength, &BranchTest3, pBranchTest3);
161 Mem::Copy((TAny *)pBranchTest3, (const TAny*)&BranchTest3, fnLength); // copy in the asm test code
162 User::IMB_Range((TAny*)pBranchTest3, fnLength+(TUint8*)pBranchTest3);
164 test.Printf(_L("PriProc: Starting back-branch test loop.\n"));
174 if (now.MicroSecondsFrom(begin).Int64()>10000000) // ten seconds ought to be long enough
178 test.Printf(_L("Ending primary back-branching loop. Ran %d times in 10s.\n"), m);
181 User::WaitForRequest(s);
182 TInt exitType=p.ExitType();
183 TInt exitReason=p.ExitReason();
184 TExitCategoryName exitCat=p.ExitCategory();
186 test.Printf(_L("SecProc: %d,%d,%S\n"),exitType,exitReason,&exitCat);
187 test(exitType==EExitKill);
188 test(exitReason==KErrNone);
192 PFV pBranchTest4 = (PFV)pCode;
193 fnLength = (TInt)&BranchTest4End-(TInt)&BranchTest4;
194 //test.Printf(_L("PriProc: Copying %d bytes from 0x%08x to 0x%08x for forward-branching speed test...\n"), fnLength, &BranchTest4, pBranchTest1);
195 Mem::Copy((TAny *)pBranchTest4, (const TAny*)&BranchTest4, fnLength); // copy in the asm test code
196 User::IMB_Range((TAny*)pBranchTest4, fnLength+(TUint8*)pBranchTest4);
198 test.Printf(_L("Speed test running with f(0)...\n"));
206 if (now.MicroSecondsFrom(begin).Int64()>10000000) // ten seconds ought to be long enough
209 test.Printf(_L("Ending f(0) test. Ran %d times in 10s.\n"), m);
211 test.Printf(_L("PriProc: Starting f(1) run.\n"));
219 if (now.MicroSecondsFrom(begin).Int64()>10000000) // ten seconds ought to be long enough
222 test.Printf(_L("Ending test loop with f(1). Ran %d times in 10s.\n"), q);
224 test(m-q>m/4); // the difference between m and q should be large, indicating successful prediction
232 GLREF_C TInt E32Main()