1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/ipdl/test/cxx/TestInterruptRaces.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,129 @@ 1.4 +#ifndef mozilla__ipdltest_TestInterruptRaces_h 1.5 +#define mozilla__ipdltest_TestInterruptRaces_h 1.6 + 1.7 +#include "mozilla/_ipdltest/IPDLUnitTests.h" 1.8 + 1.9 +#include "mozilla/_ipdltest/PTestInterruptRacesParent.h" 1.10 +#include "mozilla/_ipdltest/PTestInterruptRacesChild.h" 1.11 + 1.12 +namespace mozilla { 1.13 +namespace _ipdltest { 1.14 + 1.15 +mozilla::ipc::RacyInterruptPolicy 1.16 +MediateRace(const mozilla::ipc::MessageChannel::Message& parent, 1.17 + const mozilla::ipc::MessageChannel::Message& child); 1.18 + 1.19 +class TestInterruptRacesParent : 1.20 + public PTestInterruptRacesParent 1.21 +{ 1.22 +public: 1.23 + TestInterruptRacesParent() : mHasReply(false), 1.24 + mChildHasReply(false), 1.25 + mAnsweredParent(false) 1.26 + { } 1.27 + virtual ~TestInterruptRacesParent() { } 1.28 + 1.29 + static bool RunTestInProcesses() { return true; } 1.30 + static bool RunTestInThreads() { return true; } 1.31 + 1.32 + void Main(); 1.33 + 1.34 +protected: 1.35 + virtual bool 1.36 + RecvStartRace() MOZ_OVERRIDE; 1.37 + 1.38 + virtual bool 1.39 + AnswerRace(bool* hasRace) MOZ_OVERRIDE; 1.40 + 1.41 + virtual bool 1.42 + AnswerStackFrame() MOZ_OVERRIDE; 1.43 + 1.44 + virtual bool 1.45 + AnswerStackFrame3() MOZ_OVERRIDE; 1.46 + 1.47 + virtual bool 1.48 + AnswerParent() MOZ_OVERRIDE; 1.49 + 1.50 + virtual bool 1.51 + RecvGetAnsweredParent(bool* answeredParent) MOZ_OVERRIDE; 1.52 + 1.53 + virtual mozilla::ipc::RacyInterruptPolicy 1.54 + MediateInterruptRace(const Message& parent, const Message& child) MOZ_OVERRIDE 1.55 + { 1.56 + return MediateRace(parent, child); 1.57 + } 1.58 + 1.59 + virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE 1.60 + { 1.61 + if (NormalShutdown != why) 1.62 + fail("unexpected destruction!"); 1.63 + if (!(mHasReply && mChildHasReply)) 1.64 + fail("both sides should have replies!"); 1.65 + passed("ok"); 1.66 + QuitParent(); 1.67 + } 1.68 + 1.69 +private: 1.70 + void OnRaceTime(); 1.71 + 1.72 + void Test2(); 1.73 + void Test3(); 1.74 + 1.75 + bool mHasReply; 1.76 + bool mChildHasReply; 1.77 + bool mAnsweredParent; 1.78 +}; 1.79 + 1.80 + 1.81 +class TestInterruptRacesChild : 1.82 + public PTestInterruptRacesChild 1.83 +{ 1.84 +public: 1.85 + TestInterruptRacesChild() : mHasReply(false) { } 1.86 + virtual ~TestInterruptRacesChild() { } 1.87 + 1.88 +protected: 1.89 + virtual bool 1.90 + RecvStart() MOZ_OVERRIDE; 1.91 + 1.92 + virtual bool 1.93 + AnswerRace(bool* hasRace) MOZ_OVERRIDE; 1.94 + 1.95 + virtual bool 1.96 + AnswerStackFrame() MOZ_OVERRIDE; 1.97 + 1.98 + virtual bool 1.99 + AnswerStackFrame3() MOZ_OVERRIDE; 1.100 + 1.101 + virtual bool 1.102 + RecvWakeup() MOZ_OVERRIDE; 1.103 + 1.104 + virtual bool 1.105 + RecvWakeup3() MOZ_OVERRIDE; 1.106 + 1.107 + virtual bool 1.108 + AnswerChild() MOZ_OVERRIDE; 1.109 + 1.110 + virtual mozilla::ipc::RacyInterruptPolicy 1.111 + MediateInterruptRace(const Message& parent, const Message& child) MOZ_OVERRIDE 1.112 + { 1.113 + return MediateRace(parent, child); 1.114 + } 1.115 + 1.116 + virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE 1.117 + { 1.118 + if (NormalShutdown != why) 1.119 + fail("unexpected destruction!"); 1.120 + QuitChild(); 1.121 + } 1.122 + 1.123 +private: 1.124 + bool mHasReply; 1.125 +}; 1.126 + 1.127 + 1.128 +} // namespace _ipdltest 1.129 +} // namespace mozilla 1.130 + 1.131 + 1.132 +#endif // ifndef mozilla__ipdltest_TestInterruptRaces_h