Bug 1312964 - Add linux64-fuzz to TC and run *Fuzz* gtests r=franziskus
authorTim Taubert <ttaubert@mozilla.com>
Wed, 26 Oct 2016 14:35:36 +0200
changeset 12764 ab8881862b6c3a08fafae6cb84d12f5f3ed108a3
parent 12763 f1188a6a13d94120037c71a98c13a609c57b4b8b
child 12765 431d58ac12ad793db441c1331a012646bb71f6af
push id1706
push userttaubert@mozilla.com
push dateWed, 26 Oct 2016 12:36:26 +0000
reviewersfranziskus
bugs1312964
Bug 1312964 - Add linux64-fuzz to TC and run *Fuzz* gtests r=franziskus Differential Revision: https://nss-dev.phacility.com/D122
automation/taskcluster/graph/src/extend.js
automation/taskcluster/graph/src/try_syntax.js
automation/taskcluster/scripts/build_gyp.sh
external_tests/der_gtest/der_gtest.gyp
external_tests/util_gtest/util_gtest.gyp
lib/freebl/loader.c
tests/gtests/gtests.sh
--- a/automation/taskcluster/graph/src/extend.js
+++ b/automation/taskcluster/graph/src/extend.js
@@ -153,16 +153,18 @@ export default async function main() {
   await scheduleWindows("Windows 2012 64 (opt)", {
     env: {BUILD_OPT: "1"}
   });
 
   await scheduleWindows("Windows 2012 64 (debug)", {
     collection: "debug"
   });
 
+  await scheduleFuzzing();
+
   await scheduleTools();
 
   await scheduleLinux("Linux 32 (ARM, debug)", {
     image: "franziskus/nss-arm-ci",
     provisioner: "localprovisioner",
     collection: "arm-debug",
     workerType: "nss-rpi",
     platform: "linux32",
@@ -251,16 +253,75 @@ async function scheduleLinux(name, base)
     symbol: "noLibpkix"
   }));
 
   return queue.submit();
 }
 
 /*****************************************************************************/
 
