blob: b0b790fc3d09ba10518cf9f3d82e259c5f58583d [file] [log] [blame]
E. Scott Daniels11642d92019-04-17 14:53:34 +00001#!/usr/bin/env ksh
2
3#==================================================================================
4# Copyright (c) 2019 Nokia
5# Copyright (c) 2018-2019 AT&T Intellectual Property.
6#
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18#==================================================================================
19
20
21#
22# Mnemonic: run_all_tests.ksh
23# Abstract: This should allow one stop shopping to run all tests as
24# follows some are explicit, some are implied (e.g. if nng
25# doesn't build correctly RMr won't build):
26#
27# - complete build of RMr code and generation of a .deb with
28# expected content
29#
30# - complete build of Nanomsg and NNG
31#
32# - complete execution of the unit test script
33#
34# Assumptions:
35# - code is cloned, and the PWD is the top level repo directory
36# - running in a container such that 'make install' can be
37# executed to install RMr and NNG/Nano libraires in /usr/local
38# - needed utilities (cmake, make, gcc, ksh) are installed
39#
40# Date: 17 April 2019
41# Author: E. Scott Daniels
42# -------------------------------------------------------------------------
43
44# cat the file if error or verbose
45function err_cat {
46 if (( $1 > 0 || verbose ))
47 then
48 shift
49 while [[ -n $1 ]]
50 do
51 cat $1
52 echo ""
53 shift
54 done
55 fi
56}
57
58# if $1 (state) is not 0, write message ($2) and abort
59function abort_on_err {
60 if (( $1 != 0 ))
61 then
62 echo "$(date) [FAIL] $2"
63 exit 1
64 fi
65}
66
67function log_it {
68 echo "$(date) $1"
69}
70
71verbose=0
72refresh=1 # use -R to turn off a git pull before we start
73
74while [[ $1 == -* ]]
75do
76 case $1 in
77 -R) refresh=0;;
78 -v) verbose=1;;
79 esac
80
81 shift
82done
83
84if (( refresh ))
85then
86 log_it "[INFO] refreshing RMr code base with git pull"
87 (
88 set -e
89 git pull
90 ) >/tmp/git.log 2>&1
91 rc=$?
92 err_cat $rc /tmp/git.log
93 abort_on_err $rc "unable to refresh RMr code base"
94fi
95
96log_it "[INFO] build starts"
97# build RMr (and nano/nng)
98(
99 set -e
100 mkdir -p .build
101 cd .build
102 cmake .. -DBUILD_DOC=1
103 make package # build RMr, then put in the .deb
104) >/tmp/build.log 2>&1 # capture the reams of output and show only on error
105rc=$?
106err_cat $rc /tmp/build.log
107abort_on_err $rc "unable to setup cmake or build and install"
108
109log_it "[OK] Build successful"
110
111log_it "[INFO] validating .deb"
112(
113 set -e
114 cd .build
115 ls -al *.deb
E. Scott Daniels6d3e3342019-05-13 15:06:46 +0000116 if whence dpkg >/dev/null 2>&1
117 then
118 dpkg -i *.deb
119 else
120 log_it "[INFO] Deb installation check skipped. dpkg does not exist; trying make install"
121 make install
122 fi
E. Scott Daniels11642d92019-04-17 14:53:34 +0000123) >/tmp/dpkg.log 2>&1
124rc=$?
125err_cat $rc /tmp/dpkg.log
126abort_on_err $rc "unable to install from .deb"
127
128log_it "[OK] Deb installation successful"
129
130PATH=$PATH:.
131export LD_LIBRARY_PATH=/usr/local/lib
132export C_INCLUDE_PATH=../.build/include # must reference nano/nng from the build tree
133
E. Scott Daniels9e0c1e72019-04-17 16:31:16 +0000134log_it "[INFO] unit testing starts"
E. Scott Daniels11642d92019-04-17 14:53:34 +0000135(
136 set -e
137 cd test
138 pwd
139 ls -al unit_test.ksh
140 ./unit_test.ksh
141) >/tmp/utest.log 2>&1
142rc=$?
143err_cat $rc /tmp/utest.log
144abort_on_err $rc "unit tests failed"
E. Scott Daniels9e0c1e72019-04-17 16:31:16 +0000145log_it "[OK] unit testing passes"
E. Scott Daniels11642d92019-04-17 14:53:34 +0000146
147echo ""
148log_it "[PASS] all testing successful"
149