0
|
1 |
// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// e32test\debug\T_TRACEREDIRECT.cpp
|
|
15 |
// Print out RDebug::Prints captured by the 'trace redirection' LDD
|
|
16 |
//
|
|
17 |
//
|
|
18 |
|
|
19 |
#include <e32cmn.h>
|
|
20 |
#include <e32cmn_private.h>
|
|
21 |
#include "d_traceredirect.h"
|
|
22 |
#include <e32debug.h>
|
|
23 |
#include <e32test.h>
|
|
24 |
|
|
25 |
RTest test(_L("T_TRACEREDIRECT"));
|
|
26 |
|
|
27 |
RTraceRedirect ldd;
|
|
28 |
|
|
29 |
|
|
30 |
TInt noisythreadfn(TAny *)
|
|
31 |
{
|
|
32 |
|
|
33 |
for (TInt i=0; i<12; i++)
|
|
34 |
{
|
|
35 |
|
|
36 |
User::After(700000); // 2+1/2 a second
|
|
37 |
RDebug::Print(_L("Noisy thread 1 @ %lx"), User::TickCount());
|
|
38 |
}
|
|
39 |
RDebug::Print(_L("END"));
|
|
40 |
return KErrNone;
|
|
41 |
}
|
|
42 |
|
|
43 |
TInt noisythreadfn2(TAny *)
|
|
44 |
{
|
|
45 |
|
|
46 |
for (TInt i=0; i<20; i++)
|
|
47 |
{
|
|
48 |
|
|
49 |
User::After(300000); // 2+1/2 a second
|
|
50 |
RDebug::Print(_L("Noisy thread 2 @ %lx"), User::TickCount());
|
|
51 |
}
|
|
52 |
return KErrNone;
|
|
53 |
}
|
|
54 |
|
|
55 |
GLDEF_C TInt E32Main()
|
|
56 |
{
|
|
57 |
test.Title();
|
|
58 |
TInt r;
|
|
59 |
|
|
60 |
test.Start(_L("Loading LDD"));
|
|
61 |
r = User::LoadLogicalDevice(_L("D_TRACEREDIRECT"));
|
|
62 |
test(r==KErrNone || r==KErrAlreadyExists);
|
|
63 |
|
|
64 |
TBool logged=test.Logged();
|
|
65 |
test.SetLogged(EFalse);
|
|
66 |
test.Next(_L("Open channel to LDD"));
|
|
67 |
r = ldd.Open();
|
|
68 |
test(r==KErrNone);
|
|
69 |
|
|
70 |
|
|
71 |
test.Next(_L("Setup noisy thread"));
|
|
72 |
RThread thread;
|
|
73 |
TRequestStatus threadstat;
|
|
74 |
r=thread.Create(KNullDesC,noisythreadfn,KDefaultStackSize,&User::Allocator(),NULL);
|
|
75 |
test(r==KErrNone);
|
|
76 |
thread.Logon(threadstat);
|
|
77 |
thread.Resume();
|
|
78 |
RThread thread2;
|
|
79 |
TRequestStatus threadstat2;
|
|
80 |
r=thread2.Create(KNullDesC,noisythreadfn2,KDefaultStackSize,&User::Allocator(),NULL);
|
|
81 |
test(r==KErrNone);
|
|
82 |
thread2.Logon(threadstat2);
|
|
83 |
thread2.Resume();
|
|
84 |
|
|
85 |
test.Next(_L("Capture RDebug::Prints until 'END' is captured"));
|
|
86 |
TBuf8<256> buf;
|
|
87 |
TBuf16<256> buf16;
|
|
88 |
FOREVER
|
|
89 |
{
|
|
90 |
test(ldd.NextTrace(buf) == KErrNone);
|
|
91 |
buf16.Copy(buf);
|
|
92 |
if (buf16!=_L(""))
|
|
93 |
test.Printf(_L("Captured: '%S'\n"),&buf16);
|
|
94 |
if (buf16==_L("END"))
|
|
95 |
break;
|
|
96 |
buf=_L8("");
|
|
97 |
User::After(250000); // poll every half a second
|
|
98 |
}
|
|
99 |
test.SetLogged(logged);
|
|
100 |
|
|
101 |
test.Next(_L("Wait for noisy thread to die"));
|
|
102 |
User::WaitForRequest(threadstat);
|
|
103 |
User::WaitForRequest(threadstat2);
|
|
104 |
test(threadstat==KErrNone);
|
|
105 |
|
|
106 |
test.Next(_L("Closing ldd"));
|
|
107 |
ldd.Close();
|
|
108 |
|
|
109 |
test.End();
|
|
110 |
|
|
111 |
return(0);
|
|
112 |
}
|
|
113 |
|