ipc/ipdl/test/cxx/TestRPC.cpp

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 #include "TestRPC.h"
michael@0 2
michael@0 3 #include "IPDLUnitTests.h" // fail etc.
michael@0 4 #if defined(OS_POSIX)
michael@0 5 #include <unistd.h>
michael@0 6 #else
michael@0 7 #include <windows.h>
michael@0 8 #endif
michael@0 9
michael@0 10 namespace mozilla {
michael@0 11 namespace _ipdltest {
michael@0 12
michael@0 13 //-----------------------------------------------------------------------------
michael@0 14 // parent
michael@0 15
michael@0 16 TestRPCParent::TestRPCParent()
michael@0 17 : reentered_(false),
michael@0 18 resolved_first_cpow_(false)
michael@0 19 {
michael@0 20 MOZ_COUNT_CTOR(TestRPCParent);
michael@0 21 }
michael@0 22
michael@0 23 TestRPCParent::~TestRPCParent()
michael@0 24 {
michael@0 25 MOZ_COUNT_DTOR(TestRPCParent);
michael@0 26 }
michael@0 27
michael@0 28 void
michael@0 29 TestRPCParent::Main()
michael@0 30 {
michael@0 31 if (!SendStart())
michael@0 32 fail("sending Start");
michael@0 33 }
michael@0 34
michael@0 35 bool
michael@0 36 TestRPCParent::AnswerTest1_Start(uint32_t* aResult)
michael@0 37 {
michael@0 38 uint32_t result;
michael@0 39 if (!CallTest1_InnerQuery(&result))
michael@0 40 fail("CallTest1_InnerQuery");
michael@0 41 if (result != 300)
michael@0 42 fail("Wrong result (expected 300)");
michael@0 43
michael@0 44 *aResult = 100;
michael@0 45 return true;
michael@0 46 }
michael@0 47
michael@0 48 bool
michael@0 49 TestRPCParent::AnswerTest1_InnerEvent(uint32_t* aResult)
michael@0 50 {
michael@0 51 uint32_t result;
michael@0 52 if (!CallTest1_NoReenter(&result))
michael@0 53 fail("CallTest1_NoReenter");
michael@0 54 if (result != 400)
michael@0 55 fail("Wrong result (expected 400)");
michael@0 56
michael@0 57 *aResult = 200;
michael@0 58 return true;
michael@0 59 }
michael@0 60
michael@0 61 bool
michael@0 62 TestRPCParent::RecvTest2_Start()
michael@0 63 {
michael@0 64 // Send a CPOW. During this time, we must NOT process the RPC message, as
michael@0 65 // we could start receiving CPOW replies out-of-order.
michael@0 66 if (!CallTest2_FirstUrgent())
michael@0 67 fail("CallTest2_FirstUrgent");
michael@0 68
michael@0 69 MOZ_ASSERT(!reentered_);
michael@0 70 resolved_first_cpow_ = true;
michael@0 71 return true;
michael@0 72 }
michael@0 73
michael@0 74 bool
michael@0 75 TestRPCParent::AnswerTest2_OutOfOrder()
michael@0 76 {
michael@0 77 // Send a CPOW. If this RPC call was initiated while waiting for the first
michael@0 78 // CPOW to resolve, replies will be processed out of order, and we'll crash.
michael@0 79 if (!CallTest2_SecondUrgent())
michael@0 80 fail("CallTest2_SecondUrgent");
michael@0 81
michael@0 82 reentered_ = true;
michael@0 83 return true;
michael@0 84 }
michael@0 85
michael@0 86 bool
michael@0 87 TestRPCParent::RecvTest3_Start(uint32_t* aResult)
michael@0 88 {
michael@0 89 if (!CallTest3_WakeUp(aResult))
michael@0 90 fail("CallTest3_WakeUp");
michael@0 91
michael@0 92 return true;
michael@0 93 }
michael@0 94
michael@0 95 bool
michael@0 96 TestRPCParent::AnswerTest3_InnerEvent(uint32_t* aResult)
michael@0 97 {
michael@0 98 *aResult = 200;
michael@0 99 return true;
michael@0 100 }
michael@0 101
michael@0 102 bool
michael@0 103 TestRPCParent::AnswerTest4_Start(uint32_t* aResult)
michael@0 104 {
michael@0 105 if (!CallTest4_WakeUp(aResult))
michael@0 106 fail("CallTest4_WakeUp");
michael@0 107
michael@0 108 return true;
michael@0 109 }
michael@0 110
michael@0 111 bool
michael@0 112 TestRPCParent::AnswerTest4_Inner(uint32_t* aResult)
michael@0 113 {
michael@0 114 *aResult = 700;
michael@0 115 return true;
michael@0 116 }
michael@0 117
michael@0 118 //-----------------------------------------------------------------------------
michael@0 119 // child
michael@0 120
michael@0 121
michael@0 122 TestRPCChild::TestRPCChild()
michael@0 123 {
michael@0 124 MOZ_COUNT_CTOR(TestRPCChild);
michael@0 125 }
michael@0 126
michael@0 127 TestRPCChild::~TestRPCChild()
michael@0 128 {
michael@0 129 MOZ_COUNT_DTOR(TestRPCChild);
michael@0 130 }
michael@0 131
michael@0 132 bool
michael@0 133 TestRPCChild::RecvStart()
michael@0 134 {
michael@0 135 uint32_t result;
michael@0 136 if (!CallTest1_Start(&result))
michael@0 137 fail("CallTest1_Start");
michael@0 138 if (result != 100)
michael@0 139 fail("Wrong result (expected 100)");
michael@0 140
michael@0 141 if (!SendTest2_Start())
michael@0 142 fail("SendTest2_Start");
michael@0 143
michael@0 144 if (!CallTest2_OutOfOrder())
michael@0 145 fail("CallTest2_OutOfOrder");
michael@0 146
michael@0 147 result = 0;
michael@0 148 if (!SendTest3_Start(&result))
michael@0 149 fail("SendTest3_Start");
michael@0 150 if (result != 200)
michael@0 151 fail("Wrong result (expected 200)");
michael@0 152
michael@0 153 // See bug 937216 (RPC calls within interrupts).
michael@0 154 if (!CallTest4_Start(&result))
michael@0 155 fail("SendTest4_Start");
michael@0 156 if (result != 700)
michael@0 157 fail("Wrong result (expected 700)");
michael@0 158
michael@0 159 Close();
michael@0 160 return true;
michael@0 161 }
michael@0 162
michael@0 163 bool
michael@0 164 TestRPCChild::AnswerTest1_InnerQuery(uint32_t* aResult)
michael@0 165 {
michael@0 166 uint32_t result;
michael@0 167 if (!CallTest1_InnerEvent(&result))
michael@0 168 fail("CallTest1_InnerEvent");
michael@0 169 if (result != 200)
michael@0 170 fail("Wrong result (expected 200)");
michael@0 171
michael@0 172 *aResult = 300;
michael@0 173 return true;
michael@0 174 }
michael@0 175
michael@0 176 bool
michael@0 177 TestRPCChild::AnswerTest1_NoReenter(uint32_t* aResult)
michael@0 178 {
michael@0 179 *aResult = 400;
michael@0 180 return true;
michael@0 181 }
michael@0 182
michael@0 183 bool
michael@0 184 TestRPCChild::AnswerTest2_FirstUrgent()
michael@0 185 {
michael@0 186 return true;
michael@0 187 }
michael@0 188
michael@0 189 bool
michael@0 190 TestRPCChild::AnswerTest2_SecondUrgent()
michael@0 191 {
michael@0 192 return true;
michael@0 193 }
michael@0 194
michael@0 195 bool
michael@0 196 TestRPCChild::AnswerTest3_WakeUp(uint32_t* aResult)
michael@0 197 {
michael@0 198 if (!CallTest3_InnerEvent(aResult))
michael@0 199 fail("CallTest3_InnerEvent");
michael@0 200
michael@0 201 return true;
michael@0 202 }
michael@0 203
michael@0 204 bool
michael@0 205 TestRPCChild::AnswerTest4_WakeUp(uint32_t* aResult)
michael@0 206 {
michael@0 207 if (!CallTest4_Inner(aResult))
michael@0 208 fail("CallTest4_Inner");
michael@0 209
michael@0 210 return true;
michael@0 211 }
michael@0 212
michael@0 213 } // namespace _ipdltest
michael@0 214 } // namespace mozilla

mercurial