testcfg.py revision 80d68eab642096c1a48b6474d6ec33064b0ad1f5
1# Copyright 2008 the V8 project authors. All rights reserved.
2# Redistribution and use in source and binary forms, with or without
3# modification, are permitted provided that the following conditions are
4# met:
5#
6#     * Redistributions of source code must retain the above copyright
7#       notice, this list of conditions and the following disclaimer.
8#     * Redistributions in binary form must reproduce the above
9#       copyright notice, this list of conditions and the following
10#       disclaimer in the documentation and/or other materials provided
11#       with the distribution.
12#     * Neither the name of Google Inc. nor the names of its
13#       contributors may be used to endorse or promote products derived
14#       from this software without specific prior written permission.
15#
16# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28import test
29import os
30from os.path import join, dirname, exists
31import platform
32import utils
33
34
35class CcTestCase(test.TestCase):
36
37  def __init__(self, path, executable, mode, raw_name, dependency, context):
38    super(CcTestCase, self).__init__(context, path, mode)
39    self.executable = executable
40    self.raw_name = raw_name
41    self.dependency = dependency
42
43  def GetLabel(self):
44    return "%s %s %s" % (self.mode, self.path[-2], self.path[-1])
45
46  def GetName(self):
47    return self.path[-1]
48
49  def BuildCommand(self, name):
50    serialization_file = join('obj', 'test', self.mode, 'serdes')
51    serialization_file += '_' + self.GetName()
52    serialization_option = '--testing_serialization_file=' + serialization_file
53    result = [ self.executable, name, serialization_option ]
54    result += self.context.GetVmFlags(self, self.mode)
55    return result
56
57  def GetCommand(self):
58    return self.BuildCommand(self.raw_name)
59
60  def Run(self):
61    if self.dependency != '':
62      dependent_command = self.BuildCommand(self.dependency)
63      output = self.RunCommand(dependent_command)
64      if output.HasFailed():
65        return output
66    return test.TestCase.Run(self)
67
68
69class CcTestConfiguration(test.TestConfiguration):
70
71  def __init__(self, context, root):
72    super(CcTestConfiguration, self).__init__(context, root)
73
74  def GetBuildRequirements(self):
75    return ['cctests']
76
77  def ListTests(self, current_path, path, mode):
78    executable = join('obj', 'test', mode, 'cctest')
79    if utils.IsWindows():
80      executable += '.exe'
81    output = test.Execute([executable, '--list'], self.context)
82    if output.exit_code != 0:
83      print output.stdout
84      print output.stderr
85      return []
86    result = []
87    for test_desc in output.stdout.strip().split():
88      raw_test, dependency = test_desc.split('<')
89      relative_path = raw_test.split('/')
90      full_path = current_path + relative_path
91      if dependency != '':
92        dependency = relative_path[0] + '/' + dependency
93      if self.Contains(path, full_path):
94        result.append(CcTestCase(full_path, executable, mode, raw_test, dependency, self.context))
95    return result
96
97  def GetTestStatus(self, sections, defs):
98    status_file = join(self.root, 'cctest.status')
99    if exists(status_file):
100      test.ReadConfigurationInto(status_file, sections, defs)
101
102
103def GetConfiguration(context, root):
104  return CcTestConfiguration(context, root)
105