Commit ee336330 authored by Dominik Charousset's avatar Dominik Charousset

print unit test log info to stdout as well

parent 600ad249
...@@ -171,10 +171,11 @@ oss_wr operator<<(oss_wr&& lhs, T rhs) { ...@@ -171,10 +171,11 @@ oss_wr operator<<(oss_wr&& lhs, T rhs) {
} CPPA_VOID_STMT } CPPA_VOID_STMT
#ifndef CPPA_LOG_LEVEL #ifndef CPPA_LOG_LEVEL
inline cppa::actor_id cppa_set_aid_dummy() { return 0; }
# define CPPA_LOG_IMPL(lvlname, classname, funname, message) \ # define CPPA_LOG_IMPL(lvlname, classname, funname, message) \
CPPA_PRINT_ERROR_IMPL(lvlname, classname, funname, message) CPPA_PRINT_ERROR_IMPL(lvlname, classname, funname, message)
# define CPPA_PUSH_AID(unused) # define CPPA_PUSH_AID(unused) static_cast<void>(0)
# define CPPA_SET_AID(unused) 0 # define CPPA_SET_AID(unused) cppa_set_aid_dummy()
# define CPPA_LOG_LEVEL 1 # define CPPA_LOG_LEVEL 1
#else #else
# define CPPA_LOG_IMPL(lvlname, classname, funname, message) \ # define CPPA_LOG_IMPL(lvlname, classname, funname, message) \
......
#include <iostream> #include <iostream>
#include "test.hpp"
#include "ping_pong.hpp" #include "ping_pong.hpp"
#include "cppa/cppa.hpp" #include "cppa/cppa.hpp"
...@@ -18,11 +19,13 @@ size_t s_pongs = 0; ...@@ -18,11 +19,13 @@ size_t s_pongs = 0;
behavior ping_behavior(local_actor* self, size_t num_pings) { behavior ping_behavior(local_actor* self, size_t num_pings) {
return ( return (
on(atom("pong"), arg_match) >> [=](int value) -> any_tuple { on(atom("pong"), arg_match) >> [=](int value) -> any_tuple {
CPPA_LOGF_ERROR_IF(!self->last_sender(), "last_sender() == nullptr"); if (!self->last_sender()) {
CPPA_LOGF_INFO("received {'pong', " << value << "}"); CPPA_PRINT("last_sender() invalid!");
}
CPPA_PRINT("received {'pong', " << value << "}");
//cout << to_string(self->last_dequeued()) << endl; //cout << to_string(self->last_dequeued()) << endl;
if (++s_pongs >= num_pings) { if (++s_pongs >= num_pings) {
CPPA_LOGF_INFO("reached maximum, send {'EXIT', user_defined} " CPPA_PRINT("reached maximum, send {'EXIT', user_defined} "
<< "to last sender and quit with normal reason"); << "to last sender and quit with normal reason");
self->send_exit(self->last_sender(), exit_reason::user_shutdown); self->send_exit(self->last_sender(), exit_reason::user_shutdown);
self->quit(); self->quit();
...@@ -40,7 +43,7 @@ behavior ping_behavior(local_actor* self, size_t num_pings) { ...@@ -40,7 +43,7 @@ behavior ping_behavior(local_actor* self, size_t num_pings) {
behavior pong_behavior(local_actor* self) { behavior pong_behavior(local_actor* self) {
return ( return (
on(atom("ping"), arg_match) >> [](int value) -> any_tuple { on(atom("ping"), arg_match) >> [](int value) -> any_tuple {
CPPA_LOGF_INFO("received {'ping', " << value << "}"); CPPA_PRINT("received {'ping', " << value << "}");
return make_any_tuple(atom("pong"), value + 1); return make_any_tuple(atom("pong"), value + 1);
}, },
others() >> [=] { others() >> [=] {
......
...@@ -99,7 +99,7 @@ void peer(io::broker* self, io::connection_handle hdl, const actor& buddy) { ...@@ -99,7 +99,7 @@ void peer(io::broker* self, io::connection_handle hdl, const actor& buddy) {
}; };
self->become ( self->become (
on(atom("IO_closed"), arg_match) >> [=](io::connection_handle) { on(atom("IO_closed"), arg_match) >> [=](io::connection_handle) {
CPPA_LOGF_INFO("received IO_closed"); CPPA_PRINT("received IO_closed");
self->quit(); self->quit();
}, },
on(atom("IO_read"), arg_match) >> [=](io::connection_handle, const util::buffer& buf) { on(atom("IO_read"), arg_match) >> [=](io::connection_handle, const util::buffer& buf) {
...@@ -127,7 +127,7 @@ void peer_acceptor(io::broker* self, const actor& buddy) { ...@@ -127,7 +127,7 @@ void peer_acceptor(io::broker* self, const actor& buddy) {
self->become ( self->become (
on(atom("IO_accept"), arg_match) >> [=](io::accept_handle, io::connection_handle hdl) { on(atom("IO_accept"), arg_match) >> [=](io::accept_handle, io::connection_handle hdl) {
CPPA_CHECKPOINT(); CPPA_CHECKPOINT();
CPPA_LOGF_INFO("received IO_accept"); CPPA_PRINT("received IO_accept");
self->fork(peer, hdl, buddy); self->fork(peer, hdl, buddy);
self->quit(); self->quit();
}, },
......
...@@ -25,7 +25,7 @@ typedef vector<actor> actor_vector; ...@@ -25,7 +25,7 @@ typedef vector<actor> actor_vector;
void reflector(event_based_actor* self) { void reflector(event_based_actor* self) {
self->become ( self->become (
others() >> [=] { others() >> [=] {
CPPA_LOGF_INFO("reflect and quit"); CPPA_PRINT("reflect and quit");
self->quit(); self->quit();
return self->last_dequeued(); return self->last_dequeued();
} }
...@@ -38,10 +38,10 @@ void spawn5_server_impl(event_based_actor* self, actor client, group grp) { ...@@ -38,10 +38,10 @@ void spawn5_server_impl(event_based_actor* self, actor client, group grp) {
CPPA_CHECK(grp != invalid_group); CPPA_CHECK(grp != invalid_group);
self->spawn_in_group(grp, reflector); self->spawn_in_group(grp, reflector);
self->spawn_in_group(grp, reflector); self->spawn_in_group(grp, reflector);
CPPA_LOGF_INFO("send {'Spawn5'} and await {'ok', actor_vector}"); CPPA_PRINT("send {'Spawn5'} and await {'ok', actor_vector}");
self->sync_send(client, atom("Spawn5"), grp).then( self->sync_send(client, atom("Spawn5"), grp).then(
on(atom("ok"), arg_match) >> [=](const actor_vector& vec) { on(atom("ok"), arg_match) >> [=](const actor_vector& vec) {
CPPA_LOGF_INFO("received vector with " << vec.size() << " elements"); CPPA_PRINT("received vector with " << vec.size() << " elements");
self->send(grp, "Hello reflectors!", 5.0); self->send(grp, "Hello reflectors!", 5.0);
if (vec.size() != 5) { if (vec.size() != 5) {
CPPA_PRINTERR("remote client did not spawn five reflectors!"); CPPA_PRINTERR("remote client did not spawn five reflectors!");
...@@ -107,7 +107,7 @@ void spawn5_server_impl(event_based_actor* self, actor client, group grp) { ...@@ -107,7 +107,7 @@ void spawn5_server_impl(event_based_actor* self, actor client, group grp) {
void spawn5_server(event_based_actor* self, actor client, bool inverted) { void spawn5_server(event_based_actor* self, actor client, bool inverted) {
if (!inverted) spawn5_server_impl(self, client, group::get("local", "foobar")); if (!inverted) spawn5_server_impl(self, client, group::get("local", "foobar"));
else { else {
CPPA_LOGF_INFO("request group"); CPPA_PRINT("request group");
self->sync_send(client, atom("GetGroup")).then ( self->sync_send(client, atom("GetGroup")).then (
[=](const group& remote_group) { [=](const group& remote_group) {
spawn5_server_impl(self, client, remote_group); spawn5_server_impl(self, client, remote_group);
...@@ -119,11 +119,11 @@ void spawn5_server(event_based_actor* self, actor client, bool inverted) { ...@@ -119,11 +119,11 @@ void spawn5_server(event_based_actor* self, actor client, bool inverted) {
void spawn5_client(event_based_actor* self) { void spawn5_client(event_based_actor* self) {
self->become ( self->become (
on(atom("GetGroup")) >> []() -> group { on(atom("GetGroup")) >> []() -> group {
CPPA_LOGF_INFO("received {'GetGroup'}"); CPPA_PRINT("received {'GetGroup'}");
return group::get("local", "foobar"); return group::get("local", "foobar");
}, },
on(atom("Spawn5"), arg_match) >> [=](const group& grp) -> any_tuple { on(atom("Spawn5"), arg_match) >> [=](const group& grp) -> any_tuple {
CPPA_LOGF_INFO("received {'Spawn5'}"); CPPA_PRINT("received {'Spawn5'}");
actor_vector vec; actor_vector vec;
for (int i = 0; i < 5; ++i) { for (int i = 0; i < 5; ++i) {
vec.push_back(spawn_in_group(grp, reflector)); vec.push_back(spawn_in_group(grp, reflector));
...@@ -131,7 +131,7 @@ void spawn5_client(event_based_actor* self) { ...@@ -131,7 +131,7 @@ void spawn5_client(event_based_actor* self) {
return make_any_tuple(atom("ok"), std::move(vec)); return make_any_tuple(atom("ok"), std::move(vec));
}, },
on(atom("Spawn5Done")) >> [=] { on(atom("Spawn5Done")) >> [=] {
CPPA_LOGF_INFO("received {'Spawn5Done'}"); CPPA_PRINT("received {'Spawn5Done'}");
self->quit(); self->quit();
} }
); );
...@@ -252,10 +252,12 @@ class server : public event_based_actor { ...@@ -252,10 +252,12 @@ class server : public event_based_actor {
on(atom("SpawnPing")) >> [=]() -> any_tuple { on(atom("SpawnPing")) >> [=]() -> any_tuple {
CPPA_PRINT("received {'SpawnPing'}"); CPPA_PRINT("received {'SpawnPing'}");
auto client = last_sender(); auto client = last_sender();
CPPA_LOGF_ERROR_IF(!client, "last_sender() == nullptr"); if (!client) {
CPPA_LOGF_INFO("spawn event-based ping actor"); CPPA_PRINT("last_sender() invalid!");
}
CPPA_PRINT("spawn event-based ping actor");
auto pptr = spawn<monitored>(event_based_ping, num_pings); auto pptr = spawn<monitored>(event_based_ping, num_pings);
CPPA_LOGF_INFO("wait until spawned ping actor is done"); CPPA_PRINT("wait until spawned ping actor is done");
await_down(this, pptr, [=] { await_down(this, pptr, [=] {
CPPA_CHECK_EQUAL(pongs(), num_pings); CPPA_CHECK_EQUAL(pongs(), num_pings);
await_sync_msg(); await_sync_msg();
...@@ -331,11 +333,11 @@ int main(int argc, char** argv) { ...@@ -331,11 +333,11 @@ int main(int argc, char** argv) {
bool run_as_server = false; bool run_as_server = false;
if (argc > 1) { if (argc > 1) {
if (strcmp(argv[1], "run_remote_actor=false") == 0) { if (strcmp(argv[1], "run_remote_actor=false") == 0) {
CPPA_LOGF_INFO("don't run remote actor"); CPPA_PRINT("don't run remote actor");
run_remote_actor = false; run_remote_actor = false;
} }
else if (strcmp(argv[1], "run_as_server") == 0) { else if (strcmp(argv[1], "run_as_server") == 0) {
CPPA_LOGF_INFO("don't run remote actor"); CPPA_PRINT("don't run remote actor");
run_remote_actor = false; run_remote_actor = false;
run_as_server = true; run_as_server = true;
} }
......
...@@ -343,7 +343,7 @@ struct slave : event_based_actor { ...@@ -343,7 +343,7 @@ struct slave : event_based_actor {
void test_serial_reply() { void test_serial_reply() {
auto mirror_behavior = [=](event_based_actor* self) { auto mirror_behavior = [=](event_based_actor* self) {
self->become(others() >> [=]() -> any_tuple { self->become(others() >> [=]() -> any_tuple {
CPPA_LOGF_INFO("return self->last_dequeued()"); CPPA_PRINT("return self->last_dequeued()");
return self->last_dequeued(); return self->last_dequeued();
}); });
}; };
...@@ -357,22 +357,22 @@ void test_serial_reply() { ...@@ -357,22 +357,22 @@ void test_serial_reply() {
auto c4 = self->spawn<linked>(mirror_behavior); auto c4 = self->spawn<linked>(mirror_behavior);
self->become ( self->become (
on(atom("hi there")) >> [=]() -> continue_helper { on(atom("hi there")) >> [=]() -> continue_helper {
CPPA_LOGF_INFO("received 'hi there'"); CPPA_PRINT("received 'hi there'");
return self->sync_send(c0, atom("sub0")).then( return self->sync_send(c0, atom("sub0")).then(
on(atom("sub0")) >> [=]() -> continue_helper { on(atom("sub0")) >> [=]() -> continue_helper {
CPPA_LOGF_INFO("received 'sub0'"); CPPA_PRINT("received 'sub0'");
return self->sync_send(c1, atom("sub1")).then( return self->sync_send(c1, atom("sub1")).then(
on(atom("sub1")) >> [=]() -> continue_helper { on(atom("sub1")) >> [=]() -> continue_helper {
CPPA_LOGF_INFO("received 'sub1'"); CPPA_PRINT("received 'sub1'");
return self->sync_send(c2, atom("sub2")).then( return self->sync_send(c2, atom("sub2")).then(
on(atom("sub2")) >> [=]() -> continue_helper { on(atom("sub2")) >> [=]() -> continue_helper {
CPPA_LOGF_INFO("received 'sub2'"); CPPA_PRINT("received 'sub2'");
return self->sync_send(c3, atom("sub3")).then( return self->sync_send(c3, atom("sub3")).then(
on(atom("sub3")) >> [=]() -> continue_helper { on(atom("sub3")) >> [=]() -> continue_helper {
CPPA_LOGF_INFO("received 'sub3'"); CPPA_PRINT("received 'sub3'");
return self->sync_send(c4, atom("sub4")).then( return self->sync_send(c4, atom("sub4")).then(
on(atom("sub4")) >> [=]() -> atom_value { on(atom("sub4")) >> [=]() -> atom_value {
CPPA_LOGF_INFO("received 'sub4'"); CPPA_PRINT("received 'sub4'");
return atom("hiho"); return atom("hiho");
} }
); );
...@@ -426,13 +426,13 @@ void test_or_else() { ...@@ -426,13 +426,13 @@ void test_or_else() {
self->await_all_other_actors_done(); self->await_all_other_actors_done();
}); });
CPPA_LOGF_INFO("run_testee: handle_a.or_else(handle_b).or_else(handle_c)"); CPPA_PRINT("run_testee: handle_a.or_else(handle_b).or_else(handle_c)");
run_testee( run_testee(
spawn([=] { spawn([=] {
return handle_a.or_else(handle_b).or_else(handle_c); return handle_a.or_else(handle_b).or_else(handle_c);
}) })
); );
CPPA_LOGF_INFO("run_testee: handle_a.or_else(handle_b), on(\"c\") ..."); CPPA_PRINT("run_testee: handle_a.or_else(handle_b), on(\"c\") ...");
run_testee( run_testee(
spawn([=] { spawn([=] {
return ( return (
...@@ -441,7 +441,7 @@ void test_or_else() { ...@@ -441,7 +441,7 @@ void test_or_else() {
); );
}) })
); );
CPPA_LOGF_INFO("run_testee: on(\"a\") ..., handle_b.or_else(handle_c)"); CPPA_PRINT("run_testee: on(\"a\") ..., handle_b.or_else(handle_c)");
run_testee( run_testee(
spawn([=] { spawn([=] {
return ( return (
...@@ -832,7 +832,7 @@ void test_spawn() { ...@@ -832,7 +832,7 @@ void test_spawn() {
// create some actors linked to one single actor // create some actors linked to one single actor
// and kill them all through killing the link // and kill them all through killing the link
auto legion = spawn([](event_based_actor* self) { auto legion = spawn([](event_based_actor* self) {
CPPA_LOGF_INFO("spawn 1, 000 actors"); CPPA_PRINT("spawn 1, 000 actors");
for (int i = 0; i < 1000; ++i) { for (int i = 0; i < 1000; ++i) {
self->spawn<event_testee, linked>(); self->spawn<event_testee, linked>();
} }
......
...@@ -86,7 +86,7 @@ int main(int argc, char** argv) { ...@@ -86,7 +86,7 @@ int main(int argc, char** argv) {
auto run_remote_actor = true; auto run_remote_actor = true;
if (argc > 1) { if (argc > 1) {
if (strcmp(argv[1], "run_remote_actor=false") == 0) { if (strcmp(argv[1], "run_remote_actor=false") == 0) {
CPPA_LOGF_INFO("don't run remote actor"); CPPA_PRINT("don't run remote actor");
run_remote_actor = false; run_remote_actor = false;
} }
else { else {
......
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