Bug 833018 - Enable special ASan options for tests when running with low memory. r=jmaher,a=nonlibxul
authorChristian Holler <choller@mozilla.com>
Tue, 22 Jan 2013 16:48:02 +0100
changeset 125574 08c14f94fbb73b64f0338d8332fa28e0b26e0856
parent 125573 f3e2a5e354bdbc931d049f2a625771726bb86e21
child 125575 498f53cdde20ad4f6074cad6d6b8f8915dee6e1f
push idunknown
push userunknown
push dateunknown
reviewersjmaher, nonlibxul
bugs833018
milestone21.0a1
Bug 833018 - Enable special ASan options for tests when running with low memory. r=jmaher,a=nonlibxul
build/automation-build.mk
build/automation.py.in
testing/mochitest/runtests.py
--- a/build/automation-build.mk
+++ b/build/automation-build.mk
@@ -55,13 +55,19 @@ AUTOMATION_PPARGS += -DIS_DEBUG_BUILD=0
 endif
 
 ifdef MOZ_CRASHREPORTER
 AUTOMATION_PPARGS += -DCRASHREPORTER=1
 else
 AUTOMATION_PPARGS += -DCRASHREPORTER=0
 endif
 
+ifdef MOZ_ASAN
+AUTOMATION_PPARGS += -DIS_ASAN=1
+else
+AUTOMATION_PPARGS += -DIS_ASAN=0
+endif
+
 automation.py: $(MOZILLA_DIR)/build/automation.py.in $(MOZILLA_DIR)/build/automation-build.mk
 	$(PYTHON) $(MOZILLA_DIR)/config/Preprocessor.py \
 	$(AUTOMATION_PPARGS) $(DEFINES) $(ACDEFINES) $< > $@
 
 GARBAGE += automation.py automation.pyc
--- a/build/automation.py.in
+++ b/build/automation.py.in
@@ -48,16 +48,17 @@ import automationutils
 #expand _BIN_SUFFIX = __BIN_SUFFIX__
 #expand _PERL = __PERL__
 
 #expand _DEFAULT_APP = "./" + __BROWSER_PATH__
 #expand _CERTS_SRC_DIR = __CERTS_SRC_DIR__
 #expand _IS_TEST_BUILD = __IS_TEST_BUILD__
 #expand _IS_DEBUG_BUILD = __IS_DEBUG_BUILD__
 #expand _CRASHREPORTER = __CRASHREPORTER__ == 1
+#expand _IS_ASAN = __IS_ASAN__ == 1
 
 
 if _IS_WIN32:
   import ctypes, ctypes.wintypes, time, msvcrt
 else:
   import errno
 
 
@@ -116,16 +117,17 @@ class Automation(object):
 
   UNIXISH = not IS_WIN32 and not IS_MAC
 
   DEFAULT_APP = _DEFAULT_APP
   CERTS_SRC_DIR = _CERTS_SRC_DIR
   IS_TEST_BUILD = _IS_TEST_BUILD
   IS_DEBUG_BUILD = _IS_DEBUG_BUILD
   CRASHREPORTER = _CRASHREPORTER
+  IS_ASAN = _IS_ASAN
 
   # timeout, in seconds
   DEFAULT_TIMEOUT = 60.0
   DEFAULT_WEB_SERVER = _DEFAULT_WEB_SERVER
   DEFAULT_HTTP_PORT = _DEFAULT_HTTP_PORT
   DEFAULT_SSL_PORT = _DEFAULT_SSL_PORT
   DEFAULT_WEBSOCKET_PORT = _DEFAULT_WEBSOCKET_PORT
 
@@ -808,16 +810,33 @@ user_pref("camino.use_system_proxy_setti
       env['MOZ_CRASHREPORTER_NO_REPORT'] = '1'
       env['MOZ_CRASHREPORTER'] = '1'
     else:
       env['MOZ_CRASHREPORTER_DISABLE'] = '1'
 
     env['GNOME_DISABLE_CRASH_DIALOG'] = '1'
     env['XRE_NO_WINDOWS_CRASH_DIALOG'] = '1'
     env['NS_TRACE_MALLOC_DISABLE_STACKS'] = '1'
+
+    # ASan specific environment stuff
+    if self.IS_ASAN and (self.IS_LINUX or self.IS_MAC):
+      try:
+        totalMemory = int(os.popen("free").readlines()[1].split()[1])
+
+        # Only 2 GB RAM or less available? Use custom ASan options to reduce
+        # the amount of resources required to do the tests. Standard options 
+        # will otherwise lead to OOM conditions on the current test slaves.
+        if totalMemory <= 1024 * 1024 * 2:
+          self.log.info("INFO | automation.py | ASan running in low-memory configuration")
+          env["ASAN_OPTIONS"] = "quarantine_size=50331648:redzone=64"
+      except OSError,err:
+        self.log.info("Failed determine available memory, disabling ASan low-memory configuration: %s", err.strerror)
+      except:
+        self.log.info("Failed determine available memory, disabling ASan low-memory configuration")
+
     return env
 
   if IS_WIN32:
     PeekNamedPipe = ctypes.windll.kernel32.PeekNamedPipe
     GetLastError = ctypes.windll.kernel32.GetLastError
 
     def readWithTimeout(self, f, timeout):
       """Try to read a line of output from the file object |f|.
--- a/testing/mochitest/runtests.py
+++ b/testing/mochitest/runtests.py
@@ -384,16 +384,23 @@ class MochitestServer:
     self.shutdownURL = "http://%(server)s:%(port)s/server/shutdown" % { "server" : self.webServer, "port" : self.httpPort }
     self.testPrefix = "'webapprt_'" if options.webapprtContent else "undefined"
 
   def start(self):
     "Run the Mochitest server, returning the process ID of the server."
     
     env = self._automation.environment(xrePath = self._xrePath)
     env["XPCOM_DEBUG_BREAK"] = "warn"
+
+    # When running with an ASan build, our xpcshell server will also be ASan-enabled,
+    # thus consuming too much resources when running together with the browser on
+    # the test slaves. Try to limit the amount of resources by disabling certain
+    # features.
+    env["ASAN_OPTIONS"] = "quarantine_size=1:redzone=32"
+
     if self._automation.IS_WIN32:
       env["PATH"] = env["PATH"] + ";" + self._xrePath
 
     args = ["-g", self._xrePath,
             "-v", "170",
             "-f", "./" + "httpd.js",
             "-e", """const _PROFILE_PATH = '%(profile)s';const _SERVER_PORT = '%(port)s'; const _SERVER_ADDR = '%(server)s';
                      const _TEST_PREFIX = %(testPrefix)s; const _DISPLAY_RESULTS = %(displayResults)s;""" %