test: run multi-process tests with one harness

- Add test::RunDevices(): starts the devices with the same session,
  transport, shm options and channel config, with a deadline per run
- Add the TestDevice base: Check() fails the device, Succeed() prints
  a marker with the transport name that the harness verifies
- Make the protocol, poller and transfer-timeout devices check their
  own results and drop the InitTask() sleeps
- Replace EXPECT_EXIT() and the copied launch code in the protocol,
  poller and transfer-timeout tests
- A device that uses the wrong transport now fails the test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Claude
2026-11-03 14:27:11 +00:00
committed by Dennis Klein
parent f50b1f0e39
commit be400e4752
20 changed files with 446 additions and 800 deletions

View File

@@ -6,82 +6,46 @@
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#include "runner.h"
#include <fairmq/tools/Unique.h>
#include <fairmq/tools/Process.h>
#include <fairmq/tools/Strings.h>
#include <helper/Devices.h>
#include <helper/Transport.h>
#include <gtest/gtest.h>
#include <cstdio> // std::remove
#include <sstream> // std::stringstream
#include <thread>
#include <string>
namespace
{
using namespace std;
using namespace fair::mq::test;
using namespace fair::mq::tools;
auto RunPair(const string& transport, const string& extraDeviceCmdArgs) -> void
auto RunPair(string const& transport, string const& extraArgs) -> void
{
size_t session{fair::mq::tools::UuidHash()};
string ipcFile("/tmp/fmq_" + to_string(session) + "_data_" + transport);
string address("ipc://" + ipcFile);
IpcAddress const address("pair");
auto pairleft = execute_result{"", 100};
thread pairleft_thread([&]() {
stringstream cmd;
cmd << runTestDevice
<< " --id pairleft_" << transport
<< " --control static"
<< " --transport " << transport
<< " --shm-monitor true"
<< " --shm-segment-size 100000000"
<< " --session " << session
<< " --color false"
<< extraDeviceCmdArgs
<< " --channel-config name=data,type=pair,method=bind,address=" << address;
pairleft = execute(cmd.str(), "[PAIR L]");
});
auto const results = RunDevices({
{"pairleft_" + transport, "name=data,type=pair,method=bind,address=" + address.str()},
{"pairright_" + transport, "name=data,type=pair,method=connect,address=" + address.str()},
}, RunOptions(transport, extraArgs));
auto pairright = execute_result{"", 100};
thread pairright_thread([&]() {
stringstream cmd;
cmd << runTestDevice
<< " --id pairright_" << transport
<< " --control static"
<< " --transport " << transport
<< " --shm-monitor true"
<< " --shm-segment-size 100000000"
<< " --session " << session
<< " --color false"
<< extraDeviceCmdArgs
<< " --channel-config name=data,type=pair,method=connect,address=" << address;
pairright = execute(cmd.str(), "[PAIR R]");
});
pairleft_thread.join();
pairright_thread.join();
cerr << pairleft.console_out << pairright.console_out;
std::remove(ipcFile.c_str());
exit(pairleft.exit_code + pairright.exit_code);
for (auto const& result : results) {
EXPECT_TRUE(Succeeded(result, transport));
}
}
TEST(Pair, SingleMsg_MultiThreaded_ipc_zeromq)
{
EXPECT_EXIT(RunPair("zeromq", ""), ::testing::ExitedWithCode(0), "PAIR test successfull");
RunPair("zeromq", "");
}
TEST(Pair, SingleMsg_MultiThreaded_ipc_shmem)
{
EXPECT_EXIT(RunPair("shmem", ""), ::testing::ExitedWithCode(0), "PAIR test successfull");
RunPair("shmem", "");
}
TEST(Pair, SingleMsg_MultiThreaded_ipc_shmem_expanded_metadata)
{
EXPECT_EXIT(RunPair("shmem", " --shm-metadata-msg-size 2048"), ::testing::ExitedWithCode(0), "PAIR test successfull");
RunPair("shmem", "--shm-metadata-msg-size 2048");
}
} // namespace

View File

