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 29from . import output 30 31class TestCase(object): 32 def __init__(self, suite, path, flags=[], dependency=None): 33 self.suite = suite # TestSuite object 34 self.path = path # string, e.g. 'div-mod', 'test-api/foo' 35 self.flags = flags # list of strings, flags specific to this test case 36 self.dependency = dependency # |path| for testcase that must be run first 37 self.outcomes = None 38 self.output = None 39 self.id = None # int, used to map result back to TestCase instance 40 self.duration = None # assigned during execution 41 self.run = 1 # The nth time this test is executed. 42 43 def CopyAddingFlags(self, flags): 44 copy = TestCase(self.suite, self.path, self.flags + flags, self.dependency) 45 copy.outcomes = self.outcomes 46 return copy 47 48 def PackTask(self): 49 """ 50 Extracts those parts of this object that are required to run the test 51 and returns them as a JSON serializable object. 52 """ 53 assert self.id is not None 54 return [self.suitename(), self.path, self.flags, 55 self.dependency, list(self.outcomes or []), self.id] 56 57 @staticmethod 58 def UnpackTask(task): 59 """Creates a new TestCase object based on packed task data.""" 60 # For the order of the fields, refer to PackTask() above. 61 test = TestCase(str(task[0]), task[1], task[2], task[3]) 62 test.outcomes = set(task[4]) 63 test.id = task[5] 64 test.run = 1 65 return test 66 67 def SetSuiteObject(self, suites): 68 self.suite = suites[self.suite] 69 70 def PackResult(self): 71 """Serializes the output of the TestCase after it has run.""" 72 self.suite.StripOutputForTransmit(self) 73 return [self.id, self.output.Pack(), self.duration] 74 75 def MergeResult(self, result): 76 """Applies the contents of a Result to this object.""" 77 assert result[0] == self.id 78 self.output = output.Output.Unpack(result[1]) 79 self.duration = result[2] 80 81 def suitename(self): 82 return self.suite.name 83 84 def GetLabel(self): 85 return self.suitename() + "/" + self.suite.CommonTestName(self) 86