Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp697005imm; Wed, 4 Jul 2018 04:30:17 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcp+BR9b0acxYkIN99QVdhllr2ZPTgRGIzhbpP4+h9PNHU8lYcDZh59uHejY9MtwW0SQs6F X-Received: by 2002:a65:61af:: with SMTP id i15-v6mr1574514pgv.349.1530703817557; Wed, 04 Jul 2018 04:30:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530703817; cv=none; d=google.com; s=arc-20160816; b=t/m9NU8NqPlcdEjMlDVr3KB5UxnW++3jjkSM4eBs506wwFn0y7Px7ldEw9Xy1bBGr1 Xqugn8MCYdMNZ8UGRO6BMjX0P7c8yU4f2uXhfQLuDaxxIwWJGlGAiqHZ7w/+lytzNkY6 17QReYzlUx05aVtQlhx0VlCtNWnbhsBrRItJEuLt8JjlumOIwAMVgjFYhFQkHZybtwsO ah/fclpf5FH3AR329BKJzweYUgK+K1dlfD/yBaOH7UT7A36u7kR/Z6Hib8tSvP+bZ55Q VDG46ImgS7w5et4yJaEWeaYJrvw+sJ8e3IUiWlLbUgkjYPHhk0tQMVNzsMsf+5b5GlRD yiVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=AZhgXbBmruZXWwQotPZkgpFJZyl/w8znURiwIEpXWiA=; b=XuZCDiw/1uExE37sTHKXnrnvkrPk9jUU1y3zDxLv5Xvzc5gVTLsq6LHj2bEZPIy3mp +76wcShPzfh42IE8mmWIs8hhfR00A0VPHzLAkJfP+IebACDgdc4e7RZFGVyvULEJMPfW tF01mi6/mCAlCBr9NFbtaohFEYNDaqklXyGvbI1a1/nt5X5Uk0v0YWuKrqRX7DyKio1s xBZgGSiBImGl+gav4PgZ2+uSBQ6/BxoIUNW1VrCVvpz6tkcGUe7e7c1uew4S2biNiwSh c/QswbZsw7gx/TgXD7LjTxbc1XgNv1ac75hKkS/7xKipXm2mAhZ6rswe0g6UfZNxlJxm Uifg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b="PzRrEs5/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y20-v6si3283301plr.55.2018.07.04.04.30.01; Wed, 04 Jul 2018 04:30:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b="PzRrEs5/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933429AbeGDL2e (ORCPT + 99 others); Wed, 4 Jul 2018 07:28:34 -0400 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:19917 "EHLO smtp-fw-9102.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932576AbeGDL2d (ORCPT ); Wed, 4 Jul 2018 07:28:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1530703713; x=1562239713; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=AZhgXbBmruZXWwQotPZkgpFJZyl/w8znURiwIEpXWiA=; b=PzRrEs5/3xZaA8FQytNYLdJcmHl9zpVjYZBFF1eyMkYxswpeBj7qYwMP ysiGvjPdZLUTOd4FBjQ/gnSH9P0hq/rmnKFktrdXzKPTT6Fh3ZFBSXBLA PfL4iJJwEERP+Aw2UgeOgJQQU2ocm9Er3hisOTtWuaIO4bJ8XWFa5Qf7T g=; X-IronPort-AV: E=Sophos;i="5.51,306,1526342400"; d="scan'208";a="620783997" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-2a-f14f4a47.us-west-2.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 04 Jul 2018 11:28:30 +0000 Received: from EX13MTAUEB001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-2a-f14f4a47.us-west-2.amazon.com (8.14.7/8.14.7) with ESMTP id w64BSQp6017431 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Wed, 4 Jul 2018 11:28:28 GMT Received: from EX13D08UEB001.ant.amazon.com (10.43.60.245) by EX13MTAUEB001.ant.amazon.com (10.43.60.96) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 4 Jul 2018 11:28:27 +0000 Received: from EX13MTAUEA001.ant.amazon.com (10.43.61.82) by EX13D08UEB001.ant.amazon.com (10.43.60.245) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 4 Jul 2018 11:28:27 +0000 Received: from uc1a35a69ae4659.ant.amazon.com (10.28.85.80) by mail-relay.amazon.com (10.43.61.243) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Wed, 4 Jul 2018 11:28:26 +0000 From: Norbert Manthey To: David Woodhouse , Andrew Morton , Stephen Rothwell , "Randy Dunlap" CC: Linus Torvalds , Norbert Manthey , Subject: [build-check v2] scripts: add check_build script Date: Wed, 4 Jul 2018 13:28:14 +0200 Message-ID: <1530703699-27657-1-git-send-email-nmanthey@amazon.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <9A8BFC66-8723-4E33-B82F-BDF0DBE8133C@linux-foundation.org> References: <9A8BFC66-8723-4E33-B82F-BDF0DBE8133C@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This script performs build testing, by building several configurations several times. The script is introduced to improve the consistency of testing changes in the kernel configuration. This version build randconfig 10 times, as well as allyesconfig, allnoconfig and allmodconfig. Depending on the used machine and system setup, the script might take a while to finish. To make most out of the available CPUs, the script tries to get the number of CPUs and then assigned twice that amount as workers to the build commands. The script logs all the used config files, as well as the output of the build commands to a log directory "build_check_logs", so that this data can be retrieved after running the script. Signed-off-by: Norbert Manthey Signed-off-by: David Woodhouse --- v2: fix -j handling, extract number of CPUs from getconf or sysctl scripts/check_build.sh | 158 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100755 scripts/check_build.sh diff --git a/scripts/check_build.sh b/scripts/check_build.sh new file mode 100755 index 0000000..f0e93b0 --- /dev/null +++ b/scripts/check_build.sh @@ -0,0 +1,158 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Check whether kernel changes compile with multiple configurations. +# Configurations that fail for the current commit are tested on an upstream +# commit, and failures are ignored in case the configuration fails on the +# upstream commit as well. +# +# Usage: +# ./scripts/check_build.sh [upstream-commit] +# +# Example: +# ./scripts/check_build.sh origin/master + +# Fail early on error or uninitialized values +set -e -u + +# Write all files to this directory +declare -r LOG_DIR=build_check_logs + +# Set default value for worker, to be used for parallel build +declare -i WORKER=4 + +# Gather all configurations we should build, in form of make targets +collect_configurations () +{ + local CONFIGS="randconfig allyesconfig allnoconfig allmodconfig" + local -i I=0 + + while [ "$I" -le 8 ]; do I=$((I+1)); CONFIGS+=" randconfig"; done + + echo "$CONFIGS" +} + +# Try to extract number of processors and multiply by 2, and assign to worker +set_worker () +{ + local -i ONLINE_CPUS=$(getconf _NPROCESSORS_ONLN) + [ -n "$ONLINE_CPUS" ] || ONLINE_CPUS=$(getconf NPROCESSORS_ONLN) + [ -n "$ONLINE_CPUS" ] || ONLINE_CPUS=$(sysctl -a | egrep -i 'hw.ncpu' | cut -d' ' -f 2) + + if [ -z "$ONLINE_CPUS" ] || ! [[ "$ONLINE_CPUS" =~ ^[0-9]+$ ]] + then + echo "warning: could not extract number of online CPUs" + else + WORKER="$((ONLINE_CPUS * 2))" + fi + echo "[$SECONDS] use $WORKER workers for parallel build" +} + +# Build the kernel with the current configuration, return the status, log to $1 +build () +{ + local -r LOG_FILE="$1" + local -i STATUS=0 + + make clean -j "$WORKER" &> /dev/null + make -j "$WORKER" &>> "$LOG_FILE" || STATUS=$? + + echo "build status: $STATUS" >> "$LOG_FILE" + echo "[$SECONDS] build status: $STATUS" + return "$STATUS" +} + +# Check whether we're executing from a clean repository, and proper location +check_environment() +{ + local -r UPSTREAM_COMMIT="$1" + + if [ ! -x scripts/check_build.sh ]; then + echo "error: please execute script from repository root!" + exit 1 + fi + + if ! git diff-index --quiet HEAD --; then + echo "error: please commit or stash your local changes!" + exit 1 + fi + + if ! git cat-file -e "$UPSTREAM_COMMIT" &> /dev/null; then + echo "error: upstream commit $UPSTREAM_COMMIT does not exist!" + exit 1 + fi +} + +TEST_COMMIT=$(git rev-parse --short HEAD) + +LAST_TAG=$(git describe --abbrev=0) +DEFAULT_UPSTREAM="origin/master" +[ -z "$LAST_TAG" ] || DEFAULT_UPSTREAM="$LAST_TAG" +UPSTREAM_COMMIT="${1:-$DEFAULT_UPSTREAM}" + +# Before starting, check call location and git environment +check_environment "$UPSTREAM_COMMIT" + +# Set the number of worker for the build +set_worker + +# Collect status, as well as failing configuration file names +declare -i OVERALL_STATUS=0 +mkdir -p "$LOG_DIR" +BRANCH_FAILS="" +UPSTREAM_FAILS="" + +# Build multiple configurations +declare -i COUNT=0 +declare -r CONFIGS=$(collect_configurations) +echo "[$SECONDS] check commit $TEST_COMMIT with upstream reference $UPSTREAM_COMMIT" +for config in $CONFIGS +do + COUNT=$((COUNT+1)) + echo "[$SECONDS] build $config as build nr $COUNT" + LOG_FILE=$LOG_DIR/build-"$COUNT"-"$config".log + + # Prepare configuration, and memorize it + STATUS=0 + make "$config" &> "$LOG_FILE" || STATUS=$? + cp .config $LOG_DIR/config-"$COUNT"-"$config" + + # Try to build with current configuration + build "$LOG_FILE" || STATUS=$? + + # Evaluate build failure + if [ "$STATUS" -ne 0 ] + then + cp .config "$LOG_DIR"/config-failing-branch-"$COUNT"-"$config" + echo "[$SECONDS] check whether current configuration fails upstream as well ..." + echo "[$SECONDS] go back in time to commit $UPSTREAM_COMMIT" + + # Check whether upstream commit builds + git checkout "$UPSTREAM_COMMIT" &>> "$LOG_FILE" + UPSTREAM_STATUS=0 + build "$LOG_FILE" || UPSTREAM_STATUS=$? + git checkout "$TEST_COMMIT" &>> "$LOG_FILE" + + if [ "$UPSTREAM_STATUS" -ne 0 ] + then + echo "[$SECONDS] upstream build fails as well, ignore failure" + cp .config "$LOG_DIR"/config-failing-upstream-"$COUNT"-"$config" + UPSTREAM_FAILS+=" config-$COUNT-$config" + else + echo "[$SECONDS] upstream build succeeds, while branch build fails" + BRANCH_FAILS+=" config-$COUNT-$config" + OVERALL_STATUS=1 + fi + + echo "[$SECONDS] jump back to commit under test, $TEST_COMMIT" + fi +done + +# Print summary, and exit with status of local changes +echo "Finished after $SECONDS seconds" +echo "Found upstream failures: $UPSTREAM_FAILS" +echo "Found branch failures: $BRANCH_FAILS" +echo "Collected configurations and logs can be found in $LOG_DIR" + +# Exit 0, if no build fails, or the upstream commit always fails as well +exit $OVERALL_STATUS -- 2.7.4 Amazon Development Center Germany GmbH Berlin - Dresden - Aachen main office: Krausenstr. 38, 10117 Berlin Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger Ust-ID: DE289237879 Eingetragen am Amtsgericht Charlottenburg HRB 149173 B