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
82917ea4
Commit
82917ea4
authored
Jan 07, 2015
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Print output of child process in unit tests
parent
c44db8a4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
16 deletions
+43
-16
unit_testing/test.cpp
unit_testing/test.cpp
+14
-6
unit_testing/test.hpp
unit_testing/test.hpp
+3
-3
unit_testing/test_broker.cpp
unit_testing/test_broker.cpp
+8
-1
unit_testing/test_remote_actor.cpp
unit_testing/test_remote_actor.cpp
+9
-3
unit_testing/test_typed_remote_actor.cpp
unit_testing/test_typed_remote_actor.cpp
+9
-3
No files found.
unit_testing/test.cpp
View file @
82917ea4
...
...
@@ -74,7 +74,7 @@ void set_default_test_settings() {
cout
.
unsetf
(
ios_base
::
unitbuf
);
}
std
::
thread
run_program_impl
(
const
char
*
cpath
,
std
::
vector
<
std
::
string
>
args
)
{
std
::
thread
run_program_impl
(
actor
rc
,
const
char
*
cpath
,
vector
<
string
>
args
)
{
string
path
=
cpath
;
replace_all
(
path
,
"'"
,
"
\\
'"
);
ostringstream
oss
;
...
...
@@ -82,12 +82,20 @@ std::thread run_program_impl(const char* cpath, std::vector<std::string> args) {
for
(
auto
&
arg
:
args
)
{
oss
<<
" "
<<
arg
;
}
oss
<<
to_dev_null
;
oss
<<
" 2>&1"
;
string
cmdstr
=
oss
.
str
();
return
thread
([
cmdstr
]
{
if
(
system
(
cmdstr
.
c_str
())
!=
0
)
{
CAF_PRINTERR
(
"FATAL: command line failed: "
<<
cmdstr
);
abort
();
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
View file @
82917ea4
...
...
@@ -205,7 +205,7 @@ caf::optional<T> spro(const std::string& str) {
return
caf
::
none
;
}
std
::
thread
run_program_impl
(
c
onst
char
*
path
,
std
::
vector
<
std
::
string
>
args
);
std
::
thread
run_program_impl
(
c
af
::
actor
,
const
char
*
,
std
::
vector
<
std
::
string
>
);
template
<
class
T
>
typename
std
::
enable_if
<
...
...
@@ -221,9 +221,9 @@ inline std::string convert_to_str(std::string value) {
}
template
<
class
...
Ts
>
std
::
thread
run_program
(
const
char
*
path
,
Ts
&&
...
args
)
{
std
::
thread
run_program
(
c
af
::
actor
listener
,
c
onst
char
*
path
,
Ts
&&
...
args
)
{
std
::
vector
<
std
::
string
>
vec
{
convert_to_str
(
std
::
forward
<
Ts
>
(
args
))...};
return
run_program_impl
(
path
,
std
::
move
(
vec
));
return
run_program_impl
(
listener
,
path
,
std
::
move
(
vec
));
}
#endif // TEST_HPP
unit_testing/test_broker.cpp
View file @
82917ea4
...
...
@@ -153,12 +153,19 @@ void run_server(bool spawn_client, const char* bin_path) {
CAF_CHECKPOINT
();
cout
<<
"server is running on port "
<<
port
<<
endl
;
if
(
spawn_client
)
{
auto
child
=
run_program
(
bin_path
,
"-c"
,
port
);
auto
child
=
run_program
(
self
,
bin_path
,
"-c"
,
port
);
CAF_CHECKPOINT
();
child
.
join
();
}
}
);
self
->
await_all_other_actors_done
();
self
->
receive
(
[](
const
std
::
string
&
output
)
{
cout
<<
endl
<<
endl
<<
"*** output of client program ***"
<<
endl
<<
output
<<
endl
;
}
);
}
int
main
(
int
argc
,
char
**
argv
)
{
...
...
unit_testing/test_remote_actor.cpp
View file @
82917ea4
...
...
@@ -348,7 +348,7 @@ void test_remote_actor(const char* app_path, bool run_remote_actor) {
CAF_CHECK
(
serv
==
serv2
);
thread
child
;
if
(
run_remote_actor
)
{
child
=
run_program
(
app_path
,
"-c"
,
port2
,
port1
,
gport
);
child
=
run_program
(
self
,
app_path
,
"-c"
,
port2
,
port1
,
gport
);
}
else
{
CAF_PRINT
(
"please run client with: "
<<
"-c "
<<
port2
<<
" "
<<
port1
<<
" "
<<
gport
);
...
...
@@ -362,11 +362,17 @@ void test_remote_actor(const char* app_path, bool run_remote_actor) {
);
// wait until separate process (in sep. thread) finished execution
CAF_CHECKPOINT
();
self
->
await_all_other_actors_done
();
CAF_CHECKPOINT
();
if
(
run_remote_actor
)
{
child
.
join
();
self
->
receive
(
[](
const
std
::
string
&
output
)
{
cout
<<
endl
<<
endl
<<
"*** output of client program ***"
<<
endl
<<
output
<<
endl
;
}
);
}
CAF_CHECKPOINT
();
self
->
await_all_other_actors_done
();
}
}
// namespace <anonymous>
...
...
unit_testing/test_typed_remote_actor.cpp
View file @
82917ea4
...
...
@@ -91,13 +91,19 @@ int main(int argc, char** argv) {
CAF_CHECKPOINT
();
// execute client_part() in a separate process,
// connected via localhost socket
auto
child
=
run_program
(
argv
[
0
],
"-c"
,
port
);
scoped_actor
self
;
auto
child
=
run_program
(
self
,
argv
[
0
],
"-c"
,
port
);
CAF_CHECKPOINT
();
child
.
join
();
self
->
await_all_other_actors_done
();
self
->
receive
(
[](
const
std
::
string
&
output
)
{
cout
<<
endl
<<
endl
<<
"*** output of client program ***"
<<
endl
<<
output
<<
endl
;
}
);
}
});
CAF_CHECKPOINT
();
await_all_actors_done
();
shutdown
();
return
CAF_TEST_RESULT
();
}
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