From e786cca5e162870a81517eb2ef2a7d74b3d7cf4f Mon Sep 17 00:00:00 2001 From: Olivier Dufour Date: Tue, 23 Apr 2013 08:47:23 +0200 Subject: validation/test/av_home: generate RST report, closes #3845 --- validation/test/av_home/Makefile | 7 ++ validation/test/av_home/av_home.cfg | 1 + validation/test/av_home/av_home.py | 181 ++++++++++++++++++++++++++++++ validation/test/av_home/av_home_attr.py | 1 + validation/test/av_home/av_home_caller.py | 2 + validation/test/av_home/template.rst | 17 +++ 6 files changed, 209 insertions(+) create mode 100644 validation/test/av_home/Makefile create mode 100644 validation/test/av_home/template.rst diff --git a/validation/test/av_home/Makefile b/validation/test/av_home/Makefile new file mode 100644 index 0000000000..300453a116 --- /dev/null +++ b/validation/test/av_home/Makefile @@ -0,0 +1,7 @@ +GLOSSARY = n + +BASE = ../../.. + +DOCS = report + +include $(BASE)/common/doc/template/doc.mk diff --git a/validation/test/av_home/av_home.cfg b/validation/test/av_home/av_home.cfg index a7435b2397..850b60b109 100644 --- a/validation/test/av_home/av_home.cfg +++ b/validation/test/av_home/av_home.cfg @@ -6,3 +6,4 @@ iface = eth1 addr = 10.3.0.225 scammer_path = ../../../common/lib/scammer/ [Report] +author = Olivier Dufour diff --git a/validation/test/av_home/av_home.py b/validation/test/av_home/av_home.py index 6768a801d7..c0fa69a473 100755 --- a/validation/test/av_home/av_home.py +++ b/validation/test/av_home/av_home.py @@ -12,6 +12,7 @@ import subprocess def master_script(): print ("Executing master script") test_init () + set_test_desc () print ("Executing ping on slave PC ("+ av_home_attr.addr +")...") av_mme.ping_peer () print ("Sending MME for environment discovery to " + av_home_attr.plug_mac + @@ -45,6 +46,10 @@ def slave_script(): get_general_result ("slave") prepare_archive ("slave") +def report(): + prepare_plot () + generate_report () + def config_get_item (config, section, key): """Get the value of the key in the section from the config parser""" try: @@ -62,6 +67,7 @@ def parse_config(file): av_home_attr.addr = config_get_item (config, 'Test', 'addr') av_home_attr.output_dir = config_get_item (config, 'Test', 'output_dir') av_home_attr.scammer_path = config_get_item (config, 'Test', 'scammer_path') + av_home_attr.author = config_get_item (config, 'Report', 'author') def set_opts(options): if options.plug_mac: @@ -241,3 +247,178 @@ def prepare_archive (mode): args = shlex.split ("bzip2 -zf test-%s.tar" % mode) p = subprocess.Popen (args, shell=False) p.wait () + +def prepare_plot (): + directories = os.listdir(".") + dir_re = re.compile (r"^test_home-.*$") + for d in directories: + if re.match (dir_re, d): + do_plot ("rx", d) + do_plot ("tx", d) + +def do_plot (direction, directory): + import pylab + if direction == "rx": + f = open (os.path.join (directory, "master_plot"), "r") + else: + f = open (os.path.join (directory, "slave_plot"), "r") + lines = f.readlines () + maximum = 0 + minimum = 0 + for l in lines: + # Get minimum and maximum value from server logs + values = l.split (';') + local_maximum = (int (float (values[1])) * 4) / 3 + if local_maximum > maximum: + maximum = local_maximum + local_minimum = (int (float (values[0])) * 2) / 3 + if local_minimum < minimum: + minimum = local_minimum + x = [ j for j in xrange (len(values) - 2)] + y = [ values[j + 2] for j in xrange (len(values) - 2)] + pylab.plot (x,y) + pylab.ylim ([minimum,maximum]) + pylab.ylabel("Throughput in Mbps") + pylab.xlabel("Time in seconds") + if direction == "rx": + pylab.title("Download throughput for %s" % av_home_attr.plug_mac) + else: + pylab.title("Upload throughput for %s" % av_home_attr.plug_mac) + pylab.gcf().savefig (os.path.join (directory, "master-%s.png" % direction)) + pylab.clf() + f.close () + if direction == "rx": + f = open (os.path.join (directory, "tonemap-slave_plot"), "r") + else: + f = open (os.path.join (directory, "tonemap-master_plot"), "r") + lines = f.readlines ()[0] + x = [ j for j in xrange (1536)] + y = [ lines[j] for j in xrange (1536)] + pylab.plot (x, y) + f.close () + f = open ("tonemask", "r") + lines = f.readlines ()[0] + z = [ lines[j] for j in xrange (1536)] + pylab.plot (x, z, color='grey', alpha=0.5) + good = [] + wrong = [] + unused = [] + for i in xrange (len(y)): + if (y[i]>=z[i] and z[i] == '0'): + good.append (True) + wrong.append (False) + unused.append (False) + if z[i] != '0' and y[i] != '0': + wrong.append (True) + good.append (False) + unused.append (False) + if y[i] == '0' and z[i] != '0': + wrong.append (False) + good.append (False) + unused.append (True) + pylab.fill_between (x, y, z, where=good, color='blue') + pylab.fill_between (x, y, z, where=wrong, color='red') + pylab.fill_between (x, y, z, where=unused, color='grey', alpha=0.5) + pylab.ylim ([0,8]) + pylab.ylabel("Modulation") + pylab.xlabel("Carriers") + pylab.title("Default tonemap - %s" % direction) + pylab.gcf().savefig (os.path.join (directory, "tonemap-%s.png" % direction)) + pylab.clf() + +def get_test_data (): + tpl = """Test {name} +================ + +:: + + {desc} + +Discover list +------------- +{discovery} + +Network info +------------ +{avln} + +Attenuation list +---------------- +{attenuation} + +Tonemaps and throughput +----------------------- +{graph} +""" + result = "" + # Get all test results + directories = os.listdir(".") + dir_re = re.compile (r"^test_home-(.*)$") + for d in directories: + if dir_re.match (d): + desc = get_test_desc (d) + discovery = get_field (d, "discovery") + avln = get_field (d, "avln") + attenuation = get_field (d, "attenuation") + graph = get_graph (d) + result += tpl.format (name = dir_re.match (d).group (1), + desc = desc, + discovery = discovery, + avln = avln, + attenuation = attenuation, + graph = graph) + return result + +def get_field (d, file): + f = open (os.path.join (d, "%s-master" % file), "r") + value = f.read () + f.close () + f = open (os.path.join (d, "%s-slave" % file), "r") + value += f.read () + f.close () + return value + +def get_graph (d): + tpl = """ +Upload: + +.. image:: {upload} +.. image:: {tx} + +Download: + +.. image:: {download} +.. image:: {rx} + +""" + upload = "%s/master-tx.png" % d + download = "%s/master-rx.png" % d + tx = "%s/tonemap-tx.png" % d + rx = "%s/tonemap-rx.png" % d + + return tpl.format (upload = upload, + download = download, + tx = tx, + rx = rx) + +def generate_report (): + f = open ("template.rst", "r") + tpl = f.read () + tpl = tpl.format (author = av_home_attr.author, + master = av_home_attr.plug_mac, + slave = av_home_attr.peer_mac, + soft = get_field (".", "soft_version"), + tests = get_test_data ()) + print tpl + f.close () + +def set_test_desc (): + f = open (os.path.join (av_home_attr.output_dir, "DESC"), "w") + print >>f, raw_input ("Enter test description:") + f.close () + +def get_test_desc (d): + f = open (os.path.join (d, "DESC"), "r") + value = f.read () + f.close () + return value diff --git a/validation/test/av_home/av_home_attr.py b/validation/test/av_home/av_home_attr.py index bc095338ee..2f30fca166 100644 --- a/validation/test/av_home/av_home_attr.py +++ b/validation/test/av_home/av_home_attr.py @@ -6,4 +6,5 @@ class av_home_attr: addr = "" output_dir = "" scammer_path = "" + author = "" diff --git a/validation/test/av_home/av_home_caller.py b/validation/test/av_home/av_home_caller.py index b63a67e235..e2f66e4e1d 100755 --- a/validation/test/av_home/av_home_caller.py +++ b/validation/test/av_home/av_home_caller.py @@ -54,6 +54,8 @@ class av_home_caller: av_home.master_script(); def run_slave(self): av_home.slave_script(); + def run_report(self): + av_home.report(); if __name__ == "__main__": av_home_caller().run(sys.argv[1:]) diff --git a/validation/test/av_home/template.rst b/validation/test/av_home/template.rst new file mode 100644 index 0000000000..d41d71f702 --- /dev/null +++ b/validation/test/av_home/template.rst @@ -0,0 +1,17 @@ +|Title| - |Version| ++++++++++++++++++++ + +.. |Title| replace:: MPR520 P2P test report +.. |Version| replace:: 1.0 + +.. include:: header.rst + +Description +=========== + +Plugs: MPR520 {master}, {slave} + +{soft} + +{tests} + -- cgit v1.2.3