blob: 43cdf6d2f7f03697eede0e321a0a3d11d263e92c [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}"
vbendeb70e95092010-06-14 15:41:27 -070012UTIL_DIR="${BUILD_DIR}/utility"
13TEST_DIR="${BUILD_DIR}/tests"
Gaurav Shah445925f2010-03-19 16:19:09 -070014TESTKEY_DIR=${SCRIPT_DIR}/testkeys
15TESTCASE_DIR=${SCRIPT_DIR}/testcases
vbendeb70e95092010-06-14 15:41:27 -070016TESTKEY_SCRATCH_DIR=${TEST_DIR}/testkeys
17
18if [ ! -d ${TESTKEY_SCRATCH_DIR} ]; then
Randall Spangler844bce52013-01-15 16:16:43 -080019 mkdir -p ${TESTKEY_SCRATCH_DIR}
vbendeb70e95092010-06-14 15:41:27 -070020fi
Gaurav Shah445925f2010-03-19 16:19:09 -070021
22# Color output encodings.
23COL_RED='\E[31;1m'
24COL_GREEN='\E[32;1m'
25COL_YELLOW='\E[33;1m'
26COL_BLUE='\E[34;1m'
27COL_STOP='\E[0;m'
28
29hash_algos=( sha1 sha256 sha512 )
Bill Richardson3430b322010-11-29 14:24:51 -080030key_lengths=( 1024 2048 4096 8192 )
Gaurav Shah445925f2010-03-19 16:19:09 -070031
Bill Richardsonf1372d92010-06-11 09:15:55 -070032function happy {
33 echo -e "${COL_GREEN}$*${COL_STOP}" 1>&2
Gaurav Shah445925f2010-03-19 16:19:09 -070034}
Bill Richardsonf1372d92010-06-11 09:15:55 -070035
Bill Richardson3430b322010-11-29 14:24:51 -080036# args: [nested level [message]]
Bill Richardsonf1372d92010-06-11 09:15:55 -070037function warning {
38 echo -e "${COL_YELLOW}WARNING: $*${COL_STOP}" 1>&2
39}
40
Bill Richardson3430b322010-11-29 14:24:51 -080041# args: [nested level [message]]
Bill Richardsonf1372d92010-06-11 09:15:55 -070042function error {
Bill Richardson3430b322010-11-29 14:24:51 -080043 local lev=${1:-}
44 case "${1:-}" in
45 [0-9]*)
46 lev=$1
47 shift
48 ;;
49 *) lev=0
50 ;;
51 esac
52 local x=$(caller $lev)
53 local cline=${x%% *}
54 local cfunc=${x#* }
55 cfunc=${cfunc##*/}
56 local args="$*"
57 local spacer=${args:+: }
58 echo -e "${COL_RED}ERROR at ${cfunc}, line ${cline}${spacer}${args}" \
59 "${COL_STOP}" 1>&2
Bill Richardsonf1372d92010-06-11 09:15:55 -070060 exit 1
61}
62
63function check_test_keys {
64 [ -d ${TESTKEY_DIR} ] || \
Bill Richardson3430b322010-11-29 14:24:51 -080065 error 1 "You must run gen_test_keys.sh to generate test keys first."
Bill Richardsonf1372d92010-06-11 09:15:55 -070066}
67