blob: 2b017cc50f8162e403a29011412f2c7481addfa8 [file] [log] [blame]
Gaurav Shah445925f2010-03-19 16:19:09 -07001#!/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.
Bill Richardson793e1b42010-08-20 07:58:43 -07008SCRIPT_DIR=$(dirname $(readlink -f "$0"))
Gaurav Shah445925f2010-03-19 16:19:09 -07009
vbendeb70e95092010-06-14 15:41:27 -070010ROOT_DIR="$(dirname ${SCRIPT_DIR})"
Randall Spangler844bce52013-01-15 16:16:43 -080011BUILD_DIR="${BUILD}"
Bill Richardsonefa87562014-09-11 10:41:51 -070012BIN_DIR=${BUILD_DIR}/install_for_test/bin
Bill Richardsona1d9fe62014-09-05 12:52:27 -070013FUTILITY=${BIN_DIR}/futility
vbendeb70e95092010-06-14 15:41:27 -070014TEST_DIR="${BUILD_DIR}/tests"
Gaurav Shah445925f2010-03-19 16:19:09 -070015TESTKEY_DIR=${SCRIPT_DIR}/testkeys
16TESTCASE_DIR=${SCRIPT_DIR}/testcases
vbendeb70e95092010-06-14 15:41:27 -070017TESTKEY_SCRATCH_DIR=${TEST_DIR}/testkeys
18
19if [ ! -d ${TESTKEY_SCRATCH_DIR} ]; then
Randall Spangler844bce52013-01-15 16:16:43 -080020 mkdir -p ${TESTKEY_SCRATCH_DIR}
vbendeb70e95092010-06-14 15:41:27 -070021fi
Gaurav Shah445925f2010-03-19 16:19:09 -070022
23# Color output encodings.
24COL_RED='\E[31;1m'
25COL_GREEN='\E[32;1m'
26COL_YELLOW='\E[33;1m'
27COL_BLUE='\E[34;1m'
28COL_STOP='\E[0;m'
29
30hash_algos=( sha1 sha256 sha512 )
Bill Richardson3430b322010-11-29 14:24:51 -080031key_lengths=( 1024 2048 4096 8192 )
Gaurav Shah445925f2010-03-19 16:19:09 -070032
Bill Richardsonf1372d92010-06-11 09:15:55 -070033function happy {
34 echo -e "${COL_GREEN}$*${COL_STOP}" 1>&2
Gaurav Shah445925f2010-03-19 16:19:09 -070035}
Bill Richardsonf1372d92010-06-11 09:15:55 -070036
Bill Richardson3430b322010-11-29 14:24:51 -080037# args: [nested level [message]]
Bill Richardsonf1372d92010-06-11 09:15:55 -070038function warning {
39 echo -e "${COL_YELLOW}WARNING: $*${COL_STOP}" 1>&2
40}
41
Bill Richardson3430b322010-11-29 14:24:51 -080042# args: [nested level [message]]
Bill Richardsonf1372d92010-06-11 09:15:55 -070043function error {
Bill Richardson3430b322010-11-29 14:24:51 -080044 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
Bill Richardsonf1372d92010-06-11 09:15:55 -070061 exit 1
62}
63
64function check_test_keys {
65 [ -d ${TESTKEY_DIR} ] || \
Bill Richardson3430b322010-11-29 14:24:51 -080066 error 1 "You must run gen_test_keys.sh to generate test keys first."
Bill Richardsonf1372d92010-06-11 09:15:55 -070067}
68