summaryrefslogtreecommitdiff
path: root/validation/test/P2P_throughput/P2P_throughput_caller.py
diff options
context:
space:
mode:
authorJean-Philippe NOEL2012-09-26 17:27:39 +0200
committerJean-Philippe NOEL2012-10-05 09:46:07 +0200
commit9ae2acfb608504ef99f3b6d51a0f05e2bdfd95e2 (patch)
tree06715ba1824d953b4810f75ea2e26f8b6dd5ff8c /validation/test/P2P_throughput/P2P_throughput_caller.py
parentd722b5ecb56f3a4e28b0db91a640eaa858c1a3cc (diff)
validation: shorten the names of the P2P throughput files, refs #3363
Diffstat (limited to 'validation/test/P2P_throughput/P2P_throughput_caller.py')
-rw-r--r--validation/test/P2P_throughput/P2P_throughput_caller.py103
1 files changed, 103 insertions, 0 deletions
diff --git a/validation/test/P2P_throughput/P2P_throughput_caller.py b/validation/test/P2P_throughput/P2P_throughput_caller.py
new file mode 100644
index 0000000000..fc61423a5c
--- /dev/null
+++ b/validation/test/P2P_throughput/P2P_throughput_caller.py
@@ -0,0 +1,103 @@
+# -*- coding: utf-8 -*-
+
+"""Module allowing to call P2P_throughput, with the adequate configuration"""
+
+import numpy
+import P2P_throughput
+import sys
+import os
+
+class P2P_throughput_caller:
+
+ """P2P throughput caller"""
+
+ def __init__(self):
+ from optparse import OptionParser
+ dirname = os.path.dirname(__file__)
+ self.example_file_name = os.path.join(dirname, "config.py")
+ usage = r"""
+ %prog report conf_file
+ Generate the P2P throughput report based on conf_file
+
+ %prog clear_tokens conf_file
+ Clear the tokens on the two iperf hosts specified in conf_file
+
+ %prog set_tokens conf_file
+ Set the tokens on the two iperf hosts specified in conf_file
+
+ conf_file must be the path of a file containing exactly the same
+ parameters as the template (""" + \
+ self.example_file_name + """).\n""" + \
+ """
+ The tokens must be set before generating the report and cleared when the
+ test bench is released."""
+
+ self._commands = dict((n[4:], getattr(self, n))
+ for n in dir(self) if n.startswith('run_'))
+ self._parser = OptionParser(usage = usage)
+
+ def run(self, args):
+ if len(args) != 2:
+ self._parser.error("Bad number of arguments")
+ options, args = self._parser.parse_args(args)
+ cmd = args[0]
+ if cmd not in self._commands:
+ self._parser.error("Unknown command \"{0}\".".format(cmd))
+
+ example_config = evaluate(self.example_file_name)
+ file_name = args[1]
+
+ try:
+ config = evaluate(file_name)
+ expected = sorted(example_config.keys())
+ actual = sorted(config.keys())
+ assert actual == expected, (actual, expected)
+ except IOError:
+ self._parser.error(file_name + " cannot be read.")
+ except SyntaxError:
+ self._parser.error(file_name + " cannot be evaluated.")
+ except AttributeError:
+ self._parser.error(file_name + " does not contain a dictionnary.")
+ except AssertionError as error:
+ (actual, expected) = error.args
+ message = file_name + " does not contain exactly the same " \
+ "parameters as the template (" + \
+ self.example_file_name + ").\n" + \
+ file_name + \
+ " contains the following parameters:\n" + \
+ str(actual) + \
+ "\n" + \
+ self.example_file_name + \
+ " contains the following parameters:\n" + \
+ str(expected)
+ self._parser.error(message)
+ except Exception as error:
+ self._parser.error("Unknown error.\n" + \
+ str(type(error)) + "\n" + \
+ str(error))
+
+ self._commands[cmd](config)
+
+ def run_report(self, config):
+ P2P_throughput.report(config)
+
+ def run_set_tokens(self, config):
+ P2P_throughput.set_tokens(config)
+
+ def run_clear_tokens(self, config):
+ P2P_throughput.clear_tokens(config)
+
+def evaluate(file_name):
+ config_file = open(file_name, "r")
+ config_string = config_file.read()
+ config_file.close()
+ config = eval(config_string)
+ return config
+
+if __name__ == "__main__":
+ try:
+ P2P_throughput_caller().run(sys.argv[1:])
+ except RuntimeError, e:
+ print >> sys.stderr, "Error:", e
+ sys.exit(1)
+