1*aed3e508SAndroid Build Coastguard Worker#!/bin/sh 2*aed3e508SAndroid Build Coastguard Worker 3*aed3e508SAndroid Build Coastguard Worker# Copyright 2012 The ChromiumOS Authors 4*aed3e508SAndroid Build Coastguard Worker# Use of this source code is governed by a BSD-style license that can be 5*aed3e508SAndroid Build Coastguard Worker# found in the LICENSE file. 6*aed3e508SAndroid Build Coastguard Worker 7*aed3e508SAndroid Build Coastguard Worker. /usr/share/misc/shflags 8*aed3e508SAndroid Build Coastguard Worker 9*aed3e508SAndroid Build Coastguard WorkerDEFINE_string out "testlog.txt" "Output log from replay" 10*aed3e508SAndroid Build Coastguard WorkerDEFINE_string only_honor "Tap Enable,Sensitivity" \ 11*aed3e508SAndroid Build Coastguard Worker "Which properties from the log should be honored" 12*aed3e508SAndroid Build Coastguard Worker 13*aed3e508SAndroid Build Coastguard WorkerFLAGS_HELP="usage: replay_log [--out testlog.txt] [--only_honor Props] \ 14*aed3e508SAndroid Build Coastguard Workerinfile|feedback_url" 15*aed3e508SAndroid Build Coastguard Worker 16*aed3e508SAndroid Build Coastguard WorkerFLAGS "$@" || exit 1 17*aed3e508SAndroid Build Coastguard Workereval set -- "${FLAGS_ARGV}" 18*aed3e508SAndroid Build Coastguard Worker 19*aed3e508SAndroid Build Coastguard Worker# Only now can we die on error. shflags functions leak non-zero error codes, 20*aed3e508SAndroid Build Coastguard Worker# so will die prematurely if 'set -e' is specified before now. 21*aed3e508SAndroid Build Coastguard Workerset -e 22*aed3e508SAndroid Build Coastguard Worker 23*aed3e508SAndroid Build Coastguard Workerinfile="${1}" 24*aed3e508SAndroid Build Coastguard Workerif [ $# -ne 1 ]; then 25*aed3e508SAndroid Build Coastguard Worker echo $FLAGS_HELP 26*aed3e508SAndroid Build Coastguard Worker exit 1 27*aed3e508SAndroid Build Coastguard Workerfi 28*aed3e508SAndroid Build Coastguard Worker 29*aed3e508SAndroid Build Coastguard WorkerCOOKIE_DIR="$(readlink -f "$(dirname "$0")/../cookies")" 30*aed3e508SAndroid Build Coastguard WorkerCOOKIE_FILE="${COOKIE_DIR}/login.cookie" 31*aed3e508SAndroid Build Coastguard Worker 32*aed3e508SAndroid Build Coastguard Workersetup_login_cookie_dir() { 33*aed3e508SAndroid Build Coastguard Worker mkdir -p "$COOKIE_DIR" 34*aed3e508SAndroid Build Coastguard Worker chmod 0700 "$COOKIE_DIR" 35*aed3e508SAndroid Build Coastguard Worker} 36*aed3e508SAndroid Build Coastguard Worker 37*aed3e508SAndroid Build Coastguard Workerlogin() { 38*aed3e508SAndroid Build Coastguard Worker setup_login_cookie_dir 39*aed3e508SAndroid Build Coastguard Worker read -p "Username (without @google.com): " USER 40*aed3e508SAndroid Build Coastguard Worker read -s -p "Password: " PASS 41*aed3e508SAndroid Build Coastguard Worker echo 42*aed3e508SAndroid Build Coastguard Worker read -p "OTP: " OTP 43*aed3e508SAndroid Build Coastguard Worker LOGIN_POST_FILE="$COOKIE_DIR/login.post" 44*aed3e508SAndroid Build Coastguard Worker LOGIN_RESULTS_FILE="$COOKIE_DIR/login.results" 45*aed3e508SAndroid Build Coastguard Worker echo "u=${USER}&pw=${PASS}&otp=${OTP}" > "$LOGIN_POST_FILE" 46*aed3e508SAndroid Build Coastguard Worker echo "Logging in..." 47*aed3e508SAndroid Build Coastguard Worker curl -s -c "$COOKIE_FILE" -L -d @"$LOGIN_POST_FILE" \ 48*aed3e508SAndroid Build Coastguard Worker 'https://login.corp.google.com/login?ssoformat=CORP_SSO' \ 49*aed3e508SAndroid Build Coastguard Worker > $LOGIN_RESULTS_FILE 50*aed3e508SAndroid Build Coastguard Worker local should_abort="$FLAGS_FALSE" 51*aed3e508SAndroid Build Coastguard Worker if grep -i error ${LOGIN_RESULTS_FILE} >/dev/null; then 52*aed3e508SAndroid Build Coastguard Worker echo Login failure. 53*aed3e508SAndroid Build Coastguard Worker should_abort="$FLAGS_TRUE" 54*aed3e508SAndroid Build Coastguard Worker else 55*aed3e508SAndroid Build Coastguard Worker echo Login success 56*aed3e508SAndroid Build Coastguard Worker fi 57*aed3e508SAndroid Build Coastguard Worker rm -f "$LOGIN_POST_FILE" 58*aed3e508SAndroid Build Coastguard Worker rm -f "$LOGIN_RESULTS_FILE" 59*aed3e508SAndroid Build Coastguard Worker if [ $should_abort -eq $FLAGS_TRUE ]; then 60*aed3e508SAndroid Build Coastguard Worker exit 1 61*aed3e508SAndroid Build Coastguard Worker fi 62*aed3e508SAndroid Build Coastguard Worker} 63*aed3e508SAndroid Build Coastguard Worker 64*aed3e508SAndroid Build Coastguard Workerif [[ "$infile" = "https://"* ]]; then 65*aed3e508SAndroid Build Coastguard Worker LOG_IDNUM=$(echo "$infile" | sed 's/.*[^0-9]\([0-9][0-9][0-9][0-9]*\).*/\1/') 66*aed3e508SAndroid Build Coastguard Worker LOG_FILE="report-${LOG_IDNUM}-system_logs.bz2" 67*aed3e508SAndroid Build Coastguard Worker LOG_URL="https://feedback.corp.googleusercontent.com/\ 68*aed3e508SAndroid Build Coastguard Workerbinarydata/${LOG_FILE}?id=${LOG_IDNUM}&logIndex=0" 69*aed3e508SAndroid Build Coastguard Worker if [ -f "${LOG_FILE}" ]; then 70*aed3e508SAndroid Build Coastguard Worker echo already have file 71*aed3e508SAndroid Build Coastguard Worker infile=${LOG_FILE} 72*aed3e508SAndroid Build Coastguard Worker else 73*aed3e508SAndroid Build Coastguard Worker echo downloading log file 74*aed3e508SAndroid Build Coastguard Worker TRIES=0 75*aed3e508SAndroid Build Coastguard Worker while true; do 76*aed3e508SAndroid Build Coastguard Worker http_proxy=http://cache.corp.google.com:3128/ curl -b "$COOKIE_FILE" \ 77*aed3e508SAndroid Build Coastguard Worker -L -o "$LOG_FILE" "$LOG_URL" 78*aed3e508SAndroid Build Coastguard Worker TYPE="$(file -b "$LOG_FILE" | cut -d ' ' -f 1)" 79*aed3e508SAndroid Build Coastguard Worker if [[ "$TYPE" = bzip2 || "$TYPE" = Zip ]]; then 80*aed3e508SAndroid Build Coastguard Worker # download success 81*aed3e508SAndroid Build Coastguard Worker infile="$LOG_FILE" 82*aed3e508SAndroid Build Coastguard Worker break 83*aed3e508SAndroid Build Coastguard Worker fi 84*aed3e508SAndroid Build Coastguard Worker rm -f "$LOG_FILE" 85*aed3e508SAndroid Build Coastguard Worker TRIES=$((TRIES + 1)) 86*aed3e508SAndroid Build Coastguard Worker if [ $TRIES -eq 2 ]; then 87*aed3e508SAndroid Build Coastguard Worker echo Failed twice. Aborting 88*aed3e508SAndroid Build Coastguard Worker exit 1 89*aed3e508SAndroid Build Coastguard Worker fi 90*aed3e508SAndroid Build Coastguard Worker # login failure 91*aed3e508SAndroid Build Coastguard Worker echo 'Download failure. Logging in' 92*aed3e508SAndroid Build Coastguard Worker login 93*aed3e508SAndroid Build Coastguard Worker done 94*aed3e508SAndroid Build Coastguard Worker fi 95*aed3e508SAndroid Build Coastguard Workerfi 96*aed3e508SAndroid Build Coastguard Worker 97*aed3e508SAndroid Build Coastguard Worker# Convert the infile from a relative path to the realpath since we will 98*aed3e508SAndroid Build Coastguard Worker# change directory below. 99*aed3e508SAndroid Build Coastguard Workeroriginal_infile="$infile" 100*aed3e508SAndroid Build Coastguard Workerinfile="$(realpath $infile)" 101*aed3e508SAndroid Build Coastguard Worker 102*aed3e508SAndroid Build Coastguard Worker# Go to the Gestures source root 103*aed3e508SAndroid Build Coastguard Workercd $(dirname "$0")/.. 104*aed3e508SAndroid Build Coastguard Worker 105*aed3e508SAndroid Build Coastguard Workermake -j $(fgrep processor /proc/cpuinfo | wc -l) test 106*aed3e508SAndroid Build Coastguard Worker 107*aed3e508SAndroid Build Coastguard Workerexpand_input_file() { 108*aed3e508SAndroid Build Coastguard Worker # Get input filetype 109*aed3e508SAndroid Build Coastguard Worker intype="$(file -b "${infile}" | cut -d ' ' -f 1)" 110*aed3e508SAndroid Build Coastguard Worker # Extra check in case file gets ASCII wrong 111*aed3e508SAndroid Build Coastguard Worker if [ "$(head -n 1 "${infile}")" = "{" ]; then 112*aed3e508SAndroid Build Coastguard Worker intype="ASCII" 113*aed3e508SAndroid Build Coastguard Worker fi 114*aed3e508SAndroid Build Coastguard Worker 115*aed3e508SAndroid Build Coastguard Worker if [ "$intype" = "bzip2" -o "$intype" = "Zip" ]; then 116*aed3e508SAndroid Build Coastguard Worker # Expand to the bzip2ed file within 117*aed3e508SAndroid Build Coastguard Worker local raw_text_log="raw_text_log.txt" 118*aed3e508SAndroid Build Coastguard Worker CAT=bzcat 119*aed3e508SAndroid Build Coastguard Worker if [ "$intype" = "Zip" ]; then 120*aed3e508SAndroid Build Coastguard Worker CAT=zcat 121*aed3e508SAndroid Build Coastguard Worker fi 122*aed3e508SAndroid Build Coastguard Worker $CAT "$infile" > "$raw_text_log" 123*aed3e508SAndroid Build Coastguard Worker cp "$raw_text_log" "full_feedback_log.txt" 124*aed3e508SAndroid Build Coastguard Worker if fgrep -q hack-33025-touchpad_activity "$raw_text_log"; then 125*aed3e508SAndroid Build Coastguard Worker # Expand the hack touchpad activity log 126*aed3e508SAndroid Build Coastguard Worker awk "/hack-33025-touchpad_activity/{found=1} found{print}" \ 127*aed3e508SAndroid Build Coastguard Worker "$raw_text_log" > "$raw_text_log".tmp 128*aed3e508SAndroid Build Coastguard Worker mv "$raw_text_log".tmp "$raw_text_log" 129*aed3e508SAndroid Build Coastguard Worker fi 130*aed3e508SAndroid Build Coastguard Worker 131*aed3e508SAndroid Build Coastguard Worker zlogs="$(cat "$raw_text_log" | uudecode -o - | tar xvf -)" 132*aed3e508SAndroid Build Coastguard Worker rm "$raw_text_log" 133*aed3e508SAndroid Build Coastguard Worker # take newest log and reduce to next case 134*aed3e508SAndroid Build Coastguard Worker cp "$(ls -t $zlogs | grep touchpad_activity | head -n 1)" log.gz 135*aed3e508SAndroid Build Coastguard Worker 136*aed3e508SAndroid Build Coastguard Worker # Also expand evdev log 137*aed3e508SAndroid Build Coastguard Worker zcat "$(ls -t $zlogs | grep cmt_input_events | head -n 1)" > evlog.txt \ 138*aed3e508SAndroid Build Coastguard Worker || true 139*aed3e508SAndroid Build Coastguard Worker 140*aed3e508SAndroid Build Coastguard Worker rm -f $zlogs 141*aed3e508SAndroid Build Coastguard Worker infile="log.gz" 142*aed3e508SAndroid Build Coastguard Worker intype="gzip" 143*aed3e508SAndroid Build Coastguard Worker fi 144*aed3e508SAndroid Build Coastguard Worker 145*aed3e508SAndroid Build Coastguard Worker if [ "$intype" = "gzip" ]; then 146*aed3e508SAndroid Build Coastguard Worker zcat "$infile" > log.txt 147*aed3e508SAndroid Build Coastguard Worker infile="log.txt" 148*aed3e508SAndroid Build Coastguard Worker intype="ASCII" 149*aed3e508SAndroid Build Coastguard Worker fi 150*aed3e508SAndroid Build Coastguard Worker 151*aed3e508SAndroid Build Coastguard Worker if [ "$intype" != "ASCII" ]; then 152*aed3e508SAndroid Build Coastguard Worker echo "Unable to read input file" 153*aed3e508SAndroid Build Coastguard Worker exit 1 154*aed3e508SAndroid Build Coastguard Worker fi 155*aed3e508SAndroid Build Coastguard Worker} 156*aed3e508SAndroid Build Coastguard Worker 157*aed3e508SAndroid Build Coastguard Workerrun_test() { 158*aed3e508SAndroid Build Coastguard Worker expand_input_file 159*aed3e508SAndroid Build Coastguard Worker # We would like the shell to survive no matter whether ./test succeeds or not. 160*aed3e508SAndroid Build Coastguard Worker result=0 161*aed3e508SAndroid Build Coastguard Worker ./test --gtest_also_run_disabled_tests \ 162*aed3e508SAndroid Build Coastguard Worker --gtest_filter="ActivityReplayTest.DISABLED_SimpleTest" \ 163*aed3e508SAndroid Build Coastguard Worker --outfile="$FLAGS_out" --only_honor="$FLAGS_only_honor" --in="$infile" || 164*aed3e508SAndroid Build Coastguard Worker result=$? 165*aed3e508SAndroid Build Coastguard Worker} 166*aed3e508SAndroid Build Coastguard Worker 167*aed3e508SAndroid Build Coastguard Worker# If infile is a file, test this log as before and there is no redirection. 168*aed3e508SAndroid Build Coastguard Worker# If infile is a directory, test all logs in the directory, and output 169*aed3e508SAndroid Build Coastguard Worker# the test statistics at the end. 170*aed3e508SAndroid Build Coastguard Workerif [ -f "$infile" ]; then 171*aed3e508SAndroid Build Coastguard Worker echo "$original_infile is a file." 172*aed3e508SAndroid Build Coastguard Worker run_test 173*aed3e508SAndroid Build Coastguard Workerelif [ -d "$infile" ]; then 174*aed3e508SAndroid Build Coastguard Worker statistics_result="$(mktemp)" 175*aed3e508SAndroid Build Coastguard Worker echo -e "\nInput directory: $original_infile\n" > $statistics_result 176*aed3e508SAndroid Build Coastguard Worker indir="$infile" 177*aed3e508SAndroid Build Coastguard Worker files=$(ls "$indir") 178*aed3e508SAndroid Build Coastguard Worker count=0 179*aed3e508SAndroid Build Coastguard Worker passed=0 180*aed3e508SAndroid Build Coastguard Worker for file in $files; do 181*aed3e508SAndroid Build Coastguard Worker infile="$indir/$file" 182*aed3e508SAndroid Build Coastguard Worker if [ -f "$infile" ]; then 183*aed3e508SAndroid Build Coastguard Worker run_test 184*aed3e508SAndroid Build Coastguard Worker if [ $result -eq 0 ]; then 185*aed3e508SAndroid Build Coastguard Worker echo "[ PASSED ] $original_infile/$file" >> $statistics_result 186*aed3e508SAndroid Build Coastguard Worker passed=$(($passed + 1)) 187*aed3e508SAndroid Build Coastguard Worker else 188*aed3e508SAndroid Build Coastguard Worker echo "[ FAILED ] $original_infile/$file" >> $statistics_result 189*aed3e508SAndroid Build Coastguard Worker fi 190*aed3e508SAndroid Build Coastguard Worker count=$(($count + 1)) 191*aed3e508SAndroid Build Coastguard Worker fi 192*aed3e508SAndroid Build Coastguard Worker done 193*aed3e508SAndroid Build Coastguard Worker cat $statistics_result 194*aed3e508SAndroid Build Coastguard Worker rm -fr $statistics_result 195*aed3e508SAndroid Build Coastguard Worker echo -e "\n$passed out of $count tests passed.\n" 196*aed3e508SAndroid Build Coastguard Workerfi 197