1 #!/bin/bash 2 3 # Tests for our tools. 4 # 5 # TODO: for now, it only tests skdiff 6 # 7 # TODO: currently, this only passes on Linux (which is the platform that 8 # the housekeeper bot runs on, e.g. 9 # http://70.32.156.51:10117/builders/Skia_PerCommit_House_Keeping/builds/1415/steps/RunToolSelfTests/logs/stdio ) 10 # See https://code.google.com/p/skia/issues/detail?id=677 11 # ('make tools/tests/run.sh work cross-platform') 12 # Ideally, these tests should pass on all development platforms... 13 # otherwise, how can developers be expected to test them before committing a 14 # change? 15 16 # cd into .../trunk so all the paths will work 17 cd $(dirname $0)/../.. 18 19 # TODO: make it look in Release and/or Debug 20 SKDIFF_BINARY=out/Debug/skdiff 21 22 # Compare contents of all files within directories $1 and $2, 23 # EXCEPT for any dotfiles. 24 # If there are any differences, a description is written to stdout and 25 # we exit with a nonzero return value. 26 # Otherwise, we write nothing to stdout and return. 27 function compare_directories { 28 if [ $# != 2 ]; then 29 echo "compare_directories requires exactly 2 parameters, got $#" 30 exit 1 31 fi 32 diff --exclude=.* $1 $2 33 if [ $? != 0 ]; then 34 echo "failed in: compare_directories $1 $2" 35 exit 1 36 fi 37 } 38 39 # Run skdiff with arguments in $1 (plus implicit final argument causing skdiff 40 # to write its output, if any, to directory $2/output-actual). 41 # Then compare its results against those in $2/output-expected. 42 function skdiff_test { 43 if [ $# != 2 ]; then 44 echo "skdiff_test requires exactly 2 parameters, got $#" 45 exit 1 46 fi 47 SKDIFF_ARGS="$1" 48 ACTUAL_OUTPUT_DIR="$2/output-actual" 49 EXPECTED_OUTPUT_DIR="$2/output-expected" 50 51 rm -rf $ACTUAL_OUTPUT_DIR 52 mkdir -p $ACTUAL_OUTPUT_DIR 53 COMMAND="$SKDIFF_BINARY $SKDIFF_ARGS $ACTUAL_OUTPUT_DIR" 54 echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line 55 $COMMAND &>$ACTUAL_OUTPUT_DIR/stdout 56 echo $? >$ACTUAL_OUTPUT_DIR/return_value 57 58 compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR 59 } 60 61 SKDIFF_TESTDIR=tools/tests/skdiff 62 63 # Run skdiff over a variety of file pair types: identical bits, identical pixels, missing from 64 # baseDir, etc. 65 skdiff_test "$SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/test1" 66 67 # Run skdiff over the same set of files, but with arguments as used by our buildbots: 68 # - return the number of mismatching file pairs (but ignore any files missing from either 69 # baseDir or comparisonDir) 70 # - list filenames with each result type to stdout 71 # - don't generate HTML output files 72 skdiff_test "--failonresult DifferentPixels --failonresult DifferentSizes --failonresult Unknown --failonstatus CouldNotDecode,CouldNotRead any --failonstatus any CouldNotDecode,CouldNotRead --listfilenames --nodiffs $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/test2" 73 74 # Run skdiff over just the files that have identical bits. 75 skdiff_test "--nodiffs --match identical-bits $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/identical-bits" 76 77 # Run skdiff over just the files that have identical bits or identical pixels. 78 skdiff_test "--nodiffs --match identical-bits --match identical-pixels $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/identical-bits-or-pixels" 79 80 echo "All tests passed." 81