1##########################################################################
2# Copyright (c) 2013, 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, CAB F.78, Universitaetstr 6, CH-8092 Zurich.
8##########################################################################
9
10import re
11import tests
12from common import TestCommon
13from results import PassFailResult
14
15NUM_SPAWNS = 4
16NUM_CORES = 2
17MATCH = '.*xmpl-spawn.*Finished'
18
19@tests.add_test
20class SpawnTest(TestCommon):
21    '''Spawn a program on the twice each on the first and second core'''
22    name = "spawntest"
23
24    def setup(self, build, machine, testdir):
25        super(SpawnTest, self).setup(build, machine, testdir)
26
27        # XXX: track number of cores booted and seen for is_finished()
28        self._ncores = machine.get_ncores()
29        self._nseen = 0
30
31    def get_modules(self, build, machine):
32        modules = super(SpawnTest, self).get_modules(build, machine)
33        modules.add_module("examples/xmpl-spawn", [ NUM_SPAWNS, NUM_CORES ])
34        return modules
35
36    def is_finished(self, line):
37        if re.match(MATCH, line):
38            self._nseen += 1
39        return self._nseen == (NUM_SPAWNS + 1) or super(SpawnTest, self).is_finished(line)
40
41    def process_data(self, testdir, rawiter):
42        nspawned = 0
43        for line in rawiter:
44            if re.match(MATCH, line):
45                nspawned += 1
46        return PassFailResult(nspawned == (NUM_SPAWNS + 1))
47