Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | #include "TestInterruptRaces.h" |
michael@0 | 2 | |
michael@0 | 3 | #include "IPDLUnitTests.h" // fail etc. |
michael@0 | 4 | |
michael@0 | 5 | using mozilla::ipc::MessageChannel; |
michael@0 | 6 | |
michael@0 | 7 | template<> |
michael@0 | 8 | struct RunnableMethodTraits<mozilla::_ipdltest::TestInterruptRacesParent> |
michael@0 | 9 | { |
michael@0 | 10 | static void RetainCallee(mozilla::_ipdltest::TestInterruptRacesParent* obj) { } |
michael@0 | 11 | static void ReleaseCallee(mozilla::_ipdltest::TestInterruptRacesParent* obj) { } |
michael@0 | 12 | }; |
michael@0 | 13 | |
michael@0 | 14 | |
michael@0 | 15 | namespace mozilla { |
michael@0 | 16 | namespace _ipdltest { |
michael@0 | 17 | |
michael@0 | 18 | ipc::RacyInterruptPolicy |
michael@0 | 19 | MediateRace(const MessageChannel::Message& parent, |
michael@0 | 20 | const MessageChannel::Message& child) |
michael@0 | 21 | { |
michael@0 | 22 | return (PTestInterruptRaces::Msg_Child__ID == parent.type()) ? |
michael@0 | 23 | ipc::RIPParentWins : ipc::RIPChildWins; |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | //----------------------------------------------------------------------------- |
michael@0 | 27 | // parent |
michael@0 | 28 | void |
michael@0 | 29 | TestInterruptRacesParent::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 | TestInterruptRacesParent::RecvStartRace() |
michael@0 | 37 | { |
michael@0 | 38 | MessageLoop::current()->PostTask( |
michael@0 | 39 | FROM_HERE, |
michael@0 | 40 | NewRunnableMethod(this, &TestInterruptRacesParent::OnRaceTime)); |
michael@0 | 41 | return true; |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | void |
michael@0 | 45 | TestInterruptRacesParent::OnRaceTime() |
michael@0 | 46 | { |
michael@0 | 47 | if (!CallRace(&mChildHasReply)) |
michael@0 | 48 | fail("problem calling Race()"); |
michael@0 | 49 | |
michael@0 | 50 | if (!mChildHasReply) |
michael@0 | 51 | fail("child should have got a reply already"); |
michael@0 | 52 | |
michael@0 | 53 | mHasReply = true; |
michael@0 | 54 | |
michael@0 | 55 | MessageLoop::current()->PostTask( |
michael@0 | 56 | FROM_HERE, |
michael@0 | 57 | NewRunnableMethod(this, &TestInterruptRacesParent::Test2)); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | bool |
michael@0 | 61 | TestInterruptRacesParent::AnswerRace(bool* hasReply) |
michael@0 | 62 | { |
michael@0 | 63 | if (mHasReply) |
michael@0 | 64 | fail("apparently the parent won the Interrupt race!"); |
michael@0 | 65 | *hasReply = hasReply; |
michael@0 | 66 | return true; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | void |
michael@0 | 70 | TestInterruptRacesParent::Test2() |
michael@0 | 71 | { |
michael@0 | 72 | puts(" passed"); |
michael@0 | 73 | puts("Test 2"); |
michael@0 | 74 | |
michael@0 | 75 | mHasReply = false; |
michael@0 | 76 | mChildHasReply = false; |
michael@0 | 77 | |
michael@0 | 78 | if (!CallStackFrame()) |
michael@0 | 79 | fail("can't set up a stack frame"); |
michael@0 | 80 | |
michael@0 | 81 | puts(" passed"); |
michael@0 | 82 | |
michael@0 | 83 | MessageLoop::current()->PostTask( |
michael@0 | 84 | FROM_HERE, |
michael@0 | 85 | NewRunnableMethod(this, &TestInterruptRacesParent::Test3)); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | bool |
michael@0 | 89 | TestInterruptRacesParent::AnswerStackFrame() |
michael@0 | 90 | { |
michael@0 | 91 | if (!SendWakeup()) |
michael@0 | 92 | fail("can't wake up the child"); |
michael@0 | 93 | |
michael@0 | 94 | if (!CallRace(&mChildHasReply)) |
michael@0 | 95 | fail("can't set up race condition"); |
michael@0 | 96 | mHasReply = true; |
michael@0 | 97 | |
michael@0 | 98 | if (!mChildHasReply) |
michael@0 | 99 | fail("child should have got a reply already"); |
michael@0 | 100 | |
michael@0 | 101 | return true; |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | void |
michael@0 | 105 | TestInterruptRacesParent::Test3() |
michael@0 | 106 | { |
michael@0 | 107 | puts("Test 3"); |
michael@0 | 108 | |
michael@0 | 109 | if (!CallStackFrame3()) |
michael@0 | 110 | fail("can't set up a stack frame"); |
michael@0 | 111 | |
michael@0 | 112 | puts(" passed"); |
michael@0 | 113 | |
michael@0 | 114 | Close(); |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | bool |
michael@0 | 118 | TestInterruptRacesParent::AnswerStackFrame3() |
michael@0 | 119 | { |
michael@0 | 120 | if (!SendWakeup3()) |
michael@0 | 121 | fail("can't wake up the child"); |
michael@0 | 122 | |
michael@0 | 123 | if (!CallChild()) |
michael@0 | 124 | fail("can't set up race condition"); |
michael@0 | 125 | |
michael@0 | 126 | return true; |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | bool |
michael@0 | 130 | TestInterruptRacesParent::AnswerParent() |
michael@0 | 131 | { |
michael@0 | 132 | mAnsweredParent = true; |
michael@0 | 133 | return true; |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | bool |
michael@0 | 137 | TestInterruptRacesParent::RecvGetAnsweredParent(bool* answeredParent) |
michael@0 | 138 | { |
michael@0 | 139 | *answeredParent = mAnsweredParent; |
michael@0 | 140 | return true; |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | //----------------------------------------------------------------------------- |
michael@0 | 144 | // child |
michael@0 | 145 | bool |
michael@0 | 146 | TestInterruptRacesChild::RecvStart() |
michael@0 | 147 | { |
michael@0 | 148 | puts("Test 1"); |
michael@0 | 149 | |
michael@0 | 150 | if (!SendStartRace()) |
michael@0 | 151 | fail("problem sending StartRace()"); |
michael@0 | 152 | |
michael@0 | 153 | bool dontcare; |
michael@0 | 154 | if (!CallRace(&dontcare)) |
michael@0 | 155 | fail("problem calling Race()"); |
michael@0 | 156 | |
michael@0 | 157 | mHasReply = true; |
michael@0 | 158 | return true; |
michael@0 | 159 | } |
michael@0 | 160 | |
michael@0 | 161 | bool |
michael@0 | 162 | TestInterruptRacesChild::AnswerRace(bool* hasReply) |
michael@0 | 163 | { |
michael@0 | 164 | if (!mHasReply) |
michael@0 | 165 | fail("apparently the child lost the Interrupt race!"); |
michael@0 | 166 | |
michael@0 | 167 | *hasReply = mHasReply; |
michael@0 | 168 | |
michael@0 | 169 | return true; |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | bool |
michael@0 | 173 | TestInterruptRacesChild::AnswerStackFrame() |
michael@0 | 174 | { |
michael@0 | 175 | // reset for the second test |
michael@0 | 176 | mHasReply = false; |
michael@0 | 177 | |
michael@0 | 178 | if (!CallStackFrame()) |
michael@0 | 179 | fail("can't set up stack frame"); |
michael@0 | 180 | |
michael@0 | 181 | if (!mHasReply) |
michael@0 | 182 | fail("should have had reply by now"); |
michael@0 | 183 | |
michael@0 | 184 | return true; |
michael@0 | 185 | } |
michael@0 | 186 | |
michael@0 | 187 | bool |
michael@0 | 188 | TestInterruptRacesChild::RecvWakeup() |
michael@0 | 189 | { |
michael@0 | 190 | bool dontcare; |
michael@0 | 191 | if (!CallRace(&dontcare)) |
michael@0 | 192 | fail("can't set up race condition"); |
michael@0 | 193 | |
michael@0 | 194 | mHasReply = true; |
michael@0 | 195 | return true; |
michael@0 | 196 | } |
michael@0 | 197 | |
michael@0 | 198 | bool |
michael@0 | 199 | TestInterruptRacesChild::AnswerStackFrame3() |
michael@0 | 200 | { |
michael@0 | 201 | if (!CallStackFrame3()) |
michael@0 | 202 | fail("can't set up stack frame"); |
michael@0 | 203 | return true; |
michael@0 | 204 | } |
michael@0 | 205 | |
michael@0 | 206 | bool |
michael@0 | 207 | TestInterruptRacesChild::RecvWakeup3() |
michael@0 | 208 | { |
michael@0 | 209 | if (!CallParent()) |
michael@0 | 210 | fail("can't set up race condition"); |
michael@0 | 211 | return true; |
michael@0 | 212 | } |
michael@0 | 213 | |
michael@0 | 214 | bool |
michael@0 | 215 | TestInterruptRacesChild::AnswerChild() |
michael@0 | 216 | { |
michael@0 | 217 | bool parentAnsweredParent; |
michael@0 | 218 | // the parent is supposed to win the race, which means its |
michael@0 | 219 | // message, Child(), is supposed to be processed before the |
michael@0 | 220 | // child's message, Parent() |
michael@0 | 221 | if (!SendGetAnsweredParent(&parentAnsweredParent)) |
michael@0 | 222 | fail("sending GetAnsweredParent"); |
michael@0 | 223 | |
michael@0 | 224 | if (parentAnsweredParent) |
michael@0 | 225 | fail("parent was supposed to win the race!"); |
michael@0 | 226 | |
michael@0 | 227 | return true; |
michael@0 | 228 | } |
michael@0 | 229 | |
michael@0 | 230 | } // namespace _ipdltest |
michael@0 | 231 | } // namespace mozilla |