-
Notifications
You must be signed in to change notification settings - Fork 6
Allow passing arguments to treewidth solver and use exit codes depending on test results #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
| Requires python3-networkx | ||
|
|
||
| Copyright 2016, Holger Dell | ||
|
|
@@ -82,6 +83,7 @@ def test_case_generator(full=False): | |
|
|
||
|
|
||
| tw_executable = "" | ||
| tw_executable_args = [] | ||
| FNULL = open(os.devnull, "w") | ||
|
|
||
|
|
||
|
|
@@ -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: | ||
|
|
@@ -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", | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why switch to ++?
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)) | ||
|
|
||
|
|
@@ -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: | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not exit directly without setting an |
||
| exit_code = 1 | ||
| exit(exit_code) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
|
|
||
There was a problem hiding this comment.
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 ++--twsolveroption1Maybe 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++.