From 3fcd3bf8f3563ecb02c06c2fe050a0c2cefa3142 Mon Sep 17 00:00:00 2001
From: "Nicolas \"Pixel\" Noble" <pixel@nobis-crew.org>
Date: Sat, 10 Oct 2015 02:30:38 +0200
Subject: [PATCH 1/4] Adds coverage reports for C and C++.

---
 tools/run_tests/post_tests_c.sh | 42 +++++++++++++++++++++++++++++++++
 tools/run_tests/run_lcov.sh     |  4 ++--
 tools/run_tests/run_tests.py    | 33 ++++++++++++++++++++++++++
 3 files changed, 77 insertions(+), 2 deletions(-)
 create mode 100755 tools/run_tests/post_tests_c.sh

diff --git a/tools/run_tests/post_tests_c.sh b/tools/run_tests/post_tests_c.sh
new file mode 100755
index 00000000000..e8cfee30e15
--- /dev/null
+++ b/tools/run_tests/post_tests_c.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+# Copyright 2015, Google Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#     * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+#     * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+set -ex
+
+if [ "$CONFIG" != "gcov" ] ; then exit ; fi
+
+root=`readlink -f $(dirname $0)/../..`
+out=$root/reports/c_cxx_coverage
+tmp=`mktemp`
+cd $root
+tools/run_tests/run_tests.py -c gcov -l c c++ || true
+lcov --capture --directory . --output-file $tmp
+genhtml $tmp --output-directory $out
+rm $tmp
diff --git a/tools/run_tests/run_lcov.sh b/tools/run_tests/run_lcov.sh
index 69b1de6b897..62bbd8c24b7 100755
--- a/tools/run_tests/run_lcov.sh
+++ b/tools/run_tests/run_lcov.sh
@@ -30,9 +30,9 @@
 
 set -ex
 
-out=`realpath ${1:-coverage}`
+out=`readlink -f ${1:-coverage}`
 
-root=`realpath $(dirname $0)/../..`
+root=`readlink -f $(dirname $0)/../..`
 tmp=`mktemp`
 cd $root
 tools/run_tests/run_tests.py -c gcov -l c c++ || true
diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py
index a3bed4ef879..5120f6cb931 100755
--- a/tools/run_tests/run_tests.py
+++ b/tools/run_tests/run_tests.py
@@ -175,6 +175,12 @@ class CLanguage(object):
   def build_steps(self):
     return []
 
+  def post_tests_steps(self):
+    if self.platform == 'windows':
+      return []
+    else:
+      return [['tools/run_tests/post_tests_c.sh']]
+
   def makefile_name(self):
     return 'Makefile'
 
@@ -199,6 +205,9 @@ class NodeLanguage(object):
   def build_steps(self):
     return [['tools/run_tests/build_node.sh']]
 
+  def post_tests_steps(self):
+    return []
+
   def makefile_name(self):
     return 'Makefile'
 
@@ -224,6 +233,9 @@ class PhpLanguage(object):
   def build_steps(self):
     return [['tools/run_tests/build_php.sh']]
 
+  def post_tests_steps(self):
+    return []
+
   def makefile_name(self):
     return 'Makefile'
 
@@ -270,6 +282,9 @@ class PythonLanguage(object):
                        do_newline=True)
     return commands
 
+  def post_tests_steps(self):
+    return []
+
   def makefile_name(self):
     return 'Makefile'
 
@@ -295,6 +310,9 @@ class RubyLanguage(object):
   def build_steps(self):
     return [['tools/run_tests/build_ruby.sh']]
 
+  def post_tests_steps(self):
+    return []
+
   def makefile_name(self):
     return 'Makefile'
 
@@ -343,6 +361,9 @@ class CSharpLanguage(object):
     else:
       return [['tools/run_tests/build_csharp.sh']]
 
+  def post_tests_steps(self):
+    return []
+
   def makefile_name(self):
     return 'Makefile'
 
@@ -368,6 +389,9 @@ class ObjCLanguage(object):
   def build_steps(self):
     return [['src/objective-c/tests/build_tests.sh']]
 
+  def post_tests_steps(self):
+    return []
+
   def makefile_name(self):
     return 'Makefile'
 
@@ -631,6 +655,11 @@ build_steps.extend(set(
                    for l in languages
                    for cmdline in l.build_steps()))
 
+post_tests_steps = list(set(
+                        jobset.JobSpec(cmdline, environ={'CONFIG': cfg})
+                        for cfg in build_configs
+                        for l in languages
+                        for cmdline in l.post_tests_steps()))
 runs_per_test = args.runs_per_test
 forever = args.forever
 
@@ -788,6 +817,10 @@ def _build_and_run(
       tree = ET.ElementTree(root)
       tree.write(xml_report, encoding='UTF-8')
 
+  if not jobset.run(post_tests_steps, maxjobs=1, stop_on_failure=True,
+                    newline_on_success=newline_on_success, travis=travis):
+    return 3
+
   if cache: cache.save()
 
   return 0

From 87879b35272a7f71fef97d84c4ab750445d8e3e5 Mon Sep 17 00:00:00 2001
From: "Nicolas \"Pixel\" Noble" <pixel@nobis-crew.org>
Date: Mon, 12 Oct 2015 23:28:53 +0200
Subject: [PATCH 2/4] Forgot to add the post_build_steps for Sanity...

---
 tools/run_tests/run_tests.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py
index 5120f6cb931..b4008777dc9 100755
--- a/tools/run_tests/run_tests.py
+++ b/tools/run_tests/run_tests.py
@@ -417,6 +417,9 @@ class Sanity(object):
   def build_steps(self):
     return []
 
+  def post_tests_steps(self):
+    return []
+
   def makefile_name(self):
     return 'Makefile'
 

From c1440e3cf4f145157facec19ed73c34ff7f476f3 Mon Sep 17 00:00:00 2001
From: "Nicolas \"Pixel\" Noble" <pixel@nobis-crew.org>
Date: Tue, 13 Oct 2015 01:32:50 +0200
Subject: [PATCH 3/4] Derp.

---
 tools/run_tests/post_tests_c.sh | 1 -
 1 file changed, 1 deletion(-)

diff --git a/tools/run_tests/post_tests_c.sh b/tools/run_tests/post_tests_c.sh
index e8cfee30e15..996c10a0705 100755
--- a/tools/run_tests/post_tests_c.sh
+++ b/tools/run_tests/post_tests_c.sh
@@ -36,7 +36,6 @@ root=`readlink -f $(dirname $0)/../..`
 out=$root/reports/c_cxx_coverage
 tmp=`mktemp`
 cd $root
-tools/run_tests/run_tests.py -c gcov -l c c++ || true
 lcov --capture --directory . --output-file $tmp
 genhtml $tmp --output-directory $out
 rm $tmp

From 7eacdd480309d87d53ed63f5304ba1607f21f7f9 Mon Sep 17 00:00:00 2001
From: "Nicolas \"Pixel\" Noble" <pixel@nobis-crew.org>
Date: Tue, 13 Oct 2015 23:00:36 +0200
Subject: [PATCH 4/4] Changing backticks to $().

---
 tools/run_tests/post_tests_c.sh | 4 ++--
 tools/run_tests/run_lcov.sh     | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/run_tests/post_tests_c.sh b/tools/run_tests/post_tests_c.sh
index 996c10a0705..f2f3ce9432d 100755
--- a/tools/run_tests/post_tests_c.sh
+++ b/tools/run_tests/post_tests_c.sh
@@ -32,9 +32,9 @@ set -ex
 
 if [ "$CONFIG" != "gcov" ] ; then exit ; fi
 
-root=`readlink -f $(dirname $0)/../..`
+root=$(readlink -f $(dirname $0)/../..)
 out=$root/reports/c_cxx_coverage
-tmp=`mktemp`
+tmp=$(mktemp)
 cd $root
 lcov --capture --directory . --output-file $tmp
 genhtml $tmp --output-directory $out
diff --git a/tools/run_tests/run_lcov.sh b/tools/run_tests/run_lcov.sh
index 62bbd8c24b7..a28ec138bb6 100755
--- a/tools/run_tests/run_lcov.sh
+++ b/tools/run_tests/run_lcov.sh
@@ -30,10 +30,10 @@
 
 set -ex
 
-out=`readlink -f ${1:-coverage}`
+out=$(readlink -f ${1:-coverage})
 
-root=`readlink -f $(dirname $0)/../..`
-tmp=`mktemp`
+root=$(readlink -f $(dirname $0)/../..)
+tmp=$(mktemp)
 cd $root
 tools/run_tests/run_tests.py -c gcov -l c c++ || true
 lcov --capture --directory . --output-file $tmp