1##########################################################################
2# Copyright (c) 2011, 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##########################################################################
9import datetime
10import re
11import tests
12from common import TestCommon
13from results import PassFailResult
14
15TIMERTEST_TIMEOUT = datetime.timedelta(minutes=5)
16
17@tests.add_test
18class TimerTest(TestCommon):
19    '''Timer test'''
20    name = "timer"
21
22    def __init__(self, options):
23        super(TimerTest, self).__init__(options)
24        self.saw_line_A = False
25        self.saw_line_B = False
26
27    def get_modules(self, build, machine):
28        modules = super(TimerTest, self).get_modules(build, machine)
29        modules.add_module("lpc_timer", ["auto"])
30        core_ids = machine.get_coreids()
31        modules.add_module("timer_test",["core=%d" % core_ids[1]])
32        if len(core_ids) > 2:
33            modules.add_module("timer_test", ["core=%d" % core_ids[2], "B"])
34        else:
35            modules.add_module("timer_test", ["core=%d" % core_ids[1], "B"])
36        return modules
37
38    def get_test_A_finish_string(self):
39        return "Done with test for client_A"
40
41    def get_test_B_finish_string(self):
42        return "Done with test for client_B"
43
44    def is_finished(self, line):
45        if line.startswith(self.get_test_A_finish_string()):
46            self.saw_line_A = True
47        if line.startswith(self.get_test_B_finish_string()):
48            self.saw_line_B = True
49        return (self.saw_line_A and self.saw_line_B) or \
50                super(TimerTest, self).is_finished(line)
51
52
53
54    def boot(self, *args):
55        super(TimerTest, self).boot(*args)
56        self.set_timeout(TIMERTEST_TIMEOUT)
57
58    def process_data(self, testdir, rawiter):
59        # the test passed iff it has lines from both test_A and test_B
60        test_A_passed = False
61        test_B_passed = False
62
63        for line in rawiter:
64            if line.startswith(self.get_test_A_finish_string()):
65                test_A_passed = True
66            if line.startswith(self.get_test_B_finish_string()):
67                test_B_passed = True
68            if test_A_passed and test_B_passed:
69                return PassFailResult(True)
70
71        return PassFailResult(test_A_passed and test_B_passed)
72