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
9PROG=$0
10
11# THIS_SCRIPT_PATH is typically as follows
12#   /usr/local/autotest/tests/firmware_TouchMTB/tools/machine_replay.sh
13THIS_SCRIPT_PATH=`realpath $0`
14
15# PROJ_PATH would be
16#   /usr/local/autotest/tests/firmware_TouchMTB
17TOOLS_SUBDIR="tools"
18PROJ_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
25DEFINE_string board_path "" "the unit test path of the board" "b"
26
27FLAGS_HELP="USAGE: $PROG [flags]"
28
29FLAGS "$@" || exit 1
30eval set -- "${FLAGS_ARGV}"
31set -e
32
33# Check if the board path has been specified.
34if [ -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"
38fi
39
40
41# Make an empty directory to hold the unit test files.
42TMP_LOG_ROOT="/tmp/touch_firmware_test"
43make_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
49if [ `echo "$FLAGS_board_path" | head -c1` != "/" ]; then
50  FLAGS_board_path="${PROJ_PATH}/$FLAGS_board_path"
51fi
52
53# Copy the unit test logs to the directory just created.
54if [ -d ${FLAGS_board_path} ]; then
55  cp -r ${FLAGS_board_path}/* "$TMP_LOG_ROOT"
56else
57  die "Error: the board path $FLAGS_board_path does not exist!"
58fi
59
60# Replay the logs on the machine.
61cd $PROJ_PATH
62export DISPLAY=:0
63export XAUTHORITY=/home/chronos/.Xauthority
64for 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
68done
69