Skip to content

Commit d8f44dd

Browse files
committed
added simple 'any' tool, use environment variable BENCHEXEC_ANYTOOL_EXE to configure the path to the tool that should be executed
1 parent 249f176 commit d8f44dd

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

benchexec/tools/any.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
"""
2+
BenchExec is a framework for reliable benchmarking.
3+
This file is part of BenchExec.
4+
5+
Copyright (C) 2020 Daniel Dietsch ([email protected])
6+
All rights reserved.
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
"""
20+
import os
21+
22+
import benchexec.result as result
23+
import benchexec.tools.template
24+
import benchexec.util as util
25+
26+
27+
class MissingEnvironmentVariable(benchexec.BenchExecException):
28+
"""
29+
Raised when an environment variable, e.g., BENCHEXEC_ANYTOOL_EXE, is not set.
30+
"""
31+
32+
pass
33+
34+
35+
class Tool(benchexec.tools.template.BaseTool2):
36+
"""
37+
An implementation that can be used for any tool on-the-fly.
38+
You just need to set the environment variable BENCHEXEC_ANYTOOL_EXE to a path to the actual tool and then all
39+
options will be passed to the tool.
40+
41+
The result is RESULT_DONE if the return code is zero, otherwise it is a custom string.
42+
"""
43+
44+
REQUIRED_PATHS = []
45+
46+
def executable(self, tool_locator):
47+
executable = os.environ["BENCHEXEC_ANYTOOL_EXE"]
48+
if executable:
49+
return executable
50+
raise MissingEnvironmentVariable("BENCHEXEC_ANYTOOL_EXE")
51+
52+
def name(self):
53+
return os.environ["BENCHEXEC_ANYTOOL_EXE"]
54+
55+
def cmdline(self, executable, options, task, resource_limits):
56+
return [executable] + options + [*task.input_files]
57+
58+
def determine_result(self, run):
59+
output = run.output
60+
exit_code = run.exit_code
61+
if not output:
62+
if run.was_timeout and not exit_code.signal:
63+
return "Timeout"
64+
if run.was_timeout:
65+
return "Timeout by {}".format(exit_code.signal)
66+
if exit_code.signal:
67+
return "Terminated by {}".format(exit_code.signal)
68+
return result.RESULT_UNKNOWN
69+
last_line = output[-1:][0]
70+
if any(s in last_line for s in ["YES", "TRUE", "Termination successfully shown!"]):
71+
return result.RESULT_TRUE_PROP
72+
elif any(s in last_line for s in ["FALSE","NO"]):
73+
return result.RESULT_FALSE_TERMINATION
74+
else:
75+
return last_line

0 commit comments

Comments
 (0)