From fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:14:29 +0200 Subject: Merging upstream version 125.0.1. Signed-off-by: Daniel Baumann --- ipc/chromium/moz.build | 37 +- ipc/chromium/src/base/message_pump_mac.h | 20 + ipc/chromium/src/base/message_pump_mac.mm | 27 +- ipc/chromium/src/base/process_util_ios.cpp | 17 + ipc/chromium/src/base/process_util_posix.cc | 2 +- ipc/chromium/src/chrome/common/ipc_message.h | 1 + ipc/chromium/src/chrome/common/mach_ipc_mac.h | 1 - ipc/chromium/src/mojo/core/ports/node.cc | 2 + .../src/third_party/libeventcommon.mozbuild | 37 +- ipc/chromium/src/third_party/moz.build | 8 +- ipc/docs/processes.rst | 3 +- ipc/glue/BackgroundChildImpl.cpp | 5 +- ipc/glue/BackgroundParentImpl.cpp | 14 +- ipc/glue/BackgroundParentImpl.h | 7 +- ipc/glue/CrashReporterHost.cpp | 25 +- ipc/glue/CrashReporterHost.h | 8 +- ipc/glue/EnumSerializer.h | 8 +- ipc/glue/ForkServiceChild.cpp | 6 +- ipc/glue/ForkServiceChild.h | 6 + ipc/glue/GeckoChildProcessHost.cpp | 122 ++- ipc/glue/IPCStreamUtils.cpp | 2 +- ipc/glue/MessageChannel.cpp | 11 +- ipc/glue/MessageChannel.h | 5 + ipc/glue/MessageLink.cpp | 10 +- ipc/glue/NodeChannel.cpp | 10 +- ipc/glue/PBackground.ipdl | 3 +- ipc/glue/PUtilityAudioDecoder.ipdl | 1 - ipc/glue/PUtilityProcess.ipdl | 4 +- ipc/glue/ProcessChild.cpp | 10 +- ipc/glue/ProcessChild.h | 9 + ipc/glue/ProtocolUtils.cpp | 19 +- ipc/glue/ProtocolUtils.h | 7 + ipc/glue/UtilityAudioDecoder.cpp | 4 +- ipc/glue/UtilityAudioDecoderChild.cpp | 54 +- ipc/glue/UtilityAudioDecoderChild.h | 32 +- ipc/glue/UtilityAudioDecoderParent.cpp | 26 +- ipc/glue/UtilityAudioDecoderParent.h | 4 +- ipc/glue/UtilityProcessChild.cpp | 6 +- ipc/glue/UtilityProcessChild.h | 3 +- ipc/glue/UtilityProcessHost.cpp | 4 - ipc/glue/UtilityProcessManager.cpp | 8 +- ipc/glue/UtilityProcessManager.h | 3 +- ipc/glue/UtilityProcessParent.cpp | 2 +- ipc/glue/moz.build | 2 +- ipc/glue/test/browser/browser_audio_fallback.toml | 7 +- .../browser/browser_audio_fallback_content.toml | 3 + ipc/glue/test/browser/browser_audio_locked.toml | 3 + ipc/glue/test/browser/browser_audio_shutdown.toml | 3 + ipc/glue/test/browser/browser_child_hang.js | 2 +- .../browser/browser_utility_audioDecodeCrash.js | 2 +- .../test/browser/browser_utility_audio_shutdown.js | 8 +- .../browser/browser_utility_filepicker_crashed.js | 13 +- .../test/browser/browser_utility_memoryReport.js | 19 +- ipc/glue/test/browser/head.js | 32 +- ipc/glue/test/browser/mochitest_audio_off.toml | 7 +- ipc/glue/test/browser/mochitest_audio_on.toml | 7 +- .../test/gtest/TestUtilityProcessSandboxing.cpp | 6 +- .../utility_process_xpcom/UtilityProcessTest.cpp | 27 +- ipc/ipdl/ipdl.py | 25 + ipc/ipdl/ipdl/__init__.py | 2 +- ipc/ipdl/ipdl/ast.py | 16 +- ipc/ipdl/ipdl/cgen.py | 6 +- ipc/ipdl/ipdl/lower.py | 40 +- ipc/ipdl/ipdl/type.py | 4 + ipc/ipdl/sync-messages.ini | 90 ++- ipc/ipdl/test/cxx/PTestActorPunning.ipdl | 28 - ipc/ipdl/test/cxx/PTestActorPunningPunned.ipdl | 18 - ipc/ipdl/test/cxx/PTestActorPunningSub.ipdl | 19 - ipc/ipdl/test/cxx/PTestAsyncReturns.ipdl | 20 - ipc/ipdl/test/cxx/PTestBadActor.ipdl | 21 - ipc/ipdl/test/cxx/PTestBadActorSub.ipdl | 20 - ipc/ipdl/test/cxx/PTestCancel.ipdl | 39 - ipc/ipdl/test/cxx/PTestCrashCleanup.ipdl | 20 - ipc/ipdl/test/cxx/PTestDataStructures.ipdl | 109 --- ipc/ipdl/test/cxx/PTestDataStructuresCommon.ipdlh | 107 --- ipc/ipdl/test/cxx/PTestDataStructuresSub.ipdl | 18 - ipc/ipdl/test/cxx/PTestDemon.ipdl | 24 - ipc/ipdl/test/cxx/PTestDesc.ipdl | 24 - ipc/ipdl/test/cxx/PTestDescSub.ipdl | 21 - ipc/ipdl/test/cxx/PTestDescSubsub.ipdl | 18 - ipc/ipdl/test/cxx/PTestEndpointBridgeMain.ipdl | 25 - ipc/ipdl/test/cxx/PTestEndpointBridgeMainSub.ipdl | 28 - ipc/ipdl/test/cxx/PTestEndpointBridgeSub.ipdl | 25 - ipc/ipdl/test/cxx/PTestEndpointOpens.ipdl | 22 - ipc/ipdl/test/cxx/PTestEndpointOpensOpened.ipdl | 25 - ipc/ipdl/test/cxx/PTestFailedCtor.ipdl | 17 - ipc/ipdl/test/cxx/PTestFailedCtorSub.ipdl | 21 - ipc/ipdl/test/cxx/PTestFailedCtorSubsub.ipdl | 18 - ipc/ipdl/test/cxx/PTestHandle.ipdl | 17 - ipc/ipdl/test/cxx/PTestHangs.ipdl | 22 - ipc/ipdl/test/cxx/PTestHighestPrio.ipdl | 21 - ipc/ipdl/test/cxx/PTestInterruptErrorCleanup.ipdl | 14 - ipc/ipdl/test/cxx/PTestInterruptRaces.ipdl | 27 - ipc/ipdl/test/cxx/PTestInterruptShutdownRace.ipdl | 19 - ipc/ipdl/test/cxx/PTestJSON.ipdl | 49 -- ipc/ipdl/test/cxx/PTestLatency.ipdl | 28 - ipc/ipdl/test/cxx/PTestManyChildAllocs.ipdl | 22 - ipc/ipdl/test/cxx/PTestManyChildAllocsSub.ipdl | 22 - ipc/ipdl/test/cxx/PTestMultiMgrs.ipdl | 25 - ipc/ipdl/test/cxx/PTestMultiMgrsBottom.ipdl | 18 - ipc/ipdl/test/cxx/PTestMultiMgrsLeft.ipdl | 21 - ipc/ipdl/test/cxx/PTestMultiMgrsRight.ipdl | 21 - ipc/ipdl/test/cxx/PTestNestedLoops.ipdl | 22 - ipc/ipdl/test/cxx/PTestRPC.ipdl | 24 - ipc/ipdl/test/cxx/PTestRaceDeadlock.ipdl | 23 - ipc/ipdl/test/cxx/PTestRaceDeferral.ipdl | 22 - ipc/ipdl/test/cxx/PTestRacyInterruptReplies.ipdl | 20 - ipc/ipdl/test/cxx/PTestRacyReentry.ipdl | 23 - ipc/ipdl/test/cxx/PTestRacyUndefer.ipdl | 30 - ipc/ipdl/test/cxx/PTestSanity.ipdl | 21 - ipc/ipdl/test/cxx/PTestSelfManage.ipdl | 21 - ipc/ipdl/test/cxx/PTestSelfManageRoot.ipdl | 20 - ipc/ipdl/test/cxx/PTestShmem.ipdl | 17 - ipc/ipdl/test/cxx/PTestShutdown.ipdl | 29 - ipc/ipdl/test/cxx/PTestShutdownSub.ipdl | 23 - ipc/ipdl/test/cxx/PTestShutdownSubsub.ipdl | 17 - ipc/ipdl/test/cxx/PTestStackHooks.ipdl | 28 - ipc/ipdl/test/cxx/PTestSyncError.ipdl | 20 - ipc/ipdl/test/cxx/PTestSyncHang.ipdl | 16 - ipc/ipdl/test/cxx/PTestSyncWakeup.ipdl | 23 - ipc/ipdl/test/cxx/PTestUniquePtrIPC.ipdl | 26 - ipc/ipdl/test/cxx/PTestUrgency.ipdl | 22 - ipc/ipdl/test/cxx/PTestUrgentHangs.ipdl | 31 - ipc/ipdl/test/cxx/TestActorPunning.cpp | 125 --- ipc/ipdl/test/cxx/TestActorPunning.h | 100 --- ipc/ipdl/test/cxx/TestAsyncReturns.cpp | 101 --- ipc/ipdl/test/cxx/TestAsyncReturns.h | 54 -- ipc/ipdl/test/cxx/TestBadActor.cpp | 59 -- ipc/ipdl/test/cxx/TestBadActor.h | 84 -- ipc/ipdl/test/cxx/TestCancel.cpp | 115 --- ipc/ipdl/test/cxx/TestCancel.h | 54 -- ipc/ipdl/test/cxx/TestCrashCleanup.cpp | 100 --- ipc/ipdl/test/cxx/TestCrashCleanup.h | 49 -- ipc/ipdl/test/cxx/TestDataStructures.cpp | 888 --------------------- ipc/ipdl/test/cxx/TestDataStructures.h | 180 ----- ipc/ipdl/test/cxx/TestDemon.cpp | 362 --------- ipc/ipdl/test/cxx/TestDemon.h | 91 --- ipc/ipdl/test/cxx/TestDesc.cpp | 78 -- ipc/ipdl/test/cxx/TestDesc.h | 115 --- ipc/ipdl/test/cxx/TestEndpointBridgeMain.cpp | 226 ------ ipc/ipdl/test/cxx/TestEndpointBridgeMain.h | 132 --- ipc/ipdl/test/cxx/TestEndpointOpens.cpp | 242 ------ ipc/ipdl/test/cxx/TestEndpointOpens.h | 102 --- ipc/ipdl/test/cxx/TestFailedCtor.cpp | 112 --- ipc/ipdl/test/cxx/TestFailedCtor.h | 127 --- ipc/ipdl/test/cxx/TestHangs.cpp | 127 --- ipc/ipdl/test/cxx/TestHangs.h | 75 -- ipc/ipdl/test/cxx/TestHighestPrio.cpp | 91 --- ipc/ipdl/test/cxx/TestHighestPrio.h | 55 -- ipc/ipdl/test/cxx/TestInterruptErrorCleanup.cpp | 138 ---- ipc/ipdl/test/cxx/TestInterruptErrorCleanup.h | 52 -- ipc/ipdl/test/cxx/TestInterruptRaces.cpp | 169 ---- ipc/ipdl/test/cxx/TestInterruptRaces.h | 104 --- ipc/ipdl/test/cxx/TestInterruptShutdownRace.cpp | 111 --- ipc/ipdl/test/cxx/TestInterruptShutdownRace.h | 56 -- ipc/ipdl/test/cxx/TestJSON.cpp | 113 --- ipc/ipdl/test/cxx/TestJSON.h | 93 --- ipc/ipdl/test/cxx/TestLatency.cpp | 210 ----- ipc/ipdl/test/cxx/TestLatency.h | 107 --- ipc/ipdl/test/cxx/TestManyChildAllocs.cpp | 83 -- ipc/ipdl/test/cxx/TestManyChildAllocs.h | 82 -- ipc/ipdl/test/cxx/TestMultiMgrs.cpp | 83 -- ipc/ipdl/test/cxx/TestMultiMgrs.h | 222 ------ ipc/ipdl/test/cxx/TestNestedLoops.cpp | 78 -- ipc/ipdl/test/cxx/TestNestedLoops.h | 59 -- ipc/ipdl/test/cxx/TestRPC.cpp | 107 --- ipc/ipdl/test/cxx/TestRPC.h | 60 -- ipc/ipdl/test/cxx/TestRaceDeadlock.cpp | 102 --- ipc/ipdl/test/cxx/TestRaceDeadlock.h | 68 -- ipc/ipdl/test/cxx/TestRaceDeferral.cpp | 84 -- ipc/ipdl/test/cxx/TestRaceDeferral.h | 67 -- ipc/ipdl/test/cxx/TestRacyInterruptReplies.cpp | 94 --- ipc/ipdl/test/cxx/TestRacyInterruptReplies.h | 65 -- ipc/ipdl/test/cxx/TestRacyReentry.cpp | 63 -- ipc/ipdl/test/cxx/TestRacyReentry.h | 59 -- ipc/ipdl/test/cxx/TestRacyUndefer.cpp | 83 -- ipc/ipdl/test/cxx/TestRacyUndefer.h | 62 -- ipc/ipdl/test/cxx/TestSanity.cpp | 52 -- ipc/ipdl/test/cxx/TestSanity.h | 55 -- ipc/ipdl/test/cxx/TestSelfManageRoot.cpp | 54 -- ipc/ipdl/test/cxx/TestSelfManageRoot.h | 117 --- ipc/ipdl/test/cxx/TestShmem.cpp | 106 --- ipc/ipdl/test/cxx/TestShmem.h | 55 -- ipc/ipdl/test/cxx/TestShutdown.cpp | 185 ----- ipc/ipdl/test/cxx/TestShutdown.h | 168 ---- ipc/ipdl/test/cxx/TestStackHooks.cpp | 122 --- ipc/ipdl/test/cxx/TestStackHooks.h | 107 --- ipc/ipdl/test/cxx/TestSyncError.cpp | 45 -- ipc/ipdl/test/cxx/TestSyncError.h | 61 -- ipc/ipdl/test/cxx/TestSyncHang.cpp | 62 -- ipc/ipdl/test/cxx/TestSyncHang.h | 50 -- ipc/ipdl/test/cxx/TestSyncWakeup.cpp | 106 --- ipc/ipdl/test/cxx/TestSyncWakeup.h | 66 -- ipc/ipdl/test/cxx/TestUniquePtrIPC.cpp | 81 -- ipc/ipdl/test/cxx/TestUniquePtrIPC.h | 61 -- ipc/ipdl/test/cxx/TestUrgency.cpp | 117 --- ipc/ipdl/test/cxx/TestUrgency.h | 57 -- ipc/ipdl/test/cxx/TestUrgentHangs.cpp | 174 ---- ipc/ipdl/test/cxx/TestUrgentHangs.h | 64 -- ipc/ipdl/test/cxx/moz.build | 134 ---- ipc/ipdl/test/gtest/IPDLUnitTest.h | 97 ++- ipc/ipdl/test/gtest/PTestAsyncReturns.ipdl | 19 + ipc/ipdl/test/gtest/PTestCancel.ipdl | 39 + ipc/ipdl/test/gtest/PTestDataStructures.ipdl | 106 +++ .../test/gtest/PTestDataStructuresCommon.ipdlh | 107 +++ ipc/ipdl/test/gtest/PTestDataStructuresSub.ipdl | 15 + ipc/ipdl/test/gtest/PTestDescendant.ipdl | 22 + ipc/ipdl/test/gtest/PTestDescendantSub.ipdl | 19 + ipc/ipdl/test/gtest/PTestDescendantSubsub.ipdl | 14 + ipc/ipdl/test/gtest/PTestEndpointOpens.ipdl | 22 + ipc/ipdl/test/gtest/PTestEndpointOpensOpened.ipdl | 22 + ipc/ipdl/test/gtest/PTestHangs.ipdl | 20 + ipc/ipdl/test/gtest/PTestJSON.ipdl | 43 + ipc/ipdl/test/gtest/PTestJSONHandle.ipdl | 15 + ipc/ipdl/test/gtest/PTestManyChildAllocs.ipdl | 18 + ipc/ipdl/test/gtest/PTestManyChildAllocsSub.ipdl | 18 + ipc/ipdl/test/gtest/PTestMostNested.ipdl | 23 + ipc/ipdl/test/gtest/PTestMultiMgrs.ipdl | 23 + ipc/ipdl/test/gtest/PTestMultiMgrsBottom.ipdl | 16 + ipc/ipdl/test/gtest/PTestMultiMgrsLeft.ipdl | 19 + ipc/ipdl/test/gtest/PTestMultiMgrsRight.ipdl | 19 + ipc/ipdl/test/gtest/PTestSelfManage.ipdl | 17 + ipc/ipdl/test/gtest/PTestSelfManageRoot.ipdl | 16 + ipc/ipdl/test/gtest/PTestShmem.ipdl | 15 + ipc/ipdl/test/gtest/PTestSyncError.ipdl | 16 + ipc/ipdl/test/gtest/PTestUniquePtrIPC.ipdl | 17 + ipc/ipdl/test/gtest/PTestUrgency.ipdl | 20 + ipc/ipdl/test/gtest/TestAsyncReturns.cpp | 77 ++ ipc/ipdl/test/gtest/TestCancel.cpp | 126 +++ ipc/ipdl/test/gtest/TestDataStructures.cpp | 864 ++++++++++++++++++++ ipc/ipdl/test/gtest/TestDescendant.cpp | 98 +++ ipc/ipdl/test/gtest/TestEndpointOpens.cpp | 159 ++++ ipc/ipdl/test/gtest/TestHangs.cpp | 133 +++ ipc/ipdl/test/gtest/TestJSON.cpp | 157 ++++ ipc/ipdl/test/gtest/TestManyChildAllocs.cpp | 82 ++ ipc/ipdl/test/gtest/TestMostNested.cpp | 88 ++ ipc/ipdl/test/gtest/TestMultiMgrs.cpp | 202 +++++ ipc/ipdl/test/gtest/TestSelfManage.cpp | 100 +++ ipc/ipdl/test/gtest/TestShmem.cpp | 122 +++ ipc/ipdl/test/gtest/TestSyncError.cpp | 44 + ipc/ipdl/test/gtest/TestUniquePtrIPC.cpp | 80 ++ ipc/ipdl/test/gtest/TestUrgency.cpp | 115 +++ ipc/ipdl/test/gtest/moz.build | 41 + ipc/ipdl/test/ipdl/error/ReturnFromDestructor.ipdl | 7 + ipc/ipdl/test/ipdl/error/SyncDestructor.ipdl | 7 + ipc/ipdl/test/ipdl/ok/PDeleteSub.ipdl | 2 +- ipc/ipdl/test/ipdl/sync-messages.ini | 2 - 247 files changed, 3889 insertions(+), 10439 deletions(-) create mode 100644 ipc/chromium/src/base/process_util_ios.cpp delete mode 100644 ipc/ipdl/test/cxx/PTestActorPunning.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestActorPunningPunned.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestActorPunningSub.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestAsyncReturns.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestBadActor.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestBadActorSub.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestCancel.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestCrashCleanup.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestDataStructures.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestDataStructuresCommon.ipdlh delete mode 100644 ipc/ipdl/test/cxx/PTestDataStructuresSub.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestDemon.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestDesc.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestDescSub.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestDescSubsub.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestEndpointBridgeMain.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestEndpointBridgeMainSub.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestEndpointBridgeSub.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestEndpointOpens.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestEndpointOpensOpened.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestFailedCtor.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestFailedCtorSub.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestFailedCtorSubsub.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestHandle.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestHangs.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestHighestPrio.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestInterruptErrorCleanup.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestInterruptRaces.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestInterruptShutdownRace.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestJSON.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestLatency.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestManyChildAllocs.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestManyChildAllocsSub.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestMultiMgrs.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestMultiMgrsBottom.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestMultiMgrsLeft.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestMultiMgrsRight.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestNestedLoops.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestRPC.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestRaceDeadlock.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestRaceDeferral.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestRacyInterruptReplies.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestRacyReentry.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestRacyUndefer.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestSanity.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestSelfManage.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestSelfManageRoot.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestShmem.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestShutdown.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestShutdownSub.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestShutdownSubsub.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestStackHooks.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestSyncError.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestSyncHang.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestSyncWakeup.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestUniquePtrIPC.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestUrgency.ipdl delete mode 100644 ipc/ipdl/test/cxx/PTestUrgentHangs.ipdl delete mode 100644 ipc/ipdl/test/cxx/TestActorPunning.cpp delete mode 100644 ipc/ipdl/test/cxx/TestActorPunning.h delete mode 100644 ipc/ipdl/test/cxx/TestAsyncReturns.cpp delete mode 100644 ipc/ipdl/test/cxx/TestAsyncReturns.h delete mode 100644 ipc/ipdl/test/cxx/TestBadActor.cpp delete mode 100644 ipc/ipdl/test/cxx/TestBadActor.h delete mode 100644 ipc/ipdl/test/cxx/TestCancel.cpp delete mode 100644 ipc/ipdl/test/cxx/TestCancel.h delete mode 100644 ipc/ipdl/test/cxx/TestCrashCleanup.cpp delete mode 100644 ipc/ipdl/test/cxx/TestCrashCleanup.h delete mode 100644 ipc/ipdl/test/cxx/TestDataStructures.cpp delete mode 100644 ipc/ipdl/test/cxx/TestDataStructures.h delete mode 100644 ipc/ipdl/test/cxx/TestDemon.cpp delete mode 100644 ipc/ipdl/test/cxx/TestDemon.h delete mode 100644 ipc/ipdl/test/cxx/TestDesc.cpp delete mode 100644 ipc/ipdl/test/cxx/TestDesc.h delete mode 100644 ipc/ipdl/test/cxx/TestEndpointBridgeMain.cpp delete mode 100644 ipc/ipdl/test/cxx/TestEndpointBridgeMain.h delete mode 100644 ipc/ipdl/test/cxx/TestEndpointOpens.cpp delete mode 100644 ipc/ipdl/test/cxx/TestEndpointOpens.h delete mode 100644 ipc/ipdl/test/cxx/TestFailedCtor.cpp delete mode 100644 ipc/ipdl/test/cxx/TestFailedCtor.h delete mode 100644 ipc/ipdl/test/cxx/TestHangs.cpp delete mode 100644 ipc/ipdl/test/cxx/TestHangs.h delete mode 100644 ipc/ipdl/test/cxx/TestHighestPrio.cpp delete mode 100644 ipc/ipdl/test/cxx/TestHighestPrio.h delete mode 100644 ipc/ipdl/test/cxx/TestInterruptErrorCleanup.cpp delete mode 100644 ipc/ipdl/test/cxx/TestInterruptErrorCleanup.h delete mode 100644 ipc/ipdl/test/cxx/TestInterruptRaces.cpp delete mode 100644 ipc/ipdl/test/cxx/TestInterruptRaces.h delete mode 100644 ipc/ipdl/test/cxx/TestInterruptShutdownRace.cpp delete mode 100644 ipc/ipdl/test/cxx/TestInterruptShutdownRace.h delete mode 100644 ipc/ipdl/test/cxx/TestJSON.cpp delete mode 100644 ipc/ipdl/test/cxx/TestJSON.h delete mode 100644 ipc/ipdl/test/cxx/TestLatency.cpp delete mode 100644 ipc/ipdl/test/cxx/TestLatency.h delete mode 100644 ipc/ipdl/test/cxx/TestManyChildAllocs.cpp delete mode 100644 ipc/ipdl/test/cxx/TestManyChildAllocs.h delete mode 100644 ipc/ipdl/test/cxx/TestMultiMgrs.cpp delete mode 100644 ipc/ipdl/test/cxx/TestMultiMgrs.h delete mode 100644 ipc/ipdl/test/cxx/TestNestedLoops.cpp delete mode 100644 ipc/ipdl/test/cxx/TestNestedLoops.h delete mode 100644 ipc/ipdl/test/cxx/TestRPC.cpp delete mode 100644 ipc/ipdl/test/cxx/TestRPC.h delete mode 100644 ipc/ipdl/test/cxx/TestRaceDeadlock.cpp delete mode 100644 ipc/ipdl/test/cxx/TestRaceDeadlock.h delete mode 100644 ipc/ipdl/test/cxx/TestRaceDeferral.cpp delete mode 100644 ipc/ipdl/test/cxx/TestRaceDeferral.h delete mode 100644 ipc/ipdl/test/cxx/TestRacyInterruptReplies.cpp delete mode 100644 ipc/ipdl/test/cxx/TestRacyInterruptReplies.h delete mode 100644 ipc/ipdl/test/cxx/TestRacyReentry.cpp delete mode 100644 ipc/ipdl/test/cxx/TestRacyReentry.h delete mode 100644 ipc/ipdl/test/cxx/TestRacyUndefer.cpp delete mode 100644 ipc/ipdl/test/cxx/TestRacyUndefer.h delete mode 100644 ipc/ipdl/test/cxx/TestSanity.cpp delete mode 100644 ipc/ipdl/test/cxx/TestSanity.h delete mode 100644 ipc/ipdl/test/cxx/TestSelfManageRoot.cpp delete mode 100644 ipc/ipdl/test/cxx/TestSelfManageRoot.h delete mode 100644 ipc/ipdl/test/cxx/TestShmem.cpp delete mode 100644 ipc/ipdl/test/cxx/TestShmem.h delete mode 100644 ipc/ipdl/test/cxx/TestShutdown.cpp delete mode 100644 ipc/ipdl/test/cxx/TestShutdown.h delete mode 100644 ipc/ipdl/test/cxx/TestStackHooks.cpp delete mode 100644 ipc/ipdl/test/cxx/TestStackHooks.h delete mode 100644 ipc/ipdl/test/cxx/TestSyncError.cpp delete mode 100644 ipc/ipdl/test/cxx/TestSyncError.h delete mode 100644 ipc/ipdl/test/cxx/TestSyncHang.cpp delete mode 100644 ipc/ipdl/test/cxx/TestSyncHang.h delete mode 100644 ipc/ipdl/test/cxx/TestSyncWakeup.cpp delete mode 100644 ipc/ipdl/test/cxx/TestSyncWakeup.h delete mode 100644 ipc/ipdl/test/cxx/TestUniquePtrIPC.cpp delete mode 100644 ipc/ipdl/test/cxx/TestUniquePtrIPC.h delete mode 100644 ipc/ipdl/test/cxx/TestUrgency.cpp delete mode 100644 ipc/ipdl/test/cxx/TestUrgency.h delete mode 100644 ipc/ipdl/test/cxx/TestUrgentHangs.cpp delete mode 100644 ipc/ipdl/test/cxx/TestUrgentHangs.h create mode 100644 ipc/ipdl/test/gtest/PTestAsyncReturns.ipdl create mode 100644 ipc/ipdl/test/gtest/PTestCancel.ipdl create mode 100644 ipc/ipdl/test/gtest/PTestDataStructures.ipdl create mode 100644 ipc/ipdl/test/gtest/PTestDataStructuresCommon.ipdlh create mode 100644 ipc/ipdl/test/gtest/PTestDataStructuresSub.ipdl create mode 100644 ipc/ipdl/test/gtest/PTestDescendant.ipdl create mode 100644 ipc/ipdl/test/gtest/PTestDescendantSub.ipdl create mode 100644 ipc/ipdl/test/gtest/PTestDescendantSubsub.ipdl create mode 100644 ipc/ipdl/test/gtest/PTestEndpointOpens.ipdl create mode 100644 ipc/ipdl/test/gtest/PTestEndpointOpensOpened.ipdl create mode 100644 ipc/ipdl/test/gtest/PTestHangs.ipdl create mode 100644 ipc/ipdl/test/gtest/PTestJSON.ipdl create mode 100644 ipc/ipdl/test/gtest/PTestJSONHandle.ipdl create mode 100644 ipc/ipdl/test/gtest/PTestManyChildAllocs.ipdl create mode 100644 ipc/ipdl/test/gtest/PTestManyChildAllocsSub.ipdl create mode 100644 ipc/ipdl/test/gtest/PTestMostNested.ipdl create mode 100644 ipc/ipdl/test/gtest/PTestMultiMgrs.ipdl create mode 100644 ipc/ipdl/test/gtest/PTestMultiMgrsBottom.ipdl create mode 100644 ipc/ipdl/test/gtest/PTestMultiMgrsLeft.ipdl create mode 100644 ipc/ipdl/test/gtest/PTestMultiMgrsRight.ipdl create mode 100644 ipc/ipdl/test/gtest/PTestSelfManage.ipdl create mode 100644 ipc/ipdl/test/gtest/PTestSelfManageRoot.ipdl create mode 100644 ipc/ipdl/test/gtest/PTestShmem.ipdl create mode 100644 ipc/ipdl/test/gtest/PTestSyncError.ipdl create mode 100644 ipc/ipdl/test/gtest/PTestUniquePtrIPC.ipdl create mode 100644 ipc/ipdl/test/gtest/PTestUrgency.ipdl create mode 100644 ipc/ipdl/test/gtest/TestAsyncReturns.cpp create mode 100644 ipc/ipdl/test/gtest/TestCancel.cpp create mode 100644 ipc/ipdl/test/gtest/TestDataStructures.cpp create mode 100644 ipc/ipdl/test/gtest/TestDescendant.cpp create mode 100644 ipc/ipdl/test/gtest/TestEndpointOpens.cpp create mode 100644 ipc/ipdl/test/gtest/TestHangs.cpp create mode 100644 ipc/ipdl/test/gtest/TestJSON.cpp create mode 100644 ipc/ipdl/test/gtest/TestManyChildAllocs.cpp create mode 100644 ipc/ipdl/test/gtest/TestMostNested.cpp create mode 100644 ipc/ipdl/test/gtest/TestMultiMgrs.cpp create mode 100644 ipc/ipdl/test/gtest/TestSelfManage.cpp create mode 100644 ipc/ipdl/test/gtest/TestShmem.cpp create mode 100644 ipc/ipdl/test/gtest/TestSyncError.cpp create mode 100644 ipc/ipdl/test/gtest/TestUniquePtrIPC.cpp create mode 100644 ipc/ipdl/test/gtest/TestUrgency.cpp create mode 100644 ipc/ipdl/test/ipdl/error/ReturnFromDestructor.ipdl create mode 100644 ipc/ipdl/test/ipdl/error/SyncDestructor.ipdl (limited to 'ipc') diff --git a/ipc/chromium/moz.build b/ipc/chromium/moz.build index 56f24c24bb..429c068d34 100644 --- a/ipc/chromium/moz.build +++ b/ipc/chromium/moz.build @@ -39,7 +39,7 @@ UNIFIED_SOURCES += [ "src/mojo/core/ports/user_message.cc", ] -if os_win: +if CONFIG["TARGET_KERNEL"] == "WINNT": SOURCES += [ "src/base/condition_variable_win.cc", "src/base/lock_impl_win.cc", @@ -60,7 +60,7 @@ if os_win: elif not CONFIG["MOZ_SYSTEM_LIBEVENT"]: DIRS += ["src/third_party"] -if os_posix: +if CONFIG["TARGET_KERNEL"] != "WINNT": UNIFIED_SOURCES += [ "src/base/condition_variable_posix.cc", "src/base/lock_impl_posix.cc", @@ -75,12 +75,9 @@ if os_posix: "src/chrome/common/process_watcher_posix_sigchld.cc", ] -if os_macosx: +if CONFIG["TARGET_KERNEL"] == "Darwin": UNIFIED_SOURCES += [ - "src/base/chrome_application_mac.mm", - "src/base/mac_util.mm", "src/base/message_pump_mac.mm", - "src/base/process_util_mac.mm", "src/base/scoped_nsautorelease_pool.mm", "src/base/sys_string_conversions_mac.mm", "src/base/time_mac.cc", @@ -93,13 +90,25 @@ if os_macosx: "src/base/platform_thread_mac.mm", ] -if os_bsd: +if CONFIG["TARGET_OS"] == "OSX": + UNIFIED_SOURCES += [ + "src/base/chrome_application_mac.mm", + "src/base/mac_util.mm", + "src/base/process_util_mac.mm", + ] + +if CONFIG["TARGET_OS"] == "iOS": + UNIFIED_SOURCES += [ + "src/base/process_util_ios.cpp", + ] + +if CONFIG["TARGET_KERNEL"] in ("DragonFly", "FreeBSD", "NetBSD", "OpenBSD"): SOURCES += [ "src/base/process_util_linux.cc", "src/base/time_posix.cc", ] -if os_linux: +if CONFIG["TARGET_KERNEL"] == "Linux": SOURCES += [ "src/base/process_util_linux.cc", "src/base/set_process_title_linux.cc", @@ -112,17 +121,15 @@ if os_linux: DEFINES["ANDROID"] = True DEFINES["_POSIX_MONOTONIC_CLOCK"] = 0 -if os_bsd or os_linux: - if CONFIG["MOZ_WIDGET_TOOLKIT"] == "gtk": - SOURCES += [ - "src/base/message_pump_glib.cc", - ] - -if os_solaris: +if CONFIG["TARGET_KERNEL"] == "SunOS": SOURCES += [ "src/base/process_util_linux.cc", "src/base/time_posix.cc", ] +elif CONFIG["MOZ_WIDGET_TOOLKIT"] == "gtk": + SOURCES += [ + "src/base/message_pump_glib.cc", + ] if CONFIG["MOZ_WIDGET_TOOLKIT"] == "gtk": CXXFLAGS += CONFIG["MOZ_GTK3_CFLAGS"] diff --git a/ipc/chromium/src/base/message_pump_mac.h b/ipc/chromium/src/base/message_pump_mac.h index 13902bbf3e..7d7796b98b 100644 --- a/ipc/chromium/src/base/message_pump_mac.h +++ b/ipc/chromium/src/base/message_pump_mac.h @@ -144,11 +144,13 @@ class MessagePumpCFRunLoopBase : public MessagePump { // the basis of run loops starting and stopping. virtual void EnterExitRunLoop(CFRunLoopActivity activity); +#if !defined(XP_IOS) // IOKit power state change notification callback, called when the system // enters and leaves the sleep state. static void PowerStateNotification(void* info, io_service_t service, uint32_t message_type, void* message_argument); +#endif // The thread's run loop. CFRunLoopRef run_loop_; @@ -241,6 +243,23 @@ class MessagePumpNSRunLoop : public MessagePumpCFRunLoopBase { DISALLOW_COPY_AND_ASSIGN(MessagePumpNSRunLoop); }; +#if defined(XP_IOS) +// This is a fake message pump. It attaches sources to the main thread's +// CFRunLoop, so PostTask() will work, but it is unable to drive the loop +// directly, so calling Run() or Quit() are errors. +class MessagePumpUIApplication : public MessagePumpCFRunLoopBase { + public: + MessagePumpUIApplication() {} + + void DoRun(Delegate* delegate) override; + void Quit() override; + + private: + DISALLOW_COPY_AND_ASSIGN(MessagePumpUIApplication); +}; + +#else + class MessagePumpNSApplication : public MessagePumpCFRunLoopBase { public: MessagePumpNSApplication(); @@ -264,6 +283,7 @@ class MessagePumpNSApplication : public MessagePumpCFRunLoopBase { DISALLOW_COPY_AND_ASSIGN(MessagePumpNSApplication); }; +#endif class MessagePumpMac { public: diff --git a/ipc/chromium/src/base/message_pump_mac.mm b/ipc/chromium/src/base/message_pump_mac.mm index 1382e2a0dc..a5e7092d16 100644 --- a/ipc/chromium/src/base/message_pump_mac.mm +++ b/ipc/chromium/src/base/message_pump_mac.mm @@ -4,14 +4,18 @@ #include "base/message_pump_mac.h" -#import +#if !defined(XP_IOS) +# import +# include +#endif #import #include -#include #include -#import "base/chrome_application_mac.h" +#if !defined(XP_IOS) +# import "base/chrome_application_mac.h" +#endif #include "base/logging.h" #include "base/time.h" @@ -120,6 +124,7 @@ MessagePumpCFRunLoopBase::MessagePumpCFRunLoopBase() EnterExitObserver, &observer_context); CFRunLoopAddObserver(run_loop_, enter_exit_observer_, kCFRunLoopCommonModes); +#if !defined(XP_IOS) root_power_domain_ = IORegisterForSystemPower(this, &power_notification_port_, PowerStateNotification, &power_notification_object_); @@ -128,12 +133,14 @@ MessagePumpCFRunLoopBase::MessagePumpCFRunLoopBase() run_loop_, IONotificationPortGetRunLoopSource(power_notification_port_), kCFRunLoopCommonModes); } +#endif } // Ideally called on the run loop thread. If other run loops were running // lower on the run loop thread's stack when this object was created, the // same number of run loops must be running when this object is destroyed. MessagePumpCFRunLoopBase::~MessagePumpCFRunLoopBase() { +#if !defined(XP_IOS) if (root_power_domain_ != MACH_PORT_NULL) { CFRunLoopRemoveSource( run_loop_, IONotificationPortGetRunLoopSource(power_notification_port_), @@ -142,6 +149,7 @@ MessagePumpCFRunLoopBase::~MessagePumpCFRunLoopBase() { IOServiceClose(root_power_domain_); IONotificationPortDestroy(power_notification_port_); } +#endif CFRunLoopRemoveObserver(run_loop_, enter_exit_observer_, kCFRunLoopCommonModes); @@ -478,6 +486,7 @@ void MessagePumpCFRunLoopBase::EnterExitObserver(CFRunLoopObserverRef observer, self->EnterExitRunLoop(activity); } +#if !defined(XP_IOS) // Called from the run loop. // static void MessagePumpCFRunLoopBase::PowerStateNotification(void* info, @@ -544,6 +553,7 @@ void MessagePumpCFRunLoopBase::PowerStateNotification(void* info, break; } } +#endif // Called by MessagePumpCFRunLoopBase::EnterExitRunLoop. The default // implementation is a no-op. @@ -630,6 +640,12 @@ void MessagePumpNSRunLoop::Quit() { CFRunLoopWakeUp(run_loop()); } +#if defined(XP_IOS) +void MessagePumpUIApplication::DoRun(Delegate* delegate) { NOTREACHED(); } + +void MessagePumpUIApplication::Quit() { NOTREACHED(); } + +#else MessagePumpNSApplication::MessagePumpNSApplication() : keep_running_(true), running_own_loop_(false) {} @@ -722,11 +738,16 @@ NSAutoreleasePool* MessagePumpNSApplication::CreateAutoreleasePool() { } return pool; } +#endif // static MessagePump* MessagePumpMac::Create() { if ([NSThread isMainThread]) { +#if defined(XP_IOS) + return new MessagePumpUIApplication; +#else return new MessagePumpNSApplication; +#endif } return new MessagePumpNSRunLoop; diff --git a/ipc/chromium/src/base/process_util_ios.cpp b/ipc/chromium/src/base/process_util_ios.cpp new file mode 100644 index 0000000000..1ec4e77561 --- /dev/null +++ b/ipc/chromium/src/base/process_util_ios.cpp @@ -0,0 +1,17 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +// Copyright (c) 2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/process_util.h" + +namespace base { + +Result LaunchApp(const std::vector& argv, + LaunchOptions&& options, + ProcessHandle* process_handle) { + return Err(LaunchError("LaunchApp is not supported on iOS")); +} + +} // namespace base diff --git a/ipc/chromium/src/base/process_util_posix.cc b/ipc/chromium/src/base/process_util_posix.cc index 3229570ad8..d91dc25e9f 100644 --- a/ipc/chromium/src/base/process_util_posix.cc +++ b/ipc/chromium/src/base/process_util_posix.cc @@ -198,7 +198,7 @@ void CloseSuperfluousFds(void* aCtx, bool (*aShouldPreserve)(void*, int)) { bool IsProcessDead(ProcessHandle handle, bool blocking) { auto handleForkServer = [handle]() -> mozilla::Maybe { #ifdef MOZ_ENABLE_FORKSERVER - if (errno == ECHILD && mozilla::ipc::ForkServiceChild::Get()) { + if (errno == ECHILD && mozilla::ipc::ForkServiceChild::WasUsed()) { // We only know if a process exists, but not if it has crashed. // // Since content processes are not direct children of the chrome diff --git a/ipc/chromium/src/chrome/common/ipc_message.h b/ipc/chromium/src/chrome/common/ipc_message.h index 733ae9e493..281a6d6bad 100644 --- a/ipc/chromium/src/chrome/common/ipc_message.h +++ b/ipc/chromium/src/chrome/common/ipc_message.h @@ -37,6 +37,7 @@ namespace IPC { //------------------------------------------------------------------------------ // Generated by IPDL compiler +bool IPCMessageTypeIsSync(uint32_t aMessageType); const char* StringFromIPCMessageType(uint32_t aMessageType); class Channel; diff --git a/ipc/chromium/src/chrome/common/mach_ipc_mac.h b/ipc/chromium/src/chrome/common/mach_ipc_mac.h index c9af70c0c6..4d2af64176 100644 --- a/ipc/chromium/src/chrome/common/mach_ipc_mac.h +++ b/ipc/chromium/src/chrome/common/mach_ipc_mac.h @@ -9,7 +9,6 @@ #include #include -#include #include #include "mozilla/Maybe.h" diff --git a/ipc/chromium/src/mojo/core/ports/node.cc b/ipc/chromium/src/mojo/core/ports/node.cc index 63e58c9928..935771eeb7 100644 --- a/ipc/chromium/src/mojo/core/ports/node.cc +++ b/ipc/chromium/src/mojo/core/ports/node.cc @@ -516,6 +516,7 @@ int Node::AcceptEvent(const NodeName& from_node, ScopedEvent event) { return AcceptEventInternal(port_ref, from_node, std::move(event)); } +#ifndef FUZZING_SNAPSHOT // Before processing the event, verify the sender and sequence number. { SinglePortLocker locker(&port_ref); @@ -532,6 +533,7 @@ int Node::AcceptEvent(const NodeName& from_node, ScopedEvent event) { return OK; } } +#endif int ret = AcceptEventInternal(port_ref, from_node, std::move(event)); diff --git a/ipc/chromium/src/third_party/libeventcommon.mozbuild b/ipc/chromium/src/third_party/libeventcommon.mozbuild index 5037ec77a5..e8a74bf802 100644 --- a/ipc/chromium/src/third_party/libeventcommon.mozbuild +++ b/ipc/chromium/src/third_party/libeventcommon.mozbuild @@ -4,35 +4,18 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -os_win = 0 -os_posix = 0 -os_macosx = 0 -os_bsd = 0 -os_linux = 0 -os_solaris = 0 - -if CONFIG['OS_ARCH'] == 'WINNT': - os_win = 1 +if CONFIG['TARGET_KERNEL'] == 'Darwin': + libevent_include_suffix = 'mac' +elif CONFIG['TARGET_KERNEL'] in ('DragonFly', 'FreeBSD', 'NetBSD', 'OpenBSD'): + libevent_include_suffix = 'bsd' +elif CONFIG['TARGET_KERNEL'] == 'SunOS': + libevent_include_suffix = 'solaris' +elif CONFIG['TARGET_OS'] == 'Android': + libevent_include_suffix = 'android' else: - os_posix = 1 - if CONFIG['OS_ARCH'] == 'Darwin': - os_macosx = 1 - libevent_include_suffix = 'mac' - elif CONFIG['OS_ARCH'] in ['DragonFly', 'FreeBSD', 'GNU_kFreeBSD', - 'NetBSD', 'OpenBSD']: - os_bsd = 1 - libevent_include_suffix = 'bsd' - elif CONFIG['OS_ARCH'] == 'SunOS': - os_solaris = 1 - libevent_include_suffix = 'solaris' - else: - os_linux = 1 - if CONFIG['OS_TARGET'] == 'Android': - libevent_include_suffix = 'android' - else: - libevent_include_suffix = 'linux' + libevent_include_suffix = 'linux' -if os_posix and not CONFIG['MOZ_SYSTEM_LIBEVENT']: +if CONFIG["TARGET_KERNEL"] != "WINNT" and not CONFIG['MOZ_SYSTEM_LIBEVENT']: DEFINES['HAVE_CONFIG_H'] = True LOCAL_INCLUDES += sorted([ 'libevent', diff --git a/ipc/chromium/src/third_party/moz.build b/ipc/chromium/src/third_party/moz.build index 6572d01aa9..4a7dfd3fd1 100644 --- a/ipc/chromium/src/third_party/moz.build +++ b/ipc/chromium/src/third_party/moz.build @@ -7,7 +7,7 @@ libevent_path_prefix = '.' include(libevent_path_prefix + '/libeventcommon.mozbuild') -if os_win: +if CONFIG["TARGET_KERNEL"] == "WINNT": error('should not reach here on Windows') if CONFIG['MOZ_SYSTEM_LIBEVENT']: @@ -42,12 +42,12 @@ SOURCES += [ # 'libevent/evrpc.c', # Unused file. # conflicting TAILQ_ENTRY definition ] -if os_macosx or os_bsd: +if CONFIG["TARGET_KERNEL"] in ("Darwin", "DragonFly", "FreeBSD", "NetBSD", "OpenBSD"): UNIFIED_SOURCES += [ 'libevent/kqueue.c', ] -if os_linux: +if CONFIG["TARGET_KERNEL"] == "Linux": UNIFIED_SOURCES += [ 'libevent/epoll.c', ] @@ -56,7 +56,7 @@ if os_linux: 'libevent/epoll_sub.c', ] -if os_solaris: +if CONFIG["TARGET_KERNEL"] == "SunOS": SOURCES += [ 'libevent/devpoll.c', 'libevent/evport.c', diff --git a/ipc/docs/processes.rst b/ipc/docs/processes.rst index 89ec5e8013..08e0177de2 100644 --- a/ipc/docs/processes.rst +++ b/ipc/docs/processes.rst @@ -324,7 +324,8 @@ process there. - For `about:processes` you will probably want to follow the following steps: + Add handling for your new process type producing a unique `fluentName `_, i.e., constructing a dynamic name is highly discouraged - + Add matching localization strings within `fluent localization file `_ + + Add matching localization strings within `about:processes localization file `_ + + Add matching localization strings within `about:support localization file `_ Profiler ######## diff --git a/ipc/glue/BackgroundChildImpl.cpp b/ipc/glue/BackgroundChildImpl.cpp index 5bcfbd2838..f21f393e2c 100644 --- a/ipc/glue/BackgroundChildImpl.cpp +++ b/ipc/glue/BackgroundChildImpl.cpp @@ -138,9 +138,8 @@ void BackgroundChildImpl::ProcessingError(Result aCode, const char* aReason) { MOZ_CRASH("Unknown error code!"); } - nsDependentCString reason(aReason); - CrashReporter::AnnotateCrashReport( - CrashReporter::Annotation::ipc_channel_error, reason); + CrashReporter::RecordAnnotationCString( + CrashReporter::Annotation::ipc_channel_error, aReason); MOZ_CRASH_UNSAFE_PRINTF("%s: %s", abortMessage.get(), aReason); } diff --git a/ipc/glue/BackgroundParentImpl.cpp b/ipc/glue/BackgroundParentImpl.cpp index e9d0adbb94..6fcd344ddb 100644 --- a/ipc/glue/BackgroundParentImpl.cpp +++ b/ipc/glue/BackgroundParentImpl.cpp @@ -148,8 +148,8 @@ void BackgroundParentImpl::ProcessingError(Result aCode, const char* aReason) { GetIPCChannel()->InduceConnectionError(); } } else { - CrashReporter::AnnotateCrashReport( - CrashReporter::Annotation::ipc_channel_error, reason); + CrashReporter::RecordAnnotationCString( + CrashReporter::Annotation::ipc_channel_error, aReason); MOZ_CRASH("in-process BackgroundParent abort due to IPC error"); } @@ -191,26 +191,28 @@ bool BackgroundParentImpl::DeallocPBackgroundTestParent( } auto BackgroundParentImpl::AllocPBackgroundIDBFactoryParent( - const LoggingInfo& aLoggingInfo) + const LoggingInfo& aLoggingInfo, const nsACString& aSystemLocale) -> already_AddRefed { using mozilla::dom::indexedDB::AllocPBackgroundIDBFactoryParent; AssertIsInMainProcess(); AssertIsOnBackgroundThread(); - return AllocPBackgroundIDBFactoryParent(aLoggingInfo); + return AllocPBackgroundIDBFactoryParent(aLoggingInfo, aSystemLocale); } mozilla::ipc::IPCResult BackgroundParentImpl::RecvPBackgroundIDBFactoryConstructor( - PBackgroundIDBFactoryParent* aActor, const LoggingInfo& aLoggingInfo) { + PBackgroundIDBFactoryParent* aActor, const LoggingInfo& aLoggingInfo, + const nsACString& aSystemLocale) { using mozilla::dom::indexedDB::RecvPBackgroundIDBFactoryConstructor; AssertIsInMainProcess(); AssertIsOnBackgroundThread(); MOZ_ASSERT(aActor); - if (!RecvPBackgroundIDBFactoryConstructor(aActor, aLoggingInfo)) { + if (!RecvPBackgroundIDBFactoryConstructor(aActor, aLoggingInfo, + aSystemLocale)) { return IPC_FAIL_NO_REASON(this); } return IPC_OK(); diff --git a/ipc/glue/BackgroundParentImpl.h b/ipc/glue/BackgroundParentImpl.h index 42f40a1a2b..c36a8c83af 100644 --- a/ipc/glue/BackgroundParentImpl.h +++ b/ipc/glue/BackgroundParentImpl.h @@ -31,11 +31,12 @@ class BackgroundParentImpl : public PBackgroundParent { bool DeallocPBackgroundTestParent(PBackgroundTestParent* aActor) override; already_AddRefed - AllocPBackgroundIDBFactoryParent(const LoggingInfo& aLoggingInfo) override; + AllocPBackgroundIDBFactoryParent(const LoggingInfo& aLoggingInfo, + const nsACString& aSystemLocale) override; mozilla::ipc::IPCResult RecvPBackgroundIDBFactoryConstructor( - PBackgroundIDBFactoryParent* aActor, - const LoggingInfo& aLoggingInfo) override; + PBackgroundIDBFactoryParent* aActor, const LoggingInfo& aLoggingInfo, + const nsACString& aSystemLocale) override; PBackgroundIndexedDBUtilsParent* AllocPBackgroundIndexedDBUtilsParent() override; diff --git a/ipc/glue/CrashReporterHost.cpp b/ipc/glue/CrashReporterHost.cpp index d4f0c0f968..9fee9187a6 100644 --- a/ipc/glue/CrashReporterHost.cpp +++ b/ipc/glue/CrashReporterHost.cpp @@ -153,27 +153,26 @@ void CrashReporterHost::NotifyCrashService(GeckoProcessType aProcessType, getter_AddRefs(promise)); } -void CrashReporterHost::AddAnnotation(CrashReporter::Annotation aKey, - bool aValue) { +void CrashReporterHost::AddAnnotationBool(CrashReporter::Annotation aKey, + bool aValue) { + MOZ_ASSERT(TypeOfAnnotation(aKey) == CrashReporter::AnnotationType::Boolean, + "Wrong annotation type"); mExtraAnnotations[aKey] = aValue ? "1"_ns : "0"_ns; } -void CrashReporterHost::AddAnnotation(CrashReporter::Annotation aKey, - int aValue) { +void CrashReporterHost::AddAnnotationU32(CrashReporter::Annotation aKey, + uint32_t aValue) { + MOZ_ASSERT(TypeOfAnnotation(aKey) == CrashReporter::AnnotationType::U32, + "Wrong annotation type"); nsAutoCString valueString; valueString.AppendInt(aValue); mExtraAnnotations[aKey] = valueString; } -void CrashReporterHost::AddAnnotation(CrashReporter::Annotation aKey, - unsigned int aValue) { - nsAutoCString valueString; - valueString.AppendInt(aValue); - mExtraAnnotations[aKey] = valueString; -} - -void CrashReporterHost::AddAnnotation(CrashReporter::Annotation aKey, - const nsACString& aValue) { +void CrashReporterHost::AddAnnotationNSCString(CrashReporter::Annotation aKey, + const nsACString& aValue) { + MOZ_ASSERT(TypeOfAnnotation(aKey) == CrashReporter::AnnotationType::String, + "Wrong annotation type"); mExtraAnnotations[aKey] = aValue; } diff --git a/ipc/glue/CrashReporterHost.h b/ipc/glue/CrashReporterHost.h index 7b71b64cdf..df0af17d43 100644 --- a/ipc/glue/CrashReporterHost.h +++ b/ipc/glue/CrashReporterHost.h @@ -84,10 +84,10 @@ class CrashReporterHost { return CrashReporter::GetIDFromMinidump(targetDump, mDumpID); } - void AddAnnotation(CrashReporter::Annotation aKey, bool aValue); - void AddAnnotation(CrashReporter::Annotation aKey, int aValue); - void AddAnnotation(CrashReporter::Annotation aKey, unsigned int aValue); - void AddAnnotation(CrashReporter::Annotation aKey, const nsACString& aValue); + void AddAnnotationBool(CrashReporter::Annotation aKey, bool aValue); + void AddAnnotationU32(CrashReporter::Annotation aKey, uint32_t aValue); + void AddAnnotationNSCString(CrashReporter::Annotation aKey, + const nsACString& aValue); bool HasMinidump() const { return !mDumpID.IsEmpty(); } const nsString& MinidumpID() const { diff --git a/ipc/glue/EnumSerializer.h b/ipc/glue/EnumSerializer.h index 13c1de3841..989e1127f5 100644 --- a/ipc/glue/EnumSerializer.h +++ b/ipc/glue/EnumSerializer.h @@ -65,12 +65,12 @@ struct EnumSerializer { static bool Read(MessageReader* aReader, paramType* aResult) { uintParamType value; if (!ReadParam(aReader, &value)) { - CrashReporter::AnnotateCrashReport( - CrashReporter::Annotation::IPCReadErrorReason, "Bad iter"_ns); + CrashReporter::RecordAnnotationCString( + CrashReporter::Annotation::IPCReadErrorReason, "Bad iter"); return false; } else if (!EnumValidator::IsLegalValue(value)) { - CrashReporter::AnnotateCrashReport( - CrashReporter::Annotation::IPCReadErrorReason, "Illegal value"_ns); + CrashReporter::RecordAnnotationCString( + CrashReporter::Annotation::IPCReadErrorReason, "Illegal value"); return false; } *aResult = paramType(value); diff --git a/ipc/glue/ForkServiceChild.cpp b/ipc/glue/ForkServiceChild.cpp index 65560dfaea..09d7c48457 100644 --- a/ipc/glue/ForkServiceChild.cpp +++ b/ipc/glue/ForkServiceChild.cpp @@ -3,11 +3,13 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #include "ForkServiceChild.h" #include "ForkServer.h" -#include "mozilla/ipc/IPDLParamTraits.h" +#include "mozilla/Atomics.h" #include "mozilla/Logging.h" #include "mozilla/ipc/GeckoChildProcessHost.h" +#include "mozilla/ipc/IPDLParamTraits.h" #include "mozilla/ipc/ProtocolMessageUtils.h" #include "mozilla/StaticPrefs_dom.h" #include "mozilla/Services.h" @@ -23,6 +25,7 @@ namespace ipc { extern LazyLogModule gForkServiceLog; mozilla::UniquePtr ForkServiceChild::sForkServiceChild; +Atomic ForkServiceChild::sForkServiceUsed; static bool ConfigurePipeFd(int aFd) { int flags = fcntl(aFd, F_GETFD, 0); @@ -55,6 +58,7 @@ void ForkServiceChild::StartForkServer() { return; } + sForkServiceUsed = true; sForkServiceChild = mozilla::MakeUnique(server.release(), subprocess); } diff --git a/ipc/glue/ForkServiceChild.h b/ipc/glue/ForkServiceChild.h index 73d090d556..9db3dc3828 100644 --- a/ipc/glue/ForkServiceChild.h +++ b/ipc/glue/ForkServiceChild.h @@ -74,6 +74,11 @@ class ForkServiceChild { return child == nullptr || child->mFailed ? nullptr : child; } + /** + * Returns whether the fork server was ever active. Thread-safe. + */ + static bool WasUsed() { return sForkServiceUsed; } + private: // Called when a message is received. void OnMessageReceived(UniquePtr message); @@ -81,6 +86,7 @@ class ForkServiceChild { UniquePtr mTcver; static UniquePtr sForkServiceChild; + static Atomic sForkServiceUsed; pid_t mRecvPid; bool mFailed; // The forkserver has crashed or disconnected. GeckoChildProcessHost* mProcess; diff --git a/ipc/glue/GeckoChildProcessHost.cpp b/ipc/glue/GeckoChildProcessHost.cpp index bde3a9a389..cd03b488ed 100644 --- a/ipc/glue/GeckoChildProcessHost.cpp +++ b/ipc/glue/GeckoChildProcessHost.cpp @@ -13,6 +13,7 @@ #include "base/task.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/process_watcher.h" +#include "mozilla/ProcessType.h" #ifdef MOZ_WIDGET_COCOA # include # include @@ -66,6 +67,7 @@ #ifdef XP_WIN # include +# include "mozilla/WindowsVersion.h" # include "nsIWinTaskbar.h" # define NS_TASKBAR_CONTRACTID "@mozilla.org/windows-taskbar;1" @@ -249,7 +251,7 @@ class BaseProcessLauncher { }; #ifdef XP_WIN -class WindowsProcessLauncher : public BaseProcessLauncher { +class WindowsProcessLauncher final : public BaseProcessLauncher { public: WindowsProcessLauncher(GeckoChildProcessHost* aHost, std::vector&& aExtraOpts) @@ -261,8 +263,13 @@ class WindowsProcessLauncher : public BaseProcessLauncher { virtual RefPtr DoLaunch() override; virtual Result DoFinishLaunch() override; + private: + void AddApplicationPrefetchArgument(); + mozilla::Maybe mCmdLine; +# ifdef MOZ_SANDBOX bool mUseSandbox = false; +# endif const Buffer* mCachedNtdllThunk; }; @@ -343,7 +350,20 @@ class LinuxProcessLauncher : public PosixProcessLauncher { virtual Result DoSetup() override; }; typedef LinuxProcessLauncher ProcessLauncher; -# elif +# elif defined(MOZ_WIDGET_UIKIT) +class IosProcessLauncher : public PosixProcessLauncher { + public: + IosProcessLauncher(GeckoChildProcessHost* aHost, + std::vector&& aExtraOpts) + : PosixProcessLauncher(aHost, std::move(aExtraOpts)) {} + + protected: + virtual RefPtr DoLaunch() override { + MOZ_CRASH("IosProcessLauncher::DoLaunch not implemented"); + } +}; +typedef IosProcessLauncher ProcessLauncher; +# else # error "Unknown platform" # endif #endif // XP_UNIX @@ -1189,7 +1209,7 @@ Result PosixProcessLauncher::DoSetup() { } mLaunchOptions->env_map["LD_LIBRARY_PATH"] = new_ld_lib_path.get(); -# elif XP_DARWIN +# elif XP_MACOSX // With signed production Mac builds, the dynamic linker (dyld) will // ignore dyld environment variables preventing the use of variables // such as DYLD_LIBRARY_PATH and DYLD_INSERT_LIBRARIES. @@ -1212,7 +1232,7 @@ Result PosixProcessLauncher::DoSetup() { // Prevent connection attempts to diagnosticd(8) to save cycles. Log // messages can trigger these connection attempts, but access to // diagnosticd is blocked in sandboxed child processes. -# ifdef MOZ_SANDBOX +# if defined(MOZ_SANDBOX) && defined(XP_MACOSX) if (mDisableOSActivityMode) { mLaunchOptions->env_map["OS_ACTIVITY_MODE"] = "disable"; } @@ -1388,6 +1408,97 @@ Result MacProcessLauncher::DoFinishLaunch() { #endif // XP_MACOSX #ifdef XP_WIN +void WindowsProcessLauncher::AddApplicationPrefetchArgument() { + // The Application Launch Prefetcher (ALPF) is an ill-documented Windows + // subsystem that's intended to speed up process launching, apparently mostly + // by assuming that a binary is going to want to load the same DLLs as it did + // the last time it launched, and getting those prepped for loading as well. + // + // For most applications, that's a good bet. For Firefox, it's less so, since + // we use the same binary with different arguments to do completely different + // things. Windows does allow applications to take up multiple slots in this + // cache, but the "which bucket does this invocation go in?" mechanism is + // highly unusual: the OS scans the command line and looks for a command-line + // switch of a particular form. + // + // (There is allegedly a way to do this without involving the command line, + // OVERRIDE_PREFETCH_PARAMETER, but it's even more poorly documented.) + + // Applications' different prefetch-cache buckets are named with numbers from + // "1" to some OS-version-determined limit, with an additional implicit "0" + // cache bucket which is used when no valid prefetch cache slot is named. + // + // (The "0" bucket's existence and behavior is not documented, but has been + // confirmed by observing the creation and enumeration of cache files in the + // C:\Windows\Prefetch folder.) + static size_t const kMaxSlotNo = IsWin1122H2OrLater() ? 16 : 8; + + // Determine the prefetch-slot number to be used for the process we're about + // to launch. + // + // This may be changed freely between Firefox versions, as a Firefox update + // will completely invalidate the prefetch cache anyway. + size_t const prefetchSlot = [&]() -> size_t { + switch (mProcessType) { + // This code path is not used when starting the main process... + case GeckoProcessType_Default: + // ...ForkServer is not used on Windows... + case GeckoProcessType_ForkServer: + // ..."End" isn't a process-type, just a limit... + case GeckoProcessType_End: + // ...and any new process-types should be considered explicitly here. + default: + MOZ_ASSERT_UNREACHABLE("Invalid process type"); + return 0; + + // We reserve 1 for the main process as started by the launcher process. + // (See LauncherProcessWin.cpp.) Otherwise, we mostly match the process- + // type enumeration. + case GeckoProcessType_Content: + return 2; + case GeckoProcessType_Socket: + return 3; // usurps IPDLUnitTest + case GeckoProcessType_GMPlugin: + return 4; + case GeckoProcessType_GPU: + return 5; + case GeckoProcessType_RemoteSandboxBroker: + return 6; // usurps VR + case GeckoProcessType_RDD: + return 7; + + case GeckoProcessType_Utility: { + // Continue the enumeration, using the SandboxingKind as a + // probably-passably-precise proxy for the process's purpose. + // + // (On Win10 and earlier, or when sandboxing is not used, this will lump + // all utility processes into slot 8.) +# ifndef MOZ_SANDBOX + size_t const val = 0; +# else + size_t const val = static_cast(mSandbox); +# endif + return std::min(kMaxSlotNo, 8 + val); + } + + // These process types are started so rarely that we're not concerned + // about their interaction with the prefetch cache. Lump them together at + // the end (possibly alongside other process types). + case GeckoProcessType_IPDLUnitTest: + case GeckoProcessType_VR: + return kMaxSlotNo; + } + }(); + MOZ_ASSERT(prefetchSlot <= kMaxSlotNo); + + if (prefetchSlot == 0) { + // default; no explicit argument needed + return; + } + + mCmdLine->AppendLooseValue(StringPrintf(L"/prefetch:%zu", prefetchSlot)); +} + Result WindowsProcessLauncher::DoSetup() { Result aError = BaseProcessLauncher::DoSetup(); if (aError.isErr()) { @@ -1568,6 +1679,9 @@ Result WindowsProcessLauncher::DoSetup() { // Process type mCmdLine->AppendLooseValue(UTF8ToWide(ChildProcessType())); + // Prefetch cache hint + AddApplicationPrefetchArgument(); + # ifdef MOZ_SANDBOX if (mUseSandbox) { // Mark the handles to inherit as inheritable. diff --git a/ipc/glue/IPCStreamUtils.cpp b/ipc/glue/IPCStreamUtils.cpp index b884bf5d5d..7d73cfeace 100644 --- a/ipc/glue/IPCStreamUtils.cpp +++ b/ipc/glue/IPCStreamUtils.cpp @@ -131,7 +131,7 @@ bool SerializeIPCStream(already_AddRefed aInputStream, InputStreamHelper::SerializeInputStreamAsPipe(stream, aValue.stream()); if (aValue.stream().type() == InputStreamParams::T__None) { - MOZ_ASSERT_UNREACHABLE("Serializing as a pipe failed"); + // This can fail from OOM, etc. We will likely MOZ_CRASH now return false; } return true; diff --git a/ipc/glue/MessageChannel.cpp b/ipc/glue/MessageChannel.cpp index a7fc135748..16eb897175 100644 --- a/ipc/glue/MessageChannel.cpp +++ b/ipc/glue/MessageChannel.cpp @@ -473,9 +473,8 @@ MessageChannel::~MessageChannel() { // would be unsafe to invoke our listener's callbacks, and we may be being // destroyed on a thread other than `mWorkerThread`. if (!IsClosedLocked()) { - CrashReporter::AnnotateCrashReport( - CrashReporter::Annotation::IPCFatalErrorProtocol, - nsDependentCString(mName)); + CrashReporter::RecordAnnotationCString( + CrashReporter::Annotation::IPCFatalErrorProtocol, mName); switch (mChannelState) { case ChannelConnected: MOZ_CRASH( @@ -537,6 +536,12 @@ int32_t MessageChannel::CurrentNestedInsideSyncTransaction() const { return mTransactionStack->TransactionID(); } +bool MessageChannel::TestOnlyIsTransactionComplete() const { + AssertWorkerThread(); + MonitorAutoLock lock(*mMonitor); + return !mTransactionStack || mTransactionStack->IsComplete(); +} + bool MessageChannel::AwaitingSyncReply() const { mMonitor->AssertCurrentThreadOwns(); return mTransactionStack ? mTransactionStack->AwaitingSyncReply() : false; diff --git a/ipc/glue/MessageChannel.h b/ipc/glue/MessageChannel.h index 67540b4ac8..a1a5bad916 100644 --- a/ipc/glue/MessageChannel.h +++ b/ipc/glue/MessageChannel.h @@ -292,6 +292,11 @@ class MessageChannel : HasResultCodes { void CancelCurrentTransaction() MOZ_EXCLUDES(*mMonitor); + // Return whether the current transaction is complete. + // + // This is intended only for tests. + bool TestOnlyIsTransactionComplete() const MOZ_EXCLUDES(*mMonitor); + // IsClosed and NumQueuedMessages are safe to call from any thread, but // may provide an out-of-date value. bool IsClosed() MOZ_EXCLUDES(*mMonitor) { diff --git a/ipc/glue/MessageLink.cpp b/ipc/glue/MessageLink.cpp index 5505322a2f..0937fde6bf 100644 --- a/ipc/glue/MessageLink.cpp +++ b/ipc/glue/MessageLink.cpp @@ -98,12 +98,10 @@ void PortLink::SendMessage(UniquePtr aMessage) { mChan->mMonitor->AssertCurrentThreadOwns(); if (aMessage->size() > IPC::Channel::kMaximumMessageSize) { - CrashReporter::AnnotateCrashReport( - CrashReporter::Annotation::IPCMessageName, - nsDependentCString(aMessage->name())); - CrashReporter::AnnotateCrashReport( - CrashReporter::Annotation::IPCMessageSize, - static_cast(aMessage->size())); + CrashReporter::RecordAnnotationCString( + CrashReporter::Annotation::IPCMessageName, aMessage->name()); + CrashReporter::RecordAnnotationU32( + CrashReporter::Annotation::IPCMessageSize, aMessage->size()); MOZ_CRASH("IPC message size is too large"); } aMessage->AssertAsLargeAsHeader(); diff --git a/ipc/glue/NodeChannel.cpp b/ipc/glue/NodeChannel.cpp index 70e67bc473..169aa91f9b 100644 --- a/ipc/glue/NodeChannel.cpp +++ b/ipc/glue/NodeChannel.cpp @@ -170,12 +170,10 @@ void NodeChannel::AcceptInvite(const NodeName& aRealName, void NodeChannel::SendMessage(UniquePtr aMessage) { if (aMessage->size() > IPC::Channel::kMaximumMessageSize) { - CrashReporter::AnnotateCrashReport( - CrashReporter::Annotation::IPCMessageName, - nsDependentCString(aMessage->name())); - CrashReporter::AnnotateCrashReport( - CrashReporter::Annotation::IPCMessageSize, - static_cast(aMessage->size())); + CrashReporter::RecordAnnotationCString( + CrashReporter::Annotation::IPCMessageName, aMessage->name()); + CrashReporter::RecordAnnotationU32( + CrashReporter::Annotation::IPCMessageSize, aMessage->size()); MOZ_CRASH("IPC message size is too large"); } aMessage->AssertAsLargeAsHeader(); diff --git a/ipc/glue/PBackground.ipdl b/ipc/glue/PBackground.ipdl index 94b0079ff7..d0fe4b1731 100644 --- a/ipc/glue/PBackground.ipdl +++ b/ipc/glue/PBackground.ipdl @@ -129,7 +129,8 @@ parent: // Only called at startup during mochitests to check the basic infrastructure. async PBackgroundTest(nsCString testArg); - async PBackgroundIDBFactory(LoggingInfo loggingInfo); + async PBackgroundIDBFactory(LoggingInfo loggingInfo, + nsCString systemLocale); async PBackgroundIndexedDBUtils(); diff --git a/ipc/glue/PUtilityAudioDecoder.ipdl b/ipc/glue/PUtilityAudioDecoder.ipdl index 74dbbd2c54..5b4b8711f2 100644 --- a/ipc/glue/PUtilityAudioDecoder.ipdl +++ b/ipc/glue/PUtilityAudioDecoder.ipdl @@ -30,7 +30,6 @@ parent: #ifdef MOZ_WMF_MEDIA_ENGINE async InitVideoBridge(Endpoint endpoint, - GfxVarUpdate[] updates, ContentDeviceData contentDeviceData); async UpdateVar(GfxVarUpdate var); diff --git a/ipc/glue/PUtilityProcess.ipdl b/ipc/glue/PUtilityProcess.ipdl index 585590799f..be8b439514 100644 --- a/ipc/glue/PUtilityProcess.ipdl +++ b/ipc/glue/PUtilityProcess.ipdl @@ -21,6 +21,8 @@ include protocol PSandboxTesting; include "mozilla/ipc/ByteBufUtils.h"; +include GraphicsMessages; + using mozilla::dom::NativeThreadId from "mozilla/dom/NativeThreadId.h"; // Telemetry @@ -98,7 +100,7 @@ child: async TestTelemetryProbes(); - async StartUtilityAudioDecoderService(Endpoint aEndpoint); + async StartUtilityAudioDecoderService(Endpoint aEndpoint, GfxVarUpdate[] updates); async StartJSOracleService(Endpoint aEndpoint); diff --git a/ipc/glue/ProcessChild.cpp b/ipc/glue/ProcessChild.cpp index 724d2b09bf..fe727ffa66 100644 --- a/ipc/glue/ProcessChild.cpp +++ b/ipc/glue/ProcessChild.cpp @@ -21,7 +21,6 @@ #include "nsAppRunner.h" #include "mozilla/AppShutdown.h" -#include "mozilla/ipc/CrashReporterClient.h" #include "mozilla/ipc/IOThreadChild.h" #include "mozilla/GeckoArgs.h" @@ -29,6 +28,8 @@ namespace mozilla { namespace ipc { ProcessChild* ProcessChild::gProcessChild; +StaticMutex ProcessChild::gIPCShutdownStateLock; +nsCString ProcessChild::gIPCShutdownStateAnnotation; static Atomic sExpectingShutdown(false); @@ -39,6 +40,9 @@ ProcessChild::ProcessChild(ProcessId aParentPid, const nsID& aMessageChannelId) mMessageChannelId(aMessageChannelId) { MOZ_ASSERT(mUILoop, "UILoop should be created by now"); MOZ_ASSERT(!gProcessChild, "should only be one ProcessChild"); + CrashReporter::RegisterAnnotationNSCString( + CrashReporter::Annotation::IPCShutdownState, + &gIPCShutdownStateAnnotation); gProcessChild = this; } @@ -101,14 +105,14 @@ ProcessChild::~ProcessChild() { // we'll get into late IPC shutdown with processes still running. SleepIfEnv("MOZ_TEST_CHILD_EXIT_HANG"); #endif + gIPCShutdownStateAnnotation = ""_ns; gProcessChild = nullptr; } /* static */ void ProcessChild::NotifiedImpendingShutdown() { sExpectingShutdown = true; - CrashReporter::AppendToCrashReportAnnotation( - CrashReporter::Annotation::IPCShutdownState, + ProcessChild::AppendToIPCShutdownStateAnnotation( "NotifiedImpendingShutdown"_ns); } diff --git a/ipc/glue/ProcessChild.h b/ipc/glue/ProcessChild.h index 29948a9127..f881b316cf 100644 --- a/ipc/glue/ProcessChild.h +++ b/ipc/glue/ProcessChild.h @@ -48,6 +48,12 @@ class ProcessChild : public ChildProcess { static bool ExpectingShutdown(); + static void AppendToIPCShutdownStateAnnotation(const nsCString& aStr) { + StaticMutexAutoLock lock(gIPCShutdownStateLock); + gIPCShutdownStateAnnotation.Append(" - "_ns); + gIPCShutdownStateAnnotation.Append(aStr); + } + /** * Exit *now*. Do not shut down XPCOM, do not pass Go, do not run * static destructors, do not collect $200. @@ -63,6 +69,9 @@ class ProcessChild : public ChildProcess { private: static ProcessChild* gProcessChild; + static StaticMutex gIPCShutdownStateLock; + static nsCString gIPCShutdownStateAnnotation + MOZ_GUARDED_BY(gIPCShutdownStateLock); MessageLoop* mUILoop; ProcessId mParentPid; diff --git a/ipc/glue/ProtocolUtils.cpp b/ipc/glue/ProtocolUtils.cpp index bd78dce607..b29221d476 100644 --- a/ipc/glue/ProtocolUtils.cpp +++ b/ipc/glue/ProtocolUtils.cpp @@ -73,23 +73,28 @@ IPCResult IPCResult::FailImpl(NotNull actor, const char* where, #endif } +/* static */ +IPCResult IPCResult::FailForTesting(NotNull actor, + const char* where, const char* why) { + return IPCResult(false); +} + void AnnotateSystemError() { - int64_t error = 0; + uint32_t error = 0; #if defined(XP_WIN) error = ::GetLastError(); #else error = errno; #endif if (error) { - CrashReporter::AnnotateCrashReport( - CrashReporter::Annotation::IPCSystemError, - nsPrintfCString("%" PRId64, error)); + CrashReporter::RecordAnnotationU32( + CrashReporter::Annotation::IPCSystemError, error); } } #if defined(XP_MACOSX) void AnnotateCrashReportWithErrno(CrashReporter::Annotation tag, int error) { - CrashReporter::AnnotateCrashReport(tag, error); + CrashReporter::RecordAnnotationU32(tag, static_cast(error)); } #endif // defined(XP_MACOSX) @@ -191,8 +196,8 @@ void FatalError(const char* aMsg, bool aIsParent) { // this process if we're off the main thread. formattedMessage.AppendLiteral("\". Intentionally crashing."); NS_ERROR(formattedMessage.get()); - CrashReporter::AnnotateCrashReport( - CrashReporter::Annotation::IPCFatalErrorMsg, nsDependentCString(aMsg)); + CrashReporter::RecordAnnotationCString( + CrashReporter::Annotation::IPCFatalErrorMsg, aMsg); AnnotateSystemError(); #ifndef FUZZING MOZ_CRASH("IPC FatalError in the parent process!"); diff --git a/ipc/glue/ProtocolUtils.h b/ipc/glue/ProtocolUtils.h index 2a0c64de20..7edce9612b 100644 --- a/ipc/glue/ProtocolUtils.h +++ b/ipc/glue/ProtocolUtils.h @@ -341,6 +341,9 @@ class IProtocol : public HasResultCodes { mozilla::ipc::IPCResult::FailUnsafePrintfImpl( \ WrapNotNull(actor), __func__, nsPrintfCString(format, ##__VA_ARGS__)) +#define IPC_TEST_FAIL(actor) \ + mozilla::ipc::IPCResult::FailForTesting(WrapNotNull(actor), __func__, "") + /** * All message deserializers and message handlers should return this type via * the above macros. We use a less generic name here to avoid conflict with @@ -379,6 +382,10 @@ class IPCResult { return FailImpl(aActor, aWhere, aWhy.get()); } + // Only used in testing. + static IPCResult FailForTesting(NotNull aActor, + const char* aWhere, const char* aWhy); + private: static IPCResult FailImpl(NotNull aActor, const char* aWhere, const char* aWhy); diff --git a/ipc/glue/UtilityAudioDecoder.cpp b/ipc/glue/UtilityAudioDecoder.cpp index 0b28fd601e..0a294d95f5 100644 --- a/ipc/glue/UtilityAudioDecoder.cpp +++ b/ipc/glue/UtilityAudioDecoder.cpp @@ -6,6 +6,7 @@ #include "mozilla/ProcInfo.h" #include "mozilla/ipc/UtilityAudioDecoder.h" +#include "mozilla/dom/BindingUtils.h" #include "mozilla/ipc/UtilityProcessChild.h" namespace mozilla::ipc { @@ -34,8 +35,7 @@ UtilityActorName GetAudioActorName(const SandboxingKind aSandbox) { nsCString GetChildAudioActorName() { RefPtr s = ipc::UtilityProcessChild::Get(); MOZ_ASSERT(s, "Has UtilityProcessChild"); - return nsCString(dom::WebIDLUtilityActorNameValues::GetString( - GetAudioActorName(s->mSandbox))); + return dom::GetEnumString(GetAudioActorName(s->mSandbox)); } } // namespace mozilla::ipc diff --git a/ipc/glue/UtilityAudioDecoderChild.cpp b/ipc/glue/UtilityAudioDecoderChild.cpp index 88124a1f8b..cc3560e05b 100644 --- a/ipc/glue/UtilityAudioDecoderChild.cpp +++ b/ipc/glue/UtilityAudioDecoderChild.cpp @@ -42,8 +42,8 @@ NS_IMETHODIMP UtilityAudioDecoderChildShutdownObserver::Observe( NS_IMPL_ISUPPORTS(UtilityAudioDecoderChildShutdownObserver, nsIObserver); -static EnumeratedArray> +static EnumeratedArray, + size_t(SandboxingKind::COUNT)> sAudioDecoderChilds; UtilityAudioDecoderChild::UtilityAudioDecoderChild(SandboxingKind aKind) @@ -56,6 +56,40 @@ UtilityAudioDecoderChild::UtilityAudioDecoderChild(SandboxingKind aKind) } } +nsresult UtilityAudioDecoderChild::BindToUtilityProcess( + RefPtr aUtilityParent) { + Endpoint utilityAudioDecoderChildEnd; + Endpoint utilityAudioDecoderParentEnd; + nsresult rv = PUtilityAudioDecoder::CreateEndpoints( + aUtilityParent->OtherPid(), base::GetCurrentProcId(), + &utilityAudioDecoderParentEnd, &utilityAudioDecoderChildEnd); + + if (NS_FAILED(rv)) { + MOZ_ASSERT(false, "Protocol endpoints failure"); + return NS_ERROR_FAILURE; + } + + nsTArray updates; +#ifdef MOZ_WMF_MEDIA_ENGINE + // Only MFCDM process needs gfxVars + if (mSandbox == SandboxingKind::MF_MEDIA_ENGINE_CDM) { + updates = gfx::gfxVars::FetchNonDefaultVars(); + } +#endif + if (!aUtilityParent->SendStartUtilityAudioDecoderService( + std::move(utilityAudioDecoderParentEnd), std::move(updates))) { + MOZ_ASSERT(false, "StartUtilityAudioDecoder service failure"); + return NS_ERROR_FAILURE; + } + + Bind(std::move(utilityAudioDecoderChildEnd)); + + PROFILER_MARKER_UNTYPED("UtilityAudioDecoderChild::BindToUtilityProcess", IPC, + MarkerOptions(MarkerTiming::IntervalUntilNowFrom( + mAudioDecoderChildStart))); + return NS_OK; +} + void UtilityAudioDecoderChild::ActorDestroy(ActorDestroyReason aReason) { MOZ_ASSERT(NS_IsMainThread()); #ifdef MOZ_WMF_MEDIA_ENGINE @@ -110,15 +144,10 @@ mozilla::ipc::IPCResult UtilityAudioDecoderChild::RecvCompleteCreatedVideoBridge() { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(mSandbox == SandboxingKind::MF_MEDIA_ENGINE_CDM); - mHasCreatedVideoBridge = true; + mHasCreatedVideoBridge = State::Created; return IPC_OK(); } -bool UtilityAudioDecoderChild::HasCreatedVideoBridge() const { - MOZ_ASSERT(NS_IsMainThread()); - return mHasCreatedVideoBridge; -} - void UtilityAudioDecoderChild::OnVarChanged(const gfx::GfxVarUpdate& aVar) { MOZ_ASSERT(mSandbox == SandboxingKind::MF_MEDIA_ENGINE_CDM); SendUpdateVar(aVar); @@ -127,7 +156,7 @@ void UtilityAudioDecoderChild::OnVarChanged(const gfx::GfxVarUpdate& aVar) { void UtilityAudioDecoderChild::OnCompositorUnexpectedShutdown() { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(mSandbox == SandboxingKind::MF_MEDIA_ENGINE_CDM); - mHasCreatedVideoBridge = false; + mHasCreatedVideoBridge = State::None; CreateVideoBridge(); } @@ -135,9 +164,11 @@ bool UtilityAudioDecoderChild::CreateVideoBridge() { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(mSandbox == SandboxingKind::MF_MEDIA_ENGINE_CDM); - if (HasCreatedVideoBridge()) { + // Creating or already created, avoiding reinit a bridge. + if (mHasCreatedVideoBridge != State::None) { return true; } + mHasCreatedVideoBridge = State::Creating; // Build content device data first; this ensure that the GPU process is fully // ready. @@ -170,11 +201,10 @@ bool UtilityAudioDecoderChild::CreateVideoBridge() { return false; } - nsTArray updates = gfx::gfxVars::FetchNonDefaultVars(); gpuManager->InitVideoBridge( std::move(parentPipe), layers::VideoBridgeSource::MFMediaEngineCDMProcess); - SendInitVideoBridge(std::move(childPipe), updates, contentDeviceData); + SendInitVideoBridge(std::move(childPipe), contentDeviceData); return true; } #endif diff --git a/ipc/glue/UtilityAudioDecoderChild.h b/ipc/glue/UtilityAudioDecoderChild.h index 4e6a7792b0..0a27cb4ea3 100644 --- a/ipc/glue/UtilityAudioDecoderChild.h +++ b/ipc/glue/UtilityAudioDecoderChild.h @@ -58,32 +58,7 @@ class UtilityAudioDecoderChild final : public PUtilityAudioDecoderChild UtilityActorName GetActorName() { return GetAudioActorName(mSandbox); } - nsresult BindToUtilityProcess(RefPtr aUtilityParent) { - Endpoint utilityAudioDecoderChildEnd; - Endpoint utilityAudioDecoderParentEnd; - nsresult rv = PUtilityAudioDecoder::CreateEndpoints( - aUtilityParent->OtherPid(), base::GetCurrentProcId(), - &utilityAudioDecoderParentEnd, &utilityAudioDecoderChildEnd); - - if (NS_FAILED(rv)) { - MOZ_ASSERT(false, "Protocol endpoints failure"); - return NS_ERROR_FAILURE; - } - - if (!aUtilityParent->SendStartUtilityAudioDecoderService( - std::move(utilityAudioDecoderParentEnd))) { - MOZ_ASSERT(false, "StartUtilityAudioDecoder service failure"); - return NS_ERROR_FAILURE; - } - - Bind(std::move(utilityAudioDecoderChildEnd)); - - PROFILER_MARKER_UNTYPED( - "UtilityAudioDecoderChild::BindToUtilityProcess", IPC, - MarkerOptions( - MarkerTiming::IntervalUntilNowFrom(mAudioDecoderChildStart))); - return NS_OK; - } + nsresult BindToUtilityProcess(RefPtr aUtilityParent); void ActorDestroy(ActorDestroyReason aReason) override; @@ -96,8 +71,6 @@ class UtilityAudioDecoderChild final : public PUtilityAudioDecoderChild #ifdef MOZ_WMF_MEDIA_ENGINE mozilla::ipc::IPCResult RecvCompleteCreatedVideoBridge(); - bool HasCreatedVideoBridge() const; - void OnVarChanged(const gfx::GfxVarUpdate& aVar) override; void OnCompositorUnexpectedShutdown() override; @@ -120,7 +93,8 @@ class UtilityAudioDecoderChild final : public PUtilityAudioDecoderChild #ifdef MOZ_WMF_MEDIA_ENGINE // True if the utility process has created a video bridge with the GPU prcess. // Currently only used for media egine cdm. Main thread only. - bool mHasCreatedVideoBridge = false; + enum class State { None, Creating, Created }; + State mHasCreatedVideoBridge = State::None; #endif TimeStamp mAudioDecoderChildStart; diff --git a/ipc/glue/UtilityAudioDecoderParent.cpp b/ipc/glue/UtilityAudioDecoderParent.cpp index 2eb0936a38..ed6327061b 100644 --- a/ipc/glue/UtilityAudioDecoderParent.cpp +++ b/ipc/glue/UtilityAudioDecoderParent.cpp @@ -42,7 +42,8 @@ namespace mozilla::ipc { -UtilityAudioDecoderParent::UtilityAudioDecoderParent() +UtilityAudioDecoderParent::UtilityAudioDecoderParent( + nsTArray&& aUpdates) : mKind(GetCurrentSandboxingKind()), mAudioDecoderParentStart(TimeStamp::Now()) { #ifdef MOZ_WMF_MEDIA_ENGINE @@ -51,6 +52,9 @@ UtilityAudioDecoderParent::UtilityAudioDecoderParent() profiler_set_process_name(nsCString("MF Media Engine CDM")); gfx::gfxConfig::Init(); gfx::gfxVars::Initialize(); + for (auto& update : aUpdates) { + gfx::gfxVars::ApplyUpdate(update); + } gfx::DeviceManagerDx::Init(); return; } @@ -78,12 +82,12 @@ UtilityAudioDecoderParent::~UtilityAudioDecoderParent() { /* static */ void UtilityAudioDecoderParent::GenericPreloadForSandbox() { -#if defined(MOZ_SANDBOX) && defined(XP_WIN) && defined(MOZ_FFVPX) +#if defined(MOZ_SANDBOX) && defined(XP_WIN) // Preload AV dlls so we can enable Binary Signature Policy // to restrict further dll loads. UtilityProcessImpl::LoadLibraryOrCrash(L"mozavcodec.dll"); UtilityProcessImpl::LoadLibraryOrCrash(L"mozavutil.dll"); -#endif // defined(MOZ_SANDBOX) && defined(XP_WIN) && defined(MOZ_FFVPX) +#endif // defined(MOZ_SANDBOX) && defined(XP_WIN) } /* static */ @@ -141,7 +145,6 @@ UtilityAudioDecoderParent::RecvNewContentRemoteDecoderManager( #ifdef MOZ_WMF_MEDIA_ENGINE mozilla::ipc::IPCResult UtilityAudioDecoderParent::RecvInitVideoBridge( Endpoint&& aEndpoint, - nsTArray&& aUpdates, const ContentDeviceData& aContentDeviceData) { MOZ_ASSERT(mKind == SandboxingKind::MF_MEDIA_ENGINE_CDM); if (!RemoteDecoderManagerParent::CreateVideoBridgeToOtherProcess( @@ -149,10 +152,6 @@ mozilla::ipc::IPCResult UtilityAudioDecoderParent::RecvInitVideoBridge( return IPC_FAIL_NO_REASON(this); } - for (const auto& update : aUpdates) { - gfx::gfxVars::ApplyUpdate(update); - } - gfx::gfxConfig::Inherit( { gfx::Feature::HW_COMPOSITING, @@ -175,6 +174,17 @@ mozilla::ipc::IPCResult UtilityAudioDecoderParent::RecvInitVideoBridge( IPCResult UtilityAudioDecoderParent::RecvUpdateVar( const GfxVarUpdate& aUpdate) { MOZ_ASSERT(mKind == SandboxingKind::MF_MEDIA_ENGINE_CDM); + auto scopeExit = MakeScopeExit( + [self = RefPtr{this}, + location = GetRemoteDecodeInFromKind(mKind), + couldUseHWDecoder = gfx::gfxVars::CanUseHardwareVideoDecoding()] { + if (couldUseHWDecoder != gfx::gfxVars::CanUseHardwareVideoDecoding()) { + // The capabilities of the system may have changed, force a refresh by + // re-initializing the PDM. + Unused << self->SendUpdateMediaCodecsSupported( + location, PDMFactory::Supported(true /* force refresh */)); + } + }); gfx::gfxVars::ApplyUpdate(aUpdate); return IPC_OK(); } diff --git a/ipc/glue/UtilityAudioDecoderParent.h b/ipc/glue/UtilityAudioDecoderParent.h index 6996fa0538..7279582fdc 100644 --- a/ipc/glue/UtilityAudioDecoderParent.h +++ b/ipc/glue/UtilityAudioDecoderParent.h @@ -25,7 +25,8 @@ class UtilityAudioDecoderParent final : public PUtilityAudioDecoderParent { public: NS_INLINE_DECL_THREADSAFE_REFCOUNTING(UtilityAudioDecoderParent, override); - UtilityAudioDecoderParent(); + explicit UtilityAudioDecoderParent( + nsTArray&& aUpdates); static void GenericPreloadForSandbox(); static void WMFPreloadForSandbox(); @@ -39,7 +40,6 @@ class UtilityAudioDecoderParent final : public PUtilityAudioDecoderParent { #ifdef MOZ_WMF_MEDIA_ENGINE mozilla::ipc::IPCResult RecvInitVideoBridge( Endpoint&& aEndpoint, - nsTArray&& aUpdates, const ContentDeviceData& aContentDeviceData); IPCResult RecvUpdateVar(const mozilla::gfx::GfxVarUpdate& aUpdate); diff --git a/ipc/glue/UtilityProcessChild.cpp b/ipc/glue/UtilityProcessChild.cpp index cda3dbc817..d99c2fb361 100644 --- a/ipc/glue/UtilityProcessChild.cpp +++ b/ipc/glue/UtilityProcessChild.cpp @@ -261,11 +261,13 @@ mozilla::ipc::IPCResult UtilityProcessChild::RecvTestTelemetryProbes() { mozilla::ipc::IPCResult UtilityProcessChild::RecvStartUtilityAudioDecoderService( - Endpoint&& aEndpoint) { + Endpoint&& aEndpoint, + nsTArray&& aUpdates) { PROFILER_MARKER_UNTYPED( "UtilityProcessChild::RecvStartUtilityAudioDecoderService", MEDIA, MarkerOptions(MarkerTiming::IntervalUntilNowFrom(mChildStartTime))); - mUtilityAudioDecoderInstance = new UtilityAudioDecoderParent(); + mUtilityAudioDecoderInstance = + new UtilityAudioDecoderParent(std::move(aUpdates)); if (!mUtilityAudioDecoderInstance) { return IPC_FAIL(this, "Failed to create UtilityAudioDecoderParent"); } diff --git a/ipc/glue/UtilityProcessChild.h b/ipc/glue/UtilityProcessChild.h index db6db6bba6..42bfc421d0 100644 --- a/ipc/glue/UtilityProcessChild.h +++ b/ipc/glue/UtilityProcessChild.h @@ -63,7 +63,8 @@ class UtilityProcessChild final : public PUtilityProcessChild { mozilla::ipc::IPCResult RecvTestTelemetryProbes(); mozilla::ipc::IPCResult RecvStartUtilityAudioDecoderService( - Endpoint&& aEndpoint); + Endpoint&& aEndpoint, + nsTArray&& aUpdates); mozilla::ipc::IPCResult RecvStartJSOracleService( Endpoint&& aEndpoint); diff --git a/ipc/glue/UtilityProcessHost.cpp b/ipc/glue/UtilityProcessHost.cpp index 6b8a84966e..5f33fac81b 100644 --- a/ipc/glue/UtilityProcessHost.cpp +++ b/ipc/glue/UtilityProcessHost.cpp @@ -107,10 +107,6 @@ bool UtilityProcessHost::Launch(StringVector aExtraOpts) { } mPrefSerializer->AddSharedPrefCmdLineArgs(*this, aExtraOpts); -#if defined(XP_WIN) && defined(MOZ_SANDBOX) - mSandboxLevel = Preferences::GetInt("security.sandbox.utility.level"); -#endif - #ifdef MOZ_WMF_CDM_LPAC_SANDBOX EnsureWidevineL1PathForSandbox(aExtraOpts); #endif diff --git a/ipc/glue/UtilityProcessManager.cpp b/ipc/glue/UtilityProcessManager.cpp index e24fed476b..b4cc4687a3 100644 --- a/ipc/glue/UtilityProcessManager.cpp +++ b/ipc/glue/UtilityProcessManager.cpp @@ -214,8 +214,8 @@ RefPtr UtilityProcessManager::LaunchProcess( } p->mQueuedPrefs.Clear(); - CrashReporter::AnnotateCrashReport( - CrashReporter::Annotation::UtilityProcessStatus, "Running"_ns); + CrashReporter::RecordAnnotationCString( + CrashReporter::Annotation::UtilityProcessStatus, "Running"); return GenericNonExclusivePromise::CreateAndResolve(true, __func__); }, @@ -592,8 +592,8 @@ void UtilityProcessManager::DestroyProcess(SandboxingKind aSandbox) { mProcesses[aSandbox] = nullptr; - CrashReporter::AnnotateCrashReport( - CrashReporter::Annotation::UtilityProcessStatus, "Destroyed"_ns); + CrashReporter::RecordAnnotationCString( + CrashReporter::Annotation::UtilityProcessStatus, "Destroyed"); if (NoMoreProcesses()) { sSingleton = nullptr; diff --git a/ipc/glue/UtilityProcessManager.h b/ipc/glue/UtilityProcessManager.h index 60cea016c9..64b0f6504f 100644 --- a/ipc/glue/UtilityProcessManager.h +++ b/ipc/glue/UtilityProcessManager.h @@ -228,7 +228,8 @@ class UtilityProcessManager final : public UtilityProcessHost::Listener { ~ProcessFields() = default; }; - EnumeratedArray> + EnumeratedArray, + size_t(SandboxingKind::COUNT)> mProcesses; RefPtr GetProcess(SandboxingKind); diff --git a/ipc/glue/UtilityProcessParent.cpp b/ipc/glue/UtilityProcessParent.cpp index 2860b4704b..ea499eaee8 100644 --- a/ipc/glue/UtilityProcessParent.cpp +++ b/ipc/glue/UtilityProcessParent.cpp @@ -148,7 +148,7 @@ void UtilityProcessParent::ActorDestroy(ActorDestroyReason aWhy) { actorsName += ", "_ns + GetUtilityActorName(actor); } } - mCrashReporter->AddAnnotation( + mCrashReporter->AddAnnotationNSCString( CrashReporter::Annotation::UtilityActorsName, actorsName); } #endif diff --git a/ipc/glue/moz.build b/ipc/glue/moz.build index bb23b29a45..7aa29612b8 100644 --- a/ipc/glue/moz.build +++ b/ipc/glue/moz.build @@ -138,7 +138,7 @@ elif CONFIG["OS_ARCH"] in ("DragonFly", "FreeBSD", "NetBSD", "OpenBSD"): EXPORTS.mozilla.ipc += [ "SetProcessTitle.h", ] -elif CONFIG["OS_ARCH"] == "Darwin": +elif CONFIG["TARGET_OS"] == "OSX": UNIFIED_SOURCES += ["ProcessUtils_mac.mm"] else: UNIFIED_SOURCES += [ diff --git a/ipc/glue/test/browser/browser_audio_fallback.toml b/ipc/glue/test/browser/browser_audio_fallback.toml index 0de2a1c9e7..ab2b783e9a 100644 --- a/ipc/glue/test/browser/browser_audio_fallback.toml +++ b/ipc/glue/test/browser/browser_audio_fallback.toml @@ -1,9 +1,14 @@ [DEFAULT] +subsuite = "media-bc" +tags = "media-engine-compatible" support-files = [ "head.js", "head-multiple.js", ] -prefs = ["media.allow-audio-non-utility=true"] +prefs = [ + "media.allow-audio-non-utility=true", + "media.wmf.media-engine.channel-decoder.enabled=false" +] # Set this since we want to continue monitoring the disabling of pref since we # still allow it a little bit. environment = "MOZ_DONT_LOCK_UTILITY_PLZ_FILE_A_BUG=1" diff --git a/ipc/glue/test/browser/browser_audio_fallback_content.toml b/ipc/glue/test/browser/browser_audio_fallback_content.toml index 3efc6409ac..f074ac743d 100644 --- a/ipc/glue/test/browser/browser_audio_fallback_content.toml +++ b/ipc/glue/test/browser/browser_audio_fallback_content.toml @@ -1,4 +1,6 @@ [DEFAULT] +subsuite = "media-bc" +tags = "media-engine-compatible" support-files = [ "head.js", "head-multiple.js", @@ -6,6 +8,7 @@ support-files = [ prefs = [ "media.allow-audio-non-utility=true", "media.rdd-process.enabled=false", + "media.wmf.media-engine.channel-decoder.enabled=false" ] ["browser_utility_multipleAudio_fallback_content.js"] diff --git a/ipc/glue/test/browser/browser_audio_locked.toml b/ipc/glue/test/browser/browser_audio_locked.toml index 9f0607bf5f..82a42ff935 100644 --- a/ipc/glue/test/browser/browser_audio_locked.toml +++ b/ipc/glue/test/browser/browser_audio_locked.toml @@ -1,3 +1,6 @@ [DEFAULT] +subsuite = "media-bc" +tags = "media-engine-compatible" +prefs = ["media.wmf.media-engine.channel-decoder.enabled=false"] ["browser_utility_audio_locked.js"] diff --git a/ipc/glue/test/browser/browser_audio_shutdown.toml b/ipc/glue/test/browser/browser_audio_shutdown.toml index f99fff7830..6dbb8cdf49 100644 --- a/ipc/glue/test/browser/browser_audio_shutdown.toml +++ b/ipc/glue/test/browser/browser_audio_shutdown.toml @@ -1,5 +1,8 @@ [DEFAULT] +subsuite = "media-bc" +tags = "media-engine-compatible" support-files = ["head.js"] +prefs = ["media.wmf.media-engine.channel-decoder.enabled=false"] ["browser_utility_audio_shutdown.js"] support-files = ["../../../../dom/media/test/small-shot.ogg"] diff --git a/ipc/glue/test/browser/browser_child_hang.js b/ipc/glue/test/browser/browser_child_hang.js index cf890a6c61..e74517fbdd 100644 --- a/ipc/glue/test/browser/browser_child_hang.js +++ b/ipc/glue/test/browser/browser_child_hang.js @@ -24,7 +24,7 @@ add_task(async function () { url: "https://example.com/", forceNewProcess: true, }, - async function (browser) { + async function () { // browser.frameLoader.remoteTab.osPid is the child pid; once we // have a way to get notifications about child process termination // events, that could be useful. diff --git a/ipc/glue/test/browser/browser_utility_audioDecodeCrash.js b/ipc/glue/test/browser/browser_utility_audioDecodeCrash.js index 1c7551c623..1662ba06f3 100644 --- a/ipc/glue/test/browser/browser_utility_audioDecodeCrash.js +++ b/ipc/glue/test/browser/browser_utility_audioDecodeCrash.js @@ -22,7 +22,7 @@ async function getAudioDecoderPid(expectation) { async function crashDecoder(expectation) { const audioPid = await getAudioDecoderPid(expectation); - ok(audioPid > 0, `Found an audio decoder ${audioPid}`); + Assert.greater(audioPid, 0, `Found an audio decoder ${audioPid}`); const actorIsAudioDecoder = actorNames => { return actorNames .split(",") diff --git a/ipc/glue/test/browser/browser_utility_audio_shutdown.js b/ipc/glue/test/browser/browser_utility_audio_shutdown.js index a0a4be63f6..046b6914a8 100644 --- a/ipc/glue/test/browser/browser_utility_audio_shutdown.js +++ b/ipc/glue/test/browser/browser_utility_audio_shutdown.js @@ -31,7 +31,7 @@ async function findGenericAudioDecoder() { ); } ); - ok(audioDecoders.length === 1, "Only one audio decoder present"); + Assert.strictEqual(audioDecoders.length, 1, "Only one audio decoder present"); return audioDecoders[0].pid; } @@ -50,7 +50,7 @@ add_task(async function testKill() { ); info("Waiting 15s to trigger mShutdownBlockers assertions"); - await new Promise((resolve, reject) => { + await new Promise(resolve => { /* eslint-disable mozilla/no-arbitrary-setTimeout */ setTimeout(resolve, 15 * 1000); }); @@ -62,12 +62,12 @@ add_task(async function testShutdown() { await runTest("small-shot.ogg", "Utility Generic", "ffvpx audio decoder"); const audioDecoderPid = await findGenericAudioDecoder(); - ok(audioDecoderPid > 0, `Valid PID found: ${audioDecoderPid}`); + Assert.greater(audioDecoderPid, 0, `Valid PID found: ${audioDecoderPid}`); await cleanUtilityProcessShutdown("audioDecoder_Generic"); info("Waiting 15s to trigger mShutdownBlockers assertions"); - await new Promise((resolve, reject) => { + await new Promise(resolve => { /* eslint-disable mozilla/no-arbitrary-setTimeout */ setTimeout(resolve, 15 * 1000); }); diff --git a/ipc/glue/test/browser/browser_utility_filepicker_crashed.js b/ipc/glue/test/browser/browser_utility_filepicker_crashed.js index e8eb83cf30..1cfbb9e591 100644 --- a/ipc/glue/test/browser/browser_utility_filepicker_crashed.js +++ b/ipc/glue/test/browser/browser_utility_filepicker_crashed.js @@ -57,13 +57,18 @@ function openFileDialog() { return pid; })(); - const file = new Promise((resolve, reject) => { + const file = new Promise(resolve => { info("Opening Windows file dialog"); let fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker); - fp.init(window, "Test: browser_utility_filepicker_crashed.js", fp.modeOpen); + fp.init( + window.browsingContext, + "Test: browser_utility_filepicker_crashed.js", + fp.modeOpen + ); fp.open(result => { - ok( - result == fp.returnCancel, + Assert.equal( + result, + fp.returnCancel, "filepicker should resolve to cancellation" ); resolve(); diff --git a/ipc/glue/test/browser/browser_utility_memoryReport.js b/ipc/glue/test/browser/browser_utility_memoryReport.js index 8cec61b8be..55bc8fbffe 100644 --- a/ipc/glue/test/browser/browser_utility_memoryReport.js +++ b/ipc/glue/test/browser/browser_utility_memoryReport.js @@ -15,11 +15,15 @@ add_task(async () => { const gMgr = Cc["@mozilla.org/memory-reporter-manager;1"].getService( Ci.nsIMemoryReporterManager ); - ok(utilityPid !== undefined, `Utility process is running as ${utilityPid}`); + Assert.notStrictEqual( + utilityPid, + undefined, + `Utility process is running as ${utilityPid}` + ); var utilityReports = []; - const performCollection = new Promise((resolve, reject) => { + const performCollection = new Promise(resolve => { // Record the reports from the live memory reporters then process them. let handleReport = function ( aProcess, @@ -56,13 +60,14 @@ add_task(async () => { `Collected ${utilityReports.length} reports from utility process ${utilityPid}` ); ok(!!utilityReports.length, "Collected some reports"); - ok( - utilityReports.filter(r => r.path === "vsize" && r.amount > 0).length === 1, + Assert.strictEqual( + utilityReports.filter(r => r.path === "vsize" && r.amount > 0).length, + 1, "Collected vsize report" ); - ok( - utilityReports.filter(r => r.path === "resident" && r.amount > 0).length === - 1, + Assert.strictEqual( + utilityReports.filter(r => r.path === "resident" && r.amount > 0).length, + 1, "Collected resident report" ); ok( diff --git a/ipc/glue/test/browser/head.js b/ipc/glue/test/browser/head.js index 8acff88273..7520049cd0 100644 --- a/ipc/glue/test/browser/head.js +++ b/ipc/glue/test/browser/head.js @@ -39,7 +39,11 @@ async function getUtilityProcesses(actor = undefined, options = {}) { async function tryGetUtilityPid(actor, options = {}) { let process = await getUtilityProcesses(actor, options); if (!options?.quiet) { - ok(process.length <= 1, `at most one ${actor} process exists`); + Assert.lessOrEqual( + process.length, + 1, + `at most one ${actor} process exists` + ); } return process[0]?.pid; } @@ -47,7 +51,7 @@ async function tryGetUtilityPid(actor, options = {}) { async function checkUtilityExists(actor) { info(`Looking for a running ${actor} utility process`); const utilityPid = await tryGetUtilityPid(actor); - ok(utilityPid > 0, `Found ${actor} utility process ${utilityPid}`); + Assert.greater(utilityPid, 0, `Found ${actor} utility process ${utilityPid}`); return utilityPid; } @@ -60,7 +64,11 @@ async function cleanUtilityProcessShutdown(actor, preferKill = false) { info(`${preferKill ? "Kill" : "Clean shutdown"} Utility Process ${actor}`); const utilityPid = await tryGetUtilityPid(actor); - ok(utilityPid !== undefined, `Must have PID for ${actor} utility process`); + Assert.notStrictEqual( + utilityPid, + undefined, + `Must have PID for ${actor} utility process` + ); const utilityProcessGone = TestUtils.topicObserved( "ipc:utility-shutdown", @@ -332,7 +340,7 @@ async function checkAudioDecoder( const doc = typeof content !== "undefined" ? content.document : document; let audio = doc.querySelector("audio"); const checkPromise = new Promise((resolve, reject) => { - const timeUpdateHandler = async ev => { + const timeUpdateHandler = async () => { const debugInfo = await SpecialPowers.wrap(audio).mozRequestDebugInfo(); const audioDecoderName = debugInfo.decoder.reader.audioDecoderName; @@ -363,7 +371,7 @@ async function checkAudioDecoder( } }; - const startPlaybackHandler = async ev => { + const startPlaybackHandler = async () => { ok( await audio.play().then( _ => true, @@ -375,7 +383,7 @@ async function checkAudioDecoder( audio.addEventListener("timeupdate", timeUpdateHandler, { once: true }); }; - audio.addEventListener("error", async err => { + audio.addEventListener("error", async () => { info( `Received HTML media error: ${audio.error.code}: ${audio.error.message}` ); @@ -483,8 +491,9 @@ async function crashSomeUtility(utilityPid, actorsCheck) { info(`Waiting for utility process ${utilityPid} to go away.`); let [subject, data] = await utilityProcessGone; - ok( - parseInt(data, 10) === utilityPid, + Assert.strictEqual( + parseInt(data, 10), + utilityPid, `Should match the crashed PID ${utilityPid} with ${data}` ); ok( @@ -510,7 +519,7 @@ async function crashSomeUtility(utilityPid, actorsCheck) { ), "Record should be a utility process crash" ); - ok(crash.id === dumpID, "Record should have an ID"); + Assert.strictEqual(crash.id, dumpID, "Record should have an ID"); ok( actorsCheck(crash.metadata.UtilityActorsName), `Record should have the correct actors name for: ${crash.metadata.UtilityActorsName}` @@ -546,8 +555,9 @@ async function crashSomeUtilityActor( ) { // Get PID for utility type const procInfos = await getUtilityProcesses(actor); - ok( - procInfos.length == 1, + Assert.equal( + procInfos.length, + 1, `exactly one ${actor} utility process should be found` ); const utilityPid = procInfos[0].pid; diff --git a/ipc/glue/test/browser/mochitest_audio_off.toml b/ipc/glue/test/browser/mochitest_audio_off.toml index d174ea3939..767be0a4b3 100644 --- a/ipc/glue/test/browser/mochitest_audio_off.toml +++ b/ipc/glue/test/browser/mochitest_audio_off.toml @@ -1,4 +1,6 @@ [DEFAULT] +subsuite = "media" +tags = "media-engine-compatible" run-if = ["os == 'android' && !isolated_process"] # Bug 1771452 support-files = [ "head.js", @@ -7,6 +9,9 @@ support-files = [ "../../../../dom/media/test/small-shot.m4a", "../../../../dom/media/test/small-shot.flac", ] -prefs = ["media.utility-process.enabled=false"] +prefs = [ + "media.utility-process.enabled=false", + "media.wmf.media-engine.channel-decoder.enabled=false" +] ["test_utility_audio_off.html"] diff --git a/ipc/glue/test/browser/mochitest_audio_on.toml b/ipc/glue/test/browser/mochitest_audio_on.toml index 908f4005f1..a06930401e 100644 --- a/ipc/glue/test/browser/mochitest_audio_on.toml +++ b/ipc/glue/test/browser/mochitest_audio_on.toml @@ -1,4 +1,6 @@ [DEFAULT] +subsuite = "media" +tags = "media-engine-compatible" run-if = ["os == 'android' && !isolated_process"] # Bug 1771452 support-files = [ "head.js", @@ -7,6 +9,9 @@ support-files = [ "../../../../dom/media/test/small-shot.m4a", "../../../../dom/media/test/small-shot.flac", ] -prefs = ["media.utility-process.enabled=true"] +prefs = [ + "media.utility-process.enabled=true", + "media.wmf.media-engine.channel-decoder.enabled=false" +] ["test_utility_audio_on.html"] diff --git a/ipc/glue/test/gtest/TestUtilityProcessSandboxing.cpp b/ipc/glue/test/gtest/TestUtilityProcessSandboxing.cpp index fff17d63ef..cbb8d30b03 100644 --- a/ipc/glue/test/gtest/TestUtilityProcessSandboxing.cpp +++ b/ipc/glue/test/gtest/TestUtilityProcessSandboxing.cpp @@ -30,8 +30,10 @@ TEST(UtilityProcessSandboxing, ParseEnvVar_DisableGenericOnly) #if defined(XP_DARWIN) TEST(UtilityProcessSandboxing, ParseEnvVar_DisableAppleAudioOnly) { +# if defined(MOZ_APPLEMEDIA) EXPECT_FALSE(IsUtilitySandboxEnabled( "utility:1", SandboxingKind::UTILITY_AUDIO_DECODING_APPLE_MEDIA)); +# endif EXPECT_TRUE( IsUtilitySandboxEnabled("utility:1", SandboxingKind::GENERIC_UTILITY)); } @@ -51,11 +53,11 @@ TEST(UtilityProcessSandboxing, ParseEnvVar_DisableGenericOnly_Multiples) { EXPECT_FALSE(IsUtilitySandboxEnabled("utility:1,utility:0,utility:2", SandboxingKind::GENERIC_UTILITY)); -#if defined(XP_DARWIN) +#if defined(MOZ_APPLEMEDIA) EXPECT_FALSE(IsUtilitySandboxEnabled( "utility:1,utility:0,utility:2", SandboxingKind::UTILITY_AUDIO_DECODING_APPLE_MEDIA)); -#endif // XP_DARWIN +#endif // MOZ_APPLEMEDIA #if defined(XP_WIN) EXPECT_FALSE( IsUtilitySandboxEnabled("utility:1,utility:0,utility:2", diff --git a/ipc/glue/test/utility_process_xpcom/UtilityProcessTest.cpp b/ipc/glue/test/utility_process_xpcom/UtilityProcessTest.cpp index 6c084a3153..9d22d60d0f 100644 --- a/ipc/glue/test/utility_process_xpcom/UtilityProcessTest.cpp +++ b/ipc/glue/test/utility_process_xpcom/UtilityProcessTest.cpp @@ -7,6 +7,7 @@ #if defined(ENABLE_TESTS) # include "mozilla/ipc/UtilityProcessManager.h" # include "mozilla/ipc/UtilityProcessTest.h" +# include "mozilla/dom/ChromeUtilsBinding.h" # include "mozilla/dom/Promise.h" # include "mozilla/ProcInfo.h" # include "mozilla/IntentionalCrash.h" @@ -26,23 +27,17 @@ namespace mozilla::ipc { static UtilityActorName UtilityActorNameFromString( const nsACString& aStringName) { using namespace mozilla::dom; - - // We use WebIDLUtilityActorNames because UtilityActorNames is not designed - // for iteration. - for (size_t i = 0; i < WebIDLUtilityActorNameValues::Count; ++i) { - auto idlName = static_cast(i); - const nsDependentCSubstring idlNameString( - WebIDLUtilityActorNameValues::GetString(idlName)); - if (idlNameString.Equals(aStringName)) { - return idlName; - } + auto idlName = StringToEnum(aStringName); + if (idlName.isSome()) { + return idlName.value(); } MOZ_CRASH("Unknown utility actor name"); } // Find the utility process with the given actor or any utility process if -// the actor is UtilityActorName::EndGuard_. -static SandboxingKind FindUtilityProcessWithActor(UtilityActorName aActorName) { +// aActorName is Nothing(). +static SandboxingKind FindUtilityProcessWithActor( + const Maybe& aActorName) { RefPtr utilityProc = UtilityProcessManager::GetSingleton(); MOZ_ASSERT(utilityProc, "No UtilityprocessManager?"); @@ -52,11 +47,11 @@ static SandboxingKind FindUtilityProcessWithActor(UtilityActorName aActorName) { if (!utilityProc->Process(sbKind)) { continue; } - if (aActorName == UtilityActorName::EndGuard_) { + if (aActorName.isNothing()) { return sbKind; } for (auto actor : utilityProc->GetActors(sbKind)) { - if (actor == aActorName) { + if (actor == aActorName.ref()) { return sbKind; } } @@ -236,9 +231,9 @@ UtilityProcessTest::StopProcess(const char* aActorName) { if (aActorName) { const nsDependentCString actorStringName(aActorName); UtilityActorName actorName = UtilityActorNameFromString(actorStringName); - sbKind = FindUtilityProcessWithActor(actorName); + sbKind = FindUtilityProcessWithActor(Some(actorName)); } else { - sbKind = FindUtilityProcessWithActor(UtilityActorName::EndGuard_); + sbKind = FindUtilityProcessWithActor(Nothing()); } if (sbKind == SandboxingKind::COUNT) { diff --git a/ipc/ipdl/ipdl.py b/ipc/ipdl/ipdl.py index 230e0a213f..befaacca45 100644 --- a/ipc/ipdl/ipdl.py +++ b/ipc/ipdl/ipdl.py @@ -8,6 +8,7 @@ from configparser import RawConfigParser from io import StringIO import ipdl +from ipdl.ast import SYNC def log(minv, fmt, *args): @@ -96,6 +97,7 @@ log(2, 'Generated C++ headers will be generated relative to "%s"', headersdir) log(2, 'Generated C++ sources will be generated in "%s"', cppdir) allmessages = {} +allsyncmessages = [] allmessageprognames = [] allprotocols = [] @@ -172,10 +174,16 @@ for f in files: if ast.protocol: allmessages[ast.protocol.name] = ipdl.genmsgenum(ast) allprotocols.append(ast.protocol.name) + # e.g. PContent::RequestMemoryReport (not prefixed or suffixed.) for md in ast.protocol.messageDecls: allmessageprognames.append("%s::%s" % (md.namespace, md.decl.progname)) + if md.sendSemantics is SYNC: + allsyncmessages.append( + "%s__%s" % (ast.protocol.name, md.prettyMsgName()) + ) + allprotocols.sort() # Check if we have undefined message names in segmentCapacityDict. @@ -248,6 +256,23 @@ print( namespace IPC { +bool IPCMessageTypeIsSync(uint32_t aMessageType) +{ + switch (aMessageType) { +""", + file=ipc_msgtype_name, +) + +for msg in allsyncmessages: + print(" case %s:" % msg, file=ipc_msgtype_name) + +print( + """ return true; + default: + return false; + } +} + const char* StringFromIPCMessageType(uint32_t aMessageType) { switch (aMessageType) { diff --git a/ipc/ipdl/ipdl/__init__.py b/ipc/ipdl/ipdl/__init__.py index 50ceb4f953..c042c16444 100644 --- a/ipc/ipdl/ipdl/__init__.py +++ b/ipc/ipdl/ipdl/__init__.py @@ -75,7 +75,7 @@ def gencxx(ipdlfilename, ast, outheadersdir, outcppdir, segmentcapacitydict): def genipdl(ast, outdir): - return IPDLCodeGen().cgen(ast) + return ast.accept(IPDLCodeGen()) def genmsgenum(ast): diff --git a/ipc/ipdl/ipdl/ast.py b/ipc/ipdl/ipdl/ast.py index ff083cf628..9329bd3d23 100644 --- a/ipc/ipdl/ipdl/ast.py +++ b/ipc/ipdl/ipdl/ast.py @@ -254,37 +254,35 @@ class UsingStmt(Node): # "singletons" -class PrettyPrinted: - @classmethod +class PrettyPrinted(type): def __hash__(cls): return hash_str(cls.pretty) - @classmethod def __str__(cls): return cls.pretty -class ASYNC(PrettyPrinted): +class ASYNC(metaclass=PrettyPrinted): pretty = "async" -class INTR(PrettyPrinted): +class INTR(metaclass=PrettyPrinted): pretty = "intr" -class SYNC(PrettyPrinted): +class SYNC(metaclass=PrettyPrinted): pretty = "sync" -class INOUT(PrettyPrinted): +class INOUT(metaclass=PrettyPrinted): pretty = "inout" -class IN(PrettyPrinted): +class IN(metaclass=PrettyPrinted): pretty = "in" -class OUT(PrettyPrinted): +class OUT(metaclass=PrettyPrinted): pretty = "out" diff --git a/ipc/ipdl/ipdl/cgen.py b/ipc/ipdl/ipdl/cgen.py index 8ed8da4d81..fbf0448f33 100644 --- a/ipc/ipdl/ipdl/cgen.py +++ b/ipc/ipdl/ipdl/cgen.py @@ -44,7 +44,7 @@ class IPDLCodeGen(CodePrinter, Visitor): def visitTranslationUnit(self, tu): self.printed.add(tu.filename) self.println("//\n// Automatically generated by ipdlc\n//") - CodeGen.visitTranslationUnit(self, tu) # NOQA: F821 + Visitor.visitTranslationUnit(self, tu) # NOQA: F821 def visitCxxInclude(self, inc): self.println('include "' + inc.file + '";') @@ -64,7 +64,7 @@ class IPDLCodeGen(CodePrinter, Visitor): for namespace in p.namespaces: namespace.accept(self) - self.println("%s protocol %s\n{" % (p.sendSemantics[0], p.name)) + self.println("%s protocol %s\n{" % (p.sendSemantics, p.name)) self.indent() for mgs in p.managesStmts: @@ -87,7 +87,7 @@ class IPDLCodeGen(CodePrinter, Visitor): self.printdentln("manages " + mgs.name + ";") def visitMessageDecl(self, msg): - self.printdent("%s %s %s(" % (msg.sendSemantics[0], msg.direction[0], msg.name)) + self.printdent("%s %s %s(" % (msg.sendSemantics, msg.direction, msg.name)) for i, inp in enumerate(msg.inParams): inp.accept(self) if i != (len(msg.inParams) - 1): diff --git a/ipc/ipdl/ipdl/lower.py b/ipc/ipdl/ipdl/lower.py index aac8ebaf36..94699fdcab 100644 --- a/ipc/ipdl/ipdl/lower.py +++ b/ipc/ipdl/ipdl/lower.py @@ -4590,10 +4590,9 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor): sendmethod, (recvlbl, recvcase) = self.genAsyncCtor(md) elif isctor: sendmethod = self.genBlockingCtorMethod(md) - elif isdtor and isasync: - sendmethod, (recvlbl, recvcase) = self.genAsyncDtor(md) elif isdtor: - sendmethod = self.genBlockingDtorMethod(md) + assert isasync + sendmethod, (recvlbl, recvcase) = self.genDtor(md) elif isasync: ( sendmethod, @@ -4781,7 +4780,7 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor): ) return helper - def genAsyncDtor(self, md): + def genDtor(self, md): actorvar = ExprVar("actor") method = MethodDefn(self.makeDtorMethodDecl(md, actorvar)) @@ -4805,39 +4804,6 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor): return method, (lbl, case) - def genBlockingDtorMethod(self, md): - actorvar = ExprVar("actor") - method = MethodDefn(self.makeDtorMethodDecl(md, actorvar)) - - method.addstmt(self.dtorPrologue(actorvar)) - - msgvar, stmts = self.makeMessage(md, errfnSendDtor, actorvar) - - replyvar = self.replyvar - sendok, sendstmts = self.sendBlocking(md, msgvar, replyvar, actorvar) - method.addstmts( - stmts - + [Whitespace.NL, StmtDecl(Decl(Type("UniquePtr"), replyvar.name))] - + sendstmts - ) - - destmts = self.deserializeReply( - md, replyvar, self.side, errfnSend, errfnSentinel(), actorvar - ) - ifsendok = StmtIf(ExprLiteral.FALSE) - ifsendok.addifstmts(destmts) - ifsendok.addifstmts( - [Whitespace.NL, StmtExpr(ExprAssn(sendok, ExprLiteral.FALSE, "&="))] - ) - - method.addstmt(ifsendok) - - method.addstmts( - self.dtorEpilogue(md, actorvar) + [Whitespace.NL, StmtReturn(sendok)] - ) - - return method - def destroyActor(self, md, actorexpr, why=_DestroyReason.Deletion): if md and md.decl.type.isCtor(): destroyedType = md.decl.type.constructedType() diff --git a/ipc/ipdl/ipdl/type.py b/ipc/ipdl/ipdl/type.py index 3f091f0dd6..d8e893ddf5 100644 --- a/ipc/ipdl/ipdl/type.py +++ b/ipc/ipdl/ipdl/type.py @@ -1424,6 +1424,10 @@ class GatherDecls(TcheckVisitor): # if we error here, no big deal; move on to find more if _DELETE_MSG == msgname: + if md.sendSemantics is not ASYNC: + self.error(loc, "destructor must be async") + if md.outParams: + self.error(loc, "destructors cannot return values") isdtor = True cdtype = self.currentProtocolDecl.type diff --git a/ipc/ipdl/sync-messages.ini b/ipc/ipdl/sync-messages.ini index 63fac60c8d..9fdb216859 100644 --- a/ipc/ipdl/sync-messages.ini +++ b/ipc/ipdl/sync-messages.ini @@ -18,6 +18,90 @@ description = Only used by gtests description = Only used by gtests [PQuotaTest::TryInspect_Success_CustomErr_IpcFail] description = Only used by gtests +[PTestCancel::ImmediateCancel] +description = Only used by gtests +[PTestCancel::NestedCancel] +description = Only used by gtests +[PTestCancel::CallNestedCancel] +description = Only used by gtests +[PTestCancel::StartNestedCancelParent] +description = Only used by gtests +[PTestCancel::NestedCancelParent] +description = Only used by gtests +[PTestCancel::CheckChild] +description = Only used by gtests +[PTestCancel::CheckParent] +description = Only used by gtests +[PTestDataStructures::TestArrayOfInt] +description = Only used by gtests +[PTestDataStructures::TestArrayOfActor] +description = Only used by gtests +[PTestDataStructures::TestUnion] +description = Only used by gtests +[PTestDataStructures::TestArrayOfUnion] +description = Only used by gtests +[PTestDataStructures::TestUnionWithArray] +description = Only used by gtests +[PTestDataStructures::TestArrayOfUnionWithArray] +description = Only used by gtests +[PTestDataStructures::TestStructWithActor] +description = Only used by gtests +[PTestDataStructures::TestUnionWithActors] +description = Only used by gtests +[PTestDataStructures::TestArrayOfUnionWithActors] +description = Only used by gtests +[PTestDataStructures::TestUnions] +description = Only used by gtests +[PTestDataStructures::TestArrayOfUnions] +description = Only used by gtests +[PTestDataStructures::TestStruct] +description = Only used by gtests +[PTestDataStructures::TestStructWithArrays] +description = Only used by gtests +[PTestDataStructures::TestStructWithActors] +description = Only used by gtests +[PTestDataStructures::TestStructs] +description = Only used by gtests +[PTestDataStructures::TestUnionWithStructs] +description = Only used by gtests +[PTestDataStructures::TestStructWithUnions] +description = Only used by gtests +[PTestDataStructures::TestUnionWithCxx] +description = Only used by gtests +[PTestDataStructures::TestNsIntRegion] +description = Only used by gtests +[PTestEndpointOpensOpened::HelloSync] +description = Only used by gtests +[PTestHangs::Hang] +description = Only used by gtests +[PTestJSON::Test] +description = Only used by gtests +[PTestMostNested::Msg2] +description = Only used by gtests +[PTestMostNested::Msg4] +description = Only used by gtests +[PTestMostNested::StartInner] +description = Only used by gtests +[PTestSyncError::Error] +description = Only used by gtests +[PTestUrgency::Test1] +description = Only used by gtests +[PTestUrgency::Test3] +description = Only used by gtests +[PTestUrgency::FinalTest_Begin] +description = Only used by gtests +[PTestUrgency::Reply1] +description = Only used by gtests +[PTestUrgency::Reply2] +description = Only used by gtests + +# Clipboard +[PContent::GetClipboard] +description = Legacy synchronous clipboard API +[PContent::ClipboardHasType] +description = Legacy synchronous clipboard API +[PContent::GetClipboardDataSnapshotSync] +description = Legacy synchronous clipboard API # The rest [PHeapSnapshotTempFileHelper::OpenHeapSnapshotTempFile] @@ -56,12 +140,6 @@ description = JS MessageManager implementation description = legacy sync IPC - please add detailed description [PContent::PURLClassifier] description = legacy sync IPC - please add detailed description -[PContent::GetClipboard] -description = Legacy synchronous clipboard API -[PContent::ClipboardHasType] -description = Legacy synchronous clipboard API -[PContent::GetExternalClipboardFormats] -description = Retrieve supported clipboard formats synchronously [PContent::GetIconForExtension] description = legacy sync IPC - please add detailed description [PContent::BeginDriverCrashGuard] diff --git a/ipc/ipdl/test/cxx/PTestActorPunning.ipdl b/ipc/ipdl/test/cxx/PTestActorPunning.ipdl deleted file mode 100644 index 0aec430d9f..0000000000 --- a/ipc/ipdl/test/cxx/PTestActorPunning.ipdl +++ /dev/null @@ -1,28 +0,0 @@ - -include protocol PTestActorPunningPunned; -include protocol PTestActorPunningSub; -include "mozilla/_ipdltest/IPDLUnitTestUtils.h"; -include "mozilla/_ipdltest/TestActorPunning.h"; - -using struct mozilla::_ipdltest::Bad from "mozilla/_ipdltest/IPDLUnitTestUtils.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestActorPunningChild", ParentImpl="TestActorPunningParent"] -protocol PTestActorPunning { - manages PTestActorPunningPunned; - manages PTestActorPunningSub; - -child: - async Start(); - -parent: - async PTestActorPunningPunned(); - async PTestActorPunningSub(); - async Pun(PTestActorPunningSub a, Bad bad); - async __delete__(); -}; - -} // namespace mozilla -} // namespace _ipdltest diff --git a/ipc/ipdl/test/cxx/PTestActorPunningPunned.ipdl b/ipc/ipdl/test/cxx/PTestActorPunningPunned.ipdl deleted file mode 100644 index 5cca8a8ab5..0000000000 --- a/ipc/ipdl/test/cxx/PTestActorPunningPunned.ipdl +++ /dev/null @@ -1,18 +0,0 @@ - -include protocol PTestActorPunning; - -include "mozilla/_ipdltest/TestActorPunning.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestActorPunningPunnedChild", ParentImpl="TestActorPunningPunnedParent"] -protocol PTestActorPunningPunned { - manager PTestActorPunning; - -child: - async __delete__(); -}; - -} // namespace mozilla -} // namespace _ipdltes diff --git a/ipc/ipdl/test/cxx/PTestActorPunningSub.ipdl b/ipc/ipdl/test/cxx/PTestActorPunningSub.ipdl deleted file mode 100644 index 0cb522255c..0000000000 --- a/ipc/ipdl/test/cxx/PTestActorPunningSub.ipdl +++ /dev/null @@ -1,19 +0,0 @@ - -include protocol PTestActorPunning; - -include "mozilla/_ipdltest/TestActorPunning.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestActorPunningSubChild", ParentImpl="TestActorPunningSubParent"] -protocol PTestActorPunningSub { - manager PTestActorPunning; - -child: - async Bad(); - async __delete__(); -}; - -} // namespace mozilla -} // namespace _ipdltes diff --git a/ipc/ipdl/test/cxx/PTestAsyncReturns.ipdl b/ipc/ipdl/test/cxx/PTestAsyncReturns.ipdl deleted file mode 100644 index 42ef17d1e8..0000000000 --- a/ipc/ipdl/test/cxx/PTestAsyncReturns.ipdl +++ /dev/null @@ -1,20 +0,0 @@ -include "mozilla/_ipdltest/TestAsyncReturns.h"; - -namespace mozilla { -namespace _ipdltest { - - -[ManualDealloc, ChildImpl="TestAsyncReturnsChild", ParentImpl="TestAsyncReturnsParent"] -protocol PTestAsyncReturns { - -child: - async Ping() returns (bool one); - async NoReturn() returns (bool unused); - -parent: - async Pong() returns (uint32_t param1, uint32_t param2); -}; - - -} // namespace mozilla -} // namespace _ipdltest diff --git a/ipc/ipdl/test/cxx/PTestBadActor.ipdl b/ipc/ipdl/test/cxx/PTestBadActor.ipdl deleted file mode 100644 index 991e6eb945..0000000000 --- a/ipc/ipdl/test/cxx/PTestBadActor.ipdl +++ /dev/null @@ -1,21 +0,0 @@ -include protocol PTestBadActorSub; - -include "mozilla/_ipdltest/TestBadActor.h"; - -namespace mozilla { -namespace _ipdltest { - -// Test that a parent sending a reentrant __delete__ message -// is not killed if a child's message races with the reply. - -[ManualDealloc, ChildImpl="TestBadActorChild", ParentImpl="TestBadActorParent"] -intr protocol PTestBadActor { - manages PTestBadActorSub; - -child: - async PTestBadActorSub(); - async __delete__(); -}; - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/PTestBadActorSub.ipdl b/ipc/ipdl/test/cxx/PTestBadActorSub.ipdl deleted file mode 100644 index aadd8b6739..0000000000 --- a/ipc/ipdl/test/cxx/PTestBadActorSub.ipdl +++ /dev/null @@ -1,20 +0,0 @@ -include protocol PTestBadActor; - -include "mozilla/_ipdltest/TestBadActor.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestBadActorSubChild", ParentImpl="TestBadActorSubParent"] -intr protocol PTestBadActorSub { - manager PTestBadActor; - -child: - [LegacyIntr] intr __delete__(); - -parent: - async Ping(); -}; - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/PTestCancel.ipdl b/ipc/ipdl/test/cxx/PTestCancel.ipdl deleted file mode 100644 index 4ad902e8e1..0000000000 --- a/ipc/ipdl/test/cxx/PTestCancel.ipdl +++ /dev/null @@ -1,39 +0,0 @@ -include "mozilla/_ipdltest/TestCancel.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, NestedUpTo=inside_sync, ChildImpl="TestCancelChild", ParentImpl="TestCancelParent"] -sync protocol PTestCancel -{ -// Test1 -child: - [Nested=inside_sync] sync Test1_1(); -parent: - async Done1(); - -// Test2 -child: - async Start2(); - [Nested=inside_sync] sync Test2_2(); -parent: - sync Test2_1(); - -// Test3 -child: - [Nested=inside_sync] sync Test3_1(); -parent: - async Start3(); - [Nested=inside_sync] sync Test3_2(); - -parent: - async Done(); - -child: - [Nested=inside_sync] sync CheckChild() returns (uint32_t reply); -parent: - [Nested=inside_sync] sync CheckParent() returns (uint32_t reply); -}; - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/PTestCrashCleanup.ipdl b/ipc/ipdl/test/cxx/PTestCrashCleanup.ipdl deleted file mode 100644 index 43d955f1c7..0000000000 --- a/ipc/ipdl/test/cxx/PTestCrashCleanup.ipdl +++ /dev/null @@ -1,20 +0,0 @@ -include "mozilla/_ipdltest/TestCrashCleanup.h"; - -// See bug 538586: if the top-level protocol's actor is deleted before -// the "connection error" notification comes in from the IO thread, -// IPDL teardown never occurs, even if Channel::Close() is called -// after the error. - -namespace mozilla { -namespace _ipdltest { - -// NB: needs to be RPC so that the parent blocks on the child's crash. -[ManualDealloc, ChildImpl="TestCrashCleanupChild", ParentImpl="TestCrashCleanupParent"] -intr protocol PTestCrashCleanup { -child: - [LegacyIntr] intr DIEDIEDIE(); - async __delete__(); -}; - -} -} diff --git a/ipc/ipdl/test/cxx/PTestDataStructures.ipdl b/ipc/ipdl/test/cxx/PTestDataStructures.ipdl deleted file mode 100644 index 64b6970666..0000000000 --- a/ipc/ipdl/test/cxx/PTestDataStructures.ipdl +++ /dev/null @@ -1,109 +0,0 @@ -include protocol PTestDataStructuresSub; -include PTestDataStructuresCommon; - -include "mozilla/GfxMessageUtils.h"; -include "mozilla/_ipdltest/TestDataStructures.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestDataStructuresChild", ParentImpl="TestDataStructuresParent"] -sync protocol PTestDataStructures { - manages PTestDataStructuresSub; - -child: - async PTestDataStructuresSub(int i); - - async Start(); - -parent: - async __delete__(); - - sync Test1(int[] i1) - returns (int[] o1); - - sync Test2(PTestDataStructuresSub[] i1) - returns (PTestDataStructuresSub[] o1); - - sync Test3(IntDouble i1, - IntDouble i2) - returns (IntDouble o1, - IntDouble o2); - - sync Test4(IntDouble[] i1) - returns (IntDouble[] o1); - - sync Test5(IntDoubleArrays i1, - IntDoubleArrays i2, - IntDoubleArrays i3) - returns (IntDoubleArrays o1, - IntDoubleArrays o2, - IntDoubleArrays o3); - - sync Test6(IntDoubleArrays[] i1) - returns (IntDoubleArrays[] o1); - - sync Test7_0(ActorWrapper a1) - returns (ActorWrapper o1); - - sync Test7(Actors i1, - Actors i2, - Actors i3) - returns (Actors o1, - Actors o2, - Actors o3); - - sync Test8(Actors[] i1) - returns (Actors[] o1); - - sync Test9(Unions i1, - Unions i2, - Unions i3, - Unions i4) - returns (Unions o1, - Unions o2, - Unions o3, - Unions o4); - - sync Test10(Unions[] i1) - returns (Unions[] o1); - - sync Test11(SIntDouble i) - returns (SIntDouble o); - - sync Test12(SIntDoubleArrays i) - returns (SIntDoubleArrays o); - - sync Test13(SActors i) - returns (SActors o); - - sync Test14(Structs i) - returns (Structs o); - - sync Test15(WithStructs i1, - WithStructs i2, - WithStructs i3, - WithStructs i4, - WithStructs i5) - returns (WithStructs o1, - WithStructs o2, - WithStructs o3, - WithStructs o4, - WithStructs o5); - - sync Test16(WithUnions i) - returns (WithUnions o); - - sync Test17(Op[] ops); - - // test that the ParamTraits::Read() workaround for - // nsTArray's incorrect memmove() semantics works properly - // (nsIntRegion isn't memmove()able) - sync Test18(nsIntRegion[] ops); - - sync Dummy(ShmemUnion su) returns (ShmemUnion rsu); -}; - -} // namespace _ipdltest -} // namespace mozilla - diff --git a/ipc/ipdl/test/cxx/PTestDataStructuresCommon.ipdlh b/ipc/ipdl/test/cxx/PTestDataStructuresCommon.ipdlh deleted file mode 100644 index 39d7f482b3..0000000000 --- a/ipc/ipdl/test/cxx/PTestDataStructuresCommon.ipdlh +++ /dev/null @@ -1,107 +0,0 @@ -include protocol PTestDataStructuresSub; - -using struct mozilla::null_t from "mozilla/ipc/IPCCore.h"; -using nsIntRegion from "nsRegion.h"; - -namespace mozilla { -namespace _foo { - -union IntDouble { - int; - double; -}; - -struct SIntDouble { - int i; - double d; -}; - -union IntDoubleArrays { - int; - int[]; - double[]; -}; - -struct SIntDoubleArrays { - int i; - int[] ai; - double[] ad; -}; - -struct ActorWrapper { - PTestDataStructuresSub actor; -}; - -union Actors { - int; - int[]; - PTestDataStructuresSub[]; -}; - -struct SActors { - int i; - int[] ai; - PTestDataStructuresSub[] ap; -}; - -union Unions { - int; - int[]; - PTestDataStructuresSub[]; - Actors[]; -}; - -struct Structs { - int i; - int[] ai; - PTestDataStructuresSub[] ap; - SActors[] aa; -}; - -union WithStructs { - int; - int[]; - PTestDataStructuresSub[]; - SActors[]; - Structs[]; -}; - -struct WithUnions { - int i; - int[] ai; - PTestDataStructuresSub[] ap; - Actors[] aa; - Unions[] au; -}; - -struct CommonAttrs { bool dummy; }; -struct FooAttrs { int dummy; }; -struct BarAttrs { float dummy; }; -union SpecificAttrs { - FooAttrs; - BarAttrs; -}; -struct Attrs { - CommonAttrs common; - SpecificAttrs specific; -}; -struct SetAttrs { - PTestDataStructuresSub x; - Attrs attrs; -}; -union Op { null_t; SetAttrs; }; - -struct ShmemStruct { - int i; - Shmem mem; -}; - -union ShmemUnion { - int; - Shmem; -}; - -struct Empty { }; - -} // namespace _foo -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/PTestDataStructuresSub.ipdl b/ipc/ipdl/test/cxx/PTestDataStructuresSub.ipdl deleted file mode 100644 index 4f546a8d29..0000000000 --- a/ipc/ipdl/test/cxx/PTestDataStructuresSub.ipdl +++ /dev/null @@ -1,18 +0,0 @@ -include PTestDataStructuresCommon; -include protocol PTestDataStructures; - -include "mozilla/_ipdltest/TestDataStructures.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestDataStructuresSub", ParentImpl="TestDataStructuresSub"] -sync protocol PTestDataStructuresSub { - manager PTestDataStructures; - -parent: - sync __delete__(); -}; - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/PTestDemon.ipdl b/ipc/ipdl/test/cxx/PTestDemon.ipdl deleted file mode 100644 index f5af2396e6..0000000000 --- a/ipc/ipdl/test/cxx/PTestDemon.ipdl +++ /dev/null @@ -1,24 +0,0 @@ -include "mozilla/_ipdltest/TestDemon.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, NestedUpTo=inside_cpow, ChildImpl="TestDemonChild", ParentImpl="TestDemonParent"] -sync protocol PTestDemon -{ -child: - async Start(); - -both: - async AsyncMessage(int n); - [Nested=inside_sync] sync HiPrioSyncMessage(); - -parent: - sync SyncMessage(int n); - - [Nested=inside_cpow] async UrgentAsyncMessage(int n); - [Nested=inside_cpow] sync UrgentSyncMessage(int n); -}; - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/PTestDesc.ipdl b/ipc/ipdl/test/cxx/PTestDesc.ipdl deleted file mode 100644 index d18d2d8598..0000000000 --- a/ipc/ipdl/test/cxx/PTestDesc.ipdl +++ /dev/null @@ -1,24 +0,0 @@ -include protocol PTestDescSub; -include protocol PTestDescSubsub; - -include "mozilla/_ipdltest/TestDesc.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestDescChild", ParentImpl="TestDescParent"] -intr protocol PTestDesc { - manages PTestDescSub; -child: - [LegacyIntr] intr PTestDescSub(nullable PTestDescSubsub dummy); - - async Test(PTestDescSubsub a); - - async __delete__(); - -parent: - async Ok(PTestDescSubsub a); -}; - -} -} diff --git a/ipc/ipdl/test/cxx/PTestDescSub.ipdl b/ipc/ipdl/test/cxx/PTestDescSub.ipdl deleted file mode 100644 index a05451c639..0000000000 --- a/ipc/ipdl/test/cxx/PTestDescSub.ipdl +++ /dev/null @@ -1,21 +0,0 @@ -include protocol PTestDesc; -include protocol PTestDescSubsub; - -include "mozilla/_ipdltest/TestDesc.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestDescSubChild", ParentImpl="TestDescSubParent"] -intr protocol PTestDescSub { - manager PTestDesc; - manages PTestDescSubsub; - -child: - async __delete__(); - - [LegacyIntr] intr PTestDescSubsub(); -}; - -} -} diff --git a/ipc/ipdl/test/cxx/PTestDescSubsub.ipdl b/ipc/ipdl/test/cxx/PTestDescSubsub.ipdl deleted file mode 100644 index 542a03e2d2..0000000000 --- a/ipc/ipdl/test/cxx/PTestDescSubsub.ipdl +++ /dev/null @@ -1,18 +0,0 @@ - -include protocol PTestDescSub; - -include "mozilla/_ipdltest/TestDesc.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestDescSubsubChild", ParentImpl="TestDescSubsubParent"] -intr protocol PTestDescSubsub { - manager PTestDescSub; - -child: - [LegacyIntr] intr __delete__(); -}; - -} -} diff --git a/ipc/ipdl/test/cxx/PTestEndpointBridgeMain.ipdl b/ipc/ipdl/test/cxx/PTestEndpointBridgeMain.ipdl deleted file mode 100644 index c51967b1fa..0000000000 --- a/ipc/ipdl/test/cxx/PTestEndpointBridgeMain.ipdl +++ /dev/null @@ -1,25 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ - -include protocol PTestEndpointBridgeMainSub; -include protocol PTestEndpointBridgeSub; - -include "mozilla/_ipdltest/TestEndpointBridgeMain.h"; - -namespace mozilla { -namespace _ipdltest { - - -[ManualDealloc, ChildImpl="TestEndpointBridgeMainChild", ParentImpl="TestEndpointBridgeMainParent"] -protocol PTestEndpointBridgeMain { - -child: - async Start(); - -parent: - async Bridged(Endpoint endpoint); -}; - - -} // namespace mozilla -} // namespace _ipdltest diff --git a/ipc/ipdl/test/cxx/PTestEndpointBridgeMainSub.ipdl b/ipc/ipdl/test/cxx/PTestEndpointBridgeMainSub.ipdl deleted file mode 100644 index e899fca7aa..0000000000 --- a/ipc/ipdl/test/cxx/PTestEndpointBridgeMainSub.ipdl +++ /dev/null @@ -1,28 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ - -include protocol PTestEndpointBridgeMain; -include protocol PTestEndpointBridgeSub; - -include "mozilla/_ipdltest/TestEndpointBridgeMain.h"; - -namespace mozilla { -namespace _ipdltest { - -// (Bridge protocols can have different semantics than the endpoints -// they bridge) -[ManualDealloc, ChildImpl="TestEndpointBridgeMainSubChild", ParentImpl="TestEndpointBridgeMainSubParent"] -intr protocol PTestEndpointBridgeMainSub { -child: - async Hi(); - [LegacyIntr] intr HiRpc(); - -parent: - async Hello(); - sync HelloSync(); - [LegacyIntr] intr HelloRpc(); -}; - - -} // namespace mozilla -} // namespace _ipdltest diff --git a/ipc/ipdl/test/cxx/PTestEndpointBridgeSub.ipdl b/ipc/ipdl/test/cxx/PTestEndpointBridgeSub.ipdl deleted file mode 100644 index ab12e3bdb5..0000000000 --- a/ipc/ipdl/test/cxx/PTestEndpointBridgeSub.ipdl +++ /dev/null @@ -1,25 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ - -include protocol PTestEndpointBridgeMainSub; - -include "mozilla/_ipdltest/TestEndpointBridgeMain.h"; - -namespace mozilla { -namespace _ipdltest { - - -[ManualDealloc, ChildImpl="TestEndpointBridgeSubChild", ParentImpl="TestEndpointBridgeSubParent"] -protocol PTestEndpointBridgeSub { -child: - async Ping(); - - async Bridged(Endpoint endpoint); - -parent: - async BridgeEm(); -}; - - -} // namespace mozilla -} // namespace _ipdltest diff --git a/ipc/ipdl/test/cxx/PTestEndpointOpens.ipdl b/ipc/ipdl/test/cxx/PTestEndpointOpens.ipdl deleted file mode 100644 index 6cb20bf8eb..0000000000 --- a/ipc/ipdl/test/cxx/PTestEndpointOpens.ipdl +++ /dev/null @@ -1,22 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -include protocol PTestEndpointOpensOpened; - -include "mozilla/_ipdltest/TestEndpointOpens.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestEndpointOpensChild", ParentImpl="TestEndpointOpensParent"] -protocol PTestEndpointOpens { -child: - async Start(); - -parent: - async StartSubprotocol(Endpoint endpoint); - - async __delete__(); -}; - -} // namespace mozilla -} // namespace _ipdltest diff --git a/ipc/ipdl/test/cxx/PTestEndpointOpensOpened.ipdl b/ipc/ipdl/test/cxx/PTestEndpointOpensOpened.ipdl deleted file mode 100644 index 7f72828c30..0000000000 --- a/ipc/ipdl/test/cxx/PTestEndpointOpensOpened.ipdl +++ /dev/null @@ -1,25 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -include "mozilla/_ipdltest/TestEndpointOpens.h"; - -namespace mozilla { -namespace _ipdltest2 { - -// (Opens protocols can have different semantics than the endpoints -// that opened them) -[ManualDealloc, ChildImpl="TestEndpointOpensOpenedChild", ParentImpl="TestEndpointOpensOpenedParent"] -intr protocol PTestEndpointOpensOpened { -child: - async Hi(); - [LegacyIntr] intr HiRpc(); - -parent: - async Hello(); - sync HelloSync(); - [LegacyIntr] intr HelloRpc(); - async __delete__(); -}; - - -} // namespace mozilla -} // namespace _ipdltest2 diff --git a/ipc/ipdl/test/cxx/PTestFailedCtor.ipdl b/ipc/ipdl/test/cxx/PTestFailedCtor.ipdl deleted file mode 100644 index 0144f66dba..0000000000 --- a/ipc/ipdl/test/cxx/PTestFailedCtor.ipdl +++ /dev/null @@ -1,17 +0,0 @@ -include protocol PTestFailedCtorSub; - -include "mozilla/_ipdltest/TestFailedCtor.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestFailedCtorChild", ParentImpl="TestFailedCtorParent"] -intr protocol PTestFailedCtor { - manages PTestFailedCtorSub; -child: - [LegacyIntr] intr PTestFailedCtorSub(); - async __delete__(); -}; - -} -} diff --git a/ipc/ipdl/test/cxx/PTestFailedCtorSub.ipdl b/ipc/ipdl/test/cxx/PTestFailedCtorSub.ipdl deleted file mode 100644 index 97bc4d4bf8..0000000000 --- a/ipc/ipdl/test/cxx/PTestFailedCtorSub.ipdl +++ /dev/null @@ -1,21 +0,0 @@ -include protocol PTestFailedCtor; -include protocol PTestFailedCtorSubsub; - -include "mozilla/_ipdltest/TestFailedCtor.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestFailedCtorSubChild", ParentImpl="TestFailedCtorSubParent"] -intr protocol PTestFailedCtorSub { - manager PTestFailedCtor; - manages PTestFailedCtorSubsub; - -parent: - async PTestFailedCtorSubsub(); - sync Sync(); - async __delete__(); -}; - -} -} diff --git a/ipc/ipdl/test/cxx/PTestFailedCtorSubsub.ipdl b/ipc/ipdl/test/cxx/PTestFailedCtorSubsub.ipdl deleted file mode 100644 index 84cb2a0eb8..0000000000 --- a/ipc/ipdl/test/cxx/PTestFailedCtorSubsub.ipdl +++ /dev/null @@ -1,18 +0,0 @@ - -include protocol PTestFailedCtorSub; - -include "mozilla/_ipdltest/TestFailedCtor.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestFailedCtorSubsub", ParentImpl="TestFailedCtorSubsub"] -intr protocol PTestFailedCtorSubsub { - manager PTestFailedCtorSub; - -parent: - async __delete__(); -}; - -} -} diff --git a/ipc/ipdl/test/cxx/PTestHandle.ipdl b/ipc/ipdl/test/cxx/PTestHandle.ipdl deleted file mode 100644 index b0a65f69c0..0000000000 --- a/ipc/ipdl/test/cxx/PTestHandle.ipdl +++ /dev/null @@ -1,17 +0,0 @@ -include protocol PTestJSON; - -include "mozilla/_ipdltest/TestJSON.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestHandleChild", ParentImpl="TestHandleParent"] -protocol PTestHandle { - manager PTestJSON; - -child: - async __delete__(); -}; - -} // namespace mozilla -} // namespace _ipdltest diff --git a/ipc/ipdl/test/cxx/PTestHangs.ipdl b/ipc/ipdl/test/cxx/PTestHangs.ipdl deleted file mode 100644 index cadc1eda2e..0000000000 --- a/ipc/ipdl/test/cxx/PTestHangs.ipdl +++ /dev/null @@ -1,22 +0,0 @@ - -include "mozilla/_ipdltest/TestHangs.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestHangsChild", ParentImpl="TestHangsParent"] -intr protocol PTestHangs { -both: - [LegacyIntr] intr StackFrame(); - -parent: - async Nonce(); - -child: - async Start(); - [LegacyIntr] intr Hang(); - async __delete__(); -}; - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/PTestHighestPrio.ipdl b/ipc/ipdl/test/cxx/PTestHighestPrio.ipdl deleted file mode 100644 index 877ba427b6..0000000000 --- a/ipc/ipdl/test/cxx/PTestHighestPrio.ipdl +++ /dev/null @@ -1,21 +0,0 @@ -include "mozilla/_ipdltest/TestHighestPrio.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, NestedUpTo=inside_cpow, ChildImpl="TestHighestPrioChild", ParentImpl="TestHighestPrioParent"] -sync protocol PTestHighestPrio -{ -parent: - [Nested=inside_cpow] async Msg1(); - [Nested=inside_sync] sync Msg2(); - [Nested=inside_cpow] async Msg3(); - [Nested=inside_cpow] sync Msg4(); - -child: - async Start(); - [Nested=inside_sync] sync StartInner(); -}; - -} -} diff --git a/ipc/ipdl/test/cxx/PTestInterruptErrorCleanup.ipdl b/ipc/ipdl/test/cxx/PTestInterruptErrorCleanup.ipdl deleted file mode 100644 index ab6754cc1b..0000000000 --- a/ipc/ipdl/test/cxx/PTestInterruptErrorCleanup.ipdl +++ /dev/null @@ -1,14 +0,0 @@ -include "mozilla/_ipdltest/TestInterruptErrorCleanup.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestInterruptErrorCleanupChild", ParentImpl="TestInterruptErrorCleanupParent"] -intr protocol PTestInterruptErrorCleanup { -child: - [LegacyIntr] intr Error(); - [LegacyIntr] intr __delete__(); -}; - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/PTestInterruptRaces.ipdl b/ipc/ipdl/test/cxx/PTestInterruptRaces.ipdl deleted file mode 100644 index aa66966938..0000000000 --- a/ipc/ipdl/test/cxx/PTestInterruptRaces.ipdl +++ /dev/null @@ -1,27 +0,0 @@ -include "mozilla/_ipdltest/TestInterruptRaces.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestInterruptRacesChild", ParentImpl="TestInterruptRacesParent"] -intr protocol PTestInterruptRaces { -both: - [LegacyIntr] intr Race() returns (bool hasReply); - [LegacyIntr] intr StackFrame() returns (); - [LegacyIntr] intr StackFrame3() returns (); - -parent: - sync StartRace(); - [LegacyIntr] intr Parent(); - sync GetAnsweredParent() returns (bool answeredParent); - -child: - async Start(); - async Wakeup(); - async Wakeup3(); - [LegacyIntr] intr Child(); - async __delete__(); -}; - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/PTestInterruptShutdownRace.ipdl b/ipc/ipdl/test/cxx/PTestInterruptShutdownRace.ipdl deleted file mode 100644 index 84bc6f0a97..0000000000 --- a/ipc/ipdl/test/cxx/PTestInterruptShutdownRace.ipdl +++ /dev/null @@ -1,19 +0,0 @@ -include "mozilla/_ipdltest/TestInterruptShutdownRace.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestInterruptShutdownRaceChild", ParentImpl="TestInterruptShutdownRaceParent"] -intr protocol PTestInterruptShutdownRace { -parent: - sync StartDeath(); - async Orphan(); - -child: - async Start(); - [LegacyIntr] intr Exit(); - async __delete__(); -}; - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/PTestJSON.ipdl b/ipc/ipdl/test/cxx/PTestJSON.ipdl deleted file mode 100644 index c785abe77a..0000000000 --- a/ipc/ipdl/test/cxx/PTestJSON.ipdl +++ /dev/null @@ -1,49 +0,0 @@ -include protocol PTestHandle; - -include "mozilla/_ipdltest/TestJSON.h"; - -using struct mozilla::void_t from "mozilla/ipc/IPCCore.h"; -using struct mozilla::null_t from "mozilla/ipc/IPCCore.h"; - -namespace mozilla { -namespace _ipdltest { - -union Key { -// int; -// double; - nsString; -}; - -struct KeyValue { - Key key; - JSONVariant value; -}; - -union JSONVariant { - void_t; - null_t; - bool; - int; - double; - nsString; - PTestHandle; - KeyValue[]; - JSONVariant[]; -}; - -[ManualDealloc, ChildImpl="TestJSONChild", ParentImpl="TestJSONParent"] -sync protocol PTestJSON { - manages PTestHandle; - -child: - async Start(); - -parent: - async PTestHandle(); - sync Test(JSONVariant i) - returns (JSONVariant o); - async __delete__(); -}; - -} // namespace mozilla -} // namespace _ipdltest diff --git a/ipc/ipdl/test/cxx/PTestLatency.ipdl b/ipc/ipdl/test/cxx/PTestLatency.ipdl deleted file mode 100644 index d868d119a2..0000000000 --- a/ipc/ipdl/test/cxx/PTestLatency.ipdl +++ /dev/null @@ -1,28 +0,0 @@ -include "mozilla/_ipdltest/TestLatency.h"; - -namespace mozilla { -namespace _ipdltest { - - -[ManualDealloc, ChildImpl="TestLatencyChild", ParentImpl="TestLatencyParent"] -intr protocol PTestLatency { - -child: - async __delete__(); - async Ping(); - async Ping5(); - [LegacyIntr] intr Rpc(); - async Spam(); - [LegacyIntr] intr Synchro(); - [Compress] async CompressedSpam(uint32_t seqno); - [LegacyIntr] intr Synchro2() returns (uint32_t lastSeqno, - uint32_t numMessagesDispatched); - -parent: - async Pong(); - async Pong5(); -}; - - -} // namespace mozilla -} // namespace _ipdltest diff --git a/ipc/ipdl/test/cxx/PTestManyChildAllocs.ipdl b/ipc/ipdl/test/cxx/PTestManyChildAllocs.ipdl deleted file mode 100644 index 6f8a0e1187..0000000000 --- a/ipc/ipdl/test/cxx/PTestManyChildAllocs.ipdl +++ /dev/null @@ -1,22 +0,0 @@ -include protocol PTestManyChildAllocsSub; - -include "mozilla/_ipdltest/TestManyChildAllocs.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestManyChildAllocsChild", ParentImpl="TestManyChildAllocsParent"] -protocol PTestManyChildAllocs { - manages PTestManyChildAllocsSub; - -child: - async Go(); // start allocating - -parent: - async Done(); - - async PTestManyChildAllocsSub(); -}; - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/PTestManyChildAllocsSub.ipdl b/ipc/ipdl/test/cxx/PTestManyChildAllocsSub.ipdl deleted file mode 100644 index e20c2badfd..0000000000 --- a/ipc/ipdl/test/cxx/PTestManyChildAllocsSub.ipdl +++ /dev/null @@ -1,22 +0,0 @@ -include protocol PTestManyChildAllocs; - -include "mozilla/_ipdltest/TestManyChildAllocs.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestManyChildAllocsSubChild", ParentImpl="TestManyChildAllocsSubParent"] -protocol PTestManyChildAllocsSub { - manager PTestManyChildAllocs; - -child: - async __delete__(); - -parent: - async Hello(); - - // empty -}; - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/PTestMultiMgrs.ipdl b/ipc/ipdl/test/cxx/PTestMultiMgrs.ipdl deleted file mode 100644 index 65272fa991..0000000000 --- a/ipc/ipdl/test/cxx/PTestMultiMgrs.ipdl +++ /dev/null @@ -1,25 +0,0 @@ -include protocol PTestMultiMgrsLeft; -include protocol PTestMultiMgrsRight; - -include "mozilla/_ipdltest/TestMultiMgrs.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestMultiMgrsChild", ParentImpl="TestMultiMgrsParent"] -protocol PTestMultiMgrs { - manages PTestMultiMgrsLeft; - manages PTestMultiMgrsRight; - -parent: - async OK(); - -child: - async PTestMultiMgrsLeft(); - async PTestMultiMgrsRight(); - async Check(); - async __delete__(); -}; - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/PTestMultiMgrsBottom.ipdl b/ipc/ipdl/test/cxx/PTestMultiMgrsBottom.ipdl deleted file mode 100644 index be85b1547b..0000000000 --- a/ipc/ipdl/test/cxx/PTestMultiMgrsBottom.ipdl +++ /dev/null @@ -1,18 +0,0 @@ -include protocol PTestMultiMgrsLeft; -include protocol PTestMultiMgrsRight; - -include "mozilla/_ipdltest/TestMultiMgrs.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestMultiMgrsBottomChild", ParentImpl="TestMultiMgrsBottomParent"] -protocol PTestMultiMgrsBottom { - manager PTestMultiMgrsLeft or PTestMultiMgrsRight; - -child: - async __delete__(); -}; - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/PTestMultiMgrsLeft.ipdl b/ipc/ipdl/test/cxx/PTestMultiMgrsLeft.ipdl deleted file mode 100644 index 3796ff315e..0000000000 --- a/ipc/ipdl/test/cxx/PTestMultiMgrsLeft.ipdl +++ /dev/null @@ -1,21 +0,0 @@ -include protocol PTestMultiMgrs; -include protocol PTestMultiMgrsBottom; - -include "mozilla/_ipdltest/TestMultiMgrs.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestMultiMgrsLeftChild", ParentImpl="TestMultiMgrsLeftParent"] -protocol PTestMultiMgrsLeft { - manager PTestMultiMgrs; - - manages PTestMultiMgrsBottom; - -child: - async PTestMultiMgrsBottom(); - async __delete__(); -}; - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/PTestMultiMgrsRight.ipdl b/ipc/ipdl/test/cxx/PTestMultiMgrsRight.ipdl deleted file mode 100644 index 174ada5ca3..0000000000 --- a/ipc/ipdl/test/cxx/PTestMultiMgrsRight.ipdl +++ /dev/null @@ -1,21 +0,0 @@ -include protocol PTestMultiMgrs; -include protocol PTestMultiMgrsBottom; - -include "mozilla/_ipdltest/TestMultiMgrs.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestMultiMgrsRightChild", ParentImpl="TestMultiMgrsRightParent"] -protocol PTestMultiMgrsRight { - manager PTestMultiMgrs; - - manages PTestMultiMgrsBottom; - -child: - async PTestMultiMgrsBottom(); - async __delete__(); -}; - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/PTestNestedLoops.ipdl b/ipc/ipdl/test/cxx/PTestNestedLoops.ipdl deleted file mode 100644 index 168461ab41..0000000000 --- a/ipc/ipdl/test/cxx/PTestNestedLoops.ipdl +++ /dev/null @@ -1,22 +0,0 @@ - -include "mozilla/_ipdltest/TestNestedLoops.h"; - -namespace mozilla { -namespace _ipdltest { - - -[ManualDealloc, ChildImpl="TestNestedLoopsChild", ParentImpl="TestNestedLoopsParent"] -intr protocol PTestNestedLoops { - -child: - async Start(); - [LegacyIntr] intr R(); - async __delete__(); - -parent: - async Nonce(); -}; - - -} // namespace mozilla -} // namespace _ipdltest diff --git a/ipc/ipdl/test/cxx/PTestRPC.ipdl b/ipc/ipdl/test/cxx/PTestRPC.ipdl deleted file mode 100644 index 4d459eeb03..0000000000 --- a/ipc/ipdl/test/cxx/PTestRPC.ipdl +++ /dev/null @@ -1,24 +0,0 @@ -include "mozilla/_ipdltest/TestRPC.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, NestedUpTo=inside_sync, ChildImpl="TestRPCChild", ParentImpl="TestRPCParent"] -sync protocol PTestRPC -{ -parent: - [Nested=inside_sync] sync Test1_Start() returns (uint32_t result); - [Nested=inside_sync] sync Test1_InnerEvent() returns (uint32_t result); - async Test2_Start(); - [Nested=inside_sync] sync Test2_OutOfOrder(); - -child: - async Start(); - [Nested=inside_sync] sync Test1_InnerQuery() returns (uint32_t result); - [Nested=inside_sync] sync Test1_NoReenter() returns (uint32_t result); - [Nested=inside_sync] sync Test2_FirstUrgent(); - [Nested=inside_sync] sync Test2_SecondUrgent(); -}; - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/PTestRaceDeadlock.ipdl b/ipc/ipdl/test/cxx/PTestRaceDeadlock.ipdl deleted file mode 100644 index 125919f9af..0000000000 --- a/ipc/ipdl/test/cxx/PTestRaceDeadlock.ipdl +++ /dev/null @@ -1,23 +0,0 @@ -include "mozilla/_ipdltest/TestRaceDeadlock.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestRaceDeadlockChild", ParentImpl="TestRaceDeadlockParent"] -intr protocol PTestRaceDeadlock { -both: - async StartRace(); - -parent: - [LegacyIntr] intr Lose(); - -child: - [LegacyIntr] intr Win(); - [LegacyIntr] intr Rpc(); - async __delete__(); - -/* Tests that race resolution does not cause deadlocks */ -}; - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/PTestRaceDeferral.ipdl b/ipc/ipdl/test/cxx/PTestRaceDeferral.ipdl deleted file mode 100644 index f165fa1cea..0000000000 --- a/ipc/ipdl/test/cxx/PTestRaceDeferral.ipdl +++ /dev/null @@ -1,22 +0,0 @@ -include "mozilla/_ipdltest/TestRaceDeferral.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestRaceDeferralChild", ParentImpl="TestRaceDeferralParent"] -intr protocol PTestRaceDeferral { -parent: - [LegacyIntr] intr Lose(); - -child: - async StartRace(); - [LegacyIntr] intr Win(); - [LegacyIntr] intr Rpc(); - async __delete__(); - -// Test that messages deferred due to race resolution are -// re-considered when the winner makes later RPCs -}; - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/PTestRacyInterruptReplies.ipdl b/ipc/ipdl/test/cxx/PTestRacyInterruptReplies.ipdl deleted file mode 100644 index 37b7973e6d..0000000000 --- a/ipc/ipdl/test/cxx/PTestRacyInterruptReplies.ipdl +++ /dev/null @@ -1,20 +0,0 @@ -include "mozilla/_ipdltest/TestRacyInterruptReplies.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestRacyInterruptRepliesChild", ParentImpl="TestRacyInterruptRepliesParent"] -intr protocol PTestRacyInterruptReplies { -child: - [LegacyIntr] intr R_() returns (int replyNum); - async _A(); - async ChildTest(); - async __delete__(); - -parent: - [LegacyIntr] intr _R() returns (int replyNum); - async A_(); -}; - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/PTestRacyReentry.ipdl b/ipc/ipdl/test/cxx/PTestRacyReentry.ipdl deleted file mode 100644 index b9579cef24..0000000000 --- a/ipc/ipdl/test/cxx/PTestRacyReentry.ipdl +++ /dev/null @@ -1,23 +0,0 @@ -include "mozilla/_ipdltest/TestRacyReentry.h"; - -namespace mozilla { -namespace _ipdltest { - - -[ManualDealloc, ChildImpl="TestRacyReentryChild", ParentImpl="TestRacyReentryParent"] -intr protocol PTestRacyReentry { - -parent: - [LegacyIntr] intr E(); - async __delete__(); - -child: - async Start(); - - async N(); - [LegacyIntr] intr H(); -}; - - -} // namespace mozilla -} // namespace _ipdltest diff --git a/ipc/ipdl/test/cxx/PTestRacyUndefer.ipdl b/ipc/ipdl/test/cxx/PTestRacyUndefer.ipdl deleted file mode 100644 index 6256eca9db..0000000000 --- a/ipc/ipdl/test/cxx/PTestRacyUndefer.ipdl +++ /dev/null @@ -1,30 +0,0 @@ -include "mozilla/_ipdltest/TestRacyUndefer.h"; - -namespace mozilla { -namespace _ipdltest { - - -[ManualDealloc, ChildImpl="TestRacyUndeferChild", ParentImpl="TestRacyUndeferParent"] -intr protocol PTestRacyUndefer { - -child: - async Start(); - - async AwakenSpam(); - async AwakenRaceWinTwice(); - - [LegacyIntr] intr Race(); - - async __delete__(); - -parent: - - [LegacyIntr] intr Spam(); - [LegacyIntr] intr RaceWinTwice(); - - async Done(); -}; - - -} // namespace mozilla -} // namespace _ipdltest diff --git a/ipc/ipdl/test/cxx/PTestSanity.ipdl b/ipc/ipdl/test/cxx/PTestSanity.ipdl deleted file mode 100644 index 3b3e130d4a..0000000000 --- a/ipc/ipdl/test/cxx/PTestSanity.ipdl +++ /dev/null @@ -1,21 +0,0 @@ - -include "mozilla/_ipdltest/TestSanity.h"; - -namespace mozilla { -namespace _ipdltest { - - -[ManualDealloc, ChildImpl="TestSanityChild", ParentImpl="TestSanityParent"] -protocol PTestSanity { - -child: - async Ping(int zero, float zeroPtFive, int8_t dummy); - async __delete__(); - -parent: - async Pong(int one, float zeroPtTwoFive, uint8_t dummy); -}; - - -} // namespace mozilla -} // namespace _ipdltest diff --git a/ipc/ipdl/test/cxx/PTestSelfManage.ipdl b/ipc/ipdl/test/cxx/PTestSelfManage.ipdl deleted file mode 100644 index 19f81a5ae7..0000000000 --- a/ipc/ipdl/test/cxx/PTestSelfManage.ipdl +++ /dev/null @@ -1,21 +0,0 @@ -include protocol PTestSelfManageRoot; - -include "mozilla/_ipdltest/TestSelfManageRoot.h"; - -namespace mozilla { -namespace _ipdltest { - - -[ManualDealloc, ChildImpl="TestSelfManageChild", ParentImpl="TestSelfManageParent"] -protocol PTestSelfManage { - manager PTestSelfManageRoot or PTestSelfManage; - manages PTestSelfManage; - -child: - async PTestSelfManage(); - async __delete__(); -}; - - -} // namespace mozilla -} // namespace _ipdltest diff --git a/ipc/ipdl/test/cxx/PTestSelfManageRoot.ipdl b/ipc/ipdl/test/cxx/PTestSelfManageRoot.ipdl deleted file mode 100644 index 29953228af..0000000000 --- a/ipc/ipdl/test/cxx/PTestSelfManageRoot.ipdl +++ /dev/null @@ -1,20 +0,0 @@ -include protocol PTestSelfManage; - -include "mozilla/_ipdltest/TestSelfManageRoot.h"; - -namespace mozilla { -namespace _ipdltest { - - -[ManualDealloc, ChildImpl="TestSelfManageRootChild", ParentImpl="TestSelfManageRootParent"] -protocol PTestSelfManageRoot { - manages PTestSelfManage; - -child: - async PTestSelfManage(); - async __delete__(); -}; - - -} // namespace mozilla -} // namespace _ipdltest diff --git a/ipc/ipdl/test/cxx/PTestShmem.ipdl b/ipc/ipdl/test/cxx/PTestShmem.ipdl deleted file mode 100644 index 7eb6dfdc36..0000000000 --- a/ipc/ipdl/test/cxx/PTestShmem.ipdl +++ /dev/null @@ -1,17 +0,0 @@ -include "mozilla/_ipdltest/TestShmem.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestShmemChild", ParentImpl="TestShmemParent"] -protocol PTestShmem { -child: - async Give(Shmem mem, Shmem unsafe, uint32_t expectedSize); - -parent: - async Take(Shmem mem, Shmem unsafe, uint32_t expectedSize); - async __delete__(); -}; - -} -} diff --git a/ipc/ipdl/test/cxx/PTestShutdown.ipdl b/ipc/ipdl/test/cxx/PTestShutdown.ipdl deleted file mode 100644 index e57defa46a..0000000000 --- a/ipc/ipdl/test/cxx/PTestShutdown.ipdl +++ /dev/null @@ -1,29 +0,0 @@ -include protocol PTestShutdownSub; - -include "mozilla/_ipdltest/TestShutdown.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestShutdownChild", ParentImpl="TestShutdownParent"] -intr protocol PTestShutdown { - manages PTestShutdownSub; - -child: - async Start(); - -parent: - // NB: we test deletion and crashing only, not shutdown, because - // crashing is the same code path as shutdown, and other IPDL unit - // tests check shutdown semantics - async PTestShutdownSub(bool expectCrash); - - // Used to synchronize between parent and child, to avoid races - // around flushing socket write queues - sync Sync(); - - async __delete__(); -}; - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/PTestShutdownSub.ipdl b/ipc/ipdl/test/cxx/PTestShutdownSub.ipdl deleted file mode 100644 index e91caca740..0000000000 --- a/ipc/ipdl/test/cxx/PTestShutdownSub.ipdl +++ /dev/null @@ -1,23 +0,0 @@ -include protocol PTestShutdown; -include protocol PTestShutdownSubsub; - -include "mozilla/_ipdltest/TestShutdown.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestShutdownSubChild", ParentImpl="TestShutdownSubParent"] -intr protocol PTestShutdownSub { - manager PTestShutdown; - manages PTestShutdownSubsub; - -both: - [LegacyIntr] intr StackFrame(); - -parent: - async PTestShutdownSubsub(bool expectParentDeleted); - sync __delete__(); -}; - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/PTestShutdownSubsub.ipdl b/ipc/ipdl/test/cxx/PTestShutdownSubsub.ipdl deleted file mode 100644 index 3b1cc5cb6b..0000000000 --- a/ipc/ipdl/test/cxx/PTestShutdownSubsub.ipdl +++ /dev/null @@ -1,17 +0,0 @@ -include protocol PTestShutdownSub; - -include "mozilla/_ipdltest/TestShutdown.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestShutdownSubsubChild", ParentImpl="TestShutdownSubsubParent"] -sync protocol PTestShutdownSubsub { - manager PTestShutdownSub; - -parent: - sync __delete__(); -}; - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/PTestStackHooks.ipdl b/ipc/ipdl/test/cxx/PTestStackHooks.ipdl deleted file mode 100644 index 3026dfbfbe..0000000000 --- a/ipc/ipdl/test/cxx/PTestStackHooks.ipdl +++ /dev/null @@ -1,28 +0,0 @@ -include "mozilla/_ipdltest/TestStackHooks.h"; - -namespace mozilla { -namespace _ipdltest { - - -[ManualDealloc, ChildImpl="TestStackHooksChild", ParentImpl="TestStackHooksParent"] -intr protocol PTestStackHooks { -child: - async Start(); - - // These tests are more fruitful running child->parent, because - // children can send |sync| messages -parent: - async Async(); - sync Sync(); - [LegacyIntr] intr Rpc(); - -both: - [LegacyIntr] intr StackFrame(); - -parent: - async __delete__(); -}; - - -} // namespace mozilla -} // namespace _ipdltest diff --git a/ipc/ipdl/test/cxx/PTestSyncError.ipdl b/ipc/ipdl/test/cxx/PTestSyncError.ipdl deleted file mode 100644 index a4b6d428e8..0000000000 --- a/ipc/ipdl/test/cxx/PTestSyncError.ipdl +++ /dev/null @@ -1,20 +0,0 @@ -include "mozilla/_ipdltest/TestSyncError.h"; - -namespace mozilla { -namespace _ipdltest { - - -[ManualDealloc, ChildImpl="TestSyncErrorChild", ParentImpl="TestSyncErrorParent"] -sync protocol PTestSyncError { - -child: - async Start(); - -parent: - sync Error(); - async __delete__(); -}; - - -} // namespace mozilla -} // namespace _ipdltest diff --git a/ipc/ipdl/test/cxx/PTestSyncHang.ipdl b/ipc/ipdl/test/cxx/PTestSyncHang.ipdl deleted file mode 100644 index 05521d6ed2..0000000000 --- a/ipc/ipdl/test/cxx/PTestSyncHang.ipdl +++ /dev/null @@ -1,16 +0,0 @@ -include "mozilla/_ipdltest/TestSyncHang.h"; - -namespace mozilla { -namespace _ipdltest { - - -[ManualDealloc, ChildImpl="TestSyncHangChild", ParentImpl="TestSyncHangParent"] -protocol PTestSyncHang { - -child: - async UnusedMessage(); -}; - - -} // namespace mozilla -} // namespace _ipdltest diff --git a/ipc/ipdl/test/cxx/PTestSyncWakeup.ipdl b/ipc/ipdl/test/cxx/PTestSyncWakeup.ipdl deleted file mode 100644 index 807f558dfa..0000000000 --- a/ipc/ipdl/test/cxx/PTestSyncWakeup.ipdl +++ /dev/null @@ -1,23 +0,0 @@ -include "mozilla/_ipdltest/TestSyncWakeup.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, ChildImpl="TestSyncWakeupChild", ParentImpl="TestSyncWakeupParent"] -intr protocol PTestSyncWakeup { -both: - [LegacyIntr] intr StackFrame(); - -child: - async Start(); - async Note1(); - async Note2(); - -parent: - sync Sync1(); - sync Sync2(); - async __delete__(); -}; - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/PTestUniquePtrIPC.ipdl b/ipc/ipdl/test/cxx/PTestUniquePtrIPC.ipdl deleted file mode 100644 index b436dcbbb3..0000000000 --- a/ipc/ipdl/test/cxx/PTestUniquePtrIPC.ipdl +++ /dev/null @@ -1,26 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -include "mozilla/_ipdltest/TestUniquePtrIPC.h"; - -namespace mozilla { -namespace _ipdltest { - -struct DummyStruct { - int x; -}; - -[ManualDealloc, ChildImpl="TestUniquePtrIPCChild", ParentImpl="TestUniquePtrIPCParent"] -protocol PTestUniquePtrIPC -{ -child: - async TestMessage(UniquePtr a1, UniquePtr a2, - DummyStruct a3, UniquePtr a4); - async TestSendReference(UniquePtr a); -}; - -} -} diff --git a/ipc/ipdl/test/cxx/PTestUrgency.ipdl b/ipc/ipdl/test/cxx/PTestUrgency.ipdl deleted file mode 100644 index 7653d12102..0000000000 --- a/ipc/ipdl/test/cxx/PTestUrgency.ipdl +++ /dev/null @@ -1,22 +0,0 @@ -include "mozilla/_ipdltest/TestUrgency.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, NestedUpTo=inside_cpow, ChildImpl="TestUrgencyChild", ParentImpl="TestUrgencyParent"] -sync protocol PTestUrgency -{ -parent: - [Nested=inside_sync] sync Test1() returns (uint32_t result); - async Test2(); - sync Test3() returns (uint32_t result); - sync FinalTest_Begin(); - -child: - async Start(); - [Nested=inside_sync] sync Reply1() returns (uint32_t result); - [Nested=inside_sync] sync Reply2() returns (uint32_t result); -}; - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/PTestUrgentHangs.ipdl b/ipc/ipdl/test/cxx/PTestUrgentHangs.ipdl deleted file mode 100644 index 2c19a7afe1..0000000000 --- a/ipc/ipdl/test/cxx/PTestUrgentHangs.ipdl +++ /dev/null @@ -1,31 +0,0 @@ -include "mozilla/_ipdltest/TestUrgentHangs.h"; - -namespace mozilla { -namespace _ipdltest { - -[ManualDealloc, NestedUpTo=inside_sync, ChildImpl="TestUrgentHangsChild", ParentImpl="TestUrgentHangsParent"] -sync protocol PTestUrgentHangs -{ -parent: - [Nested=inside_sync] sync Test1_2(); - - [Nested=inside_sync] sync TestInner(); - [Nested=inside_cpow] sync TestInnerUrgent(); - -child: - [Nested=inside_sync] sync Test1_1(); - [Nested=inside_sync] sync Test1_3(); - - [Nested=inside_sync] sync Test2(); - - [Nested=inside_sync] sync Test3(); - - async Test4(); - [Nested=inside_sync] sync Test4_1(); - - async Test5(); - [Nested=inside_sync] sync Test5_1(); -}; - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestActorPunning.cpp b/ipc/ipdl/test/cxx/TestActorPunning.cpp deleted file mode 100644 index 5825796f54..0000000000 --- a/ipc/ipdl/test/cxx/TestActorPunning.cpp +++ /dev/null @@ -1,125 +0,0 @@ -#include "TestActorPunning.h" - -#include "IPDLUnitTests.h" // fail etc. -#include "mozilla/Unused.h" - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// parent - -void TestActorPunningParent::Main() { - if (!SendStart()) fail("sending Start"); -} - -mozilla::ipc::IPCResult TestActorPunningParent::RecvPun( - PTestActorPunningSubParent* a, const Bad& bad) { - if (a->SendBad()) fail("bad!"); - fail("shouldn't have received this message in the first place"); - return IPC_OK(); -} - -// By default, fatal errors kill the parent process, but this makes it -// hard to test, so instead we use the previous behavior and kill the -// child process. -void TestActorPunningParent::HandleFatalError(const char* aErrorMsg) { - if (!!strcmp(aErrorMsg, "Error deserializing 'PTestActorPunningSubParent'")) { - fail("wrong fatal error"); - } - - ipc::ScopedProcessHandle otherProcessHandle; - if (!base::OpenProcessHandle(OtherPid(), &otherProcessHandle.rwget())) { - fail("couldn't open child process"); - } else { - if (!base::KillProcess(otherProcessHandle, 0, false)) { - fail("terminating child process"); - } - } -} - -PTestActorPunningPunnedParent* -TestActorPunningParent::AllocPTestActorPunningPunnedParent() { - return new TestActorPunningPunnedParent(); -} - -bool TestActorPunningParent::DeallocPTestActorPunningPunnedParent( - PTestActorPunningPunnedParent* a) { - delete a; - return true; -} - -PTestActorPunningSubParent* -TestActorPunningParent::AllocPTestActorPunningSubParent() { - return new TestActorPunningSubParent(); -} - -bool TestActorPunningParent::DeallocPTestActorPunningSubParent( - PTestActorPunningSubParent* a) { - delete a; - return true; -} - -//----------------------------------------------------------------------------- -// child - -PTestActorPunningPunnedChild* -TestActorPunningChild::AllocPTestActorPunningPunnedChild() { - return new TestActorPunningPunnedChild(); -} - -bool TestActorPunningChild::DeallocPTestActorPunningPunnedChild( - PTestActorPunningPunnedChild*) { - fail("should have died by now"); - return true; -} - -PTestActorPunningSubChild* -TestActorPunningChild::AllocPTestActorPunningSubChild() { - return new TestActorPunningSubChild(); -} - -bool TestActorPunningChild::DeallocPTestActorPunningSubChild( - PTestActorPunningSubChild*) { - fail("should have died by now"); - return true; -} - -mozilla::ipc::IPCResult TestActorPunningChild::RecvStart() { - SendPTestActorPunningSubConstructor(); - SendPTestActorPunningPunnedConstructor(); - PTestActorPunningSubChild* a = SendPTestActorPunningSubConstructor(); - // We can't assert whether this succeeds or fails, due to race - // conditions. - SendPun(a, Bad()); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestActorPunningSubChild::RecvBad() { - fail("things are going really badly right now"); - return IPC_OK(); -} - -} // namespace _ipdltest -} // namespace mozilla - -namespace IPC { -using namespace mozilla::_ipdltest; -using namespace mozilla::ipc; - -/*static*/ void ParamTraits::Write(MessageWriter* aWriter, - const paramType& aParam) { - // Skip past the sentinel for the actor as well as the actor. - int32_t* ptr = aWriter->GetInt32PtrForTest(2 * sizeof(int32_t)); - ActorHandle* ah = reinterpret_cast(ptr); - if (ah->mId != -3) - fail("guessed wrong offset (value is %d, should be -3)", ah->mId); - ah->mId = -2; -} - -/*static*/ bool ParamTraits::Read(MessageReader* aReader, - paramType* aResult) { - return true; -} - -} // namespace IPC diff --git a/ipc/ipdl/test/cxx/TestActorPunning.h b/ipc/ipdl/test/cxx/TestActorPunning.h deleted file mode 100644 index cd88106c0c..0000000000 --- a/ipc/ipdl/test/cxx/TestActorPunning.h +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef mozilla__ipdltest_TestActorPunning_h -#define mozilla__ipdltest_TestActorPunning_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestActorPunningParent.h" -#include "mozilla/_ipdltest/PTestActorPunningPunnedParent.h" -#include "mozilla/_ipdltest/PTestActorPunningSubParent.h" -#include "mozilla/_ipdltest/PTestActorPunningChild.h" -#include "mozilla/_ipdltest/PTestActorPunningPunnedChild.h" -#include "mozilla/_ipdltest/PTestActorPunningSubChild.h" - -namespace mozilla { -namespace _ipdltest { - -class TestActorPunningParent : public PTestActorPunningParent { - friend class PTestActorPunningParent; - - public: - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return false; } - - void Main(); - - protected: - PTestActorPunningPunnedParent* AllocPTestActorPunningPunnedParent(); - bool DeallocPTestActorPunningPunnedParent(PTestActorPunningPunnedParent* a); - - PTestActorPunningSubParent* AllocPTestActorPunningSubParent(); - bool DeallocPTestActorPunningSubParent(PTestActorPunningSubParent* a); - - mozilla::ipc::IPCResult RecvPun(PTestActorPunningSubParent* a, - const Bad& bad); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown == why) fail("should have died from error!"); - passed("ok"); - QuitParent(); - } - - virtual void HandleFatalError(const char* aErrorMsg) override; -}; - -class TestActorPunningPunnedParent : public PTestActorPunningPunnedParent { - public: - TestActorPunningPunnedParent() {} - virtual ~TestActorPunningPunnedParent() {} - - protected: - virtual void ActorDestroy(ActorDestroyReason why) override {} -}; - -class TestActorPunningSubParent : public PTestActorPunningSubParent { - public: - TestActorPunningSubParent() {} - virtual ~TestActorPunningSubParent() {} - - protected: - virtual void ActorDestroy(ActorDestroyReason why) override {} -}; - -class TestActorPunningChild : public PTestActorPunningChild { - friend class PTestActorPunningChild; - - public: - TestActorPunningChild() {} - virtual ~TestActorPunningChild() {} - - protected: - PTestActorPunningPunnedChild* AllocPTestActorPunningPunnedChild(); - bool DeallocPTestActorPunningPunnedChild(PTestActorPunningPunnedChild* a); - - PTestActorPunningSubChild* AllocPTestActorPunningSubChild(); - bool DeallocPTestActorPunningSubChild(PTestActorPunningSubChild* a); - - mozilla::ipc::IPCResult RecvStart(); - - virtual void ActorDestroy(ActorDestroyReason why) override { - fail("should have been killed off!"); - } -}; - -class TestActorPunningPunnedChild : public PTestActorPunningPunnedChild { - public: - TestActorPunningPunnedChild() {} - virtual ~TestActorPunningPunnedChild() {} -}; - -class TestActorPunningSubChild : public PTestActorPunningSubChild { - public: - TestActorPunningSubChild() {} - virtual ~TestActorPunningSubChild() {} - - mozilla::ipc::IPCResult RecvBad(); -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestActorPunning_h diff --git a/ipc/ipdl/test/cxx/TestAsyncReturns.cpp b/ipc/ipdl/test/cxx/TestAsyncReturns.cpp deleted file mode 100644 index 76597143c0..0000000000 --- a/ipc/ipdl/test/cxx/TestAsyncReturns.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#include "TestAsyncReturns.h" - -#include "IPDLUnitTests.h" // fail etc. - -#include "mozilla/AbstractThread.h" -#include "mozilla/Unused.h" - -namespace mozilla { -namespace _ipdltest { - -static uint32_t sMagic1 = 0x105b59fb; -static uint32_t sMagic2 = 0x09b6f5e3; - -//----------------------------------------------------------------------------- -// parent - -TestAsyncReturnsParent::TestAsyncReturnsParent() { - MOZ_COUNT_CTOR(TestAsyncReturnsParent); -} - -TestAsyncReturnsParent::~TestAsyncReturnsParent() { - MOZ_COUNT_DTOR(TestAsyncReturnsParent); -} - -void TestAsyncReturnsParent::Main() { - SendNoReturn()->Then( - MessageLoop::current()->SerialEventTarget(), __func__, - [](bool unused) { fail("resolve handler should not be called"); }, - [](ResponseRejectReason&& aReason) { - // MozPromise asserts in debug build if the - // handler is not called - if (aReason != ResponseRejectReason::ChannelClosed) { - fail("reject with wrong reason"); - } - passed("reject handler called on channel close"); - }); - SendPing()->Then( - MessageLoop::current()->SerialEventTarget(), __func__, - [this](bool one) { - if (one) { - passed("take one argument"); - } else { - fail("get one argument but has wrong value"); - } - - // Also try with the callback-based API. - SendPing( - [this](bool one) { - if (one) { - passed("take one argument"); - } else { - fail("get one argument but has wrong value"); - } - Close(); - }, - [](ResponseRejectReason&& aReason) { fail("sending Ping"); }); - }, - [](ResponseRejectReason&& aReason) { fail("sending Ping"); }); -} - -mozilla::ipc::IPCResult TestAsyncReturnsParent::RecvPong( - PongResolver&& aResolve) { - aResolve(std::tuple(sMagic1, sMagic2)); - return IPC_OK(); -} - -//----------------------------------------------------------------------------- -// child - -TestAsyncReturnsChild::TestAsyncReturnsChild() { - MOZ_COUNT_CTOR(TestAsyncReturnsChild); -} - -TestAsyncReturnsChild::~TestAsyncReturnsChild() { - MOZ_COUNT_DTOR(TestAsyncReturnsChild); -} - -mozilla::ipc::IPCResult TestAsyncReturnsChild::RecvNoReturn( - NoReturnResolver&& aResolve) { - // Not resolving the promise intentionally - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestAsyncReturnsChild::RecvPing( - PingResolver&& aResolve) { - SendPong()->Then( - MessageLoop::current()->SerialEventTarget(), __func__, - [aResolve](const std::tuple& aParam) { - if (std::get<0>(aParam) == sMagic1 && std::get<1>(aParam) == sMagic2) { - passed("take two arguments"); - } else { - fail("get two argument but has wrong value"); - } - aResolve(true); - }, - [](ResponseRejectReason&& aReason) { fail("sending Pong"); }); - return IPC_OK(); -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestAsyncReturns.h b/ipc/ipdl/test/cxx/TestAsyncReturns.h deleted file mode 100644 index 5dad3da0ab..0000000000 --- a/ipc/ipdl/test/cxx/TestAsyncReturns.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef mozilla__ipdltest_TestAsyncReturns_h -#define mozilla__ipdltest_TestAsyncReturns_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestAsyncReturnsParent.h" -#include "mozilla/_ipdltest/PTestAsyncReturnsChild.h" - -namespace mozilla { -namespace _ipdltest { - -class TestAsyncReturnsParent : public PTestAsyncReturnsParent { - friend class PTestAsyncReturnsParent; - - public: - TestAsyncReturnsParent(); - virtual ~TestAsyncReturnsParent(); - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return true; } - - void Main(); - - protected: - mozilla::ipc::IPCResult RecvPong(PongResolver&& aResolve); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - passed("ok"); - QuitParent(); - } -}; - -class TestAsyncReturnsChild : public PTestAsyncReturnsChild { - friend class PTestAsyncReturnsChild; - - public: - TestAsyncReturnsChild(); - virtual ~TestAsyncReturnsChild(); - - protected: - mozilla::ipc::IPCResult RecvPing(PingResolver&& aResolve); - mozilla::ipc::IPCResult RecvNoReturn(NoReturnResolver&& aResolve); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - QuitChild(); - } -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestAsyncReturns_h diff --git a/ipc/ipdl/test/cxx/TestBadActor.cpp b/ipc/ipdl/test/cxx/TestBadActor.cpp deleted file mode 100644 index 6c6991dbb2..0000000000 --- a/ipc/ipdl/test/cxx/TestBadActor.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include "TestBadActor.h" -#include "IPDLUnitTests.h" -#include "mozilla/Unused.h" - -namespace mozilla { -namespace _ipdltest { - -void TestBadActorParent::Main() { - // This test is designed to test a race condition where the child sends us - // a message on an actor that we've already destroyed. The child process - // should die, and the parent process should not abort. - - PTestBadActorSubParent* child = SendPTestBadActorSubConstructor(); - if (!child) fail("Sending constructor"); - - Unused << child->Call__delete__(child); -} - -// By default, fatal errors kill the parent process, but this makes it -// hard to test, so instead we use the previous behavior and kill the -// child process. -void TestBadActorParent::HandleFatalError(const char* aErrorMsg) { - if (!!strcmp(aErrorMsg, "incoming message racing with actor deletion")) { - fail("wrong fatal error"); - } - - ipc::ScopedProcessHandle otherProcessHandle; - if (!base::OpenProcessHandle(OtherPid(), &otherProcessHandle.rwget())) { - fail("couldn't open child process"); - } else { - if (!base::KillProcess(otherProcessHandle, 0, false)) { - fail("terminating child process"); - } - } -} - -PTestBadActorSubParent* TestBadActorParent::AllocPTestBadActorSubParent() { - return new TestBadActorSubParent(); -} - -mozilla::ipc::IPCResult TestBadActorSubParent::RecvPing() { - fail("Shouldn't have received ping."); - return IPC_FAIL_NO_REASON(this); -} - -PTestBadActorSubChild* TestBadActorChild::AllocPTestBadActorSubChild() { - return new TestBadActorSubChild(); -} - -mozilla::ipc::IPCResult TestBadActorChild::RecvPTestBadActorSubConstructor( - PTestBadActorSubChild* actor) { - if (!actor->SendPing()) { - fail("Couldn't send ping to an actor which supposedly isn't dead yet."); - } - return IPC_OK(); -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestBadActor.h b/ipc/ipdl/test/cxx/TestBadActor.h deleted file mode 100644 index cefe0288f4..0000000000 --- a/ipc/ipdl/test/cxx/TestBadActor.h +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef mozilla__ipdltest_TestBadActor_h -#define mozilla__ipdltest_TestBadActor_h - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestBadActorParent.h" -#include "mozilla/_ipdltest/PTestBadActorChild.h" - -#include "mozilla/_ipdltest/PTestBadActorSubParent.h" -#include "mozilla/_ipdltest/PTestBadActorSubChild.h" - -namespace mozilla { -namespace _ipdltest { - -class TestBadActorParent : public PTestBadActorParent { - friend class PTestBadActorParent; - - public: - TestBadActorParent() {} - virtual ~TestBadActorParent() {} - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return false; } - - void Main(); - - protected: - virtual void ActorDestroy(ActorDestroyReason why) override { - if (AbnormalShutdown != why) fail("unexpected destruction"); - passed("ok"); - QuitParent(); - } - - virtual void HandleFatalError(const char* aErrorMsg) override; - - PTestBadActorSubParent* AllocPTestBadActorSubParent(); - - bool DeallocPTestBadActorSubParent(PTestBadActorSubParent* actor) { - delete actor; - return true; - } -}; - -class TestBadActorSubParent : public PTestBadActorSubParent { - friend class PTestBadActorSubParent; - - public: - TestBadActorSubParent() {} - virtual ~TestBadActorSubParent() {} - - protected: - virtual void ActorDestroy(ActorDestroyReason why) override {} - mozilla::ipc::IPCResult RecvPing(); -}; - -class TestBadActorChild : public PTestBadActorChild { - friend class PTestBadActorChild; - - public: - TestBadActorChild() {} - virtual ~TestBadActorChild() {} - - protected: - virtual PTestBadActorSubChild* AllocPTestBadActorSubChild(); - - virtual bool DeallocPTestBadActorSubChild(PTestBadActorSubChild* actor) { - delete actor; - return true; - } - - virtual mozilla::ipc::IPCResult RecvPTestBadActorSubConstructor( - PTestBadActorSubChild* actor); -}; - -class TestBadActorSubChild : public PTestBadActorSubChild { - public: - TestBadActorSubChild() {} - virtual ~TestBadActorSubChild() {} -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // mozilla__ipdltest_TestBadActor_h diff --git a/ipc/ipdl/test/cxx/TestCancel.cpp b/ipc/ipdl/test/cxx/TestCancel.cpp deleted file mode 100644 index 2f97aa2e93..0000000000 --- a/ipc/ipdl/test/cxx/TestCancel.cpp +++ /dev/null @@ -1,115 +0,0 @@ -#include "TestCancel.h" - -#include "IPDLUnitTests.h" // fail etc. - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// parent - -TestCancelParent::TestCancelParent() { MOZ_COUNT_CTOR(TestCancelParent); } - -TestCancelParent::~TestCancelParent() { MOZ_COUNT_DTOR(TestCancelParent); } - -void TestCancelParent::Main() { - if (SendTest1_1()) fail("sending Test1_1"); - - uint32_t value = 0; - if (!SendCheckChild(&value)) fail("Test1 CheckChild"); - - if (value != 12) fail("Test1 CheckChild reply"); -} - -mozilla::ipc::IPCResult TestCancelParent::RecvDone1() { - if (!SendStart2()) fail("sending Start2"); - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestCancelParent::RecvTest2_1() { - if (SendTest2_2()) fail("sending Test2_2"); - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestCancelParent::RecvStart3() { - if (SendTest3_1()) fail("sending Test3_1"); - - uint32_t value = 0; - if (!SendCheckChild(&value)) fail("Test1 CheckChild"); - - if (value != 12) fail("Test1 CheckChild reply"); - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestCancelParent::RecvTest3_2() { - GetIPCChannel()->CancelCurrentTransaction(); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestCancelParent::RecvDone() { - MessageLoop::current()->PostTask(NewNonOwningRunnableMethod( - "ipc::IToplevelProtocol::Close", this, &TestCancelParent::Close)); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestCancelParent::RecvCheckParent(uint32_t* reply) { - *reply = 12; - return IPC_OK(); -} - -//----------------------------------------------------------------------------- -// child - -mozilla::ipc::IPCResult TestCancelChild::RecvTest1_1() { - GetIPCChannel()->CancelCurrentTransaction(); - - uint32_t value = 0; - if (!SendCheckParent(&value)) fail("Test1 CheckParent"); - - if (value != 12) fail("Test1 CheckParent reply"); - - if (!SendDone1()) fail("Test1 CheckParent"); - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestCancelChild::RecvStart2() { - if (!SendTest2_1()) fail("sending Test2_1"); - - if (!SendStart3()) fail("sending Start3"); - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestCancelChild::RecvTest2_2() { - GetIPCChannel()->CancelCurrentTransaction(); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestCancelChild::RecvTest3_1() { - if (SendTest3_2()) fail("sending Test3_2"); - - uint32_t value = 0; - if (!SendCheckParent(&value)) fail("Test1 CheckParent"); - - if (value != 12) fail("Test1 CheckParent reply"); - - if (!SendDone()) fail("sending Done"); - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestCancelChild::RecvCheckChild(uint32_t* reply) { - *reply = 12; - return IPC_OK(); -} - -TestCancelChild::TestCancelChild() { MOZ_COUNT_CTOR(TestCancelChild); } - -TestCancelChild::~TestCancelChild() { MOZ_COUNT_DTOR(TestCancelChild); } - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestCancel.h b/ipc/ipdl/test/cxx/TestCancel.h deleted file mode 100644 index 7d944d6a69..0000000000 --- a/ipc/ipdl/test/cxx/TestCancel.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef mozilla__ipdltest_TestCancel_h -#define mozilla__ipdltest_TestCancel_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestCancelParent.h" -#include "mozilla/_ipdltest/PTestCancelChild.h" - -namespace mozilla { -namespace _ipdltest { - -class TestCancelParent : public PTestCancelParent { - public: - TestCancelParent(); - virtual ~TestCancelParent(); - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return false; } - - void Main(); - - mozilla::ipc::IPCResult RecvDone1(); - mozilla::ipc::IPCResult RecvTest2_1(); - mozilla::ipc::IPCResult RecvStart3(); - mozilla::ipc::IPCResult RecvTest3_2(); - mozilla::ipc::IPCResult RecvDone(); - - mozilla::ipc::IPCResult RecvCheckParent(uint32_t* reply); - - virtual void ActorDestroy(ActorDestroyReason why) override { - passed("ok"); - QuitParent(); - } -}; - -class TestCancelChild : public PTestCancelChild { - public: - TestCancelChild(); - virtual ~TestCancelChild(); - - mozilla::ipc::IPCResult RecvTest1_1(); - mozilla::ipc::IPCResult RecvStart2(); - mozilla::ipc::IPCResult RecvTest2_2(); - mozilla::ipc::IPCResult RecvTest3_1(); - - mozilla::ipc::IPCResult RecvCheckChild(uint32_t* reply); - - virtual void ActorDestroy(ActorDestroyReason why) override { QuitChild(); } -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestCancel_h diff --git a/ipc/ipdl/test/cxx/TestCrashCleanup.cpp b/ipc/ipdl/test/cxx/TestCrashCleanup.cpp deleted file mode 100644 index 6a19cc0f65..0000000000 --- a/ipc/ipdl/test/cxx/TestCrashCleanup.cpp +++ /dev/null @@ -1,100 +0,0 @@ -#include "TestCrashCleanup.h" - -#include "base/task.h" -#include "mozilla/CondVar.h" -#include "mozilla/Mutex.h" - -#include "IPDLUnitTests.h" // fail etc. -#include "IPDLUnitTestSubprocess.h" - -using mozilla::CondVar; -using mozilla::Mutex; -using mozilla::MutexAutoLock; - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// parent - -namespace { - -// NB: this test does its own shutdown, rather than going through -// QuitParent(), because it's testing degenerate edge cases - -void DeleteSubprocess(Mutex* mutex, CondVar* cvar) { - MutexAutoLock lock(*mutex); - - gSubprocess->Destroy(); - gSubprocess = nullptr; - - cvar->Notify(); -} - -void DeleteTheWorld() { - delete static_cast(gParentActor); - gParentActor = nullptr; - - // needs to be synchronous to avoid affecting event ordering on - // the main thread - Mutex mutex MOZ_UNANNOTATED("TestCrashCleanup.DeleteTheWorld.mutex"); - CondVar cvar(mutex, "TestCrashCleanup.DeleteTheWorld.cvar"); - - MutexAutoLock lock(mutex); - - XRE_GetIOMessageLoop()->PostTask( - NewRunnableFunction("DeleteSubprocess", DeleteSubprocess, &mutex, &cvar)); - - cvar.Wait(); -} - -void Done() { - static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID); - nsCOMPtr appShell(do_GetService(kAppShellCID)); - appShell->Exit(); - - passed(__FILE__); -} - -} // namespace - -TestCrashCleanupParent::TestCrashCleanupParent() : mCleanedUp(false) { - MOZ_COUNT_CTOR(TestCrashCleanupParent); -} - -TestCrashCleanupParent::~TestCrashCleanupParent() { - MOZ_COUNT_DTOR(TestCrashCleanupParent); - - if (!mCleanedUp) fail("should have been ActorDestroy()d!"); -} - -void TestCrashCleanupParent::Main() { - // NB: has to be enqueued before IO thread's error notification - MessageLoop::current()->PostTask( - NewRunnableFunction("DeleteTheWorld", DeleteTheWorld)); - - if (CallDIEDIEDIE()) fail("expected an error!"); - - Close(); - - MessageLoop::current()->PostTask(NewRunnableFunction("Done", Done)); -} - -//----------------------------------------------------------------------------- -// child - -TestCrashCleanupChild::TestCrashCleanupChild() { - MOZ_COUNT_CTOR(TestCrashCleanupChild); -} - -TestCrashCleanupChild::~TestCrashCleanupChild() { - MOZ_COUNT_DTOR(TestCrashCleanupChild); -} - -mozilla::ipc::IPCResult TestCrashCleanupChild::AnswerDIEDIEDIE() { - _exit(0); - MOZ_CRASH("unreached"); -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestCrashCleanup.h b/ipc/ipdl/test/cxx/TestCrashCleanup.h deleted file mode 100644 index 30371264e6..0000000000 --- a/ipc/ipdl/test/cxx/TestCrashCleanup.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef mozilla__ipdltest_TestCrashCleanup_h -#define mozilla__ipdltest_TestCrashCleanup_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestCrashCleanupParent.h" -#include "mozilla/_ipdltest/PTestCrashCleanupChild.h" - -namespace mozilla { -namespace _ipdltest { - -class TestCrashCleanupParent : public PTestCrashCleanupParent { - public: - TestCrashCleanupParent(); - virtual ~TestCrashCleanupParent(); - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return false; } - - void Main(); - - protected: - virtual void ActorDestroy(ActorDestroyReason why) override { - if (AbnormalShutdown != why) fail("unexpected destruction!"); - mCleanedUp = true; - } - - bool mCleanedUp; -}; - -class TestCrashCleanupChild : public PTestCrashCleanupChild { - friend class PTestCrashCleanupChild; - - public: - TestCrashCleanupChild(); - virtual ~TestCrashCleanupChild(); - - protected: - mozilla::ipc::IPCResult AnswerDIEDIEDIE(); - - virtual void ActorDestroy(ActorDestroyReason why) override { - fail("should have 'crashed'!"); - } -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestCrashCleanup_h diff --git a/ipc/ipdl/test/cxx/TestDataStructures.cpp b/ipc/ipdl/test/cxx/TestDataStructures.cpp deleted file mode 100644 index 5b1cabfe7d..0000000000 --- a/ipc/ipdl/test/cxx/TestDataStructures.cpp +++ /dev/null @@ -1,888 +0,0 @@ -#include "TestDataStructures.h" - -#include "mozilla/Unused.h" - -#include "IPDLUnitTests.h" // fail etc. - -typedef nsTArray RegionArray; - -namespace mozilla { -namespace _ipdltest { - -static const uint32_t nactors = 10; - -#define test_assert(_cond, _msg) \ - if (!(_cond)) fail(_msg) - -template -static void assert_arrays_equal(const nsTArray& a, const nsTArray& b) { - test_assert(a == b, "arrays equal"); -} - -inline static TestDataStructuresSub& Cast(PTestDataStructuresSubParent* a) { - return *static_cast(a); -} - -//----------------------------------------------------------------------------- -// parent - -TestDataStructuresParent::TestDataStructuresParent() { - MOZ_COUNT_CTOR(TestDataStructuresParent); -} - -TestDataStructuresParent::~TestDataStructuresParent() { - MOZ_COUNT_DTOR(TestDataStructuresParent); -} - -void TestDataStructuresParent::Main() { - for (uint32_t i = 0; i < nactors; ++i) - if (!SendPTestDataStructuresSubConstructor(i)) fail("can't alloc actor"); - - if (!SendStart()) fail("can't send Start()"); -} - -bool TestDataStructuresParent::DeallocPTestDataStructuresSubParent( - PTestDataStructuresSubParent* actor) { - test_assert(Cast(actor).mI == Cast(mKids[0]).mI, "dtor sent to wrong actor"); - mKids.RemoveElementAt(0); - delete actor; - if (mKids.Length() > 0) return true; - - return true; -} - -mozilla::ipc::IPCResult TestDataStructuresParent::RecvTest1(nsTArray&& ia, - nsTArray* oa) { - test_assert(5 == ia.Length(), "wrong length"); - for (int i = 0; i < 5; ++i) test_assert(i == ia[i], "wrong value"); - - *oa = ia; - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestDataStructuresParent::RecvTest2( - nsTArray&& i1, - nsTArray* o1) { - test_assert(nactors == i1.Length(), "wrong #actors"); - for (uint32_t i = 0; i < i1.Length(); ++i) - test_assert(i == Cast(i1[i]).mI, "wrong mI value"); - *o1 = i1; - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestDataStructuresParent::RecvTest3(const IntDouble& i1, - const IntDouble& i2, - IntDouble* o1, - IntDouble* o2) { - test_assert(42 == i1.get_int(), "wrong value"); - test_assert(4.0 == i2.get_double(), "wrong value"); - - *o1 = i1; - *o2 = i2; - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestDataStructuresParent::RecvTest4( - nsTArray&& i1, nsTArray* o1) { - test_assert(4 == i1.Length(), "wrong length"); - test_assert(1 == i1[0].get_int(), "wrong value"); - test_assert(2.0 == i1[1].get_double(), "wrong value"); - test_assert(3 == i1[2].get_int(), "wrong value"); - test_assert(4.0 == i1[3].get_double(), "wrong value"); - - *o1 = i1; - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestDataStructuresParent::RecvTest5( - const IntDoubleArrays& i1, const IntDoubleArrays& i2, - const IntDoubleArrays& i3, IntDoubleArrays* o1, IntDoubleArrays* o2, - IntDoubleArrays* o3) { - test_assert(42 == i1.get_int(), "wrong value"); - - const nsTArray& i2a = i2.get_ArrayOfint(); - test_assert(3 == i2a.Length(), "wrong length"); - test_assert(1 == i2a[0], "wrong value"); - test_assert(2 == i2a[1], "wrong value"); - test_assert(3 == i2a[2], "wrong value"); - - const nsTArray& i3a = i3.get_ArrayOfdouble(); - test_assert(3 == i3a.Length(), "wrong length"); - test_assert(1.0 == i3a[0], "wrong value"); - test_assert(2.0 == i3a[1], "wrong value"); - test_assert(3.0 == i3a[2], "wrong value"); - - *o1 = i1; - *o2 = i2a; - *o3 = i3a; - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestDataStructuresParent::RecvTest7_0( - const ActorWrapper& i1, ActorWrapper* o1) { - if (i1.actorChild() != nullptr) - fail("child side actor should always be null"); - - if (i1.actorParent() != mKids[0]) - fail("should have got back same actor on parent side"); - - o1->actorParent() = mKids[0]; - // malicious behavior - o1->actorChild() = - reinterpret_cast(uintptr_t(0xdeadbeef)); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestDataStructuresParent::RecvTest6( - nsTArray&& i1, nsTArray* o1) { - test_assert(3 == i1.Length(), "wrong length"); - - IntDoubleArrays id1(i1[0]); - test_assert(42 == id1.get_int(), "wrong value"); - - nsTArray i2a(i1[1].get_ArrayOfint()); - test_assert(3 == i2a.Length(), "wrong length"); - test_assert(1 == i2a[0], "wrong value"); - test_assert(2 == i2a[1], "wrong value"); - test_assert(3 == i2a[2], "wrong value"); - - nsTArray i3a(i1[2].get_ArrayOfdouble()); - test_assert(3 == i3a.Length(), "wrong length"); - test_assert(1.0 == i3a[0], "wrong value"); - test_assert(2.0 == i3a[1], "wrong value"); - test_assert(3.0 == i3a[2], "wrong value"); - - o1->AppendElement(id1); - o1->AppendElement(IntDoubleArrays(i2a)); - o1->AppendElement(IntDoubleArrays(i3a)); - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestDataStructuresParent::RecvTest7( - const Actors& i1, const Actors& i2, const Actors& i3, Actors* o1, - Actors* o2, Actors* o3) { - test_assert(42 == i1.get_int(), "wrong value"); - - nsTArray i2a(i2.get_ArrayOfint()); - test_assert(3 == i2a.Length(), "wrong length"); - test_assert(1 == i2a[0], "wrong value"); - test_assert(2 == i2a[1], "wrong value"); - test_assert(3 == i2a[2], "wrong value"); - - assert_arrays_equal(mKids, i3.get_ArrayOfPTestDataStructuresSubParent()); - - *o1 = 42; - *o2 = i2a; - *o3 = mKids; - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestDataStructuresParent::RecvTest8( - nsTArray&& i1, nsTArray* o1) { - test_assert(3 == i1.Length(), "wrong length"); - test_assert(42 == i1[0].get_int(), "wrong value"); - - const nsTArray& i2a = i1[1].get_ArrayOfint(); - test_assert(3 == i2a.Length(), "wrong length"); - test_assert(1 == i2a[0], "wrong value"); - test_assert(2 == i2a[1], "wrong value"); - test_assert(3 == i2a[2], "wrong value"); - - assert_arrays_equal(mKids, i1[2].get_ArrayOfPTestDataStructuresSubParent()); - - *o1 = i1; - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestDataStructuresParent::RecvTest9( - const Unions& i1, const Unions& i2, const Unions& i3, const Unions& i4, - Unions* o1, Unions* o2, Unions* o3, Unions* o4) { - test_assert(42 == i1.get_int(), "wrong value"); - - const nsTArray& i2a = i2.get_ArrayOfint(); - test_assert(3 == i2a.Length(), "wrong length"); - test_assert(1 == i2a[0], "wrong value"); - test_assert(2 == i2a[1], "wrong value"); - test_assert(3 == i2a[2], "wrong value"); - - assert_arrays_equal(mKids, i3.get_ArrayOfPTestDataStructuresSubParent()); - - const nsTArray& i4a = - i4.get_ArrayOfActors()[0].get_ArrayOfPTestDataStructuresSubParent(); - assert_arrays_equal(mKids, i4a); - - *o1 = i1; - *o2 = i2; - *o3 = i3; - *o4 = i4; - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestDataStructuresParent::RecvTest10( - nsTArray&& i1, nsTArray* o1) { - test_assert(42 == i1[0].get_int(), "wrong value"); - - const nsTArray& i2a = i1[1].get_ArrayOfint(); - test_assert(3 == i2a.Length(), "wrong length"); - test_assert(1 == i2a[0], "wrong value"); - test_assert(2 == i2a[1], "wrong value"); - test_assert(3 == i2a[2], "wrong value"); - - assert_arrays_equal(mKids, i1[2].get_ArrayOfPTestDataStructuresSubParent()); - - const nsTArray& i4a = - i1[3].get_ArrayOfActors()[0].get_ArrayOfPTestDataStructuresSubParent(); - assert_arrays_equal(mKids, i4a); - - *o1 = i1; - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestDataStructuresParent::RecvTest11( - const SIntDouble& i, SIntDouble* o) { - test_assert(1 == i.i(), "wrong value"); - test_assert(2.0 == i.d(), "wrong value"); - *o = i; - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestDataStructuresParent::RecvTest12( - const SIntDoubleArrays& i, SIntDoubleArrays* o) { - nsTArray ai; - ai.AppendElement(1); - ai.AppendElement(2); - ai.AppendElement(3); - - nsTArray ad; - ad.AppendElement(.5); - ad.AppendElement(1.0); - ad.AppendElement(2.0); - - test_assert(42 == i.i(), "wrong value"); - assert_arrays_equal(ai, i.ai()); - assert_arrays_equal(ad, i.ad()); - - *o = i; - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestDataStructuresParent::RecvTest13(const SActors& i, - SActors* o) { - nsTArray ai; - ai.AppendElement(1); - ai.AppendElement(2); - ai.AppendElement(3); - - test_assert(42 == i.i(), "wrong value"); - assert_arrays_equal(ai, i.ai()); - assert_arrays_equal(mKids, i.apParent()); - - *o = i; - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestDataStructuresParent::RecvTest14(const Structs& i, - Structs* o) { - nsTArray ai; - ai.AppendElement(1); - ai.AppendElement(2); - ai.AppendElement(3); - - test_assert(42 == i.i(), "wrong value"); - assert_arrays_equal(ai, i.ai()); - assert_arrays_equal(mKids, i.apParent()); - - const SActors& ia = i.aa()[0]; - test_assert(42 == ia.i(), "wrong value"); - assert_arrays_equal(ai, ia.ai()); - assert_arrays_equal(mKids, ia.apParent()); - - *o = i; - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestDataStructuresParent::RecvTest15( - const WithStructs& i1, const WithStructs& i2, const WithStructs& i3, - const WithStructs& i4, const WithStructs& i5, WithStructs* o1, - WithStructs* o2, WithStructs* o3, WithStructs* o4, WithStructs* o5) { - nsTArray ai; - ai.AppendElement(1); - ai.AppendElement(2); - ai.AppendElement(3); - - test_assert(i1 == int(42), "wrong value"); - assert_arrays_equal(i2.get_ArrayOfint(), ai); - assert_arrays_equal(i3.get_ArrayOfPTestDataStructuresSubParent(), mKids); - - const SActors& ia = i4.get_ArrayOfSActors()[0]; - test_assert(42 == ia.i(), "wrong value"); - assert_arrays_equal(ai, ia.ai()); - assert_arrays_equal(mKids, ia.apParent()); - - const Structs& is = i5.get_ArrayOfStructs()[0]; - test_assert(42 == is.i(), "wrong value"); - assert_arrays_equal(ai, is.ai()); - assert_arrays_equal(mKids, is.apParent()); - - const SActors& isa = is.aa()[0]; - test_assert(42 == isa.i(), "wrong value"); - assert_arrays_equal(ai, isa.ai()); - assert_arrays_equal(mKids, isa.apParent()); - - *o1 = i1; - *o2 = i2; - *o3 = i3; - *o4 = i4; - *o5 = i5; - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestDataStructuresParent::RecvTest16( - const WithUnions& i, WithUnions* o) { - test_assert(i.i() == 42, "wrong value"); - - nsTArray ai; - ai.AppendElement(1); - ai.AppendElement(2); - ai.AppendElement(3); - assert_arrays_equal(ai, i.ai()); - - assert_arrays_equal(i.apParent(), mKids); - - assert_arrays_equal(mKids, - i.aa()[0].get_ArrayOfPTestDataStructuresSubParent()); - - const nsTArray& iau = i.au(); - test_assert(iau[0] == 42, "wrong value"); - assert_arrays_equal(ai, iau[1].get_ArrayOfint()); - assert_arrays_equal(mKids, iau[2].get_ArrayOfPTestDataStructuresSubParent()); - assert_arrays_equal( - mKids, - iau[3].get_ArrayOfActors()[0].get_ArrayOfPTestDataStructuresSubParent()); - - *o = i; - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestDataStructuresParent::RecvTest17( - nsTArray&& sa) { - test_assert(sa.Length() == 1 && Op::TSetAttrs == sa[0].type(), "wrong value"); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestDataStructuresParent::RecvTest18(RegionArray&& ra) { - for (RegionArray::index_type i = 0; i < ra.Length(); ++i) { - // if |ra| has been realloc()d and given a different allocator - // chunk, this loop will nondeterministically crash or iloop. - for (auto iter = ra[i].RectIter(); !iter.Done(); iter.Next()) { - Unused << iter.Get(); - } - } - return IPC_OK(); -} - -//----------------------------------------------------------------------------- -// child - -TestDataStructuresChild::TestDataStructuresChild() { - MOZ_COUNT_CTOR(TestDataStructuresChild); -} - -TestDataStructuresChild::~TestDataStructuresChild() { - MOZ_COUNT_DTOR(TestDataStructuresChild); -} - -mozilla::ipc::IPCResult TestDataStructuresChild::RecvStart() { - puts("[TestDataStructuresChild] starting"); - - Test1(); - Test2(); - Test3(); - Test4(); - Test5(); - Test6(); - Test7_0(); - Test7(); - Test8(); - Test9(); - Test10(); - Test11(); - Test12(); - Test13(); - Test14(); - Test15(); - Test16(); - Test17(); - if (OtherPid() != base::GetCurrentProcId()) { - // FIXME/bug 703317 allocation of nsIntRegion uses a global - // region pool which breaks threads - Test18(); - } - - for (uint32_t i = 0; i < nactors; ++i) - if (!PTestDataStructuresSubChild::Send__delete__(mKids[i])) - fail("can't send dtor"); - - Close(); - - return IPC_OK(); -} - -void TestDataStructuresChild::Test1() { - nsTArray ia; - - for (int i = 0; i < 5; ++i) ia.AppendElement(i); - - nsTArray oa; - if (!SendTest1(ia, &oa)) fail("can't send Test1"); - - assert_arrays_equal(ia, oa); - - printf(" passed %s\n", __FUNCTION__); -} - -void TestDataStructuresChild::Test2() { - nsTArray oa; - if (!SendTest2(mKids, &oa)) fail("can't send Test2"); - assert_arrays_equal(mKids, oa); - - printf(" passed %s\n", __FUNCTION__); -} - -void TestDataStructuresChild::Test3() { - int i1i = 42; - double i2d = 4.0; - IntDouble i1(i1i); - IntDouble i2(i2d); - IntDouble o1, o2; - - SendTest3(i1, i2, &o1, &o2); - - test_assert(i1i == o1.get_int(), "wrong value"); - test_assert(i2d == o2.get_double(), "wrong value"); - - printf(" passed %s\n", __FUNCTION__); -} - -void TestDataStructuresChild::Test4() { - nsTArray i1; - i1.AppendElement(IntDouble(int(1))); - i1.AppendElement(IntDouble(2.0)); - i1.AppendElement(IntDouble(int(3))); - i1.AppendElement(IntDouble(4.0)); - - nsTArray o1; - if (!SendTest4(i1, &o1)) fail("can't send Test4"); - - // TODO Union::operator==() - test_assert(i1.Length() == o1.Length(), "wrong length"); - test_assert(1 == o1[0].get_int(), "wrong value"); - test_assert(2.0 == o1[1].get_double(), "wrong value"); - test_assert(3 == o1[2].get_int(), "wrong value"); - test_assert(4.0 == o1[3].get_double(), "wrong value"); - - printf(" passed %s\n", __FUNCTION__); -} - -void TestDataStructuresChild::Test5() { - IntDoubleArrays i1(int(42)); - nsTArray i2; - i2.AppendElement(1); - i2.AppendElement(2); - i2.AppendElement(3); - nsTArray i3; - i3.AppendElement(1.0); - i3.AppendElement(2.0); - i3.AppendElement(3.0); - - IntDoubleArrays o1, o2, o3; - if (!SendTest5(i1, IntDoubleArrays(i2), IntDoubleArrays(i3), &o1, &o2, &o3)) - fail("can't send Test5"); - - test_assert(42 == o1.get_int(), "wrong value"); - assert_arrays_equal(i2, o2.get_ArrayOfint()); - assert_arrays_equal(i3, o3.get_ArrayOfdouble()); - - printf(" passed %s\n", __FUNCTION__); -} - -void TestDataStructuresChild::Test6() { - IntDoubleArrays id1(int(42)); - nsTArray id2; - id2.AppendElement(1); - id2.AppendElement(2); - id2.AppendElement(3); - nsTArray id3; - id3.AppendElement(1.0); - id3.AppendElement(2.0); - id3.AppendElement(3.0); - - nsTArray i1; - i1.AppendElement(id1); - i1.AppendElement(IntDoubleArrays(id2)); - i1.AppendElement(IntDoubleArrays(id3)); - - nsTArray o1; - if (!SendTest6(i1, &o1)) fail("can't send Test6"); - - test_assert(3 == o1.Length(), "wrong length"); - IntDoubleArrays od1(o1[0]); - nsTArray od2(o1[1].get_ArrayOfint()); - nsTArray od3(o1[2].get_ArrayOfdouble()); - - test_assert(42 == od1.get_int(), "wrong value"); - assert_arrays_equal(id2, od2); - assert_arrays_equal(id3, od3); - - printf(" passed %s\n", __FUNCTION__); -} - -void TestDataStructuresChild::Test7_0() { - ActorWrapper iaw; - if (iaw.actorChild() != nullptr || iaw.actorParent() != nullptr) - fail("actor members should be null initially"); - - iaw.actorChild() = mKids[0]; - if (iaw.actorParent() != nullptr) - fail("parent should be null on child side after set"); - - ActorWrapper oaw; - if (!SendTest7_0(iaw, &oaw)) fail("sending Test7_0"); - - if (oaw.actorParent() != nullptr) - fail( - "parent accessor on actor-struct members should always be null in " - "child"); - - if (oaw.actorChild() != mKids[0]) - fail("should have got back same child-side actor"); -} - -void TestDataStructuresChild::Test7() { - Actors i1(42); - nsTArray i2a; - i2a.AppendElement(1); - i2a.AppendElement(2); - i2a.AppendElement(3); - - Actors o1, o2, o3; - if (!SendTest7(i1, Actors(i2a), Actors(mKids), &o1, &o2, &o3)) - fail("can't send Test7"); - - test_assert(42 == o1.get_int(), "wrong value"); - assert_arrays_equal(i2a, o2.get_ArrayOfint()); - assert_arrays_equal(mKids, o3.get_ArrayOfPTestDataStructuresSubChild()); - - printf(" passed %s\n", __FUNCTION__); -} - -void TestDataStructuresChild::Test8() { - Actors i1e(42); - nsTArray i2a; - i2a.AppendElement(1); - i2a.AppendElement(2); - i2a.AppendElement(3); - - nsTArray i1; - i1.AppendElement(i1e); - i1.AppendElement(i2a); - i1.AppendElement(mKids); - - nsTArray o1; - if (!SendTest8(i1, &o1)) fail("can't send Test8"); - - test_assert(3 == o1.Length(), "wrong length"); - test_assert(42 == o1[0].get_int(), "wrong value"); - assert_arrays_equal(i2a, o1[1].get_ArrayOfint()); - assert_arrays_equal(mKids, o1[2].get_ArrayOfPTestDataStructuresSubChild()); - - printf(" passed %s\n", __FUNCTION__); -} - -void TestDataStructuresChild::Test9() { - Unions i1(int(42)); - - nsTArray i2a; - i2a.AppendElement(1); - i2a.AppendElement(2); - i2a.AppendElement(3); - - nsTArray i4a; - i4a.AppendElement(mKids); - - Unions o1, o2, o3, o4; - if (!SendTest9(i1, Unions(i2a), Unions(mKids), Unions(i4a), &o1, &o2, &o3, - &o4)) - fail("can't send Test9"); - - test_assert(42 == o1.get_int(), "wrong value"); - assert_arrays_equal(i2a, o2.get_ArrayOfint()); - assert_arrays_equal(mKids, o3.get_ArrayOfPTestDataStructuresSubChild()); - assert_arrays_equal( - mKids, - o4.get_ArrayOfActors()[0].get_ArrayOfPTestDataStructuresSubChild()); - - printf(" passed %s\n", __FUNCTION__); -} - -void TestDataStructuresChild::Test10() { - Unions i1a(int(42)); - - nsTArray i2a; - i2a.AppendElement(1); - i2a.AppendElement(2); - i2a.AppendElement(3); - - nsTArray i4a; - i4a.AppendElement(mKids); - - nsTArray i1; - i1.AppendElement(i1a); - i1.AppendElement(Unions(i2a)); - i1.AppendElement(Unions(mKids)); - i1.AppendElement(Unions(i4a)); - - nsTArray o1; - if (!SendTest10(i1, &o1)) fail("can't send Test10"); - - test_assert(4 == o1.Length(), "wrong length"); - test_assert(42 == o1[0].get_int(), "wrong value"); - assert_arrays_equal(i2a, o1[1].get_ArrayOfint()); - assert_arrays_equal(mKids, o1[2].get_ArrayOfPTestDataStructuresSubChild()); - assert_arrays_equal( - mKids, - o1[3].get_ArrayOfActors()[0].get_ArrayOfPTestDataStructuresSubChild()); - - printf(" passed %s\n", __FUNCTION__); -} - -void TestDataStructuresChild::Test11() { - SIntDouble i(1, 2.0); - SIntDouble o; - - if (!SendTest11(i, &o)) fail("sending Test11"); - - test_assert(1 == o.i() && 2.0 == o.d(), "wrong values"); - - printf(" passed %s\n", __FUNCTION__); -} - -void TestDataStructuresChild::Test12() { - nsTArray ai; - ai.AppendElement(1); - ai.AppendElement(2); - ai.AppendElement(3); - - nsTArray ad; - ad.AppendElement(.5); - ad.AppendElement(1.0); - ad.AppendElement(2.0); - - SIntDoubleArrays i(42, ai, ad); - SIntDoubleArrays o; - - if (!SendTest12(i, &o)) fail("sending Test12"); - - test_assert(42 == o.i(), "wrong value"); - assert_arrays_equal(ai, o.ai()); - assert_arrays_equal(ad, o.ad()); - - printf(" passed %s\n", __FUNCTION__); -} - -void TestDataStructuresChild::Test13() { - nsTArray ai; - ai.AppendElement(1); - ai.AppendElement(2); - ai.AppendElement(3); - - SActors i; - i.i() = 42; - i.ai() = ai; - i.apChild() = mKids; - - SActors o; - if (!SendTest13(i, &o)) fail("can't send Test13"); - - test_assert(42 == o.i(), "wrong value"); - assert_arrays_equal(ai, o.ai()); - assert_arrays_equal(mKids, o.apChild()); - - printf(" passed %s\n", __FUNCTION__); -} - -void TestDataStructuresChild::Test14() { - nsTArray ai; - ai.AppendElement(1); - ai.AppendElement(2); - ai.AppendElement(3); - - SActors ia; - ia.i() = 42; - ia.ai() = ai; - ia.apChild() = mKids; - nsTArray aa; - aa.AppendElement(ia); - - Structs i; - i.i() = 42; - i.ai() = ai; - i.apChild() = mKids; - i.aa() = aa; - - Structs o; - if (!SendTest14(i, &o)) fail("can't send Test14"); - - test_assert(42 == o.i(), "wrong value"); - assert_arrays_equal(ai, o.ai()); - assert_arrays_equal(mKids, o.apChild()); - - const SActors& os = o.aa()[0]; - test_assert(42 == os.i(), "wrong value"); - assert_arrays_equal(ai, os.ai()); - assert_arrays_equal(mKids, os.apChild()); - - printf(" passed %s\n", __FUNCTION__); -} - -void TestDataStructuresChild::Test15() { - nsTArray ai; - ai.AppendElement(1); - ai.AppendElement(2); - ai.AppendElement(3); - - SActors ia; - ia.i() = 42; - ia.ai() = ai; - ia.apChild() = mKids; - nsTArray iaa; - iaa.AppendElement(ia); - - Structs is; - is.i() = 42; - is.ai() = ai; - is.apChild() = mKids; - is.aa() = iaa; - nsTArray isa; - isa.AppendElement(is); - - WithStructs o1, o2, o3, o4, o5; - if (!SendTest15(WithStructs(42), WithStructs(ai), WithStructs(mKids), - WithStructs(iaa), WithStructs(isa), &o1, &o2, &o3, &o4, &o5)) - fail("sending Test15"); - - test_assert(o1 == int(42), "wrong value"); - assert_arrays_equal(o2.get_ArrayOfint(), ai); - assert_arrays_equal(o3.get_ArrayOfPTestDataStructuresSubChild(), mKids); - - const SActors& oa = o4.get_ArrayOfSActors()[0]; - test_assert(42 == oa.i(), "wrong value"); - assert_arrays_equal(ai, oa.ai()); - assert_arrays_equal(mKids, oa.apChild()); - - const Structs& os = o5.get_ArrayOfStructs()[0]; - test_assert(42 == os.i(), "wrong value"); - assert_arrays_equal(ai, os.ai()); - assert_arrays_equal(mKids, os.apChild()); - - const SActors& osa = os.aa()[0]; - test_assert(42 == osa.i(), "wrong value"); - assert_arrays_equal(ai, osa.ai()); - assert_arrays_equal(mKids, osa.apChild()); - - printf(" passed %s\n", __FUNCTION__); -} - -void TestDataStructuresChild::Test16() { - WithUnions i; - - i.i() = 42; - - nsTArray ai; - ai.AppendElement(1); - ai.AppendElement(2); - ai.AppendElement(3); - i.ai() = ai; - - i.apChild() = mKids; - - nsTArray iaa; - iaa.AppendElement(mKids); - i.aa() = iaa; - - nsTArray iau; - iau.AppendElement(int(42)); - iau.AppendElement(ai); - iau.AppendElement(mKids); - iau.AppendElement(iaa); - i.au() = iau; - - WithUnions o; - if (!SendTest16(i, &o)) fail("sending Test16"); - - test_assert(42 == o.i(), "wrong value"); - assert_arrays_equal(o.ai(), ai); - assert_arrays_equal(o.apChild(), mKids); - - const Actors& oaa = o.aa()[0]; - assert_arrays_equal(oaa.get_ArrayOfPTestDataStructuresSubChild(), mKids); - - const nsTArray& oau = o.au(); - test_assert(oau[0] == 42, "wrong value"); - assert_arrays_equal(oau[1].get_ArrayOfint(), ai); - assert_arrays_equal(oau[2].get_ArrayOfPTestDataStructuresSubChild(), mKids); - assert_arrays_equal( - oau[3].get_ArrayOfActors()[0].get_ArrayOfPTestDataStructuresSubChild(), - mKids); - - printf(" passed %s\n", __FUNCTION__); -} - -void TestDataStructuresChild::Test17() { - Attrs attrs; - attrs.common() = CommonAttrs(true); - attrs.specific() = BarAttrs(1.0f); - - nsTArray ops; - ops.AppendElement(SetAttrs(nullptr, mKids[0], attrs)); - - if (!SendTest17(ops)) fail("sending Test17"); - - printf(" passed %s\n", __FUNCTION__); -} - -void TestDataStructuresChild::Test18() { - const int nelements = 1000; - RegionArray ra; - // big enough to hopefully force a realloc to a different chunk of - // memory on the receiving side, if the workaround isn't working - // correctly. But SetCapacity() here because we don't want to - // crash on the sending side. - ra.SetCapacity(nelements); - for (int i = 0; i < nelements; ++i) { - nsIntRegion r; - r.Or(nsIntRect(0, 0, 10, 10), nsIntRect(10, 10, 10, 10)); - ra.AppendElement(r); - } - - if (!SendTest18(ra)) fail("sending Test18"); - - printf(" passed %s\n", __FUNCTION__); -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestDataStructures.h b/ipc/ipdl/test/cxx/TestDataStructures.h deleted file mode 100644 index dc25b5282c..0000000000 --- a/ipc/ipdl/test/cxx/TestDataStructures.h +++ /dev/null @@ -1,180 +0,0 @@ -#ifndef mozilla__ipdltest_TestDataStructures_h -#define mozilla__ipdltest_TestDataStructures_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestDataStructuresParent.h" -#include "mozilla/_ipdltest/PTestDataStructuresChild.h" - -#include "mozilla/_ipdltest/PTestDataStructuresSubParent.h" -#include "mozilla/_ipdltest/PTestDataStructuresSubChild.h" - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// Subprotocol actors - -class TestDataStructuresSub : public PTestDataStructuresSubParent, - public PTestDataStructuresSubChild { - public: - explicit TestDataStructuresSub(uint32_t i) : mI(i) {} - virtual ~TestDataStructuresSub() {} - virtual void ActorDestroy(ActorDestroyReason why) override { - if (Deletion != why) fail("unexpected destruction!"); - } - uint32_t mI; -}; - -//----------------------------------------------------------------------------- -// Main actors - -class TestDataStructuresParent : public PTestDataStructuresParent { - friend class PTestDataStructuresParent; - - public: - TestDataStructuresParent(); - virtual ~TestDataStructuresParent(); - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return true; } - - void Main(); - - protected: - PTestDataStructuresSubParent* AllocPTestDataStructuresSubParent( - const int& i) { - PTestDataStructuresSubParent* actor = new TestDataStructuresSub(i); - mKids.AppendElement(actor); - return actor; - } - - bool DeallocPTestDataStructuresSubParent(PTestDataStructuresSubParent* actor); - - mozilla::ipc::IPCResult RecvTest1(nsTArray&& i1, nsTArray* o1); - - mozilla::ipc::IPCResult RecvTest2( - nsTArray&& i1, - nsTArray* o1); - - mozilla::ipc::IPCResult RecvTest3(const IntDouble& i1, const IntDouble& i2, - IntDouble* o1, IntDouble* o2); - - mozilla::ipc::IPCResult RecvTest4(nsTArray&& i1, - nsTArray* o1); - - mozilla::ipc::IPCResult RecvTest5(const IntDoubleArrays& i1, - const IntDoubleArrays& i2, - const IntDoubleArrays& i3, - IntDoubleArrays* o1, IntDoubleArrays* o2, - IntDoubleArrays* o3); - - mozilla::ipc::IPCResult RecvTest6(nsTArray&& i1, - nsTArray* o1); - - mozilla::ipc::IPCResult RecvTest7_0(const ActorWrapper& i1, ActorWrapper* o1); - - mozilla::ipc::IPCResult RecvTest7(const Actors& i1, const Actors& i2, - const Actors& i3, Actors* o1, Actors* o2, - Actors* o3); - - mozilla::ipc::IPCResult RecvTest8(nsTArray&& i1, - nsTArray* o1); - - mozilla::ipc::IPCResult RecvTest9(const Unions& i1, const Unions& i2, - const Unions& i3, const Unions& i4, - Unions* o1, Unions* o2, Unions* o3, - Unions* o4); - - mozilla::ipc::IPCResult RecvTest10(nsTArray&& i1, - nsTArray* o1); - - mozilla::ipc::IPCResult RecvTest11(const SIntDouble& i, SIntDouble* o); - - mozilla::ipc::IPCResult RecvTest12(const SIntDoubleArrays& i, - SIntDoubleArrays* o); - - mozilla::ipc::IPCResult RecvTest13(const SActors& i, SActors* o); - - mozilla::ipc::IPCResult RecvTest14(const Structs& i, Structs* o); - - mozilla::ipc::IPCResult RecvTest15( - const WithStructs& i1, const WithStructs& i2, const WithStructs& i3, - const WithStructs& i4, const WithStructs& i5, WithStructs* o1, - WithStructs* o2, WithStructs* o3, WithStructs* o4, WithStructs* o5); - - mozilla::ipc::IPCResult RecvTest16(const WithUnions& i, WithUnions* o); - - mozilla::ipc::IPCResult RecvTest17(nsTArray&& sa); - - mozilla::ipc::IPCResult RecvTest18(nsTArray&& ra); - - mozilla::ipc::IPCResult RecvDummy(const ShmemUnion& su, ShmemUnion* rsu) { - *rsu = su; - return IPC_OK(); - } - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - passed("ok"); - QuitParent(); - } - - private: - nsTArray mKids; -}; - -class TestDataStructuresChild : public PTestDataStructuresChild { - friend class PTestDataStructuresChild; - - public: - TestDataStructuresChild(); - virtual ~TestDataStructuresChild(); - - protected: - PTestDataStructuresSubChild* AllocPTestDataStructuresSubChild(const int& i) { - PTestDataStructuresSubChild* actor = new TestDataStructuresSub(i); - mKids.AppendElement(actor); - return actor; - } - - bool DeallocPTestDataStructuresSubChild(PTestDataStructuresSubChild* actor) { - delete actor; - return true; - } - - mozilla::ipc::IPCResult RecvStart(); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - QuitChild(); - } - - private: - void Test1(); - void Test2(); - void Test3(); - void Test4(); - void Test5(); - void Test6(); - void Test7_0(); - void Test7(); - void Test8(); - void Test9(); - void Test10(); - void Test11(); - void Test12(); - void Test13(); - void Test14(); - void Test15(); - void Test16(); - void Test17(); - void Test18(); - - nsTArray mKids; -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestDataStructures_h diff --git a/ipc/ipdl/test/cxx/TestDemon.cpp b/ipc/ipdl/test/cxx/TestDemon.cpp deleted file mode 100644 index 396974bb56..0000000000 --- a/ipc/ipdl/test/cxx/TestDemon.cpp +++ /dev/null @@ -1,362 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * vim: sw=2 ts=4 et : - */ -#include "TestDemon.h" - -#include - -#include "IPDLUnitTests.h" // fail etc. -#if defined(XP_UNIX) -# include -# include -#else -# include -# include -#endif - -namespace mozilla { -namespace _ipdltest { - -const int kMaxStackHeight = 4; - -static LazyLogModule sLogModule("demon"); - -#define DEMON_LOG(...) MOZ_LOG(sLogModule, LogLevel::Debug, (__VA_ARGS__)) - -static int gStackHeight = 0; -static bool gFlushStack = false; - -static int Choose(int count) { -#if defined(XP_UNIX) - return random() % count; -#else - return rand() % count; -#endif -} - -//----------------------------------------------------------------------------- -// parent - -TestDemonParent::TestDemonParent() : mDone(false), mIncoming(), mOutgoing() { - MOZ_COUNT_CTOR(TestDemonParent); -} - -TestDemonParent::~TestDemonParent() { MOZ_COUNT_DTOR(TestDemonParent); } - -void TestDemonParent::Main() { - if (!getenv("MOZ_TEST_IPC_DEMON")) { - QuitParent(); - return; - } -#if defined(XP_UNIX) - srandom(time(nullptr)); -#else - srand(time(nullptr)); -#endif - - DEMON_LOG("Start demon"); - - if (!SendStart()) fail("sending Start"); - - RunUnlimitedSequence(); -} - -#ifdef DEBUG -bool TestDemonParent::ShouldContinueFromReplyTimeout() { - return Choose(2) == 0; -} - -bool TestDemonParent::ArtificialTimeout() { return Choose(5) == 0; } - -void TestDemonParent::ArtificialSleep() { - if (Choose(2) == 0) { - // Sleep for anywhere from 0 to 100 milliseconds. - unsigned micros = Choose(100) * 1000; -# ifdef XP_UNIX - usleep(micros); -# else - Sleep(micros / 1000); -# endif - } -} -#endif - -mozilla::ipc::IPCResult TestDemonParent::RecvAsyncMessage(const int& n) { - DEMON_LOG("Start RecvAsync [%d]", n); - - MOZ_ASSERT(n == mIncoming[0]); - mIncoming[0]++; - - RunLimitedSequence(); - - DEMON_LOG("End RecvAsync [%d]", n); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestDemonParent::RecvHiPrioSyncMessage() { - DEMON_LOG("Start RecvHiPrioSyncMessage"); - RunLimitedSequence(); - DEMON_LOG("End RecvHiPrioSyncMessage"); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestDemonParent::RecvSyncMessage(const int& n) { - DEMON_LOG("Start RecvSync [%d]", n); - - MOZ_ASSERT(n == mIncoming[0]); - mIncoming[0]++; - - RunLimitedSequence(ASYNC_ONLY); - - DEMON_LOG("End RecvSync [%d]", n); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestDemonParent::RecvUrgentAsyncMessage(const int& n) { - DEMON_LOG("Start RecvUrgentAsyncMessage [%d]", n); - - MOZ_ASSERT(n == mIncoming[2]); - mIncoming[2]++; - - RunLimitedSequence(ASYNC_ONLY); - - DEMON_LOG("End RecvUrgentAsyncMessage [%d]", n); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestDemonParent::RecvUrgentSyncMessage(const int& n) { - DEMON_LOG("Start RecvUrgentSyncMessage [%d]", n); - - MOZ_ASSERT(n == mIncoming[2]); - mIncoming[2]++; - - RunLimitedSequence(ASYNC_ONLY); - - DEMON_LOG("End RecvUrgentSyncMessage [%d]", n); - return IPC_OK(); -} - -void TestDemonParent::RunUnlimitedSequence() { - if (mDone) { - return; - } - - gFlushStack = false; - DoAction(); - - MessageLoop::current()->PostTask(NewNonOwningRunnableMethod( - "_ipdltest::TestDemonParent::RunUnlimitedSequence", this, - &TestDemonParent::RunUnlimitedSequence)); -} - -void TestDemonParent::RunLimitedSequence(int flags) { - if (gStackHeight >= kMaxStackHeight) { - return; - } - gStackHeight++; - - int count = Choose(20); - for (int i = 0; i < count; i++) { - if (!DoAction(flags)) { - gFlushStack = true; - } - if (gFlushStack) { - gStackHeight--; - return; - } - } - - gStackHeight--; -} - -static bool AllowAsync(int outgoing, int incoming) { - return incoming >= outgoing - 5; -} - -bool TestDemonParent::DoAction(int flags) { - if (flags & ASYNC_ONLY) { - if (AllowAsync(mOutgoing[0], mIncoming[0])) { - DEMON_LOG("SendAsyncMessage [%d]", mOutgoing[0]); - return SendAsyncMessage(mOutgoing[0]++); - } else { - return true; - } - } else { - switch (Choose(3)) { - case 0: - if (AllowAsync(mOutgoing[0], mIncoming[0])) { - DEMON_LOG("SendAsyncMessage [%d]", mOutgoing[0]); - return SendAsyncMessage(mOutgoing[0]++); - } else { - return true; - } - - case 1: { - DEMON_LOG("Start SendHiPrioSyncMessage"); - bool r = SendHiPrioSyncMessage(); - DEMON_LOG("End SendHiPrioSyncMessage result=%d", r); - return r; - } - - case 2: - DEMON_LOG("Cancel"); - GetIPCChannel()->CancelCurrentTransaction(); - return true; - } - } - MOZ_CRASH(); - return false; -} - -//----------------------------------------------------------------------------- -// child - -TestDemonChild::TestDemonChild() : mIncoming(), mOutgoing() { - MOZ_COUNT_CTOR(TestDemonChild); -} - -TestDemonChild::~TestDemonChild() { MOZ_COUNT_DTOR(TestDemonChild); } - -mozilla::ipc::IPCResult TestDemonChild::RecvStart() { -#ifdef XP_UNIX - srandom(time(nullptr)); -#else - srand(time(nullptr)); -#endif - - DEMON_LOG("RecvStart"); - - RunUnlimitedSequence(); - return IPC_OK(); -} - -#ifdef DEBUG -void TestDemonChild::ArtificialSleep() { - if (Choose(2) == 0) { - // Sleep for anywhere from 0 to 100 milliseconds. - unsigned micros = Choose(100) * 1000; -# ifdef XP_UNIX - usleep(micros); -# else - Sleep(micros / 1000); -# endif - } -} -#endif - -mozilla::ipc::IPCResult TestDemonChild::RecvAsyncMessage(const int& n) { - DEMON_LOG("Start RecvAsyncMessage [%d]", n); - - MOZ_ASSERT(n == mIncoming[0]); - mIncoming[0]++; - - RunLimitedSequence(); - - DEMON_LOG("End RecvAsyncMessage [%d]", n); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestDemonChild::RecvHiPrioSyncMessage() { - DEMON_LOG("Start RecvHiPrioSyncMessage"); - RunLimitedSequence(); - DEMON_LOG("End RecvHiPrioSyncMessage"); - return IPC_OK(); -} - -void TestDemonChild::RunUnlimitedSequence() { - gFlushStack = false; - DoAction(); - - MessageLoop::current()->PostTask(NewNonOwningRunnableMethod( - "_ipdltest::TestDemonChild::RunUnlimitedSequence", this, - &TestDemonChild::RunUnlimitedSequence)); -} - -void TestDemonChild::RunLimitedSequence() { - if (gStackHeight >= kMaxStackHeight) { - return; - } - gStackHeight++; - - int count = Choose(20); - for (int i = 0; i < count; i++) { - if (!DoAction()) { - gFlushStack = true; - } - if (gFlushStack) { - gStackHeight--; - return; - } - } - - gStackHeight--; -} - -bool TestDemonChild::DoAction() { - switch (Choose(6)) { - case 0: - if (AllowAsync(mOutgoing[0], mIncoming[0])) { - DEMON_LOG("SendAsyncMessage [%d]", mOutgoing[0]); - return SendAsyncMessage(mOutgoing[0]++); - } else { - return true; - } - - case 1: { - DEMON_LOG("Start SendHiPrioSyncMessage"); - bool r = SendHiPrioSyncMessage(); - DEMON_LOG("End SendHiPrioSyncMessage result=%d", r); - return r; - } - - case 2: { - DEMON_LOG("Start SendSyncMessage [%d]", mOutgoing[0]); - bool r = SendSyncMessage(mOutgoing[0]++); - switch (GetIPCChannel()->LastSendError()) { - case SyncSendError::PreviousTimeout: - case SyncSendError::SendingCPOWWhileDispatchingSync: - case SyncSendError::SendingCPOWWhileDispatchingUrgent: - case SyncSendError::NotConnectedBeforeSend: - case SyncSendError::CancelledBeforeSend: - mOutgoing[0]--; - break; - default: - break; - } - DEMON_LOG("End SendSyncMessage result=%d", r); - return r; - } - - case 3: - DEMON_LOG("SendUrgentAsyncMessage [%d]", mOutgoing[2]); - return SendUrgentAsyncMessage(mOutgoing[2]++); - - case 4: { - DEMON_LOG("Start SendUrgentSyncMessage [%d]", mOutgoing[2]); - bool r = SendUrgentSyncMessage(mOutgoing[2]++); - switch (GetIPCChannel()->LastSendError()) { - case SyncSendError::PreviousTimeout: - case SyncSendError::SendingCPOWWhileDispatchingSync: - case SyncSendError::SendingCPOWWhileDispatchingUrgent: - case SyncSendError::NotConnectedBeforeSend: - case SyncSendError::CancelledBeforeSend: - mOutgoing[2]--; - break; - default: - break; - } - DEMON_LOG("End SendUrgentSyncMessage result=%d", r); - return r; - } - - case 5: - DEMON_LOG("Cancel"); - GetIPCChannel()->CancelCurrentTransaction(); - return true; - } - MOZ_CRASH(); - return false; -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestDemon.h b/ipc/ipdl/test/cxx/TestDemon.h deleted file mode 100644 index ba5b003436..0000000000 --- a/ipc/ipdl/test/cxx/TestDemon.h +++ /dev/null @@ -1,91 +0,0 @@ -#ifndef mozilla__ipdltest_TestDemon_h -#define mozilla__ipdltest_TestDemon_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestDemonParent.h" -#include "mozilla/_ipdltest/PTestDemonChild.h" - -using namespace mozilla::ipc; - -namespace mozilla { -namespace _ipdltest { - -class TestDemonParent : public PTestDemonParent { - public: - TestDemonParent(); - virtual ~TestDemonParent(); - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return true; } - - void Main(); - -#ifdef DEBUG - bool ShouldContinueFromReplyTimeout() override; - bool ArtificialTimeout() override; - - bool NeedArtificialSleep() override { return true; } - void ArtificialSleep() override; -#endif - - mozilla::ipc::IPCResult RecvAsyncMessage(const int& n); - mozilla::ipc::IPCResult RecvHiPrioSyncMessage(); - - mozilla::ipc::IPCResult RecvSyncMessage(const int& n); - mozilla::ipc::IPCResult RecvUrgentAsyncMessage(const int& n); - mozilla::ipc::IPCResult RecvUrgentSyncMessage(const int& n); - - virtual void ActorDestroy(ActorDestroyReason why) override { - mDone = true; - printf("Parent ActorDestroy\n"); - passed("ok"); - QuitParent(); - } - - private: - bool mDone; - int mIncoming[3]; - int mOutgoing[3]; - - enum { - ASYNC_ONLY = 1, - }; - - void RunUnlimitedSequence(); - void RunLimitedSequence(int flags = 0); - bool DoAction(int flags = 0); -}; - -class TestDemonChild : public PTestDemonChild { - public: - TestDemonChild(); - virtual ~TestDemonChild(); - - mozilla::ipc::IPCResult RecvStart(); - -#ifdef DEBUG - bool NeedArtificialSleep() override { return true; } - void ArtificialSleep() override; -#endif - - mozilla::ipc::IPCResult RecvAsyncMessage(const int& n); - mozilla::ipc::IPCResult RecvHiPrioSyncMessage(); - - virtual void ActorDestroy(ActorDestroyReason why) override { _exit(0); } - - virtual void IntentionalCrash() override { _exit(0); } - - private: - int mIncoming[3]; - int mOutgoing[3]; - - void RunUnlimitedSequence(); - void RunLimitedSequence(); - bool DoAction(); -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestDemon_h diff --git a/ipc/ipdl/test/cxx/TestDesc.cpp b/ipc/ipdl/test/cxx/TestDesc.cpp deleted file mode 100644 index 2ae199457d..0000000000 --- a/ipc/ipdl/test/cxx/TestDesc.cpp +++ /dev/null @@ -1,78 +0,0 @@ -#include "TestDesc.h" - -#include "IPDLUnitTests.h" // fail etc. - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// parent -void TestDescParent::Main() { - PTestDescSubParent* p = CallPTestDescSubConstructor(0); - if (!p) fail("can't allocate Sub"); - - PTestDescSubsubParent* pp = p->CallPTestDescSubsubConstructor(); - if (!pp) fail("can't allocate Subsub"); - - if (!SendTest(pp)) fail("can't send Subsub"); -} - -mozilla::ipc::IPCResult TestDescParent::RecvOk(PTestDescSubsubParent* a) { - if (!a) fail("didn't receive Subsub"); - - if (!PTestDescSubsubParent::Call__delete__(a)) fail("deleting Subsub"); - - Close(); - - return IPC_OK(); -} - -PTestDescSubParent* TestDescParent::AllocPTestDescSubParent( - PTestDescSubsubParent* dummy) { - if (dummy) fail("actor supposed to be null"); - return new TestDescSubParent(); -} -bool TestDescParent::DeallocPTestDescSubParent(PTestDescSubParent* actor) { - delete actor; - return true; -} - -PTestDescSubsubParent* TestDescSubParent::AllocPTestDescSubsubParent() { - return new TestDescSubsubParent(); -} -bool TestDescSubParent::DeallocPTestDescSubsubParent( - PTestDescSubsubParent* actor) { - delete actor; - return true; -} - -//----------------------------------------------------------------------------- -// child - -mozilla::ipc::IPCResult TestDescChild::RecvTest(PTestDescSubsubChild* a) { - if (!a) fail("didn't receive Subsub"); - if (!SendOk(a)) fail("couldn't send Ok()"); - return IPC_OK(); -} - -PTestDescSubChild* TestDescChild::AllocPTestDescSubChild( - PTestDescSubsubChild* dummy) { - if (dummy) fail("actor supposed to be null"); - return new TestDescSubChild(); -} -bool TestDescChild::DeallocPTestDescSubChild(PTestDescSubChild* actor) { - delete actor; - return true; -} - -PTestDescSubsubChild* TestDescSubChild::AllocPTestDescSubsubChild() { - return new TestDescSubsubChild(); -} -bool TestDescSubChild::DeallocPTestDescSubsubChild( - PTestDescSubsubChild* actor) { - delete actor; - return true; -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestDesc.h b/ipc/ipdl/test/cxx/TestDesc.h deleted file mode 100644 index c9fa04f89c..0000000000 --- a/ipc/ipdl/test/cxx/TestDesc.h +++ /dev/null @@ -1,115 +0,0 @@ -#ifndef mozilla_ipdltest_TestDesc_h -#define mozilla_ipdltest_TestDesc_h - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestDescParent.h" -#include "mozilla/_ipdltest/PTestDescChild.h" - -#include "mozilla/_ipdltest/PTestDescSubParent.h" -#include "mozilla/_ipdltest/PTestDescSubChild.h" - -#include "mozilla/_ipdltest/PTestDescSubsubParent.h" -#include "mozilla/_ipdltest/PTestDescSubsubChild.h" - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// Top-level -// -class TestDescParent : public PTestDescParent { - friend class PTestDescParent; - - public: - TestDescParent() {} - virtual ~TestDescParent() {} - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return true; } - - void Main(); - - mozilla::ipc::IPCResult RecvOk(PTestDescSubsubParent* a); - - protected: - PTestDescSubParent* AllocPTestDescSubParent(PTestDescSubsubParent*); - bool DeallocPTestDescSubParent(PTestDescSubParent* actor); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - passed("ok"); - QuitParent(); - } -}; - -class TestDescChild : public PTestDescChild { - friend class PTestDescChild; - - public: - TestDescChild() {} - virtual ~TestDescChild() {} - - protected: - PTestDescSubChild* AllocPTestDescSubChild(PTestDescSubsubChild*); - - bool DeallocPTestDescSubChild(PTestDescSubChild* actor); - - mozilla::ipc::IPCResult RecvTest(PTestDescSubsubChild* a); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - QuitChild(); - } -}; - -//----------------------------------------------------------------------------- -// First descendent -// -class TestDescSubParent : public PTestDescSubParent { - friend class PTestDescSubParent; - - public: - TestDescSubParent() {} - virtual ~TestDescSubParent() {} - - protected: - virtual void ActorDestroy(ActorDestroyReason why) override {} - PTestDescSubsubParent* AllocPTestDescSubsubParent(); - bool DeallocPTestDescSubsubParent(PTestDescSubsubParent* actor); -}; - -class TestDescSubChild : public PTestDescSubChild { - friend class PTestDescSubChild; - - public: - TestDescSubChild() {} - virtual ~TestDescSubChild() {} - - protected: - PTestDescSubsubChild* AllocPTestDescSubsubChild(); - bool DeallocPTestDescSubsubChild(PTestDescSubsubChild* actor); -}; - -//----------------------------------------------------------------------------- -// Grand-descendent -// -class TestDescSubsubParent : public PTestDescSubsubParent { - public: - TestDescSubsubParent() {} - virtual ~TestDescSubsubParent() {} - - protected: - virtual void ActorDestroy(ActorDestroyReason why) override {} -}; - -class TestDescSubsubChild : public PTestDescSubsubChild { - public: - TestDescSubsubChild() {} - virtual ~TestDescSubsubChild() {} -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla_ipdltest_TestDesc_h diff --git a/ipc/ipdl/test/cxx/TestEndpointBridgeMain.cpp b/ipc/ipdl/test/cxx/TestEndpointBridgeMain.cpp deleted file mode 100644 index 4a4366f0ba..0000000000 --- a/ipc/ipdl/test/cxx/TestEndpointBridgeMain.cpp +++ /dev/null @@ -1,226 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ - -#include "TestEndpointBridgeMain.h" - -#include "base/task.h" -#include "IPDLUnitTests.h" // fail etc. -#include "IPDLUnitTestSubprocess.h" - -using namespace std; - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// main process -void TestEndpointBridgeMainParent::Main() { - if (!SendStart()) { - fail("sending Start"); - } -} - -mozilla::ipc::IPCResult TestEndpointBridgeMainParent::RecvBridged( - Endpoint&& endpoint) { - TestEndpointBridgeMainSubParent* a = new TestEndpointBridgeMainSubParent(); - if (!endpoint.Bind(a)) { - fail("Bind failed"); - } - return IPC_OK(); -} - -void TestEndpointBridgeMainParent::ActorDestroy(ActorDestroyReason why) { - if (NormalShutdown != why) { - fail("unexpected destruction!"); - } - passed("ok"); - QuitParent(); -} - -mozilla::ipc::IPCResult TestEndpointBridgeMainSubParent::RecvHello() { - if (!SendHi()) { - return IPC_FAIL_NO_REASON(this); - } - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestEndpointBridgeMainSubParent::RecvHelloSync() { - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestEndpointBridgeMainSubParent::AnswerHelloRpc() { - if (!CallHiRpc()) { - return IPC_FAIL_NO_REASON(this); - } - return IPC_OK(); -} - -void TestEndpointBridgeMainSubParent::ActorDestroy(ActorDestroyReason why) { - if (NormalShutdown != why) { - fail("unexpected destruction!"); - } - - // ActorDestroy() is just a callback from IPDL-generated code, - // which needs the top-level actor (this) to stay alive a little - // longer so other things can be cleaned up. - MessageLoop::current()->PostTask( - do_AddRef(new DeleteTask(this))); -} - -//----------------------------------------------------------------------------- -// sub process --- child of main -TestEndpointBridgeMainChild* gEndpointBridgeMainChild; - -TestEndpointBridgeMainChild::TestEndpointBridgeMainChild() - : mSubprocess(nullptr) { - gEndpointBridgeMainChild = this; -} - -mozilla::ipc::IPCResult TestEndpointBridgeMainChild::RecvStart() { - vector subsubArgs; - subsubArgs.push_back("TestEndpointBridgeSub"); - - mSubprocess = new IPDLUnitTestSubprocess(); - if (!mSubprocess->SyncLaunch(subsubArgs)) { - fail("problem launching subprocess"); - } - - IPC::Channel* transport = mSubprocess->GetChannel(); - if (!transport) { - fail("no transport"); - } - - TestEndpointBridgeSubParent* bsp = new TestEndpointBridgeSubParent(); - bsp->Open(transport, base::GetProcId(mSubprocess->GetChildProcessHandle())); - - bsp->Main(); - return IPC_OK(); -} - -void TestEndpointBridgeMainChild::ActorDestroy(ActorDestroyReason why) { - if (NormalShutdown != why) { - fail("unexpected destruction!"); - } - // NB: this is kosher because QuitChild() joins with the IO thread - mSubprocess->Destroy(); - mSubprocess = nullptr; - QuitChild(); -} - -void TestEndpointBridgeSubParent::Main() { - if (!SendPing()) { - fail("sending Ping"); - } -} - -mozilla::ipc::IPCResult TestEndpointBridgeSubParent::RecvBridgeEm() { - Endpoint parent; - Endpoint child; - nsresult rv; - rv = PTestEndpointBridgeMainSub::CreateEndpoints( - gEndpointBridgeMainChild->OtherPid(), OtherPid(), &parent, &child); - if (NS_FAILED(rv)) { - fail("opening PTestEndpointOpensOpened"); - } - - if (!gEndpointBridgeMainChild->SendBridged(std::move(parent))) { - fail("SendBridge failed for parent"); - } - if (!SendBridged(std::move(child))) { - fail("SendBridge failed for child"); - } - - return IPC_OK(); -} - -void TestEndpointBridgeSubParent::ActorDestroy(ActorDestroyReason why) { - if (NormalShutdown != why) { - fail("unexpected destruction!"); - } - gEndpointBridgeMainChild->Close(); - - // ActorDestroy() is just a callback from IPDL-generated code, - // which needs the top-level actor (this) to stay alive a little - // longer so other things can be cleaned up. - MessageLoop::current()->PostTask( - do_AddRef(new DeleteTask(this))); -} - -//----------------------------------------------------------------------------- -// subsub process --- child of sub - -static TestEndpointBridgeSubChild* gBridgeSubChild; - -TestEndpointBridgeSubChild::TestEndpointBridgeSubChild() { - gBridgeSubChild = this; -} - -mozilla::ipc::IPCResult TestEndpointBridgeSubChild::RecvPing() { - if (!SendBridgeEm()) { - fail("sending BridgeEm"); - } - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestEndpointBridgeSubChild::RecvBridged( - Endpoint&& endpoint) { - TestEndpointBridgeMainSubChild* a = new TestEndpointBridgeMainSubChild(); - - if (!endpoint.Bind(a)) { - fail("failed to Bind"); - } - - if (!a->SendHello()) { - fail("sending Hello"); - } - - return IPC_OK(); -} - -void TestEndpointBridgeSubChild::ActorDestroy(ActorDestroyReason why) { - if (NormalShutdown != why) { - fail("unexpected destruction!"); - } - QuitChild(); -} - -mozilla::ipc::IPCResult TestEndpointBridgeMainSubChild::RecvHi() { - if (!SendHelloSync()) { - fail("sending HelloSync"); - } - if (!CallHelloRpc()) { - fail("calling HelloRpc"); - } - if (!mGotHi) { - fail("didn't answer HiRpc"); - } - - // Need to close the channel without message-processing frames on - // the C++ stack - MessageLoop::current()->PostTask( - NewNonOwningRunnableMethod("ipc::IToplevelProtocol::Close", this, - &TestEndpointBridgeMainSubChild::Close)); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestEndpointBridgeMainSubChild::AnswerHiRpc() { - mGotHi = true; // d00d - return IPC_OK(); -} - -void TestEndpointBridgeMainSubChild::ActorDestroy(ActorDestroyReason why) { - if (NormalShutdown != why) { - fail("unexpected destruction!"); - } - - gBridgeSubChild->Close(); - - // ActorDestroy() is just a callback from IPDL-generated code, - // which needs the top-level actor (this) to stay alive a little - // longer so other things can be cleaned up. - MessageLoop::current()->PostTask( - do_AddRef(new DeleteTask(this))); -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestEndpointBridgeMain.h b/ipc/ipdl/test/cxx/TestEndpointBridgeMain.h deleted file mode 100644 index 88ac12d71b..0000000000 --- a/ipc/ipdl/test/cxx/TestEndpointBridgeMain.h +++ /dev/null @@ -1,132 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ - -#ifndef mozilla__ipdltest_TestEndpointBridgeMain_h -#define mozilla__ipdltest_TestEndpointBridgeMain_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestEndpointBridgeMainParent.h" -#include "mozilla/_ipdltest/PTestEndpointBridgeMainChild.h" - -#include "mozilla/_ipdltest/PTestEndpointBridgeSubParent.h" -#include "mozilla/_ipdltest/PTestEndpointBridgeSubChild.h" - -#include "mozilla/_ipdltest/PTestEndpointBridgeMainSubParent.h" -#include "mozilla/_ipdltest/PTestEndpointBridgeMainSubChild.h" - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// "Main" process -// -class TestEndpointBridgeMainParent : public PTestEndpointBridgeMainParent { - friend class PTestEndpointBridgeMainParent; - - public: - TestEndpointBridgeMainParent() {} - virtual ~TestEndpointBridgeMainParent() {} - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return false; } - - void Main(); - - protected: - mozilla::ipc::IPCResult RecvBridged( - mozilla::ipc::Endpoint&& endpoint); - - virtual void ActorDestroy(ActorDestroyReason why) override; -}; - -class TestEndpointBridgeMainSubParent - : public PTestEndpointBridgeMainSubParent { - friend class PTestEndpointBridgeMainSubParent; - - public: - explicit TestEndpointBridgeMainSubParent() {} - virtual ~TestEndpointBridgeMainSubParent() {} - - protected: - mozilla::ipc::IPCResult RecvHello(); - mozilla::ipc::IPCResult RecvHelloSync(); - mozilla::ipc::IPCResult AnswerHelloRpc(); - - virtual void ActorDestroy(ActorDestroyReason why) override; -}; - -//----------------------------------------------------------------------------- -// "Sub" process --- child of "main" -// -class TestEndpointBridgeSubParent; - -class TestEndpointBridgeMainChild : public PTestEndpointBridgeMainChild { - friend class PTestEndpointBridgeMainChild; - - public: - TestEndpointBridgeMainChild(); - virtual ~TestEndpointBridgeMainChild() {} - - protected: - mozilla::ipc::IPCResult RecvStart(); - - virtual void ActorDestroy(ActorDestroyReason why) override; - - IPDLUnitTestSubprocess* mSubprocess; -}; - -class TestEndpointBridgeSubParent : public PTestEndpointBridgeSubParent { - friend class PTestEndpointBridgeSubParent; - - public: - TestEndpointBridgeSubParent() {} - virtual ~TestEndpointBridgeSubParent() {} - - void Main(); - - protected: - mozilla::ipc::IPCResult RecvBridgeEm(); - - virtual void ActorDestroy(ActorDestroyReason why) override; -}; - -//----------------------------------------------------------------------------- -// "Subsub" process --- child of "sub" -// -class TestEndpointBridgeSubChild : public PTestEndpointBridgeSubChild { - friend class PTestEndpointBridgeSubChild; - - public: - TestEndpointBridgeSubChild(); - virtual ~TestEndpointBridgeSubChild() {} - - protected: - mozilla::ipc::IPCResult RecvPing(); - - mozilla::ipc::IPCResult RecvBridged( - Endpoint&& endpoint); - - virtual void ActorDestroy(ActorDestroyReason why) override; -}; - -class TestEndpointBridgeMainSubChild : public PTestEndpointBridgeMainSubChild { - friend class PTestEndpointBridgeMainSubChild; - - public: - explicit TestEndpointBridgeMainSubChild() : mGotHi(false) {} - virtual ~TestEndpointBridgeMainSubChild() {} - - protected: - mozilla::ipc::IPCResult RecvHi(); - mozilla::ipc::IPCResult AnswerHiRpc(); - - virtual void ActorDestroy(ActorDestroyReason why) override; - - bool mGotHi; -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestEndpointBridgeMain_h diff --git a/ipc/ipdl/test/cxx/TestEndpointOpens.cpp b/ipc/ipdl/test/cxx/TestEndpointOpens.cpp deleted file mode 100644 index ca141f7b58..0000000000 --- a/ipc/ipdl/test/cxx/TestEndpointOpens.cpp +++ /dev/null @@ -1,242 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ - -#include "base/task.h" -#include "base/thread.h" - -#include "TestEndpointOpens.h" - -#include "IPDLUnitTests.h" // fail etc. - -using namespace mozilla::ipc; - -using base::ProcessHandle; -using base::Thread; - -namespace mozilla { -// NB: this is generally bad style, but I am lazy. -using namespace _ipdltest; -using namespace _ipdltest2; - -static MessageLoop* gMainThread; - -static void AssertNotMainThread() { - if (!gMainThread) { - fail("gMainThread is not initialized"); - } - if (MessageLoop::current() == gMainThread) { - fail("unexpectedly called on the main thread"); - } -} - -//----------------------------------------------------------------------------- -// parent - -// Thread on which TestEndpointOpensOpenedParent runs -static Thread* gParentThread; - -void TestEndpointOpensParent::Main() { - if (!SendStart()) { - fail("sending Start"); - } -} - -static void OpenParent(TestEndpointOpensOpenedParent* aParent, - Endpoint&& aEndpoint) { - AssertNotMainThread(); - - // Open the actor on the off-main thread to park it there. - // Messages will be delivered to this thread's message loop - // instead of the main thread's. - if (!aEndpoint.Bind(aParent)) { - fail("binding Parent"); - } -} - -mozilla::ipc::IPCResult TestEndpointOpensParent::RecvStartSubprotocol( - mozilla::ipc::Endpoint&& endpoint) { - gMainThread = MessageLoop::current(); - - gParentThread = new Thread("ParentThread"); - if (!gParentThread->Start()) { - fail("starting parent thread"); - } - - TestEndpointOpensOpenedParent* a = new TestEndpointOpensOpenedParent(); - gParentThread->message_loop()->PostTask( - NewRunnableFunction("OpenParent", OpenParent, a, std::move(endpoint))); - - return IPC_OK(); -} - -void TestEndpointOpensParent::ActorDestroy(ActorDestroyReason why) { - // Stops the thread and joins it - delete gParentThread; - - if (NormalShutdown != why) { - fail("unexpected destruction A!"); - } - passed("ok"); - QuitParent(); -} - -mozilla::ipc::IPCResult TestEndpointOpensOpenedParent::RecvHello() { - AssertNotMainThread(); - if (!SendHi()) { - return IPC_FAIL_NO_REASON(this); - } - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestEndpointOpensOpenedParent::RecvHelloSync() { - AssertNotMainThread(); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestEndpointOpensOpenedParent::AnswerHelloRpc() { - AssertNotMainThread(); - if (!CallHiRpc()) { - return IPC_FAIL_NO_REASON(this); - } - return IPC_OK(); -} - -static void ShutdownTestEndpointOpensOpenedParent( - TestEndpointOpensOpenedParent* parent, Transport* transport) { - delete parent; -} - -void TestEndpointOpensOpenedParent::ActorDestroy(ActorDestroyReason why) { - AssertNotMainThread(); - - if (NormalShutdown != why) { - fail("unexpected destruction B!"); - } - - // ActorDestroy() is just a callback from IPDL-generated code, - // which needs the top-level actor (this) to stay alive a little - // longer so other things can be cleaned up. - gParentThread->message_loop()->PostTask(NewRunnableFunction( - "ShutdownTestEndpointOpensOpenedParent", - ShutdownTestEndpointOpensOpenedParent, this, GetTransport())); -} - -//----------------------------------------------------------------------------- -// child - -static TestEndpointOpensChild* gOpensChild; -// Thread on which TestEndpointOpensOpenedChild runs -static Thread* gChildThread; - -TestEndpointOpensChild::TestEndpointOpensChild() { gOpensChild = this; } - -static void OpenChild(TestEndpointOpensOpenedChild* aChild, - Endpoint&& endpoint) { - AssertNotMainThread(); - - // Open the actor on the off-main thread to park it there. - // Messages will be delivered to this thread's message loop - // instead of the main thread's. - if (!endpoint.Bind(aChild)) { - fail("binding child endpoint"); - } - - // Kick off the unit tests - if (!aChild->SendHello()) { - fail("sending Hello"); - } -} - -mozilla::ipc::IPCResult TestEndpointOpensChild::RecvStart() { - Endpoint parent; - Endpoint child; - nsresult rv; - rv = PTestEndpointOpensOpened::CreateEndpoints( - OtherPid(), base::GetCurrentProcId(), &parent, &child); - if (NS_FAILED(rv)) { - fail("opening PTestEndpointOpensOpened"); - } - - gMainThread = MessageLoop::current(); - - gChildThread = new Thread("ChildThread"); - if (!gChildThread->Start()) { - fail("starting child thread"); - } - - TestEndpointOpensOpenedChild* a = new TestEndpointOpensOpenedChild(); - gChildThread->message_loop()->PostTask( - NewRunnableFunction("OpenChild", OpenChild, a, std::move(child))); - - if (!SendStartSubprotocol(std::move(parent))) { - fail("send StartSubprotocol"); - } - - return IPC_OK(); -} - -void TestEndpointOpensChild::ActorDestroy(ActorDestroyReason why) { - // Stops the thread and joins it - delete gChildThread; - - if (NormalShutdown != why) { - fail("unexpected destruction C!"); - } - QuitChild(); -} - -mozilla::ipc::IPCResult TestEndpointOpensOpenedChild::RecvHi() { - AssertNotMainThread(); - - if (!SendHelloSync()) { - fail("sending HelloSync"); - } - if (!CallHelloRpc()) { - fail("calling HelloRpc"); - } - if (!mGotHi) { - fail("didn't answer HiRpc"); - } - - // Need to close the channel without message-processing frames on - // the C++ stack - MessageLoop::current()->PostTask( - NewNonOwningRunnableMethod("ipc::IToplevelProtocol::Close", this, - &TestEndpointOpensOpenedChild::Close)); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestEndpointOpensOpenedChild::AnswerHiRpc() { - AssertNotMainThread(); - - mGotHi = true; // d00d - return IPC_OK(); -} - -static void ShutdownTestEndpointOpensOpenedChild( - TestEndpointOpensOpenedChild* child, Transport* transport) { - delete child; - - // Kick off main-thread shutdown. - gMainThread->PostTask( - NewNonOwningRunnableMethod("ipc::IToplevelProtocol::Close", gOpensChild, - &TestEndpointOpensChild::Close)); -} - -void TestEndpointOpensOpenedChild::ActorDestroy(ActorDestroyReason why) { - AssertNotMainThread(); - - if (NormalShutdown != why) { - fail("unexpected destruction D!"); - } - - // ActorDestroy() is just a callback from IPDL-generated code, - // which needs the top-level actor (this) to stay alive a little - // longer so other things can be cleaned up. Defer shutdown to - // let cleanup finish. - gChildThread->message_loop()->PostTask(NewRunnableFunction( - "ShutdownTestEndpointOpensOpenedChild", - ShutdownTestEndpointOpensOpenedChild, this, GetTransport())); -} - -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestEndpointOpens.h b/ipc/ipdl/test/cxx/TestEndpointOpens.h deleted file mode 100644 index 6721274937..0000000000 --- a/ipc/ipdl/test/cxx/TestEndpointOpens.h +++ /dev/null @@ -1,102 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ - -#ifndef mozilla__ipdltest_TestEndpointOpens_h -#define mozilla__ipdltest_TestEndpointOpens_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestEndpointOpensParent.h" -#include "mozilla/_ipdltest/PTestEndpointOpensChild.h" - -#include "mozilla/_ipdltest2/PTestEndpointOpensOpenedParent.h" -#include "mozilla/_ipdltest2/PTestEndpointOpensOpenedChild.h" - -namespace mozilla { - -// parent process - -namespace _ipdltest { - -class TestEndpointOpensParent : public PTestEndpointOpensParent { - friend class PTestEndpointOpensParent; - - public: - TestEndpointOpensParent() {} - virtual ~TestEndpointOpensParent() {} - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return false; } - - void Main(); - - protected: - mozilla::ipc::IPCResult RecvStartSubprotocol( - mozilla::ipc::Endpoint&& endpoint); - - virtual void ActorDestroy(ActorDestroyReason why) override; -}; - -} // namespace _ipdltest - -namespace _ipdltest2 { - -class TestEndpointOpensOpenedParent : public PTestEndpointOpensOpenedParent { - friend class PTestEndpointOpensOpenedParent; - - public: - explicit TestEndpointOpensOpenedParent() {} - virtual ~TestEndpointOpensOpenedParent() {} - - protected: - mozilla::ipc::IPCResult RecvHello(); - mozilla::ipc::IPCResult RecvHelloSync(); - mozilla::ipc::IPCResult AnswerHelloRpc(); - - virtual void ActorDestroy(ActorDestroyReason why) override; -}; - -} // namespace _ipdltest2 - -// child process - -namespace _ipdltest { - -class TestEndpointOpensChild : public PTestEndpointOpensChild { - friend class PTestEndpointOpensChild; - - public: - TestEndpointOpensChild(); - virtual ~TestEndpointOpensChild() {} - - protected: - mozilla::ipc::IPCResult RecvStart(); - - virtual void ActorDestroy(ActorDestroyReason why) override; -}; - -} // namespace _ipdltest - -namespace _ipdltest2 { - -class TestEndpointOpensOpenedChild : public PTestEndpointOpensOpenedChild { - friend class PTestEndpointOpensOpenedChild; - - public: - explicit TestEndpointOpensOpenedChild() : mGotHi(false) {} - virtual ~TestEndpointOpensOpenedChild() {} - - protected: - mozilla::ipc::IPCResult RecvHi(); - mozilla::ipc::IPCResult AnswerHiRpc(); - - virtual void ActorDestroy(ActorDestroyReason why) override; - - bool mGotHi; -}; - -} // namespace _ipdltest2 - -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestEndpointOpens_h diff --git a/ipc/ipdl/test/cxx/TestFailedCtor.cpp b/ipc/ipdl/test/cxx/TestFailedCtor.cpp deleted file mode 100644 index 2f08d2eeb0..0000000000 --- a/ipc/ipdl/test/cxx/TestFailedCtor.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include "TestFailedCtor.h" - -#include "IPDLUnitTests.h" // fail etc. - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// parent -void TestFailedCtorParent::Main() { - PTestFailedCtorSubParent* p = CallPTestFailedCtorSubConstructor(); - if (p) fail("expected ctor to fail"); - - Close(); -} - -PTestFailedCtorSubParent* -TestFailedCtorParent::AllocPTestFailedCtorSubParent() { - return new TestFailedCtorSubParent(); -} -bool TestFailedCtorParent::DeallocPTestFailedCtorSubParent( - PTestFailedCtorSubParent* actor) { - delete actor; - return true; -} - -PTestFailedCtorSubsubParent* -TestFailedCtorSubParent::AllocPTestFailedCtorSubsubParent() { - TestFailedCtorSubsub* a = new TestFailedCtorSubsub(); - if (!mOne) { - return mOne = a; - } else if (!mTwo) { - return mTwo = a; - } else if (!mThree) { - return mThree = a; - } else { - fail("unexpected Alloc()"); - return nullptr; - } -} -bool TestFailedCtorSubParent::DeallocPTestFailedCtorSubsubParent( - PTestFailedCtorSubsubParent* actor) { - static_cast(actor)->mDealloced = true; - return true; -} - -void TestFailedCtorSubParent::ActorDestroy(ActorDestroyReason why) { - if (mOne->mWhy != Deletion) fail("Subsub one got wrong ActorDestroyReason"); - if (mTwo->mWhy != AncestorDeletion) - fail("Subsub two got wrong ActorDestroyReason"); - if (mThree->mWhy != AncestorDeletion) - fail("Subsub three got wrong ActorDestroyReason"); - - if (FailedConstructor != why) fail("unexpected destruction!"); -} - -TestFailedCtorSubParent::~TestFailedCtorSubParent() { - if (!(mOne->mDealloced && mTwo->mDealloced && mThree->mDealloced)) - fail("Not all subsubs were Dealloc'd"); - delete mOne; - delete mTwo; - delete mThree; -} - -//----------------------------------------------------------------------------- -// child - -PTestFailedCtorSubChild* TestFailedCtorChild::AllocPTestFailedCtorSubChild() { - return new TestFailedCtorSubChild(); -} - -mozilla::ipc::IPCResult -TestFailedCtorChild::AnswerPTestFailedCtorSubConstructor( - PTestFailedCtorSubChild* actor) { - PTestFailedCtorSubsubChild* c1 = - actor->SendPTestFailedCtorSubsubConstructor(); - PTestFailedCtorSubsubChild::Send__delete__(c1); - - if (!actor->SendPTestFailedCtorSubsubConstructor() || - !actor->SendPTestFailedCtorSubsubConstructor() || !actor->SendSync()) - fail("setting up test"); - - // This causes our process to die - return IPC_FAIL_NO_REASON(this); -} - -bool TestFailedCtorChild::DeallocPTestFailedCtorSubChild( - PTestFailedCtorSubChild* actor) { - delete actor; - return true; -} - -void TestFailedCtorChild::ProcessingError(Result aCode, const char* aReason) { - if (OtherPid() != base::GetCurrentProcId()) // thread-mode - _exit(0); -} - -PTestFailedCtorSubsubChild* -TestFailedCtorSubChild::AllocPTestFailedCtorSubsubChild() { - return new TestFailedCtorSubsub(); -} - -bool TestFailedCtorSubChild::DeallocPTestFailedCtorSubsubChild( - PTestFailedCtorSubsubChild* actor) { - delete actor; - return true; -} - -void TestFailedCtorSubChild::ActorDestroy(ActorDestroyReason why) {} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestFailedCtor.h b/ipc/ipdl/test/cxx/TestFailedCtor.h deleted file mode 100644 index 6fac4eb278..0000000000 --- a/ipc/ipdl/test/cxx/TestFailedCtor.h +++ /dev/null @@ -1,127 +0,0 @@ -#ifndef mozilla_ipdltest_TestFailedCtor_h -#define mozilla_ipdltest_TestFailedCtor_h - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestFailedCtorParent.h" -#include "mozilla/_ipdltest/PTestFailedCtorChild.h" - -#include "mozilla/_ipdltest/PTestFailedCtorSubParent.h" -#include "mozilla/_ipdltest/PTestFailedCtorSubChild.h" - -#include "mozilla/_ipdltest/PTestFailedCtorSubsubParent.h" -#include "mozilla/_ipdltest/PTestFailedCtorSubsubChild.h" - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// Top-level -// -class TestFailedCtorParent : public PTestFailedCtorParent { - friend class PTestFailedCtorParent; - - public: - TestFailedCtorParent() {} - virtual ~TestFailedCtorParent() {} - - static bool RunTestInProcesses() { return true; } - - // FIXME/bug 703322 Disabled because child calls exit() to end - // test, not clear how to handle failed ctor in - // threaded mode. - static bool RunTestInThreads() { return false; } - - void Main(); - - protected: - PTestFailedCtorSubParent* AllocPTestFailedCtorSubParent(); - bool DeallocPTestFailedCtorSubParent(PTestFailedCtorSubParent* actor); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (AbnormalShutdown != why) fail("unexpected destruction!"); - passed("ok"); - QuitParent(); - } -}; - -class TestFailedCtorChild : public PTestFailedCtorChild { - friend class PTestFailedCtorChild; - - public: - TestFailedCtorChild() {} - virtual ~TestFailedCtorChild() {} - - protected: - PTestFailedCtorSubChild* AllocPTestFailedCtorSubChild(); - - mozilla::ipc::IPCResult AnswerPTestFailedCtorSubConstructor( - PTestFailedCtorSubChild* actor) override; - - bool DeallocPTestFailedCtorSubChild(PTestFailedCtorSubChild* actor); - - virtual void ProcessingError(Result aCode, const char* aReason) override; - - virtual void ActorDestroy(ActorDestroyReason why) override { - fail("should have _exit()ed"); - } -}; - -//----------------------------------------------------------------------------- -// First descendent -// -class TestFailedCtorSubsub; - -class TestFailedCtorSubParent : public PTestFailedCtorSubParent { - friend class PTestFailedCtorSubParent; - - public: - TestFailedCtorSubParent() : mOne(nullptr), mTwo(nullptr), mThree(nullptr) {} - virtual ~TestFailedCtorSubParent(); - - protected: - PTestFailedCtorSubsubParent* AllocPTestFailedCtorSubsubParent(); - - bool DeallocPTestFailedCtorSubsubParent(PTestFailedCtorSubsubParent* actor); - mozilla::ipc::IPCResult RecvSync() { return IPC_OK(); } - - virtual void ActorDestroy(ActorDestroyReason why) override; - - TestFailedCtorSubsub* mOne; - TestFailedCtorSubsub* mTwo; - TestFailedCtorSubsub* mThree; -}; - -class TestFailedCtorSubChild : public PTestFailedCtorSubChild { - friend class PTestFailedCtorSubChild; - - public: - TestFailedCtorSubChild() {} - virtual ~TestFailedCtorSubChild() {} - - protected: - PTestFailedCtorSubsubChild* AllocPTestFailedCtorSubsubChild(); - bool DeallocPTestFailedCtorSubsubChild(PTestFailedCtorSubsubChild* actor); - - virtual void ActorDestroy(ActorDestroyReason why) override; -}; - -//----------------------------------------------------------------------------- -// Grand-descendent -// -class TestFailedCtorSubsub : public PTestFailedCtorSubsubParent, - public PTestFailedCtorSubsubChild { - public: - TestFailedCtorSubsub() : mWhy(ActorDestroyReason(-1)), mDealloced(false) {} - virtual ~TestFailedCtorSubsub() {} - - virtual void ActorDestroy(ActorDestroyReason why) override { mWhy = why; } - - ActorDestroyReason mWhy; - bool mDealloced; -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla_ipdltest_TestFailedCtor_h diff --git a/ipc/ipdl/test/cxx/TestHangs.cpp b/ipc/ipdl/test/cxx/TestHangs.cpp deleted file mode 100644 index 2694cbfdab..0000000000 --- a/ipc/ipdl/test/cxx/TestHangs.cpp +++ /dev/null @@ -1,127 +0,0 @@ -#include "base/process_util.h" - -#include "TestHangs.h" - -#include "IPDLUnitTests.h" // fail etc. - -using base::KillProcess; - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// parent - -TestHangsParent::TestHangsParent() - : mDetectedHang(false), mNumAnswerStackFrame(0) { - MOZ_COUNT_CTOR(TestHangsParent); -} - -TestHangsParent::~TestHangsParent() { MOZ_COUNT_DTOR(TestHangsParent); } - -void TestHangsParent::Main() { - // Here we try to set things up to test the following sequence of events: - // - // - subprocess causes an OnMaybeDequeueOne() task to be posted to - // this thread - // - // - subprocess hangs just long enough for the hang timer to expire - // - // - hang-kill code in the parent starts running - // - // - subprocess replies to message while hang code runs - // - // - reply is processed in OnMaybeDequeueOne() before Close() has - // been called or the channel error notification has been posted - - // this tells the subprocess to send us Nonce() - if (!SendStart()) fail("sending Start"); - - // now we sleep here for a while awaiting the Nonce() message from - // the child. since we're not blocked on anything, the IO thread - // will enqueue an OnMaybeDequeueOne() task to process that - // message - // - // NB: PR_Sleep is exactly what we want, only the current thread - // sleeping - PR_Sleep(5000); - - // when we call into this, we'll pull the Nonce() message out of - // the mPending queue, but that doesn't matter ... the - // OnMaybeDequeueOne() event will remain - if (CallStackFrame() && mDetectedHang) fail("should have timed out!"); - - // the Close() task in the queue will shut us down -} - -bool TestHangsParent::ShouldContinueFromReplyTimeout() { - mDetectedHang = true; - - // so we've detected a timeout after 2 ms ... now we cheat and - // sleep for a long time, to allow the subprocess's reply to come - // in - - PR_Sleep(5000); - - // reply should be here; we'll post a task to shut things down. - // This must be after OnMaybeDequeueOne() in the event queue. - MessageLoop::current()->PostTask(NewNonOwningRunnableMethod( - "_ipdltest::TestHangsParent::CleanUp", this, &TestHangsParent::CleanUp)); - - GetIPCChannel()->CloseWithTimeout(); - - return false; -} - -mozilla::ipc::IPCResult TestHangsParent::AnswerStackFrame() { - ++mNumAnswerStackFrame; - - if (mNumAnswerStackFrame == 1) { - if (CallStackFrame()) { - fail("should have timed out!"); - } - } else if (mNumAnswerStackFrame == 2) { - // minimum possible, 2 ms. We want to detecting a hang to race - // with the reply coming in, as reliably as possible - SetReplyTimeoutMs(2); - - if (CallHang()) fail("should have timed out!"); - } else { - fail("unexpected state"); - } - - return IPC_OK(); -} - -void TestHangsParent::CleanUp() { - ipc::ScopedProcessHandle otherProcessHandle; - if (!base::OpenProcessHandle(OtherPid(), &otherProcessHandle.rwget())) { - fail("couldn't open child process"); - } else { - if (!KillProcess(otherProcessHandle, 0, false)) { - fail("terminating child process"); - } - } - Close(); -} - -//----------------------------------------------------------------------------- -// child - -TestHangsChild::TestHangsChild() { MOZ_COUNT_CTOR(TestHangsChild); } - -TestHangsChild::~TestHangsChild() { MOZ_COUNT_DTOR(TestHangsChild); } - -mozilla::ipc::IPCResult TestHangsChild::AnswerHang() { - puts(" (child process is 'hanging' now)"); - - // just sleep until we're reasonably confident the 1ms hang - // detector fired in the parent process and it's sleeping in - // ShouldContinueFromReplyTimeout() - PR_Sleep(1000); - - return IPC_OK(); -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestHangs.h b/ipc/ipdl/test/cxx/TestHangs.h deleted file mode 100644 index a3dfb991f5..0000000000 --- a/ipc/ipdl/test/cxx/TestHangs.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef mozilla__ipdltest_TestHangs_h -#define mozilla__ipdltest_TestHangs_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestHangsParent.h" -#include "mozilla/_ipdltest/PTestHangsChild.h" - -namespace mozilla { -namespace _ipdltest { - -class TestHangsParent : public PTestHangsParent { - friend class PTestHangsParent; - - public: - TestHangsParent(); - virtual ~TestHangsParent(); - - static bool RunTestInProcesses() { return true; } - - // FIXME/bug 703320 Disabled because parent kills child proc, not - // clear how that should work in threads. - static bool RunTestInThreads() { return false; } - - void Main(); - - protected: - virtual bool ShouldContinueFromReplyTimeout() override; - - mozilla::ipc::IPCResult RecvNonce() { return IPC_OK(); } - - mozilla::ipc::IPCResult AnswerStackFrame(); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (AbnormalShutdown != why) fail("unexpected destruction!"); - passed("ok"); - QuitParent(); - } - - void CleanUp(); - - bool mDetectedHang; - int32_t mNumAnswerStackFrame; -}; - -class TestHangsChild : public PTestHangsChild { - friend class PTestHangsChild; - - public: - TestHangsChild(); - virtual ~TestHangsChild(); - - protected: - mozilla::ipc::IPCResult RecvStart() { - if (!SendNonce()) fail("sending Nonce"); - return IPC_OK(); - } - - mozilla::ipc::IPCResult AnswerStackFrame() { - if (CallStackFrame()) fail("should have failed"); - return IPC_OK(); - } - - mozilla::ipc::IPCResult AnswerHang(); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (AbnormalShutdown != why) fail("unexpected destruction!"); - QuitChild(); - } -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestHangs_h diff --git a/ipc/ipdl/test/cxx/TestHighestPrio.cpp b/ipc/ipdl/test/cxx/TestHighestPrio.cpp deleted file mode 100644 index 499c352a5a..0000000000 --- a/ipc/ipdl/test/cxx/TestHighestPrio.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * vim: sw=2 ts=4 et : - */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "TestHighestPrio.h" - -#include "IPDLUnitTests.h" // fail etc. -#if defined(XP_UNIX) -# include -#else -# include -#endif - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// parent - -TestHighestPrioParent::TestHighestPrioParent() : msg_num_(0) { - MOZ_COUNT_CTOR(TestHighestPrioParent); -} - -TestHighestPrioParent::~TestHighestPrioParent() { - MOZ_COUNT_DTOR(TestHighestPrioParent); -} - -void TestHighestPrioParent::Main() { - if (!SendStart()) fail("sending Start"); -} - -mozilla::ipc::IPCResult TestHighestPrioParent::RecvMsg1() { - MOZ_ASSERT(msg_num_ == 0); - msg_num_ = 1; - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestHighestPrioParent::RecvMsg2() { - MOZ_ASSERT(msg_num_ == 1); - msg_num_ = 2; - - if (!SendStartInner()) fail("sending StartInner"); - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestHighestPrioParent::RecvMsg3() { - MOZ_ASSERT(msg_num_ == 2); - msg_num_ = 3; - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestHighestPrioParent::RecvMsg4() { - MOZ_ASSERT(msg_num_ == 3); - msg_num_ = 4; - return IPC_OK(); -} - -//----------------------------------------------------------------------------- -// child - -TestHighestPrioChild::TestHighestPrioChild() { - MOZ_COUNT_CTOR(TestHighestPrioChild); -} - -TestHighestPrioChild::~TestHighestPrioChild() { - MOZ_COUNT_DTOR(TestHighestPrioChild); -} - -mozilla::ipc::IPCResult TestHighestPrioChild::RecvStart() { - if (!SendMsg1()) fail("sending Msg1"); - - if (!SendMsg2()) fail("sending Msg2"); - - Close(); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestHighestPrioChild::RecvStartInner() { - if (!SendMsg3()) fail("sending Msg3"); - - if (!SendMsg4()) fail("sending Msg4"); - - return IPC_OK(); -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestHighestPrio.h b/ipc/ipdl/test/cxx/TestHighestPrio.h deleted file mode 100644 index 34563d7708..0000000000 --- a/ipc/ipdl/test/cxx/TestHighestPrio.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef mozilla__ipdltest_TestHighestPrio_h -#define mozilla__ipdltest_TestHighestPrio_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestHighestPrioParent.h" -#include "mozilla/_ipdltest/PTestHighestPrioChild.h" - -namespace mozilla { -namespace _ipdltest { - -class TestHighestPrioParent : public PTestHighestPrioParent { - public: - TestHighestPrioParent(); - virtual ~TestHighestPrioParent(); - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return false; } - - void Main(); - - mozilla::ipc::IPCResult RecvMsg1(); - mozilla::ipc::IPCResult RecvMsg2(); - mozilla::ipc::IPCResult RecvMsg3(); - mozilla::ipc::IPCResult RecvMsg4(); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - if (msg_num_ != 4) fail("missed IPC call"); - passed("ok"); - QuitParent(); - } - - private: - int msg_num_; -}; - -class TestHighestPrioChild : public PTestHighestPrioChild { - public: - TestHighestPrioChild(); - virtual ~TestHighestPrioChild(); - - mozilla::ipc::IPCResult RecvStart(); - mozilla::ipc::IPCResult RecvStartInner(); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - QuitChild(); - } -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestHighestPrio_h diff --git a/ipc/ipdl/test/cxx/TestInterruptErrorCleanup.cpp b/ipc/ipdl/test/cxx/TestInterruptErrorCleanup.cpp deleted file mode 100644 index 3af7ad620d..0000000000 --- a/ipc/ipdl/test/cxx/TestInterruptErrorCleanup.cpp +++ /dev/null @@ -1,138 +0,0 @@ -#include "TestInterruptErrorCleanup.h" - -#include "base/task.h" -#include "mozilla/CondVar.h" -#include "mozilla/Mutex.h" - -#include "IPDLUnitTests.h" // fail etc. -#include "IPDLUnitTestSubprocess.h" - -using mozilla::CondVar; -using mozilla::Mutex; -using mozilla::MutexAutoLock; - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// parent - -namespace { - -// NB: this test does its own shutdown, rather than going through -// QuitParent(), because it's testing degenerate edge cases - -void DeleteSubprocess(Mutex* mutex, CondVar* cvar) { - MutexAutoLock lock(*mutex); - - gSubprocess->Destroy(); - gSubprocess = nullptr; - - cvar->Notify(); -} - -void DeleteTheWorld() { - delete static_cast(gParentActor); - gParentActor = nullptr; - - // needs to be synchronous to avoid affecting event ordering on - // the main thread - Mutex mutex MOZ_UNANNOTATED("TestInterruptErrorCleanup.DeleteTheWorld.mutex"); - CondVar cvar(mutex, "TestInterruptErrorCleanup.DeleteTheWorld.cvar"); - - MutexAutoLock lock(mutex); - - XRE_GetIOMessageLoop()->PostTask( - NewRunnableFunction("DeleteSubprocess", DeleteSubprocess, &mutex, &cvar)); - - cvar.Wait(); -} - -void Done() { - static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID); - nsCOMPtr appShell(do_GetService(kAppShellCID)); - appShell->Exit(); - - passed(__FILE__); -} - -} // namespace - -TestInterruptErrorCleanupParent::TestInterruptErrorCleanupParent() - : mGotProcessingError(false) { - MOZ_COUNT_CTOR(TestInterruptErrorCleanupParent); -} - -TestInterruptErrorCleanupParent::~TestInterruptErrorCleanupParent() { - MOZ_COUNT_DTOR(TestInterruptErrorCleanupParent); -} - -void TestInterruptErrorCleanupParent::Main() { - // This test models the following sequence of events - // - // (1) Parent: Interrupt out-call - // (2) Child: crash - // --[Parent-only hereafter]-- - // (3) Interrupt out-call return false - // (4) Close() - // --[event loop]-- - // (5) delete parentActor - // (6) delete childProcess - // --[event loop]-- - // (7) Channel::OnError notification - // --[event loop]-- - // (8) Done, quit - // - // See bug 535298 and friends; this seqeunce of events captures - // three differnent potential errors - // - Close()-after-error (semantic error previously) - // - use-after-free of parentActor - // - use-after-free of channel - // - // Because of legacy constraints related to nsNPAPI* code, we need - // to ensure that this sequence of events can occur without - // errors/crashes. - - MessageLoop::current()->PostTask( - NewRunnableFunction("DeleteTheWorld", DeleteTheWorld)); - - // it's a failure if this *succeeds* - if (CallError()) fail("expected an error!"); - - if (!mGotProcessingError) fail("expected a ProcessingError() notification"); - - // it's OK to Close() a channel after an error, because nsNPAPI* - // wants to do this - Close(); - - // we know that this event *must* be after the MaybeError - // notification enqueued by AsyncChannel, because that event is - // enqueued within the same mutex that ends up signaling the - // wakeup-on-error of |CallError()| above - MessageLoop::current()->PostTask(NewRunnableFunction("Done", Done)); -} - -void TestInterruptErrorCleanupParent::ProcessingError(Result aCode, - const char* aReason) { - if (aCode != MsgDropped) fail("unexpected processing error"); - mGotProcessingError = true; -} - -//----------------------------------------------------------------------------- -// child - -TestInterruptErrorCleanupChild::TestInterruptErrorCleanupChild() { - MOZ_COUNT_CTOR(TestInterruptErrorCleanupChild); -} - -TestInterruptErrorCleanupChild::~TestInterruptErrorCleanupChild() { - MOZ_COUNT_DTOR(TestInterruptErrorCleanupChild); -} - -mozilla::ipc::IPCResult TestInterruptErrorCleanupChild::AnswerError() { - _exit(0); - MOZ_CRASH("unreached"); -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestInterruptErrorCleanup.h b/ipc/ipdl/test/cxx/TestInterruptErrorCleanup.h deleted file mode 100644 index 9ae0493cf0..0000000000 --- a/ipc/ipdl/test/cxx/TestInterruptErrorCleanup.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef mozilla__ipdltest_TestInterruptErrorCleanup_h -#define mozilla__ipdltest_TestInterruptErrorCleanup_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestInterruptErrorCleanupParent.h" -#include "mozilla/_ipdltest/PTestInterruptErrorCleanupChild.h" - -namespace mozilla { -namespace _ipdltest { - -class TestInterruptErrorCleanupParent - : public PTestInterruptErrorCleanupParent { - public: - TestInterruptErrorCleanupParent(); - virtual ~TestInterruptErrorCleanupParent(); - - static bool RunTestInProcesses() { return true; } - // FIXME/bug 703323 Could work if modified - static bool RunTestInThreads() { return false; } - - void Main(); - - protected: - virtual void ActorDestroy(ActorDestroyReason why) override { - if (AbnormalShutdown != why) fail("unexpected destruction!"); - } - - virtual void ProcessingError(Result aCode, const char* aReason) override; - - bool mGotProcessingError; -}; - -class TestInterruptErrorCleanupChild : public PTestInterruptErrorCleanupChild { - friend class PTestInterruptErrorCleanupChild; - - public: - TestInterruptErrorCleanupChild(); - virtual ~TestInterruptErrorCleanupChild(); - - protected: - mozilla::ipc::IPCResult AnswerError(); - - virtual void ActorDestroy(ActorDestroyReason why) override { - fail("should have 'crashed'!"); - } -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestInterruptErrorCleanup_h diff --git a/ipc/ipdl/test/cxx/TestInterruptRaces.cpp b/ipc/ipdl/test/cxx/TestInterruptRaces.cpp deleted file mode 100644 index 02b42cfbc3..0000000000 --- a/ipc/ipdl/test/cxx/TestInterruptRaces.cpp +++ /dev/null @@ -1,169 +0,0 @@ -#include "TestInterruptRaces.h" - -#include "IPDLUnitTests.h" // fail etc. - -using mozilla::ipc::MessageChannel; - -namespace mozilla { -namespace _ipdltest { - -ipc::RacyInterruptPolicy MediateRace(const MessageChannel::MessageInfo& parent, - const MessageChannel::MessageInfo& child) { - return (PTestInterruptRaces::Msg_Child__ID == parent.type()) - ? ipc::RIPParentWins - : ipc::RIPChildWins; -} - -//----------------------------------------------------------------------------- -// parent -void TestInterruptRacesParent::Main() { - if (!SendStart()) fail("sending Start()"); -} - -mozilla::ipc::IPCResult TestInterruptRacesParent::RecvStartRace() { - MessageLoop::current()->PostTask(NewNonOwningRunnableMethod( - "_ipdltest::TestInterruptRacesParent::OnRaceTime", this, - &TestInterruptRacesParent::OnRaceTime)); - return IPC_OK(); -} - -void TestInterruptRacesParent::OnRaceTime() { - if (!CallRace(&mChildHasReply)) fail("problem calling Race()"); - - if (!mChildHasReply) fail("child should have got a reply already"); - - mHasReply = true; - - MessageLoop::current()->PostTask( - NewNonOwningRunnableMethod("_ipdltest::TestInterruptRacesParent::Test2", - this, &TestInterruptRacesParent::Test2)); -} - -mozilla::ipc::IPCResult TestInterruptRacesParent::AnswerRace(bool* hasReply) { - if (mHasReply) fail("apparently the parent won the Interrupt race!"); - *hasReply = hasReply; - return IPC_OK(); -} - -void TestInterruptRacesParent::Test2() { - puts(" passed"); - puts("Test 2"); - - mHasReply = false; - mChildHasReply = false; - - if (!CallStackFrame()) fail("can't set up a stack frame"); - - puts(" passed"); - - MessageLoop::current()->PostTask( - NewNonOwningRunnableMethod("_ipdltest::TestInterruptRacesParent::Test3", - this, &TestInterruptRacesParent::Test3)); -} - -mozilla::ipc::IPCResult TestInterruptRacesParent::AnswerStackFrame() { - if (!SendWakeup()) fail("can't wake up the child"); - - if (!CallRace(&mChildHasReply)) fail("can't set up race condition"); - mHasReply = true; - - if (!mChildHasReply) fail("child should have got a reply already"); - - return IPC_OK(); -} - -void TestInterruptRacesParent::Test3() { - puts("Test 3"); - - if (!CallStackFrame3()) fail("can't set up a stack frame"); - - puts(" passed"); - - Close(); -} - -mozilla::ipc::IPCResult TestInterruptRacesParent::AnswerStackFrame3() { - if (!SendWakeup3()) fail("can't wake up the child"); - - if (!CallChild()) fail("can't set up race condition"); - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestInterruptRacesParent::AnswerParent() { - mAnsweredParent = true; - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestInterruptRacesParent::RecvGetAnsweredParent( - bool* answeredParent) { - *answeredParent = mAnsweredParent; - return IPC_OK(); -} - -//----------------------------------------------------------------------------- -// child -mozilla::ipc::IPCResult TestInterruptRacesChild::RecvStart() { - puts("Test 1"); - - if (!SendStartRace()) fail("problem sending StartRace()"); - - bool dontcare; - if (!CallRace(&dontcare)) fail("problem calling Race()"); - - mHasReply = true; - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestInterruptRacesChild::AnswerRace(bool* hasReply) { - if (!mHasReply) fail("apparently the child lost the Interrupt race!"); - - *hasReply = mHasReply; - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestInterruptRacesChild::AnswerStackFrame() { - // reset for the second test - mHasReply = false; - - if (!CallStackFrame()) fail("can't set up stack frame"); - - if (!mHasReply) fail("should have had reply by now"); - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestInterruptRacesChild::RecvWakeup() { - bool dontcare; - if (!CallRace(&dontcare)) fail("can't set up race condition"); - - mHasReply = true; - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestInterruptRacesChild::AnswerStackFrame3() { - if (!CallStackFrame3()) fail("can't set up stack frame"); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestInterruptRacesChild::RecvWakeup3() { - if (!CallParent()) fail("can't set up race condition"); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestInterruptRacesChild::AnswerChild() { - bool parentAnsweredParent; - // the parent is supposed to win the race, which means its - // message, Child(), is supposed to be processed before the - // child's message, Parent() - if (!SendGetAnsweredParent(&parentAnsweredParent)) - fail("sending GetAnsweredParent"); - - if (parentAnsweredParent) fail("parent was supposed to win the race!"); - - return IPC_OK(); -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestInterruptRaces.h b/ipc/ipdl/test/cxx/TestInterruptRaces.h deleted file mode 100644 index 6fa184da1a..0000000000 --- a/ipc/ipdl/test/cxx/TestInterruptRaces.h +++ /dev/null @@ -1,104 +0,0 @@ -#ifndef mozilla__ipdltest_TestInterruptRaces_h -#define mozilla__ipdltest_TestInterruptRaces_h - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestInterruptRacesParent.h" -#include "mozilla/_ipdltest/PTestInterruptRacesChild.h" - -namespace mozilla { -namespace _ipdltest { - -mozilla::ipc::RacyInterruptPolicy MediateRace( - const mozilla::ipc::MessageChannel::MessageInfo& parent, - const mozilla::ipc::MessageChannel::MessageInfo& child); - -class TestInterruptRacesParent : public PTestInterruptRacesParent { - friend class PTestInterruptRacesParent; - - public: - TestInterruptRacesParent() - : mHasReply(false), mChildHasReply(false), mAnsweredParent(false) {} - virtual ~TestInterruptRacesParent() {} - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return true; } - - void Main(); - - protected: - mozilla::ipc::IPCResult RecvStartRace(); - - mozilla::ipc::IPCResult AnswerRace(bool* hasRace); - - mozilla::ipc::IPCResult AnswerStackFrame(); - - mozilla::ipc::IPCResult AnswerStackFrame3(); - - mozilla::ipc::IPCResult AnswerParent(); - - mozilla::ipc::IPCResult RecvGetAnsweredParent(bool* answeredParent); - - mozilla::ipc::RacyInterruptPolicy MediateInterruptRace( - const MessageInfo& parent, const MessageInfo& child) override { - return MediateRace(parent, child); - } - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - if (!(mHasReply && mChildHasReply)) fail("both sides should have replies!"); - passed("ok"); - QuitParent(); - } - - private: - void OnRaceTime(); - - void Test2(); - void Test3(); - - bool mHasReply; - bool mChildHasReply; - bool mAnsweredParent; -}; - -class TestInterruptRacesChild : public PTestInterruptRacesChild { - friend class PTestInterruptRacesChild; - - public: - TestInterruptRacesChild() : mHasReply(false) {} - virtual ~TestInterruptRacesChild() {} - - protected: - mozilla::ipc::IPCResult RecvStart(); - - mozilla::ipc::IPCResult AnswerRace(bool* hasRace); - - mozilla::ipc::IPCResult AnswerStackFrame(); - - mozilla::ipc::IPCResult AnswerStackFrame3(); - - mozilla::ipc::IPCResult RecvWakeup(); - - mozilla::ipc::IPCResult RecvWakeup3(); - - mozilla::ipc::IPCResult AnswerChild(); - - virtual mozilla::ipc::RacyInterruptPolicy MediateInterruptRace( - const MessageInfo& parent, const MessageInfo& child) override { - return MediateRace(parent, child); - } - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - QuitChild(); - } - - private: - bool mHasReply; -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestInterruptRaces_h diff --git a/ipc/ipdl/test/cxx/TestInterruptShutdownRace.cpp b/ipc/ipdl/test/cxx/TestInterruptShutdownRace.cpp deleted file mode 100644 index 5482893995..0000000000 --- a/ipc/ipdl/test/cxx/TestInterruptShutdownRace.cpp +++ /dev/null @@ -1,111 +0,0 @@ -#include "TestInterruptShutdownRace.h" - -#include "base/task.h" -#include "IPDLUnitTests.h" // fail etc. -#include "IPDLUnitTestSubprocess.h" - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// parent - -namespace { - -// NB: this test does its own shutdown, rather than going through -// QuitParent(), because it's testing degenerate edge cases - -void DeleteSubprocess() { - gSubprocess->Destroy(); - gSubprocess = nullptr; -} - -void Done() { - passed(__FILE__); - QuitParent(); -} - -} // namespace - -TestInterruptShutdownRaceParent::TestInterruptShutdownRaceParent() { - MOZ_COUNT_CTOR(TestInterruptShutdownRaceParent); -} - -TestInterruptShutdownRaceParent::~TestInterruptShutdownRaceParent() { - MOZ_COUNT_DTOR(TestInterruptShutdownRaceParent); -} - -void TestInterruptShutdownRaceParent::Main() { - if (!SendStart()) fail("sending Start"); -} - -mozilla::ipc::IPCResult TestInterruptShutdownRaceParent::RecvStartDeath() { - // this will be ordered before the OnMaybeDequeueOne event of - // Orphan in the queue - MessageLoop::current()->PostTask(NewNonOwningRunnableMethod( - "_ipdltest::TestInterruptShutdownRaceParent::StartShuttingDown", this, - &TestInterruptShutdownRaceParent::StartShuttingDown)); - return IPC_OK(); -} - -void TestInterruptShutdownRaceParent::StartShuttingDown() { - // NB: we sleep here to try and avoid receiving the Orphan message - // while waiting for the CallExit() reply. if we fail at that, it - // will cause the test to pass spuriously, because there won't be - // an OnMaybeDequeueOne task for Orphan - PR_Sleep(2000); - - if (CallExit()) fail("connection was supposed to be interrupted"); - - Close(); - - delete static_cast(gParentActor); - gParentActor = nullptr; - - XRE_GetIOMessageLoop()->PostTask( - NewRunnableFunction("DeleteSubprocess", DeleteSubprocess)); - - // this is ordered after the OnMaybeDequeueOne event in the queue - MessageLoop::current()->PostTask(NewRunnableFunction("Done", Done)); - - // |this| has been deleted, be mindful -} - -mozilla::ipc::IPCResult TestInterruptShutdownRaceParent::RecvOrphan() { - // it would be nice to fail() here, but we'll process this message - // while waiting for the reply CallExit(). The OnMaybeDequeueOne - // task will still be in the queue, it just wouldn't have had any - // work to do, if we hadn't deleted ourself - return IPC_OK(); -} - -//----------------------------------------------------------------------------- -// child - -TestInterruptShutdownRaceChild::TestInterruptShutdownRaceChild() { - MOZ_COUNT_CTOR(TestInterruptShutdownRaceChild); -} - -TestInterruptShutdownRaceChild::~TestInterruptShutdownRaceChild() { - MOZ_COUNT_DTOR(TestInterruptShutdownRaceChild); -} - -mozilla::ipc::IPCResult TestInterruptShutdownRaceChild::RecvStart() { - if (!SendStartDeath()) fail("sending StartDeath"); - - // See comment in StartShuttingDown(): we want to send Orphan() - // while the parent is in its PR_Sleep() - PR_Sleep(1000); - - if (!SendOrphan()) fail("sending Orphan"); - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestInterruptShutdownRaceChild::AnswerExit() { - _exit(0); - MOZ_CRASH("unreached"); -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestInterruptShutdownRace.h b/ipc/ipdl/test/cxx/TestInterruptShutdownRace.h deleted file mode 100644 index 17425fc06c..0000000000 --- a/ipc/ipdl/test/cxx/TestInterruptShutdownRace.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef mozilla__ipdltest_TestInterruptShutdownRace_h -#define mozilla__ipdltest_TestInterruptShutdownRace_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestInterruptShutdownRaceParent.h" -#include "mozilla/_ipdltest/PTestInterruptShutdownRaceChild.h" - -namespace mozilla { -namespace _ipdltest { - -class TestInterruptShutdownRaceParent - : public PTestInterruptShutdownRaceParent { - public: - TestInterruptShutdownRaceParent(); - virtual ~TestInterruptShutdownRaceParent(); - - static bool RunTestInProcesses() { return true; } - // FIXME/bug 703323 Could work if modified - static bool RunTestInThreads() { return false; } - - void Main(); - - mozilla::ipc::IPCResult RecvStartDeath(); - - mozilla::ipc::IPCResult RecvOrphan(); - - protected: - void StartShuttingDown(); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (AbnormalShutdown != why) fail("unexpected destruction!"); - } -}; - -class TestInterruptShutdownRaceChild : public PTestInterruptShutdownRaceChild { - friend class PTestInterruptShutdownRaceChild; - - public: - TestInterruptShutdownRaceChild(); - virtual ~TestInterruptShutdownRaceChild(); - - protected: - mozilla::ipc::IPCResult RecvStart(); - - mozilla::ipc::IPCResult AnswerExit(); - - virtual void ActorDestroy(ActorDestroyReason why) override { - fail("should have 'crashed'!"); - } -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestInterruptShutdownRace_h diff --git a/ipc/ipdl/test/cxx/TestJSON.cpp b/ipc/ipdl/test/cxx/TestJSON.cpp deleted file mode 100644 index 42fac919d1..0000000000 --- a/ipc/ipdl/test/cxx/TestJSON.cpp +++ /dev/null @@ -1,113 +0,0 @@ -#include "TestJSON.h" - -#include "IPDLUnitTests.h" // fail etc. - -#define test_assert(_cond, _msg) \ - if (!(_cond)) fail(_msg) - -namespace mozilla { -namespace _ipdltest { - -static nsString String(const char* const str) { - return NS_ConvertUTF8toUTF16(str); -} - -static void Array123(nsTArray& a123) { - a123.AppendElement(1); - a123.AppendElement(2); - a123.AppendElement(3); - - test_assert(a123 == a123, "operator== is broken"); -} - -template -JSONVariant MakeTestVariant(HandleT* handle) { - // In JS syntax: - // - // return [ - // undefined, null, true, 1.25, "test string", - // handle, - // [ 1, 2, 3 ], - // { "undefined" : undefined, - // "null" : null, - // "true" : true, - // "1.25" : 1.25, - // "string" : "string" - // "handle" : handle, - // "array" : [ 1, 2, 3 ] - // } - // ] - // - nsTArray outer; - - outer.AppendElement(void_t()); - outer.AppendElement(null_t()); - outer.AppendElement(true); - outer.AppendElement(1.25); - outer.AppendElement(String("test string")); - - outer.AppendElement(handle); - - nsTArray tmp; - Array123(tmp); - outer.AppendElement(tmp); - - nsTArray obj; - obj.AppendElement(KeyValue(String("undefined"), void_t())); - obj.AppendElement(KeyValue(String("null"), null_t())); - obj.AppendElement(KeyValue(String("true"), true)); - obj.AppendElement(KeyValue(String("1.25"), 1.25)); - obj.AppendElement(KeyValue(String("string"), String("value"))); - obj.AppendElement(KeyValue(String("handle"), handle)); - nsTArray tmp2; - Array123(tmp2); - obj.AppendElement(KeyValue(String("array"), tmp2)); - - outer.AppendElement(obj); - - test_assert(outer == outer, "operator== is broken"); - - return JSONVariant(outer); -} - -//----------------------------------------------------------------------------- -// parent - -void TestJSONParent::Main() { - if (!SendStart()) fail("sending Start"); -} - -mozilla::ipc::IPCResult TestJSONParent::RecvTest(const JSONVariant& i, - JSONVariant* o) { - test_assert(i == i, "operator== is broken"); - test_assert(i == MakeTestVariant(mKid), "inparam mangled en route"); - - *o = i; - - test_assert(i == *o, "operator= is broken"); - - return IPC_OK(); -} - -//----------------------------------------------------------------------------- -// child - -mozilla::ipc::IPCResult TestJSONChild::RecvStart() { - if (!SendPTestHandleConstructor()) fail("sending Handle ctor"); - - JSONVariant i(MakeTestVariant(mKid)); - test_assert(i == i, "operator== is broken"); - test_assert(i == MakeTestVariant(mKid), "copy ctor is broken"); - - JSONVariant o; - if (!SendTest(i, &o)) fail("sending Test"); - - test_assert(i == o, "round-trip mangled input data"); - test_assert(o == MakeTestVariant(mKid), "outparam mangled en route"); - - Close(); - return IPC_OK(); -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestJSON.h b/ipc/ipdl/test/cxx/TestJSON.h deleted file mode 100644 index eaf7516525..0000000000 --- a/ipc/ipdl/test/cxx/TestJSON.h +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef mozilla__ipdltest_TestJSON_h -#define mozilla__ipdltest_TestJSON_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestJSONParent.h" -#include "mozilla/_ipdltest/PTestJSONChild.h" - -#include "mozilla/_ipdltest/PTestHandleParent.h" -#include "mozilla/_ipdltest/PTestHandleChild.h" - -namespace mozilla { -namespace _ipdltest { - -class TestHandleParent : public PTestHandleParent { - public: - TestHandleParent() {} - virtual ~TestHandleParent() {} - - protected: - virtual void ActorDestroy(ActorDestroyReason why) override {} -}; - -class TestJSONParent : public PTestJSONParent { - friend class PTestJSONParent; - - public: - TestJSONParent() {} - virtual ~TestJSONParent() {} - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return true; } - - void Main(); - - protected: - mozilla::ipc::IPCResult RecvTest(const JSONVariant& i, JSONVariant* o); - - PTestHandleParent* AllocPTestHandleParent() { - return mKid = new TestHandleParent(); - } - - bool DeallocPTestHandleParent(PTestHandleParent* actor) { - delete actor; - return true; - } - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - passed("ok"); - QuitParent(); - } - - PTestHandleParent* mKid; -}; - -class TestHandleChild : public PTestHandleChild { - public: - TestHandleChild() {} - virtual ~TestHandleChild() {} -}; - -class TestJSONChild : public PTestJSONChild { - friend class PTestJSONChild; - - public: - TestJSONChild() {} - virtual ~TestJSONChild() {} - - protected: - mozilla::ipc::IPCResult RecvStart(); - - PTestHandleChild* AllocPTestHandleChild() { - return mKid = new TestHandleChild(); - } - - bool DeallocPTestHandleChild(PTestHandleChild* actor) { - delete actor; - return true; - } - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - QuitChild(); - } - - PTestHandleChild* mKid; -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestJSON_h diff --git a/ipc/ipdl/test/cxx/TestLatency.cpp b/ipc/ipdl/test/cxx/TestLatency.cpp deleted file mode 100644 index f88d8ea644..0000000000 --- a/ipc/ipdl/test/cxx/TestLatency.cpp +++ /dev/null @@ -1,210 +0,0 @@ -#include "TestLatency.h" - -#include "IPDLUnitTests.h" // fail etc. - -// A ping/pong trial takes O(100us) or more, so if we don't have 10us -// resolution or better, the results will not be terribly useful -static const double kTimingResolutionCutoff = 0.00001; // 10us - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// parent - -TestLatencyParent::TestLatencyParent() - : mStart(), - mPPTimeTotal(), - mPP5TimeTotal(), - mRpcTimeTotal(), - mPPTrialsToGo(NR_TRIALS), - mPP5TrialsToGo(NR_TRIALS), - mNumChildProcessedCompressedSpams(0), - mWhichPong5(0) { - MOZ_COUNT_CTOR(TestLatencyParent); -} - -TestLatencyParent::~TestLatencyParent() { MOZ_COUNT_DTOR(TestLatencyParent); } - -void TestLatencyParent::Main() { - TimeDuration resolution = TimeDuration::Resolution(); - if (resolution.ToSeconds() > kTimingResolutionCutoff) { - puts(" (skipping TestLatency, timing resolution is too poor)"); - Close(); - return; - } - - printf(" timing resolution: %g seconds\n", resolution.ToSecondsSigDigits()); - - if (mozilla::ipc::LoggingEnabled()) - MOZ_CRASH( - "you really don't want to log all IPC messages during this test, trust " - "me"); - - PingPongTrial(); -} - -void TestLatencyParent::PingPongTrial() { - mStart = TimeStamp::Now(); - if (!SendPing()) fail("sending Ping()"); -} - -void TestLatencyParent::Ping5Pong5Trial() { - mStart = TimeStamp::Now(); - - if (!SendPing5() || !SendPing5() || !SendPing5() || !SendPing5() || - !SendPing5()) - fail("sending Ping5()"); -} - -mozilla::ipc::IPCResult TestLatencyParent::RecvPong() { - TimeDuration thisTrial = (TimeStamp::Now() - mStart); - mPPTimeTotal += thisTrial; - - if (0 == (mPPTrialsToGo % 1000)) - printf(" PP trial %d: %g\n", mPPTrialsToGo, - thisTrial.ToSecondsSigDigits()); - - if (--mPPTrialsToGo > 0) - PingPongTrial(); - else - Ping5Pong5Trial(); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestLatencyParent::RecvPong5() { - ++mWhichPong5; - - if (mWhichPong5 < 5) { - return IPC_OK(); - } - - mWhichPong5 = 0; - - TimeDuration thisTrial = (TimeStamp::Now() - mStart); - mPP5TimeTotal += thisTrial; - - if (0 == (mPP5TrialsToGo % 1000)) - printf(" PP5 trial %d: %g\n", mPP5TrialsToGo, - thisTrial.ToSecondsSigDigits()); - - if (0 < --mPP5TrialsToGo) - Ping5Pong5Trial(); - else - RpcTrials(); - - return IPC_OK(); -} - -void TestLatencyParent::RpcTrials() { - TimeStamp start = TimeStamp::Now(); - for (int i = 0; i < NR_TRIALS; ++i) { - if (!CallRpc()) fail("can't call Rpc()"); - if (0 == (i % 1000)) printf(" Rpc trial %d\n", i); - } - mRpcTimeTotal = (TimeStamp::Now() - start); - - SpamTrial(); -} - -void TestLatencyParent::SpamTrial() { - TimeStamp start = TimeStamp::Now(); - for (int i = 0; i < NR_SPAMS - 1; ++i) { - if (!SendSpam()) fail("sending Spam()"); - if (0 == (i % 10000)) printf(" Spam trial %d\n", i); - } - - // Synchronize with the child process to ensure all messages have - // been processed. This adds the overhead of a reply message from - // child-->here, but should be insignificant compared to >> - // NR_SPAMS. - if (!CallSynchro()) fail("calling Synchro()"); - - mSpamTimeTotal = (TimeStamp::Now() - start); - - CompressedSpamTrial(); -} - -void TestLatencyParent::CompressedSpamTrial() { - for (int i = 0; i < NR_SPAMS; ++i) { - if (!SendCompressedSpam(i + 1)) fail("sending CompressedSpam()"); - if (0 == (i % 10000)) printf(" CompressedSpam trial %d\n", i); - } - - uint32_t lastSeqno; - if (!CallSynchro2(&lastSeqno, &mNumChildProcessedCompressedSpams)) - fail("calling Synchro2()"); - - if (lastSeqno != NR_SPAMS) - fail("last seqno was %u, expected %u", lastSeqno, NR_SPAMS); - - // NB: since this is testing an optimization, it's somewhat bogus. - // Need to make a warning if it actually intermittently fails in - // practice, which is doubtful. - if (!(mNumChildProcessedCompressedSpams < NR_SPAMS)) - fail("Didn't compress any messages?"); - - Exit(); -} - -void TestLatencyParent::Exit() { Close(); } - -//----------------------------------------------------------------------------- -// child - -TestLatencyChild::TestLatencyChild() - : mLastSeqno(0), mNumProcessedCompressedSpams(0), mWhichPing5(0) { - MOZ_COUNT_CTOR(TestLatencyChild); -} - -TestLatencyChild::~TestLatencyChild() { MOZ_COUNT_DTOR(TestLatencyChild); } - -mozilla::ipc::IPCResult TestLatencyChild::RecvPing() { - SendPong(); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestLatencyChild::RecvPing5() { - ++mWhichPing5; - - if (mWhichPing5 < 5) { - return IPC_OK(); - } - - mWhichPing5 = 0; - - if (!SendPong5() || !SendPong5() || !SendPong5() || !SendPong5() || - !SendPong5()) - fail("sending Pong5()"); - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestLatencyChild::AnswerRpc() { return IPC_OK(); } - -mozilla::ipc::IPCResult TestLatencyChild::RecvSpam() { - // no-op - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestLatencyChild::AnswerSynchro() { return IPC_OK(); } - -mozilla::ipc::IPCResult TestLatencyChild::RecvCompressedSpam( - const uint32_t& seqno) { - if (seqno <= mLastSeqno) - fail("compressed seqnos must monotonically increase"); - - mLastSeqno = seqno; - ++mNumProcessedCompressedSpams; - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestLatencyChild::AnswerSynchro2( - uint32_t* lastSeqno, uint32_t* numMessagesDispatched) { - *lastSeqno = mLastSeqno; - *numMessagesDispatched = mNumProcessedCompressedSpams; - return IPC_OK(); -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestLatency.h b/ipc/ipdl/test/cxx/TestLatency.h deleted file mode 100644 index 687b107808..0000000000 --- a/ipc/ipdl/test/cxx/TestLatency.h +++ /dev/null @@ -1,107 +0,0 @@ -#ifndef mozilla__ipdltest_TestLatency_h -#define mozilla__ipdltest_TestLatency_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestLatencyParent.h" -#include "mozilla/_ipdltest/PTestLatencyChild.h" - -#include "mozilla/TimeStamp.h" - -#define NR_TRIALS 10000 -#define NR_SPAMS 25000 - -namespace mozilla { -namespace _ipdltest { - -class TestLatencyParent : public PTestLatencyParent { - friend class PTestLatencyParent; - - private: - typedef mozilla::TimeStamp TimeStamp; - typedef mozilla::TimeDuration TimeDuration; - - public: - TestLatencyParent(); - virtual ~TestLatencyParent(); - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return true; } - - void Main(); - - protected: - mozilla::ipc::IPCResult RecvPong(); - mozilla::ipc::IPCResult RecvPong5(); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - - passed( - "\n" - " average #ping-pong/sec: %g\n" - " average #ping5-pong5/sec: %g\n" - " average #RPC call-answer/sec: %g\n" - " average #spams/sec: %g\n" - " pct. spams compressed away: %g\n", - double(NR_TRIALS) / mPPTimeTotal.ToSecondsSigDigits(), - double(NR_TRIALS) / mPP5TimeTotal.ToSecondsSigDigits(), - double(NR_TRIALS) / mRpcTimeTotal.ToSecondsSigDigits(), - double(NR_SPAMS) / mSpamTimeTotal.ToSecondsSigDigits(), - 100.0 * (double(NR_SPAMS - mNumChildProcessedCompressedSpams) / - double(NR_SPAMS))); - - QuitParent(); - } - - private: - void PingPongTrial(); - void Ping5Pong5Trial(); - void RpcTrials(); - void SpamTrial(); - void CompressedSpamTrial(); - void Exit(); - - TimeStamp mStart; - TimeDuration mPPTimeTotal; - TimeDuration mPP5TimeTotal; - TimeDuration mRpcTimeTotal; - TimeDuration mSpamTimeTotal; - - int mPPTrialsToGo; - int mPP5TrialsToGo; - uint32_t mNumChildProcessedCompressedSpams; - uint32_t mWhichPong5; -}; - -class TestLatencyChild : public PTestLatencyChild { - friend class PTestLatencyChild; - - public: - TestLatencyChild(); - virtual ~TestLatencyChild(); - - protected: - mozilla::ipc::IPCResult RecvPing(); - mozilla::ipc::IPCResult RecvPing5(); - mozilla::ipc::IPCResult AnswerRpc(); - mozilla::ipc::IPCResult RecvSpam(); - mozilla::ipc::IPCResult AnswerSynchro(); - mozilla::ipc::IPCResult RecvCompressedSpam(const uint32_t& seqno); - mozilla::ipc::IPCResult AnswerSynchro2(uint32_t* lastSeqno, - uint32_t* numMessagesDispatched); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - QuitChild(); - } - - uint32_t mLastSeqno; - uint32_t mNumProcessedCompressedSpams; - uint32_t mWhichPing5; -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestLatency_h diff --git a/ipc/ipdl/test/cxx/TestManyChildAllocs.cpp b/ipc/ipdl/test/cxx/TestManyChildAllocs.cpp deleted file mode 100644 index 77d5786cfa..0000000000 --- a/ipc/ipdl/test/cxx/TestManyChildAllocs.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#include "TestManyChildAllocs.h" - -#include "IPDLUnitTests.h" // fail etc. - -#define NALLOCS 10 - -namespace mozilla { -namespace _ipdltest { - -// parent code - -TestManyChildAllocsParent::TestManyChildAllocsParent() { - MOZ_COUNT_CTOR(TestManyChildAllocsParent); -} - -TestManyChildAllocsParent::~TestManyChildAllocsParent() { - MOZ_COUNT_DTOR(TestManyChildAllocsParent); -} - -void TestManyChildAllocsParent::Main() { - if (!SendGo()) fail("can't send Go()"); -} - -mozilla::ipc::IPCResult TestManyChildAllocsParent::RecvDone() { - // explicitly *not* cleaning up, so we can sanity-check IPDL's - // auto-shutdown/cleanup handling - Close(); - - return IPC_OK(); -} - -bool TestManyChildAllocsParent::DeallocPTestManyChildAllocsSubParent( - PTestManyChildAllocsSubParent* __a) { - delete __a; - return true; -} - -PTestManyChildAllocsSubParent* -TestManyChildAllocsParent::AllocPTestManyChildAllocsSubParent() { - return new TestManyChildAllocsSubParent(); -} - -// child code - -TestManyChildAllocsChild::TestManyChildAllocsChild() { - MOZ_COUNT_CTOR(TestManyChildAllocsChild); -} - -TestManyChildAllocsChild::~TestManyChildAllocsChild() { - MOZ_COUNT_DTOR(TestManyChildAllocsChild); -} - -mozilla::ipc::IPCResult TestManyChildAllocsChild::RecvGo() { - for (int i = 0; i < NALLOCS; ++i) { - PTestManyChildAllocsSubChild* child = - SendPTestManyChildAllocsSubConstructor(); - - if (!child) fail("can't send ctor()"); - - if (!child->SendHello()) fail("can't send Hello()"); - } - - size_t len = ManagedPTestManyChildAllocsSubChild().Count(); - if (NALLOCS != len) fail("expected %lu kids, got %lu", NALLOCS, len); - - if (!SendDone()) fail("can't send Done()"); - - return IPC_OK(); -} - -bool TestManyChildAllocsChild::DeallocPTestManyChildAllocsSubChild( - PTestManyChildAllocsSubChild* __a) { - delete __a; - return true; -} - -PTestManyChildAllocsSubChild* -TestManyChildAllocsChild::AllocPTestManyChildAllocsSubChild() { - return new TestManyChildAllocsSubChild(); -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestManyChildAllocs.h b/ipc/ipdl/test/cxx/TestManyChildAllocs.h deleted file mode 100644 index 3da6461810..0000000000 --- a/ipc/ipdl/test/cxx/TestManyChildAllocs.h +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef mozilla__ipdltest_TestManyChildAllocs_h -#define mozilla__ipdltest_TestManyChildAllocs_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestManyChildAllocsParent.h" -#include "mozilla/_ipdltest/PTestManyChildAllocsChild.h" - -#include "mozilla/_ipdltest/PTestManyChildAllocsSubParent.h" -#include "mozilla/_ipdltest/PTestManyChildAllocsSubChild.h" - -namespace mozilla { -namespace _ipdltest { - -// top-level protocol - -class TestManyChildAllocsParent : public PTestManyChildAllocsParent { - friend class PTestManyChildAllocsParent; - - public: - TestManyChildAllocsParent(); - virtual ~TestManyChildAllocsParent(); - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return true; } - - void Main(); - - protected: - mozilla::ipc::IPCResult RecvDone(); - bool DeallocPTestManyChildAllocsSubParent(PTestManyChildAllocsSubParent* __a); - PTestManyChildAllocsSubParent* AllocPTestManyChildAllocsSubParent(); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - passed("ok"); - QuitParent(); - } -}; - -class TestManyChildAllocsChild : public PTestManyChildAllocsChild { - friend class PTestManyChildAllocsChild; - - public: - TestManyChildAllocsChild(); - virtual ~TestManyChildAllocsChild(); - - protected: - mozilla::ipc::IPCResult RecvGo(); - bool DeallocPTestManyChildAllocsSubChild(PTestManyChildAllocsSubChild* __a); - PTestManyChildAllocsSubChild* AllocPTestManyChildAllocsSubChild(); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - QuitChild(); - } -}; - -// do-nothing sub-protocol actors - -class TestManyChildAllocsSubParent : public PTestManyChildAllocsSubParent { - friend class PTestManyChildAllocsSubParent; - - public: - TestManyChildAllocsSubParent() {} - virtual ~TestManyChildAllocsSubParent() {} - - protected: - virtual void ActorDestroy(ActorDestroyReason why) override {} - mozilla::ipc::IPCResult RecvHello() { return IPC_OK(); } -}; - -class TestManyChildAllocsSubChild : public PTestManyChildAllocsSubChild { - public: - TestManyChildAllocsSubChild() {} - virtual ~TestManyChildAllocsSubChild() {} -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestManyChildAllocs_h diff --git a/ipc/ipdl/test/cxx/TestMultiMgrs.cpp b/ipc/ipdl/test/cxx/TestMultiMgrs.cpp deleted file mode 100644 index f09bb9ca7b..0000000000 --- a/ipc/ipdl/test/cxx/TestMultiMgrs.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#include "TestMultiMgrs.h" - -#include "IPDLUnitTests.h" // fail etc. -#include "mozilla/ipc/ProtocolUtils.h" - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// parent - -void TestMultiMgrsParent::Main() { - TestMultiMgrsLeftParent* leftie = new TestMultiMgrsLeftParent(); - if (!SendPTestMultiMgrsLeftConstructor(leftie)) fail("error sending ctor"); - - TestMultiMgrsRightParent* rightie = new TestMultiMgrsRightParent(); - if (!SendPTestMultiMgrsRightConstructor(rightie)) fail("error sending ctor"); - - TestMultiMgrsBottomParent* bottomL = new TestMultiMgrsBottomParent(); - if (!leftie->SendPTestMultiMgrsBottomConstructor(bottomL)) - fail("error sending ctor"); - - TestMultiMgrsBottomParent* bottomR = new TestMultiMgrsBottomParent(); - if (!rightie->SendPTestMultiMgrsBottomConstructor(bottomR)) - fail("error sending ctor"); - - if (!leftie->HasChild(bottomL)) - fail("leftie didn't have a child it was supposed to!"); - if (leftie->HasChild(bottomR)) fail("leftie had rightie's child!"); - - if (!rightie->HasChild(bottomR)) - fail("rightie didn't have a child it was supposed to!"); - if (rightie->HasChild(bottomL)) fail("rightie had rightie's child!"); - - if (!SendCheck()) fail("couldn't kick off the child-side check"); -} - -mozilla::ipc::IPCResult TestMultiMgrsParent::RecvOK() { - Close(); - return IPC_OK(); -} - -//----------------------------------------------------------------------------- -// child - -mozilla::ipc::IPCResult -TestMultiMgrsLeftChild::RecvPTestMultiMgrsBottomConstructor( - PTestMultiMgrsBottomChild* actor) { - static_cast(Manager())->mBottomL = actor; - return IPC_OK(); -} - -mozilla::ipc::IPCResult -TestMultiMgrsRightChild::RecvPTestMultiMgrsBottomConstructor( - PTestMultiMgrsBottomChild* actor) { - static_cast(Manager())->mBottomR = actor; - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestMultiMgrsChild::RecvCheck() { - if (1 != ManagedPTestMultiMgrsLeftChild().Count()) fail("where's leftie?"); - if (1 != ManagedPTestMultiMgrsRightChild().Count()) fail("where's rightie?"); - - TestMultiMgrsLeftChild* leftie = static_cast( - LoneManagedOrNullAsserts(ManagedPTestMultiMgrsLeftChild())); - TestMultiMgrsRightChild* rightie = static_cast( - LoneManagedOrNullAsserts(ManagedPTestMultiMgrsRightChild())); - - if (!leftie->HasChild(mBottomL)) - fail("leftie didn't have a child it was supposed to!"); - if (leftie->HasChild(mBottomR)) fail("leftie had rightie's child!"); - - if (!rightie->HasChild(mBottomR)) - fail("rightie didn't have a child it was supposed to!"); - if (rightie->HasChild(mBottomL)) fail("rightie had leftie's child!"); - - if (!SendOK()) fail("couldn't send OK()"); - - return IPC_OK(); -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestMultiMgrs.h b/ipc/ipdl/test/cxx/TestMultiMgrs.h deleted file mode 100644 index 71826d42a7..0000000000 --- a/ipc/ipdl/test/cxx/TestMultiMgrs.h +++ /dev/null @@ -1,222 +0,0 @@ -#ifndef mozilla__ipdltest_TestMultiMgrs_h -#define mozilla__ipdltest_TestMultiMgrs_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestMultiMgrsParent.h" -#include "mozilla/_ipdltest/PTestMultiMgrsChild.h" -#include "mozilla/_ipdltest/PTestMultiMgrsBottomParent.h" -#include "mozilla/_ipdltest/PTestMultiMgrsBottomChild.h" -#include "mozilla/_ipdltest/PTestMultiMgrsLeftParent.h" -#include "mozilla/_ipdltest/PTestMultiMgrsLeftChild.h" -#include "mozilla/_ipdltest/PTestMultiMgrsRightParent.h" -#include "mozilla/_ipdltest/PTestMultiMgrsRightChild.h" - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// Parent side -// - -class TestMultiMgrsBottomParent : public PTestMultiMgrsBottomParent { - public: - TestMultiMgrsBottomParent() {} - virtual ~TestMultiMgrsBottomParent() {} - - protected: - virtual void ActorDestroy(ActorDestroyReason why) override {} -}; - -class TestMultiMgrsLeftParent : public PTestMultiMgrsLeftParent { - friend class PTestMultiMgrsLeftParent; - - public: - TestMultiMgrsLeftParent() {} - virtual ~TestMultiMgrsLeftParent() {} - - bool HasChild(TestMultiMgrsBottomParent* c) { - return ManagedPTestMultiMgrsBottomParent().Contains(c); - } - - protected: - virtual void ActorDestroy(ActorDestroyReason why) override {} - - PTestMultiMgrsBottomParent* AllocPTestMultiMgrsBottomParent() { - return new TestMultiMgrsBottomParent(); - } - - bool DeallocPTestMultiMgrsBottomParent(PTestMultiMgrsBottomParent* actor) { - delete actor; - return true; - } -}; - -class TestMultiMgrsRightParent : public PTestMultiMgrsRightParent { - friend class PTestMultiMgrsRightParent; - - public: - TestMultiMgrsRightParent() {} - virtual ~TestMultiMgrsRightParent() {} - - bool HasChild(TestMultiMgrsBottomParent* c) { - return ManagedPTestMultiMgrsBottomParent().Contains(c); - } - - protected: - virtual void ActorDestroy(ActorDestroyReason why) override {} - - PTestMultiMgrsBottomParent* AllocPTestMultiMgrsBottomParent() { - return new TestMultiMgrsBottomParent(); - } - - bool DeallocPTestMultiMgrsBottomParent(PTestMultiMgrsBottomParent* actor) { - delete actor; - return true; - } -}; - -class TestMultiMgrsParent : public PTestMultiMgrsParent { - friend class PTestMultiMgrsParent; - - public: - TestMultiMgrsParent() {} - virtual ~TestMultiMgrsParent() {} - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return true; } - - void Main(); - - protected: - mozilla::ipc::IPCResult RecvOK(); - - PTestMultiMgrsLeftParent* AllocPTestMultiMgrsLeftParent() { - return new TestMultiMgrsLeftParent(); - } - - bool DeallocPTestMultiMgrsLeftParent(PTestMultiMgrsLeftParent* actor) { - delete actor; - return true; - } - - PTestMultiMgrsRightParent* AllocPTestMultiMgrsRightParent() { - return new TestMultiMgrsRightParent(); - } - - bool DeallocPTestMultiMgrsRightParent(PTestMultiMgrsRightParent* actor) { - delete actor; - return true; - } - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - passed("ok"); - QuitParent(); - } -}; - -//----------------------------------------------------------------------------- -// Child side -// - -class TestMultiMgrsBottomChild : public PTestMultiMgrsBottomChild { - public: - TestMultiMgrsBottomChild() {} - virtual ~TestMultiMgrsBottomChild() {} -}; - -class TestMultiMgrsLeftChild : public PTestMultiMgrsLeftChild { - friend class PTestMultiMgrsLeftChild; - - public: - TestMultiMgrsLeftChild() {} - virtual ~TestMultiMgrsLeftChild() {} - - bool HasChild(PTestMultiMgrsBottomChild* c) { - return ManagedPTestMultiMgrsBottomChild().Contains(c); - } - - protected: - virtual mozilla::ipc::IPCResult RecvPTestMultiMgrsBottomConstructor( - PTestMultiMgrsBottomChild* actor) override; - - PTestMultiMgrsBottomChild* AllocPTestMultiMgrsBottomChild() { - return new TestMultiMgrsBottomChild(); - } - - bool DeallocPTestMultiMgrsBottomChild(PTestMultiMgrsBottomChild* actor) { - delete actor; - return true; - } -}; - -class TestMultiMgrsRightChild : public PTestMultiMgrsRightChild { - friend class PTestMultiMgrsRightChild; - - public: - TestMultiMgrsRightChild() {} - virtual ~TestMultiMgrsRightChild() {} - - bool HasChild(PTestMultiMgrsBottomChild* c) { - return ManagedPTestMultiMgrsBottomChild().Contains(c); - } - - protected: - virtual mozilla::ipc::IPCResult RecvPTestMultiMgrsBottomConstructor( - PTestMultiMgrsBottomChild* actor) override; - - PTestMultiMgrsBottomChild* AllocPTestMultiMgrsBottomChild() { - return new TestMultiMgrsBottomChild(); - } - - bool DeallocPTestMultiMgrsBottomChild(PTestMultiMgrsBottomChild* actor) { - delete actor; - return true; - } -}; - -class TestMultiMgrsChild : public PTestMultiMgrsChild { - friend class PTestMultiMgrsChild; - - public: - TestMultiMgrsChild() {} - virtual ~TestMultiMgrsChild() {} - - void Main(); - - PTestMultiMgrsBottomChild* mBottomL; - PTestMultiMgrsBottomChild* mBottomR; - - protected: - mozilla::ipc::IPCResult RecvCheck(); - - PTestMultiMgrsLeftChild* AllocPTestMultiMgrsLeftChild() { - return new TestMultiMgrsLeftChild(); - } - - bool DeallocPTestMultiMgrsLeftChild(PTestMultiMgrsLeftChild* actor) { - delete actor; - return true; - } - - PTestMultiMgrsRightChild* AllocPTestMultiMgrsRightChild() { - return new TestMultiMgrsRightChild(); - } - - bool DeallocPTestMultiMgrsRightChild(PTestMultiMgrsRightChild* actor) { - delete actor; - return true; - } - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - passed("ok"); - QuitChild(); - } -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestMultiMgrs_h diff --git a/ipc/ipdl/test/cxx/TestNestedLoops.cpp b/ipc/ipdl/test/cxx/TestNestedLoops.cpp deleted file mode 100644 index 3658d7dfb6..0000000000 --- a/ipc/ipdl/test/cxx/TestNestedLoops.cpp +++ /dev/null @@ -1,78 +0,0 @@ -#include "base/basictypes.h" - -#include "nsThreadUtils.h" - -#include "TestNestedLoops.h" - -#include "IPDLUnitTests.h" // fail etc. - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// parent - -TestNestedLoopsParent::TestNestedLoopsParent() : mBreakNestedLoop(false) { - MOZ_COUNT_CTOR(TestNestedLoopsParent); -} - -TestNestedLoopsParent::~TestNestedLoopsParent() { - MOZ_COUNT_DTOR(TestNestedLoopsParent); -} - -void TestNestedLoopsParent::Main() { - if (!SendStart()) fail("sending Start"); - - // sigh ... spin for a while to let Nonce arrive - puts(" (sleeping to wait for nonce ... sorry)"); - PR_Sleep(5000); - - // while waiting for the reply to R, we'll receive Nonce - if (!CallR()) fail("calling R"); - - Close(); -} - -mozilla::ipc::IPCResult TestNestedLoopsParent::RecvNonce() { - // if we have an OnMaybeDequeueOne waiting for us (we may not, due - // to the inherent race condition in this test, then this event - // must be ordered after it in the queue - MessageLoop::current()->PostTask(NewNonOwningRunnableMethod( - "_ipdltest::TestNestedLoopsParent::BreakNestedLoop", this, - &TestNestedLoopsParent::BreakNestedLoop)); - - // sigh ... spin for a while to let the reply to R arrive - puts(" (sleeping to wait for reply to R ... sorry)"); - PR_Sleep(5000); - - // sigh ... we have no idea when code might do this - do { - if (!NS_ProcessNextEvent(nullptr, false)) - fail("expected at least one pending event"); - } while (!mBreakNestedLoop); - - return IPC_OK(); -} - -void TestNestedLoopsParent::BreakNestedLoop() { mBreakNestedLoop = true; } - -//----------------------------------------------------------------------------- -// child - -TestNestedLoopsChild::TestNestedLoopsChild() { - MOZ_COUNT_CTOR(TestNestedLoopsChild); -} - -TestNestedLoopsChild::~TestNestedLoopsChild() { - MOZ_COUNT_DTOR(TestNestedLoopsChild); -} - -mozilla::ipc::IPCResult TestNestedLoopsChild::RecvStart() { - if (!SendNonce()) fail("sending Nonce"); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestNestedLoopsChild::AnswerR() { return IPC_OK(); } - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestNestedLoops.h b/ipc/ipdl/test/cxx/TestNestedLoops.h deleted file mode 100644 index 001b571494..0000000000 --- a/ipc/ipdl/test/cxx/TestNestedLoops.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef mozilla__ipdltest_TestNestedLoops_h -#define mozilla__ipdltest_TestNestedLoops_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestNestedLoopsParent.h" -#include "mozilla/_ipdltest/PTestNestedLoopsChild.h" - -namespace mozilla { -namespace _ipdltest { - -class TestNestedLoopsParent : public PTestNestedLoopsParent { - friend class PTestNestedLoopsParent; - - public: - TestNestedLoopsParent(); - virtual ~TestNestedLoopsParent(); - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return true; } - - void Main(); - - protected: - mozilla::ipc::IPCResult RecvNonce(); - - void BreakNestedLoop(); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - passed("ok"); - QuitParent(); - } - - bool mBreakNestedLoop; -}; - -class TestNestedLoopsChild : public PTestNestedLoopsChild { - friend class PTestNestedLoopsChild; - - public: - TestNestedLoopsChild(); - virtual ~TestNestedLoopsChild(); - - protected: - mozilla::ipc::IPCResult RecvStart(); - - mozilla::ipc::IPCResult AnswerR(); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - QuitChild(); - } -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestNestedLoops_h diff --git a/ipc/ipdl/test/cxx/TestRPC.cpp b/ipc/ipdl/test/cxx/TestRPC.cpp deleted file mode 100644 index cf7a1b6c36..0000000000 --- a/ipc/ipdl/test/cxx/TestRPC.cpp +++ /dev/null @@ -1,107 +0,0 @@ -#include "TestRPC.h" - -#include "IPDLUnitTests.h" // fail etc. -#if defined(XP_UNIX) -# include -#else -# include -#endif - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// parent - -TestRPCParent::TestRPCParent() - : reentered_(false), resolved_first_cpow_(false) { - MOZ_COUNT_CTOR(TestRPCParent); -} - -TestRPCParent::~TestRPCParent() { MOZ_COUNT_DTOR(TestRPCParent); } - -void TestRPCParent::Main() { - if (!SendStart()) fail("sending Start"); -} - -mozilla::ipc::IPCResult TestRPCParent::RecvTest1_Start(uint32_t* aResult) { - uint32_t result; - if (!SendTest1_InnerQuery(&result)) fail("SendTest1_InnerQuery"); - if (result != 300) fail("Wrong result (expected 300)"); - - *aResult = 100; - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestRPCParent::RecvTest1_InnerEvent(uint32_t* aResult) { - uint32_t result; - if (!SendTest1_NoReenter(&result)) fail("SendTest1_NoReenter"); - if (result != 400) fail("Wrong result (expected 400)"); - - *aResult = 200; - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestRPCParent::RecvTest2_Start() { - // Send a CPOW. During this time, we must NOT process the RPC message, as - // we could start receiving CPOW replies out-of-order. - if (!SendTest2_FirstUrgent()) fail("SendTest2_FirstUrgent"); - - MOZ_ASSERT(!reentered_); - resolved_first_cpow_ = true; - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestRPCParent::RecvTest2_OutOfOrder() { - // Send a CPOW. If this RPC call was initiated while waiting for the first - // CPOW to resolve, replies will be processed out of order, and we'll crash. - if (!SendTest2_SecondUrgent()) fail("SendTest2_SecondUrgent"); - - reentered_ = true; - return IPC_OK(); -} - -//----------------------------------------------------------------------------- -// child - -TestRPCChild::TestRPCChild() { MOZ_COUNT_CTOR(TestRPCChild); } - -TestRPCChild::~TestRPCChild() { MOZ_COUNT_DTOR(TestRPCChild); } - -mozilla::ipc::IPCResult TestRPCChild::RecvStart() { - uint32_t result; - if (!SendTest1_Start(&result)) fail("SendTest1_Start"); - if (result != 100) fail("Wrong result (expected 100)"); - - if (!SendTest2_Start()) fail("SendTest2_Start"); - - if (!SendTest2_OutOfOrder()) fail("SendTest2_OutOfOrder"); - - Close(); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestRPCChild::RecvTest1_InnerQuery(uint32_t* aResult) { - uint32_t result; - if (!SendTest1_InnerEvent(&result)) fail("SendTest1_InnerEvent"); - if (result != 200) fail("Wrong result (expected 200)"); - - *aResult = 300; - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestRPCChild::RecvTest1_NoReenter(uint32_t* aResult) { - *aResult = 400; - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestRPCChild::RecvTest2_FirstUrgent() { - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestRPCChild::RecvTest2_SecondUrgent() { - return IPC_OK(); -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestRPC.h b/ipc/ipdl/test/cxx/TestRPC.h deleted file mode 100644 index 907d3fde36..0000000000 --- a/ipc/ipdl/test/cxx/TestRPC.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef mozilla__ipdltest_TestRPC_h -#define mozilla__ipdltest_TestRPC_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestRPCParent.h" -#include "mozilla/_ipdltest/PTestRPCChild.h" - -namespace mozilla { -namespace _ipdltest { - -class TestRPCParent : public PTestRPCParent { - public: - TestRPCParent(); - virtual ~TestRPCParent(); - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return false; } - - void Main(); - - mozilla::ipc::IPCResult RecvTest1_Start(uint32_t* aResult); - mozilla::ipc::IPCResult RecvTest1_InnerEvent(uint32_t* aResult); - mozilla::ipc::IPCResult RecvTest2_Start(); - mozilla::ipc::IPCResult RecvTest2_OutOfOrder(); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - if (!reentered_) fail("never processed raced RPC call!"); - if (!resolved_first_cpow_) fail("never resolved first CPOW!"); - passed("ok"); - QuitParent(); - } - - private: - bool reentered_; - bool resolved_first_cpow_; -}; - -class TestRPCChild : public PTestRPCChild { - public: - TestRPCChild(); - virtual ~TestRPCChild(); - - mozilla::ipc::IPCResult RecvStart(); - mozilla::ipc::IPCResult RecvTest1_InnerQuery(uint32_t* aResult); - mozilla::ipc::IPCResult RecvTest1_NoReenter(uint32_t* aResult); - mozilla::ipc::IPCResult RecvTest2_FirstUrgent(); - mozilla::ipc::IPCResult RecvTest2_SecondUrgent(); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - QuitChild(); - } -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestRPC_h diff --git a/ipc/ipdl/test/cxx/TestRaceDeadlock.cpp b/ipc/ipdl/test/cxx/TestRaceDeadlock.cpp deleted file mode 100644 index 76defe97a5..0000000000 --- a/ipc/ipdl/test/cxx/TestRaceDeadlock.cpp +++ /dev/null @@ -1,102 +0,0 @@ -#include "TestRaceDeadlock.h" - -#include "IPDLUnitTests.h" // fail etc. - -// #define TEST_TIMEOUT 5000 - -using namespace mozilla::ipc; -typedef mozilla::ipc::MessageChannel::Message Message; -typedef mozilla::ipc::MessageChannel::MessageInfo MessageInfo; - -namespace mozilla { -namespace _ipdltest { - -static RacyInterruptPolicy MediateRace(const MessageInfo& parent, - const MessageInfo& child) { - return (PTestRaceDeadlock::Msg_Win__ID == parent.type()) ? RIPParentWins - : RIPChildWins; -} - -//----------------------------------------------------------------------------- -// parent - -TestRaceDeadlockParent::TestRaceDeadlockParent() { - MOZ_COUNT_CTOR(TestRaceDeadlockParent); -} - -TestRaceDeadlockParent::~TestRaceDeadlockParent() { - MOZ_COUNT_DTOR(TestRaceDeadlockParent); -} - -void TestRaceDeadlockParent::Main() { - Test1(); - - Close(); -} - -bool TestRaceDeadlockParent::ShouldContinueFromReplyTimeout() { - fail("This test should not hang"); - GetIPCChannel()->CloseWithTimeout(); - return false; -} - -void TestRaceDeadlockParent::Test1() { -#if defined(TEST_TIMEOUT) - SetReplyTimeoutMs(TEST_TIMEOUT); -#endif - if (!SendStartRace()) { - fail("sending StartRace"); - } - if (!CallRpc()) { - fail("calling Rpc"); - } -} - -mozilla::ipc::IPCResult TestRaceDeadlockParent::AnswerLose() { - return IPC_OK(); -} - -RacyInterruptPolicy TestRaceDeadlockParent::MediateInterruptRace( - const MessageInfo& parent, const MessageInfo& child) { - return MediateRace(parent, child); -} - -//----------------------------------------------------------------------------- -// child - -TestRaceDeadlockChild::TestRaceDeadlockChild() { - MOZ_COUNT_CTOR(TestRaceDeadlockChild); -} - -TestRaceDeadlockChild::~TestRaceDeadlockChild() { - MOZ_COUNT_DTOR(TestRaceDeadlockChild); -} - -mozilla::ipc::IPCResult TestRaceDeadlockParent::RecvStartRace() { - if (!CallWin()) { - fail("calling Win"); - } - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestRaceDeadlockChild::RecvStartRace() { - if (!SendStartRace()) { - fail("calling SendStartRace"); - } - if (!CallLose()) { - fail("calling Lose"); - } - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestRaceDeadlockChild::AnswerWin() { return IPC_OK(); } - -mozilla::ipc::IPCResult TestRaceDeadlockChild::AnswerRpc() { return IPC_OK(); } - -RacyInterruptPolicy TestRaceDeadlockChild::MediateInterruptRace( - const MessageInfo& parent, const MessageInfo& child) { - return MediateRace(parent, child); -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestRaceDeadlock.h b/ipc/ipdl/test/cxx/TestRaceDeadlock.h deleted file mode 100644 index 2c5617130d..0000000000 --- a/ipc/ipdl/test/cxx/TestRaceDeadlock.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef mozilla__ipdltest_TestRaceDeadlock_h -#define mozilla__ipdltest_TestRaceDeadlock_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestRaceDeadlockParent.h" -#include "mozilla/_ipdltest/PTestRaceDeadlockChild.h" - -namespace mozilla { -namespace _ipdltest { - -class TestRaceDeadlockParent : public PTestRaceDeadlockParent { - friend class PTestRaceDeadlockParent; - - public: - TestRaceDeadlockParent(); - virtual ~TestRaceDeadlockParent(); - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return true; } - - void Main(); - - protected: - virtual bool ShouldContinueFromReplyTimeout() override; - - void Test1(); - - mozilla::ipc::IPCResult RecvStartRace(); - mozilla::ipc::IPCResult AnswerLose(); - - virtual mozilla::ipc::RacyInterruptPolicy MediateInterruptRace( - const MessageInfo& parent, const MessageInfo& child) override; - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - passed("ok"); - QuitParent(); - } -}; - -class TestRaceDeadlockChild : public PTestRaceDeadlockChild { - friend class PTestRaceDeadlockChild; - - public: - TestRaceDeadlockChild(); - virtual ~TestRaceDeadlockChild(); - - protected: - mozilla::ipc::IPCResult RecvStartRace(); - - mozilla::ipc::IPCResult AnswerWin(); - - mozilla::ipc::IPCResult AnswerRpc(); - - virtual mozilla::ipc::RacyInterruptPolicy MediateInterruptRace( - const MessageInfo& parent, const MessageInfo& child) override; - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - QuitChild(); - } -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestRaceDeadlock_h diff --git a/ipc/ipdl/test/cxx/TestRaceDeferral.cpp b/ipc/ipdl/test/cxx/TestRaceDeferral.cpp deleted file mode 100644 index c327b57c16..0000000000 --- a/ipc/ipdl/test/cxx/TestRaceDeferral.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include "TestRaceDeferral.h" - -#include "IPDLUnitTests.h" // fail etc. - -using namespace mozilla::ipc; -typedef mozilla::ipc::MessageChannel::Message Message; -typedef mozilla::ipc::MessageChannel::MessageInfo MessageInfo; - -namespace mozilla { -namespace _ipdltest { - -static RacyInterruptPolicy MediateRace(const MessageInfo& parent, - const MessageInfo& child) { - return (PTestRaceDeferral::Msg_Win__ID == parent.type()) ? RIPParentWins - : RIPChildWins; -} - -//----------------------------------------------------------------------------- -// parent - -TestRaceDeferralParent::TestRaceDeferralParent() : mProcessedLose(false) { - MOZ_COUNT_CTOR(TestRaceDeferralParent); -} - -TestRaceDeferralParent::~TestRaceDeferralParent() { - MOZ_COUNT_DTOR(TestRaceDeferralParent); - - if (!mProcessedLose) fail("never processed Lose"); -} - -void TestRaceDeferralParent::Main() { - Test1(); - - Close(); -} - -void TestRaceDeferralParent::Test1() { - if (!SendStartRace()) fail("sending StartRace"); - - if (!CallWin()) fail("calling Win"); - if (mProcessedLose) fail("Lose didn't lose"); - - if (!CallRpc()) fail("calling Rpc"); - if (!mProcessedLose) fail("didn't resolve Rpc vs. Lose 'race' correctly"); -} - -mozilla::ipc::IPCResult TestRaceDeferralParent::AnswerLose() { - if (mProcessedLose) fail("processed Lose twice"); - mProcessedLose = true; - return IPC_OK(); -} - -RacyInterruptPolicy TestRaceDeferralParent::MediateInterruptRace( - const MessageInfo& parent, const MessageInfo& child) { - return MediateRace(parent, child); -} - -//----------------------------------------------------------------------------- -// child - -TestRaceDeferralChild::TestRaceDeferralChild() { - MOZ_COUNT_CTOR(TestRaceDeferralChild); -} - -TestRaceDeferralChild::~TestRaceDeferralChild() { - MOZ_COUNT_DTOR(TestRaceDeferralChild); -} - -mozilla::ipc::IPCResult TestRaceDeferralChild::RecvStartRace() { - if (!CallLose()) fail("calling Lose"); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestRaceDeferralChild::AnswerWin() { return IPC_OK(); } - -mozilla::ipc::IPCResult TestRaceDeferralChild::AnswerRpc() { return IPC_OK(); } - -RacyInterruptPolicy TestRaceDeferralChild::MediateInterruptRace( - const MessageInfo& parent, const MessageInfo& child) { - return MediateRace(parent, child); -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestRaceDeferral.h b/ipc/ipdl/test/cxx/TestRaceDeferral.h deleted file mode 100644 index b30264fb64..0000000000 --- a/ipc/ipdl/test/cxx/TestRaceDeferral.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef mozilla__ipdltest_TestRaceDeferral_h -#define mozilla__ipdltest_TestRaceDeferral_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestRaceDeferralParent.h" -#include "mozilla/_ipdltest/PTestRaceDeferralChild.h" - -namespace mozilla { -namespace _ipdltest { - -class TestRaceDeferralParent : public PTestRaceDeferralParent { - friend class PTestRaceDeferralParent; - - public: - TestRaceDeferralParent(); - virtual ~TestRaceDeferralParent(); - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return true; } - - void Main(); - - protected: - void Test1(); - - mozilla::ipc::IPCResult AnswerLose(); - - virtual mozilla::ipc::RacyInterruptPolicy MediateInterruptRace( - const MessageInfo& parent, const MessageInfo& child) override; - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - passed("ok"); - QuitParent(); - } - - bool mProcessedLose; -}; - -class TestRaceDeferralChild : public PTestRaceDeferralChild { - friend class PTestRaceDeferralChild; - - public: - TestRaceDeferralChild(); - virtual ~TestRaceDeferralChild(); - - protected: - mozilla::ipc::IPCResult RecvStartRace(); - - mozilla::ipc::IPCResult AnswerWin(); - - mozilla::ipc::IPCResult AnswerRpc(); - - virtual mozilla::ipc::RacyInterruptPolicy MediateInterruptRace( - const MessageInfo& parent, const MessageInfo& child) override; - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - QuitChild(); - } -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestRaceDeferral_h diff --git a/ipc/ipdl/test/cxx/TestRacyInterruptReplies.cpp b/ipc/ipdl/test/cxx/TestRacyInterruptReplies.cpp deleted file mode 100644 index cda950b1a1..0000000000 --- a/ipc/ipdl/test/cxx/TestRacyInterruptReplies.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include "TestRacyInterruptReplies.h" - -#include "IPDLUnitTests.h" // fail etc. - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// parent - -TestRacyInterruptRepliesParent::TestRacyInterruptRepliesParent() - : mReplyNum(0) { - MOZ_COUNT_CTOR(TestRacyInterruptRepliesParent); -} - -TestRacyInterruptRepliesParent::~TestRacyInterruptRepliesParent() { - MOZ_COUNT_DTOR(TestRacyInterruptRepliesParent); -} - -void TestRacyInterruptRepliesParent::Main() { - int replyNum = -1; - if (!CallR_(&replyNum)) fail("calling R()"); - - if (1 != replyNum) fail("this should have been the first reply to R()"); - - if (!SendChildTest()) fail("sending ChildStart"); -} - -mozilla::ipc::IPCResult TestRacyInterruptRepliesParent::RecvA_() { - int replyNum = -1; - // this R() call races with the reply being generated by the other - // side to the R() call from Main(). This is a pretty nasty edge - // case for which one could argue we're breaking in-order message - // delivery, since this side will process the second reply to R() - // before the first. - if (!CallR_(&replyNum)) fail("calling R()"); - - if (2 != replyNum) fail("this should have been the second reply to R()"); - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestRacyInterruptRepliesParent::Answer_R( - int* replyNum) { - *replyNum = ++mReplyNum; - - if (1 == *replyNum) - if (!Send_A()) fail("sending _A()"); - - return IPC_OK(); -} - -//----------------------------------------------------------------------------- -// child - -TestRacyInterruptRepliesChild::TestRacyInterruptRepliesChild() : mReplyNum(0) { - MOZ_COUNT_CTOR(TestRacyInterruptRepliesChild); -} - -TestRacyInterruptRepliesChild::~TestRacyInterruptRepliesChild() { - MOZ_COUNT_DTOR(TestRacyInterruptRepliesChild); -} - -mozilla::ipc::IPCResult TestRacyInterruptRepliesChild::AnswerR_(int* replyNum) { - *replyNum = ++mReplyNum; - - if (1 == *replyNum) SendA_(); - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestRacyInterruptRepliesChild::RecvChildTest() { - int replyNum = -1; - if (!Call_R(&replyNum)) fail("calling R()"); - - if (1 != replyNum) fail("this should have been the first reply to R()"); - - Close(); - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestRacyInterruptRepliesChild::Recv_A() { - int replyNum = -1; - - if (!Call_R(&replyNum)) fail("calling _R()"); - - if (2 != replyNum) fail("this should have been the second reply to R()"); - - return IPC_OK(); -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestRacyInterruptReplies.h b/ipc/ipdl/test/cxx/TestRacyInterruptReplies.h deleted file mode 100644 index 182c07f314..0000000000 --- a/ipc/ipdl/test/cxx/TestRacyInterruptReplies.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef mozilla__ipdltest_TestRacyInterruptReplies_h -#define mozilla__ipdltest_TestRacyInterruptReplies_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestRacyInterruptRepliesParent.h" -#include "mozilla/_ipdltest/PTestRacyInterruptRepliesChild.h" - -namespace mozilla { -namespace _ipdltest { - -class TestRacyInterruptRepliesParent : public PTestRacyInterruptRepliesParent { - friend class PTestRacyInterruptRepliesParent; - - public: - TestRacyInterruptRepliesParent(); - virtual ~TestRacyInterruptRepliesParent(); - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return true; } - - void Main(); - - protected: - mozilla::ipc::IPCResult RecvA_(); - - mozilla::ipc::IPCResult Answer_R(int* replyNum); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - passed("ok"); - QuitParent(); - } - - private: - int mReplyNum; -}; - -class TestRacyInterruptRepliesChild : public PTestRacyInterruptRepliesChild { - friend class PTestRacyInterruptRepliesChild; - - public: - TestRacyInterruptRepliesChild(); - virtual ~TestRacyInterruptRepliesChild(); - - protected: - mozilla::ipc::IPCResult AnswerR_(int* replyNum); - - mozilla::ipc::IPCResult RecvChildTest(); - - mozilla::ipc::IPCResult Recv_A(); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - QuitChild(); - } - - private: - int mReplyNum; -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestRacyInterruptReplies_h diff --git a/ipc/ipdl/test/cxx/TestRacyReentry.cpp b/ipc/ipdl/test/cxx/TestRacyReentry.cpp deleted file mode 100644 index 4224018e11..0000000000 --- a/ipc/ipdl/test/cxx/TestRacyReentry.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "TestRacyReentry.h" - -#include "IPDLUnitTests.h" // fail etc. - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// parent - -TestRacyReentryParent::TestRacyReentryParent() : mRecvdE(false) { - MOZ_COUNT_CTOR(TestRacyReentryParent); -} - -TestRacyReentryParent::~TestRacyReentryParent() { - MOZ_COUNT_DTOR(TestRacyReentryParent); -} - -void TestRacyReentryParent::Main() { - if (!SendStart()) fail("sending Start"); - - if (!SendN()) fail("sending N"); -} - -mozilla::ipc::IPCResult TestRacyReentryParent::AnswerE() { - if (!mRecvdE) { - mRecvdE = true; - return IPC_OK(); - } - - if (!CallH()) fail("calling H"); - - return IPC_OK(); -} - -//----------------------------------------------------------------------------- -// child - -TestRacyReentryChild::TestRacyReentryChild() { - MOZ_COUNT_CTOR(TestRacyReentryChild); -} - -TestRacyReentryChild::~TestRacyReentryChild() { - MOZ_COUNT_DTOR(TestRacyReentryChild); -} - -mozilla::ipc::IPCResult TestRacyReentryChild::RecvStart() { - if (!CallE()) fail("calling E"); - - Close(); - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestRacyReentryChild::RecvN() { - if (!CallE()) fail("calling E"); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestRacyReentryChild::AnswerH() { return IPC_OK(); } - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestRacyReentry.h b/ipc/ipdl/test/cxx/TestRacyReentry.h deleted file mode 100644 index e31f90c0e3..0000000000 --- a/ipc/ipdl/test/cxx/TestRacyReentry.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef mozilla__ipdltest_TestRacyReentry_h -#define mozilla__ipdltest_TestRacyReentry_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestRacyReentryParent.h" -#include "mozilla/_ipdltest/PTestRacyReentryChild.h" - -namespace mozilla { -namespace _ipdltest { - -class TestRacyReentryParent : public PTestRacyReentryParent { - friend class PTestRacyReentryParent; - - public: - TestRacyReentryParent(); - virtual ~TestRacyReentryParent(); - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return true; } - - void Main(); - - protected: - mozilla::ipc::IPCResult AnswerE(); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - passed("ok"); - QuitParent(); - } - - bool mRecvdE; -}; - -class TestRacyReentryChild : public PTestRacyReentryChild { - friend class PTestRacyReentryChild; - - public: - TestRacyReentryChild(); - virtual ~TestRacyReentryChild(); - - protected: - mozilla::ipc::IPCResult RecvStart(); - - mozilla::ipc::IPCResult RecvN(); - - mozilla::ipc::IPCResult AnswerH(); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - QuitChild(); - } -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestRacyReentry_h diff --git a/ipc/ipdl/test/cxx/TestRacyUndefer.cpp b/ipc/ipdl/test/cxx/TestRacyUndefer.cpp deleted file mode 100644 index a46db5618e..0000000000 --- a/ipc/ipdl/test/cxx/TestRacyUndefer.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#include "base/basictypes.h" - -#include "TestRacyUndefer.h" - -#include "IPDLUnitTests.h" // fail etc. - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// parent - -TestRacyUndeferParent::TestRacyUndeferParent() { - MOZ_COUNT_CTOR(TestRacyUndeferParent); -} - -TestRacyUndeferParent::~TestRacyUndeferParent() { - MOZ_COUNT_DTOR(TestRacyUndeferParent); -} - -void TestRacyUndeferParent::Main() { - if (!SendStart()) fail("sending Start"); -} - -mozilla::ipc::IPCResult TestRacyUndeferParent::AnswerSpam() { - static bool spammed = false; - static bool raced = false; - if (!spammed) { - spammed = true; - - if (!SendAwakenSpam()) fail("sending AwakenSpam"); - } else if (!raced) { - raced = true; - - if (!SendAwakenRaceWinTwice()) fail("sending WinRaceTwice"); - - if (!CallRace()) fail("calling Race1"); - } - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestRacyUndeferParent::AnswerRaceWinTwice() { - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestRacyUndeferParent::RecvDone() { - Close(); - return IPC_OK(); -} - -//----------------------------------------------------------------------------- -// child - -TestRacyUndeferChild::TestRacyUndeferChild() { - MOZ_COUNT_CTOR(TestRacyUndeferChild); -} - -TestRacyUndeferChild::~TestRacyUndeferChild() { - MOZ_COUNT_DTOR(TestRacyUndeferChild); -} - -mozilla::ipc::IPCResult TestRacyUndeferChild::RecvStart() { - if (!CallSpam()) fail("calling Spam"); - - if (!SendDone()) fail("sending Done"); - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestRacyUndeferChild::RecvAwakenSpam() { - if (!CallSpam()) fail("calling Spam"); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestRacyUndeferChild::RecvAwakenRaceWinTwice() { - if (!CallRaceWinTwice()) fail("calling RaceWinTwice"); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestRacyUndeferChild::AnswerRace() { return IPC_OK(); } - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestRacyUndefer.h b/ipc/ipdl/test/cxx/TestRacyUndefer.h deleted file mode 100644 index 1e157a541b..0000000000 --- a/ipc/ipdl/test/cxx/TestRacyUndefer.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef mozilla__ipdltest_TestRacyUndefer_h -#define mozilla__ipdltest_TestRacyUndefer_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestRacyUndeferParent.h" -#include "mozilla/_ipdltest/PTestRacyUndeferChild.h" - -namespace mozilla { -namespace _ipdltest { - -class TestRacyUndeferParent : public PTestRacyUndeferParent { - friend class PTestRacyUndeferParent; - - public: - TestRacyUndeferParent(); - virtual ~TestRacyUndeferParent(); - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return true; } - - void Main(); - - protected: - mozilla::ipc::IPCResult AnswerSpam(); - - mozilla::ipc::IPCResult AnswerRaceWinTwice(); - - mozilla::ipc::IPCResult RecvDone(); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - passed("ok"); - QuitParent(); - } -}; - -class TestRacyUndeferChild : public PTestRacyUndeferChild { - friend class PTestRacyUndeferChild; - - public: - TestRacyUndeferChild(); - virtual ~TestRacyUndeferChild(); - - protected: - mozilla::ipc::IPCResult RecvStart(); - - mozilla::ipc::IPCResult RecvAwakenSpam(); - mozilla::ipc::IPCResult RecvAwakenRaceWinTwice(); - - mozilla::ipc::IPCResult AnswerRace(); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - QuitChild(); - } -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestRacyUndefer_h diff --git a/ipc/ipdl/test/cxx/TestSanity.cpp b/ipc/ipdl/test/cxx/TestSanity.cpp deleted file mode 100644 index ba1920fdcc..0000000000 --- a/ipc/ipdl/test/cxx/TestSanity.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "TestSanity.h" - -#include "IPDLUnitTests.h" // fail etc. - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// parent - -TestSanityParent::TestSanityParent() { MOZ_COUNT_CTOR(TestSanityParent); } - -TestSanityParent::~TestSanityParent() { MOZ_COUNT_DTOR(TestSanityParent); } - -void TestSanityParent::Main() { - if (!SendPing(0, 0.5f, 0)) fail("sending Ping"); -} - -mozilla::ipc::IPCResult TestSanityParent::RecvPong(const int& one, - const float& zeroPtTwoFive, - const uint8_t& /*unused*/) { - if (1 != one) fail("invalid argument `%d', should have been `1'", one); - - if (0.25f != zeroPtTwoFive) - fail("invalid argument `%g', should have been `0.25'", zeroPtTwoFive); - - Close(); - - return IPC_OK(); -} - -//----------------------------------------------------------------------------- -// child - -TestSanityChild::TestSanityChild() { MOZ_COUNT_CTOR(TestSanityChild); } - -TestSanityChild::~TestSanityChild() { MOZ_COUNT_DTOR(TestSanityChild); } - -mozilla::ipc::IPCResult TestSanityChild::RecvPing(const int& zero, - const float& zeroPtFive, - const int8_t& /*unused*/) { - if (0 != zero) fail("invalid argument `%d', should have been `0'", zero); - - if (0.5f != zeroPtFive) - fail("invalid argument `%g', should have been `0.5'", zeroPtFive); - - if (!SendPong(1, 0.25f, 0)) fail("sending Pong"); - return IPC_OK(); -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestSanity.h b/ipc/ipdl/test/cxx/TestSanity.h deleted file mode 100644 index ca29d67672..0000000000 --- a/ipc/ipdl/test/cxx/TestSanity.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef mozilla__ipdltest_TestSanity_h -#define mozilla__ipdltest_TestSanity_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestSanityParent.h" -#include "mozilla/_ipdltest/PTestSanityChild.h" - -namespace mozilla { -namespace _ipdltest { - -class TestSanityParent : public PTestSanityParent { - friend class PTestSanityParent; - - public: - TestSanityParent(); - virtual ~TestSanityParent(); - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return true; } - - void Main(); - - protected: - mozilla::ipc::IPCResult RecvPong(const int& one, const float& zeroPtTwoFive, - const uint8_t& dummy); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - passed("ok"); - QuitParent(); - } -}; - -class TestSanityChild : public PTestSanityChild { - friend class PTestSanityChild; - - public: - TestSanityChild(); - virtual ~TestSanityChild(); - - protected: - mozilla::ipc::IPCResult RecvPing(const int& zero, const float& zeroPtFive, - const int8_t& dummy); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - QuitChild(); - } -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestSanity_h diff --git a/ipc/ipdl/test/cxx/TestSelfManageRoot.cpp b/ipc/ipdl/test/cxx/TestSelfManageRoot.cpp deleted file mode 100644 index 5e09aa4d7e..0000000000 --- a/ipc/ipdl/test/cxx/TestSelfManageRoot.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include "TestSelfManageRoot.h" - -#include "IPDLUnitTests.h" // fail etc. - -#define ASSERT(c) \ - do { \ - if (!(c)) fail(#c); \ - } while (0) - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// parent - -void TestSelfManageRootParent::Main() { - TestSelfManageParent* a = - static_cast(SendPTestSelfManageConstructor()); - if (!a) fail("constructing PTestSelfManage"); - - ASSERT(1 == ManagedPTestSelfManageParent().Count()); - - TestSelfManageParent* aa = - static_cast(a->SendPTestSelfManageConstructor()); - if (!aa) fail("constructing PTestSelfManage"); - - ASSERT(1 == ManagedPTestSelfManageParent().Count() && - 1 == a->ManagedPTestSelfManageParent().Count()); - - if (!PTestSelfManageParent::Send__delete__(aa)) - fail("destroying PTestSelfManage"); - ASSERT(Deletion == aa->mWhy && 1 == ManagedPTestSelfManageParent().Count() && - 0 == a->ManagedPTestSelfManageParent().Count()); - delete aa; - - aa = static_cast(a->SendPTestSelfManageConstructor()); - if (!aa) fail("constructing PTestSelfManage"); - - ASSERT(1 == ManagedPTestSelfManageParent().Count() && - 1 == a->ManagedPTestSelfManageParent().Count()); - - if (!PTestSelfManageParent::Send__delete__(a)) - fail("destroying PTestSelfManage"); - ASSERT(Deletion == a->mWhy && AncestorDeletion == aa->mWhy && - 0 == ManagedPTestSelfManageParent().Count() && - 0 == a->ManagedPTestSelfManageParent().Count()); - delete a; - delete aa; - - Close(); -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestSelfManageRoot.h b/ipc/ipdl/test/cxx/TestSelfManageRoot.h deleted file mode 100644 index 5cea09b10d..0000000000 --- a/ipc/ipdl/test/cxx/TestSelfManageRoot.h +++ /dev/null @@ -1,117 +0,0 @@ -#ifndef mozilla__ipdltest_TestSelfManageRoot_h -#define mozilla__ipdltest_TestSelfManageRoot_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestSelfManageRootParent.h" -#include "mozilla/_ipdltest/PTestSelfManageRootChild.h" -#include "mozilla/_ipdltest/PTestSelfManageParent.h" -#include "mozilla/_ipdltest/PTestSelfManageChild.h" - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// Parent side - -class TestSelfManageParent : public PTestSelfManageParent { - friend class PTestSelfManageParent; - - public: - MOZ_COUNTED_DEFAULT_CTOR(TestSelfManageParent) - MOZ_COUNTED_DTOR_OVERRIDE(TestSelfManageParent) - - ActorDestroyReason mWhy; - - protected: - PTestSelfManageParent* AllocPTestSelfManageParent() { - return new TestSelfManageParent(); - } - - bool DeallocPTestSelfManageParent(PTestSelfManageParent* a) { return true; } - - virtual void ActorDestroy(ActorDestroyReason why) override { mWhy = why; } -}; - -class TestSelfManageRootParent : public PTestSelfManageRootParent { - friend class PTestSelfManageRootParent; - - public: - MOZ_COUNTED_DEFAULT_CTOR(TestSelfManageRootParent) - virtual ~TestSelfManageRootParent() { - MOZ_COUNT_DTOR(TestSelfManageRootParent); - } - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return true; } - - void Main(); - - protected: - PTestSelfManageParent* AllocPTestSelfManageParent() { - return new TestSelfManageParent(); - } - - bool DeallocPTestSelfManageParent(PTestSelfManageParent* a) { return true; } - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - passed("ok"); - QuitParent(); - } -}; - -//----------------------------------------------------------------------------- -// Child side - -class TestSelfManageChild : public PTestSelfManageChild { - friend class PTestSelfManageChild; - - public: - MOZ_COUNTED_DEFAULT_CTOR(TestSelfManageChild) - MOZ_COUNTED_DTOR_OVERRIDE(TestSelfManageChild) - - protected: - PTestSelfManageChild* AllocPTestSelfManageChild() { - return new TestSelfManageChild(); - } - - bool DeallocPTestSelfManageChild(PTestSelfManageChild* a) { - delete a; - return true; - } - - virtual void ActorDestroy(ActorDestroyReason why) override {} -}; - -class TestSelfManageRootChild : public PTestSelfManageRootChild { - friend class PTestSelfManageRootChild; - - public: - MOZ_COUNTED_DEFAULT_CTOR(TestSelfManageRootChild) - virtual ~TestSelfManageRootChild() { - MOZ_COUNT_DTOR(TestSelfManageRootChild); - } - - void Main(); - - protected: - PTestSelfManageChild* AllocPTestSelfManageChild() { - return new TestSelfManageChild(); - } - - bool DeallocPTestSelfManageChild(PTestSelfManageChild* a) { - delete a; - return true; - } - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - QuitChild(); - } -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestSelfManageRoot_h diff --git a/ipc/ipdl/test/cxx/TestShmem.cpp b/ipc/ipdl/test/cxx/TestShmem.cpp deleted file mode 100644 index 0a778e5322..0000000000 --- a/ipc/ipdl/test/cxx/TestShmem.cpp +++ /dev/null @@ -1,106 +0,0 @@ -#include "TestShmem.h" - -#include "IPDLUnitTests.h" // fail etc. - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// Parent - -void TestShmemParent::Main() { - Shmem mem; - Shmem unsafe; - - size_t size = 12345; - if (!AllocShmem(size, &mem)) fail("can't alloc shmem"); - if (!AllocUnsafeShmem(size, &unsafe)) fail("can't alloc shmem"); - - if (mem.Size() != size) - fail("shmem is wrong size: expected %lu, got %lu", size, mem.Size()); - if (unsafe.Size() != size) - fail("shmem is wrong size: expected %lu, got %lu", size, - unsafe.Size()); - - char* ptr = mem.get(); - memcpy(ptr, "Hello!", sizeof("Hello!")); - - char* unsafeptr = unsafe.get(); - memcpy(unsafeptr, "Hello!", sizeof("Hello!")); - - Shmem unsafecopy = unsafe; - if (!SendGive(std::move(mem), std::move(unsafe), size)) - fail("can't send Give()"); - - // uncomment the following line for a (nondeterministic) surprise! - // char c1 = *ptr; (void)c1; - - // uncomment the following line for a deterministic surprise! - // char c2 = *mem.get(); (void)c2; - - // unsafe shmem gets rid of those checks - char uc1 = *unsafeptr; - (void)uc1; - char uc2 = *unsafecopy.get(); - (void)uc2; -} - -mozilla::ipc::IPCResult TestShmemParent::RecvTake(Shmem&& mem, Shmem&& unsafe, - const size_t& expectedSize) { - if (mem.Size() != expectedSize) - fail("expected shmem size %lu, but it has size %lu", expectedSize, - mem.Size()); - if (unsafe.Size() != expectedSize) - fail("expected shmem size %lu, but it has size %lu", expectedSize, - unsafe.Size()); - - if (strcmp(mem.get(), "And yourself!")) - fail("expected message was not written"); - if (strcmp(unsafe.get(), "And yourself!")) - fail("expected message was not written"); - - if (!DeallocShmem(mem)) fail("DeallocShmem"); - if (!DeallocShmem(unsafe)) fail("DeallocShmem"); - - Close(); - - return IPC_OK(); -} - -//----------------------------------------------------------------------------- -// Child - -mozilla::ipc::IPCResult TestShmemChild::RecvGive(Shmem&& mem, Shmem&& unsafe, - const size_t& expectedSize) { - if (mem.Size() != expectedSize) - fail("expected shmem size %lu, but it has size %lu", expectedSize, - mem.Size()); - if (unsafe.Size() != expectedSize) - fail("expected shmem size %lu, but it has size %lu", expectedSize, - unsafe.Size()); - - if (strcmp(mem.get(), "Hello!")) - fail("expected message was not written"); - if (strcmp(unsafe.get(), "Hello!")) - fail("expected message was not written"); - - char* unsafeptr = unsafe.get(); - - memcpy(mem.get(), "And yourself!", sizeof("And yourself!")); - memcpy(unsafeptr, "And yourself!", sizeof("And yourself!")); - - Shmem unsafecopy = unsafe; - if (!SendTake(std::move(mem), std::move(unsafe), expectedSize)) - fail("can't send Take()"); - - // these checks also shouldn't fail in the child - char uc1 = *unsafeptr; - (void)uc1; - char uc2 = *unsafecopy.get(); - (void)uc2; - - return IPC_OK(); -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestShmem.h b/ipc/ipdl/test/cxx/TestShmem.h deleted file mode 100644 index 4ef1f4fd7b..0000000000 --- a/ipc/ipdl/test/cxx/TestShmem.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef mozilla__ipdltest_TestShmem_h -#define mozilla__ipdltest_TestShmem_h - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestShmemParent.h" -#include "mozilla/_ipdltest/PTestShmemChild.h" - -namespace mozilla { -namespace _ipdltest { - -class TestShmemParent : public PTestShmemParent { - friend class PTestShmemParent; - - public: - TestShmemParent() {} - virtual ~TestShmemParent() {} - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return true; } - - void Main(); - - protected: - mozilla::ipc::IPCResult RecvTake(Shmem&& mem, Shmem&& unsafe, - const size_t& expectedSize); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - passed("ok"); - QuitParent(); - } -}; - -class TestShmemChild : public PTestShmemChild { - friend class PTestShmemChild; - - public: - TestShmemChild() {} - virtual ~TestShmemChild() {} - - protected: - mozilla::ipc::IPCResult RecvGive(Shmem&& mem, Shmem&& unsafe, - const size_t& expectedSize); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - QuitChild(); - } -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestShmem_h diff --git a/ipc/ipdl/test/cxx/TestShutdown.cpp b/ipc/ipdl/test/cxx/TestShutdown.cpp deleted file mode 100644 index 502695bd88..0000000000 --- a/ipc/ipdl/test/cxx/TestShutdown.cpp +++ /dev/null @@ -1,185 +0,0 @@ -#include "TestShutdown.h" - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// Parent side -void TestShutdownParent::Main() { - if (!SendStart()) fail("sending Start()"); -} - -void TestShutdownParent::ActorDestroy(ActorDestroyReason why) { - if (AbnormalShutdown != why) fail("should have ended test with crash!"); - - passed("ok"); - - QuitParent(); -} - -void TestShutdownSubParent::ActorDestroy(ActorDestroyReason why) { - if (Manager()->ManagedPTestShutdownSubParent().Count() == 0) - fail("manager should still have managees!"); - - if (mExpectCrash && AbnormalShutdown != why) - fail("expected crash!"); - else if (!mExpectCrash && AbnormalShutdown == why) - fail("wasn't expecting crash!"); - - if (mExpectCrash && 0 == ManagedPTestShutdownSubsubParent().Count()) - fail("expected to *still* have kids"); -} - -void TestShutdownSubsubParent::ActorDestroy(ActorDestroyReason why) { - if (Manager()->ManagedPTestShutdownSubsubParent().Count() == 0) - fail("manager should still have managees!"); - - if (mExpectParentDeleted && AncestorDeletion != why) - fail("expected ParentDeleted == why"); - else if (!mExpectParentDeleted && AncestorDeletion == why) - fail("wasn't expecting parent delete"); -} - -//----------------------------------------------------------------------------- -// Child side - -mozilla::ipc::IPCResult TestShutdownChild::RecvStart() { - // test 1: alloc some actors and subactors, delete in - // managee-before-manager order - { - bool expectCrash = false, expectParentDeleted = false; - - PTestShutdownSubChild* c1 = SendPTestShutdownSubConstructor(expectCrash); - if (!c1) fail("problem sending ctor"); - - PTestShutdownSubChild* c2 = SendPTestShutdownSubConstructor(expectCrash); - if (!c2) fail("problem sending ctor"); - - PTestShutdownSubsubChild* c1s1 = - c1->SendPTestShutdownSubsubConstructor(expectParentDeleted); - if (!c1s1) fail("problem sending ctor"); - PTestShutdownSubsubChild* c1s2 = - c1->SendPTestShutdownSubsubConstructor(expectParentDeleted); - if (!c1s2) fail("problem sending ctor"); - - PTestShutdownSubsubChild* c2s1 = - c2->SendPTestShutdownSubsubConstructor(expectParentDeleted); - if (!c2s1) fail("problem sending ctor"); - PTestShutdownSubsubChild* c2s2 = - c2->SendPTestShutdownSubsubConstructor(expectParentDeleted); - if (!c2s2) fail("problem sending ctor"); - - if (!PTestShutdownSubsubChild::Send__delete__(c1s1)) - fail("problem sending dtor"); - if (!PTestShutdownSubsubChild::Send__delete__(c1s2)) - fail("problem sending dtor"); - if (!PTestShutdownSubsubChild::Send__delete__(c2s1)) - fail("problem sending dtor"); - if (!PTestShutdownSubsubChild::Send__delete__(c2s2)) - fail("problem sending dtor"); - - if (!c1->CallStackFrame()) fail("problem creating dummy stack frame"); - if (!c2->CallStackFrame()) fail("problem creating dummy stack frame"); - } - - // test 2: alloc some actors and subactors, delete managers first - { - bool expectCrash = false, expectParentDeleted = true; - - PTestShutdownSubChild* c1 = SendPTestShutdownSubConstructor(expectCrash); - if (!c1) fail("problem sending ctor"); - - PTestShutdownSubChild* c2 = SendPTestShutdownSubConstructor(expectCrash); - if (!c2) fail("problem sending ctor"); - - PTestShutdownSubsubChild* c1s1 = - c1->SendPTestShutdownSubsubConstructor(expectParentDeleted); - if (!c1s1) fail("problem sending ctor"); - PTestShutdownSubsubChild* c1s2 = - c1->SendPTestShutdownSubsubConstructor(expectParentDeleted); - if (!c1s2) fail("problem sending ctor"); - - PTestShutdownSubsubChild* c2s1 = - c2->SendPTestShutdownSubsubConstructor(expectParentDeleted); - if (!c2s1) fail("problem sending ctor"); - PTestShutdownSubsubChild* c2s2 = - c2->SendPTestShutdownSubsubConstructor(expectParentDeleted); - if (!c2s2) fail("problem sending ctor"); - - // delete parents without deleting kids - if (!c1->CallStackFrame()) fail("problem creating dummy stack frame"); - if (!c2->CallStackFrame()) fail("problem creating dummy stack frame"); - } - - // test 3: alloc some actors and subactors, then crash - { - bool expectCrash = true, expectParentDeleted = false; - - PTestShutdownSubChild* c1 = SendPTestShutdownSubConstructor(expectCrash); - if (!c1) fail("problem sending ctor"); - - PTestShutdownSubChild* c2 = SendPTestShutdownSubConstructor(expectCrash); - if (!c2) fail("problem sending ctor"); - - PTestShutdownSubsubChild* c1s1 = - c1->SendPTestShutdownSubsubConstructor(expectParentDeleted); - if (!c1s1) fail("problem sending ctor"); - PTestShutdownSubsubChild* c1s2 = - c1->SendPTestShutdownSubsubConstructor(expectParentDeleted); - if (!c1s2) fail("problem sending ctor"); - - PTestShutdownSubsubChild* c2s1 = - c2->SendPTestShutdownSubsubConstructor(expectParentDeleted); - if (!c2s1) fail("problem sending ctor"); - PTestShutdownSubsubChild* c2s2 = - c2->SendPTestShutdownSubsubConstructor(expectParentDeleted); - if (!c2s2) fail("problem sending ctor"); - - // make sure the ctors have been processed by the other side; - // the write end of the socket may temporarily be unwriteable - if (!SendSync()) fail("can't synchronize with parent"); - - // "crash", but without tripping tinderbox assert/abort - // detectors - _exit(0); - } -} - -void TestShutdownChild::ActorDestroy(ActorDestroyReason why) { - fail("hey wait ... we should have crashed!"); -} - -mozilla::ipc::IPCResult TestShutdownSubChild::AnswerStackFrame() { - if (!PTestShutdownSubChild::Send__delete__(this)) - fail("problem sending dtor"); - - // WATCH OUT! |this| has just deleted - - return IPC_OK(); -} - -void TestShutdownSubChild::ActorDestroy(ActorDestroyReason why) { - if (Manager()->ManagedPTestShutdownSubChild().Count() == 0) - fail("manager should still have managees!"); - - if (mExpectCrash && AbnormalShutdown != why) - fail("expected crash!"); - else if (!mExpectCrash && AbnormalShutdown == why) - fail("wasn't expecting crash!"); - - if (mExpectCrash && 0 == ManagedPTestShutdownSubsubChild().Count()) - fail("expected to *still* have kids"); -} - -void TestShutdownSubsubChild::ActorDestroy(ActorDestroyReason why) { - if (Manager()->ManagedPTestShutdownSubsubChild().Count() == 0) - fail("manager should still have managees!"); - - if (mExpectParentDeleted && AncestorDeletion != why) - fail("expected ParentDeleted == why"); - else if (!mExpectParentDeleted && AncestorDeletion == why) - fail("wasn't expecting parent delete"); -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestShutdown.h b/ipc/ipdl/test/cxx/TestShutdown.h deleted file mode 100644 index 224e42496d..0000000000 --- a/ipc/ipdl/test/cxx/TestShutdown.h +++ /dev/null @@ -1,168 +0,0 @@ -#ifndef mozilla__ipdltest_TestShutdown_h -#define mozilla__ipdltest_TestShutdown_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestShutdownParent.h" -#include "mozilla/_ipdltest/PTestShutdownChild.h" - -#include "mozilla/_ipdltest/PTestShutdownSubParent.h" -#include "mozilla/_ipdltest/PTestShutdownSubChild.h" - -#include "mozilla/_ipdltest/PTestShutdownSubsubParent.h" -#include "mozilla/_ipdltest/PTestShutdownSubsubChild.h" - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// Parent side - -class TestShutdownSubsubParent : public PTestShutdownSubsubParent { - public: - explicit TestShutdownSubsubParent(bool expectParentDeleted) - : mExpectParentDeleted(expectParentDeleted) {} - - virtual ~TestShutdownSubsubParent() {} - - protected: - virtual void ActorDestroy(ActorDestroyReason why) override; - - private: - bool mExpectParentDeleted; -}; - -class TestShutdownSubParent : public PTestShutdownSubParent { - friend class PTestShutdownSubParent; - - public: - explicit TestShutdownSubParent(bool expectCrash) - : mExpectCrash(expectCrash), mDeletedCount(0) {} - - virtual ~TestShutdownSubParent() { - if (2 != mDeletedCount) fail("managees outliving manager!"); - } - - protected: - mozilla::ipc::IPCResult AnswerStackFrame() { - if (!CallStackFrame()) { - return IPC_FAIL_NO_REASON(this); - } - return IPC_OK(); - } - - PTestShutdownSubsubParent* AllocPTestShutdownSubsubParent( - const bool& expectParentDelete) { - return new TestShutdownSubsubParent(expectParentDelete); - } - - bool DeallocPTestShutdownSubsubParent(PTestShutdownSubsubParent* actor) { - delete actor; - ++mDeletedCount; - return true; - } - - virtual void ActorDestroy(ActorDestroyReason why) override; - - private: - bool mExpectCrash; - int mDeletedCount; -}; - -class TestShutdownParent : public PTestShutdownParent { - friend class PTestShutdownParent; - - public: - TestShutdownParent() {} - virtual ~TestShutdownParent() {} - - static bool RunTestInProcesses() { return true; } - // FIXME/bug 703323 Could work if modified - static bool RunTestInThreads() { return false; } - - void Main(); - - protected: - mozilla::ipc::IPCResult RecvSync() { return IPC_OK(); } - - PTestShutdownSubParent* AllocPTestShutdownSubParent(const bool& expectCrash) { - return new TestShutdownSubParent(expectCrash); - } - - bool DeallocPTestShutdownSubParent(PTestShutdownSubParent* actor) { - delete actor; - return true; - } - - virtual void ActorDestroy(ActorDestroyReason why) override; -}; - -//----------------------------------------------------------------------------- -// Child side - -class TestShutdownSubsubChild : public PTestShutdownSubsubChild { - public: - explicit TestShutdownSubsubChild(bool expectParentDeleted) - : mExpectParentDeleted(expectParentDeleted) {} - virtual ~TestShutdownSubsubChild() {} - - protected: - virtual void ActorDestroy(ActorDestroyReason why) override; - - private: - bool mExpectParentDeleted; -}; - -class TestShutdownSubChild : public PTestShutdownSubChild { - friend class PTestShutdownSubChild; - - public: - explicit TestShutdownSubChild(bool expectCrash) : mExpectCrash(expectCrash) {} - - virtual ~TestShutdownSubChild() {} - - protected: - mozilla::ipc::IPCResult AnswerStackFrame(); - - PTestShutdownSubsubChild* AllocPTestShutdownSubsubChild( - const bool& expectParentDelete) { - return new TestShutdownSubsubChild(expectParentDelete); - } - - bool DeallocPTestShutdownSubsubChild(PTestShutdownSubsubChild* actor) { - delete actor; - return true; - } - - virtual void ActorDestroy(ActorDestroyReason why) override; - - private: - bool mExpectCrash; -}; - -class TestShutdownChild : public PTestShutdownChild { - friend class PTestShutdownChild; - - public: - TestShutdownChild() {} - virtual ~TestShutdownChild() {} - - protected: - mozilla::ipc::IPCResult RecvStart(); - - PTestShutdownSubChild* AllocPTestShutdownSubChild(const bool& expectCrash) { - return new TestShutdownSubChild(expectCrash); - } - - bool DeallocPTestShutdownSubChild(PTestShutdownSubChild* actor) { - delete actor; - return true; - } - - virtual void ActorDestroy(ActorDestroyReason why) override; -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestShutdown_h diff --git a/ipc/ipdl/test/cxx/TestStackHooks.cpp b/ipc/ipdl/test/cxx/TestStackHooks.cpp deleted file mode 100644 index 9800ac54e7..0000000000 --- a/ipc/ipdl/test/cxx/TestStackHooks.cpp +++ /dev/null @@ -1,122 +0,0 @@ -#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()"); -} - -mozilla::ipc::IPCResult 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 IPC_OK(); -} - -//----------------------------------------------------------------------------- -// child - -TestStackHooksChild::TestStackHooksChild() - : mOnStack(false), - mEntered(0), - mExited(0), - mIncallDepth(0), - mNumAnswerStackFrame(0) { - MOZ_COUNT_CTOR(TestStackHooksChild); -} - -TestStackHooksChild::~TestStackHooksChild() { - MOZ_COUNT_DTOR(TestStackHooksChild); -} - -namespace { -void RunTestsFn() { - static_cast(gChildActor)->RunTests(); -} -} // namespace - -mozilla::ipc::IPCResult 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", RunTestsFn)); - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestStackHooksChild::AnswerStackFrame() { - ++mNumAnswerStackFrame; - - if (!mOnStack) fail("missed stack notification"); - - if (1 != mIncallDepth) fail("missed EnteredCall or ExitedCall hook"); - - if (mNumAnswerStackFrame == 1) { - if (!SendAsync()) fail("sending Async()"); - } else if (mNumAnswerStackFrame == 2) { - if (!SendSync()) fail("sending Sync()"); - } else { - fail("unexpected state"); - } - - if (!mOnStack) fail("bad stack exit notification"); - - return IPC_OK(); -} - -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 diff --git a/ipc/ipdl/test/cxx/TestStackHooks.h b/ipc/ipdl/test/cxx/TestStackHooks.h deleted file mode 100644 index 315a3c1ae5..0000000000 --- a/ipc/ipdl/test/cxx/TestStackHooks.h +++ /dev/null @@ -1,107 +0,0 @@ -#ifndef mozilla__ipdltest_TestStackHooks_h -#define mozilla__ipdltest_TestStackHooks_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestStackHooksParent.h" -#include "mozilla/_ipdltest/PTestStackHooksChild.h" - -namespace mozilla { -namespace _ipdltest { - -class TestStackHooksParent : public PTestStackHooksParent { - friend class PTestStackHooksParent; - - public: - TestStackHooksParent(); - virtual ~TestStackHooksParent(); - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return true; } - - void Main(); - - protected: - mozilla::ipc::IPCResult RecvAsync() { - if (!mOnStack) fail("not on C++ stack?!"); - return IPC_OK(); - } - - mozilla::ipc::IPCResult RecvSync() { - if (!mOnStack) fail("not on C++ stack?!"); - return IPC_OK(); - } - - mozilla::ipc::IPCResult AnswerRpc() { - if (!mOnStack) fail("not on C++ stack?!"); - return IPC_OK(); - } - - mozilla::ipc::IPCResult AnswerStackFrame(); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - passed("ok"); - QuitParent(); - } - - virtual void EnteredCxxStack() override { mOnStack = true; } - virtual void ExitedCxxStack() override { mOnStack = false; } - - virtual void EnteredCall() override { ++mIncallDepth; } - virtual void ExitedCall() override { --mIncallDepth; } - - private: - bool mOnStack; - int mIncallDepth; -}; - -class TestStackHooksChild : public PTestStackHooksChild { - friend class PTestStackHooksChild; - - public: - TestStackHooksChild(); - virtual ~TestStackHooksChild(); - - void RunTests(); - - protected: - mozilla::ipc::IPCResult RecvStart(); - - mozilla::ipc::IPCResult AnswerStackFrame(); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - - if (mEntered != mExited) fail("unbalanced enter/exit notifications"); - - if (mOnStack) - fail("computing mOnStack went awry; should have failed above assertion"); - - QuitChild(); - } - - virtual void EnteredCxxStack() override { - ++mEntered; - mOnStack = true; - } - virtual void ExitedCxxStack() override { - ++mExited; - mOnStack = false; - } - - virtual void EnteredCall() override { ++mIncallDepth; } - virtual void ExitedCall() override { --mIncallDepth; } - - private: - bool mOnStack; - int mEntered; - int mExited; - int mIncallDepth; - int32_t mNumAnswerStackFrame; -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestStackHooks_h diff --git a/ipc/ipdl/test/cxx/TestSyncError.cpp b/ipc/ipdl/test/cxx/TestSyncError.cpp deleted file mode 100644 index 6c21590a87..0000000000 --- a/ipc/ipdl/test/cxx/TestSyncError.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "TestSyncError.h" - -#include "IPDLUnitTests.h" // fail etc. - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// parent - -TestSyncErrorParent::TestSyncErrorParent() { - MOZ_COUNT_CTOR(TestSyncErrorParent); -} - -TestSyncErrorParent::~TestSyncErrorParent() { - MOZ_COUNT_DTOR(TestSyncErrorParent); -} - -void TestSyncErrorParent::Main() { - if (!SendStart()) fail("sending Start"); -} - -mozilla::ipc::IPCResult TestSyncErrorParent::RecvError() { - return IPC_FAIL_NO_REASON(this); -} - -//----------------------------------------------------------------------------- -// child - -TestSyncErrorChild::TestSyncErrorChild() { MOZ_COUNT_CTOR(TestSyncErrorChild); } - -TestSyncErrorChild::~TestSyncErrorChild() { - MOZ_COUNT_DTOR(TestSyncErrorChild); -} - -mozilla::ipc::IPCResult TestSyncErrorChild::RecvStart() { - if (SendError()) fail("Error() should have return false"); - - Close(); - - return IPC_OK(); -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestSyncError.h b/ipc/ipdl/test/cxx/TestSyncError.h deleted file mode 100644 index 8b84ed5e0b..0000000000 --- a/ipc/ipdl/test/cxx/TestSyncError.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef mozilla__ipdltest_TestSyncError_h -#define mozilla__ipdltest_TestSyncError_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestSyncErrorParent.h" -#include "mozilla/_ipdltest/PTestSyncErrorChild.h" - -namespace mozilla { -namespace _ipdltest { - -class TestSyncErrorParent : public PTestSyncErrorParent { - friend class PTestSyncErrorParent; - - public: - TestSyncErrorParent(); - virtual ~TestSyncErrorParent(); - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return true; } - - void Main(); - - protected: - mozilla::ipc::IPCResult RecvError(); - - virtual void ProcessingError(Result aCode, const char* aReason) override { - // Ignore errors - } - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - passed("ok"); - QuitParent(); - } -}; - -class TestSyncErrorChild : public PTestSyncErrorChild { - friend class PTestSyncErrorChild; - - public: - TestSyncErrorChild(); - virtual ~TestSyncErrorChild(); - - protected: - mozilla::ipc::IPCResult RecvStart(); - - virtual void ProcessingError(Result aCode, const char* aReason) override { - // Ignore errors - } - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - QuitChild(); - } -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestSyncError_h diff --git a/ipc/ipdl/test/cxx/TestSyncHang.cpp b/ipc/ipdl/test/cxx/TestSyncHang.cpp deleted file mode 100644 index f53054787b..0000000000 --- a/ipc/ipdl/test/cxx/TestSyncHang.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "TestSyncHang.h" -#include "base/task.h" -#include "mozilla/ipc/GeckoChildProcessHost.h" - -#include "IPDLUnitTests.h" // fail etc. - -using std::string; -using std::vector; - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// parent - -mozilla::ipc::GeckoChildProcessHost* gSyncHangSubprocess; - -TestSyncHangParent::TestSyncHangParent() { MOZ_COUNT_CTOR(TestSyncHangParent); } - -TestSyncHangParent::~TestSyncHangParent() { - MOZ_COUNT_DTOR(TestSyncHangParent); -} - -void DeleteSyncHangSubprocess(MessageLoop* uiLoop) { - gSyncHangSubprocess->Destroy(); - gSyncHangSubprocess = nullptr; -} - -void DeferredSyncHangParentShutdown() { - // ping to DeleteSubprocess - XRE_GetIOMessageLoop()->PostTask( - NewRunnableFunction("DeleteSyncHangSubprocess", DeleteSyncHangSubprocess, - MessageLoop::current())); -} - -void TestSyncHangParent::Main() { - vector args; - args.push_back("fake/path"); - gSyncHangSubprocess = - new mozilla::ipc::GeckoChildProcessHost(GeckoProcessType_Plugin); - bool launched = gSyncHangSubprocess->SyncLaunch(args, 2); - if (launched) - fail("Calling SyncLaunch with an invalid path should return false"); - - MessageLoop::current()->PostTask(NewRunnableFunction( - "DeferredSyncHangParentShutdown", DeferredSyncHangParentShutdown)); - Close(); -} - -//----------------------------------------------------------------------------- -// child - -TestSyncHangChild::TestSyncHangChild() { MOZ_COUNT_CTOR(TestSyncHangChild); } - -TestSyncHangChild::~TestSyncHangChild() { MOZ_COUNT_DTOR(TestSyncHangChild); } - -mozilla::ipc::IPCResult TestSyncHangChild::RecvUnusedMessage() { - return IPC_OK(); -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestSyncHang.h b/ipc/ipdl/test/cxx/TestSyncHang.h deleted file mode 100644 index 911f05cd31..0000000000 --- a/ipc/ipdl/test/cxx/TestSyncHang.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef mozilla__ipdltest_TestSyncHang_h -#define mozilla__ipdltest_TestSyncHang_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestSyncHangParent.h" -#include "mozilla/_ipdltest/PTestSyncHangChild.h" - -namespace mozilla { -namespace _ipdltest { - -class TestSyncHangParent : public PTestSyncHangParent { - public: - TestSyncHangParent(); - virtual ~TestSyncHangParent(); - - static bool RunTestInProcesses() { return true; } - // FIXME/bug 703323 Could work if modified - static bool RunTestInThreads() { return false; } - - void Main(); - - protected: - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - passed("ok"); - QuitParent(); - } -}; - -class TestSyncHangChild : public PTestSyncHangChild { - friend class PTestSyncHangChild; - - public: - TestSyncHangChild(); - virtual ~TestSyncHangChild(); - - protected: - mozilla::ipc::IPCResult RecvUnusedMessage(); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - QuitChild(); - } -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestSyncHang_h diff --git a/ipc/ipdl/test/cxx/TestSyncWakeup.cpp b/ipc/ipdl/test/cxx/TestSyncWakeup.cpp deleted file mode 100644 index 90875b702b..0000000000 --- a/ipc/ipdl/test/cxx/TestSyncWakeup.cpp +++ /dev/null @@ -1,106 +0,0 @@ -#if defined(XP_UNIX) -# include // sleep() -#endif - -#include "TestSyncWakeup.h" - -#include "IPDLUnitTests.h" // fail etc. - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// parent - -TestSyncWakeupParent::TestSyncWakeupParent() { - MOZ_COUNT_CTOR(TestSyncWakeupParent); -} - -TestSyncWakeupParent::~TestSyncWakeupParent() { - MOZ_COUNT_DTOR(TestSyncWakeupParent); -} - -void TestSyncWakeupParent::Main() { - if (!SendStart()) fail("sending Start()"); -} - -mozilla::ipc::IPCResult TestSyncWakeupParent::AnswerStackFrame() { - if (!CallStackFrame()) fail("calling StackFrame()"); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestSyncWakeupParent::RecvSync1() { - if (!SendNote1()) fail("sending Note1()"); - - // XXX ugh ... need to ensure that the async message and sync - // reply come in "far enough" apart that this test doesn't pass on - // accident -#if defined(XP_UNIX) - // NB: can't use PR_Sleep (i.e. Sleep() on windows) because it's - // only spec'd to block the current thread, not the current - // process. We need the IO thread to sleep as well. - puts(" (sleeping for 5 seconds. sorry!)"); - sleep(5); -#endif - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestSyncWakeupParent::RecvSync2() { - if (!SendNote2()) fail("sending Note2()"); - -#if defined(XP_UNIX) - // see above - sleep(5); - puts(" (sleeping for 5 seconds. sorry!)"); -#endif - - return IPC_OK(); -} - -//----------------------------------------------------------------------------- -// child - -TestSyncWakeupChild::TestSyncWakeupChild() : mDone(false) { - MOZ_COUNT_CTOR(TestSyncWakeupChild); -} - -TestSyncWakeupChild::~TestSyncWakeupChild() { - MOZ_COUNT_DTOR(TestSyncWakeupChild); -} - -mozilla::ipc::IPCResult TestSyncWakeupChild::RecvStart() { - // First test: the parent fires back an async message while - // replying to a sync one - if (!SendSync1()) fail("sending Sync()"); - - // drop back into the event loop to get Note1(), then kick off the - // second test - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestSyncWakeupChild::RecvNote1() { - // Second test: the parent fires back an async message while - // replying to a sync one, with a frame on the RPC stack - if (!CallStackFrame()) fail("calling StackFrame()"); - - if (!mDone) fail("should have received Note2()!"); - - Close(); - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestSyncWakeupChild::AnswerStackFrame() { - if (!SendSync2()) fail("sending Sync()"); - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestSyncWakeupChild::RecvNote2() { - mDone = true; - return IPC_OK(); -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestSyncWakeup.h b/ipc/ipdl/test/cxx/TestSyncWakeup.h deleted file mode 100644 index 5666307929..0000000000 --- a/ipc/ipdl/test/cxx/TestSyncWakeup.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef mozilla__ipdltest_TestSyncWakeup_h -#define mozilla__ipdltest_TestSyncWakeup_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestSyncWakeupParent.h" -#include "mozilla/_ipdltest/PTestSyncWakeupChild.h" - -namespace mozilla { -namespace _ipdltest { - -class TestSyncWakeupParent : public PTestSyncWakeupParent { - friend class PTestSyncWakeupParent; - - public: - TestSyncWakeupParent(); - virtual ~TestSyncWakeupParent(); - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return true; } - - void Main(); - - protected: - mozilla::ipc::IPCResult AnswerStackFrame(); - - mozilla::ipc::IPCResult RecvSync1(); - - mozilla::ipc::IPCResult RecvSync2(); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - passed("ok"); - QuitParent(); - } -}; - -class TestSyncWakeupChild : public PTestSyncWakeupChild { - friend class PTestSyncWakeupChild; - - public: - TestSyncWakeupChild(); - virtual ~TestSyncWakeupChild(); - - protected: - mozilla::ipc::IPCResult RecvStart(); - - mozilla::ipc::IPCResult RecvNote1(); - - mozilla::ipc::IPCResult AnswerStackFrame(); - - mozilla::ipc::IPCResult RecvNote2(); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) fail("unexpected destruction!"); - QuitChild(); - } - - private: - bool mDone; -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestSyncWakeup_h diff --git a/ipc/ipdl/test/cxx/TestUniquePtrIPC.cpp b/ipc/ipdl/test/cxx/TestUniquePtrIPC.cpp deleted file mode 100644 index 7d0e8dd6ca..0000000000 --- a/ipc/ipdl/test/cxx/TestUniquePtrIPC.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "TestUniquePtrIPC.h" - -namespace mozilla { -namespace _ipdltest { - -// --------------------------------------------------------------------------- -// PARENT PROCESS -// --------------------------------------------------------------------------- - -void TestUniquePtrIPCParent::Main() { - UniquePtr a1 = MakeUnique(1); - UniquePtr a2 = MakeUnique(2); - DummyStruct a3(3); - UniquePtr a4; - - if (!SendTestMessage(std::move(a1), std::move(a2), a3, std::move(a4))) { - fail("failed sending UniquePtr items"); - } - - if (a1 || a2) { - fail("did not move TestMessage items in parent"); - } - - if (a4) { - fail("somehow turned null ptr into non-null by sending it"); - } - - // Pass UniquePtr by reference - UniquePtr b = MakeUnique(1); - - if (!SendTestSendReference(std::move(b))) { - fail("failed sending UniquePtr by reference"); - } - if (b) { - fail("did not move UniquePtr sent by reference"); - } -} - -// --------------------------------------------------------------------------- -// CHILD PROCESS -// --------------------------------------------------------------------------- - -mozilla::ipc::IPCResult TestUniquePtrIPCChild::RecvTestMessage( - UniquePtr&& aA1, UniquePtr&& aA2, const DummyStruct& aA3, - UniquePtr&& aA4) { - if ((!aA1) || (!aA2)) { - fail("TestMessage received NULL items in child"); - } - - if (aA4) { - fail("TestMessage received non-NULL when expecting NULL"); - } - - if ((*aA1 != 1) || (aA2->x() != 2) || (aA3.x() != 3)) { - fail("TestMessage received incorrect items in child"); - } - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestUniquePtrIPCChild::RecvTestSendReference( - UniquePtr&& aA) { - if (!aA) { - fail("TestSendReference received NULL item in child"); - } - - if (*aA != 1) { - fail("TestSendReference received incorrect item in child"); - } - - Close(); - return IPC_OK(); -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestUniquePtrIPC.h b/ipc/ipdl/test/cxx/TestUniquePtrIPC.h deleted file mode 100644 index 3c9de33df3..0000000000 --- a/ipc/ipdl/test/cxx/TestUniquePtrIPC.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef mozilla_TestUniquePtrIPC_h -#define mozilla_TestUniquePtrIPC_h - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestUniquePtrIPCParent.h" -#include "mozilla/_ipdltest/PTestUniquePtrIPCChild.h" - -namespace mozilla { -namespace _ipdltest { - -class TestUniquePtrIPCParent : public PTestUniquePtrIPCParent { - public: - MOZ_COUNTED_DEFAULT_CTOR(TestUniquePtrIPCParent) - MOZ_COUNTED_DTOR_OVERRIDE(TestUniquePtrIPCParent) - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return false; } - - void Main(); - - bool ShouldContinueFromReplyTimeout() override { return false; } - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) { - fail("Abnormal shutdown of parent"); - } - passed("ok"); - QuitParent(); - } -}; - -class TestUniquePtrIPCChild : public PTestUniquePtrIPCChild { - public: - MOZ_COUNTED_DEFAULT_CTOR(TestUniquePtrIPCChild) - MOZ_COUNTED_DTOR_OVERRIDE(TestUniquePtrIPCChild) - - mozilla::ipc::IPCResult RecvTestMessage(UniquePtr&& aA1, - UniquePtr&& aA2, - const DummyStruct& aA3, - UniquePtr&& aA4); - - mozilla::ipc::IPCResult RecvTestSendReference(UniquePtr&& aA); - - virtual void ActorDestroy(ActorDestroyReason why) override { - if (NormalShutdown != why) { - fail("Abnormal shutdown of child"); - } - QuitChild(); - } -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // mozilla_TestUniquePtrIPC_h diff --git a/ipc/ipdl/test/cxx/TestUrgency.cpp b/ipc/ipdl/test/cxx/TestUrgency.cpp deleted file mode 100644 index 840b9d71e9..0000000000 --- a/ipc/ipdl/test/cxx/TestUrgency.cpp +++ /dev/null @@ -1,117 +0,0 @@ -#include "TestUrgency.h" - -#include "IPDLUnitTests.h" // fail etc. -#if defined(XP_UNIX) -# include -#else -# include -#endif - -namespace mozilla { -namespace _ipdltest { - -#if defined(XP_UNIX) -static void Sleep(int ms) { sleep(ms / 1000); } -#endif - -//----------------------------------------------------------------------------- -// parent - -TestUrgencyParent::TestUrgencyParent() : inreply_(false) { - MOZ_COUNT_CTOR(TestUrgencyParent); -} - -TestUrgencyParent::~TestUrgencyParent() { MOZ_COUNT_DTOR(TestUrgencyParent); } - -void TestUrgencyParent::Main() { - if (!SendStart()) fail("sending Start"); -} - -mozilla::ipc::IPCResult TestUrgencyParent::RecvTest1(uint32_t* value) { - if (!SendReply1(value)) fail("sending Reply1"); - if (*value != 99) fail("bad value"); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestUrgencyParent::RecvTest2() { - uint32_t value; - inreply_ = true; - if (!SendReply2(&value)) fail("sending Reply2"); - inreply_ = false; - if (value != 500) fail("bad value"); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestUrgencyParent::RecvTest3(uint32_t* value) { - if (inreply_) fail("nested non-urgent on top of urgent rpc"); - *value = 1000; - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestUrgencyParent::RecvFinalTest_Begin() { - return IPC_OK(); -} - -//----------------------------------------------------------------------------- -// child - -enum { - kFirstTestBegin = 1, - kFirstTestGotReply, - kSecondTestBegin, - kSecondTestGotReply, -}; - -mozilla::ipc::IPCResult TestUrgencyChild::RecvStart() { - uint32_t result; - - // Send a synchronous message, expect to get an urgent message while - // blocked. - test_ = kFirstTestBegin; - if (!SendTest1(&result)) fail("calling SendTest1"); - if (result != 99) fail("bad result in RecvStart"); - if (test_ != kFirstTestGotReply) fail("never received urgent message"); - - // Initiate the next test by sending an asynchronous message, then becoming - // blocked. This tests that the urgent message is still delivered properly, - // and that the parent does not try to service the sync - test_ = kSecondTestBegin; - if (!SendTest2()) fail("calling SendTest2"); - if (!SendTest3(&result)) fail("calling SendTest3"); - if (test_ != kSecondTestGotReply) fail("never received urgent message #2"); - if (result != 1000) fail("wrong value from test3"); - - if (!SendFinalTest_Begin()) fail("Final test should have succeeded"); - - Close(); - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestUrgencyChild::RecvReply1(uint32_t* reply) { - if (test_ != kFirstTestBegin) fail("wrong test # in RecvReply1"); - - *reply = 99; - test_ = kFirstTestGotReply; - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestUrgencyChild::RecvReply2(uint32_t* reply) { - if (test_ != kSecondTestBegin) fail("wrong test # in RecvReply2"); - - // sleep for 5 seconds so the parent process tries to deliver more messages. - Sleep(5000); - - *reply = 500; - test_ = kSecondTestGotReply; - return IPC_OK(); -} - -TestUrgencyChild::TestUrgencyChild() : test_(0) { - MOZ_COUNT_CTOR(TestUrgencyChild); -} - -TestUrgencyChild::~TestUrgencyChild() { MOZ_COUNT_DTOR(TestUrgencyChild); } - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestUrgency.h b/ipc/ipdl/test/cxx/TestUrgency.h deleted file mode 100644 index 6af73177ee..0000000000 --- a/ipc/ipdl/test/cxx/TestUrgency.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef mozilla__ipdltest_TestUrgency_h -#define mozilla__ipdltest_TestUrgency_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestUrgencyParent.h" -#include "mozilla/_ipdltest/PTestUrgencyChild.h" - -namespace mozilla { -namespace _ipdltest { - -class TestUrgencyParent : public PTestUrgencyParent { - public: - TestUrgencyParent(); - virtual ~TestUrgencyParent(); - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return false; } - - void Main(); - - mozilla::ipc::IPCResult RecvTest1(uint32_t* value); - mozilla::ipc::IPCResult RecvTest2(); - mozilla::ipc::IPCResult RecvTest3(uint32_t* value); - mozilla::ipc::IPCResult RecvTest4_Begin(); - mozilla::ipc::IPCResult RecvTest4_NestedSync(); - mozilla::ipc::IPCResult RecvFinalTest_Begin(); - - bool ShouldContinueFromReplyTimeout() override { return false; } - virtual void ActorDestroy(ActorDestroyReason why) override { - passed("ok"); - QuitParent(); - } - - private: - bool inreply_; -}; - -class TestUrgencyChild : public PTestUrgencyChild { - public: - TestUrgencyChild(); - virtual ~TestUrgencyChild(); - - mozilla::ipc::IPCResult RecvStart(); - mozilla::ipc::IPCResult RecvReply1(uint32_t* reply); - mozilla::ipc::IPCResult RecvReply2(uint32_t* reply); - - virtual void ActorDestroy(ActorDestroyReason why) override { QuitChild(); } - - private: - uint32_t test_; -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestUrgency_h diff --git a/ipc/ipdl/test/cxx/TestUrgentHangs.cpp b/ipc/ipdl/test/cxx/TestUrgentHangs.cpp deleted file mode 100644 index 96227dd791..0000000000 --- a/ipc/ipdl/test/cxx/TestUrgentHangs.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * vim: sw=2 ts=4 et : - */ -#include "TestUrgentHangs.h" - -#include "IPDLUnitTests.h" // fail etc. -#include "prthread.h" -#if defined(XP_UNIX) -# include -#else -# include -#endif - -namespace mozilla { -namespace _ipdltest { - -//----------------------------------------------------------------------------- -// parent - -TestUrgentHangsParent::TestUrgentHangsParent() - : mInnerCount(0), mInnerUrgentCount(0) { - MOZ_COUNT_CTOR(TestUrgentHangsParent); -} - -TestUrgentHangsParent::~TestUrgentHangsParent() { - MOZ_COUNT_DTOR(TestUrgentHangsParent); -} - -void TestUrgentHangsParent::Main() { - SetReplyTimeoutMs(1000); - - // Should succeed despite the nested sleep call because the content process - // responded to the transaction. - if (!SendTest1_1()) fail("sending Test1_1"); - - // Fails with a timeout. - if (SendTest2()) fail("sending Test2"); - - // Also fails since we haven't gotten a response for Test2 yet. - if (SendTest3()) fail("sending Test3"); - - // Do a second round of testing once the reply to Test2 comes back. - MessageLoop::current()->PostDelayedTask( - NewNonOwningRunnableMethod( - "_ipdltest::TestUrgentHangsParent::SecondStage", this, - &TestUrgentHangsParent::SecondStage), - 3000); -} - -void TestUrgentHangsParent::SecondStage() { - // Send an async message that waits 2 seconds and then sends a sync message - // (which should be processed). - if (!SendTest4()) fail("sending Test4"); - - // Send a sync message that will time out because the child is waiting - // inside RecvTest4. - if (SendTest4_1()) fail("sending Test4_1"); - - MessageLoop::current()->PostDelayedTask( - NewNonOwningRunnableMethod("_ipdltest::TestUrgentHangsParent::ThirdStage", - this, &TestUrgentHangsParent::ThirdStage), - 3000); -} - -void TestUrgentHangsParent::ThirdStage() { - // The third stage does the same thing as the second stage except that the - // child sends an urgent message to us. In this case, we actually answer - // that message unconditionally. - - // Send an async message that waits 2 seconds and then sends a sync message - // (which should be processed). - if (!SendTest5()) fail("sending Test5"); - - // Send a sync message that will time out because the child is waiting - // inside RecvTest5. - if (SendTest5_1()) fail("sending Test5_1"); - - // Close the channel after the child finishes its work in RecvTest5. - MessageLoop::current()->PostDelayedTask( - NewNonOwningRunnableMethod("ipc::IToplevelProtocol::Close", this, - &TestUrgentHangsParent::Close), - 3000); -} - -mozilla::ipc::IPCResult TestUrgentHangsParent::RecvTest1_2() { - if (!SendTest1_3()) fail("sending Test1_3"); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestUrgentHangsParent::RecvTestInner() { - mInnerCount++; - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestUrgentHangsParent::RecvTestInnerUrgent() { - mInnerUrgentCount++; - return IPC_OK(); -} - -//----------------------------------------------------------------------------- -// child - -mozilla::ipc::IPCResult TestUrgentHangsChild::RecvTest1_1() { - if (!SendTest1_2()) fail("sending Test1_2"); - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestUrgentHangsChild::RecvTest1_3() { - PR_Sleep(PR_SecondsToInterval(2)); - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestUrgentHangsChild::RecvTest2() { - PR_Sleep(PR_SecondsToInterval(2)); - - // Should fail because of the timeout. - if (SendTestInner()) fail("sending TestInner"); - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestUrgentHangsChild::RecvTest3() { - fail("RecvTest3 should never be called"); - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestUrgentHangsChild::RecvTest4() { - PR_Sleep(PR_SecondsToInterval(2)); - - // This won't fail because we should handle Test4_1 here before actually - // sending TestInner to the parent. - if (!SendTestInner()) fail("sending TestInner"); - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestUrgentHangsChild::RecvTest4_1() { - // This should fail because Test4_1 timed out and hasn't gotten a response - // yet. - if (SendTestInner()) fail("sending TestInner"); - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestUrgentHangsChild::RecvTest5() { - PR_Sleep(PR_SecondsToInterval(2)); - - // This message will actually be handled by the parent even though it's in - // the timeout state. - if (!SendTestInnerUrgent()) fail("sending TestInner"); - - return IPC_OK(); -} - -mozilla::ipc::IPCResult TestUrgentHangsChild::RecvTest5_1() { - // This message will actually be handled by the parent even though it's in - // the timeout state. - if (!SendTestInnerUrgent()) fail("sending TestInner"); - - return IPC_OK(); -} - -TestUrgentHangsChild::TestUrgentHangsChild() { - MOZ_COUNT_CTOR(TestUrgentHangsChild); -} - -TestUrgentHangsChild::~TestUrgentHangsChild() { - MOZ_COUNT_DTOR(TestUrgentHangsChild); -} - -} // namespace _ipdltest -} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestUrgentHangs.h b/ipc/ipdl/test/cxx/TestUrgentHangs.h deleted file mode 100644 index facda522bf..0000000000 --- a/ipc/ipdl/test/cxx/TestUrgentHangs.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef mozilla__ipdltest_TestUrgentHangs_h -#define mozilla__ipdltest_TestUrgentHangs_h 1 - -#include "mozilla/_ipdltest/IPDLUnitTests.h" - -#include "mozilla/_ipdltest/PTestUrgentHangsParent.h" -#include "mozilla/_ipdltest/PTestUrgentHangsChild.h" - -namespace mozilla { -namespace _ipdltest { - -class TestUrgentHangsParent : public PTestUrgentHangsParent { - public: - TestUrgentHangsParent(); - virtual ~TestUrgentHangsParent(); - - static bool RunTestInProcesses() { return true; } - static bool RunTestInThreads() { return false; } - - void Main(); - void SecondStage(); - void ThirdStage(); - - mozilla::ipc::IPCResult RecvTest1_2(); - mozilla::ipc::IPCResult RecvTestInner(); - mozilla::ipc::IPCResult RecvTestInnerUrgent(); - - bool ShouldContinueFromReplyTimeout() override { return false; } - virtual void ActorDestroy(ActorDestroyReason why) override { - if (mInnerCount != 1) { - fail("wrong mInnerCount"); - } - if (mInnerUrgentCount != 2) { - fail("wrong mInnerUrgentCount"); - } - passed("ok"); - QuitParent(); - } - - private: - size_t mInnerCount, mInnerUrgentCount; -}; - -class TestUrgentHangsChild : public PTestUrgentHangsChild { - public: - TestUrgentHangsChild(); - virtual ~TestUrgentHangsChild(); - - mozilla::ipc::IPCResult RecvTest1_1(); - mozilla::ipc::IPCResult RecvTest1_3(); - mozilla::ipc::IPCResult RecvTest2(); - mozilla::ipc::IPCResult RecvTest3(); - mozilla::ipc::IPCResult RecvTest4(); - mozilla::ipc::IPCResult RecvTest4_1(); - mozilla::ipc::IPCResult RecvTest5(); - mozilla::ipc::IPCResult RecvTest5_1(); - - virtual void ActorDestroy(ActorDestroyReason why) override { QuitChild(); } -}; - -} // namespace _ipdltest -} // namespace mozilla - -#endif // ifndef mozilla__ipdltest_TestUrgentHangs_h diff --git a/ipc/ipdl/test/cxx/moz.build b/ipc/ipdl/test/cxx/moz.build index e2650df0aa..196dc09add 100644 --- a/ipc/ipdl/test/cxx/moz.build +++ b/ipc/ipdl/test/cxx/moz.build @@ -11,87 +11,11 @@ EXPORTS.mozilla._ipdltest += [ "IPDLUnitTests.h", "IPDLUnitTestTypes.h", "IPDLUnitTestUtils.h", - "TestActorPunning.h", - "TestAsyncReturns.h", - "TestBadActor.h", - "TestCancel.h", - "TestCrashCleanup.h", - "TestDataStructures.h", - "TestDemon.h", - "TestDesc.h", - "TestEndpointBridgeMain.h", - "TestEndpointOpens.h", - "TestFailedCtor.h", - "TestHangs.h", - "TestHighestPrio.h", - "TestInterruptErrorCleanup.h", - "TestInterruptRaces.h", - "TestInterruptShutdownRace.h", - "TestJSON.h", - "TestLatency.h", - "TestManyChildAllocs.h", - "TestMultiMgrs.h", - "TestNestedLoops.h", "TestOffMainThreadPainting.h", - "TestRaceDeadlock.h", - "TestRaceDeferral.h", - "TestRacyInterruptReplies.h", - "TestRacyReentry.h", - "TestRacyUndefer.h", - "TestRPC.h", - "TestSanity.h", - "TestSelfManageRoot.h", - "TestShmem.h", - "TestShutdown.h", - "TestStackHooks.h", - "TestSyncError.h", - "TestSyncHang.h", - "TestSyncWakeup.h", - "TestUniquePtrIPC.h", - "TestUrgency.h", - "TestUrgentHangs.h", ] SOURCES += [ - "TestActorPunning.cpp", - "TestAsyncReturns.cpp", - "TestBadActor.cpp", - "TestCancel.cpp", - "TestCrashCleanup.cpp", - "TestDataStructures.cpp", - "TestDemon.cpp", - "TestDesc.cpp", - "TestEndpointBridgeMain.cpp", - "TestEndpointOpens.cpp", - "TestFailedCtor.cpp", - "TestHangs.cpp", - "TestHighestPrio.cpp", - "TestInterruptErrorCleanup.cpp", - "TestInterruptRaces.cpp", - "TestInterruptShutdownRace.cpp", - "TestJSON.cpp", - "TestLatency.cpp", - "TestManyChildAllocs.cpp", - "TestMultiMgrs.cpp", - "TestNestedLoops.cpp", "TestOffMainThreadPainting.cpp", - "TestRaceDeadlock.cpp", - "TestRaceDeferral.cpp", - "TestRacyInterruptReplies.cpp", - "TestRacyReentry.cpp", - "TestRacyUndefer.cpp", - "TestRPC.cpp", - "TestSanity.cpp", - "TestSelfManageRoot.cpp", - "TestShmem.cpp", - "TestShutdown.cpp", - "TestStackHooks.cpp", - "TestSyncError.cpp", - "TestSyncHang.cpp", - "TestSyncWakeup.cpp", - "TestUniquePtrIPC.cpp", - "TestUrgency.cpp", - "TestUrgentHangs.cpp", ] SOURCES += [ @@ -101,70 +25,12 @@ SOURCES += [ ] IPDL_SOURCES += [ - "PTestActorPunning.ipdl", - "PTestActorPunningPunned.ipdl", - "PTestActorPunningSub.ipdl", - "PTestAsyncReturns.ipdl", - "PTestBadActor.ipdl", - "PTestBadActorSub.ipdl", - "PTestCancel.ipdl", - "PTestCrashCleanup.ipdl", - "PTestDataStructures.ipdl", - "PTestDataStructuresCommon.ipdlh", - "PTestDataStructuresSub.ipdl", - "PTestDemon.ipdl", - "PTestDesc.ipdl", - "PTestDescSub.ipdl", - "PTestDescSubsub.ipdl", - "PTestEndpointBridgeMain.ipdl", - "PTestEndpointBridgeMainSub.ipdl", - "PTestEndpointBridgeSub.ipdl", - "PTestEndpointOpens.ipdl", - "PTestEndpointOpensOpened.ipdl", - "PTestFailedCtor.ipdl", - "PTestFailedCtorSub.ipdl", - "PTestFailedCtorSubsub.ipdl", - "PTestHandle.ipdl", - "PTestHangs.ipdl", - "PTestHighestPrio.ipdl", "PTestIndirectProtocolParam.ipdlh", "PTestIndirectProtocolParamFirst.ipdl", "PTestIndirectProtocolParamManage.ipdl", "PTestIndirectProtocolParamSecond.ipdl", - "PTestInterruptErrorCleanup.ipdl", - "PTestInterruptRaces.ipdl", - "PTestInterruptShutdownRace.ipdl", - "PTestJSON.ipdl", - "PTestLatency.ipdl", - "PTestManyChildAllocs.ipdl", - "PTestManyChildAllocsSub.ipdl", - "PTestMultiMgrs.ipdl", - "PTestMultiMgrsBottom.ipdl", - "PTestMultiMgrsLeft.ipdl", - "PTestMultiMgrsRight.ipdl", - "PTestNestedLoops.ipdl", "PTestPaintThread.ipdl", "PTestPriority.ipdl", - "PTestRaceDeadlock.ipdl", - "PTestRaceDeferral.ipdl", - "PTestRacyInterruptReplies.ipdl", - "PTestRacyReentry.ipdl", - "PTestRacyUndefer.ipdl", - "PTestRPC.ipdl", - "PTestSanity.ipdl", - "PTestSelfManage.ipdl", - "PTestSelfManageRoot.ipdl", - "PTestShmem.ipdl", - "PTestShutdown.ipdl", - "PTestShutdownSub.ipdl", - "PTestShutdownSubsub.ipdl", - "PTestStackHooks.ipdl", - "PTestSyncError.ipdl", - "PTestSyncHang.ipdl", - "PTestSyncWakeup.ipdl", - "PTestUniquePtrIPC.ipdl", - "PTestUrgency.ipdl", - "PTestUrgentHangs.ipdl", ] include("/ipc/chromium/chromium-config.mozbuild") diff --git a/ipc/ipdl/test/gtest/IPDLUnitTest.h b/ipc/ipdl/test/gtest/IPDLUnitTest.h index f4548b508c..e2c44630b7 100644 --- a/ipc/ipdl/test/gtest/IPDLUnitTest.h +++ b/ipc/ipdl/test/gtest/IPDLUnitTest.h @@ -27,52 +27,75 @@ class IPDLTestHelper { virtual void TestBody() = 0; }; -#define IPDL_TEST_CLASS_NAME_(actorname) IPDL_TEST_##actorname +#define IPDL_TEST_CLASS_NAME_(actorname, ...) IPDL_TEST_##actorname##__VA_ARGS__ -#define IPDL_TEST_HEAD_(actorname) \ - class IPDL_TEST_CLASS_NAME_(actorname) \ - : public ::mozilla::_ipdltest::IPDLTestHelper { \ - public: \ - IPDL_TEST_CLASS_NAME_(actorname)() : mActor(new actorname##Parent) {} \ - \ - private: \ - void TestBody() override; \ - const char* GetName() override { return sName; }; \ - actorname##Parent* GetActor() override { return mActor; }; \ - \ - RefPtr mActor; \ - static const char* sName; \ - }; \ - const char* IPDL_TEST_CLASS_NAME_(actorname)::sName = \ - ::mozilla::_ipdltest::RegisterAllocChildActor( \ - #actorname, []() -> ::mozilla::ipc::IToplevelProtocol* { \ - return new actorname##Child; \ +#define IPDL_TEST_HEAD_(actorname, ...) \ + class IPDL_TEST_CLASS_NAME_(actorname, ##__VA_ARGS__) \ + : public ::mozilla::_ipdltest::IPDLTestHelper { \ + public: \ + IPDL_TEST_CLASS_NAME_(actorname, ##__VA_ARGS__) \ + () : mActor(new actorname##Parent) {} \ + \ + private: \ + void TestBody() override; \ + const char* GetName() override { return sName; }; \ + actorname##Parent* GetActor() override { return mActor; }; \ + \ + RefPtr mActor; \ + static const char* sName; \ + }; \ + const char* IPDL_TEST_CLASS_NAME_(actorname, ##__VA_ARGS__)::sName = \ + ::mozilla::_ipdltest::RegisterAllocChildActor( \ + #actorname, []() -> ::mozilla::ipc::IToplevelProtocol* { \ + return new actorname##Child; \ }); -#define IPDL_TEST_DECL_(testgroup, actorname, crossprocess) \ - TEST(testgroup, actorname) \ - { \ - IPDL_TEST_CLASS_NAME_(actorname) test; \ - test.TestWrapper(crossprocess); \ +#define IPDL_TEST_DECL_CROSSPROCESS_(actorname, ...) \ + TEST(IPDLTest_CrossProcess, actorname##__VA_ARGS__) \ + { \ + IPDL_TEST_CLASS_NAME_(actorname, ##__VA_ARGS__) test; \ + test.TestWrapper(true); \ } -#define IPDL_TEST_BODY_SEGUE_(actorname) \ - void IPDL_TEST_CLASS_NAME_(actorname)::TestBody() +#define IPDL_TEST_DECL_CROSSTHREAD_(actorname, ...) \ + TEST(IPDLTest_CrossThread, actorname##__VA_ARGS__) \ + { \ + IPDL_TEST_CLASS_NAME_(actorname, ##__VA_ARGS__) test; \ + test.TestWrapper(false); \ + } + +#define IPDL_TEST_DECL_ANY_(actorname, ...) \ + IPDL_TEST_DECL_CROSSPROCESS_(actorname, ##__VA_ARGS__) \ + IPDL_TEST_DECL_CROSSTHREAD_(actorname, ##__VA_ARGS__) + +#define IPDL_TEST_BODY_SEGUE_(actorname, ...) \ + void IPDL_TEST_CLASS_NAME_(actorname, ##__VA_ARGS__)::TestBody() -// Declare a basic IPDL unit test which will be run in both both cross-thread -// and cross-process configurations. The actor `actorname` will be instantiated -// by default-constructing the parent & child actors in the relevant processes, -// and the test block will be executed, with `mActor` being a pointer to the -// parent actor. The test is asynchronous, and will end when the IPDL connection -// between the created actors is destroyed. +// Declare an IPDL unit test. The `mode` should be set to either `CROSSTHREAD`, +// `CROSSPROCESS`, or `ANY` to run in the selected configuration(s). The actor +// `actorname` will be instantiated by default-constructing the parent & child +// actors in the relevant processes, and the test block will be executed, with +// `mActor` being a pointer to the parent actor. The test is asynchronous, and +// will end when the IPDL connection between the created actors is destroyed. +// `aCrossProcess` will indicate whether the test is running cross-process +// (true) or cross-thread (false). +// +// You can optionally pass a single additional argument which provides a +// `testname`, which will be appended to `actorname` as the full GTest test +// name. It should be of the form usually passed to the `TEST` gtest macro (an +// identifier). // // GTest assertions fired in the child process will be relayed to the parent // process, and should generally function correctly. -#define IPDL_TEST(actorname) \ - IPDL_TEST_HEAD_(actorname) \ - IPDL_TEST_DECL_(IPDLTest_CrossProcess, actorname, true) \ - IPDL_TEST_DECL_(IPDLTest_CrossThread, actorname, false) \ - IPDL_TEST_BODY_SEGUE_(actorname) +#define IPDL_TEST_ON(mode, actorname, ...) \ + IPDL_TEST_HEAD_(actorname, ##__VA_ARGS__) \ + IPDL_TEST_DECL_##mode##_(actorname, ##__VA_ARGS__) \ + IPDL_TEST_BODY_SEGUE_(actorname, ##__VA_ARGS__) + +// Declare an IPDL unit test that will run in both cross-thread and +// cross-process configurations. See the documentation of IPDL_TEST_ON for more +// info. +#define IPDL_TEST(actorname, ...) IPDL_TEST_ON(ANY, actorname, ##__VA_ARGS__) } // namespace mozilla::_ipdltest diff --git a/ipc/ipdl/test/gtest/PTestAsyncReturns.ipdl b/ipc/ipdl/test/gtest/PTestAsyncReturns.ipdl new file mode 100644 index 0000000000..5cae489b4a --- /dev/null +++ b/ipc/ipdl/test/gtest/PTestAsyncReturns.ipdl @@ -0,0 +1,19 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +namespace mozilla { +namespace _ipdltest { + +[ChildProc=any, ChildImpl=virtual, ParentImpl=virtual] +protocol PTestAsyncReturns { +child: + async Ping() returns (bool one); + async NoReturn() returns (bool unused); + +parent: + async Pong() returns (uint32_t param1, uint32_t param2); +}; + +} // namespace mozilla +} // namespace _ipdltest diff --git a/ipc/ipdl/test/gtest/PTestCancel.ipdl b/ipc/ipdl/test/gtest/PTestCancel.ipdl new file mode 100644 index 0000000000..b0af04bae7 --- /dev/null +++ b/ipc/ipdl/test/gtest/PTestCancel.ipdl @@ -0,0 +1,39 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +namespace mozilla { +namespace _ipdltest { + +[NestedUpTo=inside_sync, ChildProc=any, ChildImpl=virtual, ParentImpl=virtual] +sync protocol PTestCancel +{ + // Immediate Cancel: child sync function cancels immediately, both ends check after cancellation. +child: + [Nested=inside_sync] sync ImmediateCancel(); + + + // Nested Cancel: child nested sync function cancels +child: + async StartNestedCancel(); + [Nested=inside_sync] sync NestedCancel(); +parent: + [Nested=inside_sync] sync CallNestedCancel(); + + + // Nested Cancel Parent: parent nested sync function cancels +child: + [Nested=inside_sync] sync StartNestedCancelParent(); +parent: + [Nested=inside_sync] sync NestedCancelParent(); + + +// Common functions to check that sync messages still work. +child: + [Nested=inside_sync] sync CheckChild() returns (uint32_t reply); +parent: + [Nested=inside_sync] sync CheckParent() returns (uint32_t reply); +}; + +} // namespace _ipdltest +} // namespace mozilla diff --git a/ipc/ipdl/test/gtest/PTestDataStructures.ipdl b/ipc/ipdl/test/gtest/PTestDataStructures.ipdl new file mode 100644 index 0000000000..7b2bdd3ced --- /dev/null +++ b/ipc/ipdl/test/gtest/PTestDataStructures.ipdl @@ -0,0 +1,106 @@ +include protocol PTestDataStructuresSub; +include PTestDataStructuresCommon; + +include "mozilla/GfxMessageUtils.h"; + +namespace mozilla { +namespace _ipdltest { + +[ChildProc=any, ChildImpl=virtual, ParentImpl=virtual] +sync protocol PTestDataStructures { + manages PTestDataStructuresSub; + +child: + async PTestDataStructuresSub(int i); + + async Start(); + +parent: + async __delete__(); + + sync TestArrayOfInt(int[] i1) + returns (int[] o1); + + sync TestArrayOfActor(PTestDataStructuresSub[] i1) + returns (PTestDataStructuresSub[] o1); + + sync TestUnion(IntDouble i1, + IntDouble i2) + returns (IntDouble o1, + IntDouble o2); + + sync TestArrayOfUnion(IntDouble[] i1) + returns (IntDouble[] o1); + + sync TestUnionWithArray(IntDoubleArrays i1, + IntDoubleArrays i2, + IntDoubleArrays i3) + returns (IntDoubleArrays o1, + IntDoubleArrays o2, + IntDoubleArrays o3); + + sync TestArrayOfUnionWithArray(IntDoubleArrays[] i1) + returns (IntDoubleArrays[] o1); + + sync TestStructWithActor(ActorWrapper a1) + returns (ActorWrapper o1); + + sync TestUnionWithActors(Actors i1, + Actors i2, + Actors i3) + returns (Actors o1, + Actors o2, + Actors o3); + + sync TestArrayOfUnionWithActors(Actors[] i1) + returns (Actors[] o1); + + sync TestUnions(Unions i1, + Unions i2, + Unions i3, + Unions i4) + returns (Unions o1, + Unions o2, + Unions o3, + Unions o4); + + sync TestArrayOfUnions(Unions[] i1) + returns (Unions[] o1); + + sync TestStruct(SIntDouble i) + returns (SIntDouble o); + + sync TestStructWithArrays(SIntDoubleArrays i) + returns (SIntDoubleArrays o); + + sync TestStructWithActors(SActors i) + returns (SActors o); + + sync TestStructs(Structs i) + returns (Structs o); + + sync TestUnionWithStructs(WithStructs i1, + WithStructs i2, + WithStructs i3, + WithStructs i4, + WithStructs i5) + returns (WithStructs o1, + WithStructs o2, + WithStructs o3, + WithStructs o4, + WithStructs o5); + + sync TestStructWithUnions(WithUnions i) + returns (WithUnions o); + + sync TestUnionWithCxx(Op[] ops); + + // test that the ParamTraits::Read() workaround for + // nsTArray's incorrect memmove() semantics works properly + // (nsIntRegion isn't memmove()able) + sync TestNsIntRegion(nsIntRegion[] ops); +}; + +} // namespace _ipdltest +} // namespace mozilla + diff --git a/ipc/ipdl/test/gtest/PTestDataStructuresCommon.ipdlh b/ipc/ipdl/test/gtest/PTestDataStructuresCommon.ipdlh new file mode 100644 index 0000000000..36549cc2c6 --- /dev/null +++ b/ipc/ipdl/test/gtest/PTestDataStructuresCommon.ipdlh @@ -0,0 +1,107 @@ +include protocol PTestDataStructuresSub; + +using struct mozilla::null_t from "mozilla/ipc/IPCCore.h"; +using nsIntRegion from "nsRegion.h"; + +namespace mozilla { +namespace _foo { + +union IntDouble { + int; + double; +}; + +struct SIntDouble { + int i; + double d; +}; + +union IntDoubleArrays { + int; + int[]; + double[]; +}; + +struct SIntDoubleArrays { + int i; + int[] ai; + double[] ad; +}; + +struct ActorWrapper { + nullable PTestDataStructuresSub actor; +}; + +union Actors { + int; + int[]; + PTestDataStructuresSub[]; +}; + +struct SActors { + int i; + int[] ai; + PTestDataStructuresSub[] ap; +}; + +union Unions { + int; + int[]; + PTestDataStructuresSub[]; + Actors[]; +}; + +struct Structs { + int i; + int[] ai; + PTestDataStructuresSub[] ap; + SActors[] aa; +}; + +union WithStructs { + int; + int[]; + PTestDataStructuresSub[]; + SActors[]; + Structs[]; +}; + +struct WithUnions { + int i; + int[] ai; + PTestDataStructuresSub[] ap; + Actors[] aa; + Unions[] au; +}; + +struct CommonAttrs { bool dummy; }; +struct FooAttrs { int dummy; }; +struct BarAttrs { float dummy; }; +union SpecificAttrs { + FooAttrs; + BarAttrs; +}; +struct Attrs { + CommonAttrs common; + SpecificAttrs specific; +}; +struct SetAttrs { + PTestDataStructuresSub x; + Attrs attrs; +}; +union Op { null_t; SetAttrs; }; + +struct ShmemStruct { + int i; + Shmem mem; +}; + +union ShmemUnion { + int; + Shmem; +}; + +struct Empty { }; + +} // namespace _foo +} // namespace mozilla diff --git a/ipc/ipdl/test/gtest/PTestDataStructuresSub.ipdl b/ipc/ipdl/test/gtest/PTestDataStructuresSub.ipdl new file mode 100644 index 0000000000..f9f7d69411 --- /dev/null +++ b/ipc/ipdl/test/gtest/PTestDataStructuresSub.ipdl @@ -0,0 +1,15 @@ +include protocol PTestDataStructures; + +namespace mozilla { +namespace _ipdltest { + +[ChildProc=any, ChildImpl=virtual, ParentImpl=virtual] +async protocol PTestDataStructuresSub { + manager PTestDataStructures; + +parent: + async __delete__(); +}; + +} // namespace _ipdltest +} // namespace mozilla diff --git a/ipc/ipdl/test/gtest/PTestDescendant.ipdl b/ipc/ipdl/test/gtest/PTestDescendant.ipdl new file mode 100644 index 0000000000..b8524babab --- /dev/null +++ b/ipc/ipdl/test/gtest/PTestDescendant.ipdl @@ -0,0 +1,22 @@ +include protocol PTestDescendantSub; +include protocol PTestDescendantSubsub; + +namespace mozilla { +namespace _ipdltest { + +[ChildProc=any, ChildImpl=virtual, ParentImpl=virtual] +async protocol PTestDescendant { + manages PTestDescendantSub; +child: + async PTestDescendantSub(nullable PTestDescendantSubsub dummy); + + async Test(PTestDescendantSubsub a); + + async __delete__(); + +parent: + async Ok(PTestDescendantSubsub a); +}; + +} +} diff --git a/ipc/ipdl/test/gtest/PTestDescendantSub.ipdl b/ipc/ipdl/test/gtest/PTestDescendantSub.ipdl new file mode 100644 index 0000000000..dd76801a43 --- /dev/null +++ b/ipc/ipdl/test/gtest/PTestDescendantSub.ipdl @@ -0,0 +1,19 @@ +include protocol PTestDescendant; +include protocol PTestDescendantSubsub; + +namespace mozilla { +namespace _ipdltest { + +[ChildProc=any, ChildImpl=virtual, ParentImpl=virtual] +async protocol PTestDescendantSub { + manager PTestDescendant; + manages PTestDescendantSubsub; + +child: + async __delete__(); + + async PTestDescendantSubsub(); +}; + +} +} diff --git a/ipc/ipdl/test/gtest/PTestDescendantSubsub.ipdl b/ipc/ipdl/test/gtest/PTestDescendantSubsub.ipdl new file mode 100644 index 0000000000..a2fac12d72 --- /dev/null +++ b/ipc/ipdl/test/gtest/PTestDescendantSubsub.ipdl @@ -0,0 +1,14 @@ +include protocol PTestDescendantSub; + +namespace mozilla { +namespace _ipdltest { + +[ChildProc=any, ChildImpl=virtual, ParentImpl=virtual] +async protocol PTestDescendantSubsub { + manager PTestDescendantSub; +child: + async __delete__(); +}; + +} +} diff --git a/ipc/ipdl/test/gtest/PTestEndpointOpens.ipdl b/ipc/ipdl/test/gtest/PTestEndpointOpens.ipdl new file mode 100644 index 0000000000..0ee1759b7f --- /dev/null +++ b/ipc/ipdl/test/gtest/PTestEndpointOpens.ipdl @@ -0,0 +1,22 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +include protocol PTestEndpointOpensOpened; + +namespace mozilla { +namespace _ipdltest { + +[ChildProc=any, ChildImpl=virtual, ParentImpl=virtual] +protocol PTestEndpointOpens { +child: + async Start(); + +parent: + async StartSubprotocol(Endpoint endpoint); + + async __delete__(); +}; + +} // namespace _ipdltest +} // namespace mozilla diff --git a/ipc/ipdl/test/gtest/PTestEndpointOpensOpened.ipdl b/ipc/ipdl/test/gtest/PTestEndpointOpensOpened.ipdl new file mode 100644 index 0000000000..1baa662235 --- /dev/null +++ b/ipc/ipdl/test/gtest/PTestEndpointOpensOpened.ipdl @@ -0,0 +1,22 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +namespace mozilla { +namespace _ipdltest { + +// (Opens protocols can have different semantics than the endpoints +// that opened them) +[ChildProc=any, ChildImpl=virtual, ParentImpl=virtual] +sync protocol PTestEndpointOpensOpened { +child: + async Hi(); + +parent: + async Hello(); + sync HelloSync(); + async __delete__(); +}; + +} // namespace _ipdltest +} // namespace mozilla diff --git a/ipc/ipdl/test/gtest/PTestHangs.ipdl b/ipc/ipdl/test/gtest/PTestHangs.ipdl new file mode 100644 index 0000000000..7df791cee6 --- /dev/null +++ b/ipc/ipdl/test/gtest/PTestHangs.ipdl @@ -0,0 +1,20 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +[MoveOnly] using mozilla::CrossProcessSemaphoreHandle from "mozilla/ipc/CrossProcessSemaphore.h"; + +namespace mozilla { +namespace _ipdltest { + +[ChildProc=any, ChildImpl=virtual, ParentImpl=virtual] +sync protocol PTestHangs { +parent: + sync Hang(uint32_t hangMode, CrossProcessSemaphoreHandle timeout); +child: + async Start(uint32_t hangMode) + returns (bool detectedHang); +}; + +} // namespace _ipdltest +} // namespace mozilla diff --git a/ipc/ipdl/test/gtest/PTestJSON.ipdl b/ipc/ipdl/test/gtest/PTestJSON.ipdl new file mode 100644 index 0000000000..2486e85378 --- /dev/null +++ b/ipc/ipdl/test/gtest/PTestJSON.ipdl @@ -0,0 +1,43 @@ +include protocol PTestJSONHandle; + +using struct mozilla::void_t from "mozilla/ipc/IPCCore.h"; +using struct mozilla::null_t from "mozilla/ipc/IPCCore.h"; + +namespace mozilla { +namespace _ipdltest { + +[Comparable] +struct KeyValue { + nsString key; + JSONVariant value; +}; + +[Comparable] +union JSONVariant { + void_t; + null_t; + bool; + int; + double; + nsString; + PTestJSONHandle; + KeyValue[]; + JSONVariant[]; +}; + +[ChildProc=any, ChildImpl=virtual, ParentImpl=virtual] +sync protocol PTestJSON { + manages PTestJSONHandle; + +child: + async Start(); + +parent: + async PTestJSONHandle(); + sync Test(JSONVariant i) + returns (JSONVariant o); + async __delete__(); +}; + +} // namespace mozilla +} // namespace _ipdltest diff --git a/ipc/ipdl/test/gtest/PTestJSONHandle.ipdl b/ipc/ipdl/test/gtest/PTestJSONHandle.ipdl new file mode 100644 index 0000000000..81bbb913b4 --- /dev/null +++ b/ipc/ipdl/test/gtest/PTestJSONHandle.ipdl @@ -0,0 +1,15 @@ +include protocol PTestJSON; + +namespace mozilla { +namespace _ipdltest { + +[ChildProc=any, ChildImpl=virtual, ParentImpl=virtual] +protocol PTestJSONHandle { + manager PTestJSON; + +child: + async __delete__(); +}; + +} // namespace mozilla +} // namespace _ipdltest diff --git a/ipc/ipdl/test/gtest/PTestManyChildAllocs.ipdl b/ipc/ipdl/test/gtest/PTestManyChildAllocs.ipdl new file mode 100644 index 0000000000..149e5aefab --- /dev/null +++ b/ipc/ipdl/test/gtest/PTestManyChildAllocs.ipdl @@ -0,0 +1,18 @@ +include protocol PTestManyChildAllocsSub; + +namespace mozilla { +namespace _ipdltest { + +[ChildProc=any, ChildImpl=virtual, ParentImpl=virtual] +protocol PTestManyChildAllocs { + manages PTestManyChildAllocsSub; +child: + async Go(); // start allocating + +parent: + async Done(); + async PTestManyChildAllocsSub(); +}; + +} // namespace _ipdltest +} // namespace mozilla diff --git a/ipc/ipdl/test/gtest/PTestManyChildAllocsSub.ipdl b/ipc/ipdl/test/gtest/PTestManyChildAllocsSub.ipdl new file mode 100644 index 0000000000..4a34af2e52 --- /dev/null +++ b/ipc/ipdl/test/gtest/PTestManyChildAllocsSub.ipdl @@ -0,0 +1,18 @@ +include protocol PTestManyChildAllocs; + +namespace mozilla { +namespace _ipdltest { + +[ChildProc=any, ChildImpl=virtual, ParentImpl=virtual] +protocol PTestManyChildAllocsSub { + manager PTestManyChildAllocs; + +child: + async __delete__(); + +parent: + async Hello(); +}; + +} // namespace _ipdltest +} // namespace mozilla diff --git a/ipc/ipdl/test/gtest/PTestMostNested.ipdl b/ipc/ipdl/test/gtest/PTestMostNested.ipdl new file mode 100644 index 0000000000..2c6750137c --- /dev/null +++ b/ipc/ipdl/test/gtest/PTestMostNested.ipdl @@ -0,0 +1,23 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +namespace mozilla { +namespace _ipdltest { + +[ChildProc=any, NestedUpTo=inside_cpow, ChildImpl=virtual, ParentImpl=virtual] +sync protocol PTestMostNested +{ +parent: + [Nested=inside_cpow] async Msg1(); + [Nested=inside_sync] sync Msg2(); + [Nested=inside_cpow] async Msg3(); + [Nested=inside_cpow] sync Msg4(); + +child: + async Start(); + [Nested=inside_sync] sync StartInner(); +}; + +} +} diff --git a/ipc/ipdl/test/gtest/PTestMultiMgrs.ipdl b/ipc/ipdl/test/gtest/PTestMultiMgrs.ipdl new file mode 100644 index 0000000000..80de57459d --- /dev/null +++ b/ipc/ipdl/test/gtest/PTestMultiMgrs.ipdl @@ -0,0 +1,23 @@ +include protocol PTestMultiMgrsLeft; +include protocol PTestMultiMgrsRight; + +namespace mozilla { +namespace _ipdltest { + +[ChildProc=any, ChildImpl=virtual, ParentImpl=virtual] +protocol PTestMultiMgrs { + manages PTestMultiMgrsLeft; + manages PTestMultiMgrsRight; + +parent: + async OK(); + +child: + async PTestMultiMgrsLeft(); + async PTestMultiMgrsRight(); + async Check(); + async __delete__(); +}; + +} // namespace _ipdltest +} // namespace mozilla diff --git a/ipc/ipdl/test/gtest/PTestMultiMgrsBottom.ipdl b/ipc/ipdl/test/gtest/PTestMultiMgrsBottom.ipdl new file mode 100644 index 0000000000..03bbc7f886 --- /dev/null +++ b/ipc/ipdl/test/gtest/PTestMultiMgrsBottom.ipdl @@ -0,0 +1,16 @@ +include protocol PTestMultiMgrsLeft; +include protocol PTestMultiMgrsRight; + +namespace mozilla { +namespace _ipdltest { + +[ChildProc=any, ChildImpl=virtual, ParentImpl=virtual] +protocol PTestMultiMgrsBottom { + manager PTestMultiMgrsLeft or PTestMultiMgrsRight; + +child: + async __delete__(); +}; + +} // namespace _ipdltest +} // namespace mozilla diff --git a/ipc/ipdl/test/gtest/PTestMultiMgrsLeft.ipdl b/ipc/ipdl/test/gtest/PTestMultiMgrsLeft.ipdl new file mode 100644 index 0000000000..ee62fc3487 --- /dev/null +++ b/ipc/ipdl/test/gtest/PTestMultiMgrsLeft.ipdl @@ -0,0 +1,19 @@ +include protocol PTestMultiMgrs; +include protocol PTestMultiMgrsBottom; + +namespace mozilla { +namespace _ipdltest { + +[ChildProc=any, ChildImpl=virtual, ParentImpl=virtual] +protocol PTestMultiMgrsLeft { + manager PTestMultiMgrs; + + manages PTestMultiMgrsBottom; + +child: + async PTestMultiMgrsBottom(); + async __delete__(); +}; + +} // namespace _ipdltest +} // namespace mozilla diff --git a/ipc/ipdl/test/gtest/PTestMultiMgrsRight.ipdl b/ipc/ipdl/test/gtest/PTestMultiMgrsRight.ipdl new file mode 100644 index 0000000000..202f60247e --- /dev/null +++ b/ipc/ipdl/test/gtest/PTestMultiMgrsRight.ipdl @@ -0,0 +1,19 @@ +include protocol PTestMultiMgrs; +include protocol PTestMultiMgrsBottom; + +namespace mozilla { +namespace _ipdltest { + +[ChildProc=any, ChildImpl=virtual, ParentImpl=virtual] +protocol PTestMultiMgrsRight { + manager PTestMultiMgrs; + + manages PTestMultiMgrsBottom; + +child: + async PTestMultiMgrsBottom(); + async __delete__(); +}; + +} // namespace _ipdltest +} // namespace mozilla diff --git a/ipc/ipdl/test/gtest/PTestSelfManage.ipdl b/ipc/ipdl/test/gtest/PTestSelfManage.ipdl new file mode 100644 index 0000000000..e7dc077808 --- /dev/null +++ b/ipc/ipdl/test/gtest/PTestSelfManage.ipdl @@ -0,0 +1,17 @@ +include protocol PTestSelfManageRoot; + +namespace mozilla { +namespace _ipdltest { + +[ChildProc=any, ChildImpl=virtual, ParentImpl=virtual] +protocol PTestSelfManage { + manager PTestSelfManageRoot or PTestSelfManage; + manages PTestSelfManage; + +child: + async PTestSelfManage(); + async __delete__(); +}; + +} // namespace mozilla +} // namespace _ipdltest diff --git a/ipc/ipdl/test/gtest/PTestSelfManageRoot.ipdl b/ipc/ipdl/test/gtest/PTestSelfManageRoot.ipdl new file mode 100644 index 0000000000..37e8218720 --- /dev/null +++ b/ipc/ipdl/test/gtest/PTestSelfManageRoot.ipdl @@ -0,0 +1,16 @@ +include protocol PTestSelfManage; + +namespace mozilla { +namespace _ipdltest { + +[ChildProc=any, ChildImpl=virtual, ParentImpl=virtual] +protocol PTestSelfManageRoot { + manages PTestSelfManage; + +child: + async PTestSelfManage(); + async __delete__(); +}; + +} // namespace mozilla +} // namespace _ipdltest diff --git a/ipc/ipdl/test/gtest/PTestShmem.ipdl b/ipc/ipdl/test/gtest/PTestShmem.ipdl new file mode 100644 index 0000000000..33eeabffdf --- /dev/null +++ b/ipc/ipdl/test/gtest/PTestShmem.ipdl @@ -0,0 +1,15 @@ +namespace mozilla { +namespace _ipdltest { + +[ChildProc=any, ChildImpl=virtual, ParentImpl=virtual] +protocol PTestShmem { +child: + async Give(Shmem mem, Shmem unsafe, uint32_t expectedSize); + +parent: + async Take(Shmem mem, Shmem unsafe, uint32_t expectedSize); + async __delete__(); +}; + +} +} diff --git a/ipc/ipdl/test/gtest/PTestSyncError.ipdl b/ipc/ipdl/test/gtest/PTestSyncError.ipdl new file mode 100644 index 0000000000..e549bde919 --- /dev/null +++ b/ipc/ipdl/test/gtest/PTestSyncError.ipdl @@ -0,0 +1,16 @@ +namespace mozilla { +namespace _ipdltest { + +[ChildProc=any, ChildImpl=virtual, ParentImpl=virtual] +sync protocol PTestSyncError { + +child: + async Start(); + +parent: + sync Error(); + async __delete__(); +}; + +} // namespace mozilla +} // namespace _ipdltest diff --git a/ipc/ipdl/test/gtest/PTestUniquePtrIPC.ipdl b/ipc/ipdl/test/gtest/PTestUniquePtrIPC.ipdl new file mode 100644 index 0000000000..b55d8f19d1 --- /dev/null +++ b/ipc/ipdl/test/gtest/PTestUniquePtrIPC.ipdl @@ -0,0 +1,17 @@ +namespace mozilla { +namespace _ipdltest { + +struct DummyStruct { + int x; +}; + +[ChildProc=any, ChildImpl=virtual, ParentImpl=virtual] +protocol PTestUniquePtrIPC { +child: + async TestMessage(UniquePtr a1, UniquePtr a2, + DummyStruct a3, UniquePtr a4); + async TestSendReference(UniquePtr a); +}; + +} // namespace _ipdltest +} // namespace mozilla diff --git a/ipc/ipdl/test/gtest/PTestUrgency.ipdl b/ipc/ipdl/test/gtest/PTestUrgency.ipdl new file mode 100644 index 0000000000..ee9b44b543 --- /dev/null +++ b/ipc/ipdl/test/gtest/PTestUrgency.ipdl @@ -0,0 +1,20 @@ +namespace mozilla { +namespace _ipdltest { + +[ChildProc=any, NestedUpTo=inside_cpow, ChildImpl=virtual, ParentImpl=virtual] +sync protocol PTestUrgency +{ +parent: + [Nested=inside_sync] sync Test1() returns (uint32_t result); + async Test2(); + sync Test3() returns (uint32_t result); + sync FinalTest_Begin(); + +child: + async Start(); + [Nested=inside_sync] sync Reply1() returns (uint32_t result); + [Nested=inside_sync] sync Reply2() returns (uint32_t result); +}; + +} // namespace _ipdltest +} // namespace mozilla diff --git a/ipc/ipdl/test/gtest/TestAsyncReturns.cpp b/ipc/ipdl/test/gtest/TestAsyncReturns.cpp new file mode 100644 index 0000000000..960a2954db --- /dev/null +++ b/ipc/ipdl/test/gtest/TestAsyncReturns.cpp @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * These tests ensure that async function return values work as expected. + */ + +#include "gtest/gtest.h" + +#include "mozilla/_ipdltest/IPDLUnitTest.h" +#include "mozilla/_ipdltest/PTestAsyncReturnsChild.h" +#include "mozilla/_ipdltest/PTestAsyncReturnsParent.h" + +using namespace mozilla::ipc; + +namespace mozilla::_ipdltest { + +static uint32_t sMagic1 = 0x105b59fb; +static uint32_t sMagic2 = 0x09b6f5e3; + +class TestAsyncReturnsChild : public PTestAsyncReturnsChild { + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TestAsyncReturnsChild, override) + private: + IPCResult RecvPing(PingResolver&& resolve) final override { + SendPong( + [resolve](const std::tuple& aParam) { + EXPECT_EQ(std::get<0>(aParam), sMagic1); + EXPECT_EQ(std::get<1>(aParam), sMagic2); + resolve(true); + }, + [](ResponseRejectReason&& aReason) { FAIL() << "sending Pong"; }); + return IPC_OK(); + } + + IPCResult RecvNoReturn(NoReturnResolver&& resolve) final override { + // Not calling `resolve` intentionally + return IPC_OK(); + } + + ~TestAsyncReturnsChild() = default; +}; + +class TestAsyncReturnsParent : public PTestAsyncReturnsParent { + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TestAsyncReturnsParent, override) + private: + IPCResult RecvPong(PongResolver&& resolve) final override { + resolve(std::tuple(sMagic1, sMagic2)); + return IPC_OK(); + } + + ~TestAsyncReturnsParent() = default; +}; + +IPDL_TEST(TestAsyncReturns, NoReturn) { + mActor->SendNoReturn( + [](bool unused) { FAIL() << "resolve handler should not be called"; }, + [=](ResponseRejectReason&& aReason) { + if (aReason != ResponseRejectReason::ResolverDestroyed) { + FAIL() << "reject with wrong reason"; + } + mActor->Close(); + }); +} + +IPDL_TEST(TestAsyncReturns, PingPong) { + mActor->SendPing( + [=](bool one) { + EXPECT_TRUE(one); + mActor->Close(); + }, + [](ResponseRejectReason&& aReason) { FAIL() << "sending Ping"; }); +} + +} // namespace mozilla::_ipdltest diff --git a/ipc/ipdl/test/gtest/TestCancel.cpp b/ipc/ipdl/test/gtest/TestCancel.cpp new file mode 100644 index 0000000000..79f31751dd --- /dev/null +++ b/ipc/ipdl/test/gtest/TestCancel.cpp @@ -0,0 +1,126 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Test that IPC channel transaction cancellation (which applies to nested sync + * messages) works as expected. + */ + +#include "gtest/gtest.h" + +#include "mozilla/_ipdltest/IPDLUnitTest.h" +#include "mozilla/_ipdltest/PTestCancelChild.h" +#include "mozilla/_ipdltest/PTestCancelParent.h" + +using namespace mozilla::ipc; + +namespace mozilla::_ipdltest { + +class TestCancelParent : public PTestCancelParent { + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TestCancelParent, override) + private: + IPCResult RecvCallNestedCancel() final override { + EXPECT_FALSE(SendNestedCancel()) << "SendNestedCancel should fail"; + EXPECT_EQ(GetIPCChannel()->LastSendError(), + SyncSendError::CancelledAfterSend) + << "SendNestedCancel should be cancelled"; + + return IPC_OK(); + } + + IPCResult RecvNestedCancelParent() final override { + GetIPCChannel()->CancelCurrentTransaction(); + return IPC_OK(); + } + + IPCResult RecvCheckParent(uint32_t* reply) final override { + *reply = 42; + return IPC_OK(); + } + + ~TestCancelParent() = default; +}; + +class TestCancelChild : public PTestCancelChild { + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TestCancelChild, override) + private: + IPCResult RecvImmediateCancel() final override { + GetIPCChannel()->CancelCurrentTransaction(); + + uint32_t value = 0; + EXPECT_FALSE(SendCheckParent(&value)) << "channel should be closing"; + + return IPC_OK(); + } + + IPCResult RecvStartNestedCancel() final override { + EXPECT_FALSE(SendCallNestedCancel()); + + Close(); + return IPC_OK(); + } + + IPCResult RecvNestedCancel() final override { + GetIPCChannel()->CancelCurrentTransaction(); + + uint32_t value = 0; + EXPECT_TRUE(SendCheckParent(&value)) << "channel should be closing"; + + return IPC_OK(); + } + + IPCResult RecvStartNestedCancelParent() final override { + EXPECT_FALSE(SendNestedCancelParent()) + << "SendNestedCancelParent should fail"; + EXPECT_EQ(GetIPCChannel()->LastSendError(), + SyncSendError::CancelledAfterSend) + << "SendNestedCancelParent should be cancelled"; + + uint32_t value = 0; + EXPECT_FALSE(SendCheckParent(&value)); + + return IPC_OK(); + } + + IPCResult RecvCheckChild(uint32_t* reply) final override { + *reply = 42; + return IPC_OK(); + } + + ~TestCancelChild() = default; +}; + +// Nested sync messages can only be received on the main thread, so threaded +// tests can't be run (the child actor won't be on the main thread). + +IPDL_TEST_ON(CROSSPROCESS, TestCancel, ImmediateCancel) { + EXPECT_FALSE(mActor->SendImmediateCancel()) << "should immediately cancel"; + EXPECT_EQ(mActor->GetIPCChannel()->LastSendError(), + SyncSendError::CancelledAfterSend); + + uint32_t value = 0; + EXPECT_TRUE(mActor->SendCheckChild(&value)); + EXPECT_EQ(value, (uint32_t)42); + + mActor->Close(); +} + +IPDL_TEST_ON(CROSSPROCESS, TestCancel, NestedCancel) { + EXPECT_TRUE(mActor->SendStartNestedCancel()); +} + +IPDL_TEST_ON(CROSSPROCESS, TestCancel, NestedCancelParent) { + EXPECT_FALSE(mActor->SendStartNestedCancelParent()) + << "StartNestedCancelParent should be cancelled"; + + uint32_t value = 0; + EXPECT_TRUE(mActor->SendCheckChild(&value)); + EXPECT_EQ(value, (uint32_t)42); + + mActor->Close(); +} + +} // namespace mozilla::_ipdltest diff --git a/ipc/ipdl/test/gtest/TestDataStructures.cpp b/ipc/ipdl/test/gtest/TestDataStructures.cpp new file mode 100644 index 0000000000..b7f6a7ae95 --- /dev/null +++ b/ipc/ipdl/test/gtest/TestDataStructures.cpp @@ -0,0 +1,864 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Test many combinations of data structures (both in argument and return + * position) to ensure they are transmitted correctly. + */ + +#include "gtest/gtest.h" + +#include "mozilla/_ipdltest/IPDLUnitTest.h" +#include "mozilla/_ipdltest/PTestDataStructuresChild.h" +#include "mozilla/_ipdltest/PTestDataStructuresParent.h" +#include "mozilla/_ipdltest/PTestDataStructuresSubChild.h" +#include "mozilla/_ipdltest/PTestDataStructuresSubParent.h" + +#include "mozilla/Unused.h" + +using namespace mozilla::ipc; + +using RegionArray = nsTArray; + +namespace mozilla::_ipdltest { + +static const uint32_t nactors = 10; + +class TestDataStructuresSubParent : public PTestDataStructuresSubParent { + NS_INLINE_DECL_REFCOUNTING(TestDataStructuresSubParent, override) + + public: + explicit TestDataStructuresSubParent(uint32_t i) : mI(i) {} + uint32_t mI; + + private: + ~TestDataStructuresSubParent() = default; +}; + +class TestDataStructuresSubChild : public PTestDataStructuresSubChild { + NS_INLINE_DECL_REFCOUNTING(TestDataStructuresSubChild, override) + + public: + explicit TestDataStructuresSubChild(uint32_t i) : mI(i) {} + uint32_t mI; + + private: + ~TestDataStructuresSubChild() = default; +}; + +inline static TestDataStructuresSubParent& Cast( + PTestDataStructuresSubParent* a) { + return *static_cast(a); +} + +class TestDataStructuresParent : public PTestDataStructuresParent { + NS_INLINE_DECL_REFCOUNTING(TestDataStructuresParent, override) + + public: + nsTArray>> + kids; + + private: + IPCResult RecvTestArrayOfInt(nsTArray&& ia, + nsTArray* oa) final override { + EXPECT_EQ(5u, ia.Length()); + for (int i = 0; i < 5; ++i) EXPECT_EQ(i, ia[i]); + + *oa = std::move(ia); + + return IPC_OK(); + } + + IPCResult RecvTestArrayOfActor( + nsTArray>&& i1, + nsTArray>* o1) final override { + EXPECT_EQ(nactors, i1.Length()); + for (uint32_t i = 0; i < i1.Length(); ++i) EXPECT_EQ(i, Cast(i1[i]).mI); + *o1 = std::move(i1); + return IPC_OK(); + } + + IPCResult RecvTestUnion(const IntDouble& i1, const IntDouble& i2, + IntDouble* o1, IntDouble* o2) final override { + EXPECT_EQ(42, i1.get_int()); + EXPECT_EQ(4.0, i2.get_double()); + + *o1 = i1; + *o2 = i2; + + return IPC_OK(); + } + + IPCResult RecvTestArrayOfUnion(nsTArray&& i1, + nsTArray* o1) final override { + EXPECT_EQ(4u, i1.Length()); + EXPECT_EQ(1, i1[0].get_int()); + EXPECT_EQ(2.0, i1[1].get_double()); + EXPECT_EQ(3, i1[2].get_int()); + EXPECT_EQ(4.0, i1[3].get_double()); + + *o1 = std::move(i1); + + return IPC_OK(); + } + + IPCResult RecvTestUnionWithArray(const IntDoubleArrays& i1, + const IntDoubleArrays& i2, + const IntDoubleArrays& i3, + IntDoubleArrays* o1, IntDoubleArrays* o2, + IntDoubleArrays* o3) final override { + EXPECT_EQ(42, i1.get_int()); + + const nsTArray& i2a = i2.get_ArrayOfint(); + EXPECT_EQ(3u, i2a.Length()); + EXPECT_EQ(1, i2a[0]); + EXPECT_EQ(2, i2a[1]); + EXPECT_EQ(3, i2a[2]); + + const nsTArray& i3a = i3.get_ArrayOfdouble(); + EXPECT_EQ(3u, i3a.Length()); + EXPECT_EQ(1.0, i3a[0]); + EXPECT_EQ(2.0, i3a[1]); + EXPECT_EQ(3.0, i3a[2]); + + *o1 = i1; + *o2 = i2a; + *o3 = i3a; + + return IPC_OK(); + } + + IPCResult RecvTestArrayOfUnionWithArray( + nsTArray&& i1, + nsTArray* o1) final override { + EXPECT_EQ(3u, i1.Length()); + + IntDoubleArrays id1(i1[0]); + EXPECT_EQ(42, id1.get_int()); + + nsTArray i2a = i1[1].get_ArrayOfint().Clone(); + EXPECT_EQ(3u, i2a.Length()); + EXPECT_EQ(1, i2a[0]); + EXPECT_EQ(2, i2a[1]); + EXPECT_EQ(3, i2a[2]); + + nsTArray i3a = i1[2].get_ArrayOfdouble().Clone(); + EXPECT_EQ(3u, i3a.Length()); + EXPECT_EQ(1.0, i3a[0]); + EXPECT_EQ(2.0, i3a[1]); + EXPECT_EQ(3.0, i3a[2]); + + o1->AppendElement(id1); + o1->AppendElement(IntDoubleArrays(i2a)); + o1->AppendElement(IntDoubleArrays(i3a)); + + return IPC_OK(); + } + + IPCResult RecvTestStructWithActor(const ActorWrapper& i1, + ActorWrapper* o1) final override { + EXPECT_FALSE(i1.actor().IsChild()) << "child side should be empty"; + + EXPECT_EQ(i1.actor(), kids[0]) + << "should have got back same actor on parent side"; + + o1->actor() = kids[0]; + return IPC_OK(); + } + + IPCResult RecvTestUnionWithActors(const Actors& i1, const Actors& i2, + const Actors& i3, Actors* o1, Actors* o2, + Actors* o3) final override { + EXPECT_EQ(42, i1.get_int()); + + nsTArray i2a = i2.get_ArrayOfint().Clone(); + EXPECT_EQ(3u, i2a.Length()); + EXPECT_EQ(1, i2a[0]); + EXPECT_EQ(2, i2a[1]); + EXPECT_EQ(3, i2a[2]); + + const auto& a = i3.get_ArrayOfPTestDataStructuresSub(); + EXPECT_EQ(a.Length(), kids.Length()); + for (size_t i = 0; i < a.Length(); ++i) { + EXPECT_EQ(a[i], kids[i]); + } + + *o1 = 42; + *o2 = i2a; + *o3 = kids.Clone(); + + return IPC_OK(); + } + + IPCResult RecvTestArrayOfUnionWithActors( + nsTArray&& i1, nsTArray* o1) final override { + EXPECT_EQ(3u, i1.Length()); + EXPECT_EQ(42, i1[0].get_int()); + + const nsTArray& i2a = i1[1].get_ArrayOfint(); + EXPECT_EQ(3u, i2a.Length()); + EXPECT_EQ(1, i2a[0]); + EXPECT_EQ(2, i2a[1]); + EXPECT_EQ(3, i2a[2]); + + EXPECT_EQ(kids, i1[2].get_ArrayOfPTestDataStructuresSub()); + + *o1 = std::move(i1); + + return IPC_OK(); + } + + IPCResult RecvTestUnions(const Unions& i1, const Unions& i2, const Unions& i3, + const Unions& i4, Unions* o1, Unions* o2, Unions* o3, + Unions* o4) final override { + EXPECT_EQ(42, i1.get_int()); + + const nsTArray& i2a = i2.get_ArrayOfint(); + EXPECT_EQ(3u, i2a.Length()); + EXPECT_EQ(1, i2a[0]); + EXPECT_EQ(2, i2a[1]); + EXPECT_EQ(3, i2a[2]); + + EXPECT_EQ(kids, i3.get_ArrayOfPTestDataStructuresSub()); + + const auto& i4a = + i4.get_ArrayOfActors()[0].get_ArrayOfPTestDataStructuresSub(); + EXPECT_EQ(kids, i4a); + + *o1 = i1; + *o2 = i2; + *o3 = i3; + *o4 = i4; + + return IPC_OK(); + } + + IPCResult RecvTestArrayOfUnions(nsTArray&& i1, + nsTArray* o1) final override { + EXPECT_EQ(42, i1[0].get_int()); + + const nsTArray& i2a = i1[1].get_ArrayOfint(); + EXPECT_EQ(3u, i2a.Length()); + EXPECT_EQ(1, i2a[0]); + EXPECT_EQ(2, i2a[1]); + EXPECT_EQ(3, i2a[2]); + + EXPECT_EQ(kids, i1[2].get_ArrayOfPTestDataStructuresSub()); + + const auto& i4a = + i1[3].get_ArrayOfActors()[0].get_ArrayOfPTestDataStructuresSub(); + EXPECT_EQ(kids, i4a); + + *o1 = std::move(i1); + + return IPC_OK(); + } + + IPCResult RecvTestStruct(const SIntDouble& i, SIntDouble* o) final override { + EXPECT_EQ(1, i.i()); + EXPECT_EQ(2.0, i.d()); + *o = i; + return IPC_OK(); + } + + IPCResult RecvTestStructWithArrays(const SIntDoubleArrays& i, + SIntDoubleArrays* o) final override { + nsTArray ai; + ai.AppendElement(1); + ai.AppendElement(2); + ai.AppendElement(3); + + nsTArray ad; + ad.AppendElement(.5); + ad.AppendElement(1.0); + ad.AppendElement(2.0); + + EXPECT_EQ(42, i.i()); + EXPECT_EQ(ai, i.ai()); + EXPECT_EQ(ad, i.ad()); + + *o = i; + + return IPC_OK(); + } + + IPCResult RecvTestStructWithActors(const SActors& i, + SActors* o) final override { + nsTArray ai; + ai.AppendElement(1); + ai.AppendElement(2); + ai.AppendElement(3); + + EXPECT_EQ(42, i.i()); + EXPECT_EQ(ai, i.ai()); + EXPECT_EQ(kids, i.ap()); + + *o = i; + + return IPC_OK(); + } + + IPCResult RecvTestStructs(const Structs& i, Structs* o) final override { + nsTArray ai; + ai.AppendElement(1); + ai.AppendElement(2); + ai.AppendElement(3); + + EXPECT_EQ(42, i.i()); + EXPECT_EQ(ai, i.ai()); + EXPECT_EQ(kids, i.ap()); + + const SActors& ia = i.aa()[0]; + EXPECT_EQ(42, ia.i()); + EXPECT_EQ(ai, ia.ai()); + EXPECT_EQ(kids, ia.ap()); + + *o = i; + + return IPC_OK(); + } + + IPCResult RecvTestUnionWithStructs( + const WithStructs& i1, const WithStructs& i2, const WithStructs& i3, + const WithStructs& i4, const WithStructs& i5, WithStructs* o1, + WithStructs* o2, WithStructs* o3, WithStructs* o4, + WithStructs* o5) final override { + nsTArray ai; + ai.AppendElement(1); + ai.AppendElement(2); + ai.AppendElement(3); + + EXPECT_EQ(i1, int(42)); + EXPECT_EQ(i2.get_ArrayOfint(), ai); + EXPECT_EQ(i3.get_ArrayOfPTestDataStructuresSub(), kids); + + const SActors& ia = i4.get_ArrayOfSActors()[0]; + EXPECT_EQ(42, ia.i()); + EXPECT_EQ(ai, ia.ai()); + EXPECT_EQ(kids, ia.ap()); + + const Structs& is = i5.get_ArrayOfStructs()[0]; + EXPECT_EQ(42, is.i()); + EXPECT_EQ(ai, is.ai()); + EXPECT_EQ(kids, is.ap()); + + const SActors& isa = is.aa()[0]; + EXPECT_EQ(42, isa.i()); + EXPECT_EQ(ai, isa.ai()); + EXPECT_EQ(kids, isa.ap()); + + *o1 = i1; + *o2 = i2; + *o3 = i3; + *o4 = i4; + *o5 = i5; + + return IPC_OK(); + } + + IPCResult RecvTestStructWithUnions(const WithUnions& i, + WithUnions* o) final override { + EXPECT_EQ(i.i(), 42); + + nsTArray ai; + ai.AppendElement(1); + ai.AppendElement(2); + ai.AppendElement(3); + EXPECT_EQ(ai, i.ai()); + + EXPECT_EQ(i.ap(), kids); + + EXPECT_EQ(kids, i.aa()[0].get_ArrayOfPTestDataStructuresSub()); + + const nsTArray& iau = i.au(); + EXPECT_EQ(iau[0], 42); + EXPECT_EQ(ai, iau[1].get_ArrayOfint()); + EXPECT_EQ(kids, iau[2].get_ArrayOfPTestDataStructuresSub()); + EXPECT_EQ( + kids, + iau[3].get_ArrayOfActors()[0].get_ArrayOfPTestDataStructuresSub()); + + *o = i; + + return IPC_OK(); + } + + IPCResult RecvTestUnionWithCxx(nsTArray&& sa) final override { + EXPECT_EQ(sa.Length(), (size_t)1); + EXPECT_EQ(Op::TSetAttrs, sa[0].type()); + return IPC_OK(); + } + + IPCResult RecvTestNsIntRegion(RegionArray&& ra) final override { + for (RegionArray::index_type i = 0; i < ra.Length(); ++i) { + // if |ra| has been realloc()d and given a different allocator + // chunk, this loop will nondeterministically crash or iloop. + for (auto iter = ra[i].RectIter(); !iter.Done(); iter.Next()) { + Unused << iter.Get(); + } + } + return IPC_OK(); + } + + ~TestDataStructuresParent() = default; +}; + +class TestDataStructuresChild : public PTestDataStructuresChild { + NS_INLINE_DECL_REFCOUNTING(TestDataStructuresChild, override) + + private: + nsTArray>> + kids; + nsTArray> kidsDirect; + + already_AddRefed + AllocPTestDataStructuresSubChild(const int& i) final override { + auto child = MakeRefPtr(i); + kids.AppendElement(WrapNotNull(child)); + kidsDirect.AppendElement(WrapNotNull(child)); + return child.forget(); + } + + IPCResult RecvStart() final override { + TestArrayOfInt(); + TestArrayOfActor(); + TestUnion(); + TestArrayOfUnion(); + TestUnionWithArray(); + TestArrayOfUnionWithArray(); + TestStructWithActor(); + TestUnionWithActors(); + TestArrayOfUnionWithActors(); + TestUnions(); + TestArrayOfUnions(); + TestStruct(); + TestStructWithArrays(); + TestStructWithActors(); + TestStructs(); + TestUnionWithStructs(); + TestStructWithUnions(); + TestUnionWithCxx(); + TestNsIntRegion(); + + auto actors = kidsDirect.Clone(); + for (auto& actor : actors) { + EXPECT_TRUE(PTestDataStructuresSubChild::Send__delete__(actor)); + } + + Close(); + + return IPC_OK(); + } + + void TestArrayOfInt() { + nsTArray ia; + + for (int i = 0; i < 5; ++i) ia.AppendElement(i); + + nsTArray oa; + EXPECT_TRUE(SendTestArrayOfInt(ia, &oa)); + + EXPECT_EQ(ia, oa); + } + + void TestArrayOfActor() { + nsTArray> oa; + EXPECT_TRUE(SendTestArrayOfActor(kidsDirect, &oa)); + EXPECT_EQ(kidsDirect, oa); + } + + void TestUnion() { + int i1i = 42; + double i2d = 4.0; + IntDouble i1(i1i); + IntDouble i2(i2d); + IntDouble o1, o2; + + SendTestUnion(i1, i2, &o1, &o2); + + EXPECT_EQ(i1i, o1.get_int()); + EXPECT_EQ(i2d, o2.get_double()); + } + + void TestArrayOfUnion() { + nsTArray i1; + i1.AppendElement(IntDouble(int(1))); + i1.AppendElement(IntDouble(2.0)); + i1.AppendElement(IntDouble(int(3))); + i1.AppendElement(IntDouble(4.0)); + + nsTArray o1; + EXPECT_TRUE(SendTestArrayOfUnion(i1, &o1)); + + // TODO Union::operator==() + EXPECT_EQ(i1.Length(), o1.Length()); + EXPECT_EQ(1, o1[0].get_int()); + EXPECT_EQ(2.0, o1[1].get_double()); + EXPECT_EQ(3, o1[2].get_int()); + EXPECT_EQ(4.0, o1[3].get_double()); + } + + void TestUnionWithArray() { + IntDoubleArrays i1(int(42)); + nsTArray i2; + i2.AppendElement(1); + i2.AppendElement(2); + i2.AppendElement(3); + nsTArray i3; + i3.AppendElement(1.0); + i3.AppendElement(2.0); + i3.AppendElement(3.0); + + IntDoubleArrays o1, o2, o3; + EXPECT_TRUE(SendTestUnionWithArray(i1, IntDoubleArrays(i2), + IntDoubleArrays(i3), &o1, &o2, &o3)); + + EXPECT_EQ(42, o1.get_int()); + EXPECT_EQ(i2, o2.get_ArrayOfint()); + EXPECT_EQ(i3, o3.get_ArrayOfdouble()); + } + + void TestArrayOfUnionWithArray() { + IntDoubleArrays id1(int(42)); + nsTArray id2; + id2.AppendElement(1); + id2.AppendElement(2); + id2.AppendElement(3); + nsTArray id3; + id3.AppendElement(1.0); + id3.AppendElement(2.0); + id3.AppendElement(3.0); + + nsTArray i1; + i1.AppendElement(id1); + i1.AppendElement(IntDoubleArrays(id2)); + i1.AppendElement(IntDoubleArrays(id3)); + + nsTArray o1; + EXPECT_TRUE(SendTestArrayOfUnionWithArray(i1, &o1)); + + EXPECT_EQ(3u, o1.Length()); + IntDoubleArrays od1(o1[0]); + nsTArray od2 = o1[1].get_ArrayOfint().Clone(); + nsTArray od3 = o1[2].get_ArrayOfdouble().Clone(); + + EXPECT_EQ(42, od1.get_int()); + EXPECT_EQ(id2, od2); + EXPECT_EQ(id3, od3); + } + + void TestStructWithActor() { + ActorWrapper iaw(kidsDirect[0]); + + ActorWrapper oaw; + EXPECT_TRUE(SendTestStructWithActor(iaw, &oaw)); + + EXPECT_TRUE(oaw.actor().IsChild()); + EXPECT_EQ(oaw.actor().AsChild(), kidsDirect[0]); + } + + void TestUnionWithActors() { + Actors i1(42); + nsTArray i2a; + i2a.AppendElement(1); + i2a.AppendElement(2); + i2a.AppendElement(3); + + Actors o1, o2, o3; + EXPECT_TRUE( + SendTestUnionWithActors(i1, Actors(i2a), Actors(kids), &o1, &o2, &o3)); + + EXPECT_EQ(42, o1.get_int()); + EXPECT_EQ(i2a, o2.get_ArrayOfint()); + EXPECT_EQ(kids, o3.get_ArrayOfPTestDataStructuresSub()); + } + + void TestArrayOfUnionWithActors() { + Actors i1e(42); + nsTArray i2a; + i2a.AppendElement(1); + i2a.AppendElement(2); + i2a.AppendElement(3); + + nsTArray i1; + i1.AppendElement(i1e); + i1.AppendElement(i2a); + i1.AppendElement(kids); + + nsTArray o1; + EXPECT_TRUE(SendTestArrayOfUnionWithActors(i1, &o1)); + + EXPECT_EQ(3u, o1.Length()); + EXPECT_EQ(42, o1[0].get_int()); + EXPECT_EQ(i2a, o1[1].get_ArrayOfint()); + EXPECT_EQ(kids, o1[2].get_ArrayOfPTestDataStructuresSub()); + } + + void TestUnions() { + Unions i1(int(42)); + + nsTArray i2a; + i2a.AppendElement(1); + i2a.AppendElement(2); + i2a.AppendElement(3); + + nsTArray i4a; + i4a.AppendElement(kids); + + Unions o1, o2, o3, o4; + EXPECT_TRUE(SendTestUnions(i1, Unions(i2a), Unions(kids), Unions(i4a), &o1, + &o2, &o3, &o4)); + + EXPECT_EQ(42, o1.get_int()); + EXPECT_EQ(i2a, o2.get_ArrayOfint()); + EXPECT_EQ(kids, o3.get_ArrayOfPTestDataStructuresSub()); + EXPECT_EQ(kids, + o4.get_ArrayOfActors()[0].get_ArrayOfPTestDataStructuresSub()); + } + + void TestArrayOfUnions() { + Unions i1a(int(42)); + + nsTArray i2a; + i2a.AppendElement(1); + i2a.AppendElement(2); + i2a.AppendElement(3); + + nsTArray i4a; + i4a.AppendElement(kids); + + nsTArray i1; + i1.AppendElement(i1a); + i1.AppendElement(Unions(i2a)); + i1.AppendElement(Unions(kids)); + i1.AppendElement(Unions(i4a)); + + nsTArray o1; + EXPECT_TRUE(SendTestArrayOfUnions(i1, &o1)); + + EXPECT_EQ(4u, o1.Length()); + EXPECT_EQ(42, o1[0].get_int()); + EXPECT_EQ(i2a, o1[1].get_ArrayOfint()); + EXPECT_EQ(kids, o1[2].get_ArrayOfPTestDataStructuresSub()); + EXPECT_EQ(kids, + o1[3].get_ArrayOfActors()[0].get_ArrayOfPTestDataStructuresSub()); + } + + void TestStruct() { + SIntDouble i(1, 2.0); + SIntDouble o; + + EXPECT_TRUE(SendTestStruct(i, &o)); + + EXPECT_EQ(o.i(), 1); + EXPECT_EQ(o.d(), 2.0); + } + + void TestStructWithArrays() { + nsTArray ai; + ai.AppendElement(1); + ai.AppendElement(2); + ai.AppendElement(3); + + nsTArray ad; + ad.AppendElement(.5); + ad.AppendElement(1.0); + ad.AppendElement(2.0); + + SIntDoubleArrays i(42, ai, ad); + SIntDoubleArrays o; + + EXPECT_TRUE(SendTestStructWithArrays(i, &o)); + + EXPECT_EQ(42, o.i()); + EXPECT_EQ(ai, o.ai()); + EXPECT_EQ(ad, o.ad()); + } + + void TestStructWithActors() { + nsTArray ai; + ai.AppendElement(1); + ai.AppendElement(2); + ai.AppendElement(3); + + SActors i; + i.i() = 42; + i.ai() = ai.Clone(); + i.ap() = kids.Clone(); + + SActors o; + EXPECT_TRUE(SendTestStructWithActors(i, &o)); + + EXPECT_EQ(42, o.i()); + EXPECT_EQ(ai, o.ai()); + EXPECT_EQ(kids, o.ap()); + } + + void TestStructs() { + nsTArray ai; + ai.AppendElement(1); + ai.AppendElement(2); + ai.AppendElement(3); + + SActors ia; + ia.i() = 42; + ia.ai() = ai.Clone(); + ia.ap() = kids.Clone(); + nsTArray aa; + aa.AppendElement(ia); + + Structs i; + i.i() = 42; + i.ai() = ai.Clone(); + i.ap() = kids.Clone(); + i.aa() = aa.Clone(); + + Structs o; + EXPECT_TRUE(SendTestStructs(i, &o)); + + EXPECT_EQ(42, o.i()); + EXPECT_EQ(ai, o.ai()); + EXPECT_EQ(kids, o.ap()); + + const SActors& os = o.aa()[0]; + EXPECT_EQ(42, os.i()); + EXPECT_EQ(ai, os.ai()); + EXPECT_EQ(kids, os.ap()); + } + + void TestUnionWithStructs() { + nsTArray ai; + ai.AppendElement(1); + ai.AppendElement(2); + ai.AppendElement(3); + + SActors ia; + ia.i() = 42; + ia.ai() = ai.Clone(); + ia.ap() = kids.Clone(); + nsTArray iaa; + iaa.AppendElement(ia); + + Structs is; + is.i() = 42; + is.ai() = ai.Clone(); + is.ap() = kids.Clone(); + is.aa() = iaa.Clone(); + nsTArray isa; + isa.AppendElement(is); + + WithStructs o1, o2, o3, o4, o5; + EXPECT_TRUE(SendTestUnionWithStructs( + WithStructs(42), WithStructs(ai), WithStructs(kids), WithStructs(iaa), + WithStructs(isa), &o1, &o2, &o3, &o4, &o5)); + + EXPECT_EQ(o1, int(42)); + EXPECT_EQ(o2.get_ArrayOfint(), ai); + EXPECT_EQ(o3.get_ArrayOfPTestDataStructuresSub(), kids); + + const SActors& oa = o4.get_ArrayOfSActors()[0]; + EXPECT_EQ(42, oa.i()); + EXPECT_EQ(ai, oa.ai()); + EXPECT_EQ(kids, oa.ap()); + + const Structs& os = o5.get_ArrayOfStructs()[0]; + EXPECT_EQ(42, os.i()); + EXPECT_EQ(ai, os.ai()); + EXPECT_EQ(kids, os.ap()); + + const SActors& osa = os.aa()[0]; + EXPECT_EQ(42, osa.i()); + EXPECT_EQ(ai, osa.ai()); + EXPECT_EQ(kids, osa.ap()); + } + + void TestStructWithUnions() { + WithUnions i; + + i.i() = 42; + + nsTArray ai; + ai.AppendElement(1); + ai.AppendElement(2); + ai.AppendElement(3); + i.ai() = ai.Clone(); + + i.ap() = kids.Clone(); + + nsTArray iaa; + iaa.AppendElement(kids); + i.aa() = iaa.Clone(); + + nsTArray iau; + iau.AppendElement(int(42)); + iau.AppendElement(ai); + iau.AppendElement(kids); + iau.AppendElement(iaa); + i.au() = iau.Clone(); + + WithUnions o; + EXPECT_TRUE(SendTestStructWithUnions(i, &o)); + + EXPECT_EQ(42, o.i()); + EXPECT_EQ(o.ai(), ai); + EXPECT_EQ(o.ap(), kids); + + const Actors& oaa = o.aa()[0]; + EXPECT_EQ(oaa.get_ArrayOfPTestDataStructuresSub(), kids); + + const nsTArray& oau = o.au(); + EXPECT_EQ(oau[0], 42); + EXPECT_EQ(oau[1].get_ArrayOfint(), ai); + EXPECT_EQ(oau[2].get_ArrayOfPTestDataStructuresSub(), kids); + EXPECT_EQ(oau[3].get_ArrayOfActors()[0].get_ArrayOfPTestDataStructuresSub(), + kids); + } + + void TestUnionWithCxx() { + Attrs attrs; + attrs.common() = CommonAttrs(true); + attrs.specific() = BarAttrs(1.0f); + + nsTArray ops; + ops.AppendElement(SetAttrs(kids[0], attrs)); + + EXPECT_TRUE(SendTestUnionWithCxx(ops)); + } + + void TestNsIntRegion() { + const int nelements = 1000; + RegionArray ra; + // big enough to hopefully force a realloc to a different chunk of + // memory on the receiving side, if the workaround isn't working + // correctly. But SetCapacity() here because we don't want to + // crash on the sending side. + ra.SetCapacity(nelements); + for (int i = 0; i < nelements; ++i) { + nsIntRegion r; + r.Or(nsIntRect(0, 0, 10, 10), nsIntRect(10, 10, 10, 10)); + ra.AppendElement(r); + } + + EXPECT_TRUE(SendTestNsIntRegion(ra)); + } + + ~TestDataStructuresChild() = default; +}; + +IPDL_TEST(TestDataStructures) { + for (uint32_t i = 0; i < nactors; ++i) { + auto sub = MakeRefPtr(i); + EXPECT_TRUE(mActor->SendPTestDataStructuresSubConstructor(sub, i)) + << "can't alloc actor"; + mActor->kids.AppendElement(WrapNotNull(sub)); + } + + EXPECT_TRUE(mActor->SendStart()) << "can't send Start()"; +} + +} // namespace mozilla::_ipdltest diff --git a/ipc/ipdl/test/gtest/TestDescendant.cpp b/ipc/ipdl/test/gtest/TestDescendant.cpp new file mode 100644 index 0000000000..47f619d32a --- /dev/null +++ b/ipc/ipdl/test/gtest/TestDescendant.cpp @@ -0,0 +1,98 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Test multiple levels of descendant managed protocols. + */ + +#include "gtest/gtest.h" + +#include "mozilla/_ipdltest/IPDLUnitTest.h" +#include "mozilla/_ipdltest/PTestDescendantChild.h" +#include "mozilla/_ipdltest/PTestDescendantParent.h" +#include "mozilla/_ipdltest/PTestDescendantSubChild.h" +#include "mozilla/_ipdltest/PTestDescendantSubParent.h" +#include "mozilla/_ipdltest/PTestDescendantSubsubChild.h" +#include "mozilla/_ipdltest/PTestDescendantSubsubParent.h" + +using namespace mozilla::ipc; + +namespace mozilla::_ipdltest { + +class TestDescendantSubsubParent : public PTestDescendantSubsubParent { + NS_INLINE_DECL_REFCOUNTING(TestDescendantSubsubParent, override) + private: + ~TestDescendantSubsubParent() = default; +}; + +class TestDescendantSubsubChild : public PTestDescendantSubsubChild { + NS_INLINE_DECL_REFCOUNTING(TestDescendantSubsubChild, override) + private: + ~TestDescendantSubsubChild() = default; +}; + +class TestDescendantSubParent : public PTestDescendantSubParent { + NS_INLINE_DECL_REFCOUNTING(TestDescendantSubParent, override) + private: + ~TestDescendantSubParent() = default; +}; + +class TestDescendantSubChild : public PTestDescendantSubChild { + NS_INLINE_DECL_REFCOUNTING(TestDescendantSubChild, override) + private: + already_AddRefed AllocPTestDescendantSubsubChild() + final override { + return MakeAndAddRef(); + } + + ~TestDescendantSubChild() = default; +}; + +class TestDescendantParent : public PTestDescendantParent { + NS_INLINE_DECL_REFCOUNTING(TestDescendantParent, override) + private: + IPCResult RecvOk(NotNull a) final override { + EXPECT_TRUE(PTestDescendantSubsubParent::Send__delete__(a)) + << "deleting Subsub"; + + Close(); + + return IPC_OK(); + } + + ~TestDescendantParent() = default; +}; + +class TestDescendantChild : public PTestDescendantChild { + NS_INLINE_DECL_REFCOUNTING(TestDescendantChild, override) + private: + already_AddRefed AllocPTestDescendantSubChild( + PTestDescendantSubsubChild* dummy) final override { + EXPECT_FALSE(dummy) << "actor supposed to be null"; + return MakeAndAddRef(); + } + + IPCResult RecvTest(NotNull a) final override { + EXPECT_TRUE(SendOk(a)) << "couldn't send Ok()"; + return IPC_OK(); + } + + ~TestDescendantChild() = default; +}; + +IPDL_TEST(TestDescendant) { + auto p = MakeRefPtr(); + auto* rv1 = mActor->SendPTestDescendantSubConstructor(p, nullptr); + EXPECT_EQ(p, rv1) << "can't allocate Sub"; + + auto pp = MakeRefPtr(); + auto* rv2 = p->SendPTestDescendantSubsubConstructor(pp); + EXPECT_EQ(pp, rv2) << "can't allocate Subsub"; + + EXPECT_TRUE(mActor->SendTest(WrapNotNull(pp))) << "can't send Subsub"; +} + +} // namespace mozilla::_ipdltest diff --git a/ipc/ipdl/test/gtest/TestEndpointOpens.cpp b/ipc/ipdl/test/gtest/TestEndpointOpens.cpp new file mode 100644 index 0000000000..50dab06058 --- /dev/null +++ b/ipc/ipdl/test/gtest/TestEndpointOpens.cpp @@ -0,0 +1,159 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Test Endpoint usage. + */ + +#include "gtest/gtest.h" + +#include "mozilla/_ipdltest/IPDLUnitTest.h" +#include "mozilla/_ipdltest/PTestEndpointOpensChild.h" +#include "mozilla/_ipdltest/PTestEndpointOpensParent.h" +#include "mozilla/_ipdltest/PTestEndpointOpensOpenedChild.h" +#include "mozilla/_ipdltest/PTestEndpointOpensOpenedParent.h" + +#include + +using namespace mozilla::ipc; + +namespace mozilla::_ipdltest { + +class TestEndpointOpensOpenedParent : public PTestEndpointOpensOpenedParent { + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TestEndpointOpensOpenedParent, override) + private: + IPCResult RecvHello() final override { + EXPECT_FALSE(NS_IsMainThread()); + if (!SendHi()) { + return IPC_TEST_FAIL(this); + } + return IPC_OK(); + } + + IPCResult RecvHelloSync() final override { + EXPECT_FALSE(NS_IsMainThread()); + return IPC_OK(); + } + + void ActorDestroy(ActorDestroyReason why) final override { + EXPECT_FALSE(NS_IsMainThread()); + } + + ~TestEndpointOpensOpenedParent() = default; +}; + +class TestEndpointOpensChild : public PTestEndpointOpensChild { + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TestEndpointOpensChild, override) + private: + IPCResult RecvStart() final override; + + ~TestEndpointOpensChild() = default; +}; + +class TestEndpointOpensOpenedChild : public PTestEndpointOpensOpenedChild { + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TestEndpointOpensOpenedChild, override) + + explicit TestEndpointOpensOpenedChild(TestEndpointOpensChild* opensChild) + : mOpensChild(opensChild) {} + + private: + IPCResult RecvHi() final override { + EXPECT_FALSE(NS_IsMainThread()); + + EXPECT_TRUE(SendHelloSync()); + + Close(); + return IPC_OK(); + } + + void ActorDestroy(ActorDestroyReason why) final override { + EXPECT_FALSE(NS_IsMainThread()); + + // Kick off main-thread shutdown. + NS_DispatchToMainThread(NewRunnableMethod("ipc::IToplevelProtocol::Close", + mOpensChild, + &TestEndpointOpensChild::Close)); + } + + ~TestEndpointOpensOpenedChild() = default; + + TestEndpointOpensChild* mOpensChild; +}; + +class TestEndpointOpensParent : public PTestEndpointOpensParent { + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TestEndpointOpensParent, override) + private: + IPCResult RecvStartSubprotocol( + Endpoint&& endpoint) final override { + nsCOMPtr eventTarget; + auto rv = NS_CreateBackgroundTaskQueue("ParentThread", + getter_AddRefs(eventTarget)); + if (NS_FAILED(rv)) { + ADD_FAILURE() << "creating background task queue for child"; + return IPC_TEST_FAIL(this); + } + + eventTarget->Dispatch(NS_NewRunnableFunction( + "OpenParent", [endpoint{std::move(endpoint)}]() mutable { + EXPECT_FALSE(NS_IsMainThread()); + + // Open the actor on the off-main thread to park it there. + // Messages will be delivered to this thread's message loop + // instead of the main thread's. + auto actor = MakeRefPtr(); + ASSERT_TRUE(endpoint.Bind(actor)); + })); + + return IPC_OK(); + } + + ~TestEndpointOpensParent() = default; +}; + +IPCResult TestEndpointOpensChild::RecvStart() { + Endpoint parent; + Endpoint child; + nsresult rv; + rv = PTestEndpointOpensOpened::CreateEndpoints( + OtherPidMaybeInvalid(), base::GetCurrentProcId(), &parent, &child); + if (NS_FAILED(rv)) { + ADD_FAILURE() << "opening PTestEndpointOpensOpened"; + return IPC_TEST_FAIL(this); + } + + nsCOMPtr childEventTarget; + rv = NS_CreateBackgroundTaskQueue("ChildThread", + getter_AddRefs(childEventTarget)); + if (NS_FAILED(rv)) { + ADD_FAILURE() << "creating background task queue for child"; + return IPC_TEST_FAIL(this); + } + + auto actor = MakeRefPtr(this); + childEventTarget->Dispatch(NS_NewRunnableFunction( + "OpenChild", + [actor{std::move(actor)}, endpoint{std::move(child)}]() mutable { + EXPECT_FALSE(NS_IsMainThread()); + + // Open the actor on the off-main thread to park it there. + // Messages will be delivered to this thread's message loop + // instead of the main thread's. + ASSERT_TRUE(endpoint.Bind(actor)); + + // Kick off the unit tests + ASSERT_TRUE(actor->SendHello()); + })); + + EXPECT_TRUE(SendStartSubprotocol(std::move(parent))); + + return IPC_OK(); +} + +IPDL_TEST_ON(CROSSPROCESS, TestEndpointOpens) { + EXPECT_TRUE(mActor->SendStart()); +} + +} // namespace mozilla::_ipdltest diff --git a/ipc/ipdl/test/gtest/TestHangs.cpp b/ipc/ipdl/test/gtest/TestHangs.cpp new file mode 100644 index 0000000000..ddc4a0c7d0 --- /dev/null +++ b/ipc/ipdl/test/gtest/TestHangs.cpp @@ -0,0 +1,133 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Test various cases of behavior when a synchronous method call times out. + */ + +#include "gtest/gtest.h" + +#include "mozilla/_ipdltest/IPDLUnitTest.h" +#include "mozilla/_ipdltest/PTestHangsChild.h" +#include "mozilla/_ipdltest/PTestHangsParent.h" +#include "mozilla/ipc/CrossProcessSemaphore.h" + +using namespace mozilla::ipc; + +namespace mozilla::_ipdltest { + +enum class HangMode : uint32_t { + /// No hang should occur. + None, + /// The synchronous call should time out. + Hang, + /// The synchronous call should time out but the response should still be + /// received + /// (racing with the reply timeout logic). + HangButReceive, + /// The synchronous call should time out but the response should still be + /// received because the child indicates that processing should continue after + /// timeout. + HangPermitted +}; + +class TestHangsChild : public PTestHangsChild { + NS_INLINE_DECL_REFCOUNTING(TestHangsChild, override) + + TestHangsChild() : timeout(CrossProcessSemaphore::Create("timeout", 0)) {} + + private: + IPCResult RecvStart(const uint32_t& hangMode, + StartResolver&& resolve) final override { + // Minimum possible, 2 ms. We want to detect a hang to race with the reply + // coming in, as reliably as possible. After 1ms the wait for a response + // will be retried. + SetReplyTimeoutMs(2); + + this->hangMode = (HangMode)hangMode; + + auto result = SendHang(hangMode, timeout->CloneHandle()); + if (this->hangMode == HangMode::Hang) { + // Only the `Hang` mode should actually fail. + EXPECT_FALSE(result); + } else { + EXPECT_TRUE(result); + } + + resolve(detectedHang); + + return IPC_OK(); + } + + bool ShouldContinueFromReplyTimeout() final override { + timeout->Signal(); + detectedHang = true; + + if (hangMode == HangMode::HangButReceive) { + // Wait until the transaction is complete so that we can still receive the + // result after returning. + while (!GetIPCChannel()->TestOnlyIsTransactionComplete()) { + PR_Sleep(ticksPerSecond / 1000); + } + } + + // Return true if `HangPermitted` mode (allowing the receive loop to + // continue). + return hangMode == HangMode::HangPermitted; + } + + ~TestHangsChild() = default; + + HangMode hangMode = HangMode::None; + uint32_t ticksPerSecond = PR_TicksPerSecond(); + UniquePtr timeout; + + public: + bool detectedHang = false; +}; + +class TestHangsParent : public PTestHangsParent { + NS_INLINE_DECL_REFCOUNTING(TestHangsParent, override) + + private: + IPCResult RecvHang( + const uint32_t& hangMode, + CrossProcessSemaphoreHandle&& timeout_handle) final override { + UniquePtr timeout( + CrossProcessSemaphore::Create(std::move(timeout_handle))); + if (hangMode != (uint32_t)HangMode::None) { + // Wait to ensure the child process has called + // ShouldContinueFromReplyTimeout(). + timeout->Wait(); + } + return IPC_OK(); + } + + ~TestHangsParent() = default; +}; + +// We can verify that the Start message callbacks are run with the `Close()` +// calls; without a `Close()`, the test will hang. + +#define TEST_HANGS(mode) \ + IPDL_TEST(TestHangs, mode) { \ + mActor->SendStart( \ + (uint32_t)HangMode::mode, \ + [=](bool detectedHang) { \ + EXPECT_EQ(detectedHang, HangMode::mode != HangMode::None); \ + mActor->Close(); \ + }, \ + [](auto&& reason) { FAIL() << "failed to send start"; }); \ + } + +TEST_HANGS(None) +TEST_HANGS(Hang) +TEST_HANGS(HangButReceive) +TEST_HANGS(HangPermitted) + +#undef TEST_HANGS + +} // namespace mozilla::_ipdltest diff --git a/ipc/ipdl/test/gtest/TestJSON.cpp b/ipc/ipdl/test/gtest/TestJSON.cpp new file mode 100644 index 0000000000..a3f881abda --- /dev/null +++ b/ipc/ipdl/test/gtest/TestJSON.cpp @@ -0,0 +1,157 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Test sending JSON(-like) objects over IPC. + */ + +#include "gtest/gtest.h" + +#include "mozilla/_ipdltest/IPDLUnitTest.h" +#include "mozilla/_ipdltest/PTestJSONChild.h" +#include "mozilla/_ipdltest/PTestJSONParent.h" +#include "mozilla/_ipdltest/PTestJSONHandleChild.h" +#include "mozilla/_ipdltest/PTestJSONHandleParent.h" + +using namespace mozilla::ipc; + +namespace mozilla::_ipdltest { + +static nsString String(const char* const str) { + return NS_ConvertUTF8toUTF16(str); +} + +static void Array123(nsTArray& a123) { + a123.AppendElement(1); + a123.AppendElement(2); + a123.AppendElement(3); + + ASSERT_EQ(a123, a123) << "operator== is broken"; +} + +template +JSONVariant MakeTestVariant(HandleT* handle) { + // In JS syntax: + // + // return [ + // undefined, null, true, 1.25, "test string", + // handle, + // [ 1, 2, 3 ], + // { "undefined" : undefined, + // "null" : null, + // "true" : true, + // "1.25" : 1.25, + // "string" : "string" + // "handle" : handle, + // "array" : [ 1, 2, 3 ] + // } + // ] + // + nsTArray outer; + + outer.AppendElement(void_t()); + outer.AppendElement(null_t()); + outer.AppendElement(true); + outer.AppendElement(1.25); + outer.AppendElement(String("test string")); + + outer.AppendElement(handle); + + nsTArray tmp; + Array123(tmp); + outer.AppendElement(tmp); + + nsTArray obj; + obj.AppendElement(KeyValue(String("undefined"), void_t())); + obj.AppendElement(KeyValue(String("null"), null_t())); + obj.AppendElement(KeyValue(String("true"), true)); + obj.AppendElement(KeyValue(String("1.25"), 1.25)); + obj.AppendElement(KeyValue(String("string"), String("value"))); + obj.AppendElement(KeyValue(String("handle"), handle)); + nsTArray tmp2; + Array123(tmp2); + obj.AppendElement(KeyValue(String("array"), tmp2)); + + outer.AppendElement(obj); + + EXPECT_EQ(outer, outer) << "operator== is broken"; + + return JSONVariant(outer); +} + +//----------------------------------------------------------------------------- +// parent + +class TestJSONHandleParent : public PTestJSONHandleParent { + NS_INLINE_DECL_REFCOUNTING(TestJSONHandleParent, override) + private: + ~TestJSONHandleParent() = default; +}; + +class TestJSONHandleChild : public PTestJSONHandleChild { + NS_INLINE_DECL_REFCOUNTING(TestJSONHandleChild, override) + private: + ~TestJSONHandleChild() = default; +}; + +class TestJSONParent : public PTestJSONParent { + NS_INLINE_DECL_REFCOUNTING(TestJSONParent, override) + private: + IPCResult RecvTest(const JSONVariant& i, JSONVariant* o) final override { + EXPECT_EQ(i, MakeTestVariant(mKid.get())) << "inparam mangled en route"; + + *o = i; + + EXPECT_EQ(i, *o) << "operator== and/or copy assignment are broken"; + + return IPC_OK(); + } + + already_AddRefed AllocPTestJSONHandleParent() + final override { + auto handle = MakeRefPtr(); + EXPECT_FALSE(mKid); + mKid = handle; + return handle.forget(); + } + + ~TestJSONParent() = default; + + RefPtr mKid; +}; + +//----------------------------------------------------------------------------- +// child + +class TestJSONChild : public PTestJSONChild { + NS_INLINE_DECL_REFCOUNTING(TestJSONChild, override) + private: + IPCResult RecvStart() final override { + mKid = MakeRefPtr(); + EXPECT_TRUE(SendPTestJSONHandleConstructor(mKid)) << "sending Handle ctor"; + + JSONVariant i(MakeTestVariant(mKid.get())); + EXPECT_EQ(i, i) << "operator== is broken"; + EXPECT_EQ(i, MakeTestVariant(mKid.get())) << "copy ctor is broken"; + + JSONVariant o; + EXPECT_TRUE(SendTest(i, &o)) << "sending Test"; + + EXPECT_EQ(i, o) << "round-trip mangled input data"; + EXPECT_EQ(o, MakeTestVariant(mKid.get())) << "outparam mangled en route"; + + Close(); + return IPC_OK(); + } + + ~TestJSONChild() = default; + + RefPtr mKid; +}; + +IPDL_TEST(TestJSON) { EXPECT_TRUE(mActor->SendStart()) << "sending Start"; } + +} // namespace mozilla::_ipdltest diff --git a/ipc/ipdl/test/gtest/TestManyChildAllocs.cpp b/ipc/ipdl/test/gtest/TestManyChildAllocs.cpp new file mode 100644 index 0000000000..2111f4f49f --- /dev/null +++ b/ipc/ipdl/test/gtest/TestManyChildAllocs.cpp @@ -0,0 +1,82 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Test that many child allocations work correctly. + */ + +#include "gtest/gtest.h" + +#include "mozilla/_ipdltest/IPDLUnitTest.h" +#include "mozilla/_ipdltest/PTestManyChildAllocsChild.h" +#include "mozilla/_ipdltest/PTestManyChildAllocsParent.h" +#include "mozilla/_ipdltest/PTestManyChildAllocsSubChild.h" +#include "mozilla/_ipdltest/PTestManyChildAllocsSubParent.h" + +using namespace mozilla::ipc; + +#define NALLOCS 10 + +namespace mozilla::_ipdltest { + +class TestManyChildAllocsSubParent : public PTestManyChildAllocsSubParent { + NS_INLINE_DECL_REFCOUNTING(TestManyChildAllocsSubParent, override) + private: + IPCResult RecvHello() final override { return IPC_OK(); } + + ~TestManyChildAllocsSubParent() = default; +}; + +class TestManyChildAllocsSubChild : public PTestManyChildAllocsSubChild { + NS_INLINE_DECL_REFCOUNTING(TestManyChildAllocsSubChild, override) + private: + ~TestManyChildAllocsSubChild() = default; +}; + +class TestManyChildAllocsParent : public PTestManyChildAllocsParent { + NS_INLINE_DECL_REFCOUNTING(TestManyChildAllocsParent, override) + private: + IPCResult RecvDone() final override { + Close(); + + return IPC_OK(); + } + + already_AddRefed + AllocPTestManyChildAllocsSubParent() final override { + return MakeAndAddRef(); + } + + ~TestManyChildAllocsParent() = default; +}; + +class TestManyChildAllocsChild : public PTestManyChildAllocsChild { + NS_INLINE_DECL_REFCOUNTING(TestManyChildAllocsChild, override) + private: + IPCResult RecvGo() final override { + for (int i = 0; i < NALLOCS; ++i) { + auto child = MakeRefPtr(); + EXPECT_TRUE(SendPTestManyChildAllocsSubConstructor(child)); + EXPECT_TRUE(child->SendHello()) << "can't send Hello()"; + } + + size_t len = ManagedPTestManyChildAllocsSubChild().Count(); + EXPECT_EQ((size_t)NALLOCS, len) + << "expected " << NALLOCS << " kids, got " << len; + + EXPECT_TRUE(SendDone()) << "can't send Done()"; + + return IPC_OK(); + } + + ~TestManyChildAllocsChild() = default; +}; + +IPDL_TEST(TestManyChildAllocs) { + EXPECT_TRUE(mActor->SendGo()) << "can't send Go()"; +} + +} // namespace mozilla::_ipdltest diff --git a/ipc/ipdl/test/gtest/TestMostNested.cpp b/ipc/ipdl/test/gtest/TestMostNested.cpp new file mode 100644 index 0000000000..d3fb3582c6 --- /dev/null +++ b/ipc/ipdl/test/gtest/TestMostNested.cpp @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: sw=2 ts=4 et : + */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Test nested sync message priorities. + */ + +#include "gtest/gtest.h" + +#include "mozilla/_ipdltest/IPDLUnitTest.h" +#include "mozilla/_ipdltest/PTestMostNestedChild.h" +#include "mozilla/_ipdltest/PTestMostNestedParent.h" + +#if defined(XP_UNIX) +# include +#else +# include +#endif + +using namespace mozilla::ipc; + +namespace mozilla::_ipdltest { + +class TestMostNestedChild : public PTestMostNestedChild { + NS_INLINE_DECL_REFCOUNTING(TestMostNestedChild, override) + private: + IPCResult RecvStart() final override { + EXPECT_TRUE(SendMsg1()); + EXPECT_TRUE(SendMsg2()); + + Close(); + return IPC_OK(); + } + + IPCResult RecvStartInner() final override { + EXPECT_TRUE(SendMsg3()); + EXPECT_TRUE(SendMsg4()); + + return IPC_OK(); + } + + ~TestMostNestedChild() = default; +}; + +class TestMostNestedParent : public PTestMostNestedParent { + NS_INLINE_DECL_REFCOUNTING(TestMostNestedParent, override) + private: + IPCResult RecvMsg1() final override { + EXPECT_EQ(msg_num, 0); + msg_num = 1; + return IPC_OK(); + } + + IPCResult RecvMsg2() final override { + EXPECT_EQ(msg_num, 1); + msg_num = 2; + + EXPECT_TRUE(SendStartInner()); + + return IPC_OK(); + } + + IPCResult RecvMsg3() final override { + EXPECT_EQ(msg_num, 2); + msg_num = 3; + return IPC_OK(); + } + + IPCResult RecvMsg4() final override { + EXPECT_EQ(msg_num, 3); + msg_num = 4; + return IPC_OK(); + } + + ~TestMostNestedParent() = default; + + int msg_num = 0; +}; + +// Can only run cross-process because nested sync messages have to come from the +// main thread. +IPDL_TEST_ON(CROSSPROCESS, TestMostNested) { EXPECT_TRUE(mActor->SendStart()); } + +} // namespace mozilla::_ipdltest diff --git a/ipc/ipdl/test/gtest/TestMultiMgrs.cpp b/ipc/ipdl/test/gtest/TestMultiMgrs.cpp new file mode 100644 index 0000000000..06dac581f3 --- /dev/null +++ b/ipc/ipdl/test/gtest/TestMultiMgrs.cpp @@ -0,0 +1,202 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Test a chain of managers, ensuring ownership is maintained correctly. + */ + +#include "gtest/gtest.h" + +#include "mozilla/_ipdltest/IPDLUnitTest.h" +#include "mozilla/_ipdltest/PTestMultiMgrsChild.h" +#include "mozilla/_ipdltest/PTestMultiMgrsParent.h" +#include "mozilla/_ipdltest/PTestMultiMgrsLeftChild.h" +#include "mozilla/_ipdltest/PTestMultiMgrsLeftParent.h" +#include "mozilla/_ipdltest/PTestMultiMgrsRightChild.h" +#include "mozilla/_ipdltest/PTestMultiMgrsRightParent.h" +#include "mozilla/_ipdltest/PTestMultiMgrsBottomChild.h" +#include "mozilla/_ipdltest/PTestMultiMgrsBottomParent.h" + +#include + +using namespace mozilla::ipc; + +namespace mozilla::_ipdltest { + +class TestMultiMgrsBottomParent : public PTestMultiMgrsBottomParent { + NS_INLINE_DECL_REFCOUNTING(TestMultiMgrsBottomParent, override) + private: + ~TestMultiMgrsBottomParent() = default; +}; + +class TestMultiMgrsBottomChild : public PTestMultiMgrsBottomChild { + NS_INLINE_DECL_REFCOUNTING(TestMultiMgrsBottomChild, override) + private: + ~TestMultiMgrsBottomChild() = default; +}; + +class TestMultiMgrsChild : public PTestMultiMgrsChild { + NS_INLINE_DECL_REFCOUNTING(TestMultiMgrsChild, override) + public: + PTestMultiMgrsBottomChild* mBottomL = nullptr; + PTestMultiMgrsBottomChild* mBottomR = nullptr; + + private: + already_AddRefed AllocPTestMultiMgrsLeftChild() + final override; + + already_AddRefed AllocPTestMultiMgrsRightChild() + final override; + + IPCResult RecvCheck() final override; + + ~TestMultiMgrsChild() = default; +}; + +class TestMultiMgrsLeftParent : public PTestMultiMgrsLeftParent { + NS_INLINE_DECL_REFCOUNTING(TestMultiMgrsLeftParent, override) + public: + bool HasChild(PTestMultiMgrsBottomParent* c) { + const auto& managed = ManagedPTestMultiMgrsBottomParent(); + return std::find(managed.begin(), managed.end(), c) != managed.end(); + } + + private: + ~TestMultiMgrsLeftParent() = default; +}; + +class TestMultiMgrsLeftChild : public PTestMultiMgrsLeftChild { + NS_INLINE_DECL_REFCOUNTING(TestMultiMgrsLeftChild, override) + public: + bool HasChild(PTestMultiMgrsBottomChild* c) { + const auto& managed = ManagedPTestMultiMgrsBottomChild(); + return std::find(managed.begin(), managed.end(), c) != managed.end(); + } + + private: + already_AddRefed AllocPTestMultiMgrsBottomChild() + final override { + return MakeAndAddRef(); + } + + IPCResult RecvPTestMultiMgrsBottomConstructor( + PTestMultiMgrsBottomChild* actor) final override { + static_cast(Manager())->mBottomL = actor; + return IPC_OK(); + } + + ~TestMultiMgrsLeftChild() = default; +}; + +class TestMultiMgrsRightParent : public PTestMultiMgrsRightParent { + NS_INLINE_DECL_REFCOUNTING(TestMultiMgrsRightParent, override) + public: + bool HasChild(PTestMultiMgrsBottomParent* c) { + const auto& managed = ManagedPTestMultiMgrsBottomParent(); + return std::find(managed.begin(), managed.end(), c) != managed.end(); + } + + private: + ~TestMultiMgrsRightParent() = default; +}; + +class TestMultiMgrsRightChild : public PTestMultiMgrsRightChild { + NS_INLINE_DECL_REFCOUNTING(TestMultiMgrsRightChild, override) + public: + bool HasChild(PTestMultiMgrsBottomChild* c) { + const auto& managed = ManagedPTestMultiMgrsBottomChild(); + return std::find(managed.begin(), managed.end(), c) != managed.end(); + } + + private: + already_AddRefed AllocPTestMultiMgrsBottomChild() + final override { + return MakeAndAddRef(); + } + + IPCResult RecvPTestMultiMgrsBottomConstructor( + PTestMultiMgrsBottomChild* actor) final override { + static_cast(Manager())->mBottomR = actor; + return IPC_OK(); + } + + ~TestMultiMgrsRightChild() = default; +}; + +class TestMultiMgrsParent : public PTestMultiMgrsParent { + NS_INLINE_DECL_REFCOUNTING(TestMultiMgrsParent, override) + private: + IPCResult RecvOK() final override { + Close(); + return IPC_OK(); + } + + ~TestMultiMgrsParent() = default; +}; + +already_AddRefed +TestMultiMgrsChild::AllocPTestMultiMgrsLeftChild() { + return MakeAndAddRef(); +} + +already_AddRefed +TestMultiMgrsChild::AllocPTestMultiMgrsRightChild() { + return MakeAndAddRef(); +} + +IPCResult TestMultiMgrsChild::RecvCheck() { + EXPECT_EQ(ManagedPTestMultiMgrsLeftChild().Count(), (uint32_t)1) + << "where's leftie?"; + EXPECT_EQ(ManagedPTestMultiMgrsRightChild().Count(), (uint32_t)1) + << "where's rightie?"; + + TestMultiMgrsLeftChild* leftie = static_cast( + LoneManagedOrNullAsserts(ManagedPTestMultiMgrsLeftChild())); + TestMultiMgrsRightChild* rightie = static_cast( + LoneManagedOrNullAsserts(ManagedPTestMultiMgrsRightChild())); + + EXPECT_TRUE(leftie->HasChild(mBottomL)) + << "leftie didn't have a child it was supposed to!"; + EXPECT_FALSE(leftie->HasChild(mBottomR)) << "leftie had rightie's child!"; + + EXPECT_TRUE(rightie->HasChild(mBottomR)) + << "rightie didn't have a child it was supposed to!"; + EXPECT_FALSE(rightie->HasChild(mBottomL)) << "rightie had leftie's child!"; + + EXPECT_TRUE(SendOK()) << "couldn't send OK()"; + + return IPC_OK(); +} + +IPDL_TEST(TestMultiMgrs) { + auto leftie = MakeRefPtr(); + EXPECT_TRUE(mActor->SendPTestMultiMgrsLeftConstructor(leftie)) + << "error sending ctor"; + + auto rightie = MakeRefPtr(); + EXPECT_TRUE(mActor->SendPTestMultiMgrsRightConstructor(rightie)) + << "error sending ctor"; + + auto bottomL = MakeRefPtr(); + EXPECT_TRUE(leftie->SendPTestMultiMgrsBottomConstructor(bottomL)) + << "error sending ctor"; + + auto bottomR = MakeRefPtr(); + EXPECT_TRUE(rightie->SendPTestMultiMgrsBottomConstructor(bottomR)) + << "error sending ctor"; + + EXPECT_TRUE(leftie->HasChild(bottomL)) + << "leftie didn't have a child it was supposed to!"; + EXPECT_FALSE(leftie->HasChild(bottomR)) << "leftie had rightie's child!"; + + EXPECT_TRUE(rightie->HasChild(bottomR)) + << "rightie didn't have a child it was supposed to!"; + EXPECT_FALSE(rightie->HasChild(bottomL)) << "rightie had rightie's child!"; + + EXPECT_TRUE(mActor->SendCheck()) << "couldn't kick off the child-side check"; +} + +} // namespace mozilla::_ipdltest diff --git a/ipc/ipdl/test/gtest/TestSelfManage.cpp b/ipc/ipdl/test/gtest/TestSelfManage.cpp new file mode 100644 index 0000000000..6dc1c4b7e4 --- /dev/null +++ b/ipc/ipdl/test/gtest/TestSelfManage.cpp @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Test that actors can manage other actors of the same type. + */ + +#include "gtest/gtest.h" + +#include "mozilla/_ipdltest/IPDLUnitTest.h" +#include "mozilla/_ipdltest/PTestSelfManageChild.h" +#include "mozilla/_ipdltest/PTestSelfManageParent.h" +#include "mozilla/_ipdltest/PTestSelfManageRootChild.h" +#include "mozilla/_ipdltest/PTestSelfManageRootParent.h" + +using namespace mozilla::ipc; + +namespace mozilla::_ipdltest { + +class TestSelfManageParent : public PTestSelfManageParent { + NS_INLINE_DECL_REFCOUNTING(TestSelfManageParent, override) + public: + ActorDestroyReason mWhy = ActorDestroyReason(-1); + + private: + void ActorDestroy(ActorDestroyReason why) final override { mWhy = why; } + + ~TestSelfManageParent() = default; +}; + +class TestSelfManageChild : public PTestSelfManageChild { + NS_INLINE_DECL_REFCOUNTING(TestSelfManageChild, override) + private: + already_AddRefed AllocPTestSelfManageChild() + final override { + return MakeAndAddRef(); + } + + ~TestSelfManageChild() = default; +}; + +class TestSelfManageRootParent : public PTestSelfManageRootParent { + NS_INLINE_DECL_REFCOUNTING(TestSelfManageRootParent, override) + private: + ~TestSelfManageRootParent() = default; +}; + +class TestSelfManageRootChild : public PTestSelfManageRootChild { + NS_INLINE_DECL_REFCOUNTING(TestSelfManageRootChild, override) + private: + already_AddRefed AllocPTestSelfManageChild() + final override { + return MakeAndAddRef(); + } + + ~TestSelfManageRootChild() = default; +}; + +IPDL_TEST(TestSelfManageRoot) { + auto child = MakeRefPtr(); + EXPECT_TRUE(mActor->SendPTestSelfManageConstructor(child)); + + EXPECT_EQ(mActor->ManagedPTestSelfManageParent().Count(), 1u); + + { + auto childsChild = MakeRefPtr(); + EXPECT_TRUE(child->SendPTestSelfManageConstructor(childsChild)); + + EXPECT_EQ(mActor->ManagedPTestSelfManageParent().Count(), 1u); + EXPECT_EQ(child->ManagedPTestSelfManageParent().Count(), 1u); + + EXPECT_TRUE(PTestSelfManageParent::Send__delete__(childsChild)); + + EXPECT_EQ(childsChild->mWhy, IProtocol::Deletion); + EXPECT_EQ(mActor->ManagedPTestSelfManageParent().Count(), 1u); + EXPECT_EQ(child->ManagedPTestSelfManageParent().Count(), 0u); + } + + { + auto childsChild = MakeRefPtr(); + EXPECT_TRUE(child->SendPTestSelfManageConstructor(childsChild)); + + EXPECT_EQ(mActor->ManagedPTestSelfManageParent().Count(), 1u); + EXPECT_EQ(child->ManagedPTestSelfManageParent().Count(), 1u); + + EXPECT_TRUE(PTestSelfManageParent::Send__delete__(child)); + + EXPECT_EQ(child->mWhy, IProtocol::Deletion); + EXPECT_EQ(childsChild->mWhy, IProtocol::AncestorDeletion); + EXPECT_EQ(mActor->ManagedPTestSelfManageParent().Count(), 0u); + EXPECT_EQ(child->ManagedPTestSelfManageParent().Count(), 0u); + } + + mActor->Close(); +} + +} // namespace mozilla::_ipdltest diff --git a/ipc/ipdl/test/gtest/TestShmem.cpp b/ipc/ipdl/test/gtest/TestShmem.cpp new file mode 100644 index 0000000000..e08bcee179 --- /dev/null +++ b/ipc/ipdl/test/gtest/TestShmem.cpp @@ -0,0 +1,122 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Test sending and receiving Shmem values. + */ + +#include "gtest/gtest.h" + +#include "mozilla/_ipdltest/IPDLUnitTest.h" +#include "mozilla/_ipdltest/PTestShmemChild.h" +#include "mozilla/_ipdltest/PTestShmemParent.h" + +using namespace mozilla::ipc; + +namespace mozilla::_ipdltest { + +class TestShmemParent : public PTestShmemParent { + NS_INLINE_DECL_REFCOUNTING(TestShmemParent, override) + private: + IPCResult RecvTake(Shmem&& mem, Shmem&& unsafe, + const uint32_t& expectedSize) final override { + EXPECT_EQ(mem.Size(), expectedSize) + << "expected shmem size " << expectedSize << ", but it has size " + << mem.Size(); + EXPECT_EQ(unsafe.Size(), expectedSize) + << "expected shmem size " << expectedSize << ", but it has size " + << unsafe.Size(); + + EXPECT_FALSE(strcmp(mem.get(), "And yourself!")) + << "expected message was not written"; + EXPECT_FALSE(strcmp(unsafe.get(), "And yourself!")) + << "expected message was not written"; + + EXPECT_TRUE(DeallocShmem(mem)); + EXPECT_TRUE(DeallocShmem(unsafe)); + + Close(); + + return IPC_OK(); + } + + ~TestShmemParent() = default; +}; + +class TestShmemChild : public PTestShmemChild { + NS_INLINE_DECL_REFCOUNTING(TestShmemChild, override) + private: + IPCResult RecvGive(Shmem&& mem, Shmem&& unsafe, + const uint32_t& expectedSize) final override { + EXPECT_EQ(mem.Size(), expectedSize) + << "expected shmem size " << expectedSize << ", but it has size " + << mem.Size(); + EXPECT_EQ(unsafe.Size(), expectedSize) + << "expected shmem size " << expectedSize << ", but it has size " + << unsafe.Size(); + + EXPECT_FALSE(strcmp(mem.get(), "Hello!")) + << "expected message was not written"; + EXPECT_FALSE(strcmp(unsafe.get(), "Hello!")) + << "expected message was not written"; + + char* unsafeptr = unsafe.get(); + + memcpy(mem.get(), "And yourself!", sizeof("And yourself!")); + memcpy(unsafeptr, "And yourself!", sizeof("And yourself!")); + + Shmem unsafecopy = unsafe; + EXPECT_TRUE(SendTake(std::move(mem), std::move(unsafe), expectedSize)); + + // these checks also shouldn't fail in the child + char uc1 = *unsafeptr; + (void)uc1; + char uc2 = *unsafecopy.get(); + (void)uc2; + + return IPC_OK(); + } + + ~TestShmemChild() = default; +}; + +IPDL_TEST(TestShmem) { + Shmem mem; + Shmem unsafe; + + uint32_t size = 12345; + EXPECT_TRUE(mActor->AllocShmem(size, &mem)) << "can't alloc shmem"; + EXPECT_TRUE(mActor->AllocUnsafeShmem(size, &unsafe)) << "can't alloc shmem"; + + EXPECT_EQ(mem.Size(), size) << "shmem is wrong size: expected " << size + << ", got " << mem.Size(); + EXPECT_EQ(unsafe.Size(), size) + << "shmem is wrong size: expected " << size << ", got " + << unsafe.Size(); + + char* ptr = mem.get(); + memcpy(ptr, "Hello!", sizeof("Hello!")); + + char* unsafeptr = unsafe.get(); + memcpy(unsafeptr, "Hello!", sizeof("Hello!")); + + Shmem unsafecopy = unsafe; + EXPECT_TRUE(mActor->SendGive(std::move(mem), std::move(unsafe), size)); + + // uncomment the following line for a (nondeterministic) surprise! + // char c1 = *ptr; (void)c1; + + // uncomment the following line for a deterministic surprise! + // char c2 = *mem.get(); (void)c2; + + // unsafe shmem gets rid of those checks + char uc1 = *unsafeptr; + (void)uc1; + char uc2 = *unsafecopy.get(); + (void)uc2; +} + +} // namespace mozilla::_ipdltest diff --git a/ipc/ipdl/test/gtest/TestSyncError.cpp b/ipc/ipdl/test/gtest/TestSyncError.cpp new file mode 100644 index 0000000000..f7a85598a6 --- /dev/null +++ b/ipc/ipdl/test/gtest/TestSyncError.cpp @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Test what happens when a sync message fails. + */ + +#include "gtest/gtest.h" + +#include "mozilla/_ipdltest/IPDLUnitTest.h" +#include "mozilla/_ipdltest/PTestSyncErrorChild.h" +#include "mozilla/_ipdltest/PTestSyncErrorParent.h" + +using namespace mozilla::ipc; + +namespace mozilla::_ipdltest { + +class TestSyncErrorParent : public PTestSyncErrorParent { + NS_INLINE_DECL_REFCOUNTING(TestSyncErrorParent, override) + private: + IPCResult RecvError() final override { return IPC_TEST_FAIL(this); } + + ~TestSyncErrorParent() = default; +}; + +class TestSyncErrorChild : public PTestSyncErrorChild { + NS_INLINE_DECL_REFCOUNTING(TestSyncErrorChild, override) + private: + IPCResult RecvStart() final override { + EXPECT_FALSE(SendError()) << "Error() should have return false"; + + Close(); + + return IPC_OK(); + } + ~TestSyncErrorChild() = default; +}; + +IPDL_TEST(TestSyncError) { EXPECT_TRUE(mActor->SendStart()); } + +} // namespace mozilla::_ipdltest diff --git a/ipc/ipdl/test/gtest/TestUniquePtrIPC.cpp b/ipc/ipdl/test/gtest/TestUniquePtrIPC.cpp new file mode 100644 index 0000000000..52ca322f8e --- /dev/null +++ b/ipc/ipdl/test/gtest/TestUniquePtrIPC.cpp @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Test UniquePtr IPC arguments. + */ + +#include "gtest/gtest.h" + +#include "mozilla/_ipdltest/IPDLUnitTest.h" +#include "mozilla/_ipdltest/PTestUniquePtrIPCChild.h" +#include "mozilla/_ipdltest/PTestUniquePtrIPCParent.h" + +using namespace mozilla::ipc; + +namespace mozilla::_ipdltest { + +class TestUniquePtrIPCParent : public PTestUniquePtrIPCParent { + NS_INLINE_DECL_REFCOUNTING(TestUniquePtrIPCParent, override) + private: + ~TestUniquePtrIPCParent() = default; +}; + +class TestUniquePtrIPCChild : public PTestUniquePtrIPCChild { + NS_INLINE_DECL_REFCOUNTING(TestUniquePtrIPCChild, override) + private: + IPCResult RecvTestMessage(const UniquePtr& aA1, + const UniquePtr& aA2, + const DummyStruct& aA3, + const UniquePtr& aA4) final override { + EXPECT_TRUE(aA1) << "TestMessage received NULL aA1"; + EXPECT_TRUE(aA2) << "TestMessage received NULL aA2"; + EXPECT_FALSE(aA4) + << "TestMessage received non-NULL when expecting NULL aA4"; + + EXPECT_EQ(*aA1, 1); + EXPECT_EQ(aA2->x(), 2); + EXPECT_EQ(aA3.x(), 3); + + return IPC_OK(); + } + + IPCResult RecvTestSendReference( + const UniquePtr& aA) final override { + EXPECT_TRUE(aA) << "TestSendReference received NULL item in child"; + EXPECT_EQ(aA->x(), 1); + + Close(); + return IPC_OK(); + } + + ~TestUniquePtrIPCChild() = default; +}; + +IPDL_TEST(TestUniquePtrIPC) { + UniquePtr a1 = MakeUnique(1); + UniquePtr a2 = MakeUnique(2); + DummyStruct a3(3); + UniquePtr a4; + + EXPECT_TRUE(mActor->SendTestMessage(a1, a2, a3, a4)); + + EXPECT_TRUE(a1) + << "IPC arguments are passed by const reference and shouldn't be moved"; + EXPECT_TRUE(a2) + << "IPC arguments are passed by const reference and shouldn't be moved"; + + EXPECT_FALSE(a4) << "somehow turned null ptr into non-null by sending it"; + + // Pass UniquePtr by reference + UniquePtr b = MakeUnique(1); + + EXPECT_TRUE(mActor->SendTestSendReference(b)); + EXPECT_TRUE(b) + << "IPC arguments are passed by const reference and shouldn't be moved"; +} + +} // namespace mozilla::_ipdltest diff --git a/ipc/ipdl/test/gtest/TestUrgency.cpp b/ipc/ipdl/test/gtest/TestUrgency.cpp new file mode 100644 index 0000000000..a4f7d0ea3e --- /dev/null +++ b/ipc/ipdl/test/gtest/TestUrgency.cpp @@ -0,0 +1,115 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Test that sync messages preempt other messages in the expected way. + */ + +#include "gtest/gtest.h" + +#include "mozilla/_ipdltest/IPDLUnitTest.h" +#include "mozilla/_ipdltest/PTestUrgencyChild.h" +#include "mozilla/_ipdltest/PTestUrgencyParent.h" + +using namespace mozilla::ipc; + +namespace mozilla::_ipdltest { + +enum { + kFirstTestBegin = 1, + kFirstTestGotReply, + kSecondTestBegin, + kSecondTestGotReply, +}; + +class TestUrgencyParent : public PTestUrgencyParent { + NS_INLINE_DECL_REFCOUNTING(TestUrgencyParent, override) + private: + IPCResult RecvTest1(uint32_t* value) final override { + EXPECT_TRUE(SendReply1(value)); + EXPECT_EQ(*value, (uint32_t)99) << "unexpected value"; + return IPC_OK(); + } + + IPCResult RecvTest2() final override { + uint32_t value; + inreply_ = true; + EXPECT_TRUE(SendReply2(&value)); + inreply_ = false; + EXPECT_EQ(value, (uint32_t)500) << "unexpected value"; + return IPC_OK(); + } + + IPCResult RecvTest3(uint32_t* value) final override { + EXPECT_FALSE(inreply_) << "nested non-urgent on top of urgent message"; + *value = 1000; + return IPC_OK(); + } + + IPCResult RecvFinalTest_Begin() final override { return IPC_OK(); } + + ~TestUrgencyParent() = default; + + bool inreply_ = false; +}; + +class TestUrgencyChild : public PTestUrgencyChild { + NS_INLINE_DECL_REFCOUNTING(TestUrgencyChild, override) + private: + IPCResult RecvStart() final override { + uint32_t result; + + // Send a synchronous message, expect to get an urgent message while + // blocked. + test_ = kFirstTestBegin; + EXPECT_TRUE(SendTest1(&result)); + EXPECT_EQ(result, (uint32_t)99) << "wrong value from SendTest1"; + EXPECT_EQ(test_, kFirstTestGotReply) + << "never received first urgent message"; + + // Initiate the next test by sending an asynchronous message, then becoming + // blocked. This tests that the urgent message is still delivered properly, + // and that the parent does not try to service the sync + test_ = kSecondTestBegin; + EXPECT_TRUE(SendTest2()); + EXPECT_TRUE(SendTest3(&result)); + EXPECT_EQ(test_, kSecondTestGotReply) + << "never received second urgent message"; + EXPECT_EQ(result, (uint32_t)1000) << "wrong value from SendTest3"; + + EXPECT_TRUE(SendFinalTest_Begin()); + + Close(); + + return IPC_OK(); + } + + IPCResult RecvReply1(uint32_t* reply) final override { + EXPECT_EQ(test_, kFirstTestBegin) << "wrong test state in RecvReply1"; + + *reply = 99; + test_ = kFirstTestGotReply; + return IPC_OK(); + } + + IPCResult RecvReply2(uint32_t* reply) final override { + EXPECT_EQ(test_, kSecondTestBegin) << "wrong test state in RecvReply2"; + + *reply = 500; + test_ = kSecondTestGotReply; + return IPC_OK(); + } + + ~TestUrgencyChild() = default; + + uint32_t test_ = 0; +}; + +// Only run cross-process because we need to send nested sync messages (this can +// only be done from the main thread). +IPDL_TEST_ON(CROSSPROCESS, TestUrgency) { EXPECT_TRUE(mActor->SendStart()); } + +} // namespace mozilla::_ipdltest diff --git a/ipc/ipdl/test/gtest/moz.build b/ipc/ipdl/test/gtest/moz.build index 129e366a4b..86fa2eca9e 100644 --- a/ipc/ipdl/test/gtest/moz.build +++ b/ipc/ipdl/test/gtest/moz.build @@ -16,18 +16,59 @@ EXPORTS.mozilla._ipdltest += [ SOURCES += [ "IPDLUnitTest.cpp", + "TestAsyncReturns.cpp", "TestBasic.cpp", + "TestCancel.cpp", "TestCrossProcessSemaphore.cpp", + "TestDataStructures.cpp", + "TestDescendant.cpp", + "TestEndpointOpens.cpp", + "TestHangs.cpp", "TestInduceConnectionError.cpp", + "TestJSON.cpp", + "TestManyChildAllocs.cpp", "TestManyHandles.cpp", + "TestMostNested.cpp", + "TestMultiMgrs.cpp", + "TestSelfManage.cpp", + "TestShmem.cpp", + "TestSyncError.cpp", + "TestUniquePtrIPC.cpp", + "TestUrgency.cpp", ] IPDL_SOURCES += [ "PIPDLUnitTest.ipdl", + "PTestAsyncReturns.ipdl", "PTestBasic.ipdl", + "PTestCancel.ipdl", "PTestCrossProcessSemaphore.ipdl", + "PTestDataStructures.ipdl", + "PTestDataStructuresCommon.ipdlh", + "PTestDataStructuresSub.ipdl", + "PTestDescendant.ipdl", + "PTestDescendantSub.ipdl", + "PTestDescendantSubsub.ipdl", + "PTestEndpointOpens.ipdl", + "PTestEndpointOpensOpened.ipdl", + "PTestHangs.ipdl", "PTestInduceConnectionError.ipdl", + "PTestJSON.ipdl", + "PTestJSONHandle.ipdl", + "PTestManyChildAllocs.ipdl", + "PTestManyChildAllocsSub.ipdl", "PTestManyHandles.ipdl", + "PTestMostNested.ipdl", + "PTestMultiMgrs.ipdl", + "PTestMultiMgrsBottom.ipdl", + "PTestMultiMgrsLeft.ipdl", + "PTestMultiMgrsRight.ipdl", + "PTestSelfManage.ipdl", + "PTestSelfManageRoot.ipdl", + "PTestShmem.ipdl", + "PTestSyncError.ipdl", + "PTestUniquePtrIPC.ipdl", + "PTestUrgency.ipdl", ] include("/ipc/chromium/chromium-config.mozbuild") diff --git a/ipc/ipdl/test/ipdl/error/ReturnFromDestructor.ipdl b/ipc/ipdl/test/ipdl/error/ReturnFromDestructor.ipdl new file mode 100644 index 0000000000..3e409389a8 --- /dev/null +++ b/ipc/ipdl/test/ipdl/error/ReturnFromDestructor.ipdl @@ -0,0 +1,7 @@ +//error: destructors cannot return values + +[ChildProc=any] +protocol ReturnFromDestructor { +child: + async __delete__() returns (bool something); +}; diff --git a/ipc/ipdl/test/ipdl/error/SyncDestructor.ipdl b/ipc/ipdl/test/ipdl/error/SyncDestructor.ipdl new file mode 100644 index 0000000000..08eb39ff34 --- /dev/null +++ b/ipc/ipdl/test/ipdl/error/SyncDestructor.ipdl @@ -0,0 +1,7 @@ +//error: destructor must be async + +[ChildProc=any] +protocol SyncDestructor { +child: + sync __delete__(); +}; diff --git a/ipc/ipdl/test/ipdl/ok/PDeleteSub.ipdl b/ipc/ipdl/test/ipdl/ok/PDeleteSub.ipdl index 12b4c677eb..c46f225d0f 100644 --- a/ipc/ipdl/test/ipdl/ok/PDeleteSub.ipdl +++ b/ipc/ipdl/test/ipdl/ok/PDeleteSub.ipdl @@ -4,7 +4,7 @@ sync protocol PDeleteSub { manager PDelete; parent: - sync __delete__(int x) returns (double d); + async __delete__(int x); }; diff --git a/ipc/ipdl/test/ipdl/sync-messages.ini b/ipc/ipdl/test/ipdl/sync-messages.ini index 989964f0dd..82af605d01 100644 --- a/ipc/ipdl/test/ipdl/sync-messages.ini +++ b/ipc/ipdl/test/ipdl/sync-messages.ini @@ -24,8 +24,6 @@ description = test only description = test only [PsyncProtocol::SyncMsg] description = test only -[PDeleteSub::__delete__] -description = test only [PintrMessageCompress::foo] description = test only [PintrMessageCompress::bar] -- cgit v1.2.3