e20f738a216aeee61bd7127630506d6c0f112074
[ric-app/mc.git] / sidecars / listener / run_unit_test.ksh
1 #!/usr/bin/env bash
2
3 #==================================================================================
4 #        Copyright (c) 2018-2019 AT&T Intellectual Property.
5 #
6 #   Licensed under the Apache License, Version 2.0 (the "License");
7 #   you may not use this file except in compliance with the License.
8 #   You may obtain a copy of the License at
9 #
10 #       http://www.apache.org/licenses/LICENSE-2.0
11 #
12 #   Unless required by applicable law or agreed to in writing, software
13 #   distributed under the License is distributed on an "AS IS" BASIS,
14 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 #   See the License for the specific language governing permissions and
16 #   limitations under the License.
17 #==================================================================================
18
19
20 #
21 #       Mnemonic:       run_unit_test.ksh
22 #       Abstract:       This drives unit testing setting up working directories
23 #                               and such.
24 #
25 #       Date:           10 December 2019
26 #       Author:         E. Scott Daniels
27 # -------------------------------------------------------------------------
28
29 function setup_dirs {
30         mkdir -p /tmp/fifos
31         mkdir -p /tmp/mc_listener_test/final
32         mkdir -p /tmp/mc_listener_test/stage
33
34         mv_src=/tmp/mc_listener_test/mv_src             # source that will be renamed rather than copied
35         mv_dest=/tmp/mc_listener_test/mv_dest
36         ps -elf >$mv_src
37
38         copy_src=/tmp/mc_listener_test/copy_src
39         copy_dest=/tmp/mc_listener_test/copy_dest
40         ps -elf >$copy_src
41
42         src_md5=$( cat $copy_src | md5sum )             # use cat so that filename doesn't factor in to output
43         rm -f $copy_dest
44 }
45
46 function purge_dirs {
47         rm -fr /tmp/mc_listener_test
48 }
49
50
51 if ! make -B unit_test                  # ensure that it's fresh
52 then
53         echo "[FAIL] cannot make unit_test"
54         exit 1
55 fi
56
57 if [[ $1 == "purge" ]]
58 then
59         purge_dirs
60         exit 0
61 fi
62
63 setup_dirs
64
65 if [[ $1 == "set"* ]]
66 then
67         exit
68 fi
69
70 if ! unit_test >/tmp/PID$$.utlog 2>&1
71 then
72         cat /tmp/PID$$.utlog
73         rm -f /tmp/PID$$.*
74         purge_dirs
75         exit 1
76 fi
77
78 echo "[PASS] base unit tests all pass"
79 echo "[INFO] file/directory verification begins...."
80
81 # validate files that should have been created/copied
82
83 rc=0
84
85 ls -al /tmp/mc_listener_test/* >/tmp/PID$$.fdlog 2>&1
86
87 if [[ -e $copy_src ]]
88 then
89         echo "[FAIL] copy source test should have been unlinked but was there!"
90         rc=1
91 else 
92         dest_md5=$( cat $copy_dest | md5sum )           # use cat so that filename doesn't factor in to output
93         if [[ $dest_md5 != $src_md5 ]]
94         then
95                 echo "[FAIL] md5 of copy test file didn't match soruce"
96 cat $dest_md5
97 echo "$dest_md5  $src_md5"
98                 rc=1
99         fi
100 fi
101 purge_dirs
102
103 if (( rc > 0 ))
104 then
105         cat /tmp/PID$$.fdlog
106 fi
107
108
109 show_coverage.ksh unit_test.c                                                           # compute coverage and generate .gcov files
110 echo "Coverage with discounting (raw values in parens)"
111 discount_chk.ksh $(ls *gcov|egrep -v "^test_|unit_test.c")
112
113
114 if (( rc > 0 ))
115 then
116         echo "[FAIL] overall test fails"
117 else
118         echo "[PASS] overall test passes"
119 fi
120
121 rm -f /tmp/PID$$.*
122 exit $rc