1#!/bin/bash -eu 2# Copyright 2013 The Chromium OS Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6# Load common constants and variables. 7SCRIPTDIR=$(dirname $(readlink -f "$0")) 8. "$SCRIPTDIR/common.sh" 9 10# Mandatory arg is the directory where futility is installed. 11[ -z "${1:-}" ] && error "Directory argument is required" 12BINDIR="$1" 13shift 14 15FUTILITY="$BINDIR/futility" 16 17 18# The Makefile should export the $BUILD directory, but if it's not just warn 19# and guess (mostly so we can run the script manually). 20if [ -z "${BUILD:-}" ]; then 21 BUILD=$(dirname "${BINDIR}") 22 yellow "Assuming BUILD=$BUILD" 23fi 24# Same for $SRCDIR 25if [ -z "${SRCDIR:-}" ]; then 26 SRCDIR=$(readlink -f "${SCRIPTDIR}/../..") 27 yellow "Assuming SRCDIR=$SRCDIR" 28fi 29OUTDIR="${BUILD}/tests/futility_test_results" 30[ -d "$OUTDIR" ] || mkdir -p "$OUTDIR" 31 32 33# Let each test know where to find things... 34export BUILD 35export SRCDIR 36export FUTILITY 37export SCRIPTDIR 38export BINDIR 39export OUTDIR 40 41# These are the scripts to run. Binaries are invoked directly by the Makefile. 42TESTS=" 43${SCRIPTDIR}/test_create.sh 44${SCRIPTDIR}/test_dump_fmap.sh 45${SCRIPTDIR}/test_gbb_utility.sh 46${SCRIPTDIR}/test_load_fmap.sh 47${SCRIPTDIR}/test_main.sh 48${SCRIPTDIR}/test_show_kernel.sh 49${SCRIPTDIR}/test_show_vs_verify.sh 50${SCRIPTDIR}/test_sign_firmware.sh 51${SCRIPTDIR}/test_sign_fw_main.sh 52${SCRIPTDIR}/test_sign_kernel.sh 53${SCRIPTDIR}/test_sign_keyblocks.sh 54" 55 56# Get ready... 57pass=0 58progs=0 59 60############################################################################## 61# Invoke the scripts that test the builtin functions. 62 63# Let the test scripts use >&3 to indicate progress 64exec 3>&1 65 66echo "-- builtin --" 67for i in $TESTS; do 68 j=${i##*/} 69 70 : $(( progs++ )) 71 72 echo -n "$j ... " 73 rm -rf "${OUTDIR}/$j."* 74 rc=$("$i" "$FUTILITY" 1>"${OUTDIR}/$j.stdout" \ 75 2>"${OUTDIR}/$j.stderr" || echo "$?") 76 echo "${rc:-0}" > "${OUTDIR}/$j.return" 77 if [ ! "$rc" ]; then 78 green "passed" 79 : $(( pass++ )) 80 rm -f ${OUTDIR}/$j.{stdout,stderr,return} 81 else 82 red "failed" 83 fi 84 85done 86 87############################################################################## 88# How'd we do? 89 90if [ "$pass" -eq "$progs" ]; then 91 green "Success: $pass / $progs passed" 92 exit 0 93fi 94 95red "FAIL: $pass / $progs passed" 96exit 1 97