Home | History | Annotate | Download | only in cctest
      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 os
     29 import shutil
     30 
     31 from testrunner.local import commands
     32 from testrunner.local import testsuite
     33 from testrunner.local import utils
     34 from testrunner.objects import testcase
     35 
     36 
     37 class CcTestSuite(testsuite.TestSuite):
     38 
     39   def __init__(self, name, root):
     40     super(CcTestSuite, self).__init__(name, root)
     41     if utils.IsWindows():
     42       build_dir = "build"
     43     else:
     44       build_dir = "out"
     45     self.serdes_dir = os.path.normpath(
     46         os.path.join(root, "..", "..", build_dir, ".serdes"))
     47 
     48   def SetupWorkingDirectory(self):
     49     # This is only called once per machine, while init above is called once per
     50     # process.
     51     if os.path.exists(self.serdes_dir):
     52       shutil.rmtree(self.serdes_dir, True)
     53     os.makedirs(self.serdes_dir)
     54 
     55   def ListTests(self, context):
     56     shell = os.path.abspath(os.path.join(context.shell_dir, self.shell()))
     57     if utils.IsWindows():
     58       shell += ".exe"
     59     output = commands.Execute(context.command_prefix +
     60                               [shell, "--list"] +
     61                               context.extra_flags)
     62     if output.exit_code != 0:
     63       print output.stdout
     64       print output.stderr
     65       return []
     66     tests = []
     67     for test_desc in output.stdout.strip().split():
     68       if test_desc.find('<') < 0:
     69         # Native Client output can contain a few non-test arguments
     70         # before the tests. Skip these.
     71         continue
     72       raw_test, dependency = test_desc.split('<')
     73       if dependency != '':
     74         dependency = raw_test.split('/')[0] + '/' + dependency
     75       else:
     76         dependency = None
     77       test = testcase.TestCase(self, raw_test, dependency=dependency)
     78       tests.append(test)
     79     tests.sort()
     80     return tests
     81 
     82   def GetFlagsForTestCase(self, testcase, context):
     83     testname = testcase.path.split(os.path.sep)[-1]
     84     serialization_file = os.path.join(self.serdes_dir, "serdes_" + testname)
     85     serialization_file += ''.join(testcase.flags).replace('-', '_')
     86     return (testcase.flags + [testcase.path] + context.mode_flags +
     87             ["--testing_serialization_file=" + serialization_file])
     88 
     89   def shell(self):
     90     return "cctest"
     91 
     92 
     93 def GetSuite(name, root):
     94   return CcTestSuite(name, root)
     95