| OLD | NEW |
| 1 # Copyright 2012 the V8 project authors. All rights reserved. | 1 # Copyright 2012 the V8 project authors. All rights reserved. |
| 2 # Redistribution and use in source and binary forms, with or without | 2 # Redistribution and use in source and binary forms, with or without |
| 3 # modification, are permitted provided that the following conditions are | 3 # modification, are permitted provided that the following conditions are |
| 4 # met: | 4 # met: |
| 5 # | 5 # |
| 6 # * Redistributions of source code must retain the above copyright | 6 # * Redistributions of source code must retain the above copyright |
| 7 # notice, this list of conditions and the following disclaimer. | 7 # notice, this list of conditions and the following disclaimer. |
| 8 # * Redistributions in binary form must reproduce the above | 8 # * Redistributions in binary form must reproduce the above |
| 9 # copyright notice, this list of conditions and the following | 9 # copyright notice, this list of conditions and the following |
| 10 # disclaimer in the documentation and/or other materials provided | 10 # disclaimer in the documentation and/or other materials provided |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 | 28 |
| 29 from . import output | 29 from . import output |
| 30 | 30 |
| 31 class TestCase(object): | 31 class TestCase(object): |
| 32 def __init__(self, suite, path, variant='default', flags=None, | 32 def __init__(self, suite, path, variant='default', flags=None, |
| 33 dependency=None): | 33 dependency=None, override_shell=None): |
| 34 self.suite = suite # TestSuite object | 34 self.suite = suite # TestSuite object |
| 35 self.path = path # string, e.g. 'div-mod', 'test-api/foo' | 35 self.path = path # string, e.g. 'div-mod', 'test-api/foo' |
| 36 self.flags = flags or [] # list of strings, flags specific to this test | 36 self.flags = flags or [] # list of strings, flags specific to this test |
| 37 self.variant = variant # name of the used testing variant | 37 self.variant = variant # name of the used testing variant |
| 38 self.dependency = dependency # |path| for testcase that must be run first | 38 self.dependency = dependency # |path| for testcase that must be run first |
| 39 self.override_shell = override_shell |
| 39 self.outcomes = set([]) | 40 self.outcomes = set([]) |
| 40 self.output = None | 41 self.output = None |
| 41 self.id = None # int, used to map result back to TestCase instance | 42 self.id = None # int, used to map result back to TestCase instance |
| 42 self.duration = None # assigned during execution | 43 self.duration = None # assigned during execution |
| 43 self.run = 1 # The nth time this test is executed. | 44 self.run = 1 # The nth time this test is executed. |
| 44 | 45 |
| 45 def CopyAddingFlags(self, variant, flags): | 46 def CopyAddingFlags(self, variant, flags): |
| 46 copy = TestCase(self.suite, self.path, variant, self.flags + flags, | 47 copy = TestCase(self.suite, self.path, variant, self.flags + flags, |
| 47 self.dependency) | 48 self.dependency, self.override_shell) |
| 48 copy.outcomes = self.outcomes | 49 copy.outcomes = self.outcomes |
| 49 return copy | 50 return copy |
| 50 | 51 |
| 51 def PackTask(self): | 52 def PackTask(self): |
| 52 """ | 53 """ |
| 53 Extracts those parts of this object that are required to run the test | 54 Extracts those parts of this object that are required to run the test |
| 54 and returns them as a JSON serializable object. | 55 and returns them as a JSON serializable object. |
| 55 """ | 56 """ |
| 56 assert self.id is not None | 57 assert self.id is not None |
| 57 return [self.suitename(), self.path, self.variant, self.flags, | 58 return [self.suitename(), self.path, self.variant, self.flags, |
| 58 self.dependency, list(self.outcomes or []), self.id] | 59 self.dependency, self.override_shell, list(self.outcomes or []), |
| 60 self.id] |
| 59 | 61 |
| 60 @staticmethod | 62 @staticmethod |
| 61 def UnpackTask(task): | 63 def UnpackTask(task): |
| 62 """Creates a new TestCase object based on packed task data.""" | 64 """Creates a new TestCase object based on packed task data.""" |
| 63 # For the order of the fields, refer to PackTask() above. | 65 # For the order of the fields, refer to PackTask() above. |
| 64 test = TestCase(str(task[0]), task[1], task[2], task[3], task[4]) | 66 test = TestCase(str(task[0]), task[1], task[2], task[3], task[4], task[5]) |
| 65 test.outcomes = set(task[5]) | 67 test.outcomes = set(task[6]) |
| 66 test.id = task[6] | 68 test.id = task[7] |
| 67 test.run = 1 | 69 test.run = 1 |
| 68 return test | 70 return test |
| 69 | 71 |
| 70 def SetSuiteObject(self, suites): | 72 def SetSuiteObject(self, suites): |
| 71 self.suite = suites[self.suite] | 73 self.suite = suites[self.suite] |
| 72 | 74 |
| 73 def PackResult(self): | 75 def PackResult(self): |
| 74 """Serializes the output of the TestCase after it has run.""" | 76 """Serializes the output of the TestCase after it has run.""" |
| 75 self.suite.StripOutputForTransmit(self) | 77 self.suite.StripOutputForTransmit(self) |
| 76 return [self.id, self.output.Pack(), self.duration] | 78 return [self.id, self.output.Pack(), self.duration] |
| 77 | 79 |
| 78 def MergeResult(self, result): | 80 def MergeResult(self, result): |
| 79 """Applies the contents of a Result to this object.""" | 81 """Applies the contents of a Result to this object.""" |
| 80 assert result[0] == self.id | 82 assert result[0] == self.id |
| 81 self.output = output.Output.Unpack(result[1]) | 83 self.output = output.Output.Unpack(result[1]) |
| 82 self.duration = result[2] | 84 self.duration = result[2] |
| 83 | 85 |
| 84 def suitename(self): | 86 def suitename(self): |
| 85 return self.suite.name | 87 return self.suite.name |
| 86 | 88 |
| 87 def GetLabel(self): | 89 def GetLabel(self): |
| 88 return self.suitename() + "/" + self.suite.CommonTestName(self) | 90 return self.suitename() + "/" + self.suite.CommonTestName(self) |
| 89 | 91 |
| 92 def shell(self): |
| 93 if self.override_shell: |
| 94 return self.override_shell |
| 95 return self.suite.shell() |
| 96 |
| 90 def __getstate__(self): | 97 def __getstate__(self): |
| 91 """Representation to pickle test cases. | 98 """Representation to pickle test cases. |
| 92 | 99 |
| 93 The original suite won't be sent beyond process boundaries. Instead | 100 The original suite won't be sent beyond process boundaries. Instead |
| 94 send the name only and retrieve a process-local suite later. | 101 send the name only and retrieve a process-local suite later. |
| 95 """ | 102 """ |
| 96 return dict(self.__dict__, suite=self.suite.name) | 103 return dict(self.__dict__, suite=self.suite.name) |
| OLD | NEW |