Add CMake to drive unit tests in sidecars 28/4528/3
authorE. Scott Daniels <daniels@research.att.com>
Mon, 10 Aug 2020 16:21:20 +0000 (12:21 -0400)
committerE. Scott Daniels <daniels@research.att.com>
Tue, 11 Aug 2020 13:41:28 +0000 (09:41 -0400)
In order to support sonar vetting, the unit tests must be driven by
CMake with a CMake file at the repo root. This change adds a CMake
file at the top level which will initially drive the unit tests
in the sidecars. This can be extended to include the core application.

Issue-ID: RIC-632

Signed-off-by: E. Scott Daniels <daniels@research.att.com>
Change-Id: I5707fa05bcd642a4f18473f05b4467a533b3cf34

CMakeLists.txt [new file with mode: 0644]
sidecars/listener/Dockerfile
sidecars/listener/run_unit_test.ksh
sidecars/listener/unit_test.c

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..78964fe
--- /dev/null
@@ -0,0 +1,46 @@
+#
+#==================================================================================
+#      Copyright (c) 2018-2020 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.
+#==================================================================================
+#
+
+# This top level CMake definition is intended only to suppor the LF jenkins
+# environment which seems not to be customisable. It does NOT build anything.
+# Run tests like this:
+#
+#      mkdir .build
+#      cd .build
+#      cmake ..
+#      make tests ARGS=-v
+
+#      See ci/build_all for an example of how to build and test
+
+project( mc_testing LANGUAGES C )
+cmake_minimum_required( VERSION 3.5 )
+
+# ------------- testing -------------------------------------------------------
+enable_testing()
+
+# cmake cannot set env vars, so we have to passed desired vars on the wrapper command
+# and assume the wrapper will do the right thing with them.  CMake also seems unable
+# to reference ../dir1/dir2 (../dir1 works), so we have to use the crazy syntax
+# with the absurdly long variable name.
+#
+add_test(
+               NAME drive_listener_tests
+               COMMAND  ksh run_unit_test.ksh CMBUILD=${CMAKE_CURRENT_BINARY_DIR}
+               WORKING_DIRECTORY   ${CMAKE_CURRENT_BINARY_DIR}/../sidecars/listener
+)
+               #WORKING_DIRECTORY ../sidecars/listener
index b9cb9c1..c29c416 100644 (file)
@@ -41,7 +41,7 @@
 #      Author:         E. Scott Daniels
 
 
-FROM nexus3.o-ran-sc.org:10004/o-ran-sc/bldr-ubuntu18-c-go:8-u18.04 as buildenv
+FROM nexus3.o-ran-sc.org:10004/o-ran-sc/bldr-ubuntu18-c-go:9-u18.04 as buildenv
 
 RUN mkdir /playpen
 
index 757b81e..8d350fb 100755 (executable)
@@ -31,7 +31,7 @@ function abort_after {
        sleep ${1:-60}
        if [[ -e /tmp/running ]]
        then
-               echo "abort: unit test running too long"
+               echo "abort: unit test running too long, killing $2"
                kill -9 ${2:-bad-pid}
        fi
 }
@@ -57,7 +57,6 @@ function purge_dirs {
        rm -fr /tmp/mc_listener_test
 }
 
-
 if ! make -B unit_test                 # ensure that it's fresh
 then
        echo "[FAIL] cannot make unit_test"
@@ -77,16 +76,16 @@ then
        exit
 fi
 
-abort_after 60 
+abort_after 60
 if ! unit_test >/tmp/PID$$.utlog 2>&1
 then
-       rm /tmp/running
+       rm -f /tmp/running
        cat /tmp/PID$$.utlog
        rm -f /tmp/PID$$.*
        purge_dirs
        exit 1
 fi
-rm /tmp/running
+rm -f /tmp/running
 
 echo "[PASS] base unit tests all pass"
 echo "[INFO] file/directory verification begins...."
@@ -101,7 +100,7 @@ if [[ -e $copy_src ]]
 then
        echo "[FAIL] copy source test should have been unlinked but was there!"
        rc=1
-else 
+else
        dest_md5=$( cat $copy_dest | md5sum )           # use cat so that filename doesn't factor in to output
        if [[ $dest_md5 != $src_md5 ]]
        then
@@ -129,6 +128,7 @@ then
        echo "[FAIL] overall test fails"
 else
        echo "[PASS] overall test passes"
+       rm -f *test*.gcov
 fi
 
 rm -f /tmp/PID$$.*
index edcc139..a946c8c 100644 (file)
@@ -159,6 +159,7 @@ int main( int argc,  char** argv ) {
        logit( LOG_WARN, "warning message" );
        logit( LOG_STAT, "stats message" );
 
+       fprintf( stderr, "[INFO] expected create fail message should follow\n" );
        bad_ctx = mcl_mk_context( "/nosuchdirectoryinthesystem" );              // create a context where fifo opens should fail
        if( bad_ctx == NULL ) {
                fprintf( stderr, "[FAIL] couldn't make 'bad' context" );