build/automationutils.py
author Phil Ringnalda <philringnalda@gmail.com>
Sat, 13 Jun 2009 11:53:38 -0700
changeset 29200 ee3149258d6402bf71e29dc0032f1ea46303d3ce
parent 28231 6461b3507d98608fd398992b0306de679420fb4b
child 31995 f6bf83b50648c8039699e08e62519489f8eb84fd
permissions -rw-r--r--
Bug 495021 - CAPS unconditionally builds tests, r=shaver

import sys, glob, os, subprocess, logging

__all__ = [
    "addCommonOptions",
    "checkForCrashes",
    ]

log = logging.getLogger()

def addCommonOptions(parser, defaults={}):
    parser.add_option("--xre-path",
                      action = "store", type = "string", dest = "xrePath",
                      # individual scripts will set a sane default
                      default = None,
                      help = "absolute path to directory containing XRE (probably xulrunner)")
    if 'SYMBOLS_PATH' not in defaults:
        defaults['SYMBOLS_PATH'] = None
    parser.add_option("--symbols-path",
                      action = "store", type = "string", dest = "symbolsPath",
                      default = defaults['SYMBOLS_PATH'],
                      help = "absolute path to directory containing breakpad symbols")

def checkForCrashes(dumpDir, symbolsPath, testName=None):
  stackwalkPath = os.environ.get('MINIDUMP_STACKWALK', None)
  # try to get the caller's filename if no test name is given
  if testName is None:
      try:
          testName = os.path.basename(sys._getframe(1).f_code.co_filename)
      except:
          testName = "unknown"

  foundCrash = False
  dumps = glob.glob(os.path.join(dumpDir, '*.dmp'))
  for d in dumps:
    log.info("TEST-UNEXPECTED-FAIL | %s | application crashed (minidump found)", testName)
    if symbolsPath and stackwalkPath:
      nullfd = open(os.devnull, 'w')
      # eat minidump_stackwalk errors
      subprocess.call([stackwalkPath, d, symbolsPath], stderr=nullfd)
      nullfd.close()
    os.remove(d)
    extra = os.path.splitext(d)[0] + ".extra"
    if os.path.exists(extra):
        os.remove(extra)
    foundCrash = True
  return foundCrash