1#!/bin/sh 2 3# Copyright (C) 2007-2008 Dan McMahill 4# Copyright (C) 2007-2011 gEDA Contributors 5# Copyright (C) 2018-2021 Lepton EDA Contributors 6 7# This file is part of lepton-refdes_renum. 8 9# This program is free software; you can redistribute it and/or 10# modify it under the terms of the GNU General Public License 11# as published by the Free Software Foundation, version 2 12# of the License. 13 14# This program is distributed in the hope that it will be useful, 15# but WITHOUT ANY WARRANTY; without even the implied warranty of 16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17# GNU General Public License for more details. 18 19# You should have received a copy of the GNU General Public License 20# along with this program; if not, write to the Free Software 21# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 22# 02110-1301, USA. 23 24regen=no 25 26usage() { 27cat << EOF 28 29$0 -- Testsuite program for lepton-refdes_renum 30 31Usage 32 33 $0 [-h | --help] 34 $0 [-r | --regen] [test1 [test2 [....]]] 35 36Options 37 38 -h | --help Prints this help message and exits. 39 40 -r | --regen Regenerates the reference files. If you use 41 this option, YOU MUST HAND VERIFY THE RESULTS 42 BEFORE COMMITTING to the repository. 43 44Description 45 46$0 reads a file, tests.list, describing tests to run on lepton-refdes_renum. 47If no specific test is specified on the $0 command line, then all 48tests are run. 49 50Examples 51 52$0 53$0 basic_renum 54$0 --regen new_test 55 56EOF 57} 58while test -n "$1" 59do 60 case "$1" 61 in 62 63 -h|--help) 64 usage 65 exit 0 66 ;; 67 68 -r|--regen) 69 # regenerate the 'golden' output files. Use this with caution. 70 # In particular, all differences should be noted and understood. 71 regen=yes 72 shift 73 ;; 74 75 -*) 76 echo "unknown option: $1" 77 usage 78 exit 1 79 ;; 80 81 *) 82 break 83 ;; 84 85 esac 86done 87 88 89# make sure we have the right paths when running this from inside the 90# source tree and also from outside the source tree. 91here=`pwd` 92srcdir=${srcdir:-$here} 93srcdir=`cd $srcdir && pwd` 94 95top_srcdir=${top_srcdir:-$here/../..} 96top_srcdir=`cd $top_srcdir && pwd` 97 98# the perl program 99PERL=${PERL:-perl} 100 101rundir=${here}/run 102 103GOLDEN_DIR=${srcdir}/outputs 104INPUT_DIR=${srcdir}/inputs 105 106 107TESTLIST=${srcdir}/tests.list 108 109if test ! -f $TESTLIST ; then 110 echo "ERROR: ($0) Test list $TESTLIST does not exist" 111 exit 1 112fi 113 114# fail/pass/total counts 115fail=0 116pass=0 117skip=0 118tot=0 119 120if test -z "$1" ; then 121 all_tests=`awk 'BEGIN{FS="|"} /^#/{next} /^[ \t]*$/{next} {print $1}' $TESTLIST | sed 's; ;;g'` 122else 123 all_tests=$* 124fi 125 126cat << EOF 127 128Starting tests in $here 129srcdir: $srcdir 130top_srcdir: $top_srcdir 131INPUT_DIR: ${INPUT_DIR} 132GOLDEN_DIR: ${GOLDEN_DIR} 133all_tests: 134 135${all_tests} 136 137EOF 138 139for t in $all_tests ; do 140 141 # strip any leading garbage 142 t=`echo $t | sed 's;^\*;;g'` 143 144 # figure out what files we need to copy for this test and what 145 # arguments to feed lepton-refdes_renum 146 files=`grep "^[ \t]*${t}[ \t]*|" $TESTLIST | awk 'BEGIN{FS="|"} {print $2}'` 147 args=`grep "^[ \t]*${t}[ \t]*|" $TESTLIST | awk 'BEGIN{FS="|"} {print $3}'` 148 code=`grep "^[ \t]*${t}[ \t]*|" $TESTLIST | awk 'BEGIN{FS="|"} {print $4}'` 149 if test "X$code" = "X" ; then 150 code=0 151 fi 152 153 154 tot=`expr $tot + 1` 155 156 # create temporary run directory 157 if test ! -d $rundir ; then 158 mkdir -p $rundir 159 fi 160 161 # Create the files needed 162 if test ! -z "$files" ; then 163 for f in $files ; do 164 cp ${INPUT_DIR}/${f} ${rundir} 165 chmod 644 ${rundir}/${f} 166 done 167 fi 168 169 # run lepton-refdes_renum 170 # 171 172 echo "${PERL} -w ${top_srcdir}/refdes_renum/lepton-refdes_renum $args $files" 173 cd ${rundir} && ${PERL} -w ${top_srcdir}/refdes_renum/lepton-refdes_renum $args $files 174 rc=$? 175 if test $rc -ne $code ; then 176 echo "FAILED: lepton-refdes_renum returned $rc which did not match the expected $code" 177 fail=`expr $fail + 1` 178 continue 179 fi 180 181 good=1 182 bad=0 183 soso=0 184 for f in ${files} ; do 185 ref=${GOLDEN_DIR}/${t}-${f} 186 out=${rundir}/${f} 187 188 if test "X$regen" = "Xyes" ; then 189 cp ${out} ${ref} 190 echo "Regenerated ${ref}" 191 elif test -f ${ref} ; then 192 if diff -w ${ref} ${out} >/dev/null ; then 193 echo "PASS" 194 else 195 echo "FAILED: See diff -w ${ref} ${out}" 196 fail=`expr $fail + 1` 197 bad=1 198 good=0 199 fi 200 else 201 echo "No reference file. Skipping" 202 good=0 203 soso=1 204 fi 205 done 206 if test $soso -ne 0 ; then 207 good=0 208 bad=0 209 fi 210 pass=`expr $pass + $good` 211 fail=`expr $fail + $bad` 212 skip=`expr $skip + $soso` 213 214 cd $here 215 216 # clean up the rundirectory 217 rm -fr ${rundir} 218 219done 220 221echo "Passed $pass, failed $fail, skipped $skip out of $tot tests." 222 223rc=0 224if test $pass -ne $tot ; then 225 rc=`expr $tot - $pass` 226 227fi 228 229exit $rc 230