133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# Copyright 2012 the V8 project authors. All rights reserved.
233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# Redistribution and use in source and binary forms, with or without
333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# modification, are permitted provided that the following conditions are
433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# met:
533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org#
633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org#     * Redistributions of source code must retain the above copyright
733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org#       notice, this list of conditions and the following disclaimer.
833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org#     * Redistributions in binary form must reproduce the above
933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org#       copyright notice, this list of conditions and the following
1033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org#       disclaimer in the documentation and/or other materials provided
1133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org#       with the distribution.
1233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org#     * Neither the name of Google Inc. nor the names of its
1333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org#       contributors may be used to endorse or promote products derived
1433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org#       from this software without specific prior written permission.
1533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org#
1633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org
2833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org
2933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.orgfrom . import output
3033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org
3133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.orgclass TestCase(object):
3233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org  def __init__(self, suite, path, flags=[], dependency=None):
3333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    self.suite = suite  # TestSuite object
3433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    self.path = path    # string, e.g. 'div-mod', 'test-api/foo'
3533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    self.flags = flags  # list of strings, flags specific to this test case
3633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    self.dependency = dependency  # |path| for testcase that must be run first
3733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    self.outcomes = None
3833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    self.output = None
3933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    self.id = None  # int, used to map result back to TestCase instance
4033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    self.duration = None  # assigned during execution
41d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org    self.run = 1  # The nth time this test is executed.
4233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org
4333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org  def CopyAddingFlags(self, flags):
4433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    copy = TestCase(self.suite, self.path, self.flags + flags, self.dependency)
4533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    copy.outcomes = self.outcomes
4633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    return copy
4733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org
4833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org  def PackTask(self):
4933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    """
5033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    Extracts those parts of this object that are required to run the test
5133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    and returns them as a JSON serializable object.
5233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    """
5333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    assert self.id is not None
5433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    return [self.suitename(), self.path, self.flags,
5533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org            self.dependency, list(self.outcomes or []), self.id]
5633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org
5733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org  @staticmethod
5833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org  def UnpackTask(task):
5933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    """Creates a new TestCase object based on packed task data."""
6033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    # For the order of the fields, refer to PackTask() above.
6133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    test = TestCase(str(task[0]), task[1], task[2], task[3])
6233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    test.outcomes = set(task[4])
6333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    test.id = task[5]
64d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org    test.run = 1
6533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    return test
6633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org
6733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org  def SetSuiteObject(self, suites):
6833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    self.suite = suites[self.suite]
6933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org
7033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org  def PackResult(self):
7133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    """Serializes the output of the TestCase after it has run."""
7233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    self.suite.StripOutputForTransmit(self)
7333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    return [self.id, self.output.Pack(), self.duration]
7433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org
7533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org  def MergeResult(self, result):
7633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    """Applies the contents of a Result to this object."""
7733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    assert result[0] == self.id
7833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    self.output = output.Output.Unpack(result[1])
7933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    self.duration = result[2]
8033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org
8133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org  def suitename(self):
8233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    return self.suite.name
8333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org
8433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org  def GetLabel(self):
8533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    return self.suitename() + "/" + self.suite.CommonTestName(self)
86