Gaurav Shah | 445925f | 2010-03-19 16:19:09 -0700 | [diff] [blame] | 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. |
Bill Richardson | 793e1b4 | 2010-08-20 07:58:43 -0700 | [diff] [blame] | 8 | SCRIPT_DIR=$(dirname $(readlink -f "$0")) |
Gaurav Shah | 445925f | 2010-03-19 16:19:09 -0700 | [diff] [blame] | 9 | |
vbendeb | 70e9509 | 2010-06-14 15:41:27 -0700 | [diff] [blame] | 10 | ROOT_DIR="$(dirname ${SCRIPT_DIR})" |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame] | 11 | BUILD_DIR="${BUILD}" |
Bill Richardson | 3e3790d | 2014-07-14 15:05:54 -0700 | [diff] [blame^] | 12 | BIN_DIR="${BUILD_DIR}/install_for_test" |
vbendeb | 70e9509 | 2010-06-14 15:41:27 -0700 | [diff] [blame] | 13 | TEST_DIR="${BUILD_DIR}/tests" |
Gaurav Shah | 445925f | 2010-03-19 16:19:09 -0700 | [diff] [blame] | 14 | TESTKEY_DIR=${SCRIPT_DIR}/testkeys |
| 15 | TESTCASE_DIR=${SCRIPT_DIR}/testcases |
vbendeb | 70e9509 | 2010-06-14 15:41:27 -0700 | [diff] [blame] | 16 | TESTKEY_SCRATCH_DIR=${TEST_DIR}/testkeys |
| 17 | |
| 18 | if [ ! -d ${TESTKEY_SCRATCH_DIR} ]; then |
Randall Spangler | 844bce5 | 2013-01-15 16:16:43 -0800 | [diff] [blame] | 19 | mkdir -p ${TESTKEY_SCRATCH_DIR} |
vbendeb | 70e9509 | 2010-06-14 15:41:27 -0700 | [diff] [blame] | 20 | fi |
Gaurav Shah | 445925f | 2010-03-19 16:19:09 -0700 | [diff] [blame] | 21 | |
| 22 | # Color output encodings. |
| 23 | COL_RED='\E[31;1m' |
| 24 | COL_GREEN='\E[32;1m' |
| 25 | COL_YELLOW='\E[33;1m' |
| 26 | COL_BLUE='\E[34;1m' |
| 27 | COL_STOP='\E[0;m' |
| 28 | |
| 29 | hash_algos=( sha1 sha256 sha512 ) |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 30 | key_lengths=( 1024 2048 4096 8192 ) |
Gaurav Shah | 445925f | 2010-03-19 16:19:09 -0700 | [diff] [blame] | 31 | |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 32 | function happy { |
| 33 | echo -e "${COL_GREEN}$*${COL_STOP}" 1>&2 |
Gaurav Shah | 445925f | 2010-03-19 16:19:09 -0700 | [diff] [blame] | 34 | } |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 35 | |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 36 | # args: [nested level [message]] |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 37 | function warning { |
| 38 | echo -e "${COL_YELLOW}WARNING: $*${COL_STOP}" 1>&2 |
| 39 | } |
| 40 | |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 41 | # args: [nested level [message]] |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 42 | function error { |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 43 | 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 Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 60 | exit 1 |
| 61 | } |
| 62 | |
| 63 | function check_test_keys { |
| 64 | [ -d ${TESTKEY_DIR} ] || \ |
Bill Richardson | 3430b32 | 2010-11-29 14:24:51 -0800 | [diff] [blame] | 65 | error 1 "You must run gen_test_keys.sh to generate test keys first." |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 66 | } |
| 67 | |