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
9DEFINE_string "log_root_dir" "" "the log root directory" "d"
10VERBOSE_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"
16DEFINE_string "verbose" "2" "$VERBOSE_MSG" "v"
17DEFINE_boolean "scores" false "display the summary scores" "s"
18DEFINE_boolean "individual" false \
19               "calculate statistics for every individual round" "i"
20
21PROG=$0
22EXAMPLES="
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"
32FLAGS_HELP=\
33"USAGE: $PROG [flags]
34
35Examples:
36$EXAMPLES
37"
38
39FLAGS "$@" || exit 1
40eval set -- "${FLAGS_ARGV}"
41set -e
42
43PROJ="firmware_TouchMTB"
44if [ -n "$FLAGS_log_root_dir" ]; then
45  LOG_ROOT="$FLAGS_log_root_dir"
46else
47  LOG_ROOT="/var/tmp"
48fi
49TEST_DIR="${LOG_ROOT}/touch_firmware_test"
50SUMMARY_ROOT="${LOG_ROOT}/summary"
51SUMMARY_BASE_DIR="summary_`date -u +%Y%m%d_%H%M%S`"
52SUMMARY_DIR="${SUMMARY_ROOT}/$SUMMARY_BASE_DIR"
53SUMMARY_FILE="${SUMMARY_DIR}/${SUMMARY_BASE_DIR}.txt"
54SUMMARY_TARBALL="${SUMMARY_BASE_DIR}.tbz2"
55SUMMARY_MODULE="firmware_summary.py"
56
57# Print an error message and exit.
58die() {
59  echo "$@"
60  exit 1
61}
62
63# Make sure that this script is invoked in a chromebook machine.
64if ! grep -q -i CHROMEOS_RELEASE /etc/lsb-release 2>/dev/null; then
65  die "Error: the script '$0' should be executed in a chromebook."
66fi
67
68# Make sure that the script is located in the correct directory.
69SCRIPT_DIR=$(dirname $(readlink -f $0))
70SCRIPT_BASE_DIR=$(echo "$SCRIPT_DIR" | awk -F/ '{print $NF}')
71if [ "$SCRIPT_BASE_DIR" != "$PROJ" ]; then
72  die "Error: the script '$0' should be located under $PROJ"
73fi
74
75# Make sure that TEST_DIR only contains the desired directories.
76echo "The following directories in $TEST_DIR will be included in your summary."
77ls "$TEST_DIR" --hide=latest
78read -p "Is this correct (y/n)?" response
79if [ "$response" != "y" ]; then
80  echo "You typed: $response"
81  die "Please remove those undesired directories from $TEST_DIR"
82fi
83
84# Create a summary directory.
85mkdir -p "$SUMMARY_DIR"
86
87# Copy all .html and .log files in the test directory to the summary directory.
88find "$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=""
96python "${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.
100cd $SUMMARY_ROOT
101tar -jcf "$SUMMARY_TARBALL" "$SUMMARY_BASE_DIR" 2>/dev/null
102echo "Summary report file: $SUMMARY_FILE"
103echo "Summary tarball: ${SUMMARY_ROOT}/$SUMMARY_TARBALL"
104