@@ -6,89 +6,41 @@
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#include "runner.h"
#include <fairmq/tools/Unique.h>
#include <fairmq/tools/Process.h>
#include <fairmq/tools/Strings.h>
#include <helper/Devices.h>
#include <helper/Transport.h>
#include <gtest/gtest.h>
#include <cstdio> // std::remove
#include <sstream> // std::stringstream
#include <thread>
#include <string>
namespace
{
using namespace std;
using namespace fair::mq::test;
using namespace fair::mq::tools;
auto RunPubSub(string transport) -> void
auto RunPubSub(string const& transport) -> void
{
size_t session{fair::mq::tools::UuidHash()};
string dataIpcFile("/tmp/fmq_" + to_string(session) + "_data_" + transport);
string ctrlIpcFile("/tmp/fmq_" + to_string(session) + "_ctrl_" + transport);
string dataAddress("ipc://" + dataIpcFile);
string ctrlAddress("ipc://" + ctrlIpcFile);
IpcAddress const data("pub_sub_data");
IpcAddress const control("pub_sub_control");
auto pub = execute_result{"", 0};
thread pub_thread([&]() {
stringstream cmd;
cmd << runTestDevice
<< " --id pub_" << transport
<< " --control static"
<< " --transport " << transport
<< " --session " << session
<< " --color false"
<< " --channel-config name=data,type=pub,method=bind,address=" << dataAddress
<< " name=control,type=pull,method=bind,address=" << ctrlAddress;
pub = execute(cmd.str(), "[PUB]");
});
auto const subChannels = "name=data,type=sub,method=connect,address=" + data.str()
+ " name=control,type=push,method=connect,address=" + control.str();
auto const results = RunDevices({
{"pub_" + transport, "name=data,type=pub,method=bind,address=" + data.str()
+ " name=control,type=pull,method=bind,address=" + control.str()},
{"sub_1_" + transport, subChannels},
{"sub_2_" + transport, subChannels},
}, RunOptions(transport));
auto sub1 = execute_result{"", 0};
thread sub1_thread([&]() {
stringstream cmd;
cmd << runTestDevice
<< " --id sub_1_" << transport
<< " --control static"
<< " --transport " << transport
<< " --session " << session
<< " --color false"
<< " --channel-config name=data,type=sub,method=connect,address=" << dataAddress
<< " name=control,type=push,method=connect,address=" << ctrlAddress;
sub1 = execute(cmd.str(), "[SUB1]");
});
auto sub2 = execute_result{"", 0};
thread sub2_thread([&]() {
stringstream cmd;
cmd << runTestDevice
<< " --id sub_2_" << transport
<< " --control static"
<< " --transport " << transport
<< " --session " << session
<< " --color false"
<< " --channel-config name=data,type=sub,method=connect,address=" << dataAddress
<< " name=control,type=push,method=connect,address=" << ctrlAddress;
sub2 = execute(cmd.str(), "[SUB2]");
});
pub_thread.join();
sub1_thread.join();
sub2_thread.join();
cerr << pub.console_out << sub1.console_out << sub2.console_out << endl;
std::remove(dataIpcFile.c_str());
std::remove(ctrlIpcFile.c_str());
exit(pub.exit_code + sub1.exit_code + sub2.exit_code);
for (auto const& result : results) {
EXPECT_TRUE(Succeeded(result, transport));
}
}
TEST(PubSub, zeromq)
{
EXPECT_EXIT(RunPubSub("zeromq"), ::testing::ExitedWithCode(0), "PUB-SUB test successfull");
RunPubSub("zeromq");
}
} // namespace

View File

@@ -6,82 +6,46 @@
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#include "runner.h"
#include <fairmq/tools/Unique.h>
#include <fairmq/tools/Process.h>
#include <fairmq/tools/Strings.h>
#include <helper/Devices.h>
#include <helper/Transport.h>
#include <gtest/gtest.h>
#include <cstdio> // std::remove
#include <sstream> // std::stringstream
#include <thread>
#include <string>
namespace
{
using namespace std;
using namespace fair::mq::test;
using namespace fair::mq::tools;
auto RunPushPull(string transport, const string& extraDeviceCmdArgs) -> void
auto RunPushPull(string const& transport, string const& extraArgs) -> void
{
size_t session(fair::mq::tools::UuidHash());
string ipcFile("/tmp/fmq_" + to_string(session) + "_data_" + transport);
string address("ipc://" + ipcFile);
IpcAddress const address("push_pull");
auto push = execute_result{"", 100};
thread push_thread([&]() {
stringstream cmd;
cmd << runTestDevice
<< " --id push_" << transport
<< " --control static"
<< " --transport " << transport
<< " --shm-monitor true"
<< " --shm-segment-size 100000000"
<< " --session " << session
<< " --color false"
<< extraDeviceCmdArgs
<< " --channel-config name=data,type=push,method=bind,address=" << address;
push = execute(cmd.str(), "[PUSH]");
});
auto const results = RunDevices({
{"push_" + transport, "name=data,type=push,method=bind,address=" + address.str()},
{"pull_" + transport, "name=data,type=pull,method=connect,address=" + address.str()},
}, RunOptions(transport, extraArgs));
auto pull = execute_result{"", 100};
thread pull_thread([&]() {
stringstream cmd;
cmd << runTestDevice
<< " --id pull_" << transport
<< " --control static"
<< " --transport " << transport
<< " --shm-monitor true"
<< " --shm-segment-size 100000000"
<< " --session " << session
<< " --color false"
<< extraDeviceCmdArgs
<< " --channel-config name=data,type=pull,method=connect,address=" << address;
pull = execute(cmd.str(), "[PULL]");
});
push_thread.join();
pull_thread.join();
cerr << push.console_out << pull.console_out;
std::remove(ipcFile.c_str());
exit(push.exit_code + pull.exit_code);
for (auto const& result : results) {
EXPECT_TRUE(Succeeded(result, transport));
}
}
TEST(PushPull, SingleMsg_MultiThreaded_ipc_zeromq)
{
EXPECT_EXIT(RunPushPull("zeromq", ""), ::testing::ExitedWithCode(0), "PUSH-PULL test successfull");
RunPushPull("zeromq", "");
}
TEST(PushPull, SingleMsg_MultiThreaded_ipc_shmem)
{
EXPECT_EXIT(RunPushPull("shmem", ""), ::testing::ExitedWithCode(0), "PUSH-PULL test successfull");
RunPushPull("shmem", "");
}
TEST(PushPull, SingleMsg_MultiThreaded_ipc_shmem_expanded_metadata)
{
EXPECT_EXIT(RunPushPull("shmem", " --shm-metadata-msg-size 2048"), ::testing::ExitedWithCode(0), "PUSH-PULL test successfull");
RunPushPull("shmem", "--shm-metadata-msg-size 2048");
}
} // namespace

