E. Scott Daniels | 11642d9 | 2019-04-17 14:53:34 +0000 | [diff] [blame] | 1 | #!/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 |
| 45 | function 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 |
| 59 | function abort_on_err { |
| 60 | if (( $1 != 0 )) |
| 61 | then |
| 62 | echo "$(date) [FAIL] $2" |
| 63 | exit 1 |
| 64 | fi |
| 65 | } |
| 66 | |
| 67 | function log_it { |
| 68 | echo "$(date) $1" |
| 69 | } |
| 70 | |
| 71 | verbose=0 |
| 72 | refresh=1 # use -R to turn off a git pull before we start |
| 73 | |
| 74 | while [[ $1 == -* ]] |
| 75 | do |
| 76 | case $1 in |
| 77 | -R) refresh=0;; |
| 78 | -v) verbose=1;; |
| 79 | esac |
| 80 | |
| 81 | shift |
| 82 | done |
| 83 | |
| 84 | if (( refresh )) |
| 85 | then |
| 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" |
| 94 | fi |
| 95 | |
| 96 | log_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 |
| 105 | rc=$? |
| 106 | err_cat $rc /tmp/build.log |
| 107 | abort_on_err $rc "unable to setup cmake or build and install" |
| 108 | |
| 109 | log_it "[OK] Build successful" |
| 110 | |
| 111 | log_it "[INFO] validating .deb" |
| 112 | ( |
| 113 | set -e |
| 114 | cd .build |
| 115 | ls -al *.deb |
E. Scott Daniels | 6d3e334 | 2019-05-13 15:06:46 +0000 | [diff] [blame] | 116 | 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 Daniels | 11642d9 | 2019-04-17 14:53:34 +0000 | [diff] [blame] | 123 | ) >/tmp/dpkg.log 2>&1 |
| 124 | rc=$? |
| 125 | err_cat $rc /tmp/dpkg.log |
| 126 | abort_on_err $rc "unable to install from .deb" |
| 127 | |
| 128 | log_it "[OK] Deb installation successful" |
| 129 | |
| 130 | PATH=$PATH:. |
| 131 | export LD_LIBRARY_PATH=/usr/local/lib |
| 132 | export C_INCLUDE_PATH=../.build/include # must reference nano/nng from the build tree |
| 133 | |
E. Scott Daniels | 9e0c1e7 | 2019-04-17 16:31:16 +0000 | [diff] [blame] | 134 | log_it "[INFO] unit testing starts" |
E. Scott Daniels | 11642d9 | 2019-04-17 14:53:34 +0000 | [diff] [blame] | 135 | ( |
| 136 | set -e |
| 137 | cd test |
| 138 | pwd |
| 139 | ls -al unit_test.ksh |
| 140 | ./unit_test.ksh |
| 141 | ) >/tmp/utest.log 2>&1 |
| 142 | rc=$? |
| 143 | err_cat $rc /tmp/utest.log |
| 144 | abort_on_err $rc "unit tests failed" |
E. Scott Daniels | 9e0c1e7 | 2019-04-17 16:31:16 +0000 | [diff] [blame] | 145 | log_it "[OK] unit testing passes" |
E. Scott Daniels | 11642d9 | 2019-04-17 14:53:34 +0000 | [diff] [blame] | 146 | |
| 147 | echo "" |
| 148 | log_it "[PASS] all testing successful" |
| 149 | |