Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | #if defined(OS_POSIX) |
michael@0 | 2 | #include <unistd.h> // sleep() |
michael@0 | 3 | #endif |
michael@0 | 4 | |
michael@0 | 5 | #include "TestSyncWakeup.h" |
michael@0 | 6 | |
michael@0 | 7 | #include "IPDLUnitTests.h" // fail etc. |
michael@0 | 8 | |
michael@0 | 9 | namespace mozilla { |
michael@0 | 10 | namespace _ipdltest { |
michael@0 | 11 | |
michael@0 | 12 | //----------------------------------------------------------------------------- |
michael@0 | 13 | // parent |
michael@0 | 14 | |
michael@0 | 15 | TestSyncWakeupParent::TestSyncWakeupParent() |
michael@0 | 16 | { |
michael@0 | 17 | MOZ_COUNT_CTOR(TestSyncWakeupParent); |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | TestSyncWakeupParent::~TestSyncWakeupParent() |
michael@0 | 21 | { |
michael@0 | 22 | MOZ_COUNT_DTOR(TestSyncWakeupParent); |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | void |
michael@0 | 26 | TestSyncWakeupParent::Main() |
michael@0 | 27 | { |
michael@0 | 28 | if (!SendStart()) |
michael@0 | 29 | fail("sending Start()"); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | bool |
michael@0 | 33 | TestSyncWakeupParent::AnswerStackFrame() |
michael@0 | 34 | { |
michael@0 | 35 | if (!CallStackFrame()) |
michael@0 | 36 | fail("calling StackFrame()"); |
michael@0 | 37 | return true; |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | bool |
michael@0 | 41 | TestSyncWakeupParent::RecvSync1() |
michael@0 | 42 | { |
michael@0 | 43 | if (!SendNote1()) |
michael@0 | 44 | fail("sending Note1()"); |
michael@0 | 45 | |
michael@0 | 46 | // XXX ugh ... need to ensure that the async message and sync |
michael@0 | 47 | // reply come in "far enough" apart that this test doesn't pass on |
michael@0 | 48 | // accident |
michael@0 | 49 | #if defined(OS_POSIX) |
michael@0 | 50 | // NB: can't use PR_Sleep (i.e. Sleep() on windows) because it's |
michael@0 | 51 | // only spec'd to block the current thread, not the current |
michael@0 | 52 | // process. We need the IO thread to sleep as well. |
michael@0 | 53 | puts(" (sleeping for 5 seconds. sorry!)"); |
michael@0 | 54 | sleep(5); |
michael@0 | 55 | #endif |
michael@0 | 56 | |
michael@0 | 57 | return true; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | bool |
michael@0 | 61 | TestSyncWakeupParent::RecvSync2() |
michael@0 | 62 | { |
michael@0 | 63 | if (!SendNote2()) |
michael@0 | 64 | fail("sending Note2()"); |
michael@0 | 65 | |
michael@0 | 66 | #if defined(OS_POSIX) |
michael@0 | 67 | // see above |
michael@0 | 68 | sleep(5); |
michael@0 | 69 | puts(" (sleeping for 5 seconds. sorry!)"); |
michael@0 | 70 | #endif |
michael@0 | 71 | |
michael@0 | 72 | return true; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | //----------------------------------------------------------------------------- |
michael@0 | 76 | // child |
michael@0 | 77 | |
michael@0 | 78 | TestSyncWakeupChild::TestSyncWakeupChild() : mDone(false) |
michael@0 | 79 | { |
michael@0 | 80 | MOZ_COUNT_CTOR(TestSyncWakeupChild); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | TestSyncWakeupChild::~TestSyncWakeupChild() |
michael@0 | 84 | { |
michael@0 | 85 | MOZ_COUNT_DTOR(TestSyncWakeupChild); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | bool |
michael@0 | 89 | TestSyncWakeupChild::RecvStart() |
michael@0 | 90 | { |
michael@0 | 91 | // First test: the parent fires back an async message while |
michael@0 | 92 | // replying to a sync one |
michael@0 | 93 | if (!SendSync1()) |
michael@0 | 94 | fail("sending Sync()"); |
michael@0 | 95 | |
michael@0 | 96 | // drop back into the event loop to get Note1(), then kick off the |
michael@0 | 97 | // second test |
michael@0 | 98 | return true; |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | bool |
michael@0 | 102 | TestSyncWakeupChild::RecvNote1() |
michael@0 | 103 | { |
michael@0 | 104 | // Second test: the parent fires back an async message while |
michael@0 | 105 | // replying to a sync one, with a frame on the RPC stack |
michael@0 | 106 | if (!CallStackFrame()) |
michael@0 | 107 | fail("calling StackFrame()"); |
michael@0 | 108 | |
michael@0 | 109 | if (!mDone) |
michael@0 | 110 | fail("should have received Note2()!"); |
michael@0 | 111 | |
michael@0 | 112 | Close(); |
michael@0 | 113 | |
michael@0 | 114 | return true; |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | bool |
michael@0 | 118 | TestSyncWakeupChild::AnswerStackFrame() |
michael@0 | 119 | { |
michael@0 | 120 | if (!SendSync2()) |
michael@0 | 121 | fail("sending Sync()"); |
michael@0 | 122 | |
michael@0 | 123 | return true; |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | bool |
michael@0 | 127 | TestSyncWakeupChild::RecvNote2() |
michael@0 | 128 | { |
michael@0 | 129 | mDone = true; |
michael@0 | 130 | return true; |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | } // namespace _ipdltest |
michael@0 | 134 | } // namespace mozilla |