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
15@tests.add_test
16class MemTest(TestCommon):
17    '''basic memory allocation functionality on a single core'''
18    name = "memtest"
19
20    def get_modules(self, build, machine):
21        modules = super(MemTest, self).get_modules(build, machine)
22        modules.add_module("memtest")
23        return modules
24
25    def get_finish_string(self):
26        return "memtest passed successfully!"
27
28    def process_data(self, testdir, rawiter):
29        # the test passed iff the last line is the finish string
30        lastline = ''
31        for line in rawiter:
32            lastline = line
33        passed = lastline.startswith(self.get_finish_string())
34        return PassFailResult(passed)
35
36@tests.add_test
37class MemTestMulti(TestCommon):
38    '''memory allocation functionality on all cores'''
39    name = "memtest_multicore"
40
41    def setup(self, build, machine, testdir):
42        super(MemTestMulti, self).setup(build, machine, testdir)
43
44        # XXX: track number of cores booted and seen for is_finished()
45        self._ncores = machine.get_ncores()
46        self._nseen = 0
47
48    def get_modules(self, build, machine):
49        modules = super(MemTestMulti, self).get_modules(build, machine)
50        modules.add_module("memtest", ["core=0-%d" % (machine.get_ncores()-1)])
51        return modules
52
53    def is_finished(self, line):
54        # XXX: count number of times we have seen the finish string
55        if line.startswith("memtest passed successfully!"):
56            self._nseen += 1
57        return self._nseen == self._ncores or super(MemTestMulti, self).is_finished(line)
58
59    def process_data(self, testdir, rawiter):
60        nspawned = nseen = 0
61        for line in rawiter:
62            if re.match(r'.*pawning .*memtest on core', line):
63                nspawned += 1
64            if line.startswith("memtest passed successfully!"):
65                nseen += 1
66        return PassFailResult(nspawned > 0 and nspawned == nseen)
67