| 1 | #! /bin/sh |
| 2 | |
| 3 | set -e |
| 4 | : ${test=./mdup.t} |
| 5 | cases= |
| 6 | |
| 7 | ###-------------------------------------------------------------------------- |
| 8 | ### Set up the test cases. |
| 9 | ### |
| 10 | ### The mdup-test program takes a command-line representation of an mdup_fd |
| 11 | ### array, calls mdup, and checks the result. In particular, it ensures that |
| 12 | ### the file descriptors returned are the ones asked for, and that the |
| 13 | ### resulting file descriptors actually correspond to the requested files. |
| 14 | ### (It does the latter by comparing inodes before and after.) |
| 15 | |
| 16 | ## Very simple tests. |
| 17 | cases="$cases 3:4" |
| 18 | cases="$cases 4:3" |
| 19 | |
| 20 | ## Overlapping sources and destinations. |
| 21 | cases="$cases 4:3,3:5,5:6" |
| 22 | |
| 23 | ## Repeated sources. |
| 24 | cases="$cases 3:4,3:3,3:-1" |
| 25 | cases="$cases 5:8,3:4,3:5,4:6" |
| 26 | |
| 27 | ## Cycles. |
| 28 | cases="$cases 5:7,3:4,3:5,4:6,5:3" |
| 29 | cases="$cases 5:8,3:4,3:5,4:6,5:3" |
| 30 | |
| 31 | ###-------------------------------------------------------------------------- |
| 32 | ### Actually run the tests. |
| 33 | |
| 34 | ## Initialize counters. |
| 35 | win=0 |
| 36 | lose=0 |
| 37 | total=0 |
| 38 | |
| 39 | ## Run the tests. |
| 40 | for case in $cases; do |
| 41 | total=$(expr $total + 1) |
| 42 | case=$(echo "$case" | sed 'y/,/ /') |
| 43 | printf "%d: %-60s " $total "$case" |
| 44 | if $test $case >mdup.$total.out 2>mdup.$total.err; then |
| 45 | echo "ok" |
| 46 | win=$(expr $win + 1) |
| 47 | rm mdup.$total.out mdup.$total.err |
| 48 | else |
| 49 | echo "FAIL" |
| 50 | lose=$(expr $lose + 1) |
| 51 | fi |
| 52 | done |
| 53 | |
| 54 | ## Announce the outcome. |
| 55 | if [ $win = $total ]; then |
| 56 | echo "All $total tests successful." |
| 57 | rc=0 |
| 58 | else |
| 59 | echo "FAILED $lose of $total tests." |
| 60 | rc=1 |
| 61 | fi |
| 62 | |
| 63 | ## And exit. |
| 64 | exit $rc |
| 65 | |
| 66 | ###----- That's all, folks -------------------------------------------------- |