1##########################################################################
2# Copyright (c) 2009, 2010, ETH Zurich.
3# All rights reserved.
4#
5# This file is distributed under the terms in the attached LICENSE file.
6# If you do not find this file, copies can be found by writing to:
7# ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
8##########################################################################
9
10import re
11import debug, tests
12from common import TestCommon, TimeoutError
13from results import RawResults, PassFailResult
14
15class MultihopTestCommon(TestCommon):
16
17    def get_module_name(self):
18        raise NotImplementedError
19
20    def get_modules(self, build, machine):
21        modules = super(MultihopTestCommon, self).get_modules(build, machine)
22        modules.add_module(self.get_module_name())
23        return modules
24
25@tests.add_test
26class MultihopTest(MultihopTestCommon):
27    ''' Test whether multi-hop messaging is working '''
28    name = "multihop_test"
29
30    def get_module_name(self):
31        return "multihoptest"
32
33    def get_finish_string(self):
34        return "server all done"
35
36    def get_modules(self, build, machine):
37        modules = super(MultihopTestCommon, self).get_modules(build, machine)
38        modules.add_module(self.get_module_name(),["core=0", "server"])
39        modules.add_module(self.get_module_name(),["core=1", "client"])
40        return modules
41
42    def process_data(self, testdir, rawiter):
43         # the test passed iff we see the finish string
44	passed = False
45        for line in rawiter:
46            if line.startswith(self.get_finish_string()):
47		passed = True
48        return PassFailResult(passed)
49
50
51@tests.add_test
52class MultihopLatencyTest(MultihopTestCommon):
53    ''' Multihop Transport Throughput microbenchmark '''
54    name = "multihop_throughput_latency"
55
56    def get_module_name(self):
57        return "multihop_latency_bench"
58
59    def process_data(self, testdir, rawiter):
60        results = RawResults('message type')
61        times = []
62        iteration = None
63        for line in rawiter:
64            m = re.match("Running latency test for message (.*)....", line)
65            if m:
66                if times:
67                    results.add_group(iteration, times)
68                iteration = m.group(1)
69                times = []
70                continue
71
72            m = re.match("page \d+ took (\d+)", line)
73            if m:
74                assert(iteration is not None)
75                times.append(int(m.group(1)))
76
77        if len(times) != 0:
78            results.add_group(iteration, times)
79        return results
80
81