Home | History | Annotate | Download | only in firmware_TouchMTB
      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 # Read command flags
      8 . /usr/share/misc/shflags
      9 DEFINE_string "log_root_dir" "" "the log root directory" "d"
     10 VERBOSE_MSG=\
     11 "verbose level to display the summary metrics
     12      0:  hide some metrics statistics when they passed
     13      1:  display all metrics statistics
     14      2:  display all metrics statistics with raw metrics values
     15 "
     16 DEFINE_string "verbose" "2" "$VERBOSE_MSG" "v"
     17 DEFINE_boolean "scores" false "display the summary scores" "s"
     18 DEFINE_boolean "individual" false \
     19                "calculate statistics for every individual round" "i"
     20 
     21 PROG=$0
     22 EXAMPLES="
     23   # Display all metrics statistics with raw metrics values.
     24   $ $PROG -d /tmp
     25 
     26   # Display all metrics statistics without raw metrics values.
     27   $ $PROG -d /tmp -v 1
     28 
     29   # Hide some metrics statistics when they passed.
     30   $ $PROG -d /tmp -v 0
     31 "
     32 FLAGS_HELP=\
     33 "USAGE: $PROG [flags]
     34 
     35 Examples:
     36 $EXAMPLES
     37 "
     38 
     39 FLAGS "$@" || exit 1
     40 eval set -- "${FLAGS_ARGV}"
     41 set -e
     42 
     43 PROJ="firmware_TouchMTB"
     44 if [ -n "$FLAGS_log_root_dir" ]; then
     45   LOG_ROOT="$FLAGS_log_root_dir"
     46 else
     47   LOG_ROOT="/var/tmp"
     48 fi
     49 TEST_DIR="${LOG_ROOT}/touch_firmware_test"
     50 SUMMARY_ROOT="${LOG_ROOT}/summary"
     51 SUMMARY_BASE_DIR="summary_`date -u +%Y%m%d_%H%M%S`"
     52 SUMMARY_DIR="${SUMMARY_ROOT}/$SUMMARY_BASE_DIR"
     53 SUMMARY_FILE="${SUMMARY_DIR}/${SUMMARY_BASE_DIR}.txt"
     54 SUMMARY_TARBALL="${SUMMARY_BASE_DIR}.tbz2"
     55 SUMMARY_MODULE="firmware_summary.py"
     56 
     57 # Print an error message and exit.
     58 die() {
     59   echo "$@"
     60   exit 1
     61 }
     62 
     63 # Make sure that this script is invoked in a chromebook machine.
     64 if ! grep -q -i CHROMEOS_RELEASE /etc/lsb-release 2>/dev/null; then
     65   die "Error: the script '$0' should be executed in a chromebook."
     66 fi
     67 
     68 # Make sure that the script is located in the correct directory.
     69 SCRIPT_DIR=$(dirname $(readlink -f $0))
     70 SCRIPT_BASE_DIR=$(echo "$SCRIPT_DIR" | awk -F/ '{print $NF}')
     71 if [ "$SCRIPT_BASE_DIR" != "$PROJ" ]; then
     72   die "Error: the script '$0' should be located under $PROJ"
     73 fi
     74 
     75 # Make sure that TEST_DIR only contains the desired directories.
     76 echo "The following directories in $TEST_DIR will be included in your summary."
     77 ls "$TEST_DIR" --hide=latest
     78 read -p "Is this correct (y/n)?" response
     79 if [ "$response" != "y" ]; then
     80   echo "You typed: $response"
     81   die "Please remove those undesired directories from $TEST_DIR"
     82 fi
     83 
     84 # Create a summary directory.
     85 mkdir -p "$SUMMARY_DIR"
     86 
     87 # Copy all .html and .log files in the test directory to the summary directory.
     88 find "$TEST_DIR" \( -name \*.log -o -name \*.html \) \
     89   -exec cp -t "$SUMMARY_DIR" {} \;
     90 
     91 # Run firmware_summary module to derive the summary report.
     92 [ ${FLAGS_scores} -eq ${FLAGS_TRUE} ] && scores_flag="--scores" \
     93                                       || scores_flag=""
     94 [ ${FLAGS_individual} -eq ${FLAGS_TRUE} ] && individual_flag="--individual" \
     95                                           || individual_flag=""
     96 python "${SCRIPT_DIR}/$SUMMARY_MODULE" -m "$FLAGS_verbose" $individual_flag \
     97        $scores_flag -d "$SUMMARY_DIR" > "$SUMMARY_FILE"
     98 
     99 # Create a tarball for the summary files.
    100 cd $SUMMARY_ROOT
    101 tar -jcf "$SUMMARY_TARBALL" "$SUMMARY_BASE_DIR" 2>/dev/null
    102 echo "Summary report file: $SUMMARY_FILE"
    103 echo "Summary tarball: ${SUMMARY_ROOT}/$SUMMARY_TARBALL"
    104