24
|
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 "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 |
// EtelPacketTestMultipleClients.cpp
|
|
15 |
// This file tests the scenario of Multiple Clients using the Packet API simultaneously.
|
|
16 |
// It is primarily used to exercise the mutex in the methods RPacketContext::OpenNewContext()
|
|
17 |
// and RPacketContext::OpenNewSecondaryContext().
|
|
18 |
//
|
|
19 |
//
|
|
20 |
|
|
21 |
|
|
22 |
// Symbian OS includes
|
|
23 |
#include <e32base.h>
|
|
24 |
#include <e32std.h>
|
|
25 |
|
|
26 |
#include <etelpckt.h>
|
|
27 |
#include <pcktcs.h>
|
|
28 |
|
|
29 |
#include "Te_EtelPacketTestStepBase.h"
|
|
30 |
|
|
31 |
#include "testdef.h"
|
|
32 |
|
|
33 |
#include "Te_EtelPacketTestMultipleClients.h"
|
|
34 |
#include "Te_etelpckt_defs.h"
|
|
35 |
|
|
36 |
|
|
37 |
// constructor
|
|
38 |
CEtelPacketTestMultipleClients::CEtelPacketTestMultipleClients()
|
|
39 |
{
|
|
40 |
// store the name of this test case
|
|
41 |
SetTestStepName(_L("Multiple_Clients"));
|
|
42 |
}
|
|
43 |
|
|
44 |
// destructor
|
|
45 |
CEtelPacketTestMultipleClients::~CEtelPacketTestMultipleClients()
|
|
46 |
{
|
|
47 |
}
|
|
48 |
|
|
49 |
|
|
50 |
enum TVerdict CEtelPacketTestMultipleClients::doTestStepL( void )
|
|
51 |
/**
|
|
52 |
* Test step Multiple_Clients tests simultaneous use of the API by Multiple clients.
|
|
53 |
*/
|
|
54 |
{
|
|
55 |
// Allocate the size of the stack and heap objects
|
|
56 |
const TInt KStackSize=0x8000;
|
|
57 |
const TInt KHeapSize=0x8000;
|
|
58 |
const TInt KMaxHeapSize=0x80000;
|
|
59 |
|
|
60 |
// Create 2 RThread objects
|
|
61 |
_LIT(KClientApp1ThreadName,"ClientApp1");
|
|
62 |
_LIT(KClientApp2ThreadName,"ClientApp2");
|
|
63 |
|
|
64 |
RThread thread1;
|
|
65 |
RThread thread2;
|
|
66 |
|
|
67 |
TInt res1=thread1.Create(KClientApp1ThreadName,ContextCreationFunction,
|
|
68 |
KStackSize,KHeapSize,KMaxHeapSize,this);
|
|
69 |
|
|
70 |
TInt res2=thread2.Create(KClientApp2ThreadName,ContextCreationFunction,
|
|
71 |
KStackSize,KHeapSize,KMaxHeapSize,this);
|
|
72 |
|
|
73 |
TRequestStatus thread1Status;
|
|
74 |
TRequestStatus thread2Status;
|
|
75 |
TBool req1Complete=EFalse;
|
|
76 |
TBool req2Complete=EFalse;
|
|
77 |
|
|
78 |
// If both threads have been created successfully, start their execution
|
|
79 |
if (res1==KErrNone && res2==KErrNone)
|
|
80 |
{
|
|
81 |
thread1.Logon(thread1Status);
|
|
82 |
thread2.Logon(thread2Status);
|
|
83 |
thread1.Resume();
|
|
84 |
thread2.Resume();
|
|
85 |
|
|
86 |
while ( req1Complete==EFalse || req2Complete==EFalse)
|
|
87 |
{
|
|
88 |
User::WaitForAnyRequest();
|
|
89 |
if (thread1Status != KRequestPending && req1Complete==EFalse)
|
|
90 |
{
|
|
91 |
CHECKPOINT(thread1Status.Int(),KErrNone,CHP_CNTXT_CASE("A.MC2"));
|
|
92 |
req1Complete=ETrue;
|
|
93 |
}
|
|
94 |
if (thread2Status != KRequestPending && req2Complete==EFalse)
|
|
95 |
{
|
|
96 |
CHECKPOINT(thread2Status.Int(),KErrNone,CHP_CNTXT_CASE("A.MC3"));
|
|
97 |
req2Complete=ETrue;
|
|
98 |
}
|
|
99 |
} // while statement
|
|
100 |
} // if statement
|
|
101 |
|
|
102 |
thread1.Close();
|
|
103 |
thread2.Close();
|
|
104 |
|
|
105 |
return TestStepResult();
|
|
106 |
}
|
|
107 |
|
|
108 |
|
|
109 |
TInt CEtelPacketTestMultipleClients::ContextCreationFunction(TAny* /*aThread*/ )
|
|
110 |
/**
|
|
111 |
* Static thread function. A primary and secondary context are created in this function.
|
|
112 |
* The following sequence is carried out in order to create a secondary context:
|
|
113 |
* Connect to the Telephony server, Load the Telephony module, open handles to a phone,
|
|
114 |
* packet service and primary context object.
|
|
115 |
* Once the secondary context is created, all the handles are closed. Context
|
|
116 |
* functionality is exercised in other test modules and is not repeated here.
|
|
117 |
* Note that logging is done explicitly in this function to the generated test result
|
|
118 |
* file. This is to enable a tester examine the behaviour of this test without having to
|
|
119 |
* resort to checking the dummy TSY logs.
|
|
120 |
*
|
|
121 |
* Note The logging code has been temporarily commented out. This is because the logging
|
|
122 |
* used by the test harness, scheduletest is not thread safe for multithreaded calls.
|
|
123 |
* When the test harness has been modified (either by making it thread safe for multithreaded
|
|
124 |
* calls or by using FLOGGER, the logging for this test case should be updated.
|
|
125 |
* - 16/05/02
|
|
126 |
*/
|
|
127 |
{
|
|
128 |
// Create a cleanup stack object
|
|
129 |
CTrapCleanup* cleanup=CTrapCleanup::New();
|
|
130 |
if (cleanup==NULL)
|
|
131 |
return KErrNoMemory;
|
|
132 |
|
|
133 |
|
|
134 |
// Use the 'this' pointer to access functionality available to the test step class.
|
|
135 |
//CEtelPacketTestMultipleClients* ptr = (CEtelPacketTestMultipleClients*) aThreadData;
|
|
136 |
//ptr->INFO_PRINTF1(_L("Thread %d finished Wait()."), RThread().Id());
|
|
137 |
|
|
138 |
|
|
139 |
// Establish a connection to the ETel Server and open handles for this thread.
|
|
140 |
// An arbitrary value of 20 is assigned for the buffer size for the context names.
|
|
141 |
// Using a TName object would incur a significant load on the stack, which is
|
|
142 |
// unnecessary for this test code.
|
|
143 |
RTelServer server;
|
|
144 |
RPhone pcktPhone;
|
|
145 |
RPacketService wcdmaService;
|
|
146 |
RPacketContext primaryContext;
|
|
147 |
RPacketContext wcdmaContext;
|
|
148 |
TBuf<20> contextName;
|
|
149 |
TBuf<20> secondaryContextName;
|
|
150 |
|
|
151 |
TInt ret= KErrNone;
|
|
152 |
|
|
153 |
if ( (ret=server.Connect())==KErrNone)
|
|
154 |
{
|
|
155 |
//ptr->INFO_PRINTF1(_L("Thread %d: Connect to ETel server - Pass."), RThread().Id());
|
|
156 |
if ( (ret=server.LoadPhoneModule(DPCKTTSY_MODULE_NAME))==KErrNone)
|
|
157 |
{
|
|
158 |
//ptr->INFO_PRINTF1(_L("Thread %d: Load phone module - Pass."), RThread().Id());
|
|
159 |
if ( (ret=pcktPhone.Open(server,DPCKTTSY_PHONE_NAME))==KErrNone)
|
|
160 |
{
|
|
161 |
//ptr->INFO_PRINTF1(_L("Thread %d: Open Packet phone - Pass."), RThread().Id());
|
|
162 |
if ( (ret=wcdmaService.Open(pcktPhone))==KErrNone)
|
|
163 |
{
|
|
164 |
//ptr->INFO_PRINTF1(_L("Thread %d: Open Packet service - Pass."), RThread().Id());
|
|
165 |
if ( (ret=primaryContext.OpenNewContext(wcdmaService, contextName))==KErrNone)
|
|
166 |
{
|
|
167 |
//ptr->INFO_PRINTF1(_L("Thread %d: Open Primary context - Pass."), RThread().Id());
|
|
168 |
if ( (ret=wcdmaContext.OpenNewSecondaryContext(wcdmaService, contextName, secondaryContextName))==KErrNone)
|
|
169 |
{
|
|
170 |
//ptr->INFO_PRINTF1(_L("Thread %d: Open Secondary context - Pass."), RThread().Id());
|
|
171 |
wcdmaContext.Close();
|
|
172 |
//ptr->INFO_PRINTF1(_L("Thread %d: Close Secondary context - Pass."), RThread().Id());
|
|
173 |
}
|
|
174 |
primaryContext.Close();
|
|
175 |
//ptr->INFO_PRINTF1(_L("Thread %d: Close Primary context - Pass."), RThread().Id());
|
|
176 |
}
|
|
177 |
wcdmaService.Close();
|
|
178 |
//ptr->INFO_PRINTF1(_L("Thread %d: Close Packet service - Pass."), RThread().Id());
|
|
179 |
}
|
|
180 |
pcktPhone.Close();
|
|
181 |
//ptr->INFO_PRINTF1(_L("Thread %d: Close Packet phone - Pass."), RThread().Id());
|
|
182 |
}
|
|
183 |
server.UnloadPhoneModule(DPCKTTSY_MODULE_NAME);
|
|
184 |
//ptr->INFO_PRINTF1(_L("Thread %d: Unload phone module - Pass."), RThread().Id());
|
|
185 |
}
|
|
186 |
server.Close();
|
|
187 |
//ptr->INFO_PRINTF1(_L("Thread %d: Close ETel server - Pass."), RThread().Id());
|
|
188 |
}
|
|
189 |
|
|
190 |
delete cleanup;
|
|
191 |
|
|
192 |
return ret;
|
|
193 |
}
|