1#!/bin/bash 2 3# Copyright (c) 2010 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# Wrapper to run the platform_BootPerfServer autotest, and store the 8# results for later analysis by the 'showbootdata' script. 9# 10# NOTE: This script must be run from inside the chromeos build 11# chroot environment. 12# 13COMMONSH="/mnt/host/source/src/scripts/common.sh" 14. ${COMMONSH} || (echo "Unable to load ${COMMONSH}" && exit 1) 15 16# TODO(jrbarnette) The log files produced in this script will be 17# stored inside the chroot. So, from outside the chroot, this 18# script doesn't work. I don't know if this is easy to fix, but 19# you're welcome to try. Let me know how it goes. :-) 20assert_inside_chroot 21 22DEFINE_string output_dir "" "output directory for results" o 23DEFINE_string board "" "name of board we are testing" 24DEFINE_boolean keep_logs "$FLAGS_FALSE" "keep autotest results" k 25 26RUN_TEST="test_that" 27TEST='platform_BootPerfServer.bootperf' 28TMP_RESULTS="$(mktemp -d /tmp/bootperf.XXXXXX)" 29RESULTS_ROOT="results-1-$TEST" 30RESULTS_DIR=platform_BootPerfServer/results 31RESULTS_KEYVAL=$RESULTS_DIR/keyval 32RESULTS_SUMMARY_FILES=( 33 $RESULTS_DIR 34 keyval 35 platform_BootPerfServer/keyval 36 platform_BootPerfServer/platform_BootPerf/keyval 37 platform_BootPerfServer/platform_BootPerf/status 38 platform_BootPerfServer/status 39 platform_BootPerfServer/status.log 40 platform_BootPerfServer/sysinfo/cmdline 41 platform_BootPerfServer/sysinfo/cpuinfo 42 platform_BootPerfServer/sysinfo/modules 43 platform_BootPerfServer/sysinfo/uname 44 platform_BootPerfServer/sysinfo/version 45 status.log 46) 47 48# Structure of a results directory: 49# $RUNDIR.$ITER/ - directory 50# $RUNDIR_LOG - file 51# $RUNDIR_SUMMARY/ - directory 52# $RUNDIR_ALL_RESULTS/ - optional directory 53# $KEYVAL_SUMMARY/ - file 54# If you add any other content under the results directory, you'll 55# probably need to change extra_files(), below. 56RUNDIR=run 57RUNDIR_LOG=log.txt 58RUNDIR_SUMMARY=summary 59RUNDIR_ALL_RESULTS=logs 60KEYVAL_SUMMARY=results_keyval 61 62 63# Usage/help function. This function is known to the shflags library, 64# and mustn't be renamed. 65flags_help() { 66 cat <<END_USAGE >&2 67usage: $(basename $0) [ <options> ] <ip-address> [ <count> ] 68Options: 69 --output_dir <directory> 70 --o <directory> Specify output directory for results 71 72 --board <BOARDNAME> name of board we are testing (e.g. daisy) 73 74 --[no]keep_logs 75 -k Keep [don't keep] autotest log files 76Summary: 77 Run the platform_BootPerfServer autotest, and store results in the 78 given destination directory. The test target is specified by 79 <ip-address>. 80 81 By default, the test is run once; if <count> is given, the test is 82 run that many times. Note that the platform_BootPerfServer test 83 reboots the target 10 times, so the total number of reboots will 84 be 10*<count>. 85 86 If the destination directory doesn't exist, it is created. If the 87 destination directory already holds test results, additional 88 results are added in without overwriting earlier results. 89 90 If no destination is specified, the current directory is used, 91 provided that the directory is empty, or has been previously used 92 as a destination directory for this command. 93 94 By default, only a summary subset of the log files created by 95 autotest is preserved; with --keep_logs the (potentially large) 96 autotest logs are preserved with the test results. 97END_USAGE 98 return $FLAGS_TRUE 99} 100 101usage() { 102 if [ $# -gt 0 ]; then 103 error "$(basename $0): $*" 104 echo >&2 105 fi 106 flags_help 107 exit 1 108} 109 110# List any files in the current directory not created as output 111# from running this script. 112extra_files() { 113 ls | grep -v "^$RUNDIR[.]...\$" | 114 grep -v $KEYVAL_SUMMARY 115} 116 117# Main function to run the boot performance test. Run the boot 118# performance test for the given count, putting output into the 119# current directory. 120# 121# Arguments are <ip-address> and <count> arguments, as for the main 122# command. 123# 124# We terminate test runs if "test_that" ever fails to produce the 125# results keyval file; generally this is the result of a serious 126# error (e.g. disk full) that won't go away if we just plow on. 127run_boot_test() { 128 local remote="$1" 129 local count="${2:-1}" 130 131 local iter=$(expr "$(echo $RUNDIR.???)" : '.*\(...\)') 132 if [ "$iter" != "???" ]; then 133 iter=$(echo $iter | awk '{printf "%03d\n", $1 + 1}') 134 else 135 iter=000 136 fi 137 138 i=0 139 while [ $i -lt $count ]; do 140 local iter_rundir=$RUNDIR.$iter 141 local logfile=$(pwd)/$iter_rundir/$RUNDIR_LOG 142 local summary_dir=$iter_rundir/$RUNDIR_SUMMARY 143 local all_results_dir=$iter_rundir/$RUNDIR_ALL_RESULTS 144 145 mkdir $iter_rundir 146 echo "$(date '+%T') - $logfile" 147 148 $RUN_TEST --results_dir="$TMP_RESULTS" --args "10" $BOARD \ 149 "$remote" $TEST >$logfile 2>&1 150 if [ ! -e "$TMP_RESULTS/$RESULTS_ROOT/$RESULTS_KEYVAL" ]; then 151 error "No results file; terminating test runs." 152 error "Check $logfile for output from the test run," 153 error "and see $TMP_RESULTS for full test logs and output." 154 return 155 fi 156 mkdir $summary_dir 157 tar cf - -C $TMP_RESULTS/$RESULTS_ROOT "${RESULTS_SUMMARY_FILES[@]}" | 158 tar xf - -C $summary_dir 159 if [ $FLAGS_keep_logs -eq $FLAGS_TRUE ]; then 160 mv $TMP_RESULTS $all_results_dir 161 chmod 755 $all_results_dir 162 else 163 rm -rf $TMP_RESULTS 164 fi 165 i=$(expr $i + 1) 166 iter=$(echo $iter | awk '{printf "%03d\n", $1 + 1}') 167 done 168 date '+%T' 169 cat $RUNDIR.???/$RUNDIR_SUMMARY/$RESULTS_KEYVAL >$KEYVAL_SUMMARY 170} 171 172# Main routine - check validity of the (already parsed) command line 173# options. 'cd' to the results directory, if it was specified. If 174# all the arguments checks pass, hand control to run_boot_test 175main() { 176 if [ $# -lt 1 ]; then 177 usage "Missing target host address" 178 elif [ $# -gt 2 ]; then 179 usage "Too many arguments" 180 fi 181 182 if [ -n "${FLAGS_board}" ]; then 183 BOARD="--board=${FLAGS_board}" 184 fi 185 186 if [ -n "${FLAGS_output_dir}" ]; then 187 if [ ! -d "${FLAGS_output_dir}" ]; then 188 if ! mkdir "${FLAGS_output_dir}"; then 189 usage "Unable to create ${FLAGS_output_dir}" 190 fi 191 fi 192 cd "${FLAGS_output_dir}" || 193 usage "No permissions to chdir to ${FLAGS_output_dir}" 194 elif [ -n "$(extra_files)" ]; then 195 error "No results directory specified, and current directory" 196 error "contains contents other than run results." 197 error "You can override this error by using the --output_dir option" 198 usage 199 fi 200 201 # Check the count argument. 202 # N.B. the test [ "$2" -eq "$2" ] tests whether "$2" is valid as a 203 # number; when it fails it will also report a syntax error (which 204 # we suppress). 205 if [ -n "$2" ]; then 206 if ! [ "$2" -eq "$2" ] 2>/dev/null || [ "$2" -le 0 ]; then 207 usage "<count> argument must be a positive number" 208 fi 209 fi 210 211 run_boot_test "$@" 212} 213 214# shflags defines --help implicitly; if it's used on the command 215# line FLAGS will invoke flags_help, set FLAGS_help to TRUE, and 216# then return false. To avoid printing help twice, we have to check 217# for that case here. 218if ! FLAGS "$@"; then 219 if [ ${FLAGS_help} -eq ${FLAGS_TRUE} ]; then 220 exit 0 221 else 222 usage 223 fi 224fi 225 226eval main "${FLAGS_ARGV}" 227