ipc/ipdl/test/cxx/TestInterruptRaces.h

branch
TOR_BUG_3246
changeset 6
8bccb770b82d
equal deleted inserted replaced
-1:000000000000 0:77b05f8e4c86
1 #ifndef mozilla__ipdltest_TestInterruptRaces_h
2 #define mozilla__ipdltest_TestInterruptRaces_h
3
4 #include "mozilla/_ipdltest/IPDLUnitTests.h"
5
6 #include "mozilla/_ipdltest/PTestInterruptRacesParent.h"
7 #include "mozilla/_ipdltest/PTestInterruptRacesChild.h"
8
9 namespace mozilla {
10 namespace _ipdltest {
11
12 mozilla::ipc::RacyInterruptPolicy
13 MediateRace(const mozilla::ipc::MessageChannel::Message& parent,
14 const mozilla::ipc::MessageChannel::Message& child);
15
16 class TestInterruptRacesParent :
17 public PTestInterruptRacesParent
18 {
19 public:
20 TestInterruptRacesParent() : mHasReply(false),
21 mChildHasReply(false),
22 mAnsweredParent(false)
23 { }
24 virtual ~TestInterruptRacesParent() { }
25
26 static bool RunTestInProcesses() { return true; }
27 static bool RunTestInThreads() { return true; }
28
29 void Main();
30
31 protected:
32 virtual bool
33 RecvStartRace() MOZ_OVERRIDE;
34
35 virtual bool
36 AnswerRace(bool* hasRace) MOZ_OVERRIDE;
37
38 virtual bool
39 AnswerStackFrame() MOZ_OVERRIDE;
40
41 virtual bool
42 AnswerStackFrame3() MOZ_OVERRIDE;
43
44 virtual bool
45 AnswerParent() MOZ_OVERRIDE;
46
47 virtual bool
48 RecvGetAnsweredParent(bool* answeredParent) MOZ_OVERRIDE;
49
50 virtual mozilla::ipc::RacyInterruptPolicy
51 MediateInterruptRace(const Message& parent, const Message& child) MOZ_OVERRIDE
52 {
53 return MediateRace(parent, child);
54 }
55
56 virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE
57 {
58 if (NormalShutdown != why)
59 fail("unexpected destruction!");
60 if (!(mHasReply && mChildHasReply))
61 fail("both sides should have replies!");
62 passed("ok");
63 QuitParent();
64 }
65
66 private:
67 void OnRaceTime();
68
69 void Test2();
70 void Test3();
71
72 bool mHasReply;
73 bool mChildHasReply;
74 bool mAnsweredParent;
75 };
76
77
78 class TestInterruptRacesChild :
79 public PTestInterruptRacesChild
80 {
81 public:
82 TestInterruptRacesChild() : mHasReply(false) { }
83 virtual ~TestInterruptRacesChild() { }
84
85 protected:
86 virtual bool
87 RecvStart() MOZ_OVERRIDE;
88
89 virtual bool
90 AnswerRace(bool* hasRace) MOZ_OVERRIDE;
91
92 virtual bool
93 AnswerStackFrame() MOZ_OVERRIDE;
94
95 virtual bool
96 AnswerStackFrame3() MOZ_OVERRIDE;
97
98 virtual bool
99 RecvWakeup() MOZ_OVERRIDE;
100
101 virtual bool
102 RecvWakeup3() MOZ_OVERRIDE;
103
104 virtual bool
105 AnswerChild() MOZ_OVERRIDE;
106
107 virtual mozilla::ipc::RacyInterruptPolicy
108 MediateInterruptRace(const Message& parent, const Message& child) MOZ_OVERRIDE
109 {
110 return MediateRace(parent, child);
111 }
112
113 virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE
114 {
115 if (NormalShutdown != why)
116 fail("unexpected destruction!");
117 QuitChild();
118 }
119
120 private:
121 bool mHasReply;
122 };
123
124
125 } // namespace _ipdltest
126 } // namespace mozilla
127
128
129 #endif // ifndef mozilla__ipdltest_TestInterruptRaces_h

mercurial