Home | History | Annotate | Download | only in futility
      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.
      7 SCRIPTDIR=$(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"
     12 BINDIR="$1"
     13 shift
     14 
     15 FUTILITY="$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).
     20 if [ -z "${BUILD:-}" ]; then
     21   BUILD=$(dirname "${BINDIR}")
     22   yellow "Assuming BUILD=$BUILD"
     23 fi
     24 # Same for $SRCDIR
     25 if [ -z "${SRCDIR:-}" ]; then
     26   SRCDIR=$(readlink -f "${SCRIPTDIR}/../..")
     27   yellow "Assuming SRCDIR=$SRCDIR"
     28 fi
     29 OUTDIR="${BUILD}/tests/futility_test_results"
     30 [ -d "$OUTDIR" ] || mkdir -p "$OUTDIR"
     31 
     32 
     33 # Let each test know where to find things...
     34 export BUILD
     35 export SRCDIR
     36 export FUTILITY
     37 export SCRIPTDIR
     38 export BINDIR
     39 export OUTDIR
     40 
     41 # These are the scripts to run. Binaries are invoked directly by the Makefile.
     42 TESTS="
     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...
     57 pass=0
     58 progs=0
     59 
     60 ##############################################################################
     61 # Invoke the scripts that test the builtin functions.
     62 
     63 # Let the test scripts use >&3 to indicate progress
     64 exec 3>&1
     65 
     66 echo "-- builtin --"
     67 for 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 
     85 done
     86 
     87 ##############################################################################
     88 # How'd we do?
     89 
     90 if [ "$pass" -eq "$progs" ]; then
     91   green "Success: $pass / $progs passed"
     92   exit 0
     93 fi
     94 
     95 red "FAIL: $pass / $progs passed"
     96 exit 1
     97