summaryrefslogtreecommitdiffstats
path: root/ipc/ipdl/test/cxx/TestStackHooks.cpp
blob: b4181985c5f67cc1089f5658c74b0fd40d7895fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include "TestStackHooks.h"

#include "base/task.h"
#include "IPDLUnitTests.h"      // fail etc.



namespace mozilla {
namespace _ipdltest {

//-----------------------------------------------------------------------------
// parent

TestStackHooksParent::TestStackHooksParent() :
    mOnStack(false), mIncallDepth(0)
{
    MOZ_COUNT_CTOR(TestStackHooksParent);
}

TestStackHooksParent::~TestStackHooksParent()
{
    MOZ_COUNT_DTOR(TestStackHooksParent);
}

void
TestStackHooksParent::Main()
{
    if (!SendStart())
        fail("sending Start()");
}


bool
TestStackHooksParent::AnswerStackFrame()
{
    if (!mOnStack)
        fail("not on C++ stack?!");

    if (!CallStackFrame())
        fail("calling StackFrame()");

    if (!mOnStack)
        fail("not on C++ stack?!");

    if (1 != mIncallDepth)
        fail("missed EnteredCall or ExitedCall hook");

    return true;
}

//-----------------------------------------------------------------------------
// child

TestStackHooksChild::TestStackHooksChild() :
    mOnStack(false),
    mEntered(0),
    mExited(0),
    mIncallDepth(0)
{
    MOZ_COUNT_CTOR(TestStackHooksChild);
}

TestStackHooksChild::~TestStackHooksChild()
{
    MOZ_COUNT_DTOR(TestStackHooksChild);
}

namespace {
void RunTestsFn() {
    static_cast<TestStackHooksChild*>(gChildActor)->RunTests();
}
}

bool
TestStackHooksChild::RecvStart()
{
    if (!mOnStack)
        fail("missed stack notification");

    if (0 != mIncallDepth)
        fail("EnteredCall/ExitedCall malfunction");

    // kick off tests from a runnable so that we can start with
    // MessageChannel code on the C++ stack
    MessageLoop::current()->PostTask(NewRunnableFunction(RunTestsFn));

    return true;
}

bool
TestStackHooksChild::AnswerStackFrame()
{
    if (!mOnStack)
        fail("missed stack notification");

    if (1 != mIncallDepth)
        fail("missed EnteredCall or ExitedCall hook");

    if (PTestStackHooks::TEST4_3 == state()) {
        if (!SendAsync())
            fail("sending Async()");
    }
    else if (PTestStackHooks::TEST5_3 == state()) {
        if (!SendSync())
            fail("sending Sync()");
    }
    else {
        fail("unexpected state");
    }

    if (!mOnStack)
        fail("bad stack exit notification");

    return true;
}

void
TestStackHooksChild::RunTests()
{
    // 1 because of RecvStart()
    if (1 != mEntered)
        fail("missed stack notification");
    if (mOnStack)
        fail("spurious stack notification");
    if (0 != mIncallDepth)
        fail("EnteredCall/ExitedCall malfunction");

    if (!SendAsync())
        fail("sending Async()");
    if (mOnStack)
        fail("spurious stack notification");
    if (0 != mIncallDepth)
        fail("EnteredCall/ExitedCall malfunction");
    if (2 != mEntered)
        fail("missed stack notification");

    if (!SendSync())
        fail("sending Sync()");
    if (mOnStack)
        fail("spurious stack notification");
    if (0 != mIncallDepth)
        fail("EnteredCall/ExitedCall malfunction");
    if (3 != mEntered)
        fail("missed stack notification");

    if (!CallRpc())
        fail("calling RPC()");
    if (mOnStack)
        fail("spurious stack notification");
    if (0 != mIncallDepth)
        fail("EnteredCall/ExitedCall malfunction");
    if (4 != mEntered)
        fail("missed stack notification");

    if (!CallStackFrame())
        fail("calling StackFrame()");
    if (mOnStack)
        fail("spurious stack notification");
    if (0 != mIncallDepth)
        fail("EnteredCall/ExitedCall malfunction");
    if (5 != mEntered)
        fail("missed stack notification");

    Close();
}

} // namespace _ipdltest
} // namespace mozilla