+async function scheduleFuzzing() {
+  let base = {
+    env: {
+      ASAN_OPTIONS: "allocator_may_return_null=1",
+      UBSAN_OPTIONS: "print_stacktrace=1",
+      CC: "clang",
+      CCC: "clang++",
+      USE_64: "1"
+    },
+    platform: "linux64",
+    collection: "fuzz",
+    image: LINUX_IMAGE
+  };
+
+  // Build base definition.
+  let build_base = merge({
+    command: [
+      "/bin/bash",
+      "-c",
+      "bin/checkout.sh && " +
+      "nss/automation/taskcluster/scripts/build_gyp.sh -g -v --fuzz"
+    ],
+    artifacts: {
+      public: {
+        expires: 24 * 7,
+        type: "directory",
+        path: "/home/worker/artifacts"
+      }
+    },
+    kind: "build",
+    symbol: "B"
+  }, base);
+
+  // The task that builds NSPR+NSS.
+  let task_build = queue.scheduleTask(merge(build_base, {
+    name: "Linux x64 (debug, fuzz)"
+  }));
+
+  // Schedule tests.
+  queue.scheduleTask(merge(base, {
+    parent: task_build,
+    name: "Gtests",
+    command: [
+      "/bin/bash",
+      "-c",
+      "bin/checkout.sh && nss/automation/taskcluster/scripts/run_tests.sh"
+    ],
+    env: {GTESTFILTER: "*Fuzz*"},
+    symbol: "Gtest",
+    tests: "gtests",
+    cycle: "standard",
+    kind: "test"
+  }));
+
+  return queue.submit();
+}
+
+/*****************************************************************************/
+
 async function scheduleWindows(name, base) {
   base = merge(base, {
     workerType: "nss-win2012r2",
     platform: "windows2012-64",
     env: {
       PATH: "c:\\mozilla-build\\python;c:\\mozilla-build\\msys\\local\\bin;" +
             "c:\\mozilla-build\\7zip;c:\\mozilla-build\\info-zip;" +
             "c:\\mozilla-build\\python\\Scripts;c:\\mozilla-build\\yasm;" +
--- a/automation/taskcluster/graph/src/try_syntax.js
+++ b/automation/taskcluster/graph/src/try_syntax.js
@@ -17,17 +17,18 @@ function parseOptions(opts) {
   let builds = intersect(opts.build.split(""), ["d", "o"]);
 
   // If the given value is nonsense default to debug and opt builds.
   if (builds.length == 0) {
     builds = ["d", "o"];
   }
 
   // Parse platforms.
-  let allPlatforms = ["linux", "linux64", "linux64-asan", "win64", "arm", "linux64-gyp"];
+  let allPlatforms = ["linux", "linux64", "linux64-asan", "win64", "arm",
+                      "linux64-gyp", "linux64-fuzz"];
   let platforms = intersect(opts.platform.split(/\s*,\s*/), allPlatforms);
 
   // If the given value is nonsense or "none" default to all platforms.
   if (platforms.length == 0 && opts.platform != "none") {
     platforms = allPlatforms;
   }
 
   // Parse unit tests.
@@ -96,44 +97,48 @@ function filter(opts) {
 
     let coll = name => name == (task.collection || "opt");
 
     // Filter by platform.
     let found = opts.platforms.some(platform => {
       let aliases = {
         "linux": "linux32",
         "linux64-asan": "linux64",
+        "linux64-fuzz": "linux64",
         "linux64-gyp": "linux64",
         "win64": "windows2012-64",
         "arm": "linux32"
       };
 
       // Check the platform name.
       let keep = (task.platform == (aliases[platform] || platform));
 
       // Additional checks.
       if (platform == "linux64-asan") {
         keep &= coll("asan") || coll("ubsan");
       } else if (platform == "arm") {
         keep &= coll("arm-opt") || coll("arm-debug");
       } else if (platform == "linux64-gyp") {
         keep &= coll("gyp");
+      } else if (platform == "linux64-fuzz") {
+        keep &= coll("fuzz");
       } else {
         keep &= coll("opt") || coll("debug");
       }
 
       return keep;
     });
 
     if (!found) {
       return false;
     }
 
     // Finally, filter by build type.
-    let isDebug = coll("debug") || coll("asan") || coll("ubsan") || coll("arm-debug") || coll("gyp");
+    let isDebug = coll("debug") || coll("asan") || coll("ubsan") ||
+                  coll("arm-debug") || coll("gyp") || coll("fuzz");
     return (isDebug && opts.builds.includes("d")) ||
            (!isDebug && opts.builds.includes("o"));
   }
 }
 
 export function initFilter() {
   let comment = process.env.TC_COMMENT || "";
 
--- a/automation/taskcluster/scripts/build_gyp.sh
+++ b/automation/taskcluster/scripts/build_gyp.sh
@@ -1,18 +1,18 @@
 #!/usr/bin/env bash
 
 source $(dirname $0)/tools.sh
 
 if [[ $(id -u) -eq 0 ]]; then
     # Drop privileges by re-running this script.
-    exec su worker $0
+    exec su worker -c "$0 $*"
 fi
 
 # Clone NSPR if needed.
 hg_clone https://hg.mozilla.org/projects/nspr nspr default
 
 # Build.
-nss/build.sh -g -v
+nss/build.sh ${*-"-g -v"}
 
 # Package.
 mkdir artifacts
 tar cvfjh artifacts/dist.tar.bz2 dist
--- a/external_tests/der_gtest/der_gtest.gyp
+++ b/external_tests/der_gtest/der_gtest.gyp
@@ -11,22 +11,17 @@
       'target_name': 'der_gtest',
       'type': 'executable',
       'sources': [
         'der_getint_unittest.cc',
         '<(DEPTH)/external_tests/common/gtests.cc'
       ],
       'dependencies': [
         '<(DEPTH)/exports.gyp:nss_exports',
-        '<(DEPTH)/lib/nss/nss.gyp:nss3',
-        '<(DEPTH)/lib/util/util.gyp:nssutil3',
-        '<(DEPTH)/lib/smime/smime.gyp:smime3',
-        '<(DEPTH)/lib/ssl/ssl.gyp:ssl3',
         '<(DEPTH)/external_tests/google_test/google_test.gyp:gtest',
-        '<(DEPTH)/cmd/lib/lib.gyp:sectool'
       ]
     }
   ],
   'target_defaults': {
     'include_dirs': [
       '../../external_tests/google_test/gtest/include',
       '../../external_tests/common'
     ]
--- a/external_tests/util_gtest/util_gtest.gyp
+++ b/external_tests/util_gtest/util_gtest.gyp
@@ -11,23 +11,18 @@
       'target_name': 'util_gtest',
       'type': 'executable',
       'sources': [
         'util_utf8_unittest.cc',
         '<(DEPTH)/external_tests/common/gtests.cc'
       ],
       'dependencies': [
         '<(DEPTH)/exports.gyp:nss_exports',
-        '<(DEPTH)/lib/nss/nss.gyp:nss3',
-        '<(DEPTH)/lib/util/util.gyp:nssutil3',
-        '<(DEPTH)/lib/smime/smime.gyp:smime3',
-        '<(DEPTH)/lib/ssl/ssl.gyp:ssl3',
         '<(DEPTH)/external_tests/google_test/google_test.gyp:gtest',
         '<(DEPTH)/lib/util/util.gyp:nssutil',
-        '<(DEPTH)/cmd/lib/lib.gyp:sectool'
       ]
     }
   ],
   'target_defaults': {
     'include_dirs': [
       '../../external_tests/google_test/gtest/include',
       '../../external_tests/common',
       '../../lib/util'
--- a/lib/freebl/loader.c
+++ b/lib/freebl/loader.c
@@ -809,17 +809,17 @@ BL_Unload(void)
 {
     /* This function is not thread-safe, but doesn't need to be, because it is
      * only called from functions that are also defined as not thread-safe,
      * namely C_Finalize in softoken, and the SSL bypass shutdown callback called
      * from NSS_Shutdown. */
     char *disableUnload = NULL;
     vector = NULL;
     disableUnload = PR_GetEnvSecure("NSS_DISABLE_UNLOAD");
-    if (!disableUnload) {
+    if (blLib && !disableUnload) {
 #ifdef DEBUG
         PRStatus status = PR_UnloadLibrary(blLib);
         PORT_Assert(PR_SUCCESS == status);
 #else
         PR_UnloadLibrary(blLib);
 #endif
     }
     blLib = NULL;
--- a/tests/gtests/gtests.sh
+++ b/tests/gtests/gtests.sh
@@ -50,17 +50,18 @@ gtest_start()
     html_head "$i"
     if [ ! -d "$GTESTDIR" ]; then
       mkdir -p "$GTESTDIR"
     fi
     cd "$GTESTDIR"
     GTESTREPORT="$GTESTDIR/report.xml"
     PARSED_REPORT="$GTESTDIR/report.parsed"
     echo "executing $i"
-    ${BINDIR}/$i -d "$GTESTDIR" --gtest_output=xml:"${GTESTREPORT}"
+    ${BINDIR}/$i -d "$GTESTDIR" --gtest_output=xml:"${GTESTREPORT}" \
+                                --gtest_filter="${GTESTFILTER-*}"
     html_msg $? 0 "$i run successfully"
     echo "test output dir: ${GTESTREPORT}"
     echo "executing sed to parse the xml report"
     sed -f ${COMMON}/parsegtestreport.sed "${GTESTREPORT}" > "${PARSED_REPORT}"
     echo "processing the parsed report"
     cat "${PARSED_REPORT}" | while read result name; do
       if [ "$result" = "notrun" ]; then
         echo "$name" SKIPPED