Commit 7ef94fef authored by Dominik Charousset's avatar Dominik Charousset

Refactor launch process of sub-unit tests

parent 4e2e66cc
......@@ -66,7 +66,7 @@ set (LIBCAF_CORE_SRCS
src/replies_to.cpp
src/resumable.cpp
src/ripemd_160.cpp
src/run_program.cpp
src/run_sub_unit_test.cpp
src/scoped_actor.cpp
src/set_scheduler.cpp
src/serializer.cpp
......
......@@ -20,25 +20,24 @@
#ifndef CAF_DETAIL_RUN_PROGRAM_HPP
#define CAF_DETAIL_RUN_PROGRAM_HPP
#include "caf/send.hpp"
#include "caf/actor.hpp"
#include "caf/message.hpp"
#include "caf/string_algorithms.hpp"
#include <thread>
#include <vector>
#include <string>
#include <initializer_list>
#include "caf/send.hpp"
#include "caf/actor.hpp"
#include "caf/message.hpp"
namespace caf {
namespace detail {
std::thread run_program_impl(caf::actor, const char*, std::vector<std::string>);
template <class... Ts>
std::thread run_program(caf::actor listener, const char* path, Ts&&... args) {
std::vector<std::string> vec{convert_to_str(std::forward<Ts>(args))...};
return run_program_impl(listener, path, std::move(vec));
}
std::thread run_sub_unit_test(caf::actor listener,
const char* path,
int max_runtime,
const char* suite_name,
bool set_asio_option,
std::initializer_list<std::string> args);
} // namespace detail
} // namespace caf
......
......@@ -104,9 +104,6 @@ uniform_value make_uniform_value(const uniform_type_info* uti, Ts&&... xs) {
/// runtime.
///
/// ~~~
/// #include "caf/all.hpp"
/// using namespace caf;
///
/// struct foo { int a; int b; };
///
/// int main() {
......
......@@ -17,13 +17,15 @@
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/detail/run_program.hpp"
#include "caf/detail/run_sub_unit_test.hpp"
#include <sstream>
#include <iostream>
#include "caf/config.hpp"
#include "caf/string_algorithms.hpp"
#ifdef CAF_MSVC
# include <windows.h>
#endif
......@@ -32,16 +34,23 @@ namespace caf {
namespace detail {
#ifndef CAF_WINDOWS
std::thread run_program_impl(actor rc, const char* cpath,
std::vector<std::string> args) {
std::thread run_sub_unit_test(actor rc,
const char* cpath,
int max_runtime,
const char* suite_name,
bool set_asio_option,
std::initializer_list<std::string> args) {
using namespace std;
string path = cpath;
replace_all(path, "'", "\\'");
ostringstream oss;
oss << "'" << path << "'";
for (auto& arg : args) {
// set path and default options for sub unit tests
oss << "'" << path << "' "
<< "-n -s " << suite_name << " -r " << max_runtime << " --";
for (auto& arg : args)
oss << " " << arg;
}
if (set_asio_option)
oss << " --use-asio";
oss << " 2>&1";
string cmdstr = oss.str();
return std::thread{ [cmdstr, rc] {
......@@ -67,15 +76,19 @@ std::thread run_program_impl(actor rc, const char* cpath,
}};
}
#else
std::thread run_program_impl(actor rc, const char* cpath,
std::vector<std::string> args) {
std::thread run_sub_unit_test(actor rc, const char* cpath,
std::vector<std::string> args) {
std::string path = cpath;
replace_all(path, "'", "\\'");
std::ostringstream oss;
oss << path;
for (auto& arg : args) {
// set path and default options for sub unit tests
oss << "'" << path << "' "
<< "-n -s " << suite_name << " -r " << max_runtime << " --";
for (auto& arg : args)
oss << " " << arg;
}
if (set_asio_option)
oss << " --use-asio";
return std::thread([rc](std::string cmdstr) {
STARTUPINFO si;
PROCESS_INFORMATION pi;
......
......@@ -54,7 +54,7 @@ struct fixture {
if (expect_fail) {
self->sync_send(spawner, get_atom::value, "test_actor", std::move(args)).await(
[&](error_atom, const std::string&) {
CAF_TEST_VERBOSE("received error_atom (expected)");
CAF_MESSAGE("received error_atom (expected)");
}
);
} else {
......
......@@ -57,7 +57,7 @@ void chattier_actor(event_based_actor* self, const std::string& fn) {
CAF_TEST_FIXTURE_SCOPE(aout_tests, fixture)
CAF_TEST(global_redirect) {
CAF_TEST(redirect_aout_globally) {
scoped_actor self;
self->join(group::get("local", global_redirect));
actor_ostream::redirect_all(global_redirect);
......
......@@ -110,7 +110,7 @@ CAF_TEST(receive_atoms) {
);
atom_value x = atom("abc");
atom_value y = abc_atom::value;
CAF_CHECK_EQUAL(x, y);
CAF_CHECK(x == y);
auto msg = make_message(atom("abc"));
self->send(self, msg);
self->receive(
......
......@@ -499,7 +499,7 @@ CAF_TEST(send_to_self) {
self->receive(on() >> [] {});
}
CAF_TEST(echo_actor) {
CAF_TEST(echo_actor_messaging) {
scoped_actor self;
auto mecho = spawn<echo_actor>();
self->send(mecho, "hello echo");
......@@ -531,7 +531,7 @@ CAF_TEST(delayed_spawn) {
spawn<testee1>();
}
CAF_TEST(spawn_event_testee2) {
CAF_TEST(spawn_event_testee2_test) {
scoped_actor self;
spawn_event_testee2(self);
self->receive(
......@@ -631,7 +631,7 @@ CAF_TEST(sync_sends) {
self->receive (
[&](const down_msg& dm) {
CAF_CHECK_EQUAL(dm.reason, exit_reason::normal);
CAF_CHECK_EQUAL(dm.source, sync_testee);
CAF_CHECK(dm.source == sync_testee);
}
);
self->await_all_other_actors_done();
......
......@@ -25,10 +25,15 @@
#include <string>
#include <vector>
#include "caf/on.hpp"
#include "caf/message.hpp"
#include "caf/message_builder.hpp"
#include "caf/message_handler.hpp"
#include "caf/all.hpp"
namespace caf {
std::ostream& operator<<(std::ostream& out, const message& msg) {
return out << to_string(msg);
}
} // namespace caf
using namespace caf;
......
......@@ -22,8 +22,7 @@
#define CAF_SUITE message
#include "caf/test/unit_test.hpp"
#include "caf/message.hpp"
#include "caf/message_builder.hpp"
#include "caf/all.hpp"
using namespace caf;
......
......@@ -27,8 +27,7 @@
#include <typeinfo>
#include <type_traits>
#include "caf/shutdown.hpp"
#include "caf/uniform_type_info.hpp"
#include "caf/all.hpp"
#include "caf/detail/ctm.hpp"
#include "caf/detail/int_list.hpp"
......
......@@ -25,10 +25,8 @@
#define CAF_SUITE profiled_coordinator
#include "caf/test/unit_test.hpp"
#include "caf/config.hpp"
#include "caf/shutdown.hpp"
#include "caf/all.hpp"
#include "caf/set_scheduler.hpp"
#include "caf/scheduler/profiled_coordinator.hpp"
using namespace caf;
......
......@@ -238,7 +238,7 @@ CAF_TEST(test_int32_t) {
CAF_CHECK_EQUAL(i32, x);
}
CAF_TEST(test_enum) {
CAF_TEST(test_enum_serialization) {
auto buf = binary_util::serialize(te);
test_enum x;
binary_util::deserialize(buf, &x);
......
......@@ -471,7 +471,7 @@ CAF_TEST(sync_send) {
s->sync_send(serv, request_atom::value).await(
[=](response_atom) {
CAF_MESSAGE("received `response_atom`");
CAF_CHECK_EQUAL(s->current_sender(), work);
CAF_CHECK(s->current_sender() == work);
},
others >> [&] {
CAF_TEST_ERROR("Unexpected message: "
......@@ -483,7 +483,7 @@ CAF_TEST(sync_send) {
send_as(work, serv, idle_atom::value, work);
handle.await(
[=](response_atom) {
CAF_CHECK_EQUAL(s->current_sender(), work);
CAF_CHECK(s->current_sender() == work);
},
others >> [&] {
CAF_TEST_ERROR("Unexpected message: "
......
......@@ -22,10 +22,7 @@
#define CAF_SUITE work_sharing
#include "caf/test/unit_test.hpp"
#include "caf/config.hpp"
#include "caf/shutdown.hpp"
#include "caf/set_scheduler.hpp"
#include "caf/all.hpp"
#include "caf/policy/work_sharing.hpp"
......
......@@ -34,7 +34,7 @@
#include "caf/io/network/interfaces.hpp"
#include "caf/io/network/test_multiplexer.hpp"
#include "caf/detail/run_program.hpp"
#include "caf/detail/run_sub_unit_test.hpp"
#ifdef CAF_USE_ASIO
#include "caf/io/network/asio_multiplexer.hpp"
......@@ -76,11 +76,12 @@ using pong_atom = atom_constant<atom("pong")>;
*/
std::thread run_prog(const char* arg, uint16_t port, bool use_asio) {
return detail::run_program(invalid_actor, test::engine::path(), "-n",
"-s", CAF_XSTR(CAF_SUITE),
"-r", test::engine::max_runtime(), "--",
arg, "-p", port,
(use_asio ? "--use-asio" : ""));
return detail::run_sub_unit_test(invalid_actor,
test::engine::path(),
test::engine::max_runtime(),
CAF_XSTR(CAF_SUITE),
use_asio,
{"--port=" + std::to_string(port), arg});
}
// we run the same code on all three nodes, a simple ping-pong client
......@@ -208,7 +209,7 @@ void run_earth(bool use_asio, bool as_server, uint16_t pub_port) {
mars_process.join();
self->receive(
[&](delete_atom, const node_id& nid) {
CAF_CHECK_EQUAL(nid, mars);
CAF_CHECK(nid == mars);
}
);
CAF_MESSAGE("check whether we still can talk to Jupiter");
......@@ -221,7 +222,7 @@ void run_earth(bool use_asio, bool as_server, uint16_t pub_port) {
}
);
std::set<actor_addr> expected{aut.address(), jupiter_addr};
CAF_CHECK_EQUAL(found, expected);
CAF_CHECK(found == expected);
CAF_MESSAGE("shutdown Jupiter");
anon_send_exit(jupiter_addr, exit_reason::kill);
if (jupiter_process.joinable())
......@@ -247,8 +248,8 @@ void run_jupiter(uint16_t port_to_mars) {
CAF_TEST(triangle_setup) {
uint16_t port = 0;
uint16_t publish_port = 0;
auto argv = caf::test::engine::argv();
auto argc = caf::test::engine::argc();
auto argv = test::engine::argv();
auto argc = test::engine::argc();
auto r = message_builder(argv, argv + argc).extract_opts({
{"port,p", "port of remote side (when running mars or jupiter)", port},
{"mars", "run mars"},
......
......@@ -30,7 +30,7 @@
#include "caf/string_algorithms.hpp"
#include "caf/detail/run_program.hpp"
#include "caf/detail/run_sub_unit_test.hpp"
#ifdef CAF_USE_ASIO
#include "caf/io/network/asio_multiplexer.hpp"
......@@ -186,11 +186,13 @@ void run_server(bool spawn_client, const char* bin_path, bool use_asio) {
[&](uint16_t port) {
CAF_MESSAGE("server is running on port " << port);
if (spawn_client) {
auto child = detail::run_program(self, bin_path, "-n",
"-s", CAF_XSTR(CAF_SUITE),
"-r", test::engine::max_runtime(),
"--", "-c", port,
(use_asio ? "--use-asio" : ""));
auto child = detail::run_sub_unit_test(self,
bin_path,
test::engine::max_runtime(),
CAF_XSTR(CAF_SUITE),
use_asio,
{"--client-port="
+ std::to_string(port)});
CAF_MESSAGE("block till child process has finished");
child.join();
}
......@@ -208,8 +210,8 @@ void run_server(bool spawn_client, const char* bin_path, bool use_asio) {
} // namespace <anonymous>
CAF_TEST(test_broker) {
auto argv = caf::test::engine::argv();
auto argc = caf::test::engine::argc();
auto argv = test::engine::argv();
auto argc = test::engine::argc();
uint16_t port = 0;
auto r = message_builder(argv, argv + argc).extract_opts({
{"client-port,c", "set port for IO client", port},
......@@ -238,7 +240,7 @@ CAF_TEST(test_broker) {
// run in server mode
run_server(false, argv[0], use_asio);
} else {
run_server(true, caf::test::engine::path(), use_asio);
run_server(true, test::engine::path(), use_asio);
}
CAF_MESSAGE("block on `await_all_actors_done`");
await_all_actors_done();
......
......@@ -220,8 +220,8 @@ public:
CAF_REQUIRE((buf.size() >= x.size()));
CAF_REQUIRE((std::equal(buf.begin(),
buf.begin() + static_cast<ptrdiff_t>(x.size()),
x.begin()));
buf.erase(buf.begin(), buf.begin() + static_cast<ptrdiff_t>(x.size())));
x.begin())));
buf.erase(buf.begin(), buf.begin() + static_cast<ptrdiff_t>(x.size()));
return *this;
}
......
......@@ -34,7 +34,7 @@
#include "caf/detail/logging.hpp"
#include "caf/detail/singletons.hpp"
#include "caf/detail/run_program.hpp"
#include "caf/detail/run_sub_unit_test.hpp"
#ifdef CAF_USE_ASIO
#include "caf/io/network/asio_multiplexer.hpp"
......@@ -70,10 +70,10 @@ behavior ping_behavior(local_actor* self, size_t ping_msgs) {
if (! self->current_sender()) {
CAF_TEST_ERROR("current_sender() invalid!");
}
CAF_TEST_INFO("received {'pong', " << value << "}");
CAF_MESSAGE("received {'pong', " << value << "}");
// cout << to_string(self->current_message()) << endl;
if (++s_pongs >= ping_msgs) {
CAF_TEST_INFO("reached maximum, send {'EXIT', user_defined} "
CAF_MESSAGE("reached maximum, send {'EXIT', user_defined} "
<< "to last sender and quit with normal reason");
self->send_exit(self->current_sender(),
exit_reason::user_shutdown);
......@@ -480,17 +480,21 @@ void test_remote_actor(const char* path, bool run_remote, bool use_asio) {
CAF_CHECK(serv == serv2);
thread child;
if (run_remote) {
child = detail::run_program(self, path, "-n", "-s", CAF_XSTR(CAF_SUITE),
"-r", test::engine::max_runtime(), "--",
"-c", port2, "-c", port1, "-g", gport,
(use_asio ? "--use-asio" : ""));
child = detail::run_sub_unit_test(self,
path,
test::engine::max_runtime(),
CAF_XSTR(CAF_SUITE),
use_asio,
{"--client-port=" + std::to_string(port2),
"--client-port=" + std::to_string(port1),
"--group-port=" + std::to_string(gport)});
} else {
CAF_MESSAGE("please run client with: "
<< "-c " << port2 << " -c " << port1 << " -g " << gport);
}
self->receive(
[&](const down_msg& dm) {
CAF_CHECK_EQUAL(dm.source, serv);
CAF_CHECK(dm.source == serv);
CAF_CHECK_EQUAL(dm.reason, exit_reason::normal);
}
);
......@@ -509,9 +513,9 @@ void test_remote_actor(const char* path, bool run_remote, bool use_asio) {
} // namespace <anonymous>
CAF_TEST(test_remote_actor) {
auto argv = caf::test::engine::argv();
auto argc = caf::test::engine::argc();
CAF_TEST(remote_actors) {
auto argv = test::engine::argv();
auto argc = test::engine::argc();
announce<actor_vector>("actor_vector");
cout << "this node is: " << to_string(caf::detail::singletons::get_node_id())
<< endl;
......@@ -557,7 +561,7 @@ CAF_TEST(test_remote_actor) {
auto c = self->spawn<client, monitored>(serv);
self->receive(
[&](const down_msg& dm) {
CAF_CHECK_EQUAL(dm.source, c);
CAF_CHECK(dm.source == c);
CAF_CHECK_EQUAL(dm.reason, exit_reason::normal);
}
);
......@@ -565,7 +569,7 @@ CAF_TEST(test_remote_actor) {
} else {
for (int i = 0; i < 100; ++i) spawn([]{});
await_all_actors_done();
test_remote_actor(caf::test::engine::path(), true, use_asio);
test_remote_actor(test::engine::path(), true, use_asio);
}
await_all_actors_done();
shutdown();
......
......@@ -32,7 +32,7 @@
#include "caf/all.hpp"
#include "caf/io/all.hpp"
#include "caf/detail/run_program.hpp"
#include "caf/detail/run_sub_unit_test.hpp"
#include "caf/experimental/announce_actor_type.hpp"
......@@ -109,8 +109,8 @@ behavior server(stateful_actor<server_state>* self) {
CAF_TEST(remote_spawn) {
announce_actor_type("mirror", mirror);
auto argv = caf::test::engine::argv();
auto argc = caf::test::engine::argc();
auto argv = test::engine::argv();
auto argc = test::engine::argc();
uint16_t port = 0;
auto r = message_builder(argv, argv + argc).extract_opts({
{"server,s", "run as server (don't run client"},
......@@ -137,14 +137,16 @@ CAF_TEST(remote_spawn) {
}
auto serv = spawn(server);
port = io::publish(serv, port);
CAF_TEST_INFO("published server at port " << port);
CAF_MESSAGE("published server at port " << port);
if (r.opts.count("server") == 0) {
CAF_MESSAGE("run client program");
auto child = detail::run_program(invalid_actor, caf::test::engine::path(),
"-n", "-s", CAF_XSTR(CAF_SUITE),
"-r", test::engine::max_runtime(), "--",
"-c", port,
(use_asio ? "--use-asio" : ""));
auto child = detail::run_sub_unit_test(invalid_actor,
test::engine::path(),
test::engine::max_runtime(),
CAF_XSTR(CAF_SUITE),
use_asio,
{"--client="
+ std::to_string(port)});
child.join();
}
await_all_actors_done();
......
......@@ -32,7 +32,7 @@
#include "caf/string_algorithms.hpp"
#include "caf/detail/run_program.hpp"
#include "caf/detail/run_sub_unit_test.hpp"
#ifdef CAF_USE_ASIO
#include "caf/io/network/asio_multiplexer.hpp"
......@@ -191,11 +191,13 @@ void run_server(bool spawn_client, const char* bin_path, bool use_asio) {
[&](uint16_t port) {
CAF_MESSAGE("server is running on port " << port);
if (spawn_client) {
auto child = detail::run_program(self, bin_path, "-n",
"-s", CAF_XSTR(CAF_SUITE),
"-r", test::engine::max_runtime(),
"--", "-c", port,
(use_asio ? "--use-asio" : ""));
auto child = detail::run_sub_unit_test(self,
bin_path,
test::engine::max_runtime(),
CAF_XSTR(CAF_SUITE),
use_asio,
{"--client-port="
+ std::to_string(port)});
CAF_MESSAGE("block till child process has finished");
child.join();
}
......@@ -213,8 +215,8 @@ void run_server(bool spawn_client, const char* bin_path, bool use_asio) {
} // namespace <anonymous>
CAF_TEST(test_typed_broker) {
auto argv = caf::test::engine::argv();
auto argc = caf::test::engine::argc();
auto argv = test::engine::argv();
auto argc = test::engine::argc();
uint16_t port = 0;
auto r = message_builder(argv, argv + argc).extract_opts({
{"client-port,c", "set port for IO client", port},
......@@ -243,7 +245,7 @@ CAF_TEST(test_typed_broker) {
// run in server mode
run_server(false, argv[0], use_asio);
} else {
run_server(true, caf::test::engine::path(), use_asio);
run_server(true, test::engine::path(), use_asio);
}
CAF_MESSAGE("block on `await_all_actors_done`");
await_all_actors_done();
......
......@@ -32,7 +32,7 @@
#include "caf/all.hpp"
#include "caf/io/all.hpp"
#include "caf/detail/run_program.hpp"
#include "caf/detail/run_sub_unit_test.hpp"
#ifdef CAF_USE_ASIO
#include "caf/io/network/asio_multiplexer.hpp"
......@@ -101,8 +101,8 @@ uint16_t run_server() {
}
CAF_TEST(test_typed_remote_actor) {
auto argv = caf::test::engine::argv();
auto argc = caf::test::engine::argc();
auto argv = test::engine::argv();
auto argc = test::engine::argc();
announce<ping>("ping", &ping::value);
announce<pong>("pong", &pong::value);
uint16_t port = 0;
......@@ -133,11 +133,13 @@ CAF_TEST(test_typed_remote_actor) {
// execute client_part() in a separate process,
// connected via localhost socket
scoped_actor self;
auto child = detail::run_program(self, test::engine::path(), "-n",
"-s", CAF_XSTR(CAF_SUITE),
"-r", test::engine::max_runtime(), "--",
"-c", port,
(use_asio ? "--use-asio" : ""));
auto child = detail::run_sub_unit_test(self,
test::engine::path(),
test::engine::max_runtime(),
CAF_XSTR(CAF_SUITE),
use_asio,
{"--client-port="
+ std::to_string(port)});
CAF_MESSAGE("block till child process has finished");
child.join();
self->await_all_other_actors_done();
......
......@@ -62,8 +62,8 @@ void test_invalid_unpublish(const actor& published, uint16_t port) {
}
CAF_TEST(unpublishing) {
auto argv = caf::test::engine::argv();
auto argc = caf::test::engine::argc();
auto argv = test::engine::argv();
auto argc = test::engine::argc();
if (argc == 1 && strcmp(argv[0], "--use-asio") == 0) {
# ifdef CAF_USE_ASIO
CAF_MESSAGE("enable ASIO backend");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment