common.sh 1.5 KB

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