1##########################################################################
2# Copyright (c) 2009, 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 tests
12from common import TestCommon
13from results import PassFailResult
14
15class RpcCapTestCommon(TestCommon):
16    def get_finish_string(self):
17        return "TEST PASSED"
18
19    def process_data(self, testdir, rawiter):
20        # the test passed iff the last line is the finish string
21        lastline = ''
22        for line in rawiter:
23            lastline = line
24        passed = lastline.startswith(self.get_finish_string())
25        return PassFailResult(passed)
26
27    def get_modules(self, build, machine):
28        modules = super(RpcCapTestCommon, self).get_modules(build, machine)
29        ccid = self.get_client_coreid(machine)
30
31        modules.add_module("rpc_cap_test",
32                ["core=%d" % machine.get_coreids()[0], "server"])
33        modules.add_module("rpc_cap_test",
34                ["core=%d" % ccid, "client", "id=0"])
35        modules.add_module("rpc_cap_test",
36                ["core=%d" % ccid, "client", "id=1"])
37        modules.add_module("rpc_cap_test",
38                ["core=%d" % ccid, "client", "id=2"])
39        return modules
40
41@tests.add_test
42class RpcCapTestLocal(RpcCapTestCommon):
43    ''' test cap transfer using RPC. Client/server on same core '''
44    name = "rpc_cap_local"
45
46    def get_client_coreid(self, machine):
47        return machine.get_coreids()[0]
48
49
50@tests.add_test
51class RpcCapTestCross(RpcCapTestCommon):
52    ''' test cap transfer using RPC. Cross-core '''
53    name = "rpc_cap_cross"
54
55    def get_client_coreid(self, machine):
56        if machine.get_ncores() < 2:
57            raise Exception("Machine must have at least 2 cores")
58        return machine.get_coreids()[1]
59
60