Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions autotest-tw-solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
exhibited bugs.

Optional argument:
--full run test on all graphs with min-degree 3 and at most 8 vertices

++full run test on all graphs with min-degree 3 and at most 8 vertices
++ any number of arguments that get passed on to the treewidth solver
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the interface now like this? ./autotest-tw-solver.py mysolver ++--twsolveroption1
Maybe a nicer interface would be: ./autotest-tw-solver.py [--full] <solver> [arguments for solver] so that solver arguments can be given as-is, without having to prepend ++.


Requires python3-networkx

Copyright 2016, Holger Dell
Expand Down Expand Up @@ -82,6 +83,7 @@ def test_case_generator(full=False):


tw_executable = ""
tw_executable_args = []
FNULL = open(os.devnull, "w")


Expand All @@ -106,12 +108,15 @@ def run_one_testcase(arg):
"""given the name of a testcase, the input stream for a .gr file, and the
correct treewidth, this function runs the test"""

global tw_executable
global tw_executable, tw_executable_args
name, ifstream, treewidth = arg

with tempfile.TemporaryFile("w+") as tmp_td:
executable = [tw_executable]
for arg in tw_executable_args:
executable.append(arg)
p = subprocess.Popen(
[tw_executable], stdin=ifstream, stdout=tmp_td, stderr=FNULL
executable, stdin=ifstream, stdout=tmp_td, stderr=FNULL
)

try:
Expand Down Expand Up @@ -155,26 +160,35 @@ def run_one_testcase(arg):

def main():
parser = argparse.ArgumentParser(
description="Automatically test a given treewidth solver"
description="Automatically test a given treewidth solver",
prefix_chars='+'
)
parser.add_argument(
"twsolver", help="path to the treewidth solver you want to test"
)
parser.add_argument(
"--full",
"++full",
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why switch to ++?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this somehow standard for testing frameworks?

help="run test on all 2753 graphs with min-degree 3 and at most 8 vertices (this could take a while)",
action="store_true",
)
parser.add_argument(
"++",
dest="solver_args",
nargs="*",
default=[],
help="arguments for the tw-solver executable",
)

args = parser.parse_args()

global tw_executable
global tw_executable, tw_executable_args
tw_executable = args.twsolver
tw_executable_args = args.solver_args

f = "./td-validate"
if not os.path.isfile(f):
print("File {:s} not found. Run 'make' first!\n".format(f))
return
exit(255)

print("Automatically testing {:s}...\n".format(tw_executable))

Expand All @@ -190,14 +204,19 @@ def main():
total_nonoptimal += 1

print()
exit_code = 0
if total == total_valid:
print("Produced a valid .td on all {:d} instances.".format(total))
else:
print("{:d} out of {:d} tests produced a valid .td".format(total_valid, total))
exit_code = 2
if total_nonoptimal == 0:
print("All tree decompositions were optimal")
else:
print("{:d} tree decompositions were not optimal".format(total_nonoptimal))
if exit_code == 0:
Copy link
Copy Markdown
Owner

@holgerdell holgerdell Mar 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not exit directly without setting an exit_code variable?

exit_code = 1
exit(exit_code)


if __name__ == "__main__":
Expand Down