Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | #include "TestCrashCleanup.h" |
michael@0 | 2 | |
michael@0 | 3 | #include "mozilla/CondVar.h" |
michael@0 | 4 | #include "mozilla/Mutex.h" |
michael@0 | 5 | |
michael@0 | 6 | #include "IPDLUnitTests.h" // fail etc. |
michael@0 | 7 | #include "IPDLUnitTestSubprocess.h" |
michael@0 | 8 | |
michael@0 | 9 | using mozilla::CondVar; |
michael@0 | 10 | using mozilla::Mutex; |
michael@0 | 11 | using mozilla::MutexAutoLock; |
michael@0 | 12 | |
michael@0 | 13 | namespace mozilla { |
michael@0 | 14 | namespace _ipdltest { |
michael@0 | 15 | |
michael@0 | 16 | //----------------------------------------------------------------------------- |
michael@0 | 17 | // parent |
michael@0 | 18 | |
michael@0 | 19 | namespace { |
michael@0 | 20 | |
michael@0 | 21 | // NB: this test does its own shutdown, rather than going through |
michael@0 | 22 | // QuitParent(), because it's testing degenerate edge cases |
michael@0 | 23 | |
michael@0 | 24 | void DeleteSubprocess(Mutex* mutex, CondVar* cvar) |
michael@0 | 25 | { |
michael@0 | 26 | MutexAutoLock lock(*mutex); |
michael@0 | 27 | |
michael@0 | 28 | delete gSubprocess; |
michael@0 | 29 | gSubprocess = nullptr; |
michael@0 | 30 | |
michael@0 | 31 | cvar->Notify(); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | void DeleteTheWorld() |
michael@0 | 35 | { |
michael@0 | 36 | delete static_cast<TestCrashCleanupParent*>(gParentActor); |
michael@0 | 37 | gParentActor = nullptr; |
michael@0 | 38 | |
michael@0 | 39 | // needs to be synchronous to avoid affecting event ordering on |
michael@0 | 40 | // the main thread |
michael@0 | 41 | Mutex mutex("TestCrashCleanup.DeleteTheWorld.mutex"); |
michael@0 | 42 | CondVar cvar(mutex, "TestCrashCleanup.DeleteTheWorld.cvar"); |
michael@0 | 43 | |
michael@0 | 44 | MutexAutoLock lock(mutex); |
michael@0 | 45 | |
michael@0 | 46 | XRE_GetIOMessageLoop()->PostTask( |
michael@0 | 47 | FROM_HERE, |
michael@0 | 48 | NewRunnableFunction(DeleteSubprocess, &mutex, &cvar)); |
michael@0 | 49 | |
michael@0 | 50 | cvar.Wait(); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | void Done() |
michael@0 | 54 | { |
michael@0 | 55 | static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID); |
michael@0 | 56 | nsCOMPtr<nsIAppShell> appShell (do_GetService(kAppShellCID)); |
michael@0 | 57 | appShell->Exit(); |
michael@0 | 58 | |
michael@0 | 59 | passed(__FILE__); |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | } // namespace <anon> |
michael@0 | 63 | |
michael@0 | 64 | TestCrashCleanupParent::TestCrashCleanupParent() : mCleanedUp(false) |
michael@0 | 65 | { |
michael@0 | 66 | MOZ_COUNT_CTOR(TestCrashCleanupParent); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | TestCrashCleanupParent::~TestCrashCleanupParent() |
michael@0 | 70 | { |
michael@0 | 71 | MOZ_COUNT_DTOR(TestCrashCleanupParent); |
michael@0 | 72 | |
michael@0 | 73 | if (!mCleanedUp) |
michael@0 | 74 | fail("should have been ActorDestroy()d!"); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | void |
michael@0 | 78 | TestCrashCleanupParent::Main() |
michael@0 | 79 | { |
michael@0 | 80 | // NB: has to be enqueued before IO thread's error notification |
michael@0 | 81 | MessageLoop::current()->PostTask( |
michael@0 | 82 | FROM_HERE, NewRunnableFunction(DeleteTheWorld)); |
michael@0 | 83 | |
michael@0 | 84 | if (CallDIEDIEDIE()) |
michael@0 | 85 | fail("expected an error!"); |
michael@0 | 86 | |
michael@0 | 87 | Close(); |
michael@0 | 88 | |
michael@0 | 89 | MessageLoop::current()->PostTask(FROM_HERE, NewRunnableFunction(Done)); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | |
michael@0 | 93 | //----------------------------------------------------------------------------- |
michael@0 | 94 | // child |
michael@0 | 95 | |
michael@0 | 96 | TestCrashCleanupChild::TestCrashCleanupChild() |
michael@0 | 97 | { |
michael@0 | 98 | MOZ_COUNT_CTOR(TestCrashCleanupChild); |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | TestCrashCleanupChild::~TestCrashCleanupChild() |
michael@0 | 102 | { |
michael@0 | 103 | MOZ_COUNT_DTOR(TestCrashCleanupChild); |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | bool |
michael@0 | 107 | TestCrashCleanupChild::AnswerDIEDIEDIE() |
michael@0 | 108 | { |
michael@0 | 109 | _exit(0); |
michael@0 | 110 | NS_RUNTIMEABORT("unreached"); |
michael@0 | 111 | return false; |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | |
michael@0 | 115 | } // namespace _ipdltest |
michael@0 | 116 | } // namespace mozilla |