summaryrefslogtreecommitdiff
path: root/tools/replay_log
blob: 27298ca92abd9a105f0039aa26ce0ca820264303 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/sh

# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

. /usr/share/misc/shflags

DEFINE_string out "testlog.txt" "Output log from replay"
DEFINE_string only_honor "Tap Enable,Sensitivity" \
    "Which properties from the log should be honored"

FLAGS_HELP="usage: replay_log [--out testlog.txt] [--only_honor Props] \
infile|feedback_url"

FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"

# Only now can we die on error.  shflags functions leak non-zero error codes,
# so will die prematurely if 'set -e' is specified before now.
set -e

infile="${1}"
if [ $# -ne 1 ]; then
  echo $FLAGS_HELP
  exit 1
fi

COOKIE_DIR="$(readlink -f "$(dirname "$0")/../cookies")"
COOKIE_FILE="${COOKIE_DIR}/login.cookie"

setup_login_cookie_dir() {
  mkdir -p "$COOKIE_DIR"
  chmod 0700 "$COOKIE_DIR"
}

login() {
  setup_login_cookie_dir
  read -p "Username (without @google.com): " USER
  read -s -p "Password: " PASS
  echo
  read -p "OTP: " OTP
  LOGIN_POST_FILE="$COOKIE_DIR/login.post"
  LOGIN_RESULTS_FILE="$COOKIE_DIR/login.results"
  echo "u=${USER}&pw=${PASS}&otp=${OTP}" > "$LOGIN_POST_FILE"
  echo "Logging in..."
  curl -s -c "$COOKIE_FILE" -L -d @"$LOGIN_POST_FILE" \
    'https://login.corp.google.com/login?ssoformat=CORP_SSO' \
    > $LOGIN_RESULTS_FILE
  local should_abort="$FLAGS_FALSE"
  if grep -i error ${LOGIN_RESULTS_FILE} >/dev/null; then
    echo Login failure.
    should_abort="$FLAGS_TRUE"
  else
    echo Login success
  fi
  rm -f "$LOGIN_POST_FILE"
  rm -f "$LOGIN_RESULTS_FILE"
  if [ $should_abort -eq $FLAGS_TRUE ]; then
    exit 1
  fi
}

if [[ "$infile" = "https://"* ]]; then
  LOG_IDNUM=$(echo "$infile" | sed 's/.*[^0-9]\([0-9][0-9][0-9][0-9]*\).*/\1/')
  LOG_FILE="report-${LOG_IDNUM}-system_logs.bz2"
  LOG_URL="https://feedback.corp.googleusercontent.com/\
binarydata/${LOG_FILE}?id=${LOG_IDNUM}&logIndex=0"
  if [ -f "${LOG_FILE}" ]; then
    echo already have file
    infile=${LOG_FILE}
  else
    echo downloading log file
    TRIES=0
    while true; do
      http_proxy=http://cache.corp.google.com:3128/ curl -b "$COOKIE_FILE" \
        -L -o "$LOG_FILE" "$LOG_URL"
      TYPE="$(file "$LOG_FILE")"
      if [[ "$TYPE" = *bzip2* ]]; then
        # download success
        infile="$LOG_FILE"
        break
      fi
      rm -f "$LOG_FILE"
      TRIES=$((TRIES + 1))
      if [ $TRIES -eq 2 ]; then
        echo Failed twice. Aborting
        exit 1
      fi
      # login failure
      echo 'Download failure. Logging in'
      login
    done
  fi
fi

# Go to the Gestures source root
cd $(dirname "$0")/..

make -j $(fgrep processor /proc/cpuinfo | wc -l) test

# Get input filetype
intype="$(file -b "${infile}" | cut -d ' ' -f 1)"
# Extra check in case file gets ASCII wrong
if [ "$(head -n 1 "${infile}")" = "{" ]; then
  intype="ASCII"
fi

if [ "$intype" = "bzip2" ]; then
  # Expand to the bzip2ed file within
  zlogs="$(bzcat "$infile" | uudecode -o - | tar xvf -)"
  # take newest log and reduce to next case
  mv "$(ls -t $zlogs | grep touchpad_activity | head -n 1)" log.gz
  rm -f $zlogs
  infile="log.gz"
  intype="gzip"
fi

if [ "$intype" = "gzip" ]; then
  zcat "$infile" > log.txt
  infile="log.txt"
  intype="ASCII"
fi

if [ "$intype" != "ASCII" ]; then
  echo "Unable to read input file"
  exit 1
fi

./test --gtest_also_run_disabled_tests \
    --gtest_filter="ActivityReplayTest.DISABLED_SimpleTest" \
    --outfile="$FLAGS_out" --only_honor="$FLAGS_only_honor" --in="$infile"