1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/ipdl/test/cxx/TestSyncWakeup.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,134 @@ 1.4 +#if defined(OS_POSIX) 1.5 +#include <unistd.h> // sleep() 1.6 +#endif 1.7 + 1.8 +#include "TestSyncWakeup.h" 1.9 + 1.10 +#include "IPDLUnitTests.h" // fail etc. 1.11 + 1.12 +namespace mozilla { 1.13 +namespace _ipdltest { 1.14 + 1.15 +//----------------------------------------------------------------------------- 1.16 +// parent 1.17 + 1.18 +TestSyncWakeupParent::TestSyncWakeupParent() 1.19 +{ 1.20 + MOZ_COUNT_CTOR(TestSyncWakeupParent); 1.21 +} 1.22 + 1.23 +TestSyncWakeupParent::~TestSyncWakeupParent() 1.24 +{ 1.25 + MOZ_COUNT_DTOR(TestSyncWakeupParent); 1.26 +} 1.27 + 1.28 +void 1.29 +TestSyncWakeupParent::Main() 1.30 +{ 1.31 + if (!SendStart()) 1.32 + fail("sending Start()"); 1.33 +} 1.34 + 1.35 +bool 1.36 +TestSyncWakeupParent::AnswerStackFrame() 1.37 +{ 1.38 + if (!CallStackFrame()) 1.39 + fail("calling StackFrame()"); 1.40 + return true; 1.41 +} 1.42 + 1.43 +bool 1.44 +TestSyncWakeupParent::RecvSync1() 1.45 +{ 1.46 + if (!SendNote1()) 1.47 + fail("sending Note1()"); 1.48 + 1.49 + // XXX ugh ... need to ensure that the async message and sync 1.50 + // reply come in "far enough" apart that this test doesn't pass on 1.51 + // accident 1.52 +#if defined(OS_POSIX) 1.53 + // NB: can't use PR_Sleep (i.e. Sleep() on windows) because it's 1.54 + // only spec'd to block the current thread, not the current 1.55 + // process. We need the IO thread to sleep as well. 1.56 + puts(" (sleeping for 5 seconds. sorry!)"); 1.57 + sleep(5); 1.58 +#endif 1.59 + 1.60 + return true; 1.61 +} 1.62 + 1.63 +bool 1.64 +TestSyncWakeupParent::RecvSync2() 1.65 +{ 1.66 + if (!SendNote2()) 1.67 + fail("sending Note2()"); 1.68 + 1.69 +#if defined(OS_POSIX) 1.70 + // see above 1.71 + sleep(5); 1.72 + puts(" (sleeping for 5 seconds. sorry!)"); 1.73 +#endif 1.74 + 1.75 + return true; 1.76 +} 1.77 + 1.78 +//----------------------------------------------------------------------------- 1.79 +// child 1.80 + 1.81 +TestSyncWakeupChild::TestSyncWakeupChild() : mDone(false) 1.82 +{ 1.83 + MOZ_COUNT_CTOR(TestSyncWakeupChild); 1.84 +} 1.85 + 1.86 +TestSyncWakeupChild::~TestSyncWakeupChild() 1.87 +{ 1.88 + MOZ_COUNT_DTOR(TestSyncWakeupChild); 1.89 +} 1.90 + 1.91 +bool 1.92 +TestSyncWakeupChild::RecvStart() 1.93 +{ 1.94 + // First test: the parent fires back an async message while 1.95 + // replying to a sync one 1.96 + if (!SendSync1()) 1.97 + fail("sending Sync()"); 1.98 + 1.99 + // drop back into the event loop to get Note1(), then kick off the 1.100 + // second test 1.101 + return true; 1.102 +} 1.103 + 1.104 +bool 1.105 +TestSyncWakeupChild::RecvNote1() 1.106 +{ 1.107 + // Second test: the parent fires back an async message while 1.108 + // replying to a sync one, with a frame on the RPC stack 1.109 + if (!CallStackFrame()) 1.110 + fail("calling StackFrame()"); 1.111 + 1.112 + if (!mDone) 1.113 + fail("should have received Note2()!"); 1.114 + 1.115 + Close(); 1.116 + 1.117 + return true; 1.118 +} 1.119 + 1.120 +bool 1.121 +TestSyncWakeupChild::AnswerStackFrame() 1.122 +{ 1.123 + if (!SendSync2()) 1.124 + fail("sending Sync()"); 1.125 + 1.126 + return true; 1.127 +} 1.128 + 1.129 +bool 1.130 +TestSyncWakeupChild::RecvNote2() 1.131 +{ 1.132 + mDone = true; 1.133 + return true; 1.134 +} 1.135 + 1.136 +} // namespace _ipdltest 1.137 +} // namespace mozilla