Home | History | Annotate | Download | only in platform_GCC
      1 #!/bin/bash
      2 # Copyright (c) 2011 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 find_common_sh() {
      6   local common_paths=(/usr/lib/crosutils $(dirname "$0"))
      7   local path
      8 
      9   SCRIPT_ROOT=
     10   for path in "${common_paths[@]}"; do
     11     local common="${path}/common.sh"
     12     if ([ -r "${common}" ] && . "${common}" && [ -d "${SCRIPTS_DIR}" ]); then
     13       SCRIPT_ROOT="${path}"
     14       break
     15     fi
     16   done
     17 }
     18 find_common_sh
     19 . "${SCRIPT_ROOT}/common.sh" || ! echo "Unable to load common.sh" || exit 1
     20 
     21 DEFAULT_PRIVATE_KEY="${GCLIENT_ROOT}/src/scripts/mod_for_test_scripts/\
     22 ssh_keys/testing_rsa"
     23 
     24 TMP="/tmp/dejagnu-tests/"
     25 TMP_PRIVATE_KEY=${TMP}/private_key
     26 TMP_KNOWN_HOSTS=${TMP}/known_hosts
     27 CONTROL_PATH="${TMP}/%r@%h:%p"
     28 SSH_ARGS="-p22 -o StrictHostKeyChecking=no \
     29     -o UserKnownHostsFile=${TMP_KNOWN_HOSTS} -i ${TMP_PRIVATE_KEY}"
     30 
     31 dejagnu_init_remote() {
     32   mkdir -p ${TMP}
     33   cp ${DEFAULT_PRIVATE_KEY} ${TMP_PRIVATE_KEY}
     34   chmod 0400 ${TMP_PRIVATE_KEY}
     35   PS1=. TERM=linux ssh ${SSH_ARGS} -t -t -M -S "${CONTROL_PATH}" root@$1 \
     36       >/dev/null  2>&1 &
     37   echo $! > "${TMP}/master-pid"
     38   dejagnu_ssh root@$1 -- "echo Connection OK."
     39 }
     40 
     41 dejagnu_cleanup_remote() {
     42   set +e
     43   kill "$(cat ${TMP}/master-pid)"
     44   set -e
     45   rm -rf "${TMP}"
     46 }
     47 
     48 dejagnu_ssh() {
     49   COMMAND="ssh ${SSH_ARGS} -t -o ControlPath=${CONTROL_PATH} $@"
     50   # TODO(raymes): Remove this timeout hack once our tests run without
     51   # infinite loops.
     52   TIMEOUT_COMMAND="$(echo "$COMMAND" | sed "s/sh -c '/sh -c 'timeout 5 /g")"
     53   $TIMEOUT_COMMAND
     54 }
     55 
     56 dejagnu_scp() {
     57   scp ${SSH_ARGS} -o ControlPath="${CONTROL_PATH}" $@
     58 }
     59