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