ipc/ipdl/test/cxx/TestSyncWakeup.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.

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

mercurial