Files
palemoon27/ipc/ipdl/test/cxx/TestHangs.cpp
T
roytam1 81d61fa324 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1265036 - Use NS_ABORT_OOM() if try_realloc() fails. r=billm (c30f4f83d5)
- Bug 1263292 - Handle calling realloc(0) (r=jld) (f292859ee9)
- Bug 1256366 - Remove linear and exponential stats collection from histogram.cc. r=gfritzsche (f9a1c869a1)
- Bug 1263953 - Reduce the growth rate of Pickle. r=wmccloskey (6eb5228490)
- Bug 1233275 - Copy environment for IPC using NSPR. r=jld (2004db748e)
- Bug 1261094 - Improve how MessageChannel::mInterruptStack is used in IPC code, r=jld (56e2c114a4)
- Bug 1246931: Include dbus.h in DBus IPC headers, r=shuang (43e797c2d8)
- Bug 1264887: Make DBus helpers available on desktop builds, r=shuang (58bff1f640)
- Bug 1268130, part 1 - Reimplement ByteLengthIsValid using CheckedInt. r=froydnj (6018e22ae0)
- Bug 1268130, part 2 - Make ByteLengthIsValid failures fatal in release builds. r=froydnj (f9d934a498)
- Bug 1269365, part 1 - Swap fallible and infallible TArray ParamTraits. r=froydnj (ad423bc04d)
- Bug 1269365, part 2 - Make ParamTraits<nsTArray<E>>::Read use infallible allocation. r=froydnj (9b902a5bc4)
- Bug 1269365, part 3 - Use infallible array allocation in implementSpecialArrayPickling. r=froydnj (592fe648d3)
- Bug 1264820 - Measure IPC reply size in telemetry (r=mccr8) (62c54d3141)
- Bug 1268938 - Use the name of the original message in Send for reply telemetry. r=billm (a2de5c6a91)
- Bug 1266954: Remove temporary |ScopedClose| from PDU receive code, r=jacheng (cb06315c33)
- Bug 1142109 - Fix IPDL tests (r=dvander) (df3f0cda32)
- Bug 1177013 - Fix IPDL tests for not allowing CPOWs during sync (r=dvander) (5da0a8a4c9)
- Bug 1261307: Convert RIL sockets to |UniquePtr|, r=nfroyd (08609783b3)
- Bug 1253622 - Move the mozilla-trace.h generation into moz.build; r=ted (f01dc418bc)
- Bug 1267318 ignore cert expiration for mozilla-signed packages, r=dkeeler (7a1ddd6090)
- Bug 1029173 - Clean up nsDataSignatureVerifier. r=keeler (f9602341ea)
- bug 1267463 - add a more nuanced subject common name fallback option for prerelease channels r=Cykesiopka,jcj (9b55320c9b)
- Bug 1253108 - Enable ESLint "strict" rule for PSM. r=keeler (54802bdc38)
- Bug 1255425 - part 1 - clearly delineate steps when outputting HSTS preload list; r=keeler (79f73189c8)
- Bug 1251801 - Fully implement nsNSSShutDownObject and obviate manual NSS resource management. r=keeler (af32315d3f)
- Bug 1251801 - Improve handling of PK11_* function error codes. r=keeler (9f2c8ac64b)
- Fix unified-build bustage from bug 1264706. r=bustage (11bc0417c7)
- Bug 1265164 - Always use nsCOMPtrs with getNSSDialogs(). r=keeler (ce5a703972)
2024-09-03 10:19:02 +08:00

154 lines
3.8 KiB
C++

#include "base/process_util.h"
#include "TestHangs.h"
#include "IPDLUnitTests.h" // fail etc.
using base::KillProcess;
template<>
struct RunnableMethodTraits<mozilla::_ipdltest::TestHangsParent>
{
static void RetainCallee(mozilla::_ipdltest::TestHangsParent* obj) { }
static void ReleaseCallee(mozilla::_ipdltest::TestHangsParent* obj) { }
};
namespace mozilla {
namespace _ipdltest {
//-----------------------------------------------------------------------------
// parent
TestHangsParent::TestHangsParent() : mDetectedHang(false)
{
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(
FROM_HERE, NewRunnableMethod(this, &TestHangsParent::CleanUp));
GetIPCChannel()->CloseWithTimeout();
return false;
}
bool
TestHangsParent::AnswerStackFrame()
{
if (PTestHangs::HANG != state()) {
if (CallStackFrame())
fail("should have timed out!");
}
else {
// 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!");
}
return true;
}
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);
}
bool
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 true;
}
} // namespace _ipdltest
} // namespace mozilla