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