Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
aa9ef7c7
Commit
aa9ef7c7
authored
Apr 23, 2015
by
Marian Triebe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete outdated unit_testing folder
parent
50615664
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
0 additions
and
442 deletions
+0
-442
unit_testing/CMakeLists.txt
unit_testing/CMakeLists.txt
+0
-50
unit_testing/test.cpp
unit_testing/test.cpp
+0
-153
unit_testing/test.hpp
unit_testing/test.hpp
+0
-239
No files found.
unit_testing/CMakeLists.txt
deleted
100644 → 0
View file @
50615664
cmake_minimum_required
(
VERSION 2.8
)
project
(
caf_unit_tests CXX
)
add_custom_target
(
all_unit_tests
)
include_directories
(
${
LIBCAF_INCLUDE_DIRS
}
)
macro
(
add_unit_test name
)
add_executable
(
test_
${
name
}
test_
${
name
}
.cpp test.cpp
${
ARGN
}
)
target_link_libraries
(
test_
${
name
}
${
LD_FLAGS
}
${
LIBCAF_LIBRARIES
}
${
PTHREAD_LIBRARIES
}
)
add_test
(
${
name
}
${
EXECUTABLE_OUTPUT_PATH
}
/test_
${
name
}
)
add_dependencies
(
test_
${
name
}
all_unit_tests
)
endmacro
()
add_unit_test
(
ripemd_160
)
add_unit_test
(
variant
)
add_unit_test
(
atom
)
add_unit_test
(
metaprogramming
)
#add_unit_test(intrusive_containers)
add_unit_test
(
match
)
add_unit_test
(
message
)
add_unit_test
(
serialization
)
add_unit_test
(
uniform_type
)
add_unit_test
(
fixed_vector
)
add_unit_test
(
intrusive_ptr
)
add_unit_test
(
spawn ping_pong.cpp
)
add_unit_test
(
simple_reply_response
)
add_unit_test
(
serial_reply
)
add_unit_test
(
or_else
)
add_unit_test
(
either
)
add_unit_test
(
constructor_attach
)
add_unit_test
(
custom_exception_handler
)
add_unit_test
(
typed_spawn
)
add_unit_test
(
actor_lifetime
)
add_unit_test
(
message_lifetime
)
add_unit_test
(
local_group
)
add_unit_test
(
sync_send
)
add_unit_test
(
broker
)
add_unit_test
(
remote_actor ping_pong.cpp
)
add_unit_test
(
typed_remote_actor
)
add_unit_test
(
unpublish
)
add_unit_test
(
optional
)
add_unit_test
(
fixed_stack_actor
)
add_unit_test
(
actor_pool
)
if
(
NOT WIN32
)
add_unit_test
(
profiled_coordinator
)
endif
()
unit_testing/test.cpp
deleted
100644 → 0
View file @
50615664
#include <mutex>
#include <atomic>
#include <thread>
#include <condition_variable>
#include "test.hpp"
#include "caf/all.hpp"
#include "caf/string_algorithms.hpp"
using
namespace
std
;
using
namespace
caf
;
namespace
{
atomic
<
size_t
>
s_error_count
{
0
};
std
::
mutex
s_stdout_mtx
;
class
watchdog
{
public:
watchdog
()
{
m_thread
=
thread
([
&
]
{
auto
tp
=
chrono
::
high_resolution_clock
::
now
()
+
chrono
::
seconds
(
10
);
std
::
unique_lock
<
mutex
>
guard
{
m_mtx
};
while
(
!
m_canceled
&&
m_cv
.
wait_until
(
guard
,
tp
)
!=
cv_status
::
timeout
)
{
// spin
}
if
(
!
m_canceled
)
{
std
::
lock_guard
<
std
::
mutex
>
io_guard
{
s_stdout_mtx
};
cerr
<<
"WATCHDOG: unit test did finish within 10s, abort"
<<
endl
;
abort
();
}
});
}
~
watchdog
()
{
{
// lifetime scope of guard
std
::
lock_guard
<
std
::
mutex
>
guard
{
m_mtx
};
m_canceled
=
true
;
m_cv
.
notify_all
();
}
m_thread
.
join
();
}
volatile
bool
m_canceled
=
false
;
std
::
mutex
m_mtx
;
std
::
condition_variable
m_cv
;
std
::
thread
m_thread
;
};
watchdog
*
s_watchdog
;
}
// namespace <anonymous>
std
::
mutex
&
caf_stdout_mtx
()
{
return
s_stdout_mtx
;
}
size_t
caf_error_count
()
{
return
s_error_count
;
}
void
caf_inc_error_count
()
{
++
s_error_count
;
}
void
caf_launch_watchdog
()
{
s_watchdog
=
new
watchdog
;
}
void
caf_cancel_watchdog
()
{
delete
s_watchdog
;
}
string
caf_fill4
(
size_t
value
)
{
string
result
=
to_string
(
value
);
while
(
result
.
size
()
<
4
)
result
.
insert
(
result
.
begin
(),
'0'
);
return
result
;
}
const
char
*
caf_strip_path
(
const
char
*
file
)
{
auto
res
=
file
;
auto
i
=
file
;
for
(
char
c
=
*
i
;
c
!=
'\0'
;
c
=
*++
i
)
{
if
(
c
==
'/'
)
{
res
=
i
+
1
;
}
}
return
res
;
}
void
caf_unexpected_message
(
const
char
*
file
,
size_t
line
,
message
t
)
{
CAF_PRINTERRC
(
file
,
line
,
"unexpected message: "
<<
to_string
(
t
));
}
void
caf_unexpected_timeout
(
const
char
*
file
,
size_t
line
)
{
CAF_PRINTERRC
(
file
,
line
,
"unexpected timeout"
);
}
vector
<
string
>
split
(
const
string
&
str
,
char
delim
,
bool
keep_empties
)
{
using
namespace
std
;
vector
<
string
>
result
;
stringstream
strs
{
str
};
string
tmp
;
while
(
getline
(
strs
,
tmp
,
delim
))
{
if
(
!
tmp
.
empty
()
||
keep_empties
)
result
.
push_back
(
move
(
tmp
));
}
return
result
;
}
void
verbose_terminate
()
{
try
{
throw
;
}
catch
(
std
::
exception
&
e
)
{
CAF_PRINTERR
(
"terminate called after throwing "
<<
to_verbose_string
(
e
));
}
catch
(...)
{
CAF_PRINTERR
(
"terminate called after throwing an unknown exception"
);
}
abort
();
}
void
set_default_test_settings
()
{
set_terminate
(
verbose_terminate
);
cout
.
unsetf
(
ios_base
::
unitbuf
);
}
std
::
thread
run_program_impl
(
actor
rc
,
const
char
*
cpath
,
vector
<
string
>
args
)
{
string
path
=
cpath
;
replace_all
(
path
,
"'"
,
"
\\
'"
);
ostringstream
oss
;
oss
<<
"'"
<<
path
<<
"'"
;
for
(
auto
&
arg
:
args
)
{
oss
<<
" "
<<
arg
;
}
oss
<<
" 2>&1"
;
string
cmdstr
=
oss
.
str
();
return
std
::
thread
([
cmdstr
,
rc
]
{
string
output
;
auto
fp
=
popen
(
cmdstr
.
c_str
(),
"r"
);
if
(
!
fp
)
{
CAF_PRINTERR
(
"FATAL: command line failed: "
<<
cmdstr
);
abort
();
}
char
buf
[
512
];
while
(
fgets
(
buf
,
sizeof
(
buf
),
fp
))
{
output
+=
buf
;
}
pclose
(
fp
);
anon_send
(
rc
,
output
);
});
}
unit_testing/test.hpp
deleted
100644 → 0
View file @
50615664
#ifndef TEST_HPP
#define TEST_HPP
#include <mutex>
#include <vector>
#include <string>
#include <thread>
#include <cstring>
#include <cstddef>
#include <sstream>
#include <iostream>
#include <type_traits>
#include "caf/all.hpp"
#include "caf/actor.hpp"
#include "caf/config.hpp"
#include "caf/shutdown.hpp"
#include "caf/to_string.hpp"
#include "caf/detail/logging.hpp"
#include "caf/detail/scope_guard.hpp"
#ifndef CAF_WINDOWS
constexpr
char
to_dev_null
[]
=
" &>/dev/null"
;
#else
constexpr
char
to_dev_null
[]
=
""
;
#endif // CAF_WINDOWS
void
set_default_test_settings
();
std
::
mutex
&
caf_stdout_mtx
();
size_t
caf_error_count
();
void
caf_inc_error_count
();
std
::
string
caf_fill4
(
size_t
value
);
const
char
*
caf_strip_path
(
const
char
*
file
);
void
caf_unexpected_message
(
const
char
*
file
,
size_t
line
,
caf
::
message
t
);
void
caf_unexpected_timeout
(
const
char
*
file
,
size_t
line
);
#define CAF_STREAMIFY(fname, line, message) \
caf_strip_path(fname) << ":" << caf_fill4(line) << " " << message
#define CAF_PRINTC(filename, line, message) \
{ \
std::lock_guard<std::mutex> guard{caf_stdout_mtx()}; \
std::cout << CAF_STREAMIFY(filename, line, message) << std::endl; \
} \
static_cast<void>(0)
#define CAF_PRINT(message) CAF_PRINTC(__FILE__, __LINE__, message)
#define CAF_PRINTERRC(fname, line, msg) \
{ \
std::lock_guard<std::mutex> guard{caf_stdout_mtx()}; \
std::cerr << "ERROR: " << CAF_STREAMIFY(fname, line, msg) << std::endl; \
} \
caf_inc_error_count();
#define CAF_PRINTERR(message) CAF_PRINTERRC(__FILE__, __LINE__, message)
template
<
class
T1
,
typename
T2
>
struct
both_integral
{
static
constexpr
bool
value
=
std
::
is_integral
<
T1
>::
value
&&
std
::
is_integral
<
T2
>::
value
;
};
template
<
bool
V
,
typename
T1
,
typename
T2
>
struct
enable_integral
:
std
::
enable_if
<
both_integral
<
T1
,
T2
>::
value
==
V
&&
not
std
::
is_pointer
<
T1
>::
value
&&
not
std
::
is_pointer
<
T2
>::
value
>
{
};
template
<
class
T
>
const
T
&
caf_stream_arg
(
const
T
&
value
)
{
return
value
;
}
inline
std
::
string
caf_stream_arg
(
const
caf
::
actor
&
ptr
)
{
return
caf
::
to_string
(
ptr
);
}
inline
std
::
string
caf_stream_arg
(
const
caf
::
actor_addr
&
ptr
)
{
return
caf
::
to_string
(
ptr
);
}
inline
std
::
string
caf_stream_arg
(
const
bool
&
value
)
{
return
value
?
"true"
:
"false"
;
}
inline
void
caf_passed
(
const
char
*
fname
,
size_t
line_number
)
{
CAF_PRINTC
(
fname
,
line_number
,
"passed"
);
}
template
<
class
V1
,
typename
V2
>
inline
void
caf_failed
(
const
V1
&
v1
,
const
V2
&
v2
,
const
char
*
fname
,
size_t
line_number
)
{
CAF_PRINTERRC
(
fname
,
line_number
,
"expected value: "
<<
caf_stream_arg
(
v2
)
<<
", found: "
<<
caf_stream_arg
(
v1
));
}
inline
void
caf_check_value
(
const
std
::
string
&
v1
,
const
std
::
string
&
v2
,
const
char
*
fname
,
size_t
line
,
bool
expected
=
true
)
{
if
((
v1
==
v2
)
==
expected
)
{
caf_passed
(
fname
,
line
);
}
else
{
caf_failed
(
v1
,
v2
,
fname
,
line
);
}
}
template
<
class
V1
,
typename
V2
>
inline
void
caf_check_value
(
const
V1
&
v1
,
const
V2
&
v2
,
const
char
*
fname
,
size_t
line
,
bool
expected
=
true
,
typename
enable_integral
<
false
,
V1
,
V2
>::
type
*
=
0
)
{
if
(
caf
::
detail
::
safe_equal
(
v1
,
v2
)
==
expected
)
{
caf_passed
(
fname
,
line
);
}
else
{
caf_failed
(
v1
,
v2
,
fname
,
line
);
}
}
template
<
class
V1
,
typename
V2
>
inline
void
caf_check_value
(
V1
v1
,
V2
v2
,
const
char
*
fname
,
size_t
line
,
bool
expected
=
true
,
typename
enable_integral
<
true
,
V1
,
V2
>::
type
*
=
0
)
{
if
((
v1
==
static_cast
<
V1
>
(
v2
))
==
expected
)
{
caf_passed
(
fname
,
line
);
}
else
{
caf_failed
(
v1
,
v2
,
fname
,
line
);
}
}
#define CAF_VERBOSE_EVAL(LineOfCode) \
CAF_PRINT(#LineOfCode << " = " << (LineOfCode));
void
caf_launch_watchdog
();
void
caf_cancel_watchdog
();
#define CAF_TEST(testname) \
caf_launch_watchdog(); \
set_default_test_settings();
#define CAF_TEST_RESULT() \
caf_cancel_watchdog(), ((caf_error_count() == 0) ? 0 : -1)
#define CAF_CHECK_VERBOSE(line_of_code, err_stream) \
if (!(line_of_code)) { \
std::cerr << err_stream << std::endl; \
caf_inc_error_count(); \
} else { \
CAF_PRINT("passed"); \
} \
((void)0)
#define CAF_CHECK(line_of_code) \
if (!(line_of_code)) { \
CAF_PRINTERR(#line_of_code); \
} else { \
CAF_PRINT("passed"); \
} \
static_cast<void>(0)
#define CAF_CHECK_EQUAL(lhs_loc, rhs_loc) \
caf_check_value((lhs_loc), (rhs_loc), __FILE__, __LINE__)
#define CAF_CHECK_NOT_EQUAL(rhs_loc, lhs_loc) \
caf_check_value((lhs_loc), (rhs_loc), __FILE__, __LINE__, false)
#define CAF_FAILURE(err_msg) \
{ \
CAF_PRINTERR("ERROR: " << err_msg); \
} \
static_cast<void>(0)
#define CAF_CHECKPOINT() CAF_PRINT("passed")
#define CAF_UNEXPECTED_TOUT() caf_unexpected_timeout(__FILE__, __LINE__)
#define CAF_UNEXPECTED_MSG(selfptr) \
caf_unexpected_message(__FILE__, __LINE__, selfptr->current_message())
// some convenience macros for defining callbacks
#define CAF_CHECKPOINT_CB() \
[] { CAF_CHECKPOINT(); }
#define CAF_FAILURE_CB(err_msg) \
[] { CAF_FAILURE(err_msg); }
#define CAF_UNEXPECTED_MSG_CB(selfptr) \
[=] { CAF_UNEXPECTED_MSG(selfptr); }
#define CAF_UNEXPECTED_MSG_CB_REF(selfref) \
[&] { CAF_UNEXPECTED_MSG(selfref); }
#define CAF_UNEXPECTED_TOUT_CB() \
[] { CAF_UNEXPECTED_TOUT(); }
// string projection
template
<
class
T
>
caf
::
optional
<
T
>
spro
(
const
std
::
string
&
str
)
{
T
value
;
std
::
istringstream
iss
(
str
);
if
(
iss
>>
value
)
{
return
value
;
}
return
caf
::
none
;
}
std
::
thread
run_program_impl
(
caf
::
actor
,
const
char
*
,
std
::
vector
<
std
::
string
>
);
template
<
class
T
>
typename
std
::
enable_if
<
std
::
is_arithmetic
<
T
>::
value
,
std
::
string
>::
type
convert_to_str
(
T
value
)
{
return
std
::
to_string
(
value
);
}
inline
std
::
string
convert_to_str
(
std
::
string
value
)
{
return
std
::
move
(
value
);
}
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
));
}
using
ping_atom
=
caf
::
atom_constant
<
caf
::
atom
(
"ping"
)
>
;
using
pong_atom
=
caf
::
atom_constant
<
caf
::
atom
(
"pong"
)
>
;
using
check_atom
=
caf
::
atom_constant
<
caf
::
atom
(
"check"
)
>
;
using
passed_atom
=
caf
::
atom_constant
<
caf
::
atom
(
"passed"
)
>
;
using
kickoff_atom
=
caf
::
atom_constant
<
caf
::
atom
(
"kickoff"
)
>
;
#endif // TEST_HPP
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment