[asterisk-scf-commits] asterisk-scf/release/testsuite.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Tue Apr 12 10:30:57 CDT 2011


branch "master" has been updated
       via  1462303021e9fc15825401d263b16e82bf6a69d5 (commit)
      from  d85be7a7177f83eafcf5e280c9f09f21bb68a5aa (commit)

Summary of changes:
 bamboo/bin/boost_to_junit.xsl |   79 +++++++++++++++++++++++++++++++
 bamboo/bin/tests.py           |  103 +++++++++++++++++++++++++++--------------
 2 files changed, 147 insertions(+), 35 deletions(-)
 create mode 100644 bamboo/bin/boost_to_junit.xsl
 mode change 100755 => 100644 bamboo/bin/tests.py


- Log -----------------------------------------------------------------
commit 1462303021e9fc15825401d263b16e82bf6a69d5
Author: Darren Sessions <dsessions at digium.com>
Date:   Tue Apr 12 10:30:50 2011 -0500

    Refactored some code in the tests.py build script and added the boost/junit conversion code that I've been testing. Also added a basic xslt style sheet for converting boost xml to junit xml.

diff --git a/bamboo/bin/boost_to_junit.xsl b/bamboo/bin/boost_to_junit.xsl
new file mode 100644
index 0000000..6e77b2d
--- /dev/null
+++ b/bamboo/bin/boost_to_junit.xsl
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Boost.Test XML to J-Unit XML 
+ XSL Transformation Stylesheet 
+
+ Asterisk SCF Test-Suite
+ Copyright (C) 2011, Digium, Inc.
+   
+ Darren Sessions <dsessions at digium.com>
+
+ This program is free software, distributed under the terms of
+ the GNU General Public License Version 2.
+
+-->
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+    <xsl:template match="TestResult">
+        <xsl:call-template name="testSuite" />
+    </xsl:template>
+
+    <xsl:template name="testSuite">
+        <xsl:for-each select="TestSuite">
+            <testsuite>
+                <xsl:attribute name="skipped">
+                    <xsl:value-of select="@test_cases_skipped"/>
+                </xsl:attribute>
+                <xsl:attribute name="not-run">
+                    <xsl:value-of select="@test_cases_skipped"/>
+                </xsl:attribute>
+                <xsl:attribute name="failures">
+                    <xsl:value-of select="@test_cases_failed"/>
+                </xsl:attribute>
+                <xsl:attribute name="expected_failures">
+                    <xsl:value-of select="@test_cases_expected_failures"/>
+                </xsl:attribute>
+                <xsl:attribute name="errors">
+                    <xsl:value-of select="@test_cases_failed + @test_cases_aborted"/>
+                </xsl:attribute>
+                <xsl:attribute name="tests">
+                    <xsl:value-of select="@test_cases_passed + @test_cases_failed + @test_cases_expected_failures + @test_cases_skipped + @test_cases_aborted"/>
+                </xsl:attribute>
+                <xsl:call-template name="testAttributes" />
+                <xsl:call-template name="testSuite" />
+                <xsl:for-each select="TestCase">
+                    <testcase>
+                        <xsl:call-template name="testAttributes" />
+                        <xsl:call-template name="testCaseElements" />
+                    </testcase>
+                 </xsl:for-each>
+            </testsuite>
+        </xsl:for-each>
+    </xsl:template>
+
+    <xsl:template name="testAttributes">
+        <xsl:attribute name="name">
+            <xsl:value-of select="@name"/>
+        </xsl:attribute>
+        <xsl:attribute name="success">
+            <xsl:choose>
+                <xsl:when test="@result = 'passed'">True</xsl:when>
+                <xsl:when test="@result != 'passed'">False</xsl:when>
+            </xsl:choose>
+        </xsl:attribute>
+        <xsl:attribute name="executed">True</xsl:attribute>
+        <xsl:attribute name="time">0</xsl:attribute>
+        <xsl:attribute name="expected_failures">0</xsl:attribute>
+        <xsl:attribute name="asserts">
+            <xsl:value-of select="@assertions_failed + @assertions_passed"/>
+        </xsl:attribute>
+    </xsl:template>
+
+    <xsl:template name="testCaseElements">
+        <xsl:if test="@result != 'passed'">
+            <failure type="A failure type was not reported." message="No message was reported."/>
+        </xsl:if>
+    </xsl:template>
+
+    <xsl:output method="xml" indent="yes"/>
+</xsl:stylesheet>
diff --git a/bamboo/bin/tests.py b/bamboo/bin/tests.py
old mode 100755
new mode 100644
index 871eddd..66104df
--- a/bamboo/bin/tests.py
+++ b/bamboo/bin/tests.py
@@ -1,8 +1,9 @@
 #!/usr/bin/env python
 '''
 
- Asterisk SCF build and unit-test engine for Atlassian Bamboo
+ Build and unit-test engine for Atlassian Bamboo
 
+ Asterisk SCF Test-Suite 
  Copyright (C) 2011, Digium, Inc.
    
  Darren Sessions <dsessions at digium.com>
@@ -12,43 +13,60 @@
 
 '''
 
-import os, sys, time, platform, optparse, subprocess
+import os
+import re
+import sys
+import time
+import platform
+import optparse
+import subprocess
+
 from xml.dom.minidom import Document
 
 class test_asterisk_scf:
     def __init__(self, component):
-        self.component = component
-        self.msbuild_path = "/Windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe"
-        self.build()
-        self.unit_tests()
-        self.write_results_xml(stdout=True)
-
-    def unit_tests(self):
+        self._component = component
+        self._msbuild_path = "/Windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe"
+        self.__build()
+        self.__unit_tests()
+        self.__convert_boost_to_junit()
+        self.__write_results_xml(stdout=True)
+
+    def __convert_boost_to_junit(self):
+        os.chdir("../..")
+        tree = os.walk(".")
+        for root, dirs, files in tree:
+            if len(files)>0:
+                for f in files:
+                    if re.search(".*?_test-result.xml", f):
+                       print "matched %s" % f 
+                       os.system("%s /opt/bamboo/boost_to_junit.xsl %s >> converted_%s" % (which("xsltproc"), f, f))
+                       os.remove(f)
+
+    def __unit_tests(self):
         self.total_failures = 0
         self.total_time = 0
         self.tests = 0
         self.passed = 1
         self.did_run = True
 
-        if not os.path.exists("./build/%s/test" % self.component):
-            print "Unable to find the test directory for the '%s' component!" % self.component
+        if not os.path.exists("./build/%s/test" % self._component):
+            print "Unable to find the test directory for the '%s' component!" % self._component
             return
 
-        os.chdir("./build/%s/test" % self.component)
-
+        os.chdir("./build/%s/test" % self._component)
         start_time = time.time()
-
         self.passed = uni_make(None, None, 'test')
-
         self.total_time = time.time() - start_time
 
         if self.passed != 0:
             self.total_failures = 1
         self.tests = 1
 
-    def write_results_xml(self, stdout=False):
+    def __write_results_xml(self, stdout=False): 
+        print os.getcwd()          
         try:
-            f = open("../../../test_results.xml", "w")
+            f = open("./unit_test_results.xml", "w")
         except IOError:
             print "Failed to open test results output file: "
             return
@@ -60,7 +78,7 @@ class test_asterisk_scf:
         f.write('<testsuite errors="0" tests="%s" time="%.2f" failures="%d" '
                 'name="Asterisk SCF Test-Suite">\n' %
                 (self.tests, self.total_time, self.total_failures))
-        f.write('\t<testcase time="%.2f" name="%s unit tests"' % (self.total_time, self.component))
+        f.write('\t<testcase time="%.2f" name="%s unit tests"' % (self.total_time, self._component))
         if self.passed == 0:
             f.write('/>\n')
         else:
@@ -71,7 +89,7 @@ class test_asterisk_scf:
 
         if stdout is True:
             try:
-                f = open("../../../test_results.xml", "r")
+                f = open("./unit_test_results.xml", "r")
             except IOError:
                 print "Failed to open test results output file:"
             except:
@@ -80,7 +98,7 @@ class test_asterisk_scf:
                 print f.read()
                 f.close()
 
-    def build(self):
+    def __build(self):
         if os.path.exists("./gitall"):
              errorout("'gitall' already exists!")
 
@@ -88,39 +106,39 @@ class test_asterisk_scf:
         os.chdir("./gitall") 
         os.system("bash ./gitall-asterisk-scf.sh")
 
-        if self.component == "gitall":
+        if self._component == "gitall":
             cloned_rev = readinfile(".git/refs/heads/master").rstrip('\n')
         else:
-            cloned_rev = readinfile("%s/.git/refs/heads/master" % self.component).rstrip('\n')
+            cloned_rev = readinfile("%s/.git/refs/heads/master" % self._component).rstrip('\n')
 
-        print "\n\nTest build initiated for: %s" % self.component
+        print "\n\nTest build initiated for: %s" % self._component
         print "-----------------\nBamboo revision = %s\nCloned revision = %s\n-----------------\n" % (crev, cloned_rev)
     
         if crev != cloned_rev:
             print "Reverting to %s" % crev
-            if self.component != "gitall":
-                os.chdir("./%s" % self.component)
+            if self._component != "gitall":
+                os.chdir("./%s" % self._component)
             os.system("git checkout %s" % crev)
             os.chdir("..")
 
         if plat == "Windows":
             system_call(["/cygwin/bin/bash.exe","./cmake/init-cmake.sh","--nmake"])
             os.chdir("./pjproject/pjlib/build")
-            system_call(["%s" % self.msbuild_path, "pjlib.vcxproj"])
+            system_call(["%s" % self._msbuild_path, "pjlib.vcxproj"])
             os.chdir("../../pjlib-util/build")
-            system_call(["%s" % self.msbuild_path, "pjlib_util.vcxproj"])
+            system_call(["%s" % self._msbuild_path, "pjlib_util.vcxproj"])
             os.chdir("../../pjmedia/build")
-            system_call(["%s" % self.msbuild_path, "pjmedia.vcxproj"])
-            system_call(["%s" % self.msbuild_path, "pjmedia_audiodev.vcxproj"])
+            system_call(["%s" % self._msbuild_path, "pjmedia.vcxproj"])
+            system_call(["%s" % self._msbuild_path, "pjmedia_audiodev.vcxproj"])
             os.chdir("../../third_party/build/srtp")
-            system_call(["%s" % self.msbuild_path, "libsrtp.vcxproj"])
+            system_call(["%s" % self._msbuild_path, "libsrtp.vcxproj"])
             os.chdir("../../../pjnath/build")
-            system_call(["%s" % self.msbuild_path, "pjnath.vcxproj"])
+            system_call(["%s" % self._msbuild_path, "pjnath.vcxproj"])
             os.chdir("../../pjsip/build")
-            system_call(["%s" % self.msbuild_path, "pjsip_simple.vcxproj"])
-            system_call(["%s" % self.msbuild_path, "pjsip_ua.vcxproj"])
-            system_call(["%s" % self.msbuild_path, "pjsip_core.vcxproj"])
-            system_call(["%s" % self.msbuild_path, "pjsua_lib.vcxproj"])
+            system_call(["%s" % self._msbuild_path, "pjsip_simple.vcxproj"])
+            system_call(["%s" % self._msbuild_path, "pjsip_ua.vcxproj"])
+            system_call(["%s" % self._msbuild_path, "pjsip_core.vcxproj"])
+            system_call(["%s" % self._msbuild_path, "pjsua_lib.vcxproj"])
             os.chdir("../../../build")
             uni_make(None, None, None)
             os.chdir("..")
@@ -139,6 +157,21 @@ def system_call(cmd):
     else:
         errorout("FAILED TO EXECUTE %s, it must exist and be executable" % cmd)
 
+def which(app):
+    def if_exists(file_path):
+        return os.path.exists(file_path) and os.access(file_path, os.X_OK)
+
+    file_path, file_name = os.path.split(app)
+    if file_path:
+        if if_exists(app):
+            return app
+    else:
+        for path in os.environ["PATH"].split(os.pathsep):
+            prog = os.path.join(path, app)
+            if if_exists(prog):
+                return prog
+    return 
+
 def test_ice():
     print "\n\nBuilding Ice\n"
     os.chdir("./cpp")

-----------------------------------------------------------------------


-- 
asterisk-scf/release/testsuite.git



More information about the asterisk-scf-commits mailing list