Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame^] | 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 | CCTEST_DEBUG_FLAGS = ['--enable-slow-asserts', '--debug-code', '--verify-heap'] |
| 35 | |
| 36 | |
| 37 | class CcTestCase(test.TestCase): |
| 38 | |
| 39 | def __init__(self, path, executable, mode, raw_name, dependency, context): |
| 40 | super(CcTestCase, self).__init__(context, path) |
| 41 | self.executable = executable |
| 42 | self.mode = mode |
| 43 | self.raw_name = raw_name |
| 44 | self.dependency = dependency |
| 45 | |
| 46 | def GetLabel(self): |
| 47 | return "%s %s %s" % (self.mode, self.path[-2], self.path[-1]) |
| 48 | |
| 49 | def GetName(self): |
| 50 | return self.path[-1] |
| 51 | |
| 52 | def BuildCommand(self, name): |
| 53 | serialization_file = join('obj', 'test', self.mode, 'serdes') |
| 54 | serialization_file += '_' + self.GetName() |
| 55 | serialization_option = '--testing_serialization_file=' + serialization_file |
| 56 | result = [ self.executable, name, serialization_option ] |
| 57 | if self.mode == 'debug': |
| 58 | result += CCTEST_DEBUG_FLAGS |
| 59 | return result |
| 60 | |
| 61 | def GetCommand(self): |
| 62 | return self.BuildCommand(self.raw_name) |
| 63 | |
| 64 | def Run(self): |
| 65 | if self.dependency != '': |
| 66 | dependent_command = self.BuildCommand(self.dependency) |
| 67 | output = self.RunCommand(dependent_command) |
| 68 | if output.HasFailed(): |
| 69 | return output |
| 70 | return test.TestCase.Run(self) |
| 71 | |
| 72 | |
| 73 | class CcTestConfiguration(test.TestConfiguration): |
| 74 | |
| 75 | def __init__(self, context, root): |
| 76 | super(CcTestConfiguration, self).__init__(context, root) |
| 77 | |
| 78 | def GetBuildRequirements(self): |
| 79 | return ['cctests'] |
| 80 | |
| 81 | def ListTests(self, current_path, path, mode): |
| 82 | executable = join('obj', 'test', mode, 'cctest') |
| 83 | if utils.IsWindows(): |
| 84 | executable += '.exe' |
| 85 | output = test.Execute([executable, '--list'], self.context) |
| 86 | if output.exit_code != 0: |
| 87 | print output.stdout |
| 88 | print output.stderr |
| 89 | return [] |
| 90 | result = [] |
| 91 | for test_desc in output.stdout.strip().split(): |
| 92 | raw_test, dependency = test_desc.split('<') |
| 93 | relative_path = raw_test.split('/') |
| 94 | full_path = current_path + relative_path |
| 95 | if dependency != '': |
| 96 | dependency = relative_path[0] + '/' + dependency |
| 97 | if self.Contains(path, full_path): |
| 98 | result.append(CcTestCase(full_path, executable, mode, raw_test, dependency, self.context)) |
| 99 | return result |
| 100 | |
| 101 | def GetTestStatus(self, sections, defs): |
| 102 | status_file = join(self.root, 'cctest.status') |
| 103 | if exists(status_file): |
| 104 | test.ReadConfigurationInto(status_file, sections, defs) |
| 105 | |
| 106 | |
| 107 | def GetConfiguration(context, root): |
| 108 | return CcTestConfiguration(context, root) |