]> xenbits.xensource.com Git - people/aperard/linux-chromebook.git/commitdiff
CHROMIUM: chromeos: Add script to update smatch error whitelist
authorSimon Que <sque@chromium.org>
Fri, 11 Jan 2013 01:14:37 +0000 (17:14 -0800)
committerChromeBot <chrome-bot@google.com>
Fri, 18 Jan 2013 23:15:50 +0000 (15:15 -0800)
This script can be used to add known smatch errors for new boards to the
smatch error whitelist.  It runs the kernel build and check for each new
board and aggregates the new errors into a log file.

BUG=chromium-os:37418
TEST=Run "./update_smatch_whitelist x86-generic amd64-generic daisy"
Make sure there was a log file produced containing new errors.

Change-Id: I6912b6a0d9b9d577af296b15ef1e356e55a9f3ce
Signed-off-by: Simon Que <sque@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/41079
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Mandeep Singh Baines <msb@chromium.org>
chromeos/scripts/update_smatch_whitelist [new file with mode: 0755]

diff --git a/chromeos/scripts/update_smatch_whitelist b/chromeos/scripts/update_smatch_whitelist
new file mode 100755 (executable)
index 0000000..11d5e98
--- /dev/null
@@ -0,0 +1,91 @@
+#! /bin/bash
+#
+# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+# Distributed under the terms of the GNU General Public License v2
+
+# Print help if no args provided.
+if [[ $# -eq 0 || $1 == "--help" || $1 == "-h" ]]; then
+       name=$(basename $0)
+       cat <<-EOF
+       USAGE: ./${name} [list of boards]
+         e.g. ./${name} x86-generic amd64-generic daisy
+         This command will build kernel for the following boards:
+           - x86-generic
+           - amd64-generic
+           - daisy
+         It will then generate a file containing all smatch errors not already
+         in the known errors whitelist.  Duplicates will be listed only once.
+
+         If chromeos-kernel is not cros_workon'd for a board, that board will
+         be skipped.
+       EOF
+       exit
+fi
+
+# Put board name arguments into a list.
+BOARDS=()
+SKIPPED_BOARDS=()
+while [[ $# -gt 0 ]]; do
+       board=$1
+       # If kernel is not cros-workon'd, then skip this board.
+       if cros_workon-${board} list | grep -q chromeos-kernel; then
+               BOARDS+=( "${board}" )
+       else
+               SKIPPED_BOARDS+=( "${board}" )
+       fi
+       shift
+done
+
+datestamp() {
+       date +%Y%m%d%H%M%s
+}
+
+# We want to ignore smatch test errors when building kernel, so that we can
+# collect those errors for updating the whitelist.
+export FEATURES='test test-fail-continue'
+export USE="smatch ignore_test_errors"
+LOG_FILES=()
+for board in "${BOARDS[@]}"; do
+       LOG_FILE=/tmp/${board}-kernel-$(datestamp).log
+
+       emerge-${board} chromeos-kernel |& tee "${LOG_FILE}"
+       pipestatus=${PIPESTATUS[*]}
+       if [[ ${pipestatus// } -ne 0 ]]; then
+               echo "Error building kernel for ${board}" >&2
+               exit 1
+       fi
+
+       grep "Non-whitelisted error found:" "${LOG_FILE}" | \
+               grep -o "kernel/files.*" | sort > "${LOG_FILE}.new_errors"
+       LOG_FILES+=( "${LOG_FILE}.new_errors" )
+done
+
+# Create a new log file to contain all errors, overwriting it if it already
+# exists.  For each board's new errors, add to this log file the errors that
+# haven't already been added.  This creates the union of all new errors.
+NEW_ERRORS_FILE=/tmp/smatch_new_errors-$(datestamp).log
+for log_file in "${LOG_FILES[@]}"; do
+       while read line; do
+               fgrep -q "${line}" "${NEW_ERRORS_FILE}" && continue
+               echo "${line}"
+       done < "${log_file}"
+done > "${NEW_ERRORS_FILE}"
+
+# Rename the new errors file to reflect the new boards, and move it to the
+# current working directory.
+BOARDS_NO_SPACES=$(printf -- -%s "${BOARDS[@]}")
+NEW_ERRORS_FILE_FINAL=smatch_new_errors${BOARDS_NO_SPACES}.log
+if [[ $(wc -l < "${NEW_ERRORS_FILE}") -ne 0 ]]; then
+       mv "${NEW_ERRORS_FILE}" "${NEW_ERRORS_FILE_FINAL}" || exit
+fi
+
+echo "*****************************************************"
+echo "Done building kernel for these boards: ${BOARDS[*]}"
+[[ ${#SKIPPED_BOARDS[@]} -gt 0 ]] && \
+       echo "Skipped these boards because kernel was not cros_workon'd:" \
+               "${SKIPPED_BOARDS[*]}"
+if [[ -e ${NEW_ERRORS_FILE_FINAL} ]]; then
+       echo "New smatch errors are in ${NEW_ERRORS_FILE_FINAL}"
+else
+       echo "No new smatch errors found."
+fi