|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32math.h> |
|
19 #include <e32cmn.h> |
|
20 #include "IpcFuzzTest.h" |
|
21 |
|
22 RIpcFuzzTest::RIpcFuzzTest(RTest& aTest) |
|
23 :iTest(aTest) |
|
24 { |
|
25 // No implementation required |
|
26 } |
|
27 |
|
28 |
|
29 RIpcFuzzTest::~RIpcFuzzTest() |
|
30 { |
|
31 Close(); |
|
32 } |
|
33 |
|
34 /** |
|
35 |
|
36 @SYMTestCaseID PIM-IPCFUZZTEST-0001 |
|
37 |
|
38 */ |
|
39 |
|
40 void RIpcFuzzTest::RunTestL(const TDesC& aTargetSrvName, TInt aMinFuncRange, TInt aMaxFuncRange) |
|
41 { |
|
42 TVersion version(0,1,1); |
|
43 |
|
44 TInt err = CreateSession(aTargetSrvName, version); |
|
45 if(err == KErrNotFound) // Server not running? |
|
46 { |
|
47 HBufC* buf = HBufC::NewLC(aTargetSrvName.Length() + 16); |
|
48 TPtr ptr = buf->Des(); |
|
49 ptr.Copy(aTargetSrvName); |
|
50 ptr.Append(_L(".exe")); |
|
51 |
|
52 // Use the RProcess API to start the server. |
|
53 RProcess server; |
|
54 User::LeaveIfError(server.Create(*buf,KNullDesC)); |
|
55 CleanupStack::PopAndDestroy(buf); |
|
56 |
|
57 server.SetPriority(EPriorityHigh); |
|
58 |
|
59 // Synchronise with the server. |
|
60 TRequestStatus reqStatus; |
|
61 server.Rendezvous(reqStatus); |
|
62 server.Resume(); |
|
63 |
|
64 // Server will call the reciprocal static synchronisation call. |
|
65 User::WaitForRequest(reqStatus); |
|
66 server.Close(); |
|
67 User::LeaveIfError(reqStatus.Int()); |
|
68 |
|
69 // Create the server session. |
|
70 User::LeaveIfError(CreateSession(aTargetSrvName,version)); |
|
71 } |
|
72 else |
|
73 { |
|
74 User::LeaveIfError(err); |
|
75 } |
|
76 |
|
77 itest.Next(_L("@SYMTESTCaseID:PIM-IPCFUZZTEST-0001 Start IPC Fuzz Test")); |
|
78 |
|
79 iTest.Printf(_L("IPC Fuzz Test against %S"), &aTargetSrvName); |
|
80 |
|
81 for(TInt func = aMinFuncRange; func < aMaxFuncRange; ++func) |
|
82 { |
|
83 iTest.Printf(_L("Fuzz Test on function number %d"), func); |
|
84 Fuzz(func, 0); |
|
85 FuzzL(func, _L("Random")); |
|
86 } |
|
87 |
|
88 } |
|
89 |
|
90 TInt RIpcFuzzTest::Fuzz(TInt aMsg, TInt /*aNotUsed*/) |
|
91 { |
|
92 TIpcArgs args(Math::Random(), Math::Random(), Math::Random(), Math::Random()); |
|
93 return SendReceive(aMsg, args); |
|
94 } |
|
95 |
|
96 TInt RIpcFuzzTest::FuzzL(TInt aMsg, const TDesC&) |
|
97 { |
|
98 HBufC* buf = HBufC::NewLC(255); |
|
99 TPtr ptr = buf->Des(); |
|
100 ptr.Fill(Math::Random(),255); |
|
101 |
|
102 TIpcArgs args(&ptr, &ptr, &ptr, &ptr); |
|
103 TInt ret = SendReceive(aMsg, args); |
|
104 |
|
105 CleanupStack::PopAndDestroy(buf); |
|
106 return ret; |
|
107 } |