The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.

Please select the desired protocol below to get the URL.

This URL has Read-Only access.

Statistics
| Branch: | Revision:

main_repo / deps / v8 / test / test262 / testcfg.py @ f230a1cf

History | View | Annotate | Download (4.89 KB)

1
# Copyright 2012 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 hashlib
30
import os
31
import sys
32
import tarfile
33
import urllib
34

    
35
from testrunner.local import testsuite
36
from testrunner.objects import testcase
37

    
38

    
39
TEST_262_ARCHIVE_REVISION = "99aac3bc1cad"  # This is the r365 revision.
40
TEST_262_ARCHIVE_MD5 = "aadbd720ce9bdb4f8f3de066f4d7eea1"
41
TEST_262_URL = "http://hg.ecmascript.org/tests/test262/archive/%s.tar.bz2"
42
TEST_262_HARNESS = ["sta.js", "testBuiltInObject.js", "testIntl.js"]
43

    
44

    
45
class Test262TestSuite(testsuite.TestSuite):
46

    
47
  def __init__(self, name, root):
48
    super(Test262TestSuite, self).__init__(name, root)
49
    self.testroot = os.path.join(root, "data", "test", "suite")
50
    self.harness = [os.path.join(self.root, "data", "test", "harness", f)
51
                    for f in TEST_262_HARNESS]
52
    self.harness += [os.path.join(self.root, "harness-adapt.js")]
53

    
54
  def CommonTestName(self, testcase):
55
    return testcase.path.split(os.path.sep)[-1]
56

    
57
  def ListTests(self, context):
58
    tests = []
59
    for dirname, dirs, files in os.walk(self.testroot):
60
      for dotted in [x for x in dirs if x.startswith(".")]:
61
        dirs.remove(dotted)
62
      if context.noi18n and "intl402" in dirs:
63
        dirs.remove("intl402")
64
      dirs.sort()
65
      files.sort()
66
      for filename in files:
67
        if filename.endswith(".js"):
68
          testname = os.path.join(dirname[len(self.testroot) + 1:],
69
                                  filename[:-3])
70
          case = testcase.TestCase(self, testname)
71
          tests.append(case)
72
    return tests
73

    
74
  def GetFlagsForTestCase(self, testcase, context):
75
    return (testcase.flags + context.mode_flags + self.harness +
76
            [os.path.join(self.testroot, testcase.path + ".js")])
77

    
78
  def GetSourceForTest(self, testcase):
79
    filename = os.path.join(self.testroot, testcase.path + ".js")
80
    with open(filename) as f:
81
      return f.read()
82

    
83
  def IsNegativeTest(self, testcase):
84
    return "@negative" in self.GetSourceForTest(testcase)
85

    
86
  def IsFailureOutput(self, output, testpath):
87
    if output.exit_code != 0:
88
      return True
89
    return "FAILED!" in output.stdout
90

    
91
  def DownloadData(self):
92
    revision = TEST_262_ARCHIVE_REVISION
93
    archive_url = TEST_262_URL % revision
94
    archive_name = os.path.join(self.root, "test262-%s.tar.bz2" % revision)
95
    directory_name = os.path.join(self.root, "data")
96
    directory_old_name = os.path.join(self.root, "data.old")
97
    if not os.path.exists(archive_name):
98
      print "Downloading test data from %s ..." % archive_url
99
      urllib.urlretrieve(archive_url, archive_name)
100
      if os.path.exists(directory_name):
101
        os.rename(directory_name, directory_old_name)
102
    if not os.path.exists(directory_name):
103
      print "Extracting test262-%s.tar.bz2 ..." % revision
104
      md5 = hashlib.md5()
105
      with open(archive_name, "rb") as f:
106
        for chunk in iter(lambda: f.read(8192), ""):
107
          md5.update(chunk)
108
      if md5.hexdigest() != TEST_262_ARCHIVE_MD5:
109
        os.remove(archive_name)
110
        raise Exception("Hash mismatch of test data file")
111
      archive = tarfile.open(archive_name, "r:bz2")
112
      if sys.platform in ("win32", "cygwin"):
113
        # Magic incantation to allow longer path names on Windows.
114
        archive.extractall(u"\\\\?\\%s" % self.root)
115
      else:
116
        archive.extractall(self.root)
117
      os.rename(os.path.join(self.root, "test262-%s" % revision),
118
                directory_name)
119

    
120

    
121
def GetSuite(name, root):
122
  return Test262TestSuite(name, root)