Home | History | Annotate | Download | only in test262
      1 # Copyright 2011 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 
     29 import test
     30 import os
     31 from os.path import join, exists
     32 
     33 
     34 TEST_262_HARNESS = ['sta.js']
     35 
     36 
     37 class Test262TestCase(test.TestCase):
     38 
     39   def __init__(self, filename, path, context, root, mode, framework):
     40     super(Test262TestCase, self).__init__(context, path, mode)
     41     self.filename = filename
     42     self.framework = framework
     43     self.root = root
     44 
     45   def IsNegative(self):
     46     return self.filename.endswith('-n.js')
     47 
     48   def GetLabel(self):
     49     return "%s test262 %s %s" % (self.mode, self.GetGroup(), self.GetName())
     50 
     51   def IsFailureOutput(self, output):
     52     if output.exit_code != 0:
     53       return True
     54     return 'FAILED!' in output.stdout
     55 
     56   def GetCommand(self):
     57     result = self.context.GetVmCommand(self, self.mode)
     58     result += ['-e', 'var window = this']
     59     result += self.framework
     60     result.append(self.filename)
     61     return result
     62 
     63   def GetName(self):
     64     return self.path[-1]
     65 
     66   def GetGroup(self):
     67     return self.path[0]
     68 
     69   def GetSource(self):
     70     return open(self.filename).read()
     71 
     72 
     73 class Test262TestConfiguration(test.TestConfiguration):
     74 
     75   def __init__(self, context, root):
     76     super(Test262TestConfiguration, self).__init__(context, root)
     77 
     78   def AddIETestCenter(self, tests, current_path, path, mode):
     79     current_root = join(self.root, 'data', 'test', 'suite', 'ietestcenter')
     80     harness = [join(self.root, 'data', 'test', 'harness', f)
     81                    for f in TEST_262_HARNESS]
     82     harness += [join(self.root, 'harness-adapt.js')]
     83     for root, dirs, files in os.walk(current_root):
     84       for dotted in [x  for x in dirs if x.startswith('.')]:
     85         dirs.remove(dotted)
     86       dirs.sort()
     87       root_path = root[len(self.root):].split(os.path.sep)
     88       root_path = current_path + [x for x in root_path if x]
     89       files.sort()
     90       for file in files:
     91         if file.endswith('.js'):
     92           if self.Contains(path, root_path):
     93             test_path = ['ietestcenter', file[:-3]]
     94             test = Test262TestCase(join(root, file), test_path, self.context,
     95                                    self.root, mode, harness)
     96             tests.append(test)
     97 
     98   def AddSputnikConvertedTests(self, tests, current_path, path, mode):
     99     # To be enabled
    100     pass
    101 
    102   def AddSputnikTests(self, tests, current_path, path, mode):
    103     # To be enabled
    104     pass
    105 
    106   def ListTests(self, current_path, path, mode, variant_flags):
    107     tests = []
    108     self.AddIETestCenter(tests, current_path, path, mode)
    109     self.AddSputnikConvertedTests(tests, current_path, path, mode)
    110     self.AddSputnikTests(tests, current_path, path, mode)
    111     return tests
    112 
    113   def GetBuildRequirements(self):
    114     return ['sample', 'sample=shell']
    115 
    116   def GetTestStatus(self, sections, defs):
    117     status_file = join(self.root, 'test262.status')
    118     if exists(status_file):
    119       test.ReadConfigurationInto(status_file, sections, defs)
    120 
    121 
    122 def GetConfiguration(context, root):
    123   return Test262TestConfiguration(context, root)
    124