Updated V8 from git://github.com/v8/v8.git to 3e6ec7e018bbf2c63ef04b85ff688198ea204c04
[profile/ivi/qtjsbackend.git] / src / 3rdparty / v8 / test / cctest / testcfg.py
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
28 import test
29 import os
30 from os.path import join, dirname, exists
31 import platform
32 import utils
33
34
35 class CcTestCase(test.TestCase):
36
37   def __init__(self, path, executable, mode, raw_name, dependency, context, variant_flags):
38     super(CcTestCase, self).__init__(context, path, mode)
39     self.executable = executable
40     self.raw_name = raw_name
41     self.dependency = dependency
42     self.variant_flags = variant_flags
43
44   def GetLabel(self):
45     return "%s %s %s" % (self.mode, self.path[-2], self.path[-1])
46
47   def GetName(self):
48     return self.path[-1]
49
50   def BuildCommand(self, name):
51     serialization_file = ''
52     if exists(join(self.context.buildspace, 'obj', 'test', self.mode)):
53       serialization_file = join('obj', 'test', self.mode, 'serdes')
54     else:
55       serialization_file = join('obj', 'serdes')
56       if not exists(join(self.context.buildspace, 'obj')):
57         os.makedirs(join(self.context.buildspace, 'obj'))
58     serialization_file += '_' + self.GetName()
59     serialization_file = join(self.context.buildspace, serialization_file)
60     serialization_file += ''.join(self.variant_flags).replace('-', '_')
61     serialization_option = '--testing_serialization_file=' + serialization_file
62     result = [ self.executable, name, serialization_option ]
63     result += self.context.GetVmFlags(self, self.mode)
64     return result
65
66   def GetCommand(self):
67     return self.BuildCommand(self.raw_name)
68
69   def Run(self):
70     if self.dependency != '':
71       dependent_command = self.BuildCommand(self.dependency)
72       output = self.RunCommand(dependent_command)
73       if output.HasFailed():
74         return output
75     return test.TestCase.Run(self)
76
77
78 class CcTestConfiguration(test.TestConfiguration):
79
80   def __init__(self, context, root):
81     super(CcTestConfiguration, self).__init__(context, root)
82
83   def GetBuildRequirements(self):
84     return ['cctests']
85
86   def ListTests(self, current_path, path, mode, variant_flags):
87     executable = 'cctest'
88     if utils.IsWindows():
89       executable += '.exe'
90     executable = join(self.context.buildspace, executable)
91     if not exists(executable):
92       executable = join('obj', 'test', mode, 'cctest')
93       if utils.IsWindows():
94         executable += '.exe'
95       executable = join(self.context.buildspace, executable)
96     output = test.Execute([executable, '--list'], self.context)
97     if output.exit_code != 0:
98       print output.stdout
99       print output.stderr
100       return []
101     result = []
102     for test_desc in output.stdout.strip().split():
103       raw_test, dependency = test_desc.split('<')
104       relative_path = raw_test.split('/')
105       full_path = current_path + relative_path
106       if dependency != '':
107         dependency = relative_path[0] + '/' + dependency
108       if self.Contains(path, full_path):
109         result.append(CcTestCase(full_path, executable, mode, raw_test, dependency, self.context, variant_flags))
110     result.sort()
111     return result
112
113   def GetTestStatus(self, sections, defs):
114     status_file = join(self.root, 'cctest.status')
115     if exists(status_file):
116       test.ReadConfigurationInto(status_file, sections, defs)
117
118
119 def GetConfiguration(context, root):
120   return CcTestConfiguration(context, root)