author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 25 May 2010 14:09:55 +0300 | |
branch | RCL_3 |
changeset 117 | 5b5d147c7838 |
parent 62 | 4a8fed1c0ef6 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2008-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 |
// e32\kernel\stest.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
#include <kernel/kern_priv.h> |
|
19 |
#include "kern_test.h" |
|
62
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
20 |
#include "securerng.h" |
0 | 21 |
|
22 |
#ifdef _DEBUG |
|
23 |
class TTestCallback: public TUserModeCallback |
|
24 |
{ |
|
25 |
public: |
|
26 |
enum TCallbackType { ESleep, ESpin }; |
|
27 |
||
28 |
static void Callback(TAny* aThisPtr, TUserModeCallbackReason aReasonCode); |
|
29 |
TTestCallback(TCallbackType aType); |
|
30 |
||
31 |
private: |
|
32 |
TCallbackType iType; |
|
33 |
}; |
|
34 |
||
35 |
TTestCallback::TTestCallback(TCallbackType aType) |
|
36 |
: TUserModeCallback(Callback), iType(aType) |
|
37 |
{ |
|
38 |
} |
|
39 |
||
40 |
void TTestCallback::Callback(TAny* aThisPtr, TUserModeCallbackReason aReasonCode) |
|
41 |
{ |
|
42 |
TTestCallback* tc = (TTestCallback*)aThisPtr; |
|
43 |
TCallbackType type = tc->iType; |
|
44 |
Kern::AsyncFree(tc); |
|
45 |
// we leave the CS here so we can be killed |
|
46 |
// we won't ever return normally, so it's ok that it's unbalanced |
|
47 |
NKern::ThreadLeaveCS(); |
|
48 |
if (aReasonCode == EUserModeCallbackRun) |
|
49 |
{ |
|
50 |
if (type == ESleep) |
|
51 |
NKern::Sleep(KMaxTInt); |
|
52 |
else if (type == ESpin) |
|
53 |
for (;;) {} |
|
54 |
} |
|
55 |
} |
|
56 |
#endif |
|
57 |
||
58 |
||
59 |
EXPORT_C TInt KernTest::Test(TTestFunction aFunc, TAny* a1, TAny* a2, TAny* a3) |
|
60 |
{ |
|
61 |
TInt r = KErrNotSupported; |
|
62 |
(void)aFunc; (void)a1; (void)a2; (void)a3; |
|
63 |
||
64 |
switch(aFunc) |
|
65 |
{ |
|
62
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
66 |
#ifdef _DEBUG |
0 | 67 |
case EUserModeCallbackSleep: |
68 |
{ |
|
69 |
// a1 is a DThread*. We add a user mode callback to that thread |
|
70 |
// which sleeps for a long time, effectively blocking the thread |
|
71 |
// indefinately. |
|
72 |
DThread* t = (DThread*)a1; |
|
73 |
NKern::ThreadEnterCS(); |
|
74 |
r = NKern::QueueUserModeCallback(&t->iNThread, new TTestCallback(TTestCallback::ESleep)); |
|
75 |
NKern::ThreadLeaveCS(); |
|
76 |
break; |
|
77 |
} |
|
78 |
case EUserModeCallbackSpin: |
|
79 |
{ |
|
80 |
// a1 is a DThread*. We add a user mode callback to that thread |
|
81 |
// which spins in an infinite loop, ensuring that it will be |
|
82 |
// preempted rather than finishing or blocking. |
|
83 |
DThread* t = (DThread*)a1; |
|
84 |
NKern::ThreadEnterCS(); |
|
85 |
r = NKern::QueueUserModeCallback(&t->iNThread, new TTestCallback(TTestCallback::ESpin)); |
|
86 |
NKern::ThreadLeaveCS(); |
|
87 |
break; |
|
88 |
} |
|
62
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
89 |
#endif |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
90 |
case ERNGReseedHook: |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
91 |
{ |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
92 |
// a1 is a function which wants to be called with arg a2 when the RNG is reseeded. |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
93 |
// Used to test if reseeds are sufficiently frequent. |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
94 |
SecureRNG->SetReseedHook((void(*)(TAny*))a1, a2); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
95 |
break; |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
96 |
} |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
97 |
default: |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
98 |
// To stop compiler warnings about unhandled enum cases in release builds |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
99 |
break; |
0 | 100 |
} |
101 |
||
102 |
return r; |
|
103 |
} |