Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
uwdkn
mjtest
Commits
29d891a3
Commit
29d891a3
authored
Dec 17, 2018
by
Andreas Fried
Browse files
Read test input as binary data.
parent
7b4adf13
Changes
4
Hide whitespace changes
Inline
Side-by-side
mjtest/environment.py
View file @
29d891a3
...
...
@@ -180,13 +180,13 @@ class Environment:
cmd
.
extend
(
list
(
args
))
return
execute
(
cmd
,
timeout
=
timeout
or
self
.
timeout
)
def
run_command
(
self
,
cmd
:
str
,
*
args
:
Tuple
[
str
],
timeout
:
float
=
None
,
input_
str
:
Optional
[
str
]
=
None
)
->
Tuple
[
bytes
,
bytes
,
int
]:
def
run_command
(
self
,
cmd
:
str
,
*
args
:
Tuple
[
str
],
timeout
:
float
=
None
,
input_
bytes
:
Optional
[
bytes
]
=
None
)
->
Tuple
[
bytes
,
bytes
,
int
]:
"""
Execute the passend command with its arguments
:return: (out, err, return code)
"""
return
execute
([
cmd
]
+
list
(
args
),
timeout
=
timeout
or
self
.
timeout
,
input_
str
=
input_
str
)
return
execute
([
cmd
]
+
list
(
args
),
timeout
=
timeout
or
self
.
timeout
,
input_
bytes
=
input_
bytes
)
def
has_to_preprocess
(
self
,
file
:
str
)
->
bool
:
return
os
.
path
.
relpath
(
file
,
self
.
test_dir
).
startswith
(
"exec"
)
...
...
@@ -249,4 +249,4 @@ class Environment:
timer
.
cancel
()
else
:
stdout
,
stderr
=
proc
.
communicate
()
return
stdout
,
stderr
,
proc
.
returncode
,
timeouted
\ No newline at end of file
return
stdout
,
stderr
,
proc
.
returncode
,
timeouted
mjtest/test/exec_tests.py
View file @
29d891a3
...
...
@@ -59,24 +59,23 @@ class JavaExecTest(BasicSyntaxTest):
cwd
=
os
.
getcwd
()
os
.
chdir
(
tmp_dir
)
exp_out
=
None
input_
str
=
None
input_
bytes
=
None
#print(base_filename, get_main_class_name(base_filename + ".java"))
test_result
=
ExtensibleTestResult
(
self
)
if
self
.
_has_input_file
:
if
self
.
_has_character_input
:
with
open
(
self
.
_input_file
,
"r
"
,
errors
=
"backslashreplace
"
)
as
f
:
input_
str
=
f
.
read
()
with
open
(
self
.
_input_file
,
"r
b
"
)
as
f
:
input_
bytes
=
f
.
read
()
else
:
with
open
(
self
.
_input_file
,
"r"
,
errors
=
"backslashreplace"
)
as
f
:
char
s
=
bytearray
(
'ascii'
,
'ignore'
)
# type: bytearray
input_byte
s
=
bytearray
(
encoding
=
'ascii'
,
errors
=
'ignore'
)
# type: bytearray
for
line
in
f
.
readlines
():
for
part
in
line
.
split
(
" "
):
part
=
part
.
strip
()
if
len
(
part
)
>
0
:
chars
.
append
(
int
(
part
))
input_str
=
decode
(
chars
)
if
not
self
.
_has_expected_output_file
and
not
self
.
_only_compile
:
_
,
err
,
javac_rtcode
=
\
...
...
@@ -95,7 +94,7 @@ class JavaExecTest(BasicSyntaxTest):
main_class
=
base_filename
if
not
self
.
_only_compile
:
exp_out
,
err
,
java_rtcode
=
\
self
.
env
.
run_command
(
"java"
,
get_main_class_name
(
base_filename
+
".java"
),
timeout
=
timeout
,
input_
str
=
input_
str
)
self
.
env
.
run_command
(
"java"
,
get_main_class_name
(
base_filename
+
".java"
),
timeout
=
timeout
,
input_
bytes
=
input_
bytes
)
if
javac_rtcode
!=
0
:
test_result
.
add_long_text
(
"Java output: "
,
decode
(
exp_out
))
test_result
.
incorrect_msg
=
"java runtime error"
...
...
@@ -146,7 +145,7 @@ class JavaExecTest(BasicSyntaxTest):
test_result
.
add_file
(
"Source file"
,
self
.
preprocessed_file
)
return
test_result
try
:
out
,
err
,
rtcode
=
self
.
env
.
run_command
(
"./a.out"
,
timeout
=
timeout
,
input_
str
=
input_
str
)
out
,
err
,
rtcode
=
self
.
env
.
run_command
(
"./a.out"
,
timeout
=
timeout
,
input_
bytes
=
input_
bytes
)
if
rtcode
!=
0
:
test_result
.
incorrect_msg
=
"binary can't be run, non zero error code"
test_result
.
set_error_code
(
rtcode
)
...
...
mjtest/test/tests.py
View file @
29d891a3
...
...
@@ -582,4 +582,4 @@ import mjtest.test.syntax_tests
import
mjtest.test.ast_tests
import
mjtest.test.semantic_tests
import
mjtest.test.exec_tests
import
mjtest.test.bench
\ No newline at end of file
import
mjtest.test.bench
mjtest/util/shell.py
View file @
29d891a3
...
...
@@ -16,7 +16,7 @@ try:
except
ImportError
:
has_resource_module
=
False
pass
import
sys
import
signal
import
threading
...
...
@@ -46,14 +46,14 @@ def _lower_rlimit(res, limit):
class
_Execute
(
object
):
def
__init__
(
self
,
cmd
,
timeout
,
env
,
rlimit
,
input_
str
):
def
__init__
(
self
,
cmd
,
timeout
,
env
,
rlimit
,
input_
bytes
):
self
.
cmd
=
cmd
self
.
timeout
=
timeout
self
.
env
=
env
self
.
proc
=
None
self
.
exception
=
None
self
.
rlimit
=
rlimit
self
.
input_
str
=
input_
str
self
.
input_
bytes
=
input_
bytes
MB
=
1024
*
1024
if
not
'RLIMIT_CORE'
in
rlimit
:
rlimit
[
'RLIMIT_CORE'
]
=
0
...
...
@@ -80,14 +80,13 @@ class _Execute(object):
self
.
proc
=
subprocess
.
Popen
(
self
.
cmd
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
stdin
=
subprocess
.
PIPE
if
self
.
input_
str
else
None
,
stdin
=
subprocess
.
PIPE
if
self
.
input_
bytes
else
None
,
env
=
self
.
env
,
shell
=
True
,
**
prexec_args
)
#if self.input_str:
# self.proc.stdin.write(self.input_str.decode)
input_bytes
=
self
.
input_str
.
encode
()
if
self
.
input_str
else
None
x
=
self
.
proc
.
communicate
(
input
=
input_bytes
,
timeout
=
self
.
timeout
if
self
.
timeout
>
0.0
else
None
)
#if self.input_bytes:
# self.proc.stdin.write(self.input_bytes.decode)
x
=
self
.
proc
.
communicate
(
input
=
self
.
input_bytes
,
timeout
=
self
.
timeout
if
self
.
timeout
>
0.0
else
None
)
self
.
out
,
self
.
err
=
x
self
.
returncode
=
self
.
proc
.
returncode
except
subprocess
.
TimeoutExpired
as
t
:
...
...
@@ -110,7 +109,7 @@ class _Execute(object):
raise
SigKill
(
-
self
.
returncode
,
_EXIT_CODES
[
self
.
returncode
]
+
": "
+
os
.
strerror
(
-
self
.
returncode
))
return
(
self
.
out
,
self
.
err
,
self
.
returncode
)
def
execute
(
cmd
,
env
=
None
,
timeout
=
0
,
rlimit
=
None
,
propagate_sigint
=
True
,
input_
str
=
None
):
def
execute
(
cmd
,
env
=
None
,
timeout
=
0
,
rlimit
=
None
,
propagate_sigint
=
True
,
input_
bytes
=
None
):
"""Execute a command and return stderr and stdout data"""
if
not
rlimit
:
rlimit
=
dict
()
...
...
@@ -120,7 +119,7 @@ def execute(cmd, env=None, timeout=0, rlimit=None, propagate_sigint=True, input_
else
:
#cmd = shlex.split(cmd[0]) + cmd[1:]
cmd
=
" "
.
join
(
shlex
.
quote
(
c
)
for
c
in
cmd
)
exc
=
_Execute
(
cmd
,
timeout
,
env
,
rlimit
,
input_
str
)
exc
=
_Execute
(
cmd
,
timeout
,
env
,
rlimit
,
input_
bytes
)
(
out
,
err
,
returncode
)
=
exc
.
run
()
if
returncode
==
-
signal
.
SIGINT
:
raise
KeyboardInterrupt
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment