Bug 1333003 part 6 - Fix test scripts to run ASan on Windows. r?ted draft
authorTing-Yu Chou <janus926@gmail.com>
Fri, 10 Mar 2017 12:08:34 +0800
changeset 503561 15a744912867f4e91dab2b1b5ae67056bf54381a
parent 503560 b4d9764de3c62319122c6cc2cf453193d18cd18b
child 503562 2bd0c944eb016475e12efe86621e6be958cbf193
push id50622
push userbmo:janus926@gmail.com
push dateThu, 23 Mar 2017 10:00:07 +0000
reviewersted
bugs1333003
milestone55.0a1
Bug 1333003 part 6 - Fix test scripts to run ASan on Windows. r?ted MozReview-Commit-ID: 6F9UXgTRb2Y
testing/gtest/rungtests.py
testing/mochitest/runtests.py
testing/mozbase/mozrunner/mozrunner/utils.py
testing/runcppunittests.py
testing/xpcshell/runxpcshelltests.py
--- a/testing/gtest/rungtests.py
+++ b/testing/gtest/rungtests.py
@@ -123,17 +123,19 @@ class GTests(object):
             if pathvar in env:
                 env[pathvar] = "%s%s%s" % (self.xre_path, os.pathsep, env[pathvar])
             else:
                 env[pathvar] = self.xre_path
 
         # ASan specific environment stuff
         if mozinfo.info["asan"]:
             # Symbolizer support
-            llvmsym = os.path.join(self.xre_path, "llvm-symbolizer")
+            llvmsym = os.path.join(
+                self.xre_path,
+                "llvm-symbolizer" + mozinfo.info["bin_suffix"].encode('ascii'))
             if os.path.isfile(llvmsym):
                 env["ASAN_SYMBOLIZER_PATH"] = llvmsym
                 log.info("gtest | ASan using symbolizer at %s", llvmsym)
             else:
                 # This should be |testFail| instead of |info|. See bug 1050891.
                 log.info("gtest | Failed to find ASan symbolizer at %s", llvmsym)
 
         return env
--- a/testing/mochitest/runtests.py
+++ b/testing/mochitest/runtests.py
@@ -1549,17 +1549,17 @@ toolbar#nav-bar {
             d['closeWhenDone'] = '1'
         content = json.dumps(d)
 
         with open(os.path.join(options.profilePath, "testConfig.js"), "w") as config:
             config.write(content)
 
     def buildBrowserEnv(self, options, debugger=False, env=None):
         """build the environment variables for the specific test and operating system"""
-        if mozinfo.info["asan"]:
+        if mozinfo.info["asan"] and mozinfo.isLinux and mozinfo.bits == 64:
             lsanPath = SCRIPT_DIR
         else:
             lsanPath = None
 
         browserEnv = self.environment(
             xrePath=options.xrePath,
             env=env,
             debugger=debugger,
@@ -2024,17 +2024,17 @@ toolbar#nav-bar {
             args.append('-foreground')
             self.start_script_kwargs['testUrl'] = testUrl or 'about:blank'
 
             if detectShutdownLeaks:
                 shutdownLeaks = ShutdownLeaks(self.log)
             else:
                 shutdownLeaks = None
 
-            if mozinfo.info["asan"] and (mozinfo.isLinux or mozinfo.isMac):
+            if mozinfo.info["asan"] and mozinfo.isLinux and mozinfo.bits == 64:
                 lsanLeaks = LSANLeaks(self.log)
             else:
                 lsanLeaks = None
 
             # create an instance to process the output
             outputHandler = self.OutputHandler(
                 harness=self,
                 utilityPath=utilityPath,
--- a/testing/mozbase/mozrunner/mozrunner/utils.py
+++ b/testing/mozbase/mozrunner/mozrunner/utils.py
@@ -148,31 +148,36 @@ def test_environment(xrePath, env=None, 
         'signaling:3,mtransport:4,DataChannel:4,jsep:4,MediaPipelineFactory:4'
     )
     env.setdefault('R_LOG_LEVEL', '6')
     env.setdefault('R_LOG_DESTINATION', 'stderr')
     env.setdefault('R_LOG_VERBOSE', '1')
 
     # ASan specific environment stuff
     asan = bool(mozinfo.info.get("asan"))
-    if asan and (mozinfo.isLinux or mozinfo.isMac):
+    if asan:
         try:
             # Symbolizer support
-            llvmsym = os.path.join(xrePath, "llvm-symbolizer")
+            llvmsym = os.path.join(
+                xrePath,
+                "llvm-symbolizer" + mozinfo.info["bin_suffix"].encode('ascii'))
             if os.path.isfile(llvmsym):
                 env["ASAN_SYMBOLIZER_PATH"] = llvmsym
                 log.info("INFO | runtests.py | ASan using symbolizer at %s"
                          % llvmsym)
             else:
                 log.info("TEST-UNEXPECTED-FAIL | runtests.py | Failed to find"
                          " ASan symbolizer at %s" % llvmsym)
 
             # Returns total system memory in kilobytes.
-            # Works only on unix-like platforms where `free` is in the path.
-            totalMemory = int(os.popen("free").readlines()[1].split()[1])
+            if mozinfo.isWin:
+                totalMemory = int(
+                    os.popen("wmic computersystem get TotalPhysicalMemory").readlines()[1]) / 1024
+            else:
+                totalMemory = int(os.popen("free").readlines()[1].split()[1])
 
             # Only 4 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.
             message = "INFO | runtests.py | ASan running in %s configuration"
             asanOptions = []
             if totalMemory <= 1024 * 1024 * 4:
                 message = message % 'low-memory'
--- a/testing/runcppunittests.py
+++ b/testing/runcppunittests.py
@@ -118,17 +118,19 @@ class CPPUnitTests(object):
         if pathvar:
             if pathvar in env:
                 env[pathvar] = "%s%s%s" % (libpath, os.pathsep, env[pathvar])
             else:
                 env[pathvar] = libpath
 
         if mozinfo.info["asan"]:
             # Use llvm-symbolizer for ASan if available/required
-            llvmsym = os.path.join(self.xre_path, "llvm-symbolizer")
+            llvmsym = os.path.join(
+                self.xre_path,
+                "llvm-symbolizer" + mozinfo.info["bin_suffix"].encode('ascii'))
             if os.path.isfile(llvmsym):
                 env["ASAN_SYMBOLIZER_PATH"] = llvmsym
                 self.log.info("ASan using symbolizer at %s" % llvmsym)
             else:
                 self.log.info("Failed to find ASan symbolizer at %s" % llvmsym)
 
             # media/mtransport tests statically link in NSS, which
             # causes ODR violations. See bug 1215679.
--- a/testing/xpcshell/runxpcshelltests.py
+++ b/testing/xpcshell/runxpcshelltests.py
@@ -937,17 +937,19 @@ class XPCShellTests(object):
                 self.env["LD_LIBRARY_PATH"] = self.xrePath
             else:
                 self.env["LD_LIBRARY_PATH"] = ":".join([self.xrePath, self.env["LD_LIBRARY_PATH"]])
 
         usingASan = "asan" in self.mozInfo and self.mozInfo["asan"]
         usingTSan = "tsan" in self.mozInfo and self.mozInfo["tsan"]
         if usingASan or usingTSan:
             # symbolizer support
-            llvmsym = os.path.join(self.xrePath, "llvm-symbolizer")
+            llvmsym = os.path.join(
+                self.xrePath,
+                "llvm-symbolizer" + self.mozInfo["bin_suffix"].encode('ascii'))
             if os.path.isfile(llvmsym):
                 if usingASan:
                     self.env["ASAN_SYMBOLIZER_PATH"] = llvmsym
                 else:
                     oldTSanOptions = self.env.get("TSAN_OPTIONS", "")
                     self.env["TSAN_OPTIONS"] = "external_symbolizer_path={} {}".format(llvmsym, oldTSanOptions)
                 self.log.info("runxpcshelltests.py | using symbolizer at %s" % llvmsym)
             else: