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 RpcTestCommon(TestCommon):
16
17    def get_module_name(self):
18        raise NotImplementedError
19
20    def get_modules(self, build, machine):
21        modules = super(RpcTestCommon, self).get_modules(build, machine)
22        cores = machine.get_ncores()
23        modules.add_module(self.get_module_name(), ["core=1", "server"])
24        modules.add_module(self.get_module_name(),
25                           ["core=%d" % (cores - 1), "client"])
26        return modules
27
28    def run(self, build, machine, testdir):
29        modules = self.get_modules(build, machine)
30        self.boot(machine, modules)
31        return self.collect_data(machine)
32
33    def process_data(self, testdir, rawiter):
34        results = RawResults('connections')
35        times = []
36        connections = None
37        for line in rawiter:
38            m = re.match("running with (\d+) connections", line)
39            if m:
40                if times:
41                    results.add_group(connections, times)
42                connections = int(m.group(1))
43                times = []
44                continue
45
46            m = re.match("\d+ (\d+)", line)
47            if m:
48                assert(connections is not None)
49                times.append(int(m.group(1)))
50
51        if len(times) != 0:
52            results.add_group(connections, times)
53        return results
54
55@tests.add_test
56class ChannelCostTest(RpcTestCommon):
57    ''' Cost of incrementally more channels '''
58    name = "channel_cost"
59
60    def get_module_name(self):
61        return "channel_cost_bench"
62