View File

@@ -6,99 +6,47 @@
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#include "runner.h"
#include <fairmq/tools/Unique.h>
#include <fairmq/tools/Process.h>
#include <fairmq/tools/Strings.h>
#include <helper/Devices.h>
#include <helper/Transport.h>
#include <gtest/gtest.h>
#include <cstdio> // std::remove
#include <sstream> // std::stringstream
#include <thread>
#include <string>
namespace
{
using namespace std;
using namespace fair::mq::test;
using namespace fair::mq::tools;
auto RunReqRep(string transport, const string& extraDeviceCmdArgs) -> void
auto RunReqRep(string const& transport, string const& extraArgs) -> void
{
size_t session{fair::mq::tools::UuidHash()};
string ipcFile("/tmp/fmq_" + to_string(session) + "_data_" + transport);
string address("ipc://" + ipcFile);
IpcAddress const address("req_rep");
auto rep = execute_result{"", 0};
thread rep_thread([&]() {
stringstream cmd;
cmd << runTestDevice
<< " --id rep_" << transport
<< " --control static"
<< " --transport " << transport
<< " --shm-monitor true"
<< " --shm-segment-size 100000000"
<< " --session " << session
<< " --color false"
<< extraDeviceCmdArgs
<< " --channel-config name=data,type=rep,method=bind,address=" << address;
rep = execute(cmd.str(), "[REP]");
});
auto const results = RunDevices({
{"rep_" + transport, "name=data,type=rep,method=bind,address=" + address.str()},
{"req_1_" + transport, "name=data,type=req,method=connect,address=" + address.str()},
{"req_2_" + transport, "name=data,type=req,method=connect,address=" + address.str()},
}, RunOptions(transport, extraArgs));
auto req1 = execute_result{"", 0};
thread req1_thread([&]() {
stringstream cmd;
cmd << runTestDevice
<< " --id req_1_" << transport
<< " --control static"
<< " --transport " << transport
<< " --shm-monitor true"
<< " --shm-segment-size 100000000"
<< " --session " << session
<< " --color false"
<< extraDeviceCmdArgs
<< " --channel-config name=data,type=req,method=connect,address=" << address;
req1 = execute(cmd.str(), "[REQ1]");
});
auto req2 = execute_result{"", 0};
thread req2_thread([&]() {
stringstream cmd;
cmd << runTestDevice
<< " --id req_2_" << transport
<< " --control static"
<< " --transport " << transport
<< " --shm-monitor true"
<< " --shm-segment-size 100000000"
<< " --session " << session
<< " --color false"
<< extraDeviceCmdArgs
<< " --channel-config name=data,type=req,method=connect,address=" << address;
req2 = execute(cmd.str(), "[REQ2]");
});
rep_thread.join();
req1_thread.join();
req2_thread.join();
cerr << req1.console_out << req2.console_out << rep.console_out;
std::remove(ipcFile.c_str());
exit(req1.exit_code + req2.exit_code + rep.exit_code);
for (auto const& result : results) {
EXPECT_TRUE(Succeeded(result, transport));
}
}
TEST(ReqRep, zeromq)
{
EXPECT_EXIT(RunReqRep("zeromq", ""), ::testing::ExitedWithCode(0), "REQ-REP test successfull");
RunReqRep("zeromq", "");
}
TEST(ReqRep, shmem)
{
EXPECT_EXIT(RunReqRep("shmem", ""), ::testing::ExitedWithCode(0), "REQ-REP test successfull");
RunReqRep("shmem", "");
}
TEST(ReqRep, shmem_expanded_metadata)
{
EXPECT_EXIT(RunReqRep("shmem", " --shm-metadata-msg-size 2048"), ::testing::ExitedWithCode(0), "REQ-REP test successfull");
RunReqRep("shmem", "--shm-metadata-msg-size 2048");
}
} // namespace