| 1 | #!/bin/bash |
| 2 | ############################################################################### |
| 3 | # Copyright (c) 2000-2016 Ericsson Telecom AB |
| 4 | # All rights reserved. This program and the accompanying materials |
| 5 | # are made available under the terms of the Eclipse Public License v1.0 |
| 6 | # which accompanies this distribution, and is available at |
| 7 | # http://www.eclipse.org/legal/epl-v10.html |
| 8 | # |
| 9 | # Contributors: |
| 10 | # Balasko, Jeno |
| 11 | # Baranyi, Botond |
| 12 | # |
| 13 | ############################################################################### |
| 14 | |
| 15 | |
| 16 | #Description: |
| 17 | #The goal of this script is to compare the logfile generation result for two different Titan version. |
| 18 | #If switches are not applied the original logfiles given as input will be compared with the just generated log files |
| 19 | #This is the use case in folder regression_test/logger/logtest |
| 20 | |
| 21 | |
| 22 | #Inputs |
| 23 | # old_logfilename.txt -if "-o" not used |
| 24 | # old_logfilename_modified.txt -if "-o" not used |
| 25 | # Outputs: |
| 26 | # old_logfilename.txt -if "-o" used |
| 27 | # old_logfilename_modified.txt -if "-o" used |
| 28 | # Console_old_logfilename.txt |
| 29 | # new_logfilename.txt |
| 30 | # new_logfilename_modified.txt |
| 31 | # Console_new_logfilename.txt |
| 32 | |
| 33 | create_old=0 |
| 34 | cfg_filename="Titan_LogTest.cfg" |
| 35 | old_logfilename="original_merged_log" |
| 36 | new_logfilename="new_merged_log" |
| 37 | generate_makefile=0 |
| 38 | |
| 39 | |
| 40 | |
| 41 | ##### FUNCTIONS ####### |
| 42 | |
| 43 | #################### |
| 44 | # showUsage |
| 45 | #################### |
| 46 | showUsage() |
| 47 | { |
| 48 | echo "Usage: $0 <options>" |
| 49 | echo "Options:" |
| 50 | echo " -o create old versions" |
| 51 | echo " -c [config filename] e.g.: Titan_LogTest.cfg" |
| 52 | echo " -O [Old log file name (before modification)]" |
| 53 | echo " -N [New log file name (before modification)]" |
| 54 | echo " -g generate makefiles. Mandatory if -o applied" |
| 55 | echo "Prerequisite: TTCN3_DIR set for the new ttcn3 dir" |
| 56 | } |
| 57 | |
| 58 | #################### |
| 59 | # init |
| 60 | #################### |
| 61 | init() { |
| 62 | echo "Init called" |
| 63 | |
| 64 | if [ "$TTCN3_DIR_OLD" == "" ] |
| 65 | then |
| 66 | TTCN3_DIR_OLD="/mnt/TTCN/Releases/TTCNv3-1.8.pl5" |
| 67 | fi |
| 68 | echo "TTCN3_DIR_OLD:${TTCN3_DIR_OLD}" |
| 69 | |
| 70 | if [ "$TTCN3_DIR" == "" ] |
| 71 | then |
| 72 | TTCN3_DIR="/export/localhome/TCC/ethbaat/XmlTest/install" |
| 73 | fi |
| 74 | TTCN3_DIR_NEW=${TTCN3_DIR} |
| 75 | |
| 76 | echo "TTCN3_DIR:${TTCN3_DIR}" |
| 77 | |
| 78 | LD_LIBRARY_PATH_ORIG=$LD_LIBRARY_PATH |
| 79 | |
| 80 | SYSTEM_NAME=`uname -n` |
| 81 | HOST_NAME=`hostname` |
| 82 | export HOST_NAME |
| 83 | if [ "$USER" == "" ] |
| 84 | then |
| 85 | export USER=$(whoami) |
| 86 | fi |
| 87 | if [ "$USER" == "" ] |
| 88 | then |
| 89 | export USER=$(/usr/ucb/whoami) |
| 90 | fi |
| 91 | } |
| 92 | |
| 93 | #################### |
| 94 | # create_log |
| 95 | # $1: name of the cfg file |
| 96 | # $2: name of the merged log file |
| 97 | # $3: name of the merged modified log file (timestamps removed) |
| 98 | #################### |
| 99 | create_log() { |
| 100 | |
| 101 | echo "Create_log called" |
| 102 | |
| 103 | make clean |
| 104 | |
| 105 | if [ "${generate_makefile}" == "1" ] |
| 106 | then |
| 107 | ttcn3_makefilegen -fg Titan_LogTest.ttcn Titan_LogTestDefinitions.ttcn *.cc *.hh |
| 108 | fi |
| 109 | |
| 110 | make |
| 111 | echo "ttcn3_start Titan_LogTest $1" |
| 112 | ttcn3_start Titan_LogTest "$1" | tee "Console_$2" |
| 113 | |
| 114 | #ttcn3_logmerge *.log > "$2" |
| 115 | #logmerge the order of the loglines can be different per executions |
| 116 | # therefore the logs will be appended instead of merge |
| 117 | echo "Appended logs:" > "$2" |
| 118 | list=$(ls Titan_LogTest*.log | xargs) |
| 119 | for i in $list |
| 120 | do |
| 121 | cat $i >> "$2" |
| 122 | done |
| 123 | |
| 124 | cmd=' |
| 125 | s/^.*\(EXECUTOR_COMPONENT - TTCN-3 Parallel Test Component started on\).*\( Component reference:\).*$/\1 \2/g |
| 126 | s/^.*\(PORTEVENT_UNQUALIFIED - Port internal_port is waiting for connection from\).*$/\1/g |
| 127 | s/^.*\(EXECUTOR_UNQUALIFIED - The local IP address of the control connection to\).*$/\1/g |
| 128 | s/^.*\(EXECUTOR_COMPONENT - TTCN-3 Main Test Component started on\).*$/\1/g |
| 129 | s/^.*\(EXECUTOR_RUNTIME - TTCN-3 Host Controller started on\).*$/\1/g |
| 130 | s/^.*\(EXECUTOR_UNQUALIFIED - The address of MC was set to\).*$/\1/g |
| 131 | s/^.*\(EXECUTOR_RUNTIME - MTC was created. Process id\).*$/\1/g |
| 132 | s/^.*\(Random number generator was initialized with seed\)\(.*\)$/\1/g |
| 133 | s/^.*\(Function rnd() returned\)\(.*\)$/\1/g |
| 134 | s/^.*\(PARALLEL_PTC - PTC was created. Component reference: \).*\(testcase name:\).*\(, process id:\)\(.*\)$/\1\2\3/g |
| 135 | s/^.*\(ERROR_UNQUALIFIED Titan_LogTest.ttcn\)\(.*\)\(Dynamic test case error: Assignment of an unbound integer value\).*/\1 \3/g |
| 136 | s/^.*\(TIMEROP_READ Titan_LogTest.ttcn\)\(.*\)/\1/g |
| 137 | s/^.*\(USER_UNQUALIFIED Titan_LogTest.ttcn\)\(.*\)/\1/g |
| 138 | s/^.*\(PARALLEL_PTC - PTC with component reference\)\(.*\)/\1/g |
| 139 | s/^.*\(PARALLEL_PTC - MTC finished.\)\(.*\)//g |
| 140 | s/^.*\(EXECUTOR_RUNTIME - Maximum number of open file descriptors\).*//g |
| 141 | s/^.\{15\} //g |
| 142 | ' |
| 143 | # TODO: s/^.*\(PARALLEL_PTC - MTC finished.\)\(.*\)/\1/g should be used instead of s/^.*\(PARALLEL_PTC - MTC finished.\)\(.*\)//g |
| 144 | # TODO: s/^.*\(EXECUTOR_RUNTIME - Maximum number of open file descriptors\).*//g kiszedese |
| 145 | # This line removes the random/seldom line from the log |
| 146 | sed -e "$cmd" -e "/^$/d" < "$2" > "$3" |
| 147 | |
| 148 | } |
| 149 | |
| 150 | #################### |
| 151 | # create_log_old |
| 152 | # $1: name of the cfg file |
| 153 | # $2: name of the merged log file |
| 154 | # $3: name of the merged modified log file (timestamps removed) |
| 155 | #################### |
| 156 | create_log_old() { |
| 157 | TTCN3_DIR_ORIG=${TTCN3_DIR} |
| 158 | TTCN3_DIR=${TTCN3_DIR_OLD} |
| 159 | PATH_ORIG=$PATH} |
| 160 | PATH=${TTCN3_DIR}/bin:${PATH} |
| 161 | LD_LIBRARY_PATH_ORIG=${LD_LIBRARY_PATH} |
| 162 | LD_LIBRARY_PATH=${TTCN3_DIR}/lib:${LD_LIBRARY_PATH} |
| 163 | export TTCN3_DIR PATH LD_LIBRARY_PATH |
| 164 | |
| 165 | create_log $1 $2 $3 |
| 166 | |
| 167 | TTCN3_DIR=${TTCN3_DIR_ORIG} |
| 168 | PATH=${PATH_ORIG} |
| 169 | LD_LIBRARY_PATH=${LD_LIBRARY_PATH_ORIG} |
| 170 | export TTCN3_DIR PATH LD_LIBRARY_PATH |
| 171 | } |
| 172 | |
| 173 | #################### |
| 174 | # create_log_new |
| 175 | # $1: name of the cfg file |
| 176 | # $2: name of the merged log file |
| 177 | # $3: name of the merged modified log file (timestamps removed) |
| 178 | #################### |
| 179 | create_log_new() { |
| 180 | echo ">>>>create_log_new args: $1 $2 $3" |
| 181 | TTCN3_DIR_ORIG=${TTCN3_DIR} |
| 182 | TTCN3_DIR=${TTCN3_DIR_NEW} |
| 183 | PATH_ORIG=${PATH} |
| 184 | PATH=${TTCN3_DIR}/bin:${PATH} |
| 185 | LD_LIBRARY_PATH_ORIG=${LD_LIBRARY_PATH} |
| 186 | LD_LIBRARY_PATH=${TTCN3_DIR}/lib:${LD_LIBRARY_PATH} |
| 187 | export TTCN3_DIR PATH LD_LIBRARY_PATH |
| 188 | |
| 189 | create_log $1 $2 $3 |
| 190 | |
| 191 | TTCN3_DIR=${TTCN3_DIR_ORIG} |
| 192 | PATH=${PATH_ORIG} |
| 193 | LD_LIBRARY_PATH=${LD_LIBRARY_PATH_ORIG} |
| 194 | export TTCN3_DIR PATH LD_LIBRARY_PATH |
| 195 | } |
| 196 | #################### |
| 197 | # compare |
| 198 | # $1: name of the old merged modified log file |
| 199 | # $2: name of the new merged modified log file |
| 200 | #################### |
| 201 | compare() { |
| 202 | echo "Comparison follows" |
| 203 | diff "$1" "$2" |
| 204 | result=$? |
| 205 | echo "Comparison result is $result" |
| 206 | exit $result |
| 207 | } |
| 208 | |
| 209 | ####################### EOF FUNCTIONS ################################### |
| 210 | |
| 211 | #===== MAIN ======= |
| 212 | while getopts "hoc:O:N:g" o |
| 213 | do |
| 214 | case "$o" in |
| 215 | h) showUsage; exit 1;; |
| 216 | o) create_old=1;; |
| 217 | c) cfg_filename=$OPTARG;; |
| 218 | O) old_logfilename=$OPTARG;; |
| 219 | N) new_logfilename=$OPTARG;; |
| 220 | g) generate_makefile=1;; |
| 221 | [?]) showUsage; exit 1;; |
| 222 | esac |
| 223 | done |
| 224 | |
| 225 | init |
| 226 | |
| 227 | if [ "${create_old}" == "1" ] |
| 228 | then |
| 229 | echo ">>>CREATES OLD<<<" |
| 230 | create_log_old "${cfg_filename}" "${old_logfilename}.txt" "${old_logfilename}_modified.txt" |
| 231 | else |
| 232 | echo ">>>OLD LOG NOT CREATED<<<" |
| 233 | echo ">>>${create_old}<<<" |
| 234 | fi |
| 235 | |
| 236 | create_log_new "${cfg_filename}" "${new_logfilename}.txt" "${new_logfilename}_modified.txt" |
| 237 | |
| 238 | compare "${old_logfilename}_modified.txt" "${new_logfilename}_modified.txt" |