From: Alina Quereilhac Date: Sun, 3 Aug 2014 18:10:42 +0000 (+0200) Subject: Unit test for ExperimentRunner with LinuxApplication and Collector X-Git-Tag: nepi-3.2.0~105^2 X-Git-Url: http://git.onelab.eu/?p=nepi.git;a=commitdiff_plain;h=a3e02ea08e65fabe6104d4ba30ee635c42ebd4d1 Unit test for ExperimentRunner with LinuxApplication and Collector --- diff --git a/src/nepi/execution/runner.py b/src/nepi/execution/runner.py index 6757d7b5..60e75a4f 100644 --- a/src/nepi/execution/runner.py +++ b/src/nepi/execution/runner.py @@ -64,7 +64,7 @@ class ExperimentRunner(object): :param compute_metric_callback: function to invoke after each experiment run, to compute an experiment metric. It will be invoked with the ec and the run count as arguments, - and it must return the value of the computed metric: + and it must return a numeric value for the computed metric: metric = compute_metric_callback(ec, run) @@ -119,11 +119,12 @@ class ExperimentRunner(object): if compute_metric_callback: metric = compute_metric_callback(ec, run) - samples.append(metric) + if metric is not None: + samples.append(metric) - if run >= min_runs and evaluate_convergence_callback: - if evaluate_convergence_callback(ec, run, samples): - break + if run >= min_runs and evaluate_convergence_callback: + if evaluate_convergence_callback(ec, run, samples): + break del ec return run @@ -132,7 +133,7 @@ class ExperimentRunner(object): if len(samples) == 0: msg = "0 samples collected" raise RuntimeError, msg - + x = numpy.array(samples) n = len(samples) std = x.std() diff --git a/test/resources/linux/multirun.py b/test/resources/linux/multirun.py new file mode 100755 index 00000000..d548bd2c --- /dev/null +++ b/test/resources/linux/multirun.py @@ -0,0 +1,109 @@ +#!/usr/bin/env python +# +# NEPI, a framework to manage network experiments +# Copyright (C) 2013 INRIA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Author: Alina Quereilhac + +from nepi.execution.ec import ExperimentController +from nepi.execution.runner import ExperimentRunner + +from test_utils import skipIfNotAlive, skipInteractive + +import functools +import glob +import os +import re +import shutil +import time +import tempfile +import unittest + +_ping_re = re.compile("[^/]+rtt min/avg/max/mdev = (?P\d\.\d+)/(?P\d\.\d+)/(?P\d\.\d+)/(?P\d\.\d+)[^/]+", re.MULTILINE) + +class LinuxMultiRunTestCase(unittest.TestCase): + def setUp(self): + self.fedora_host = "nepi2.pl.sophia.inria.fr" + self.fedora_user = "inria_nepi" + + self.ubuntu_host = "roseval.pl.sophia.inria.fr" + self.ubuntu_user = "inria_nepi" + + self.target = "nepi5.pl.sophia.inria.fr" + + @skipIfNotAlive + def t_simple_multirun(self, host, user, depends): + + dirpath = tempfile.mkdtemp() + + ec = ExperimentController(exp_id="test-condition-multirun") + + node = ec.register_resource("LinuxNode") + ec.set(node, "hostname", host) + ec.set(node, "username", user) + ec.set(node, "cleanHome", True) + ec.set(node, "cleanProcesses", True) + + ping = ec.register_resource("LinuxApplication") + ec.set(ping, "command", "ping -c10 nepi.inria.fr") + ec.register_connection(ping, node) + + collector = ec.register_resource("Collector") + ec.set(collector, "traceName", "stdout") + ec.set(collector, "storeDir", dirpath) + ec.set(collector, "useRunId", True) + ec.register_connection(ping, collector) + + def compute_metric_callback(ping, ec, run): + stdout = ec.trace(ping, "stdout") + + m = _ping_re.match(stdout) + if not m: + return None + + return float(m.groupdict()["min"]) + + metric_callback = functools.partial(compute_metric_callback, ping) + + rnr = ExperimentRunner() + runs = rnr.run(ec, min_runs = 5, + compute_metric_callback = metric_callback, + wait_guids = [ping], + wait_time = 0) + + self.assertTrue(runs >= 5) + + dircount = 0 + for d in os.listdir(dirpath): + path = os.path.join(dirpath, d) + if os.path.isdir(path): + dircount += 1 + logs = glob.glob(os.path.join(path, "*.stdout")) + self.assertEquals(len(logs), 1) + + self.assertEquals(runs, dircount) + + shutil.rmtree(dirpath) + + def test_simple_multirun_fedora(self): + self.t_simple_multirun(self.fedora_host, self.fedora_user, "nc") + + def test_simple_multirun_ubuntu(self): + self.t_simple_multirun(self.ubuntu_host, self.ubuntu_user, "netcat") + +if __name__ == '__main__': + unittest.main() + diff --git a/test/resources/linux/serialization.py b/test/resources/linux/serialization.py index 5f4dd36d..c133ab36 100755 --- a/test/resources/linux/serialization.py +++ b/test/resources/linux/serialization.py @@ -30,7 +30,7 @@ import time import tempfile import unittest -class LinuxApplicationSerializationTestCase(unittest.TestCase): +class LinuxSerializationTestCase(unittest.TestCase): def setUp(self): self.fedora_host = "nepi2.pl.sophia.inria.fr" self.fedora_user = "inria_nepi"