Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions test/mp/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <list> // IWYU pragma: keep
#include <map>
#include <memory>
#include <mp/config.h>
#include <mp/proxy.h>
#include <mp/proxy.capnp.h>
#include <mp/proxy-io.h>
Expand Down Expand Up @@ -668,9 +667,27 @@ KJ_TEST("Call async IPC method dispatched to pool thread")
}
}

#ifdef HAVE_PTHREAD_GETNAME_NP
//! Return whether OS thread names set by SetOsThreadName()
//! can be read back by ThreadName() on this platform.
static bool OsThreadNamesSupported()
{
static const bool supported = [] {
bool found = false;
std::thread([&found] {
SetOsThreadName("mptest-probe");
found = ThreadName("").find("/mptest-probe-") != std::string::npos;
}).join();
if (!found) {
KJ_LOG(WARNING, "OS thread names cannot be set and read back on this platform; skipping thread name tests");
}
return found;
}();
return supported;
}

KJ_TEST("Worker thread has OS thread name")
{
if (!OsThreadNamesSupported()) return;
TestSetup setup;
ProxyClient<messages::FooInterface>* foo = setup.client.get();
foo->initThreadMap();
Expand All @@ -685,6 +702,7 @@ KJ_TEST("Worker thread has OS thread name")

KJ_TEST("Pool thread has OS thread name")
{
if (!OsThreadNamesSupported()) return;
TestSetup setup;
ProxyClient<messages::FooInterface>* foo = setup.client.get();
foo->initThreadMap();
Expand Down Expand Up @@ -717,6 +735,7 @@ KJ_TEST("Pool thread has OS thread name")

KJ_TEST("Async cleanup thread has OS thread name")
{
if (!OsThreadNamesSupported()) return;
std::promise<std::string> thread_name;
{
TestSetup setup;
Expand All @@ -728,7 +747,6 @@ KJ_TEST("Async cleanup thread has OS thread name")
const std::string name{thread_name.get_future().get()};
KJ_EXPECT(name.find("/capnp-async-") != std::string::npos, name);
}
#endif // HAVE_PTHREAD_GETNAME_NP

KJ_TEST("Call async IPC method without thread or pool errors correctly")
{
Expand Down
Loading