Home | History | Annotate | Download | only in tools
      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 # This script describes how to replay the raw data and generate new logs.
      8 
      9 PROG=$0
     10 
     11 # THIS_SCRIPT_PATH is typically as follows
     12 #   /usr/local/autotest/tests/firmware_TouchMTB/tools/machine_replay.sh
     13 THIS_SCRIPT_PATH=`realpath $0`
     14 
     15 # PROJ_PATH would be
     16 #   /usr/local/autotest/tests/firmware_TouchMTB
     17 TOOLS_SUBDIR="tools"
     18 PROJ_PATH=${THIS_SCRIPT_PATH%/${TOOLS_SUBDIR}/$(basename $PROG)}
     19 
     20 # Source the local common script.
     21 . "${PROJ_PATH}/${TOOLS_SUBDIR}/firmware_common.sh" || exit 1
     22 
     23 # Read command flags
     24 . /usr/share/misc/shflags
     25 DEFINE_string board_path "" "the unit test path of the board" "b"
     26 
     27 FLAGS_HELP="USAGE: $PROG [flags]"
     28 
     29 FLAGS "$@" || exit 1
     30 eval set -- "${FLAGS_ARGV}"
     31 set -e
     32 
     33 # Check if the board path has been specified.
     34 if [ -z $FLAGS_board_path ]; then
     35   die "
     36     Should specify the unitest path of the board with the option '"-b"'. E.g.,
     37     (cr) $ tools/machine_replay.sh -b tests/logs/lumpy \n"
     38 fi
     39 
     40 
     41 # Make an empty directory to hold the unit test files.
     42 TMP_LOG_ROOT="/tmp/touch_firmware_test"
     43 make_empty_dir "$TMP_LOG_ROOT"
     44 
     45 # If this is a relative path, convert it to the correct absolute path
     46 # as this script might not be executed under $PROJ_PATH. This might occur
     47 # when executing the script through ssh.
     48 # Note: do not use "[[ "$FLAGS_board_path" = /* ]]" below for better protability
     49 if [ `echo "$FLAGS_board_path" | head -c1` != "/" ]; then
     50   FLAGS_board_path="${PROJ_PATH}/$FLAGS_board_path"
     51 fi
     52 
     53 # Copy the unit test logs to the directory just created.
     54 if [ -d ${FLAGS_board_path} ]; then
     55   cp -r ${FLAGS_board_path}/* "$TMP_LOG_ROOT"
     56 else
     57   die "Error: the board path $FLAGS_board_path does not exist!"
     58 fi
     59 
     60 # Replay the logs on the machine.
     61 cd $PROJ_PATH
     62 export DISPLAY=:0
     63 export XAUTHORITY=/home/chronos/.Xauthority
     64 for round_dir in "$TMP_LOG_ROOT"/*; do
     65   if [ -d $round_dir -a ! -L $round_dir ]; then
     66     python main.py -m complete --skip_html -i 3 --replay $round_dir
     67   fi
     68 done
     69