Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
uwdkn
mjtest
Commits
62e7ac8e
Commit
62e7ac8e
authored
Dec 02, 2016
by
Johannes Bechberger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #47
parent
3a7be959
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
0 deletions
+31
-0
mjtest/environment.py
mjtest/environment.py
+30
-0
mjtest/test/exec_tests.py
mjtest/test/exec_tests.py
+1
-0
No files found.
mjtest/environment.py
View file @
62e7ac8e
import
logging
import
os
import
random
import
shlex
import
shutil
import
tempfile
from
datetime
import
datetime
import
time
from
threading
import
Timer
from
typing
import
Dict
import
subprocess
from
mjtest.util.shell
import
execute
from
mjtest.util.utils
import
get_mjtest_basedir
,
force_colored_output
import
mjtest.util.utils
...
...
@@ -201,3 +205,29 @@ class Environment:
raise
return
dst_file
def
run_command_till_timeout
(
self
,
cmd
:
str
,
*
args
:
Tuple
[
str
],
timeout
:
float
=
0
)
->
Tuple
[
bytes
,
bytes
,
int
,
bool
]:
"""
Much slower than `run_command` but captures the command output even when a
timeout occurs.
Inspired by http://stackoverflow.com/a/10768774
"""
cmds
=
[
cmd
]
+
list
(
args
)
cmds
=
[
shlex
.
quote
(
c
)
for
c
in
cmds
]
proc
=
subprocess
.
Popen
(
cmds
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
timeouted
=
False
def
kill_proc
(
proc
):
timeouted
=
True
proc
.
kill
()
stdout
,
stderr
=
None
,
None
if
timeout
>=
0.0
:
timer
=
Timer
(
timeout
,
kill_proc
,
[
proc
])
timer
.
start
()
stdout
,
stderr
=
proc
.
communicate
()
timer
.
cancel
()
else
:
stdout
,
stderr
=
proc
.
communicate
()
return
stdout
,
stderr
,
proc
.
returncode
,
timeouted
\ No newline at end of file
mjtest/test/exec_tests.py
View file @
62e7ac8e
...
...
@@ -206,6 +206,7 @@ class JavaInfiniteLoopTest(BasicSyntaxTest):
return
test_result
except
SigKill
as
sig
:
if
sig
.
retcode
==
signal
.
SIGXCPU
:
out
,
_
,
_
,
_
=
self
.
env
.
run_command_till_timeout
(
"./"
+
base_filename
,
timeout
=
1
)
test_result
.
add_long_text
(
"Output"
,
out
.
decode
())
if
self
.
_has_output_file
:
out
=
out
.
decode
().
strip
()
...
...
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