Commit a86ae7a4 authored by neverlord's avatar neverlord

unit tests update

parent a1dd3460
...@@ -53,8 +53,6 @@ unit_testing/test__queue_performance.cpp ...@@ -53,8 +53,6 @@ unit_testing/test__queue_performance.cpp
cppa/util/single_reader_queue.hpp cppa/util/single_reader_queue.hpp
cppa/util/singly_linked_list.hpp cppa/util/singly_linked_list.hpp
unit_testing/test__local_group.cpp unit_testing/test__local_group.cpp
unit_testing/hash_of.cpp
unit_testing/hash_of.hpp
cppa/detail/channel.hpp cppa/detail/channel.hpp
cppa/local_actor.hpp cppa/local_actor.hpp
cppa/channel.hpp cppa/channel.hpp
......
...@@ -209,12 +209,14 @@ auto abstract_scheduled_actor::dq(queue_node_ptr& node, ...@@ -209,12 +209,14 @@ auto abstract_scheduled_actor::dq(queue_node_ptr& node,
} }
else else
{ {
/*
std::string err_msg = "unhandled message in actor "; std::string err_msg = "unhandled message in actor ";
err_msg += std::to_string(id()); err_msg += std::to_string(id());
err_msg += ": "; err_msg += ": ";
err_msg += to_string(node->msg); err_msg += to_string(node->msg);
err_msg += "\n"; err_msg += "\n";
cout << err_msg; cout << err_msg;
*/
buffer.push_back(node.release()); buffer.push_back(node.release());
return dq_indeterminate; return dq_indeterminate;
} }
......
...@@ -3,8 +3,7 @@ ACLOCAL_AMFLAGS = -I ../m4 ...@@ -3,8 +3,7 @@ ACLOCAL_AMFLAGS = -I ../m4
noinst_PROGRAMS = unit_tests noinst_PROGRAMS = unit_tests
unit_tests_SOURCES = hash_of.cpp \ unit_tests_SOURCES = main.cpp \
main.cpp \
ping_pong.cpp \ ping_pong.cpp \
test__atom.cpp \ test__atom.cpp \
test__intrusive_ptr.cpp \ test__intrusive_ptr.cpp \
......
#include <cstring>
#include "hash_of.hpp"
unsigned int MurmurHash2 ( const void * key, int len, unsigned int seed )
{
static_assert(sizeof(int) == 4,
"MurmurHash2 requires sizeof(int) == 4");
// 'm' and 'r' are mixing constants generated offline.
// They're not really 'magic', they just happen to work well.
const unsigned int m = 0x5bd1e995;
const int r = 24;
// Initialize the hash to a 'random' value
unsigned int h = seed ^ len;
// Mix 4 bytes at a time into the hash
const unsigned char * data = (const unsigned char *)key;
while(len >= 4)
{
unsigned int k = *(unsigned int *)data;
k *= m;
k ^= k >> r;
k *= m;
h *= m;
h ^= k;
data += 4;
len -= 4;
}
// Handle the last few bytes of the input array
switch(len)
{
case 3: h ^= data[2] << 16;
case 2: h ^= data[1] << 8;
case 1: h ^= data[0];
h *= m;
};
// Do a few final mixes of the hash to ensure the last few
// bytes are well-incorporated.
h ^= h >> 13;
h *= m;
h ^= h >> 15;
return h;
}
unsigned int hash_of(const char* what, int what_length)
{
return MurmurHash2(what, what_length, 0x15091984);
}
unsigned int hash_of(const std::string& what)
{
return MurmurHash2(what.c_str(), what.size(), 0x15091984);
}
#ifndef HASH_OF_HPP
#define HASH_OF_HPP
#include <string>
unsigned int hash_of(const std::string& what);
unsigned int hash_of(const char* what, int what_length);
#endif // HASH_OF_HPP
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include <iostream> #include <iostream>
#include "test.hpp" #include "test.hpp"
#include "hash_of.hpp"
#include "cppa/tuple.hpp" #include "cppa/tuple.hpp"
#include "cppa/config.hpp" #include "cppa/config.hpp"
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
#include <iostream> #include <iostream>
#include "test.hpp" #include "test.hpp"
#include "hash_of.hpp"
#include "cppa/util.hpp" #include "cppa/util.hpp"
#include "cppa/cppa.hpp" #include "cppa/cppa.hpp"
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <algorithm> #include <algorithm>
#include "test.hpp" #include "test.hpp"
#include "hash_of.hpp"
#include "cppa/on.hpp" #include "cppa/on.hpp"
#include "cppa/self.hpp" #include "cppa/self.hpp"
......
...@@ -331,7 +331,6 @@ size_t test__spawn() ...@@ -331,7 +331,6 @@ size_t test__spawn()
CPPA_TEST(test__spawn); CPPA_TEST(test__spawn);
spawn(testee1); spawn(testee1);
return 0;
spawn(event_testee2()); spawn(event_testee2());
auto cstk = spawn(new chopstick); auto cstk = spawn(new chopstick);
...@@ -352,18 +351,13 @@ size_t test__spawn() ...@@ -352,18 +351,13 @@ size_t test__spawn()
// create 20,000 actors linked to one single actor // create 20,000 actors linked to one single actor
// and kill them all through killing the link // and kill them all through killing the link
// auto my_link = spawn(new event_testee); auto my_link = spawn(new event_testee);
// for (int i = 0; i < 20000; ++i) for (int i = 0; i < 20000; ++i)
// { {
// link(my_link, spawn(new event_testee)); link(my_link, spawn(new event_testee));
// } }
// send(my_link, atom(":Exit"), exit_reason::user_defined); send(my_link, atom(":Exit"), exit_reason::user_defined);
return CPPA_TEST_RESULT; await_all_others_done();
auto report_unexpected = [&]() auto report_unexpected = [&]()
{ {
...@@ -375,12 +369,11 @@ size_t test__spawn() ...@@ -375,12 +369,11 @@ size_t test__spawn()
auto pong_actor = spawn(pong, spawn(ping)); auto pong_actor = spawn(pong, spawn(ping));
monitor(pong_actor); monitor(pong_actor);
self->link_to(pong_actor); self->link_to(pong_actor);
// monitor(spawn(testee2, spawn(testee1)));
int i = 0; int i = 0;
int flags = 0; int flags = 0;
future_send(self, std::chrono::seconds(1), atom("FooBar")); future_send(self, std::chrono::seconds(1), atom("FooBar"));
// wait for :Down and :Exit messages of pong // wait for :Down and :Exit messages of pong
receive_while([&i]() { return ++i <= 3 /*4*/; }) receive_while([&i]() { return ++i <= 3; })
( (
on<atom(":Exit"), std::uint32_t>() >> [&](std::uint32_t reason) on<atom(":Exit"), std::uint32_t>() >> [&](std::uint32_t reason)
{ {
...@@ -411,13 +404,13 @@ size_t test__spawn() ...@@ -411,13 +404,13 @@ size_t test__spawn()
cout << "!!! TIMEOUT !!!" << endl; cout << "!!! TIMEOUT !!!" << endl;
CPPA_CHECK(false); CPPA_CHECK(false);
} }
); );
// wait for termination of all spawned actors // wait for termination of all spawned actors
await_all_others_done(); await_all_others_done();
CPPA_CHECK_EQUAL(flags, 0x07); CPPA_CHECK_EQUAL(flags, 0x07);
// verify pong messages // verify pong messages
CPPA_CHECK_EQUAL(pongs(), 5); CPPA_CHECK_EQUAL(pongs(), 5);
/* /*
spawn(testee3, self); spawn(testee3, self);
i = 0; i = 0;
...@@ -437,7 +430,7 @@ size_t test__spawn() ...@@ -437,7 +430,7 @@ size_t test__spawn()
CPPA_CHECK(false); CPPA_CHECK(false);
} }
); );
await_all_others_done();
*/ */
await_all_others_done();
return CPPA_TEST_RESULT; return CPPA_TEST_RESULT;
} }
...@@ -63,7 +63,7 @@ size_t test__tuple() ...@@ -63,7 +63,7 @@ size_t test__tuple()
CPPA_CHECK_EQUAL(v0_0, "1"); CPPA_CHECK_EQUAL(v0_0, "1");
CPPA_CHECK_EQUAL(get<0>(t0), get<0>(v0)); CPPA_CHECK_EQUAL(get<0>(t0), get<0>(v0));
// check cow semantics // check cow semantics
CPPA_CHECK_EQUAL(&get<0>(t0), &get<0>(v0)); // point to the same string CPPA_CHECK_EQUAL(&get<0>(t0), &get<0>(v0)); // point to the same
get_ref<0>(t0) = "hello world"; // detaches t0 from v0 get_ref<0>(t0) = "hello world"; // detaches t0 from v0
CPPA_CHECK_EQUAL(get<0>(t0), "hello world"); // t0 contains new value CPPA_CHECK_EQUAL(get<0>(t0), "hello world"); // t0 contains new value
CPPA_CHECK_EQUAL(get<0>(v0), "1"); // v0 contains old value CPPA_CHECK_EQUAL(get<0>(v0), "1"); // v0 contains old value
......
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE
#endif
#include <atomic> #include <atomic>
#include <cstring> #include <cstring>
#include <cstdint> #include <cstdint>
#include <type_traits>
#include <ucontext.h>
#include <sys/mman.h>
#include <signal.h>
#include <cstddef>
#include <iostream> #include <iostream>
#include <type_traits>
#include "test.hpp" #include "test.hpp"
#include "cppa/util/fiber.hpp" #include "cppa/util/fiber.hpp"
...@@ -56,19 +46,15 @@ void coroutine(void* worker) ...@@ -56,19 +46,15 @@ void coroutine(void* worker)
size_t test__yield_interface() size_t test__yield_interface()
{ {
CPPA_TEST(test__yield_interface); CPPA_TEST(test__yield_interface);
# ifdef CPPA_DISABLE_CONTEXT_SWITCHING # ifdef CPPA_DISABLE_CONTEXT_SWITCHING
cout << "WARNING: context switching was explicitly disabled using " cout << "WARNING: context switching was explicitly disabled using "
"CPPA_DISABLE_CONTEXT_SWITCHING" "CPPA_DISABLE_CONTEXT_SWITCHING"
<< endl; << endl;
return CPPA_TEST_RESULT;
# else # else
pseudo_worker worker;
fiber fself; fiber fself;
pseudo_worker worker;
fiber fcoroutine(coroutine, &worker); fiber fcoroutine(coroutine, &worker);
yield_state ys; yield_state ys;
int i = 0; int i = 0;
do do
{ {
...@@ -77,11 +63,9 @@ size_t test__yield_interface() ...@@ -77,11 +63,9 @@ size_t test__yield_interface()
++i; ++i;
} }
while (ys != yield_state::done && i < 12); while (ys != yield_state::done && i < 12);
CPPA_CHECK_EQUAL(ys, yield_state::done); CPPA_CHECK_EQUAL(ys, yield_state::done);
CPPA_CHECK_EQUAL(worker.m_count, 10); CPPA_CHECK_EQUAL(worker.m_count, 10);
CPPA_CHECK_EQUAL(i, 12); CPPA_CHECK_EQUAL(i, 12);
return CPPA_TEST_RESULT;
# endif # endif
return CPPA_TEST_RESULT;
} }
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