Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ufebl
mjtest
Commits
b8fdbb2b
Commit
b8fdbb2b
authored
Nov 29, 2016
by
Johannes Bechberger
Browse files
Improve infinite loop test cases runner
parent
b8bd79dd
Changes
1
Hide whitespace changes
Inline
Side-by-side
mjtest/test/exec_tests.py
View file @
b8fdbb2b
...
...
@@ -17,8 +17,8 @@ class JavaExecTest(BasicSyntaxTest):
The MiniJava compiler should behave the same as javac
"""
FILE_ENDINGS
=
[
".java"
]
INVALID_FILE_ENDINGS
=
[
".inf.java"
]
FILE_ENDINGS
=
[
".java"
,
".mj"
]
INVALID_FILE_ENDINGS
=
[
".inf.java"
,
".inf.mj"
]
OUTPUT_FILE_ENDING
=
".out"
MODE
=
TestMode
.
compile_firm
...
...
@@ -96,11 +96,14 @@ TestCase.TEST_CASE_CLASSES[TestMode.compile_firm].append(JavaExecTest)
class
JavaInfiniteLoopTest
(
BasicSyntaxTest
):
FILE_ENDINGS
=
[
".inf.java"
]
FILE_ENDINGS
=
[
".inf.java"
,
".inf.mj"
]
OUTPUT_FILE_ENDING
=
".out"
MODE
=
TestMode
.
compile_firm
def
__init__
(
self
,
env
:
Environment
,
type
:
str
,
file
:
str
,
preprocessed_file
:
str
):
super
().
__init__
(
env
,
type
,
file
,
preprocessed_file
)
self
.
_output_file
=
self
.
file
+
self
.
OUTPUT_FILE_ENDING
self
.
_has_output_file
=
path
.
exists
(
self
.
_output_file
)
def
run
(
self
)
->
BasicTestResult
:
base_filename
=
path
.
basename
(
self
.
file
).
split
(
"."
)[
0
]
...
...
@@ -109,20 +112,31 @@ class JavaInfiniteLoopTest(BasicSyntaxTest):
cwd
=
os
.
getcwd
()
os
.
chdir
(
tmp_dir
)
timeout
=
1
err
=
""
out
=
""
out2
=
""
try
:
_
,
err
,
rtcode
=
self
.
env
.
run_mj_command
(
self
.
MODE
,
base_filename
+
".java"
)
out2
,
err
,
rtcode
=
self
.
env
.
run_mj_command
(
self
.
MODE
,
base_filename
+
".java"
)
out
,
_
,
_
=
self
.
env
.
run_command
(
"./"
+
base_filename
,
timeout
=
timeout
)
except
SigKill
as
kill
:
os
.
chdir
(
cwd
)
if
kill
.
retcode
==
signal
.
SIGXCPU
:
return
BasicTestResult
(
self
,
err
.
decode
(),
0
,
out
.
decode
())
if
self
.
_has_output_file
:
out
=
out
.
decode
().
strip
()
exp_out
=
""
with
open
(
self
.
_output_file
,
"r"
)
as
f
:
exp_out
=
f
.
read
().
strip
()
if
not
out
.
startswith
(
exp_out
):
return
BasicDiffTestResult
(
self
,
1
,
out
,
err
.
decode
(),
exp_out
,
"Output doesn't start like expected"
)
return
BasicTestResult
(
self
,
0
,
err
.
decode
(),
out
.
decode
())
else
:
return
BasicTestResult
(
self
,
kill
.
retcode
,
""
,
""
,
"No timeout, got "
+
kill
.
name
)
return
BasicTestResult
(
self
,
kill
.
retcode
,
""
,
err
.
decode
()
,
"No timeout, got "
+
kill
.
name
)
except
:
os
.
chdir
(
cwd
)
raise
os
.
chdir
(
cwd
)
return
BasicTestResult
(
self
,
1
,
""
,
""
,
"No timeout"
)
return
BasicTestResult
(
self
,
1
,
""
,
err
.
decode
()
,
"No timeout"
)
TestCase
.
TEST_CASE_CLASSES
[
TestMode
.
compile_firm
].
append
(
JavaInfiniteLoopTest
)
\ No newline at end of file
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