• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
29import test
30import os
31from os.path import join, exists
32
33
34EXCLUDED = ['CVS']
35
36
37FRAMEWORK = """
38  browser.js
39  shell.js
40  jsref.js
41  template.js
42""".split()
43
44
45TEST_DIRS = """
46  ecma
47  ecma_2
48  ecma_3
49  js1_1
50  js1_2
51  js1_3
52  js1_4
53  js1_5
54""".split()
55
56
57class MozillaTestCase(test.TestCase):
58
59  def __init__(self, filename, path, context, root, mode, framework):
60    super(MozillaTestCase, self).__init__(context, path)
61    self.filename = filename
62    self.mode = mode
63    self.framework = framework
64    self.root = root
65
66  def IsNegative(self):
67    return self.filename.endswith('-n.js')
68
69  def GetLabel(self):
70    return "%s mozilla %s" % (self.mode, self.GetName())
71
72  def IsFailureOutput(self, output):
73    if output.exit_code != 0:
74      return True
75    return 'FAILED!' in output.stdout
76
77  def GetCommand(self):
78    result = [self.context.GetVm(self.mode), '--expose-gc',
79              join(self.root, 'mozilla-shell-emulation.js')]
80    result += self.framework
81    result.append(self.filename)
82    return result
83
84  def GetName(self):
85    return self.path[-1]
86
87  def GetSource(self):
88    return open(self.filename).read()
89
90
91class MozillaTestConfiguration(test.TestConfiguration):
92
93  def __init__(self, context, root):
94    super(MozillaTestConfiguration, self).__init__(context, root)
95
96  def ListTests(self, current_path, path, mode):
97    tests = []
98    for test_dir in TEST_DIRS:
99      current_root = join(self.root, 'data', test_dir)
100      for root, dirs, files in os.walk(current_root):
101        for dotted in [x  for x in dirs if x.startswith('.')]:
102          dirs.remove(dotted)
103        for excluded in EXCLUDED:
104          if excluded in dirs:
105            dirs.remove(excluded)
106        dirs.sort()
107        root_path = root[len(self.root):].split(os.path.sep)
108        root_path = current_path + [x for x in root_path if x]
109        framework = []
110        for i in xrange(len(root_path)):
111          if i == 0: dir = root_path[1:]
112          else: dir = root_path[1:-i]
113          script = join(self.root, reduce(join, dir, ''), 'shell.js')
114          if exists(script):
115            framework.append(script)
116        framework.reverse()
117        files.sort()
118        for file in files:
119          if (not file in FRAMEWORK) and file.endswith('.js'):
120            full_path = root_path + [file[:-3]]
121            full_path = [x for x in full_path if x != 'data']
122            if self.Contains(path, full_path):
123              test = MozillaTestCase(join(root, file), full_path, self.context,
124                                     self.root, mode, framework)
125              tests.append(test)
126    return tests
127
128  def GetBuildRequirements(self):
129    return ['sample', 'sample=shell']
130
131  def GetTestStatus(self, sections, defs):
132    status_file = join(self.root, 'mozilla.status')
133    if exists(status_file):
134      test.ReadConfigurationInto(status_file, sections, defs)
135
136
137def GetConfiguration(context, root):
138  return MozillaTestConfiguration(context, root)
139