sl@0
|
1 |
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// e32test\system\d_atomic.cpp
|
sl@0
|
15 |
// LDD for testing atomic operations
|
sl@0
|
16 |
//
|
sl@0
|
17 |
//
|
sl@0
|
18 |
|
sl@0
|
19 |
#include <kernel/kern_priv.h>
|
sl@0
|
20 |
#include "t_atomic.h"
|
sl@0
|
21 |
|
sl@0
|
22 |
class DAtomicTest;
|
sl@0
|
23 |
struct TPerThreadK : public TPerThread
|
sl@0
|
24 |
{
|
sl@0
|
25 |
TAny* iOldExtraContext;
|
sl@0
|
26 |
const SSlowExecEntry* iOldSlowExecTable;
|
sl@0
|
27 |
DAtomicTest* iCh;
|
sl@0
|
28 |
TInt iId;
|
sl@0
|
29 |
};
|
sl@0
|
30 |
|
sl@0
|
31 |
|
sl@0
|
32 |
class DAtomicTestFactory : public DLogicalDevice
|
sl@0
|
33 |
{
|
sl@0
|
34 |
public:
|
sl@0
|
35 |
DAtomicTestFactory();
|
sl@0
|
36 |
~DAtomicTestFactory();
|
sl@0
|
37 |
virtual TInt Install();
|
sl@0
|
38 |
virtual void GetCaps(TDes8& aDes) const;
|
sl@0
|
39 |
virtual TInt Create(DLogicalChannelBase*& aChannel);
|
sl@0
|
40 |
public:
|
sl@0
|
41 |
};
|
sl@0
|
42 |
|
sl@0
|
43 |
|
sl@0
|
44 |
class DAtomicTest : public DLogicalChannelBase
|
sl@0
|
45 |
{
|
sl@0
|
46 |
public:
|
sl@0
|
47 |
virtual ~DAtomicTest();
|
sl@0
|
48 |
protected:
|
sl@0
|
49 |
virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
|
sl@0
|
50 |
virtual TInt Request(TInt aFunction, TAny* a1, TAny* a2);
|
sl@0
|
51 |
private:
|
sl@0
|
52 |
void SetupExecTable();
|
sl@0
|
53 |
static TInt XGetThreadInfo(TAny* aDest);
|
sl@0
|
54 |
static TInt XSetThreadInfo(const TAny* aSrc);
|
sl@0
|
55 |
static TInt XAtomicAction(TAny* aPtr);
|
sl@0
|
56 |
static TInt XRestore();
|
sl@0
|
57 |
private:
|
sl@0
|
58 |
TUint64A iReg;
|
sl@0
|
59 |
TPerThreadK iPerThread[KMaxThreads];
|
sl@0
|
60 |
TUint32 iXT[19];
|
sl@0
|
61 |
};
|
sl@0
|
62 |
|
sl@0
|
63 |
|
sl@0
|
64 |
DAtomicTestFactory::DAtomicTestFactory()
|
sl@0
|
65 |
{
|
sl@0
|
66 |
}
|
sl@0
|
67 |
|
sl@0
|
68 |
DAtomicTestFactory::~DAtomicTestFactory()
|
sl@0
|
69 |
{
|
sl@0
|
70 |
}
|
sl@0
|
71 |
TInt DAtomicTestFactory::Create(DLogicalChannelBase*& aChannel)
|
sl@0
|
72 |
{
|
sl@0
|
73 |
aChannel = new DAtomicTest;
|
sl@0
|
74 |
return KErrNone;
|
sl@0
|
75 |
}
|
sl@0
|
76 |
|
sl@0
|
77 |
TInt DAtomicTestFactory::Install()
|
sl@0
|
78 |
{
|
sl@0
|
79 |
return SetName(&KAtomicTestLddName);
|
sl@0
|
80 |
}
|
sl@0
|
81 |
|
sl@0
|
82 |
void DAtomicTestFactory::GetCaps(TDes8& aDes) const
|
sl@0
|
83 |
{
|
sl@0
|
84 |
// Not used but required as DLogicalDevice::GetCaps is pure virtual
|
sl@0
|
85 |
}
|
sl@0
|
86 |
|
sl@0
|
87 |
DECLARE_STANDARD_LDD()
|
sl@0
|
88 |
{
|
sl@0
|
89 |
return new DAtomicTestFactory;
|
sl@0
|
90 |
}
|
sl@0
|
91 |
|
sl@0
|
92 |
|
sl@0
|
93 |
TInt DAtomicTest::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
|
sl@0
|
94 |
{
|
sl@0
|
95 |
SetupExecTable();
|
sl@0
|
96 |
return KErrNone;
|
sl@0
|
97 |
}
|
sl@0
|
98 |
|
sl@0
|
99 |
DAtomicTest::~DAtomicTest()
|
sl@0
|
100 |
{
|
sl@0
|
101 |
}
|
sl@0
|
102 |
|
sl@0
|
103 |
void DAtomicTest::SetupExecTable()
|
sl@0
|
104 |
{
|
sl@0
|
105 |
NThread* t = NKern::CurrentThread();
|
sl@0
|
106 |
SSlowExecTable& sxt = *(SSlowExecTable*)iXT;
|
sl@0
|
107 |
const SSlowExecTable& orig_sxt = *_LOFF(t->iSlowExecTable, SSlowExecTable, iEntries);
|
sl@0
|
108 |
sxt.iSlowExecCount = 4; // get thread info, set thread info, atomic action, restore exec table
|
sl@0
|
109 |
sxt.iInvalidExecHandler = orig_sxt.iInvalidExecHandler;
|
sl@0
|
110 |
sxt.iPreprocessHandler = 0; // not used
|
sl@0
|
111 |
sxt.iEntries[0].iFlags = 0; // don't do anything special on entry or exit
|
sl@0
|
112 |
sxt.iEntries[0].iFunction = (TLinAddr)&XGetThreadInfo;
|
sl@0
|
113 |
sxt.iEntries[1].iFlags = 0; // don't do anything special on entry or exit
|
sl@0
|
114 |
sxt.iEntries[1].iFunction = (TLinAddr)&XSetThreadInfo;
|
sl@0
|
115 |
sxt.iEntries[2].iFlags = 0; // don't do anything special on entry or exit
|
sl@0
|
116 |
sxt.iEntries[2].iFunction = (TLinAddr)&XAtomicAction;
|
sl@0
|
117 |
sxt.iEntries[3].iFlags = 0; // don't do anything special on entry or exit
|
sl@0
|
118 |
sxt.iEntries[3].iFunction = (TLinAddr)&XRestore;
|
sl@0
|
119 |
}
|
sl@0
|
120 |
|
sl@0
|
121 |
TInt DAtomicTest::Request(TInt aFunction, TAny* a1, TAny* a2)
|
sl@0
|
122 |
{
|
sl@0
|
123 |
TInt r = KErrNotSupported;
|
sl@0
|
124 |
switch (aFunction)
|
sl@0
|
125 |
{
|
sl@0
|
126 |
case RTestAtomic::ETDGExecuteK:
|
sl@0
|
127 |
{
|
sl@0
|
128 |
TDGBase tdg;
|
sl@0
|
129 |
kumemget32(&tdg, a1, sizeof(tdg));
|
sl@0
|
130 |
r = tdg.Execute();
|
sl@0
|
131 |
kumemput32(a1, &tdg, sizeof(tdg));
|
sl@0
|
132 |
break;
|
sl@0
|
133 |
}
|
sl@0
|
134 |
case RTestAtomic::EInitialise:
|
sl@0
|
135 |
{
|
sl@0
|
136 |
kumemget32(&iReg, a1, sizeof(TUint64));
|
sl@0
|
137 |
break;
|
sl@0
|
138 |
}
|
sl@0
|
139 |
case RTestAtomic::ERetrieve:
|
sl@0
|
140 |
{
|
sl@0
|
141 |
kumemput32(a1, &iReg, sizeof(TUint64));
|
sl@0
|
142 |
break;
|
sl@0
|
143 |
}
|
sl@0
|
144 |
case RTestAtomic::ESetCurrentThreadTimeslice:
|
sl@0
|
145 |
{
|
sl@0
|
146 |
NKern::ThreadSetTimeslice(NKern::CurrentThread(), NKern::TimesliceTicks((TInt)a1));
|
sl@0
|
147 |
r = KErrNone;
|
sl@0
|
148 |
break;
|
sl@0
|
149 |
}
|
sl@0
|
150 |
case RTestAtomic::ESwitchExecTables:
|
sl@0
|
151 |
{
|
sl@0
|
152 |
TUint tid = (TUint)a1;
|
sl@0
|
153 |
NThread* nt = NKern::CurrentThread();
|
sl@0
|
154 |
DThread& t = Kern::CurrentThread();
|
sl@0
|
155 |
if (Kern::NThreadToDThread(nt)==&t && tid<TUint(KMaxThreads))
|
sl@0
|
156 |
{
|
sl@0
|
157 |
TPerThreadK* p = iPerThread + tid;
|
sl@0
|
158 |
p->iOldExtraContext = nt->iExtraContext;
|
sl@0
|
159 |
p->iOldSlowExecTable = nt->iSlowExecTable;
|
sl@0
|
160 |
p->iId = tid;
|
sl@0
|
161 |
p->iCh = this;
|
sl@0
|
162 |
nt->iExtraContext = p;
|
sl@0
|
163 |
SSlowExecTable& sxt = *(SSlowExecTable*)iXT;
|
sl@0
|
164 |
nt->iSlowExecTable = sxt.iEntries;
|
sl@0
|
165 |
r = KErrNone;
|
sl@0
|
166 |
}
|
sl@0
|
167 |
break;
|
sl@0
|
168 |
}
|
sl@0
|
169 |
case RTestAtomic::EGetKernelMemoryAddress:
|
sl@0
|
170 |
{
|
sl@0
|
171 |
r = (TInt)NKern::CurrentThread(); // if we trash this the test should go bang
|
sl@0
|
172 |
break;
|
sl@0
|
173 |
}
|
sl@0
|
174 |
default:
|
sl@0
|
175 |
break;
|
sl@0
|
176 |
}
|
sl@0
|
177 |
return r;
|
sl@0
|
178 |
}
|
sl@0
|
179 |
|
sl@0
|
180 |
TInt DAtomicTest::XGetThreadInfo(TAny* aDest)
|
sl@0
|
181 |
{
|
sl@0
|
182 |
NThread* t = NKern::CurrentThread();
|
sl@0
|
183 |
TPerThreadK* p = (TPerThreadK*)t->iExtraContext;
|
sl@0
|
184 |
kumemput32(aDest, p, sizeof(TPerThread));
|
sl@0
|
185 |
return KErrNone;
|
sl@0
|
186 |
}
|
sl@0
|
187 |
|
sl@0
|
188 |
TInt DAtomicTest::XSetThreadInfo(const TAny* aSrc)
|
sl@0
|
189 |
{
|
sl@0
|
190 |
NThread* t = NKern::CurrentThread();
|
sl@0
|
191 |
TPerThreadK* p = (TPerThreadK*)t->iExtraContext;
|
sl@0
|
192 |
kumemget32(p, aSrc, sizeof(TPerThread));
|
sl@0
|
193 |
return KErrNone;
|
sl@0
|
194 |
}
|
sl@0
|
195 |
|
sl@0
|
196 |
TInt DAtomicTest::XAtomicAction(TAny* aPtr)
|
sl@0
|
197 |
{
|
sl@0
|
198 |
NThread* t = NKern::CurrentThread();
|
sl@0
|
199 |
TPerThreadK* p = (TPerThreadK*)t->iExtraContext;
|
sl@0
|
200 |
TAtomicAction action;
|
sl@0
|
201 |
kumemget32(&action, aPtr, sizeof(TAtomicAction));
|
sl@0
|
202 |
if (action.iThread!=p->iId || TUint(action.iIndex)>=TUint(TOTAL_INDEXES))
|
sl@0
|
203 |
return KErrNotSupported;
|
sl@0
|
204 |
return DoAtomicAction(&p->iCh->iReg, p, action);
|
sl@0
|
205 |
}
|
sl@0
|
206 |
|
sl@0
|
207 |
TInt DAtomicTest::XRestore()
|
sl@0
|
208 |
{
|
sl@0
|
209 |
NThread* t = NKern::CurrentThread();
|
sl@0
|
210 |
TPerThreadK* p = (TPerThreadK*)t->iExtraContext;
|
sl@0
|
211 |
t->iExtraContext = p->iOldExtraContext;
|
sl@0
|
212 |
t->iSlowExecTable = p->iOldSlowExecTable;
|
sl@0
|
213 |
return KErrNone;
|
sl@0
|
214 |
}
|