Home | History | Annotate | Download | only in tests
      1 #!/bin/bash
      2 
      3 # Copyright (c) 2010 The Chromium OS 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 # Determine script directory.
      8 SCRIPT_DIR=$(dirname $(readlink -f "$0"))
      9 
     10 ROOT_DIR="$(dirname ${SCRIPT_DIR})"
     11 BUILD_DIR="${BUILD}"
     12 BIN_DIR=${BUILD_DIR}/install_for_test/bin
     13 FUTILITY=${BIN_DIR}/futility
     14 TEST_DIR="${BUILD_DIR}/tests"
     15 TESTKEY_DIR=${SCRIPT_DIR}/testkeys
     16 TESTCASE_DIR=${SCRIPT_DIR}/testcases
     17 TESTKEY_SCRATCH_DIR=${TEST_DIR}/testkeys
     18 
     19 if [ ! -d ${TESTKEY_SCRATCH_DIR} ]; then
     20     mkdir -p ${TESTKEY_SCRATCH_DIR}
     21 fi
     22 
     23 # Color output encodings.
     24 COL_RED='\E[31;1m'
     25 COL_GREEN='\E[32;1m'
     26 COL_YELLOW='\E[33;1m'
     27 COL_BLUE='\E[34;1m'
     28 COL_STOP='\E[0;m'
     29 
     30 hash_algos=( sha1 sha256 sha512 )
     31 key_lengths=( 1024 2048 4096 8192 )
     32 
     33 function happy {
     34   echo -e "${COL_GREEN}$*${COL_STOP}" 1>&2
     35 }
     36 
     37 # args: [nested level [message]]
     38 function warning {
     39   echo -e "${COL_YELLOW}WARNING: $*${COL_STOP}" 1>&2
     40 }
     41 
     42 # args: [nested level [message]]
     43 function error {
     44   local lev=${1:-}
     45   case "${1:-}" in
     46     [0-9]*)
     47       lev=$1
     48       shift
     49       ;;
     50     *) lev=0
     51       ;;
     52   esac
     53   local x=$(caller $lev)
     54   local cline=${x%% *}
     55   local cfunc=${x#* }
     56   cfunc=${cfunc##*/}
     57   local args="$*"
     58   local spacer=${args:+: }
     59   echo -e "${COL_RED}ERROR at ${cfunc}, line ${cline}${spacer}${args}" \
     60     "${COL_STOP}" 1>&2
     61   exit 1
     62 }
     63 
     64 function check_test_keys {
     65   [ -d ${TESTKEY_DIR} ] || \
     66     error 1 "You must run gen_test_keys.sh to generate test keys first."
     67 }
     68 
     69