Update contrib.
1 // Copyright (c) 2005-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\debug\t_btrace.cpp
16 // Tests generation of traces using the BTrace APIs
17 // and captuirng of these by BTRACE.LDD and BTRACEC.DLL.
48 #define __E32TEST_EXTENSION__
52 #include <e32def_private.h>
54 #include "../../../kernel/eka/include/d32btrace.h"
55 #include "../../../kernel/eka/include/e32btrace.h"
58 #define __TRACE_LINE__() test.Printf(_L("%d\n"),__LINE__)
60 RTest test(_L("T_BTRACE"));
62 TUint BaseSize; // Size of a standard test trace with no data
65 RBTraceTest TraceTest;
67 TInt ContextOffset(const TUint8* aData)
69 TInt size = 4; // header size
70 if(aData[BTrace::EFlagsIndex]&BTrace::EHeader2Present)
72 if(aData[BTrace::EFlagsIndex]&BTrace::ETimestampPresent)
74 if(aData[BTrace::EFlagsIndex]&BTrace::ETimestamp2Present)
80 TInt ExtraSize(const TUint8* aData)
82 TInt size = ContextOffset(aData);
83 if(aData[BTrace::EFlagsIndex]&BTrace::EContextIdPresent)
85 if(aData[BTrace::EFlagsIndex]&BTrace::EPcPresent)
87 if(aData[BTrace::EFlagsIndex]&BTrace::EExtraPresent)
93 TUint32* Body(const TUint8* aData)
95 return (TUint32*)(aData+ExtraSize(aData));
99 TPtrC8 Text(const TUint8* aData)
101 TInt size = aData[BTrace::ESizeIndex];
102 TInt extra = ExtraSize(aData);
103 extra += 8; // skip past first 2 32bit args
105 return TPtrC8(aData+extra,size);
109 const TUint KTest1SubCategory = 0x81;
110 const TUint KTest2SubCategory = 0xc3;
112 TUint8 KTestTrace1[KMaxBTraceRecordSize*2] = { BTrace::ETest1, KTest1SubCategory };
113 TUint8 KTestTrace2[KMaxBTraceRecordSize*2] = { BTrace::ETest2, KTest2SubCategory };
114 TUint32 BigFilter2[KNumBTraceFilterTestUids];
116 void Trace1(TInt aSize, TInt aDelay=0)
118 test_KErrNone(TraceTest.Trace(0,KTestTrace1,aSize,aDelay));
121 void Trace2(TInt aSize, TInt aDelay=0)
123 test_KErrNone(TraceTest.Trace(0,KTestTrace2,aSize,aDelay));
126 TBool CheckTrace1(TUint8* aData, TInt aSize, TInt aSubCategory=KTest1SubCategory)
128 if(((aData[BTrace::ESizeIndex]+3)&~3)!=aSize)
130 if(aData[BTrace::ECategoryIndex]!=BTrace::ETest1)
132 if(aData[BTrace::ESubCategoryIndex]!=aSubCategory)
134 TInt extra = ExtraSize(aData);
135 aSize = aData[BTrace::ESizeIndex]-extra;
139 if(((TUint8*)KTestTrace1)[4+aSize]!=aData[aSize])
145 TBool CheckTrace2(TUint8* aData, TInt aSize, TInt aSubCategory=KTest2SubCategory)
147 if(((aData[BTrace::ESizeIndex]+3)&~3)!=aSize)
149 if(aData[BTrace::ECategoryIndex]!=BTrace::ETest2)
151 if(aData[BTrace::ESubCategoryIndex]!=aSubCategory)
153 TInt extra = ExtraSize(aData);
154 aSize = aData[BTrace::ESizeIndex]-extra;
158 if(((TUint8*)KTestTrace2)[4+aSize]!=aData[aSize])
165 TBool CheckSize(const TUint8* aData, TInt aSize, TInt aExpected)
167 TInt extra = ExtraSize(aData);
168 if(aSize==((extra+aExpected+3)&~3))
172 TInt actual_size = aData[0];
173 if (aSize > actual_size)
175 test.Printf(_L("Trace data:\n"));
177 for (i=0; i<actual_size; ++i)
179 test.Printf(_L(" %02x"), aData[i]);
180 if ((i&15)==15 || i==actual_size-1)
181 test.Printf(_L("\n"));
183 test.Printf(_L("extra=%d aExp=%d aSize=%d\n"), extra, aExpected, aSize);
189 TInt Trace1Sequence = 0;
190 TInt Trace2Sequence = 0;
195 TInt BadTrace(TUint8* aData)
198 TUint8* buffer = Trace.DataChunk().Base();
199 test.Printf(_L("BAD TRACE: data=%x buffer=%x (dataRead=%x,%x)\n"),aData,buffer,TraceData,TraceDataSize);
200 TUint8* bufferEnd = buffer+((TUint32*)buffer)[1]; // TBTraceBuffer.iEnd
201 while(buffer<bufferEnd)
203 RDebug::Printf("%08x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
204 buffer,buffer[0],buffer[1],buffer[2],buffer[3],buffer[4],buffer[5],buffer[6],buffer[7],
205 buffer[8],buffer[9],buffer[10],buffer[11],buffer[12],buffer[13],buffer[14],buffer[15]);
208 buffer = Trace.DataChunk().Base();
209 TInt size = ((TUint32*)buffer)[9];
210 buffer += ((TUint32*)buffer)[8];
211 bufferEnd = buffer+size;
212 test.Printf(_L("copyBuffer=%x\n"),buffer,0);
213 while(buffer<bufferEnd)
215 RDebug::Printf("%08x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
216 buffer,buffer[0],buffer[1],buffer[2],buffer[3],buffer[4],buffer[5],buffer[6],buffer[7],
217 buffer[8],buffer[9],buffer[10],buffer[11],buffer[12],buffer[13],buffer[14],buffer[15]);
223 void CheckTraceData(TUint8* aData, TUint aSize)
226 TraceDataSize = aSize;
227 TUint8* end = aData+aSize;
230 TUint size = (aData[BTrace::ESizeIndex]+3)&~3;
232 test(BadTrace(aData));
233 TUint subCategory = aData[BTrace::ESubCategoryIndex];
234 if(aData[BTrace::EFlagsIndex]&(BTrace::EMissingRecord))
239 if(aData[BTrace::ECategoryIndex]==BTrace::ETest1)
241 if(subCategory!=(TUint)Trace1Sequence && Trace1Sequence!=-1)
243 test.Printf(_L("Sequence wrong %02x!=%02x\n"),subCategory,Trace1Sequence);
244 test(BadTrace(aData));
246 if(!CheckTrace1(aData,size,subCategory))
247 test(BadTrace(aData));
248 Trace1Sequence = subCategory+1;
249 Trace1Sequence &= 0xff;
253 if(aData[BTrace::ECategoryIndex]!=BTrace::ETest2)
254 test(BadTrace(aData));
255 if(subCategory!=(TUint)Trace2Sequence && Trace2Sequence!=-1)
257 test.Printf(_L("Sequence wrong %02x!=%02x\n"),subCategory,Trace2Sequence);
258 test(BadTrace(aData));
260 if(!CheckTrace2(aData,size,subCategory))
261 test(BadTrace(aData));
262 Trace2Sequence = subCategory+1;
263 Trace2Sequence &= 0xff;
265 aData = BTrace::NextRecord(aData);
272 TBuf8<(80+KMaxBTraceDataArray*9/4)*2> buf;
276 TInt dataSize = Trace.GetData(record);
279 TUint8* end = record+dataSize;
282 TUint size = record[BTrace::ESizeIndex];
283 TUint flags = record[BTrace::EFlagsIndex];
284 TUint category = record[BTrace::ECategoryIndex];
285 TUint subCategory = record[BTrace::ESubCategoryIndex];
286 TUint8* data = record+4;
291 if(flags&(BTrace::EHeader2Present))
293 header2 = *(TUint32*)data;
298 if((flags&(BTrace::ETimestampPresent|BTrace::ETimestamp2Present))==(BTrace::ETimestampPresent|BTrace::ETimestamp2Present))
300 buf.AppendFormat(_L8("time:%08x:%08x "),((TUint32*)data)[1],*(TUint32*)data);
304 else if(flags&(BTrace::ETimestampPresent|BTrace::ETimestamp2Present))
306 buf.AppendFormat(_L8("time:%08x "),*(TUint32*)data);
311 if(flags&(BTrace::EContextIdPresent))
313 buf.AppendFormat(_L8("context:%08x "),*(TUint32*)data);
319 buf.AppendFormat(_L8(" "));
322 if(flags&(BTrace::EPcPresent))
324 buf.AppendFormat(_L8("pc:%08x "),*(TUint32*)data);
330 if(flags&(BTrace::EExtraPresent))
332 extra = *(TUint32*)data;
337 TUint32 data0 = (size>0) ? *(TUint32*)(data) : 0;
338 TUint32 data1 = (size>4) ? *(TUint32*)(data+4) : 0;
339 TUint32 data2 = (size>8) ? *(TUint32*)(data+8) : 0;
342 des.Set(data+8,size-8);
345 case BTrace::EKernPrintf:
346 case BTrace::ERDebugPrintf:
347 case BTrace::EPlatsecPrintf:
349 if(category==BTrace::EKernPrintf)
350 buf.Append(_L8("Kern::Printf "));
351 else if(category==BTrace::ERDebugPrintf)
352 buf.Append(_L8("RDebug::Printf "));
354 buf.Append(_L8("PlatSecPrintf "));
355 switch(header2&BTrace::EMultipartFlagMask)
357 case BTrace::EMultipartFirst:
358 buf.AppendFormat(_L8("seq:%d size:%d thread-id:%d \"%S\""),extra,data0,data1,&des);
360 case BTrace::EMultipartMiddle:
361 case BTrace::EMultipartLast:
362 buf.AppendFormat(_L8("seq:%d size:%d offset:%d \"%S\""),extra,data0,data1,&des);
365 des.Set(data+4,size-4);
366 buf.AppendFormat(_L8("thread-id:%d \"%S\""),data0,&des);
372 case BTrace::EThreadIdentification:
376 case BTrace::ENanoThreadCreate:
377 buf.AppendFormat(_L8("NanoThreadCreate thrd:%08x"),data0);
379 case BTrace::ENanoThreadDestroy:
380 buf.AppendFormat(_L8("NanoThreadDestroy thrd:%08x"),data0);
382 case BTrace::EThreadCreate:
383 buf.AppendFormat(_L8("ThreadCreate thrd:%08x proc:%08x name:%S"),data0,data1,&des);
385 case BTrace::EThreadDestroy:
386 buf.AppendFormat(_L8("ThreadDestroy thrd:%08x proc:%08x id:%d"),data0,data1,data2);
388 case BTrace::EThreadName:
389 buf.AppendFormat(_L8("ThreadName thrd:%08x proc:%08x name:%S"),data0,data1,&des);
391 case BTrace::EThreadId:
392 buf.AppendFormat(_L8("ThreadId thrd:%08x proc:%08x id:%d"),data0,data1,data2);
394 case BTrace::EProcessName:
395 buf.AppendFormat(_L8("ProcessName thrd:%08x proc:%08x name:%S"),data0,data1,&des);
401 case BTrace::ECpuUsage:
405 case BTrace::EIrqStart:
406 buf.AppendFormat(_L8("IrqStart"));
408 case BTrace::EIrqEnd:
409 buf.AppendFormat(_L8("IrqEnd"));
411 case BTrace::EFiqStart:
412 buf.AppendFormat(_L8("FiqStart"));
414 case BTrace::EFiqEnd:
415 buf.AppendFormat(_L8("FiqEnd"));
417 case BTrace::EIDFCStart:
418 buf.AppendFormat(_L8("IDFCStart"));
420 case BTrace::EIDFCEnd:
421 buf.AppendFormat(_L8("IDFCEnd"));
423 case BTrace::ENewThreadContext:
424 buf.AppendFormat(_L8("NewThreadContext"));
430 case BTrace::EClientServer:
434 case BTrace::EServerCreate:
435 buf.AppendFormat(_L8("EServerCreate serv:%08x name:%S"),data0,&des);
437 case BTrace::EServerDestroy:
438 buf.AppendFormat(_L8("EServerDestroy serv:%08x"),data0);
440 case BTrace::ESessionAttach:
441 buf.AppendFormat(_L8("ESessionAttach sess:%08x serv:%08x"),data0,data1);
443 case BTrace::ESessionDetach:
444 buf.AppendFormat(_L8("ESessionDetach sess:%08x"),data0);
446 case BTrace::EMessageSend:
447 buf.AppendFormat(_L8("EMessageSend mess:%08x func:%08x sess:%08x"),data0,data1,data2);
449 case BTrace::EMessageReceive:
450 buf.AppendFormat(_L8("EMessageReceive mess:%08x"),data0);
452 case BTrace::EMessageComplete:
453 buf.AppendFormat(_L8("EMessageComplete mess:%08x reas:%08x"),data0,data1);
459 case BTrace::ERequests:
463 case BTrace::ERequestComplete:
464 buf.AppendFormat(_L8("ERequestComplete thrd:%08x stat:%08x resn:%08x"),data0,data1,data2);
472 buf.AppendFormat(_L8("size:%d flags:%02x cat:%d,%d data: "),size,flags,category,subCategory);
473 for(TUint i=0; i<size; i+=4)
474 buf.AppendFormat(_L8("%08x "),*(TUint32*)(data+i));
480 RDebug::RawPrint(buf.Expand());
482 record = BTrace::NextRecord(record);
489 //---------------------------------------------
490 //! @SYMTestCaseID KBASE-T_BTRACE-0058-0059
492 //! @SYMPREQ PREQ1030
493 //! @SYMTestCaseDesc Basic functionality tests which run in both 'sample' and 'free-running' modes.
494 //! @SYMTestActions Test basic functionality provided by the functions:
495 //! RBTrace::SetFilter(), RBTrace::Empty(),
496 //! RBTrace::GetData(), RBTrace::DataUsed(),
497 //! RBTrace::RequestData(), RBTrace::CancelRequestData(),
498 //! RBTrace::BufferSize(), and RBTrace::ResizeBuffer()
499 //! @SYMTestExpectedResults Function produce expected results.
500 //! @SYMTestPriority High
501 //! @SYMTestStatus Implemented
502 //---------------------------------------------
503 void TestBasics(TUint aMode)
505 aMode |= RBTrace::EEnable;
510 test.Start(_L("Check a second Open() fails"));
512 TInt r = dummy.Open();
513 test_Equal(KErrInUse,r);
515 test_Equal(KErrInUse,r);
517 test.Next(_L("Reset trace buffer"));
520 Trace.SetMode(aMode);
522 TUint8* buffer_base = Trace.DataChunk().Base();
523 test.Printf(_L("Buffer base %08x\n"), buffer_base);
525 test.Next(_L("Test SetFilter() and GetData()"));
526 Trace.SetFilter(BTrace::ETest1,0);
527 Trace.SetFilter(BTrace::ETest2,0);
528 size = Trace.GetData(data);
531 size = Trace.GetData(data);
534 size = Trace.GetData(data);
536 Trace.SetFilter(BTrace::ETest1,1);
538 size = Trace.GetData(data);
541 size = Trace.GetData(data);
542 test(CheckSize(data,size,4));
544 test.Printf(_L("BaseSize=%d\n"), BaseSize);
546 test.Next(_L("Test Empty()"));
548 size = Trace.GetData(data);
551 test.Next(_L("Test DataUsed()"));
553 size = Trace.GetData(data);
554 test(CheckSize(data,size,0));
556 size = Trace.GetData(data);
559 test.Next(_L("Test RequestData()"));
563 test_KErrNone(timer.CreateLocal());
565 // immediate notification...
566 Trace.RequestData(s1,0);
567 test_Equal(KRequestPending, s1.Int());
568 timer.After(s2,5*1000000);
570 User::WaitForRequest(s1,s2);
571 test_KErrNone(s1.Int());
573 User::WaitForRequest(s2);
575 // immediate notification with size>n ...
576 Trace.RequestData(s1,BaseSize+8);
577 test_Equal(KRequestPending,s1.Int());
578 timer.After(s2,5*1000000);
580 User::WaitForRequest(s1,s2);
581 test_KErrNone(s1.Int());
583 User::WaitForRequest(s2);
585 size = Trace.GetData(data);
586 test_Compare(size, >= , BaseSize+8);
588 size = Trace.GetData(data);
591 // delayed notification...
592 Trace.RequestData(s1,0);
593 timer.After(s2,5*1000000);
595 test_Equal(KRequestPending,s1.Int());
596 User::WaitForRequest(s1,s2);
597 test_KErrNone(s1.Int());
599 User::WaitForRequest(s2);
600 size = Trace.GetData(data);
601 test(CheckSize(data,size,4));
604 // delayed notification with size>n...
605 Trace.RequestData(s1,BaseSize+8);
607 test_Equal(KRequestPending,s1.Int());
608 timer.After(s2,1000000);
609 User::WaitForRequest(s1,s2);
610 test_KErrNone(s2.Int());
611 timer.After(s2,5*1000000);
613 test_Equal(KRequestPending,s1.Int());
614 User::WaitForRequest(s1,s2);
615 test_KErrNone(s1.Int());
617 User::WaitForRequest(s2);
619 size = Trace.GetData(data);
620 test_Compare(size, >=, BaseSize+8);
622 size = Trace.GetData(data);
625 test.Next(_L("Test RequestData() when data is already available"));
627 Trace.RequestData(s1,0);
628 test_KErrNone(s1.Int());
629 User::WaitForRequest(s1);
630 size = Trace.GetData(data);
631 test(CheckSize(data,size,4));
633 size = Trace.GetData(data);
637 Trace.RequestData(s1,1);
638 test_KErrNone(s1.Int());
639 User::WaitForRequest(s1);
640 size = Trace.GetData(data);
641 test(CheckSize(data,size,4));
643 size = Trace.GetData(data);
646 test.Next(_L("Test RequestData() for ISR disabled traces"));
647 Trace.RequestData(s1,0);
648 test_Equal(KRequestPending,s1.Int());
649 timer.After(s2,5*1000000);
650 TraceTest.Trace(RBTraceTest::EContextIntsOff,KTestTrace1,4);
651 User::WaitForRequest(s1,s2);
652 test_KErrNone(s1.Int());
654 User::WaitForRequest(s2);
655 size = Trace.GetData(data);
656 test(CheckSize(data,size,4));
658 size = Trace.GetData(data);
661 test.Next(_L("Test CancelRequestData()"));
662 Trace.RequestData(s1,0);
663 test_Equal(KRequestPending,s1.Int());
664 Trace.CancelRequestData();
665 User::WaitForRequest(s1);
666 test_Equal(KErrCancel,s1.Int());
668 test.Next(_L("Test trace data contents"));
670 size = Trace.GetData(data);
671 test(CheckSize(data,size,0));
672 test(CheckTrace1(data,size));
673 if(data[BTrace::EFlagsIndex]&BTrace::ETimestampPresent)
674 test.Printf(_L("Timestamps are present\n"));
676 test.Printf(_L("Timestamps are NOT present\n"));
680 size = Trace.GetData(data);
681 test(CheckSize(data,size,4));
682 test(CheckTrace1(data,size));
686 for(i=0; i<=8+(TInt)KMaxBTraceDataArray; i++)
689 size = Trace.GetData(data);
690 test(CheckSize(data,size,i));
691 test(CheckTrace1(data,size));
695 size = Trace.GetData(data);
696 test(data[BTrace::EFlagsIndex]&BTrace::ERecordTruncated);
697 test(CheckSize(data,size,i-1));
698 test(CheckTrace1(data,size));
701 test.Next(_L("Test BufferSize() and ResizeBuffer()"));
702 TInt oldSize = Trace.BufferSize();
704 size = Trace.GetData(data);
705 test(CheckSize(data,size,50));
706 r = Trace.ResizeBuffer(oldSize+0x1000);
708 size = Trace.BufferSize();
709 test_Equal(oldSize+0x1000,size);
710 Trace.SetMode(aMode);
711 size = Trace.GetData(data);
714 size = Trace.GetData(data);
715 test(CheckSize(data,size,40));
717 r = Trace.ResizeBuffer(oldSize);
719 size = Trace.BufferSize();
720 test_Equal(oldSize,size);
728 //---------------------------------------------
729 //! @SYMTestCaseID KBASE-T_BTRACE-0060
731 //! @SYMPREQ PREQ1030
732 //! @SYMTestCaseDesc Test traces generated from user code.
733 //! @SYMTestActions Generate traces using BTrace0, BTrace4, BTrace8, BTrace12,
734 //! and BTraceN macros.
735 //! @SYMTestExpectedResults All trace contents captured by RBTrace match those specified
736 //! at point of trace generation.
737 //! @SYMTestPriority High
738 //! @SYMTestStatus Implemented
739 //---------------------------------------------
740 void TestUserTrace(TUint aMode)
742 aMode |= RBTrace::EEnable;
747 test.Start(_L("Reset trace buffer"));
750 Trace.SetMode(RBTrace::EEnable);
751 Trace.SetFilter(BTrace::ETest1,1);
752 Trace.SetFilter(BTrace::ETest2,0);
754 test.Next(_L("BTrace0"));
755 BTrace0(BTrace::ETest1,KTest1SubCategory);
756 size = Trace.GetData(data);
757 test(CheckSize(data,size,0));
758 test(CheckTrace1(data,size));
761 test.Next(_L("BTrace4"));
762 BTrace4(BTrace::ETest1,KTest1SubCategory,*(TUint32*)(KTestTrace1+4));
763 size = Trace.GetData(data);
764 test(CheckSize(data,size,4));
765 test(CheckTrace1(data,size));
768 test.Next(_L("BTrace8"));
769 BTrace8(BTrace::ETest1,KTest1SubCategory,*(TUint32*)(KTestTrace1+4),*(TUint32*)(KTestTrace1+8));
770 size = Trace.GetData(data);
771 test(CheckSize(data,size,8));
772 test(CheckTrace1(data,size));
775 test.Next(_L("BTrace12"));
776 BTrace12(BTrace::ETest1,KTest1SubCategory,*(TUint32*)(KTestTrace1+4),*(TUint32*)(KTestTrace1+8),*(TUint32*)(KTestTrace1+12));
777 size = Trace.GetData(data);
778 test(CheckSize(data,size,12));
779 test(CheckTrace1(data,size));
782 test.Next(_L("BTraceN"));
784 for(i=8; i<=8+(TInt)KMaxBTraceDataArray; i++)
786 BTraceN(BTrace::ETest1,KTest1SubCategory,*(TUint32*)(KTestTrace1+4),*(TUint32*)(KTestTrace1+8),KTestTrace1+12,i-8);
787 size = Trace.GetData(data);
788 test(CheckSize(data,size,i));
789 test(CheckTrace1(data,size));
792 BTraceN(BTrace::ETest1,KTest1SubCategory,*(TUint32*)(KTestTrace1+4),*(TUint32*)(KTestTrace1+8),KTestTrace1+12,i-8);
793 size = Trace.GetData(data);
794 test(data[BTrace::EFlagsIndex]&BTrace::ERecordTruncated);
795 test(CheckSize(data,size,i-1));
796 test(CheckTrace1(data,size));
803 TBool CompareFilter2(const TUint32* aUids, TInt aNumUids, TInt aGlobalFilter)
805 TUint32* filter2Buffer = (TUint32*)-1; // initialise to invalid value
806 TInt filter2Global = 0x80000000; // initialise to invalid value
807 TInt filter2Size = Trace.Filter2(filter2Buffer,filter2Global);
810 if(filter2Size!=aNumUids)
812 else if(filter2Global!=aGlobalFilter)
814 else if(0!=Mem::Compare((TUint8*)filter2Buffer,filter2Size,(TUint8*)aUids,aNumUids))
817 delete filter2Buffer;
824 test.Start(_L("Get filter2"));
825 TUint32* filter2Buffer = (TUint32*)-1; // initialise to invalid value
826 TInt filter2Global = 0x80000000; // initialise to invalid value
827 TInt filter2Size = Trace.Filter2(filter2Buffer,filter2Global);
828 test_NotNegative(filter2Size);
829 test_Compare(filter2Buffer, != , (TUint32*)-1);
830 test_Compare(filter2Global, != , -1);
831 test(CompareFilter2(filter2Buffer,filter2Size,filter2Global));
832 Trace.SetFilter(BTrace::ETest1,1);
835 test.Next(_L("Clear filter2"));
836 r = Trace.SetFilter2((TUint32*)0,0);
839 test(CompareFilter2(0,0,0));
842 test.Next(_L("Check SetFilter2's 'New' fails gracefully"));
845 r = Trace.SetFilter2(KBTraceFilterTestUid1,1);
846 test_Equal(KErrNoMemory, r);
851 test.Next(_L("Test set and clear single uid"));
852 r = Trace.SetFilter2(KBTraceFilterTestUid1,0);
854 test(CompareFilter2(0,0,0));
855 r = Trace.SetFilter2(KBTraceFilterTestUid1,1);
857 test(CompareFilter2(&KBTraceFilterTestUid1,1,-1));
858 r = Trace.SetFilter2(KBTraceFilterTestUid1,0);
860 test(CompareFilter2(0,0,0));
862 test.Next(_L("Test set multiple uid API"));
863 r = Trace.SetFilter2(&KBTraceFilterTestUid1,1);
865 test(CompareFilter2(&KBTraceFilterTestUid1,1,-1));
866 r = Trace.SetFilter2(KBTraceFilterTestUid1,0);
868 test(CompareFilter2(0,0,0));
870 test.Next(_L("Test set and clear uids with lots of permutations"));
871 TInt itterations = 0;
872 const TInt maxUids = 5;
873 TInt permute[maxUids] = {0};
875 RArray<TUint32> sortedArray(maxUids);
876 RArray<TUint32> array(maxUids);
877 for(numUids=1; numUids<=maxUids; ++numUids)
884 __BREAKPOINT(); // debuging breakpoint for a specific itteration
886 // make arrays of uids
890 for(i=0; i<numUids; ++i)
892 sortedArray.InsertInUnsignedKeyOrder(KBTraceFilterTestUid+permute[i]);
893 array.Append(KBTraceFilterTestUid+permute[i]);
896 // set filter using single uid api...
898 for(i=0; i<numUids; ++i)
900 r = Trace.SetFilter2(KBTraceFilterTestUid+permute[i],1);
903 test(CompareFilter2(&sortedArray[0],sortedArray.Count(),-1));
905 // set filter using multiple uid api...
907 r = Trace.SetFilter2(&array[0],array.Count());
909 test(CompareFilter2(&sortedArray[0],sortedArray.Count(),-1));
912 for(i=0; i<numUids; ++i)
914 TUint32 removedUid = KBTraceFilterTestUid+permute[i];
915 TBool removed = EFalse;
916 r = sortedArray.FindInUnsignedKeyOrder(removedUid);
919 test(BTrace::CheckFilter2(BTrace::ETest1,removedUid));
920 sortedArray.Remove(r);
923 r = Trace.SetFilter2(removedUid,0);
927 test(!BTrace::CheckFilter2(BTrace::ETest1,removedUid));
929 r = sortedArray.Count();
931 test(CompareFilter2(&sortedArray[0],r,-1));
934 test(CompareFilter2(0,0,0));
939 // make next permutation
941 while(p<numUids && ++permute[p] == numUids)
947 test.Next(_L("Test global filter"));
949 test(CompareFilter2(0,0,0));
951 test(CompareFilter2(0,0,1));
952 r = Trace.SetFilter2(KBTraceFilterTestUid1,1);
954 test(CompareFilter2(0,0,1));
955 r = Trace.SetFilter2(KBTraceFilterTestUid1,0);
956 test_Equal(KErrNotSupported,r);
957 test(CompareFilter2(0,0,1));
958 r = Trace.SetFilter2(&KBTraceFilterTestUid1,1);
960 test(CompareFilter2(&KBTraceFilterTestUid1,1,-1));
962 test.Next(_L("Restore filter2"));
963 r = Trace.SetFilter2(filter2Buffer,filter2Size);
965 Trace.SetFilter2(filter2Global);
966 Trace.SetFilter(BTrace::ETest1,0);
967 delete filter2Buffer;
972 TUint32 ThisTraceContextId;
974 void TestTrace1(TUint aType,TInt aSize)
976 if(!(aType&RBTraceTest::EUserTrace))
978 // use driver to create a kernel trace...
979 TraceTest.Trace(aType,KTestTrace1,aSize);
984 TUint32* data = (TUint32*)KTestTrace1;
985 BTrace::TCategory category = BTrace::ETest1;
986 TUint subCategory = KTest1SubCategory;
987 TUint type = aType&0xff;
988 TBool bigTrace = aType&RBTraceTest::EBigTrace;
989 TBool filter2Trace = aType&RBTraceTest::EFilter2Trace;
993 if(type==BTrace::EPcPresent)
997 BTracePcBig(category,subCategory,data[1],data+2,size-4);
998 BTracePcBig(category,subCategory,data[1],data+2,size-4);
1002 BTracePc0(category,subCategory);
1003 BTracePc0(category,subCategory);
1007 BTracePc4(category,subCategory,data[1]);
1008 BTracePc4(category,subCategory,data[1]);
1012 BTracePc8(category,subCategory,data[1],data[2]);
1013 BTracePc8(category,subCategory,data[1],data[2]);
1017 BTracePcN(category,subCategory,data[1],data[2],data+3,size-8);
1018 BTracePcN(category,subCategory,data[1],data[2],data+3,size-8);
1021 else if(type==BTrace::EContextIdPresent)
1025 BTraceContextBig(category,subCategory,data[1],data+2,size-4);
1026 BTraceContextBig(category,subCategory,data[1],data+2,size-4);
1030 BTraceContext0(category,subCategory);
1031 BTraceContext0(category,subCategory);
1035 BTraceContext4(category,subCategory,data[1]);
1036 BTraceContext4(category,subCategory,data[1]);
1040 BTraceContext8(category,subCategory,data[1],data[2]);
1041 BTraceContext8(category,subCategory,data[1],data[2]);
1045 BTraceContextN(category,subCategory,data[1],data[2],data+3,size-8);
1046 BTraceContextN(category,subCategory,data[1],data[2],data+3,size-8);
1049 else if(type==BTrace::EContextIdPresent+BTrace::EPcPresent)
1053 BTraceContextPcBig(category,subCategory,data[1],data+2,size-4);
1054 BTraceContextPcBig(category,subCategory,data[1],data+2,size-4);
1058 BTraceContextPc0(category,subCategory);
1059 BTraceContextPc0(category,subCategory);
1063 BTraceContextPc4(category,subCategory,data[1]);
1064 BTraceContextPc4(category,subCategory,data[1]);
1068 BTraceContextPc8(category,subCategory,data[1],data[2]);
1069 BTraceContextPc8(category,subCategory,data[1],data[2]);
1073 BTraceContextPcN(category,subCategory,data[1],data[2],data+3,size-8);
1074 BTraceContextPcN(category,subCategory,data[1],data[2],data+3,size-8);
1080 BTraceBig(category,subCategory,data[1],data+2,size-4);
1082 BTrace0(category,subCategory);
1084 BTrace4(category,subCategory,data[1]);
1086 BTrace8(category,subCategory,data[1],data[2]);
1088 BTraceN(category,subCategory,data[1],data[2],data+3,size-8);
1093 if(type==BTrace::EPcPresent)
1097 BTraceFilteredPcBig(category,subCategory,data[1],data+2,size-4);
1098 BTraceFilteredPcBig(category,subCategory,data[1],data+2,size-4);
1106 BTraceFilteredPc4(category,subCategory,data[1]);
1107 BTraceFilteredPc4(category,subCategory,data[1]);
1111 BTraceFilteredPc8(category,subCategory,data[1],data[2]);
1112 BTraceFilteredPc8(category,subCategory,data[1],data[2]);
1116 BTraceFilteredPcN(category,subCategory,data[1],data[2],data+3,size-8);
1117 BTraceFilteredPcN(category,subCategory,data[1],data[2],data+3,size-8);
1120 else if(type==BTrace::EContextIdPresent)
1124 BTraceFilteredContextBig(category,subCategory,data[1],data+2,size-4);
1125 BTraceFilteredContextBig(category,subCategory,data[1],data+2,size-4);
1133 BTraceFilteredContext4(category,subCategory,data[1]);
1134 BTraceFilteredContext4(category,subCategory,data[1]);
1138 BTraceFilteredContext8(category,subCategory,data[1],data[2]);
1139 BTraceFilteredContext8(category,subCategory,data[1],data[2]);
1143 BTraceFilteredContextN(category,subCategory,data[1],data[2],data+3,size-8);
1144 BTraceFilteredContextN(category,subCategory,data[1],data[2],data+3,size-8);
1147 else if(type==BTrace::EContextIdPresent+BTrace::EPcPresent)
1151 BTraceFilteredContextPcBig(category,subCategory,data[1],data+2,size-4);
1152 BTraceFilteredContextPcBig(category,subCategory,data[1],data+2,size-4);
1160 BTraceFilteredContextPc4(category,subCategory,data[1]);
1161 BTraceFilteredContextPc4(category,subCategory,data[1]);
1165 BTraceFilteredContextPc8(category,subCategory,data[1],data[2]);
1166 BTraceFilteredContextPc8(category,subCategory,data[1],data[2]);
1170 BTraceFilteredContextPcN(category,subCategory,data[1],data[2],data+3,size-8);
1171 BTraceFilteredContextPcN(category,subCategory,data[1],data[2],data+3,size-8);
1177 BTraceFilteredBig(category,subCategory,data[1],data+2,size-4);
1183 BTraceFiltered4(category,subCategory,data[1]);
1185 BTraceFiltered8(category,subCategory,data[1],data[2]);
1187 BTraceFilteredN(category,subCategory,data[1],data[2],data+3,size-8);
1194 //---------------------------------------------
1195 //! @SYMTestCaseID KBASE-T_BTRACE-0062-0063
1197 //! @SYMPREQ PREQ1030
1198 //! @SYMTestCaseDesc Test traces which specify thread context and/or program counter values.
1199 //! @SYMTestActions Generate traces from user and kernel code using the BTracePcX,
1200 //! BTraceContextX and BTraceContextPcX macros. Kernel traces are additionaly
1201 //! generated in ISR and IDFC context.
1202 //! @SYMTestExpectedResults All trace contents captured by RBTrace match those specified
1203 //! at point of trace generation. Also, where appropriate, PC and/or Context ID values
1204 //! are present and correct.
1205 //! @SYMTestPriority High
1206 //! @SYMTestStatus Implemented
1207 //---------------------------------------------
1208 void TestTrace(TBool aUserTrace, TBool aFilter2)
1210 test.Start(_L("Reset trace buffer"));
1211 TInt oldSize = Trace.BufferSize();
1212 TInt r = Trace.ResizeBuffer(0x100000);
1214 Trace.SetMode(RBTrace::EEnable);
1216 // dummy trace do get current thread context id
1217 Trace.SetFilter(BTrace::ETest1,0);
1218 ThisTraceContextId = TraceTest.Trace(BTrace::EContextIdPresent,KTestTrace1,0);
1220 // create a test filter...
1221 TInt extraFlags = 0;
1223 extraFlags |= RBTraceTest::EUserTrace;
1227 extraFlags |= RBTraceTest::EFilter2Trace;
1232 for(filterMode=0; filterMode<(aFilter2?6:2); ++filterMode)
1236 Trace.SetFilter(BTrace::ETest1,1);
1237 Trace.SetFilter2(BigFilter2,KNumBTraceFilterTestUids);
1238 if(filterMode==0 || filterMode==2)
1239 Trace.SetFilter(BTrace::ETest1,0); // disable in primary filter
1240 if(filterMode==0 || filterMode==1)
1241 Trace.SetFilter2(KBTraceFilterTestUid1,0); // disable in secondary filter
1243 Trace.SetFilter2(0); // disable entire secondary filter
1245 Trace.SetFilter2(1); // enable entire secondary filter
1247 // expectTrace is true if we expect trace to be output...
1248 TBool expectTrace = aFilter2 ? (filterMode==3 || filterMode==5) : filterMode&1;
1252 case 0: test.Next(_L("Test with primary filter OFF, secondary filter OFF")); break;
1253 case 1: test.Next(_L("Test with primary filter ON, secondary filter OFF")); break;
1254 case 2: test.Next(_L("Test with primary filter OFF, secondary filter ON")); break;
1255 case 3: test.Next(_L("Test with primary filter ON, secondary filter ON")); break;
1256 case 4: test.Next(_L("Test with primary filter ON, global secondary filter OFF")); break;
1257 case 5: test.Next(_L("Test with primary filter ON, global secondary filter ON")); break;
1260 test.Start(_L("Traces without special context"));
1262 for(i=minSize; i<=8+(TInt)KMaxBTraceDataArray; i++)
1264 TestTrace1(extraFlags,i);
1268 size = Trace.GetData(data);
1275 test(CheckSize(data,size,i));
1276 test(CheckTrace1(data,size,KTest1SubCategory));
1278 test(!(data[BTrace::EFlagsIndex]&BTrace::EContextIdPresent));
1279 test(!(data[BTrace::EFlagsIndex]&BTrace::EPcPresent));
1284 test.Next(_L("Traces with PC"));
1285 for(i=minSize; i<=8+(TInt)KMaxBTraceDataArray; i++)
1287 TestTrace1(BTrace::EPcPresent|extraFlags,i);
1292 size=Trace.GetData(data);
1301 test(CheckSize(data,size,i));
1302 test(CheckTrace1(data,size,KTest1SubCategory));
1304 test(CheckSize(data2,size,i));
1305 test(CheckTrace1(data2,size,KTest1SubCategory));
1307 test(!(data[BTrace::EFlagsIndex]&BTrace::EContextIdPresent));
1308 test((data[BTrace::EFlagsIndex]&BTrace::EPcPresent));
1310 TInt offset = ContextOffset(data);
1311 test_Compare( ((TUint32*)(data+offset))[0], != ,((TUint32*)(data2+offset))[0]);
1316 test.Next(_L("Traces with Context ID"));
1317 for(i=minSize; i<=8+(TInt)KMaxBTraceDataArray; i++)
1319 TestTrace1(BTrace::EContextIdPresent|extraFlags,i);
1324 size=Trace.GetData(data);
1333 test(CheckSize(data,size,i));
1334 test(CheckTrace1(data,size,KTest1SubCategory));
1336 test(CheckSize(data2,size,i));
1337 test(CheckTrace1(data2,size,KTest1SubCategory));
1339 test((data[BTrace::EFlagsIndex]&BTrace::EContextIdPresent));
1340 test(!(data[BTrace::EFlagsIndex]&BTrace::EPcPresent));
1342 TUint offset = ContextOffset(data);
1343 test_Equal(ThisTraceContextId, ((TUint32*)(data+offset))[0]);
1344 test_Equal(ThisTraceContextId, ((TUint32*)(data2+offset))[0]);
1348 test.Next(_L("Traces with Context ID and PC"));
1349 for(i=minSize; i<=8+(TInt)KMaxBTraceDataArray; i++)
1351 TestTrace1(BTrace::EContextIdPresent|BTrace::EPcPresent|extraFlags,i);
1356 size=Trace.GetData(data);
1365 test(CheckSize(data,size,i));
1366 test(CheckTrace1(data,size,KTest1SubCategory));
1368 test(CheckSize(data2,size,i));
1369 test(CheckTrace1(data2,size,KTest1SubCategory));
1371 test((data[BTrace::EFlagsIndex]&BTrace::EContextIdPresent));
1372 test((data[BTrace::EFlagsIndex]&BTrace::EPcPresent));
1374 TUint offset = ContextOffset(data);
1376 test_Equal(ThisTraceContextId, ((TUint32*)(data+offset))[0]);
1377 test_Equal(ThisTraceContextId, ((TUint32*)(data2+offset))[0]);
1378 test_Compare( ((TUint32*)(data+offset))[1], != ,((TUint32*)(data2+offset))[1]);
1385 test.Next(_L("Traces with Context ID in ISR mode"));
1386 for(i=minSize; i<=8+(TInt)KMaxBTraceDataArray; i++)
1388 TraceTest.Trace(BTrace::EContextIdPresent|RBTraceTest::EContextIsr|extraFlags,KTestTrace1,i);
1393 size=Trace.GetData(data);
1402 test(CheckSize(data,size,i));
1403 test(CheckTrace1(data,size,KTest1SubCategory));
1405 test(CheckSize(data2,size,i));
1406 test(CheckTrace1(data2,size,KTest1SubCategory));
1408 test((data[BTrace::EFlagsIndex]&BTrace::EContextIdPresent));
1409 test(!(data[BTrace::EFlagsIndex]&BTrace::EPcPresent));
1411 TUint offset = ContextOffset(data);
1412 test( ((TUint32*)(data+offset))[0] == 2 );
1413 test( ((TUint32*)(data2+offset))[0] == 2 );
1418 test.Next(_L("Traces with Context ID in IDFC mode"));
1419 for(i=minSize; i<=8+(TInt)KMaxBTraceDataArray; i++)
1421 TraceTest.Trace(BTrace::EContextIdPresent|RBTraceTest::EContextIDFC|extraFlags,KTestTrace1,i);
1426 size=Trace.GetData(data);
1435 test(CheckSize(data,size,i));
1436 test(CheckTrace1(data,size,KTest1SubCategory));
1438 test(CheckSize(data2,size,i));
1439 test(CheckTrace1(data2,size,KTest1SubCategory));
1441 test((data[BTrace::EFlagsIndex]&BTrace::EContextIdPresent));
1442 test(!(data[BTrace::EFlagsIndex]&BTrace::EPcPresent));
1444 TUint offset = ContextOffset(data);
1445 test( ((TUint32*)(data+offset))[0] == 3 );
1446 test( ((TUint32*)(data2+offset))[0] == 3 );
1452 r = Trace.ResizeBuffer(0x100000); // avoid buffer wrap problems
1454 Trace.SetMode(RBTrace::EEnable);
1457 test.Next(_L("Restore buffer"));
1458 r = Trace.ResizeBuffer(oldSize);
1460 Trace.SetFilter2(0);
1466 TUint32 BigTraceId = 0;
1468 TBool BigTraceFirst = 0;
1469 TBool BigTraceMiddle = 0;
1470 TBool BigTraceEnd = 0;
1472 void BigTraceBeginTest()
1479 TBool BigTraceEndTest()
1481 return BigTraceFirst&&BigTraceMiddle&&BigTraceEnd;
1484 TBool DoCheckBigTrace1(TUint8*& aData, TUint32 aOutSize, TUint32& aOffset, TUint32 aExtraIds = 0)
1486 TUint32* ptr = (TUint32*)aData;
1487 if(aData[BTrace::ECategoryIndex]!=BTrace::ETest1)
1489 if(aData[BTrace::ESubCategoryIndex]!=KTest1SubCategory)
1491 // TUint32 header = *ptr++;
1494 if(aData[BTrace::EFlagsIndex]&BTrace::ERecordTruncated)
1497 if(!(aData[BTrace::EFlagsIndex]&BTrace::EHeader2Present))
1499 TUint32 header2 = *ptr++;
1500 if(aData[BTrace::EFlagsIndex]&BTrace::ETimestampPresent)
1502 if(aData[BTrace::EFlagsIndex]&BTrace::ETimestamp2Present)
1505 if(aData[BTrace::EFlagsIndex]&BTrace::EContextIdPresent)
1507 if(aData[BTrace::EFlagsIndex]&BTrace::EPcPresent)
1510 if(!(aData[BTrace::EFlagsIndex]&BTrace::EExtraPresent))
1514 if(*ptr++ != aOutSize)
1517 if(aOffset && *ptr++ != aOffset)
1520 TInt size = aData[BTrace::ESizeIndex]-((TInt)ptr-(TInt)aData);
1521 TUint8* data = (TUint8*)ptr;
1522 TUint8* out = (TUint8*)KTestTrace1+4+aOffset;
1526 if((header2&BTrace::EMultipartFlagMask) != BTrace::EMultipartFirst)
1529 aOffset += size-4-aExtraIds;
1530 BigTraceFirst = ETrue;
1537 out += 4 + aExtraIds;
1538 if(aOffset==aOutSize)
1540 if((header2&BTrace::EMultipartFlagMask) != BTrace::EMultipartLast)
1542 BigTraceEnd = ETrue;
1546 if((header2&BTrace::EMultipartFlagMask) != BTrace::EMultipartMiddle)
1548 BigTraceMiddle = ETrue;
1551 if(aOffset>aOutSize)
1564 TBool CheckBigTrace1(TUint8* aData, TInt aSize, TInt aOutSize, TInt aSubCategory=KTest1SubCategory, TUint32 aExtraIds = 0)
1566 if(aOutSize<=(TInt)KMaxBTraceDataArray+8)
1568 if(!CheckSize(aData,aSize,aOutSize))
1570 if(!CheckTrace1(aData,aSize,aSubCategory))
1575 TUint8* end = aData+aSize;
1576 aOutSize -= 4 + aExtraIds; // first 4 bytes of trace are always present, and don't count towards 'size' of multipart trace
1577 TUint32 aOffset = 0;
1578 while(aOffset<TUint32(aOutSize))
1579 if(!DoCheckBigTrace1(aData,aOutSize,aOffset,aExtraIds))
1581 aData = (TUint8*)(((TInt)aData+3)&~3);
1589 //---------------------------------------------
1590 //! @SYMTestCaseID KBASE-T_BTRACE-0061
1592 //! @SYMPREQ PREQ1030
1593 //! @SYMTestCaseDesc Test Big (mutipart) kernel traces.
1594 //! @SYMTestActions Generate traces from kernel code using the BTraceBig,
1595 //! BTracePcBig, BTraceContextBig and BTraceContextPcBig macros.
1596 //! @SYMTestExpectedResults Traces where broken down into mutiple parts and
1597 //! all trace contents captured by RBTrace matched those specified
1598 //! at point of trace generation. Also, where appropriate, PC and/or
1599 //! Context ID values are present and correct.
1600 //! @SYMTestPriority High
1601 //! @SYMTestStatus Implemented
1602 //---------------------------------------------
1603 void TestBig(TBool aUserTrace, TBool aFilter2)
1605 test.Start(_L("Reset trace buffer"));
1606 TInt oldSize = Trace.BufferSize();
1607 TInt r = Trace.ResizeBuffer(0x100000);
1609 Trace.SetMode(RBTrace::EEnable);
1611 // dummy trace do get current thread context id
1612 Trace.SetFilter(BTrace::ETest1,0);
1613 ThisTraceContextId = TraceTest.Trace(BTrace::EContextIdPresent,KTestTrace1,0);
1615 // create a test filter...
1616 TInt extraFlags = 0;
1618 extraFlags |= RBTraceTest::EUserTrace;
1622 extraFlags |= RBTraceTest::EFilter2Trace;
1627 for(filterMode=0; filterMode<(aFilter2?6:2); ++filterMode)
1631 Trace.SetFilter(BTrace::ETest1,1);
1632 Trace.SetFilter2(BigFilter2,KNumBTraceFilterTestUids);
1633 if(filterMode==0 || filterMode==2)
1634 Trace.SetFilter(BTrace::ETest1,0); // disable in primary filter
1635 if(filterMode==0 || filterMode==1)
1636 Trace.SetFilter2(KBTraceFilterTestUid1,0); // disable in secondary filter
1638 Trace.SetFilter2(0); // disable entire secondary filter
1640 Trace.SetFilter2(1); // enable entire secondary filter
1642 // expectTrace is true if we expect trace to be output...
1643 TBool expectTrace = aFilter2 ? (filterMode==3 || filterMode==5) : filterMode&1;
1647 case 0: test.Next(_L("Test with primary filter OFF, secondary filter OFF")); break;
1648 case 1: test.Next(_L("Test with primary filter ON, secondary filter OFF")); break;
1649 case 2: test.Next(_L("Test with primary filter OFF, secondary filter ON")); break;
1650 case 3: test.Next(_L("Test with primary filter ON, secondary filter ON")); break;
1651 case 4: test.Next(_L("Test with primary filter ON, global secondary filter OFF")); break;
1652 case 5: test.Next(_L("Test with primary filter ON, global secondary filter ON")); break;
1655 test.Start(_L("Big traces without special context"));
1657 for(i=minSize; i<=(TInt)sizeof(KTestTrace1)-4; i++)
1659 TestTrace1(RBTraceTest::EBigTrace|extraFlags,i);
1663 size = Trace.GetData(data);
1669 test(CheckBigTrace1(data,size,i,KTest1SubCategory));
1673 test.Next(_L("Big traces with PC"));
1674 BigTraceBeginTest();
1675 for(i=minSize; i<=(TInt)sizeof(KTestTrace1)-4; i++)
1677 TraceTest.Trace(RBTraceTest::EBigTrace|BTrace::EPcPresent|extraFlags,KTestTrace1,i);
1682 size=Trace.GetData(data);
1691 test(CheckBigTrace1(data,size,i,KTest1SubCategory));
1692 test(CheckBigTrace1(data2,size,i,KTest1SubCategory));
1694 test(!(data[BTrace::EFlagsIndex]&BTrace::EContextIdPresent));
1695 test((data[BTrace::EFlagsIndex]&BTrace::EPcPresent));
1697 TInt offset = ContextOffset(data);
1698 test( ((TUint32*)(data+offset))[0] != ((TUint32*)(data2+offset))[0]);
1702 test_Equal(expectTrace,BigTraceEndTest()); // check we actually got mutilpart traces
1704 test.Next(_L("Big traces with Context ID"));
1705 BigTraceBeginTest();
1706 for(i=minSize; i<=(TInt)sizeof(KTestTrace1)-4; i++)
1708 TestTrace1(RBTraceTest::EBigTrace|BTrace::EContextIdPresent|extraFlags,i);
1713 size=Trace.GetData(data);
1722 test(CheckBigTrace1(data,size,i,KTest1SubCategory));
1723 test(CheckBigTrace1(data2,size,i,KTest1SubCategory));
1725 test((data[BTrace::EFlagsIndex]&BTrace::EContextIdPresent));
1726 test(!(data[BTrace::EFlagsIndex]&BTrace::EPcPresent));
1728 TUint offset = ContextOffset(data);
1729 test_Equal(ThisTraceContextId, ((TUint32*)(data+offset))[0]);
1730 test_Equal(ThisTraceContextId, ((TUint32*)(data2+offset))[0]);
1734 test_Equal(expectTrace,BigTraceEndTest()); // check we actually got mutilpart traces
1736 test.Next(_L("Big traces with Context ID and PC"));
1737 BigTraceBeginTest();
1738 for(i=minSize; i<=(TInt)sizeof(KTestTrace1)-4; i++)
1740 TestTrace1(RBTraceTest::EBigTrace|BTrace::EContextIdPresent|BTrace::EPcPresent|extraFlags,i);
1745 size=Trace.GetData(data);
1754 test(CheckBigTrace1(data,size,i,KTest1SubCategory));
1755 test(CheckBigTrace1(data2,size,i,KTest1SubCategory));
1757 test((data[BTrace::EFlagsIndex]&BTrace::EContextIdPresent));
1758 test((data[BTrace::EFlagsIndex]&BTrace::EPcPresent));
1760 TUint offset = ContextOffset(data);
1761 test_Equal(ThisTraceContextId, ((TUint32*)(data+offset))[0] );
1762 test_Equal(ThisTraceContextId, ((TUint32*)(data2+offset))[0] );
1763 test_Compare( ((TUint32*)(data+offset))[1], != ,((TUint32*)(data2+offset))[1]);
1767 test_Equal(expectTrace,BigTraceEndTest()); // check we actually got mutilpart traces
1771 test.Next(_L("Restore buffer"));
1772 r = Trace.ResizeBuffer(oldSize);
1774 Trace.SetFilter2(0);
1780 TUint MainThreadTraceId = 0;
1782 //---------------------------------------------
1783 //! @SYMTestCaseID KBASE-T_BTRACE-0064
1785 //! @SYMPREQ PREQ1030
1786 //! @SYMTestCaseDesc Test BTrace category EThreadIdentification.
1787 //! @SYMTestActions Enable the EThreadIdentification trace category, causing it to be 'primed'.
1788 //! Rename a thread and a process, then create and destory a thread.
1789 //! No actions are performed if the kernel doesn't support this trace category.
1790 //! @SYMTestExpectedResults All test actions produced traces and their contents matched
1791 //! the expected results.
1792 //! @SYMTestPriority High
1793 //! @SYMTestStatus Implemented
1794 //---------------------------------------------
1795 void TestThreadIdentification()
1797 if(KErrNotSupported==Trace.Filter(BTrace::EThreadIdentification))
1799 test.Start(_L("Trace category not supported by this build of kernel."));
1804 TBuf8<KMaxKernelName> threadName = RThread().Name().Collapse();
1805 TUint threadId = RThread().Id();
1806 TBuf8<KMaxKernelName> processName = RProcess().Name().Collapse();
1808 TUint32 threadTraceId = 0;
1809 TUint32 processTraceId = 0;
1813 test.Start(_L("Reset trace buffer"));
1815 TInt oldSize = Trace.BufferSize();
1816 TInt r = Trace.ResizeBuffer(0x100000);
1818 Trace.SetFilter(BTrace::EThreadIdentification,0);
1819 Trace.SetMode(RBTrace::EEnable);
1821 test.Next(_L("Test category is primed correct when it is enabled"));
1822 Trace.SetFilter(BTrace::EThreadIdentification,1);
1823 // search for current thread in trace...
1825 size=Trace.GetData(trace);
1827 TUint8* end = trace+size;
1828 for(data=trace; data<end; data=BTrace::NextRecord(data))
1829 if(data[BTrace::ECategoryIndex]==BTrace::EThreadIdentification)
1830 if(data[BTrace::ESubCategoryIndex]==BTrace::EProcessName)
1831 if(processName==Text(data))
1833 processTraceId = Body(data)[1];
1836 test_Compare(data, < , end);
1837 for(; data<end; data=BTrace::NextRecord(data))
1838 if(data[BTrace::ECategoryIndex]==BTrace::EThreadIdentification)
1839 if(data[BTrace::ESubCategoryIndex]==BTrace::EThreadName)
1840 if(processTraceId==Body(data)[1])
1841 if(threadName==Text(data))
1843 threadTraceId = Body(data)[0];
1846 test_Compare(data, < , end);
1847 for(; data<end; data=BTrace::NextRecord(data))
1848 if(data[BTrace::ECategoryIndex]==BTrace::EThreadIdentification)
1849 if(data[BTrace::ESubCategoryIndex]==BTrace::EThreadId)
1850 if(threadTraceId==Body(data)[0])
1851 if(processTraceId==Body(data)[1])
1852 if(threadId==Body(data)[2])
1856 test_Compare(data, < ,end);
1858 MainThreadTraceId = threadTraceId;
1860 test.Next(_L("Test thread rename traces"));
1861 test_KErrNone(User::RenameThread(_L("t_btrace-main")));
1862 threadName = RThread().Name().Collapse();
1863 size=Trace.GetData(data);
1866 test_Equal(BTrace::EThreadIdentification,data[BTrace::ECategoryIndex]);
1867 test_Equal(BTrace::EThreadName, data[BTrace::ESubCategoryIndex]);
1868 test_Equal(threadTraceId, Body(data)[0]);
1869 test_Equal(processTraceId, Body(data)[1]);
1870 test(threadName==Text(data));
1871 data=BTrace::NextRecord(data);
1875 test.Next(_L("Test process rename traces"));
1876 test_KErrNone(User::RenameProcess(_L("T_BTRACE-renamed")));
1877 processName = RProcess().Name().Collapse();
1878 size=Trace.GetData(data);
1881 test_Equal(BTrace::EThreadIdentification,data[BTrace::ECategoryIndex]);
1882 test_Equal(BTrace::EProcessName ,data[BTrace::ESubCategoryIndex]);
1883 test_Equal(processTraceId, Body(data)[1]);
1884 test(processName==Text(data));
1885 data=BTrace::NextRecord(data);
1889 test.Next(_L("Test thread creation traces"));
1891 test_KErrNone(thread.Create(KNullDesC,0,0x1000,&User::Allocator(),0));
1892 threadName = thread.Name().Collapse();
1893 threadId = thread.Id();
1894 size=Trace.GetData(data);
1898 test_Equal(BTrace::EThreadIdentification,data[BTrace::ECategoryIndex]);
1899 test_Equal(BTrace::ENanoThreadCreate ,data[BTrace::ESubCategoryIndex]);
1900 threadTraceId = Body(data)[0];
1901 data=BTrace::NextRecord(data);
1902 test_Compare(data, < ,end);
1904 test_Equal(BTrace::EThreadIdentification,data[BTrace::ECategoryIndex]);
1905 test_Equal(BTrace::EProcessName ,data[BTrace::ESubCategoryIndex]);
1906 test_Equal(processTraceId, Body(data)[1]);
1907 test(processName==Text(data));
1908 data=BTrace::NextRecord(data);
1909 test_Compare(data, < ,end);
1911 test_Equal(BTrace::EThreadIdentification,data[BTrace::ECategoryIndex]);
1912 test_Equal(BTrace::EThreadCreate ,data[BTrace::ESubCategoryIndex]);
1913 test_Equal(threadTraceId, Body(data)[0]);
1914 processTraceId = Body(data)[1];
1915 test(threadName==Text(data));
1916 data=BTrace::NextRecord(data);
1917 test_Compare(data, < ,end);
1919 test_Equal(BTrace::EThreadIdentification,data[BTrace::ECategoryIndex]);
1920 test_Equal(BTrace::EThreadId ,data[BTrace::ESubCategoryIndex]);
1921 test_Equal(threadTraceId, Body(data)[0]);
1922 test_Equal(processTraceId, Body(data)[1]);
1923 test(threadId==Body(data)[2]);
1924 data=BTrace::NextRecord(data);
1925 test_Equal(data,end);
1928 test.Next(_L("Test thread destruction traces"));
1930 User::After(100000);
1931 size=Trace.GetData(data);
1935 test_Equal(BTrace::EThreadIdentification,data[BTrace::ECategoryIndex]);
1936 test_Equal(BTrace::ENanoThreadDestroy ,data[BTrace::ESubCategoryIndex]);
1937 test_Equal(threadTraceId, Body(data)[0]);
1938 data=BTrace::NextRecord(data);
1939 test_Compare(data, < ,end);
1941 test_Equal(BTrace::EThreadIdentification,data[BTrace::ECategoryIndex]);
1942 test_Equal(BTrace::EThreadDestroy ,data[BTrace::ESubCategoryIndex]);
1943 test_Equal(threadTraceId, Body(data)[0]);
1944 test_Equal(processTraceId, Body(data)[1]);
1945 test(threadId==Body(data)[2]);
1946 data=BTrace::NextRecord(data);
1947 test_Equal(data,end);
1950 test.Next(_L("Cleanup after tests"));
1951 Trace.SetFilter(BTrace::EThreadIdentification,0);
1953 r = Trace.ResizeBuffer(oldSize);
1960 //---------------------------------------------
1961 //! @SYMTestCaseID KBASE-T_BTRACE-0065
1963 //! @SYMPREQ PREQ1030
1964 //! @SYMTestCaseDesc Test BTrace category ECpuUsage.
1965 //! @SYMTestActions Enable the ECpuUsage trace category for one second, then obtain captured
1966 //! traces using RBTrace.
1967 //! @SYMTestExpectedResults Traces are generated for the sub-categories EIrqStart, EIDFCStart,
1968 //! EIDFCEnd and ENewThreadContext. The later must include the context ID of the main test
1970 //! @SYMTestPriority High
1971 //! @SYMTestStatus Implemented
1972 //---------------------------------------------
1975 if(KErrNotSupported==Trace.Filter(BTrace::ECpuUsage))
1977 test.Start(_L("Trace category not supported by this build of kernel."));
1982 test.Start(_L("Reset trace buffer"));
1984 TInt oldSize = Trace.BufferSize();
1985 TInt r = Trace.ResizeBuffer(0x100000);
1987 Trace.SetMode(RBTrace::EEnable);
1989 test.Next(_L("Generate traces for a short time..."));
1990 Trace.SetFilter(BTrace::ECpuUsage,1);
1991 User::After(1000*1000);
1992 Trace.SetFilter(BTrace::ECpuUsage,0);
1994 test.Next(_L("Process traces"));
1995 TUint8 subCategories[256] = {0};
1998 while((size=Trace.GetData(data))!=0)
2000 TUint8* end = data+size;
2001 for( ; data<end; data=BTrace::NextRecord(data))
2003 test_Equal(BTrace::ECpuUsage,data[BTrace::ECategoryIndex]);
2004 TUint subCategory = data[BTrace::ESubCategoryIndex];
2005 TUint8* context = data+ContextOffset(data);
2006 TUint8* recordEnd = BTrace::NextRecord(data);
2007 if(subCategory==BTrace::ENewThreadContext)
2009 test_Equal(context+4, recordEnd); // trace record should end after context data
2010 if(*(TUint32*)context != MainThreadTraceId)
2011 continue; // not a context switch to this thread
2013 else if (subCategory==BTrace::EIrqStart || subCategory==BTrace::EFiqStart)
2015 // may or may not contain vector number
2016 if (recordEnd != context)
2018 test_Equal(context+4, recordEnd);
2023 test_Equal(context, recordEnd); // trace record should have no context or any data after
2025 subCategories[subCategory] = 1; // set flag to say we've seen this kind of trace
2030 test.Next(_L("Check for expected traces"));
2031 // timer interrupts should have generated IRQ traces...
2032 test(subCategories[BTrace::EIrqStart]);
2033 // User::After should have caused timer interrupt to queue a DFC...
2034 test(subCategories[BTrace::EIDFCStart]);
2035 test(subCategories[BTrace::EIDFCEnd]);
2036 // Current thread must have got scheduled again...
2037 test(subCategories[BTrace::ENewThreadContext]);
2039 test.Next(_L("Cleanup after tests"));
2040 Trace.SetFilter(BTrace::ECpuUsage,0);
2042 r = Trace.ResizeBuffer(oldSize);
2049 volatile TBool SoakDone = EFalse; // always false, but stops compiler warnings in SoakThreadFunction
2051 RThread SoakThread[4];
2053 TInt SoakThreadFunction(TAny* aData)
2056 BTrace::TCategory category = (BTrace::TCategory)*(TUint8*)aData;
2057 TUint subCategory = 0;
2060 random = random*69069+1;
2061 TUint size = (random>>24u);
2064 BTrace0(category,subCategory);
2066 BTrace4(category,subCategory,((TUint32*)aData)[1]);
2068 BTrace8(category,subCategory,((TUint32*)aData)[1],((TUint32*)aData)[2]);
2070 BTraceN(category,subCategory,((TUint32*)aData)[1],((TUint32*)aData)[2],&((TUint32*)aData)[3],size-12);
2077 TInt SoakThreadFunction2(TAny* aData)
2080 BTrace::TCategory category = (BTrace::TCategory)*(TUint8*)aData;
2081 TUint subCategory = 0;
2084 random = random*69069+1;
2085 TUint size = (random>>24u);
2089 outOk = BTraceFiltered4(category,subCategory,((TUint32*)aData)[1]);
2091 outOk = BTraceFiltered8(category,subCategory,((TUint32*)aData)[1],((TUint32*)aData)[2]);
2093 outOk = BTraceFilteredN(category,subCategory,((TUint32*)aData)[1],((TUint32*)aData)[2],&((TUint32*)aData)[3],size-12);
2101 TInt SoakControlThreadFunction(TAny*)
2103 // randomly mess with thread priorities of soak test threads so
2104 // we get lots of preemption going on
2105 const TThreadPriority priorities[] =
2116 User::AfterHighRes(1);
2117 random = random*69069+1;
2118 SoakThread[(random>>16)%3].SetPriority(priorities[(random>>14)&3]);
2124 void ChangeSecondaryFilter()
2126 // mess with secondary filter...
2127 static TUint32 random = 0;
2128 random = random*69069+1;
2132 Trace.SetFilter2(KBTraceFilterTestUid1,0);
2135 Trace.SetFilter2(KBTraceFilterTestUid1,1);
2138 Trace.SetFilter2(KBTraceFilterTestUid2,0);
2141 Trace.SetFilter2(KBTraceFilterTestUid2,1);
2144 Trace.SetFilter2(0);
2147 Trace.SetFilter2(1);
2150 Trace.SetFilter2(&KBTraceFilterTestUid1,1);
2153 Trace.SetFilter2(&KBTraceFilterTestUid2,1);
2158 //---------------------------------------------
2159 //! @SYMTestCaseID KBASE-T_BTRACE-0066
2161 //! @SYMPREQ PREQ1030
2162 //! @SYMTestCaseDesc Soak tests
2163 //! @SYMTestActions Generate ordered traces of random size using two worker threads and
2164 //! read the generated trace in the main test program thread. All threads are scheduled
2165 //! in a random manner.
2166 //! @SYMTestExpectedResults Captured traces must contain the correct data and any
2167 //! missing traces must be indicated by the EMissingRecord flag in the next trace.
2168 //! @SYMTestPriority High
2169 //! @SYMTestStatus Implemented
2170 //---------------------------------------------
2171 void TestSoak(TUint aMode,TUint aTimeInSeconds)
2173 aMode |= RBTrace::EEnable;
2175 test.Start(_L("Reset trace buffer"));
2176 TInt oldSize = Trace.BufferSize();
2177 TInt r = Trace.ResizeBuffer(0x10000);
2179 Trace.SetMode(aMode);
2180 Trace.SetFilter(BTrace::ETest1,1);
2181 Trace.SetFilter(BTrace::ETest2,1);
2182 Trace.SetFilter2(KBTraceFilterTestUid2,1);
2184 TUint32* buffer = (TUint32*)Trace.DataChunk().Base();
2185 test.Printf(_L("Buffer=%x %x,%x,%x,%x,%x,%x,%x,%x,%x,%x\n"),buffer,
2186 buffer[0],buffer[1],buffer[2],buffer[3],buffer[4],buffer[5],buffer[6],buffer[7],buffer[8],buffer[9]);
2188 test.Next(_L("Random traces..."));
2192 test_KErrNone(timer.CreateLocal());
2193 SoakThread[0].Duplicate(RThread(),EOwnerProcess);
2194 test_KErrNone(SoakThread[1].Create(KNullDesC,SoakThreadFunction,0x1000,&User::Allocator(),KTestTrace1));
2195 test_KErrNone(SoakThread[2].Create(KNullDesC,SoakThreadFunction2,0x1000,&User::Allocator(),KTestTrace2));
2196 test_KErrNone(SoakThread[3].Create(KNullDesC,SoakControlThreadFunction,0x1000,&User::Allocator(),KTestTrace2));
2197 // The control thread must be resumed first otherwise time slicing perculiarities
2198 // can cause the soak threads to take all of the CPU time...
2199 SoakThread[3].SetPriority(EPriorityMuchMore);
2200 SoakThread[3].Resume();
2203 TTimeIntervalMicroSeconds32 tickPeriod;
2204 UserHal::TickPeriod(tickPeriod);
2205 TInt64 ticks = aTimeInSeconds;
2207 ticks /= tickPeriod.Int();
2208 timer.AfterTicks(s,(TInt)ticks);
2210 // resume threads producing trace output...
2211 SoakThread[1].Resume();
2212 SoakThread[2].Resume();
2214 TInt64 totalSize = 0;
2217 ChangeSecondaryFilter();
2218 const TInt KTraceDataBlockSize = 0x1000;
2221 while(s==KRequestPending && (size=Trace.GetData(data))!=0)
2223 // RDebug::Printf("READ: data=%08x size=%08x\n",data,size);
2224 if(s!=KRequestPending)
2226 CheckTraceData(data,size);
2230 if(s!=KRequestPending)
2232 TRequestStatus waitStatus;
2233 Trace.RequestData(waitStatus,KTraceDataBlockSize);
2234 User::WaitForRequest(waitStatus);
2235 test_KErrNone(waitStatus.Int());
2237 User::WaitForRequest(s);
2238 test_Equal(EExitPending, SoakThread[1].ExitType() );
2239 test_Equal(EExitPending, SoakThread[2].ExitType() );
2240 test_Equal(EExitPending, SoakThread[3].ExitType() );
2241 SoakThread[1].Kill(0);
2242 SoakThread[2].Kill(0);
2243 SoakThread[3].Kill(0);
2244 SoakThread[1].Close();
2245 SoakThread[2].Close();
2246 SoakThread[3].Close();
2248 test.Printf(_L("total trace data processed = %ld k\n"),totalSize>>10);
2250 test.Next(_L("Restore buffer"));
2251 r = Trace.ResizeBuffer(oldSize);
2258 void KernelBenchmark(TUint& aTime1,TUint& aTime2,TUint& aTime3,TBool aTraceEnabled,TBool aFilter2)
2260 TInt oldSize = Trace.BufferSize();
2262 TInt r = Trace.ResizeBuffer(0x1000);
2264 Trace.SetMode(RBTrace::EFreeRunning|RBTrace::EEnable);
2267 r = 1+TraceTest.TestBenchmark2(0,1000000);
2269 r = 1+TraceTest.TestBenchmark(0,1000000);
2271 TInt size = Trace.GetData(data);
2272 test(aTraceEnabled ? size!=0 : size==0);
2274 aTime1 = 1000000000/r;
2276 r = Trace.ResizeBuffer(0x1000);
2278 Trace.SetMode(RBTrace::EFreeRunning|RBTrace::EEnable);
2281 r = 1+TraceTest.TestBenchmark2(KMaxBTraceDataArray,1000000);
2283 r = 1+TraceTest.TestBenchmark(KMaxBTraceDataArray,1000000);
2284 size = Trace.GetData(data);
2285 test(aTraceEnabled ? size!=0 : size==0);
2287 aTime2 = 1000000000/r;
2289 r = 1+TraceTest.TestBenchmarkCheckFilter(aFilter2,1000000);
2290 aTime3 = 1000000000/r;
2292 r = Trace.ResizeBuffer(oldSize);
2297 void UserBenchmark(TUint& aTime1,TUint& aTime2,TUint& aTime3,TBool aTraceEnabled,TBool aFilter2)
2299 TInt oldSize = Trace.BufferSize();
2302 TRequestStatus status;
2303 test_KErrNone(timer.CreateLocal());
2305 TInt r = Trace.ResizeBuffer(0x1000);
2307 Trace.SetMode(RBTrace::EFreeRunning|RBTrace::EEnable);
2309 timer.After(status,1);
2310 User::WaitForRequest(status);
2311 timer.After(status,1000000);
2316 BTraceFiltered4(BTrace::ETest1,0,KBTraceFilterTestUid1);
2319 while(status==KRequestPending);
2323 BTrace0(BTrace::ETest1,0);
2326 while(status==KRequestPending);
2327 User::WaitForRequest(status);
2329 TInt size = Trace.GetData(data);
2330 test(aTraceEnabled ? size!=0 : size==0);
2332 aTime1 = 1000000000/r;
2334 r = Trace.ResizeBuffer(0x1000);
2336 Trace.SetMode(RBTrace::EFreeRunning|RBTrace::EEnable);
2338 timer.After(status,1);
2339 User::WaitForRequest(status);
2340 timer.After(status,1000000);
2345 BTraceFilteredContextN(BTrace::ETest1,0,KBTraceFilterTestUid1,0,KTestTrace1,KMaxBTraceDataArray);
2348 while(status==KRequestPending);
2352 BTraceContextN(BTrace::ETest1,0,0,0,KTestTrace1,KMaxBTraceDataArray);
2355 while(status==KRequestPending);
2356 User::WaitForRequest(status);
2357 size = Trace.GetData(data);
2358 test(aTraceEnabled ? size!=0 : size==0);
2360 aTime2 = 1000000000/r;
2362 timer.After(status,1);
2363 User::WaitForRequest(status);
2364 timer.After(status,1000000);
2370 check = BTrace::CheckFilter2(BTrace::ETest1,KBTraceFilterTestUid1);
2373 while(status==KRequestPending);
2377 check = BTrace::CheckFilter(BTrace::ETest1);
2380 while(status==KRequestPending);
2381 test(check == aTraceEnabled);
2382 aTime3 = 1000000000/r;
2384 r = Trace.ResizeBuffer(oldSize);
2389 //---------------------------------------------
2390 //! @SYMTestCaseID KBASE-T_BTRACE-0066-0067
2392 //! @SYMPREQ PREQ1030
2393 //! @SYMTestCaseDesc Benchmark tracing.
2394 //! @SYMTestActions Time the generation of minimum and maximum sized traces both with
2395 //! and without the trace filter enabled for the trace category.
2396 //! @SYMTestExpectedResults Trace time with filter enabled should not excede 2000 nano-seconds,
2397 //! and time with filter disabled should not excede 500 nano-seconds. (These limits are not
2398 //! asserted). If time significantly excedes this then detailed investigation is required.
2399 //! @SYMTestPriority Medium
2400 //! @SYMTestStatus Implemented
2401 //---------------------------------------------
2402 void TestBenchmark(TBool aUserTrace)
2408 #define BENCH(a1,a2) aUserTrace ? UserBenchmark(t1,t2,t3,a1,a2) : KernelBenchmark(t1,t2,t3,a1,a2)
2410 test.Printf(_L(" Min Trace Max Trace Filter\n"));
2412 Trace.SetFilter(BTrace::ETest1,0);
2414 test.Printf(_L("filter1 off %6d ns %6d ns %6d ns\n"),t1,t2,t3);
2416 Trace.SetFilter(BTrace::ETest1,1);
2418 test.Printf(_L("filter1 on %6d ns %6d ns %6d ns\n"),t1,t2,t3);
2420 Trace.SetFilter(BTrace::ETest1,0);
2421 Trace.SetFilter2(0);
2423 test.Printf(_L("filter1 off filter2 off %6d ns %6d ns %6d ns\n"),t1,t2,t3);
2425 Trace.SetFilter(BTrace::ETest1,1);
2426 Trace.SetFilter2(0);
2428 test.Printf(_L("filter1 on global filter2 off %6d ns %6d ns %6d ns\n"),t1,t2,t3);
2430 Trace.SetFilter2(1);
2432 test.Printf(_L("filter1 on global filter2 on %6d ns %6d ns %6d ns\n"),t1,t2,t3);
2434 Trace.SetFilter2(&KBTraceFilterTestUid2,1);
2436 test.Printf(_L("filter1 on 1 UID filter2 off %6d ns %6d ns %6d ns\n"),t1,t2,t3);
2438 Trace.SetFilter2(&KBTraceFilterTestUid1,1);
2440 test.Printf(_L("filter1 on 1 UID filter2 on %6d ns %6d ns %6d ns\n"),t1,t2,t3);
2442 Trace.SetFilter2(BigFilter2,sizeof(BigFilter2)/sizeof(TUint32));
2443 Trace.SetFilter2(KBTraceFilterTestUid1,0);
2445 test.Printf(_L("filter1 on 100 UID filter2 off %6d ns %6d ns %6d ns\n"),t1,t2,t3);
2447 Trace.SetFilter2(BigFilter2,sizeof(BigFilter2)/sizeof(TUint32));
2449 test.Printf(_L("filter1 on 100 UID filter2 on %6d ns %6d ns %6d ns\n"),t1,t2,t3);
2451 Trace.SetFilter(BTrace::ETest1,0);
2452 Trace.SetFilter2(0);
2455 struct THREADTRACETESTSTRUCT {
2460 LOCAL_D TInt threadtraceTestThread(TAny* param)
2462 THREADTRACETESTSTRUCT* p = (THREADTRACETESTSTRUCT*)param;
2463 p->alloc_addr = new TInt;
2464 delete p->alloc_addr;
2468 void TestHeapAndChunkTrace()
2470 if(KErrNotSupported==Trace.Filter(BTrace::EHeap))
2472 test.Start(_L("Trace category EHeap not supported by this build of kernel."));
2477 test.Start(_L("Reset trace buffer"));
2479 TInt oldSize = Trace.BufferSize();
2480 TInt r = Trace.ResizeBuffer(0x100000);
2482 Trace.SetFilter(BTrace::EHeap,0);
2483 Trace.SetFilter(BTrace::EChunks,0);
2484 Trace.SetMode(RBTrace::EEnable);
2486 test.Next(_L("Test heap-alloc works as expected"));
2487 Trace.SetFilter(BTrace::EHeap,1);
2488 TBool chunkTraceEnabled = Trace.SetFilter(BTrace::EChunks,1)!=KErrNotSupported;
2490 // Create a test thread
2491 THREADTRACETESTSTRUCT threadtest;
2493 TRequestStatus stat;
2494 test.Next(_L("Test thread creation heap trace"));
2495 r=thread.Create(_L("t_tbrace_2"),threadtraceTestThread,KDefaultStackSize,0x2000,0x2000,&threadtest);
2499 User::WaitForRequest(stat);
2502 // search for heap records in trace...
2505 TInt size=Trace.GetData(trace);
2507 TUint8* end = trace+size;
2508 TUint chunk_ptr = 0, heap_chunk_ptr = 0;
2509 int found_chunk_create = 0;
2510 int found_heap_chunk_create = 0;
2511 int found_heap_create=0;
2512 int found_heap_alloc=0;
2513 int found_heap_free=0;
2514 for(data=trace; data<end; data=BTrace::NextRecord(data))
2516 if(data[BTrace::ECategoryIndex]==BTrace::EChunks)
2518 if(data[BTrace::ESubCategoryIndex]==BTrace::EChunkCreated)
2520 found_chunk_create=1;
2521 chunk_ptr = Body(data)[0];
2524 if(data[BTrace::ECategoryIndex]==BTrace::EHeap)
2526 if(data[BTrace::ESubCategoryIndex]==BTrace::EHeapCreate)
2527 found_heap_create=1;
2528 if(data[BTrace::ESubCategoryIndex]==BTrace::EHeapChunkCreate)
2530 found_heap_chunk_create=1;
2531 heap_chunk_ptr = Body(data)[1];
2533 if(data[BTrace::ESubCategoryIndex]==BTrace::EHeapAlloc)
2535 if(Body(data)[1]==(TUint)threadtest.alloc_addr)
2538 test_Equal(4, Body(data)[2]);
2539 test_Compare(Body(data)[3], >= ,4);
2542 if(data[BTrace::ESubCategoryIndex]==BTrace::EHeapFree)
2544 if(Body(data)[1]==(TUint)threadtest.alloc_addr)
2549 test(found_heap_create);
2550 test(found_heap_chunk_create);
2551 test(found_heap_alloc);
2552 test(found_heap_free);
2553 if(!chunkTraceEnabled)
2555 test.Next(_L("Trace category EChunk not supported by this build of kernel."));
2559 test(chunk_ptr && heap_chunk_ptr);
2560 test(chunk_ptr == heap_chunk_ptr);
2563 // Turn on chunk trace and empty btrace buffer
2564 test.Next(_L("Chunk testing"));
2565 Trace.SetFilter(BTrace::EChunks,1);
2568 // Create a chunk and test the expected traces
2570 test_KErrNone(chunk.CreateLocal(4096, 4*1024*1024));
2572 size=Trace.GetData(trace);
2575 found_chunk_create=0;
2576 for(data=trace; data<end; data=BTrace::NextRecord(data))
2578 if(data[BTrace::ECategoryIndex]==BTrace::EChunks)
2580 if(data[BTrace::ESubCategoryIndex]==BTrace::EChunkCreated)
2582 test_Equal(4*1024*1024, Body(data)[1]);
2583 found_chunk_create = 1;
2585 if(data[BTrace::ESubCategoryIndex]==BTrace::EChunkMemoryAllocated)
2587 test_Equal(4096, Body(data)[2]);
2588 found_heap_alloc = 1;
2592 test(found_heap_alloc && found_chunk_create);
2595 test.Next(_L("Cleanup after tests"));
2596 Trace.SetFilter(BTrace::EHeap,0);
2598 r = Trace.ResizeBuffer(oldSize);
2604 void SetBTraceFilter(const TUint32* aNew,TUint32* aOld)
2609 TUint32 newBits = *aNew++;
2610 TUint32 oldBits = 0;
2614 if(Trace.SetFilter(category,newBits&1))
2615 oldBits |= 0x80000000u;
2623 while(category<256);
2627 TUint32 OldTraceFilter[8] = {0};
2630 //thread function to generate BTrace::EHeap::EHeapAllocFail event
2631 LOCAL_D TInt ThreadtraceAllocFailTestThread(TAny* /*param*/)
2633 RPointerArray<TInt32> array(1000);
2637 TInt32* p = new TInt32[(++i)*2];
2641 if(array.Append(p) == KErrNoMemory)
2644 array.ResetAndDestroy();
2649 //thread function to generate BTrace::EHeap::EHeapReAllocFail event
2650 LOCAL_D TInt ThreadtraceReAllocFailTestThread(TAny* /*param*/)
2653 TUint8 *p = (TUint8*)User::Alloc(s);
2657 TUint8* np = (TUint8*)User::ReAlloc(p, s);
2671 //---------------------------------------------------------------------------------------------------------------------
2672 //! @SYMTestCaseID KBASE-T_BTRACE-0733
2673 //! @SYMTestCaseDesc Test BTrace - EHeapAllocFail and EHeapReAllocFail subcategories.
2675 //! @SYMPREQ PREQ1340
2676 //! @SYMTestPriority Medium
2678 //! 1. Configure BTrace to use EHeap and EThreadIdentification as main filter
2680 //! 2. Create and start a thread which will eventually exhaust
2681 //! all memory resources (this should result with sending a trace
2682 //! from allocator class - sent trace should have
2683 //! category - EHeap and subcategory - EHeapAllocFail).
2684 //! 3. After thread (from previous point) crashes, get trace data from BTrace
2685 //! and search for trace with category EHeap and subcategory EHeapAllocFail
2686 //! 4. Validate trace data payload - it should have exactly 8 bytes (2x4 bytes values).
2688 //! @SYMTestExpectedResults
2689 //! 1. Trace data should contain at least one trace with category
2690 //! EHeap and subcategory EHeapAllocFail.
2691 //! 2. Trace data payload (where category is EHeap and subcategory is EHeapAllocFail) should
2692 //! be 8 bytes long (2 x 4 bytes values).
2693 //---------------------------------------------------------------------------------------------------------------------
2694 void TestHeapAllocFailEvent(TInt aTestCategory)
2697 if(aTestCategory == BTrace::EHeapAllocFail)
2698 test.Next(_L("Test to check BTrace::EHeap::EHeapAllocFail trace event"));
2699 else if(aTestCategory == BTrace::EHeapReAllocFail)
2700 test.Next(_L("Test to check BTrace::EHeap::EHeapReAllocFail trace event"));
2704 TInt r = Trace.ResizeBuffer(0x100000);
2707 Trace.SetFilter(BTrace::EHeap,0);
2708 Trace.SetFilter(BTrace::EChunks,0);
2709 Trace.SetMode(RBTrace::EEnable);
2710 Trace.SetFilter(BTrace::EHeap,1);
2711 Trace.SetFilter(BTrace::EThreadIdentification,1);
2713 //start thread to cause EHeapAllocFail event
2715 TRequestStatus stat;
2717 //starting test thread
2718 if(aTestCategory == BTrace::EHeapAllocFail)
2719 r = thread.Create(_L("t_btrace_allocfail_thread"), ThreadtraceAllocFailTestThread, KDefaultStackSize, 0x2000, 0x2000, NULL);
2720 else if(aTestCategory == BTrace::EHeapReAllocFail)
2721 r = thread.Create(_L("t_btrace_reallocfail_thread"), ThreadtraceReAllocFailTestThread, KDefaultStackSize, 0x2000, 0x2000, NULL);
2726 User::WaitForRequest(stat);
2729 //getting trace data
2732 TInt size=Trace.GetData(trace);
2735 TUint8* end = trace+size;
2736 TInt8 found_heap_allocfail = 0;
2738 TInt subCat = BTrace::EHeapAllocFail;
2739 TInt expectedDataSize = 8;
2740 if(aTestCategory == BTrace::EHeapReAllocFail)
2742 subCat = BTrace::EHeapReAllocFail;
2743 expectedDataSize = 12;
2746 for(data=trace; data<end; data=BTrace::NextRecord(data))
2748 if(data[BTrace::ECategoryIndex]==BTrace::EHeap)
2749 if(data[BTrace::ESubCategoryIndex]==subCat)
2751 found_heap_allocfail = 1;
2752 TInt allocfail_data_size = ((TInt)data[BTrace::ESizeIndex]) - ExtraSize(data);
2753 test_Equal(allocfail_data_size,expectedDataSize);
2754 break; //we're looking only for one record
2757 test(found_heap_allocfail);
2767 bool FindHeapCorruptionTrace(TUint8* aData, TInt aSize, TInt& aFoundSize)
2769 TUint8* end = aData+aSize;
2771 for(data=aData; data<end; data=BTrace::NextRecord(data))
2773 if(data[BTrace::ECategoryIndex] == BTrace::EHeap)
2774 if(data[BTrace::ESubCategoryIndex] == BTrace::EHeapCorruption)
2776 aFoundSize = data[BTrace::ESizeIndex] - ExtraSize(data);
2784 //---------------------------------------------------------------------------------------------------------------------
2785 //! @SYMTestCaseID KBASE-T_BTRACE-0734
2786 //! @SYMTestCaseDesc Test BTrace - EHeapCorruption subcategory.
2788 //! @SYMPREQ PREQ1340
2789 //! @SYMTestPriority Medium
2791 //! 1. Configure BTrace to use EHeap and EThreadIdentification categories.
2792 //! 2. Use test application (t_heapcorruption.exe) with parameters: 1, 2, 3 or 4 to
2793 //! to corrupt heap memory (for this application)
2794 //! 3. Get trace data from BTrace and search for trace with category EHeap and
2795 //! subcategory EHeapCorruption.
2796 //! 4. Validate payload size for found traces.
2798 //! @SYMTestExpectedResults
2799 //! 1. Test application (when started with either argument) should generate at least
2800 //! one trace with category EHeap and subcategory EHeapCorruption.
2801 //! 2. Trace data payload should be 12 bytes long (3x4 bytes values).
2802 //---------------------------------------------------------------------------------------------------------------------
2803 void TestHeapCorruptionEvents()
2806 test.Next(_L("Test to check BTrace::EHeap::EHeapCorruption trace events"));
2810 Trace.ResizeBuffer(0x100000);
2812 Trace.SetFilter(BTrace::EHeap,0);
2813 Trace.SetFilter(BTrace::EChunks,0);
2814 Trace.SetMode(RBTrace::EEnable);
2815 Trace.SetFilter(BTrace::EHeap,1);
2816 Trace.SetFilter(BTrace::EThreadIdentification,1);
2818 _LIT(KHeapCorrApp, "t_heapcorruption.exe");
2819 _LIT(KCorruption0, "0"); //RHeap:: corruption type (when EMonitorMemory flag is set)
2820 _LIT(KCorruption1, "1"); //RHeap::EBadFreeCellAddress corruption type
2821 _LIT(KCorruption2, "2"); //RHeap::EBadFreeCellSize corruption type
2822 _LIT(KCorruption3, "3"); //RHeap::EBadAllocatedCellSize corruption type
2823 _LIT(KCorruption4, "4"); //RHeap::EBadAllocatedCellAddress corruption type
2824 _LIT(KCorruptionSpecial1, "1000"); //RHeap::EBadAllocatedCellSize (with EMonitorMemory flag set)
2827 TRequestStatus status;
2829 TInt size, payloadSize;
2832 //test 0 (for memory monitoring tools - when EMonitorMemory heap flag is set)
2833 test.Printf(_L("test 0\n"));
2834 Trace.SetMode(RBTrace::EEnable);
2835 e = p.Create(KHeapCorrApp, KCorruption0);
2839 User::WaitForRequest(status);
2841 size = Trace.GetData(trace);
2843 res = FindHeapCorruptionTrace(trace, size, payloadSize);
2845 test(payloadSize == 12); //payload in this case must be 12 bytes long (3x4bytes)
2851 test.Printf(_L("test 1\n"));
2852 Trace.SetMode(RBTrace::EEnable);
2853 e = p.Create(KHeapCorrApp, KCorruption1);
2857 User::WaitForRequest(status);
2859 size = Trace.GetData(trace);
2861 res = FindHeapCorruptionTrace(trace, size, payloadSize);
2863 test(payloadSize == 12); //payload in this case must be 12 bytes long (3x4bytes)
2869 test.Printf(_L("test 2\n"));
2870 Trace.SetMode(RBTrace::EEnable);
2871 e = p.Create(KHeapCorrApp, KCorruption2);
2875 User::WaitForRequest(status);
2877 size = Trace.GetData(trace);
2879 res = FindHeapCorruptionTrace(trace, size, payloadSize);
2881 test(payloadSize == 12); //payload in this case must be 12 bytes long (3x4bytes)
2887 test.Printf(_L("test 3\n"));
2888 Trace.SetMode(RBTrace::EEnable);
2889 e = p.Create(KHeapCorrApp, KCorruption3);
2893 User::WaitForRequest(status);
2895 size = Trace.GetData(trace);
2897 res = FindHeapCorruptionTrace(trace, size, payloadSize);
2899 test(payloadSize == 12); //payload in this case must be 12 bytes long (3x4bytes)
2905 test.Printf(_L("test 4\n"));
2906 Trace.SetMode(RBTrace::EEnable);
2907 e = p.Create(KHeapCorrApp, KCorruption4);
2911 User::WaitForRequest(status);
2913 size = Trace.GetData(trace);
2915 res = FindHeapCorruptionTrace(trace, size, payloadSize);
2917 test(payloadSize == 12); //payload in this case must be 12 bytes long (3x4bytes)
2922 //test 5 (test ____MEMORY_MONITOR_CHECK_CELL macro)
2923 test.Printf(_L("test 5\n"));
2924 Trace.SetMode(RBTrace::EEnable);
2925 e = p.Create(KHeapCorrApp, KCorruptionSpecial1);
2929 User::WaitForRequest(status);
2931 size = Trace.GetData(trace);
2933 res = FindHeapCorruptionTrace(trace, size, payloadSize);
2935 test(payloadSize == 12); //payload in this case must be 12 bytes long (3x4bytes)
2949 TUint32 KUtracePcValues[3]={0, 0x123456, 0x987654};
2951 #define T_UTRACE_HEADER(aSize,aClassification,aContext,aPc) \
2952 ((((aSize) + (aContext?4:0) + (aPc?4:0)) << BTrace::ESizeIndex*8) \
2953 +(((aContext?BTrace::EContextIdPresent:0) | (aPc?BTrace::EPcPresent:0)) << BTrace::EFlagsIndex*8) \
2954 +((aClassification) << BTrace::ECategoryIndex*8) \
2955 +((KTest1SubCategory) << BTrace::ESubCategoryIndex*8))
2957 #define UTRACE_SECONDARY(aClassification,aModuleUid,aThreadIdPresent,aPcPresent,aPc,aFormatId) \
2958 BTrace::OutFilteredPcFormatBig(T_UTRACE_HEADER(8,aClassification,aThreadIdPresent,aPcPresent),(TUint32)(aModuleUid),aPc,aFormatId,0,0)
2960 #define UTRACE_SECONDARY_4(aClassification,aModuleUid,aThreadIdPresent,aPcPresent,aPc,aFormatId, aData1) \
2961 BTrace::OutFilteredPcFormatBig(T_UTRACE_HEADER(8,aClassification,aThreadIdPresent,aPcPresent),(TUint32)(aModuleUid),aPc,aFormatId,&aData1,4)
2963 #define UTRACE_SECONDARY_ANY(aClassification, aModuleUid, aThreadIdPresent, aPcPresent, aPc, aFormatId, aData, aDataSize) \
2964 BTrace::OutFilteredPcFormatBig(T_UTRACE_HEADER(8,aClassification,aThreadIdPresent,aPcPresent),(TUint32)(aModuleUid),aPc,aFormatId,aData,(TInt)(aDataSize))
2966 void UTraceUserBenchmark(TUint& aTime1,TUint& aTime2,TUint& aTime3,TBool aTraceEnabled)
2968 TInt oldSize = Trace.BufferSize();
2971 TRequestStatus status;
2972 test_KErrNone(timer.CreateLocal());
2974 TInt r = Trace.ResizeBuffer(0x1000);
2976 Trace.SetMode(RBTrace::EFreeRunning|RBTrace::EEnable);
2978 timer.After(status,1);
2979 User::WaitForRequest(status);
2980 timer.After(status,1000000);
2982 TUint32* frm = (TUint32*)KTestTrace1;
2983 TUint16 formatId = (TUint16)frm[2];
2987 UTRACE_SECONDARY(BTrace::ETest1,KBTraceFilterTestUid1,EFalse,EFalse,0,formatId);
2990 while(status==KRequestPending);
2991 User::WaitForRequest(status);
2993 TInt size = Trace.GetData(data);
2994 test(aTraceEnabled ? size!=0 : size==0);
2996 aTime1 = 1000000000/r;
2998 r = Trace.ResizeBuffer(0x1000);
3000 Trace.SetMode(RBTrace::EFreeRunning|RBTrace::EEnable);
3002 timer.After(status,1);
3003 User::WaitForRequest(status);
3004 timer.After(status,1000000);
3008 //BTraceFilteredContextN(BTrace::ETest1,0,KBTraceFilterTestUid1,0,KTestTrace1,KMaxBTraceDataArray);
3009 UTRACE_SECONDARY_ANY(BTrace::ETest1,KBTraceFilterTestUid1,ETrue,EFalse,0,formatId,KTestTrace1,KMaxBTraceDataArray);
3012 while(status==KRequestPending);
3013 User::WaitForRequest(status);
3014 size = Trace.GetData(data);
3015 test(aTraceEnabled ? size!=0 : size==0);
3017 aTime2 = 1000000000/r;
3019 timer.After(status,1);
3020 User::WaitForRequest(status);
3021 timer.After(status,1000000);
3026 check = BTrace::CheckFilter2(BTrace::ETest1,KBTraceFilterTestUid1);
3029 while(status==KRequestPending);
3030 test(check == aTraceEnabled);
3031 aTime3 = 1000000000/r;
3033 r = Trace.ResizeBuffer(oldSize);
3037 //---------------------------------------------
3038 //! @SYMTestCaseID KBASE-T_BTRACE-2442
3041 //! @SYMTestCaseDesc Benchmark utracing.
3042 //! @SYMTestActions Time the generation of minimum and maximum sized utraces both with
3043 //! and without the trace filter enabled for the trace category.
3044 //! @SYMTestExpectedResults Trace time with filter enabled should not excede 2000 nano-seconds,
3045 //! and time with filter disabled should not excede 500 nano-seconds. (These limits are not
3046 //! asserted). If time significantly excedes this then detailed investigation is required.
3047 //! @SYMTestPriority Medium
3048 //! @SYMTestStatus Prototype
3049 //---------------------------------------------
3050 void TestUtraceBenchmark(TBool aUserTrace)
3055 //This uses btrace kernel benching atm, need to change once kernel is implemented
3056 #define UBENCH(a1) aUserTrace ? UTraceUserBenchmark(t1,t2,t3,a1) : KernelBenchmark(t1,t2,t3,a1,1)
3058 test.Printf(_L(" Min Trace Max Trace Filter\n"));
3060 Trace.SetFilter(BTrace::ETest1,0);
3061 Trace.SetFilter2(0);
3063 test.Printf(_L("filter1 off filter2 off %6d ns %6d ns %6d ns\n"),t1,t2,t3);
3065 Trace.SetFilter(BTrace::ETest1,1);
3066 Trace.SetFilter2(0);
3068 test.Printf(_L("filter1 on global filter2 off %6d ns %6d ns %6d ns\n"),t1,t2,t3);
3070 Trace.SetFilter2(1);
3072 test.Printf(_L("filter1 on global filter2 on %6d ns %6d ns %6d ns\n"),t1,t2,t3);
3074 Trace.SetFilter2(&KBTraceFilterTestUid2,1);
3076 test.Printf(_L("filter1 on 1 UID filter2 off %6d ns %6d ns %6d ns\n"),t1,t2,t3);
3078 Trace.SetFilter2(&KBTraceFilterTestUid1,1);
3080 test.Printf(_L("filter1 on 1 UID filter2 on %6d ns %6d ns %6d ns\n"),t1,t2,t3);
3082 Trace.SetFilter2(BigFilter2,sizeof(BigFilter2)/sizeof(TUint32));
3083 Trace.SetFilter2(KBTraceFilterTestUid1,0);
3085 test.Printf(_L("filter1 on 100 UID filter2 off %6d ns %6d ns %6d ns\n"),t1,t2,t3);
3087 Trace.SetFilter2(BigFilter2,sizeof(BigFilter2)/sizeof(TUint32));
3089 test.Printf(_L("filter1 on 100 UID filter2 on %6d ns %6d ns %6d ns\n"),t1,t2,t3);
3091 Trace.SetFilter(BTrace::ETest1,0);
3092 Trace.SetFilter2(0);
3096 void CallUtrace(TBool aType, TBool aContextPresent, TBool aPcPresent, TInt aSizeOfData)
3098 if(!(aType&RBTraceTest::EUserTrace))
3100 // use driver to create a kernel trace...
3101 TraceTest.Trace(aType,KTestTrace1,aSizeOfData);
3105 TUint32* data = (TUint32*)KTestTrace1;
3106 TUint16 formatId = (TUint16)data[2];
3107 //multiparted traces (depending on size)
3108 if(aSizeOfData <= 0)
3110 UTRACE_SECONDARY(BTrace::ETest1, KBTraceFilterTestUid1, aContextPresent, aPcPresent, KUtracePcValues[1], formatId);
3111 UTRACE_SECONDARY(BTrace::ETest1, KBTraceFilterTestUid1, aContextPresent, aPcPresent, KUtracePcValues[2], formatId);
3113 else if(aSizeOfData <= 4)
3115 UTRACE_SECONDARY_4(BTrace::ETest1, KBTraceFilterTestUid1, aContextPresent, aPcPresent, KUtracePcValues[1], formatId, data[3]);
3116 UTRACE_SECONDARY_4(BTrace::ETest1, KBTraceFilterTestUid1, aContextPresent, aPcPresent, KUtracePcValues[2], formatId, data[3]);
3118 else //aSizeOfData > 8
3120 UTRACE_SECONDARY_ANY(BTrace::ETest1, KBTraceFilterTestUid1, aContextPresent, aPcPresent, KUtracePcValues[1], formatId, data+3, aSizeOfData);
3121 UTRACE_SECONDARY_ANY(BTrace::ETest1, KBTraceFilterTestUid1, aContextPresent, aPcPresent, KUtracePcValues[2], formatId, data+3, aSizeOfData);
3122 //BTraceFilteredContextPcBig(BTrace::ETest1,KTest1SubCategory,KBTraceFilterTestUid1,data+2,aSizeOfData-4);
3123 //BTraceFilteredContextPcBig(BTrace::ETest1,KTest1SubCategory,KBTraceFilterTestUid1,data+2,aSizeOfData-4);
3128 void CheckUtraceFlags(TUint8* aData, TUint8* aData2, TBool aContextPresent, TBool aPcPresent)
3130 TUint offset = ContextOffset(aData);
3133 aContextPresent = BTrace::EContextIdPresent;
3134 test((aContextPresent == (aData[BTrace::EFlagsIndex]&BTrace::EContextIdPresent)));
3135 test_Equal(ThisTraceContextId, ((TUint32*)(aData+offset))[0] );
3136 test_Equal(ThisTraceContextId, ((TUint32*)(aData2+offset))[0] );
3140 aPcPresent = BTrace::EPcPresent;
3141 test((aPcPresent == (aData[BTrace::EFlagsIndex]&BTrace::EPcPresent)));
3144 test_Compare(((TUint32*)(aData+offset))[1], ==, KUtracePcValues[1]); //(offset plus 1 because context id is before pc)
3145 test_Compare(((TUint32*)(aData2+offset))[1], ==, KUtracePcValues[2]);
3149 test_Compare(((TUint32*)(aData+offset))[0], ==, KUtracePcValues[1]);
3150 test_Compare(((TUint32*)(aData2+offset))[0], ==, KUtracePcValues[2]);
3155 void SetupTestDataForUtrace(TBool aChangeData = ETrue)
3157 if(aChangeData)//change to accomodate iFormatId only being 16 bit
3159 KTestTrace1[10] = (TUint8) 0;
3160 KTestTrace1[11] = (TUint8) 0;
3162 else //restore to original data
3164 KTestTrace1[10] = (TUint8) 10;
3165 KTestTrace1[11] = (TUint8) 11;
3169 //---------------------------------------------
3170 //! @SYMTestCaseID KBASE-T_BTRACE-2441
3173 //! @SYMTestCaseDesc Test UTraces, including multiparted utraces, only testing user side for now, kernel side will be added later
3174 //! @SYMTestActions Generate traces from kernel code using the UTrace macros as defined above,
3175 //! @SYMTestExpectedResults Traces where broken down into multiple parts and
3176 //! all trace contents captured by RBTrace matched those specified
3177 //! at point of trace generation. Also, where appropriate, PC and/or
3178 //! Context ID values are present and correct.
3179 //! @SYMTestPriority High
3180 //! @SYMTestStatus Prototype
3181 //---------------------------------------------
3182 void TestUtrace(TBool aUserTrace, TBool aFilter2)
3184 test.Next(_L("Testing utrace\n"));
3185 TInt oldSize = Trace.BufferSize();
3186 TInt r = Trace.ResizeBuffer(0x100000);
3188 Trace.SetMode(RBTrace::EEnable);
3190 //set up the test data for UTrace
3191 SetupTestDataForUtrace();
3193 // dummy trace do get current thread context id
3194 Trace.SetFilter(BTrace::ETest1,0);
3195 ThisTraceContextId = TraceTest.Trace(BTrace::EContextIdPresent,KTestTrace1,0);
3197 // create a test filter...
3198 TInt extraFlags = 0;
3200 extraFlags |= RBTraceTest::EUserTrace;
3204 extraFlags |= RBTraceTest::EFilter2Trace;
3208 //Test that filtering works...
3210 for(filterMode=0; filterMode<(aFilter2?6:2); ++filterMode)
3214 Trace.SetFilter(BTrace::ETest1,1);
3215 Trace.SetFilter2(BigFilter2,KNumBTraceFilterTestUids);
3216 if(filterMode==0 || filterMode==2)
3217 Trace.SetFilter(BTrace::ETest1,0); // disable in primary filter
3218 if(filterMode==0 || filterMode==1)
3219 Trace.SetFilter2(KBTraceFilterTestUid1,0); // disable in secondary filter
3221 Trace.SetFilter2(0); // disable entire secondary filter
3223 Trace.SetFilter2(1); // enable entire secondary filter
3225 // expectTrace is true if we expect trace to be output...
3226 TBool expectTrace = aFilter2 ? (filterMode==3 || filterMode==5) : filterMode&1;
3230 case 0: test.Next(_L("Test with primary filter OFF, secondary filter OFF")); break;
3231 case 1: test.Next(_L("Test with primary filter ON, secondary filter OFF")); break;
3232 case 2: test.Next(_L("Test with primary filter OFF, secondary filter ON")); break;
3233 case 3: test.Next(_L("Test with primary filter ON, secondary filter ON")); break;
3234 case 4: test.Next(_L("Test with primary filter ON, global secondary filter OFF")); break;
3235 case 5: test.Next(_L("Test with primary filter ON, global secondary filter ON")); break;
3238 TBool contextPresent = EFalse;
3239 TBool pcPresent = EFalse;
3240 for(TInt flags = 0; flags < 4; flags++)
3244 case 0: test.Printf(_L("ContextId OFF, Pc OFF\n")); break;
3245 case 1: contextPresent = ETrue; extraFlags = BTrace::EContextIdPresent|BTrace::EPcPresent|extraFlags; test.Printf(_L("ContextId ON, Pc OFF\n"));break;
3246 case 2: pcPresent = ETrue; extraFlags = BTrace::EContextIdPresent|BTrace::EPcPresent|extraFlags; test.Printf(_L("ContextId OFF, Pc ON\n"));break;
3247 case 3: contextPresent = ETrue; pcPresent = ETrue; extraFlags = BTrace::EContextIdPresent|BTrace::EPcPresent|extraFlags; test.Printf(_L("ContextId ON, Pc ON\n"));break;
3250 // multiparted traces...
3251 BigTraceBeginTest();
3252 for(TInt i=0; i<=(TInt)sizeof(KTestTrace1)-4; i++)
3254 //CallUtrace(typeOfCall, contextPresent, pcPresent, i);
3255 CallUtrace(extraFlags, contextPresent, pcPresent, i);
3259 TInt size = Trace.GetData(data);
3268 TInt sizePlusFormatId = i + 8;
3269 test(CheckBigTrace1(data, size, sizePlusFormatId, KTest1SubCategory, 4));
3270 test(CheckBigTrace1(data2, size, sizePlusFormatId, KTest1SubCategory, 4));
3272 CheckUtraceFlags(data, data2, contextPresent, pcPresent);
3275 test_Equal(expectTrace,BigTraceEndTest()); // check we actually got multipart traces
3279 //Restore trace data
3280 SetupTestDataForUtrace(EFalse);
3282 test.Next(_L("Restore buffer\n"));
3283 r = Trace.ResizeBuffer(oldSize);
3285 Trace.SetFilter2(0);
3290 GLDEF_C TInt E32Main()
3292 // initialise test trace data...
3293 KTestTrace1[0] = BTrace::ETest1;
3295 for(i=8; i<sizeof(KTestTrace1); i++)
3297 KTestTrace1[i] = (TUint8)i;
3298 KTestTrace2[i] = (TUint8)~i;
3300 KTestTrace1[4] = (KBTraceFilterTestUid1>>0)&0xff;
3301 KTestTrace1[5] = (KBTraceFilterTestUid1>>8)&0xff;
3302 KTestTrace1[6] = (KBTraceFilterTestUid1>>16)&0xff;
3303 KTestTrace1[7] = (KBTraceFilterTestUid1>>24)&0xff;
3305 KTestTrace2[4] = (KBTraceFilterTestUid2>>0)&0xff;
3306 KTestTrace2[5] = (KBTraceFilterTestUid2>>8)&0xff;
3307 KTestTrace2[6] = (KBTraceFilterTestUid2>>16)&0xff;
3308 KTestTrace2[7] = (KBTraceFilterTestUid2>>24)&0xff;
3310 for(i=0; i<KNumBTraceFilterTestUids; i++)
3311 BigFilter2[i] = KBTraceFilterTestUid+i;
3316 test.Start(_L("Open LDD"));
3320 test.Next(_L("Open test LDD"));
3321 r = User::LoadLogicalDevice(RBTraceTest::Name());
3322 test(r==KErrNone || r==KErrAlreadyExists);
3323 r = TraceTest.Open();
3326 // save trace settings...
3327 TUint savedMode = Trace.Mode();
3328 SetBTraceFilter(OldTraceFilter,OldTraceFilter);
3330 TBuf<256> commandLine;
3331 User::CommandLine(commandLine);
3332 if(commandLine==_L("dump"))
3334 test.Next(_L("Dumping trace buffer..."));
3338 else if(commandLine==_L("soak"))
3340 test.Next(_L("Running endless soak test..."));
3343 test.Next(_L("Soak test in free-running mode"));
3344 TestSoak(RBTrace::EFreeRunning,60);
3345 test.Next(_L("Soak test in sample mode"));
3350 test.Next(_L("Basic tests in sample mode"));
3352 test.Next(_L("Basic tests in free-running mode"));
3353 TestBasics(RBTrace::EFreeRunning);
3354 test.Next(_L("User BTrace test in sample mode"));
3356 test.Next(_L("Check secondary filter"));
3359 test.Next(_L("Test user traces"));
3360 TestTrace(ETrue,EFalse);
3361 test.Next(_L("Test kernel traces"));
3362 TestTrace(EFalse,EFalse);
3363 test.Next(_L("Test user traces using secondary filter"));
3364 TestTrace(ETrue,ETrue);
3365 test.Next(_L("Test kernel traces using secondary filter"));
3366 TestTrace(EFalse,ETrue);
3368 test.Next(_L("Big user traces"));
3369 TestBig(ETrue,EFalse);
3370 test.Next(_L("Big kernel traces"));
3371 TestBig(EFalse,EFalse);
3372 test.Next(_L("Big user traces using secondary filter"));
3373 TestBig(ETrue,ETrue);
3374 test.Next(_L("Big kernel traces using secondary filter"));
3375 TestBig(EFalse,ETrue);
3377 test.Next(_L("Test category EThreadIdentification"));
3378 TestThreadIdentification();
3379 test.Next(_L("Test category ECpuUsage"));
3382 test.Next(_L("Soak test in sample mode"));
3384 test.Next(_L("Soak test in free-running mode"));
3385 TestSoak(RBTrace::EFreeRunning,10);
3387 test.Next(_L("Benchmark kernel tracing"));
3389 test.Next(_L("Benchmark user tracing"));
3392 test.Next(_L("Test category EHeap"));
3393 TestHeapAndChunkTrace();
3395 test.Next(_L("Test user side utraces"));
3396 TestUtrace(ETrue, ETrue);
3397 //Kernel side is currently not implemented
3398 //test.Next(_L("Test kernel side utraces"));
3399 //TestUtrace(EFalse, ETrue);
3400 test.Next(_L("Benchmark user side UTraces"));
3401 TestUtraceBenchmark(ETrue);
3404 // restore trace settin gs...
3406 SetBTraceFilter(OldTraceFilter,OldTraceFilter);
3407 Trace.SetMode(savedMode);
3409 test.Next(_L("Close LDD"));
3412 User::FreeLogicalDevice(RBTraceTest::Name());
3414 //test RHeap instrumentation:
3415 //with BTrace:EHeap:EHeapAllocFail trace points
3416 TestHeapAllocFailEvent(BTrace::EHeapAllocFail);
3417 //with BTrace:EHeap:EHeapReAllocFail trace points
3418 TestHeapAllocFailEvent(BTrace::EHeapReAllocFail);
3419 //with BTrace:EHeap:EHeapCorruption trace points
3420 TestHeapCorruptionEvents();