Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
IPDSnelting
mjtest
Commits
949a1de9
Commit
949a1de9
authored
Nov 27, 2016
by
Johannes Bechberger
Browse files
Improve performance by caching java's output
parent
7430f261
Changes
2
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
949a1de9
...
...
@@ -11,3 +11,4 @@ build/
mjtest.egg-info
.preprocessed
.DS_Store
.java_output
\ No newline at end of file
mjtest/test/exec_tests.py
View file @
949a1de9
...
...
@@ -2,7 +2,6 @@ import logging
import
os
import
shutil
from
os
import
path
import
sys
from
mjtest.environment
import
TestMode
,
Environment
from
mjtest.test.syntax_tests
import
BasicSyntaxTest
from
mjtest.test.tests
import
TestCase
,
BasicDiffTestResult
,
BasicTestResult
...
...
@@ -22,7 +21,16 @@ class JavaExecTest(BasicSyntaxTest):
def
__init__
(
self
,
env
:
Environment
,
type
:
str
,
file
:
str
,
preprocessed_file
:
str
):
super
().
__init__
(
env
,
type
,
file
,
preprocessed_file
)
self
.
_expected_output_file
=
file
+
self
.
OUTPUT_FILE_ENDING
prev_out_dir
=
path
.
join
(
path
.
dirname
(
file
),
".java_output"
)
if
not
path
.
exists
(
prev_out_dir
):
os
.
mkdir
(
prev_out_dir
)
self
.
_prev_out_file
=
path
.
join
(
prev_out_dir
,
path
.
basename
(
self
.
_expected_output_file
))
self
.
_has_expected_output_file
=
path
.
exists
(
self
.
_expected_output_file
)
if
not
self
.
_has_expected_output_file
:
if
path
.
exists
(
self
.
_prev_out_file
)
and
self
.
compare_files_by_age
(
file
,
self
.
_prev_out_file
)
==
-
1
:
self
.
_has_expected_output_file
=
True
self
.
_expected_output_file
=
self
.
_prev_out_file
_LOG
.
info
(
"Reuse old java output file
\"
{}
\"
"
.
format
(
path
.
relpath
(
self
.
_prev_out_file
)))
self
.
_should_succeed
=
True
def
run
(
self
)
->
BasicDiffTestResult
:
...
...
@@ -43,6 +51,9 @@ class JavaExecTest(BasicSyntaxTest):
exp_out
,
_
,
_
=
\
self
.
env
.
run_command
(
"java"
,
base_filename
)
exp_out
=
exp_out
.
decode
().
strip
()
with
open
(
self
.
_prev_out_file
,
"w"
)
as
f
:
f
.
write
(
exp_out
)
f
.
flush
()
if
self
.
_has_expected_output_file
and
self
.
type
==
self
.
MODE
and
self
.
env
.
mode
==
self
.
MODE
:
with
open
(
self
.
_expected_output_file
,
"r"
)
as
f
:
exp_out
=
f
.
read
()
...
...
@@ -62,4 +73,18 @@ class JavaExecTest(BasicSyntaxTest):
os
.
chdir
(
cwd
)
raise
def
get_file_time
(
self
,
file
:
str
)
->
float
:
return
max
(
os
.
path
.
getmtime
(
file
),
os
.
path
.
getatime
(
file
))
def
compare_files_by_age
(
self
,
file
:
str
,
other_file
:
str
)
->
int
:
"""
:return: -1 == file is older, 0 == almost equal ages, 1 == other file is older
"""
diff
=
self
.
get_file_time
(
file
)
-
self
.
get_file_time
(
other_file
)
if
diff
<
60
:
return
-
1
if
diff
>
-
60
:
return
1
return
0
TestCase
.
TEST_CASE_CLASSES
[
TestMode
.
comile_firm
].
append
(
JavaExecTest
)
\ No newline at end of file
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