1##########################################################################
2# Copyright (c) 2017, 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 datetime
11import tests
12import re
13from common import TestCommon
14from results import PassFailResult
15
16@tests.add_test
17class ProcMgmtTest(TestCommon):
18    '''Process management service API. Requires at least 2 cores.'''
19    name = "proc_mgmt_test"
20
21    def setup(self, build, machine, testdir):
22        super(ProcMgmtTest, self).setup(build, machine, testdir)
23        self.test_timeout_delta = datetime.timedelta(seconds=15*60)
24
25    def get_modules(self, build, machine):
26        modules = super(ProcMgmtTest, self).get_modules(build, machine)
27        modules.add_module("proc_mgmt_test", ["core=0", "0", "starter"])
28        return modules
29
30    def get_finish_string(self):
31        return "TEST DONE"
32
33    def process_data(self, testdir, rawiter):
34        sleeper = False
35        num_wait = 0
36
37        for line in rawiter:
38
39            if line.startswith("Unblocked") and sleeper:
40                num_wait += 1
41                sleeper = False
42            else:
43                sleeper = False
44
45            if line.startswith("Sleeper exit"):
46                sleeper = True
47
48
49            if line.startswith("Failed"):
50                return PassFailResult(False)
51
52        if num_wait == 2:
53            return PassFailResult(True)
54        else:
55            return PassFailResult(False)
56