#!/bin/bash # Ensure the data directory has 750 permissions chmod 750 data # Must run with env -i so that students cannot "accidentally" use the # standard shell environment variables EXE="env -i PATH=/usr/bin:. ../dukesh" SKIP_C="" SKIP_B="" SKIP_A="" function run_test { # parameters TAG=$1 ARGS=$2 PTAG=$(printf '%-30s' "$TAG") if [[ $(echo $TAG | cut -d'_' -f1) == $SKIP_C || $(echo $TAG | cut -d'_' -f1) == $SKIP_B || $(echo $TAG | cut -d'_' -f1) == $SKIP_A ]] ; then echo "$PTAG SKIPPED (previous phases not complete)" return fi # file paths OUTPUT=outputs/$TAG.txt DIFF=outputs/$TAG.diff EXPECT=expected/$TAG.txt VALGRND=valgrind/$TAG.txt # run test and compare output to the expected version $EXE $ARGS 2>/dev/null >"$OUTPUT" diff -u "$OUTPUT" "$EXPECT" >"$DIFF" passed=false EFILES=$(find expected -type f -name "$TAG-*.txt") if [ ! -s "$DIFF" ]; then passed=true elif [ "$EFILES" != "" ]; then for EF in $EFILES ; do DF=$(echo $EF | sed 's/^expected/outputs/' | sed 's/txt$/diff/') diff -u "$OUTPUT" "$EF" >"$DF" if [ ! -s "$DF" ]; then passed=true fi done fi if [[ $passed = true ]] ; then echo "$PTAG pass" rm outputs/$TAG*diff else echo "$PTAG FAIL - Command line: $EXE $ARGS" if [ "$EFILES" != "" ] ; then echo "$(printf '%30s' ' ') *WARNING* This test has more than one possible output file." echo "$(printf '%30s' ' ') *WARNING* Please inspect each manually for comparison." else echo "$(printf '%30s' ' ') See $DIFF for diff with expected output" fi echo "" if [[ $(echo $PTAG | cut -d'_' -f1) == 'D' ]] ; then SKIP_C="C" SKIP_B="B" SKIP_A="A" elif [[ $(echo $PTAG | cut -d'_' -f1) == 'C' ]] ; then SKIP_B="B" SKIP_A="A" elif [[ $(echo $PTAG | cut -d'_' -f1) == 'B' ]] ; then SKIP_A="A" fi fi # run valgrind valgrind $EXE $ARGS &>$VALGRND } # initialize output folders mkdir -p outputs mkdir -p valgrind rm -f outputs/* valgrind/* # run individual tests source itests.include # check for memory leaks LEAK=`cat valgrind/*.txt | grep 'definitely lost' | grep -v ' 0 bytes in 0 blocks'` if [ -z "$LEAK" ]; then echo "No memory leak found." else echo "Memory leak(s) found. See files listed below for details." grep 'definitely lost' valgrind/*.txt | grep -v ' 0 bytes in 0 blocks' | sed -e 's/:.*$//g' | sed -e 's/^/ - /g' fi