15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#!/bin/bash 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# Copyright 2014 The Chromium Authors. All rights reserved. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# Use of this source code is governed by a BSD-style license that can be 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# found in the LICENSE file. 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# Hacky, primitive testing: This runs the style plugin for a set of input files 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# and compares the output with golden result files. 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)E_BADARGS=65 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)E_FAILEDTEST=1 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)failed_any_test= 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# Prints usage information. 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)usage() { 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) echo "Usage: $(basename "${0}")" \ 181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci "<path to clang>" \ 191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci "<path to plugin>" 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) echo "" 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) echo " Runs all the libBlinkGCPlugin unit tests" 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) echo "" 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# Runs a single test case. 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)do_testcase() { 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) local flags="" 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if [ -e "${3}" ]; then 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) flags="$(cat "${3}")" 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) fi 311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci local output="$("${CLANG_PATH}" -c -Wno-c++11-extensions \ 321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci -Xclang -load -Xclang "${PLUGIN_PATH}" \ 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) -Xclang -add-plugin -Xclang blink-gc-plugin ${flags} ${1} 2>&1)" 34effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch local json="${input%cpp}graph.json" 35effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if [ -f "$json" ]; then 36effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch output="$(python ../process-graph.py -c ${json} 2>&1)" 37effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch fi 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) local diffout="$(echo "${output}" | diff - "${2}")" 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if [ "${diffout}" = "" ]; then 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) echo "PASS: ${1}" 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) else 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) failed_any_test=yes 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) echo "FAIL: ${1}" 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) echo "Output of compiler:" 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) echo "${output}" 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) echo "Expected output:" 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) cat "${2}" 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) echo 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) fi 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# Validate input to the script. 535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)if [[ -z "${1}" ]]; then 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) usage 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) exit ${E_BADARGS} 561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccielif [[ -z "${2}" ]]; then 571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci usage 581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci exit ${E_BADARGS} 591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccielif [[ ! -x "${1}" ]]; then 601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci echo "${1} is not an executable" 611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci usage 621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci exit ${E_BADARGS} 631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccielif [[ ! -f "${2}" ]]; then 641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci echo "${2} could not be found" 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) usage 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) exit ${E_BADARGS} 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)else 681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci export CLANG_PATH="${1}" 691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci export PLUGIN_PATH="${2}" 701320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci echo "Using clang ${CLANG_PATH}..." 711320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci echo "Using plugin ${PLUGIN_PATH}..." 725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) # The golden files assume that the cwd is this directory. To make the script 745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) # work no matter what the cwd is, explicitly cd to there. 755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) cd "$(dirname "${0}")" 765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)fi 775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)for input in *.cpp; do 795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) do_testcase "${input}" "${input%cpp}txt" "${input%cpp}flags" 805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)done 815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)if [[ "${failed_any_test}" ]]; then 835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) exit ${E_FAILEDTEST} 845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)fi 85