1 #!/bin/sh 2 3 # Copyright (c) 2013 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 # What this script does: 8 # ---------------------- 9 # (1) run machine_replay.sh on the remote machine to replay the gestures 10 # and to generate new logs, 11 # (2) remove the old logs in tests/logs/ for every board on the host, and 12 # (3) scp the new logs from the machine into the proper board on the host. 13 # 14 # Note: this script needs to be invoked in the firmware_TouchMTB home directory: 15 # .../autotest/files/client/site_tests/firmware_TouchMTB 16 # inside chroot on the host. 17 # 18 # Usage: 19 # (cr) .../firmware_TouchMTB $ tools/host_replay.sh -m $MACHINE_IP -s 20 # Example: 21 # (cr) .../firmware_TouchMTB $ tools/host_replay.sh -m 172.30.210.110 -s 22 23 24 # Confirm that current working directory is firmware_TouchMTB. 25 PROG=$0 26 BASE_PROJ="firmware_TouchMTB" 27 if [ `basename $(realpath .)` != "$BASE_PROJ" ]; then 28 echo "You need to execute $PROG under $BASE_PROJ on the host." 29 exit 1 30 fi 31 32 # Source the local common script. 33 . "$(dirname "$PROG")/firmware_common.sh" || exit 1 34 35 # Source the cros common script and assert that this is inside chroot. 36 source_cros_common_script 37 assert_inside_chroot 38 39 40 # Read command flags 41 . /usr/share/misc/shflags 42 DEFINE_string machine_ip "" "the machine ip address" "m" 43 44 FLAGS_HELP="USAGE: $PROG [flags]" 45 46 FLAGS "$@" || exit 1 47 eval set -- "${FLAGS_ARGV}" 48 set -e 49 50 # Check if the machine ip has been specified. 51 if [ -z $FLAGS_machine_ip ]; then 52 echo You need to specify the machine ip with the option '"-m"'. E.g.; 53 echo -e "(cr) $ tools/host_replay.sh -m 10.20.30.40\n" 54 exit 1 55 fi 56 57 58 MACHINE_PROJ_DIR="/usr/local/autotest/tests/$BASE_PROJ" 59 MACHINE_LOG_ROOT="/tmp/touch_firmware_test" 60 MACHINE_REPLAY="tools/machine_replay.sh" 61 HOST_TMP_LOG_DIR="/tmp/touch_firmware_logs" 62 63 64 # Invoke the machine replay script. 65 run_remote_machine_replay() { 66 echo Replaying on the machine_ip: $FLAGS_machine_ip 67 ssh root@$FLAGS_machine_ip "${MACHINE_PROJ_DIR}/${MACHINE_REPLAY} -b $board" 68 } 69 70 71 # Remove the old log files on the host. 72 # There usually exist multiple sub-directories for multiple rounds 73 # (generated by the robot or manually) for every board. 74 # We allow only a log file in every round. Since the new log files are 75 # to be generated in next step, we need to remove the old log ones here. 76 # Otherwise, it becomes a bit difficult to determine which one is 77 # the old log file in every round sub-directory to remove manually. 78 # These new logs are supposed to be checked in to gerrit so that the 79 # unit tests can be run correctly. 80 remove_old_logs_on_host() { 81 log_files=$(find ${board} -name "*.log" -type f 2>/dev/null) 82 # Since there are multiple filenames in $log_files, note that 83 # there should be no double quotes around $log_files after git rm. 84 [ -n "$log_files" ] && git rm $log_files 85 } 86 87 88 # Scp the new logs from the machine to the host. 89 scp_logs_from_machine_to_host() { 90 # Get the new log files generated on the machine side. 91 LOG_PATHNAMES=`ssh root@$FLAGS_machine_ip "ls ${MACHINE_LOG_ROOT}/*/*.log"` 92 93 make_empty_dir "$HOST_TMP_LOG_DIR" 94 scp root@$FLAGS_machine_ip:"${MACHINE_LOG_ROOT}"/*/*.log "$HOST_TMP_LOG_DIR" 95 for file in $LOG_PATHNAMES; do 96 # Read the log base directories and the log filenames so that we know 97 # how to copy the files into the proper paths on the host. 98 read log_dir log_file <<< `echo $file | awk -F/ 'BEGIN{OFS=" ";} \ 99 {print $(NF-1), $NF;}'` 100 cp "${HOST_TMP_LOG_DIR}/${log_file}" "${board}/${log_dir}/${log_file}" 101 done 102 rm -fr "$HOST_TMP_LOG_DIR" 103 } 104 105 106 boards=`find tests/logs/* -maxdepth 0 -type d` 107 for board in $boards; do 108 run_remote_machine_replay 109 remove_old_logs_on_host 110 scp_logs_from_machine_to_host 111 done 112