Bug 1790872 - Part 2: Make the process mode available to IPDL gtests, r=ipc-reviewers,mccr8

This will be useful in the next part to write a test with different behaviour
depending on whether it's cross-process.

Differential Revision: https://phabricator.services.mozilla.com/D158274
This commit is contained in:
Nika Layzell 2022-11-08 01:11:12 +00:00
Родитель 40c26a2ea0
Коммит a190397bee
2 изменённых файлов: 42 добавлений и 31 удалений

Просмотреть файл

@ -196,11 +196,12 @@ void IPDLUnitTestChild::ActorDestroy(ActorDestroyReason aWhy) {
} }
} }
void IPDLTestHelper::TestWrapper(bool aCrossProcess) { void IPDLTestHelper::TestWrapper() {
// Create the host and start the test actor with it. // Create the host and start the test actor with it.
RefPtr<IPDLUnitTestParent> host = RefPtr<IPDLUnitTestParent> host =
aCrossProcess ? IPDLUnitTestParent::CreateCrossProcess() GetTestMode() == TestMode::CrossProcess
: IPDLUnitTestParent::CreateCrossThread(); ? IPDLUnitTestParent::CreateCrossProcess()
: IPDLUnitTestParent::CreateCrossThread();
ASSERT_TRUE(host); ASSERT_TRUE(host);
if (!host->Start(GetName(), GetActor())) { if (!host->Start(GetName(), GetActor())) {
FAIL(); FAIL();

Просмотреть файл

@ -21,39 +21,49 @@ const char* RegisterAllocChildActor(
// Internal helper type used to declare IPDL tests. // Internal helper type used to declare IPDL tests.
class IPDLTestHelper { class IPDLTestHelper {
public: public:
void TestWrapper(bool aCrossProcess); enum class TestMode {
SameProcess,
CrossProcess,
};
void TestWrapper();
virtual const char* GetName() = 0; virtual const char* GetName() = 0;
virtual ipc::IToplevelProtocol* GetActor() = 0; virtual ipc::IToplevelProtocol* GetActor() = 0;
virtual TestMode GetTestMode() = 0;
virtual void TestBody() = 0; virtual void TestBody() = 0;
}; };
#define IPDL_TEST_CLASS_NAME_(actorname) IPDL_TEST_##actorname #define IPDL_TEST_CLASS_NAME_(actorname) IPDL_TEST_##actorname
#define IPDL_TEST_HEAD_(actorname) \ #define IPDL_TEST_HEAD_(actorname) \
class IPDL_TEST_CLASS_NAME_(actorname) \ class IPDL_TEST_CLASS_NAME_(actorname) \
: public ::mozilla::_ipdltest::IPDLTestHelper { \ : public ::mozilla::_ipdltest::IPDLTestHelper { \
public: \ public: \
IPDL_TEST_CLASS_NAME_(actorname)() : mActor(new actorname##Parent) {} \ explicit IPDL_TEST_CLASS_NAME_(actorname)(TestMode aTestMode) \
\ : mTestMode(aTestMode), mActor(new actorname##Parent) {} \
private: \ \
void TestBody() override; \ private: \
const char* GetName() override { return sName; }; \ void TestBody() override; \
actorname##Parent* GetActor() override { return mActor; }; \ const char* GetName() override { return sName; } \
\ actorname##Parent* GetActor() override { return mActor; } \
actorname##Parent* mActor; \ TestMode GetTestMode() override { return mTestMode; } \
static const char* sName; \ \
}; \ const TestMode mTestMode; \
const char* IPDL_TEST_CLASS_NAME_(actorname)::sName = \ actorname##Parent* mActor; \
::mozilla::_ipdltest::RegisterAllocChildActor( \ static const char* sName; \
#actorname, []() -> ::mozilla::ipc::IToplevelProtocol* { \ }; \
return new actorname##Child; \ const char* IPDL_TEST_CLASS_NAME_(actorname)::sName = \
::mozilla::_ipdltest::RegisterAllocChildActor( \
#actorname, []() -> ::mozilla::ipc::IToplevelProtocol* { \
return new actorname##Child; \
}); });
#define IPDL_TEST_DECL_(testgroup, actorname, crossprocess) \ #define IPDL_TEST_DECL_(testgroup, actorname, mode) \
TEST(testgroup, actorname) \ TEST(testgroup, actorname) \
{ \ { \
IPDL_TEST_CLASS_NAME_(actorname) test; \ IPDL_TEST_CLASS_NAME_(actorname){ \
test.TestWrapper(crossprocess); \ ::mozilla::_ipdltest::IPDLTestHelper::TestMode::mode} \
.TestWrapper(); \
} }
#define IPDL_TEST_BODY_SEGUE_(actorname) \ #define IPDL_TEST_BODY_SEGUE_(actorname) \
@ -68,10 +78,10 @@ class IPDLTestHelper {
// //
// GTest assertions fired in the child process will be relayed to the parent // GTest assertions fired in the child process will be relayed to the parent
// process, and should generally function correctly. // process, and should generally function correctly.
#define IPDL_TEST(actorname) \ #define IPDL_TEST(actorname) \
IPDL_TEST_HEAD_(actorname) \ IPDL_TEST_HEAD_(actorname) \
IPDL_TEST_DECL_(IPDLTest_CrossProcess, actorname, true) \ IPDL_TEST_DECL_(IPDLTest_CrossProcess, actorname, CrossProcess) \
IPDL_TEST_DECL_(IPDLTest_CrossThread, actorname, false) \ IPDL_TEST_DECL_(IPDLTest_CrossThread, actorname, SameProcess) \
IPDL_TEST_BODY_SEGUE_(actorname) IPDL_TEST_BODY_SEGUE_(actorname)
} // namespace mozilla::_ipdltest } // namespace mozilla::_ipdltest