1 #!/bin/bash 2 # 3 # Copyright 2014 The Chromium Authors. All rights reserved. 4 # Use of this source code is governed by a BSD-style license that can be 5 # found in the LICENSE file. 6 # 7 # Hacky, primitive testing: This runs the style plugin for a set of input files 8 # and compares the output with golden result files. 9 10 E_BADARGS=65 11 E_FAILEDTEST=1 12 13 failed_any_test= 14 15 # Prints usage information. 16 usage() { 17 echo "Usage: $(basename "${0}")" \ 18 "<Path to the llvm build dir, usually Release+Asserts>" 19 echo "" 20 echo " Runs all the libBlinkGCPlugin unit tests" 21 echo "" 22 } 23 24 # Runs a single test case. 25 do_testcase() { 26 local flags="" 27 if [ -e "${3}" ]; then 28 flags="$(cat "${3}")" 29 fi 30 local output="$("${CLANG_DIR}"/bin/clang -c -Wno-c++11-extensions \ 31 -Xclang -load -Xclang "${CLANG_DIR}"/lib/lib${LIBNAME}.${LIB} \ 32 -Xclang -add-plugin -Xclang blink-gc-plugin ${flags} ${1} 2>&1)" 33 local json="${input%cpp}graph.json" 34 if [ -f "$json" ]; then 35 output="$(python ../process-graph.py -c ${json} 2>&1)" 36 fi 37 local diffout="$(echo "${output}" | diff - "${2}")" 38 if [ "${diffout}" = "" ]; then 39 echo "PASS: ${1}" 40 else 41 failed_any_test=yes 42 echo "FAIL: ${1}" 43 echo "Output of compiler:" 44 echo "${output}" 45 echo "Expected output:" 46 cat "${2}" 47 echo 48 fi 49 } 50 51 # Validate input to the script. 52 if [[ -z "${1}" ]]; then 53 usage 54 exit ${E_BADARGS} 55 elif [[ ! -d "${1}" ]]; then 56 echo "${1} is not a directory." 57 usage 58 exit ${E_BADARGS} 59 else 60 export CLANG_DIR="${PWD}/${1}" 61 echo "Using clang directory ${CLANG_DIR}..." 62 63 # The golden files assume that the cwd is this directory. To make the script 64 # work no matter what the cwd is, explicitly cd to there. 65 cd "$(dirname "${0}")" 66 67 export LIBNAME=$(grep LIBRARYNAME ../Makefile | cut -d ' ' -f 3) 68 if [ "$(uname -s)" = "Linux" ]; then 69 export LIB=so 70 elif [ "$(uname -s)" = "Darwin" ]; then 71 export LIB=dylib 72 fi 73 fi 74 75 for input in *.cpp; do 76 do_testcase "${input}" "${input%cpp}txt" "${input%cpp}flags" 77 done 78 79 if [[ "${failed_any_test}" ]]; then 80 exit ${E_FAILEDTEST} 81 fi 82