Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Alchemy Viewer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Silent mode is enabled
All outbound communications are blocked.
Learn more
.
Show more breadcrumbs
Alchemy Viewer
Alchemy Viewer
Commits
4bfd84d3
Commit
4bfd84d3
authored
13 years ago
by
Nat Goodspeed
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for child-process args management and for kill() method.
parent
2ae9f921
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
indra/llcommon/tests/llprocesslauncher_test.cpp
+79
-1
79 additions, 1 deletion
indra/llcommon/tests/llprocesslauncher_test.cpp
with
79 additions
and
1 deletion
indra/llcommon/tests/llprocesslauncher_test.cpp
+
79
−
1
View file @
4bfd84d3
...
@@ -23,6 +23,8 @@
...
@@ -23,6 +23,8 @@
#include
"apr_thread_proc.h"
#include
"apr_thread_proc.h"
#include
<boost/foreach.hpp>
#include
<boost/foreach.hpp>
#include
<boost/function.hpp>
#include
<boost/function.hpp>
#include
<boost/algorithm/string/find_iterator.hpp>
#include
<boost/algorithm/string/finder.hpp>
//#include <boost/lambda/lambda.hpp>
//#include <boost/lambda/lambda.hpp>
//#include <boost/lambda/bind.hpp>
//#include <boost/lambda/bind.hpp>
// other Linden headers
// other Linden headers
...
@@ -513,7 +515,7 @@ namespace tut
...
@@ -513,7 +515,7 @@ namespace tut
set_test_name
(
"setWorkingDirectory()"
);
set_test_name
(
"setWorkingDirectory()"
);
// We want to test setWorkingDirectory(). But what directory is
// We want to test setWorkingDirectory(). But what directory is
// guaranteed to exist on every machine, under every OS? Have to
// guaranteed to exist on every machine, under every OS? Have to
// create one.
// create one.
Naturally, ensure we clean it up when done.
NamedTempDir
tempdir
;
NamedTempDir
tempdir
;
PythonProcessLauncher
py
(
"getcwd()"
,
PythonProcessLauncher
py
(
"getcwd()"
,
"import os, sys
\n
"
"import os, sys
\n
"
...
@@ -523,4 +525,80 @@ namespace tut
...
@@ -523,4 +525,80 @@ namespace tut
py
.
mPy
.
setWorkingDirectory
(
tempdir
.
getName
());
py
.
mPy
.
setWorkingDirectory
(
tempdir
.
getName
());
ensure_equals
(
"os.getcwd()"
,
py
.
run_read
(),
tempdir
.
getName
());
ensure_equals
(
"os.getcwd()"
,
py
.
run_read
(),
tempdir
.
getName
());
}
}
template
<
>
template
<
>
void
object
::
test
<
4
>
()
{
set_test_name
(
"clearArguments()"
);
PythonProcessLauncher
py
(
"args"
,
"import sys
\n
"
// note nonstandard output-file arg!
"with open(sys.argv[3], 'w') as f:
\n
"
" for arg in sys.argv[1:]:
\n
"
" print >>f, arg
\n
"
);
// We expect that PythonProcessLauncher has already called
// addArgument() with the name of its own NamedTempFile. But let's
// change it up.
py
.
mPy
.
clearArguments
();
// re-add script pathname
py
.
mPy
.
addArgument
(
py
.
mScript
.
getName
());
// sys.argv[0]
py
.
mPy
.
addArgument
(
"first arg"
);
// sys.argv[1]
py
.
mPy
.
addArgument
(
"second arg"
);
// sys.argv[2]
// run_read() calls addArgument() one more time, hence [3]
std
::
string
output
(
py
.
run_read
());
boost
::
split_iterator
<
std
::
string
::
const_iterator
>
li
(
output
,
boost
::
first_finder
(
"
\n
"
)),
lend
;
ensure
(
"didn't get first arg"
,
li
!=
lend
);
std
::
string
arg
(
li
->
begin
(),
li
->
end
());
ensure_equals
(
arg
,
"first arg"
);
++
li
;
ensure
(
"didn't get second arg"
,
li
!=
lend
);
arg
.
assign
(
li
->
begin
(),
li
->
end
());
ensure_equals
(
arg
,
"second arg"
);
++
li
;
ensure
(
"didn't get output filename?!"
,
li
!=
lend
);
arg
.
assign
(
li
->
begin
(),
li
->
end
());
ensure
(
"output filename empty?!"
,
!
arg
.
empty
());
++
li
;
ensure
(
"too many args"
,
li
==
lend
);
}
template
<
>
template
<
>
void
object
::
test
<
5
>
()
{
set_test_name
(
"kill()"
);
PythonProcessLauncher
py
(
"kill()"
,
"import sys, time
\n
"
"with open(sys.argv[1], 'w') as f:
\n
"
" f.write('ok')
\n
"
"# now sleep; expect caller to kill
\n
"
"time.sleep(120)
\n
"
"# if caller hasn't managed to kill by now, bad
\n
"
"with open(sys.argv[1], 'w') as f:
\n
"
" f.write('bad')
\n
"
);
NamedTempFile
out
(
"out"
,
"not started"
);
py
.
mPy
.
addArgument
(
out
.
getName
());
ensure_equals
(
"couldn't launch kill() script"
,
py
.
mPy
.
launch
(),
0
);
// Wait for the script to wake up and do its first write
int
i
=
0
,
timeout
=
60
;
for
(
;
i
<
timeout
;
++
i
)
{
sleep
(
1
);
if
(
readfile
(
out
.
getName
(),
"from kill() script"
)
==
"ok"
)
break
;
}
// If we broke this loop because of the counter, something's wrong
ensure
(
"script never started"
,
i
<
timeout
);
// script has performed its first write and should now be sleeping.
py
.
mPy
.
kill
();
// wait for the script to terminate... one way or another.
while
(
py
.
mPy
.
isRunning
())
{
sleep
(
1
);
}
// If kill() failed, the script would have woken up on its own and
// overwritten the file with 'bad'. But if kill() succeeded, it should
// not have had that chance.
ensure_equals
(
"kill() script output"
,
readfile
(
out
.
getName
()),
"ok"
);
}
}
// namespace tut
}
// namespace tut
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment