test(unit): Add nanomsg unit tests
This adds unit tests which drive the nanomsg portion of the
library. The unit test script also now merges coverage
reports so that common portions of the library do not need
to be tested by both nano and nng tests in order to show
accurate coverage information.
Change-Id: Id852d46272972f481d4f37d8a60681228b4bc0ff
Signed-off-by: E. Scott Daniels <daniels@research.att.com>
diff --git a/test/cov2xml.ksh b/test/cov2xml.ksh
new file mode 100755
index 0000000..1b57c53
--- /dev/null
+++ b/test/cov2xml.ksh
@@ -0,0 +1,100 @@
+#!/usr/bin/env ksh
+
+#==================================================================================
+# Copyright (c) 2019 Nokia
+# Copyright (c) 2018-2019 AT&T Intellectual Property.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#==================================================================================
+
+
+#
+# Mnemonic: cov2xml.ksh
+# Abstract: Process the coverage file(s) which are read from standard in
+# to generate a single set of XML output that Sonar can ingest.
+# Basic usage is:
+# cat *.gcov | cov2xml.ksh >file.xml
+#
+# The XML generated is based on the Sonar doc:
+# https://docs.sonarqube.org/latest/analysis/generic-test/
+#
+# Date: 30 April 2019
+# Author: E. Scott Daniels
+# -------------------------------------------------------------------------
+
+awk '
+ function start() {
+ printf( "<coverage version=\"1\">\n" ) # sonar is VERY picky about this
+ }
+
+ function end() {
+ printf( "</coverage>\n" )
+ }
+
+ function start_file( name ) {
+ printf( "<file path=\"%s\">\n", name )
+ }
+
+ function end_file( ) {
+ printf( "</file>\n" )
+ }
+
+ function good_line( num ) {
+ if( num > 0 ) {
+ printf( "<lineToCover lineNumber=\"%d\" covered=\"true\"/>\n", num )
+ }
+ }
+
+ function bad_line( num ) {
+ if( num > 0 ) {
+ printf( "<lineToCover lineNumber=\"%d\" covered=\"false\"/>\n", num )
+ }
+ }
+
+ BEGIN {
+ start()
+ }
+
+ /Source:/ {
+ gsub( "../src", "src", $0 ) # sonar doesnt view test dir as root, so strip
+ n = split( $0, a, ":" )
+ if( fip ) {
+ end_file()
+ }
+ fip = 1
+ start_file( a[n] )
+ next;
+ }
+
+ /-:/ { next } # not executable
+
+ /#####:/ { # never executed
+ bad_line( $2 + 0 )
+ next
+ }
+
+ {
+ good_line( $2 + 0 )
+ }
+
+ END {
+ if( fip ) {
+ end_file();
+ }
+
+ end()
+ }
+' $1
+
+exit $/
+