From 67e51745a91b40c97eac753ddaa8a440b3afc41e Mon Sep 17 00:00:00 2001 From: Lucas Jenss Date: Tue, 24 Nov 2015 06:02:39 +0100 Subject: [PATCH] Improve execution of static-tests Allow execution of static tests with the `make static-tests` command and improve its output for the human reader --- Makefile | 2 + Makefile.tests | 3 + dist/tools/static-tests.sh | 45 +++++++++++ dist/tools/travis-scripts/build_and_test.sh | 82 +++++++++++++++------ 4 files changed, 111 insertions(+), 21 deletions(-) create mode 100644 Makefile.tests create mode 100755 dist/tools/static-tests.sh diff --git a/Makefile b/Makefile index c2510fb18a11f..890f740ac5369 100644 --- a/Makefile +++ b/Makefile @@ -36,3 +36,5 @@ welcome: @echo " https://github.com/RIOT-OS/RIOT/wiki/Quick-Start-Guide" @echo "Or ask questions on our mailing list:" @echo " users@riot-os.org (http://lists.riot-os.org/mailman/listinfo/users)" + +-include Makefile.tests diff --git a/Makefile.tests b/Makefile.tests new file mode 100644 index 0000000000000..fd5e492ce6b01 --- /dev/null +++ b/Makefile.tests @@ -0,0 +1,3 @@ + +static-test: + ./dist/tools/static-tests.sh diff --git a/dist/tools/static-tests.sh b/dist/tools/static-tests.sh new file mode 100755 index 0000000000000..d04c197637bcf --- /dev/null +++ b/dist/tools/static-tests.sh @@ -0,0 +1,45 @@ +#!/bin/bash +# +# Copyright (C) 2015 Lucas Jenß +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. +# + +# Change to RIOT root +cd "$(dirname "$0")/../../" + +function dep { + which $1 2>&1 1>/dev/null + if (( $? != 0 )); then + echo "Dependency not met: $1" + exit 1 + fi +} + +function abort { + echo "$(tput setaf 1)$1$(tput sgr0)" + exit 1 +} + +function request_confirmation { + read -p "$(tput setaf 4)$1 (y/n) $(tput sgr0)" + [ "$REPLY" == "y" ] || abort "Aborted!" +} + +# Make sure all required commands are available +dep cppcheck +dep pcregrep + +RIOT_REMOTE_COUNT="$(git remote | grep "^riot$" | wc -l)" +if (( "$RIOT_REMOTE_COUNT" != 1 )); then + echo "The static test setup expect a remote called 'riot', pointing to the" + echo "central repository. This remote currently does not exist." + request_confirmation "Do you wish to create it?" + + git remote add riot https://github.com/RIOT-OS/RIOT.git + git fetch riot +fi + +BUILDTEST_MCU_GROUP=static-tests ./dist/tools/travis-scripts/build_and_test.sh diff --git a/dist/tools/travis-scripts/build_and_test.sh b/dist/tools/travis-scripts/build_and_test.sh index 17daf5dbe4c05..02651f9b5968c 100755 --- a/dist/tools/travis-scripts/build_and_test.sh +++ b/dist/tools/travis-scripts/build_and_test.sh @@ -7,6 +7,46 @@ # directory for more details. # +function print_result { + local RED="\033[0;31m" + local GREEN="\033[0;32m" + local NO_COLOUR="\033[0m" + + if (( "$1" == 0 )); then + echo -e "${GREEN}✓$NO_COLOUR" + else + echo -e "${RED}x$NO_COLOUR" + fi +} + +RESULT=0 +set_result() { + NEW_RESULT=$1 + + if (( $NEW_RESULT != 0)) + then + RESULT=$NEW_RESULT + fi +} + +function run { + echo -n "Running '$@' " + OUT=$($@ 2>&1) + NEW_RESULT=$? + + print_result $NEW_RESULT + set_result $NEW_RESULT + + # Indent command output so that its easily discernable from the rest + OUT_LENGTH="$(echo -n $OUT | wc -c)" + if (( "$OUT_LENGTH" > 0 )); then + echo -e "Command output:\n" + (echo $OUT | while read -r line; do echo -ne "\t"; echo $line; done) + echo "" + fi +} + + if [[ $BUILDTEST_MCU_GROUP ]] then @@ -15,7 +55,7 @@ then RESULT=0 RECALL="$1" - if git diff master HEAD -- .travis.yml &> /dev/null; then + if git diff riot/master HEAD -- .travis.yml &> /dev/null; then # check if .travis.yml was changed in the current PR and skip if so if ! git diff --name-only $(git merge-base HEAD master)..HEAD -- \ .travis.yml &> 1; then @@ -31,8 +71,8 @@ then fi if [ "$RECALL" != "recall" ]; then - if git diff master HEAD -- "$0" &> /dev/null; then - git rebase master || git rebase --abort + if git diff riot/master HEAD -- "$0" &> /dev/null; then + git rebase riot/master || git rebase --abort "$0" "recall" exit $? @@ -41,31 +81,26 @@ then trap "RESULT=1" ERR - git rebase master || git rebase --abort - if [ $RESULT -ne 0 ]; then - exit $RESULT + git rebase riot/master + if (( $? != 0 )); then + git rebase --abort > /dev/null 2>&1 + echo "Rebase failed, aborting..." + exit 1 fi - ./dist/tools/whitespacecheck/check.sh master - - ./dist/tools/licenses/check.sh master --diff-filter=MR --error-exitcode=0 - - ./dist/tools/licenses/check.sh master --diff-filter=AC - - ./dist/tools/doccheck/check.sh master - - ./dist/tools/externc/check.sh master + run ./dist/tools/whitespacecheck/check.sh riot/master + run ./dist/tools/licenses/check.sh riot/master --diff-filter=MR --error-exitcode=0 + run ./dist/tools/licenses/check.sh riot/master --diff-filter=AC + run ./dist/tools/doccheck/check.sh riot/master + run ./dist/tools/externc/check.sh riot/master # TODO: # Remove all but `master` parameters to cppcheck (and remove second # invocation) once all warnings of cppcheck have been taken care of # in master. - ./dist/tools/cppcheck/check.sh master --diff-filter=MR --error-exitcode=0 - - ./dist/tools/cppcheck/check.sh master --diff-filter=AC - - ./dist/tools/pr_check/pr_check.sh master - + run ./dist/tools/cppcheck/check.sh riot/master --diff-filter=MR --error-exitcode=0 + run ./dist/tools/cppcheck/check.sh riot/master --diff-filter=AC + run ./dist/tools/pr_check/pr_check.sh riot/master exit $RESULT fi @@ -77,11 +112,16 @@ then if [ "$BUILDTEST_MCU_GROUP" == "x86" ] then make -C ./tests/unittests all-debug test BOARD=native TERMPROG='gdb -batch -ex r -ex bt $(ELF)' || exit + set_result $? # TODO: # Reenable once https://github.com/RIOT-OS/RIOT/issues/2300 is # resolved: # - make -C ./tests/unittests all test BOARD=qemu-i386 || exit fi + BASE_BRANCH="${TRAVIS_BRANCH:-${CI_BASE_BRANCH}}" ./dist/tools/compile_test/compile_test.py $BASE_BRANCH + set_result $? fi + +exit $RESULT