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
f85d59eb
Commit
f85d59eb
authored
Dec 12, 2014
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix shell escaping in unit tests
parent
7070b868
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
41 deletions
+50
-41
unit_testing/test.cpp
unit_testing/test.cpp
+19
-0
unit_testing/test.hpp
unit_testing/test.hpp
+20
-4
unit_testing/test_broker.cpp
unit_testing/test_broker.cpp
+3
-11
unit_testing/test_remote_actor.cpp
unit_testing/test_remote_actor.cpp
+7
-16
unit_testing/test_typed_remote_actor.cpp
unit_testing/test_typed_remote_actor.cpp
+1
-10
No files found.
unit_testing/test.cpp
View file @
f85d59eb
...
...
@@ -2,6 +2,7 @@
#include "test.hpp"
#include "caf/all.hpp"
#include "caf/string_algorithms.hpp"
using
namespace
std
;
using
namespace
caf
;
...
...
@@ -68,3 +69,21 @@ void set_default_test_settings() {
set_terminate
(
verbose_terminate
);
cout
.
unsetf
(
ios_base
::
unitbuf
);
}
std
::
thread
run_program_impl
(
const
char
*
cpath
,
std
::
vector
<
std
::
string
>
args
)
{
string
path
=
cpath
;
replace_all
(
path
,
"'"
,
"
\\
'"
);
ostringstream
oss
;
oss
<<
"'"
<<
path
<<
"'"
;
for
(
auto
&
arg
:
args
)
{
oss
<<
" "
<<
arg
;
}
oss
<<
to_dev_null
;
string
cmdstr
=
oss
.
str
();
return
thread
{[
cmdstr
]
{
if
(
system
(
cmdstr
.
c_str
())
!=
0
)
{
CAF_PRINTERR
(
"FATAL: command line failed: "
<<
cmdstr
);
abort
();
}
}};
}
unit_testing/test.hpp
View file @
f85d59eb
...
...
@@ -3,6 +3,7 @@
#include <vector>
#include <string>
#include <thread>
#include <cstring>
#include <cstddef>
#include <sstream>
...
...
@@ -199,10 +200,25 @@ caf::optional<T> spro(const std::string& str) {
return
caf
::
none
;
}
std
::
vector
<
std
::
string
>
split
(
const
std
::
string
&
str
,
char
delim
=
' '
,
bool
keep_empties
=
true
);
std
::
thread
run_program_impl
(
const
char
*
path
,
std
::
vector
<
std
::
string
>
args
);
std
::
map
<
std
::
string
,
std
::
string
>
get_kv_pairs
(
int
argc
,
char
**
argv
,
int
begin
=
1
);
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
(
const
char
*
path
,
Ts
&&
...
args
)
{
std
::
vector
<
std
::
string
>
vec
{
convert_to_str
(
std
::
forward
<
Ts
>
(
args
))...};
return
run_program_impl
(
path
,
std
::
move
(
vec
));
}
#endif // TEST_HPP
unit_testing/test_broker.cpp
View file @
f85d59eb
...
...
@@ -24,6 +24,8 @@
#include "caf/all.hpp"
#include "caf/io/all.hpp"
#include "caf/string_algorithms.hpp"
using
namespace
std
;
using
namespace
caf
;
using
namespace
caf
::
io
;
...
...
@@ -157,16 +159,7 @@ void run_server(bool spawn_client, const char* bin_path) {
CAF_CHECKPOINT
();
cout
<<
"server is running on port "
<<
port
<<
endl
;
if
(
spawn_client
)
{
ostringstream
oss
;
oss
<<
bin_path
<<
" -c "
<<
port
<<
to_dev_null
;
thread
child
{[
&
oss
]
{
CAF_LOGC_TRACE
(
"NONE"
,
"main$thread_launcher"
,
""
);
auto
cmdstr
=
oss
.
str
();
if
(
system
(
cmdstr
.
c_str
())
!=
0
)
{
CAF_PRINTERR
(
"FATAL: command failed: "
<<
cmdstr
);
abort
();
}
}};
auto
child
=
run_program
(
bin_path
,
"-c"
,
port
);
CAF_CHECKPOINT
();
child
.
join
();
}
...
...
@@ -189,7 +182,6 @@ int main(int argc, char** argv) {
},
on
()
>>
[
&
]
{
run_server
(
true
,
argv
[
0
]);
},
others
()
>>
[
&
]
{
cerr
<<
"usage: "
<<
argv
[
0
]
<<
" [-c PORT]"
<<
endl
;
...
...
unit_testing/test_remote_actor.cpp
View file @
f85d59eb
...
...
@@ -342,7 +342,7 @@ uint16_t at_some_port(uint16_t first_port, F fun) {
}
}
void
test_remote_actor
(
std
::
string
app_path
,
bool
run_remote_actor
)
{
void
test_remote_actor
(
const
char
*
app_path
,
bool
run_remote_actor
)
{
scoped_actor
self
;
auto
serv
=
self
->
spawn
<
server
,
monitored
>
();
auto
publish_serv
=
[
=
](
uint16_t
p
)
{
...
...
@@ -365,22 +365,11 @@ void test_remote_actor(std::string app_path, bool run_remote_actor) {
CAF_CHECK
(
serv2
!=
invalid_actor
&&
!
serv2
->
is_remote
());
CAF_CHECK
(
serv
==
serv2
);
thread
child
;
ostringstream
oss
;
oss
<<
app_path
<<
" -c "
<<
port
<<
" "
<<
port0
<<
" "
<<
gport
;
if
(
run_remote_actor
)
{
oss
<<
to_dev_null
;
// execute client_part() in a separate process,
// connected via localhost socket
child
=
thread
([
&
oss
]()
{
CAF_LOGC_TRACE
(
"NONE"
,
"main$thread_launcher"
,
""
);
string
cmdstr
=
oss
.
str
();
if
(
system
(
cmdstr
.
c_str
())
!=
0
)
{
CAF_PRINTERR
(
"FATAL: command
\"
"
<<
cmdstr
<<
"
\"
failed!"
);
abort
();
}
});
child
=
run_program
(
app_path
,
"-c"
,
port
,
port0
,
gport
);
}
else
{
CAF_PRINT
(
"please run client: "
<<
oss
.
str
());
CAF_PRINT
(
"please run client with: "
<<
"-c "
<<
port
<<
" "
<<
port0
<<
" "
<<
gport
);
}
CAF_CHECKPOINT
();
self
->
receive
(
...
...
@@ -391,7 +380,9 @@ void test_remote_actor(std::string app_path, bool run_remote_actor) {
);
// wait until separate process (in sep. thread) finished execution
CAF_CHECKPOINT
();
if
(
run_remote_actor
)
child
.
join
();
if
(
run_remote_actor
)
{
child
.
join
();
}
CAF_CHECKPOINT
();
self
->
await_all_other_actors_done
();
}
...
...
unit_testing/test_typed_remote_actor.cpp
View file @
f85d59eb
...
...
@@ -99,18 +99,9 @@ int main(int argc, char** argv) {
on
()
>>
[
&
]
{
auto
port
=
run_server
();
CAF_CHECKPOINT
();
ostringstream
oss
;
oss
<<
argv
[
0
]
<<
" -c "
<<
port
<<
to_dev_null
;
// execute client_part() in a separate process,
// connected via localhost socket
auto
child
=
thread
([
&
oss
]()
{
CAF_LOGC_TRACE
(
"NONE"
,
"main$thread_launcher"
,
""
);
string
cmdstr
=
oss
.
str
();
if
(
system
(
cmdstr
.
c_str
())
!=
0
)
{
CAF_PRINTERR
(
"FATAL: command
\"
"
<<
cmdstr
<<
"
\"
failed!"
);
abort
();
}
});
auto
child
=
run_program
(
argv
[
0
],
"-c"
,
port
);
CAF_CHECKPOINT
();
child
.
join
();
}
...
...
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