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.orgimport signal
3033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org
3133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.orgfrom ..local import utils
3233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org
3333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.orgclass Output(object):
3433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org
3533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org  def __init__(self, exit_code, timed_out, stdout, stderr):
3633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    self.exit_code = exit_code
3733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    self.timed_out = timed_out
3833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    self.stdout = stdout
3933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    self.stderr = stderr
4033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org
4133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org  def HasCrashed(self):
4233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    if utils.IsWindows():
4333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org      return 0x80000000 & self.exit_code and not (0x3FFFFF00 & self.exit_code)
4433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    else:
4533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org      # Timed out tests will have exit_code -signal.SIGTERM.
4633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org      if self.timed_out:
4733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org        return False
4833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org      return (self.exit_code < 0 and
4933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org              self.exit_code != -signal.SIGABRT)
5033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org
5133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org  def HasTimedOut(self):
5233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    return self.timed_out
5333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org
5433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org  def Pack(self):
5533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    return [self.exit_code, self.timed_out, self.stdout, self.stderr]
5633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org
5733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org  @staticmethod
5833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org  def Unpack(packed):
5933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    # For the order of the fields, refer to Pack() above.
6033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org    return Output(packed[0], packed[1], packed[2], packed[3])
61