Skip to content

Commit

Permalink
Improve execution of static-tests
Browse files Browse the repository at this point in the history
Allow execution of static tests with the `make static-tests`
command and improve its output for the human reader
  • Loading branch information
x3ro committed Jun 28, 2016
1 parent 121028d commit 67e5174
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 21 deletions.
2 changes: 2 additions & 0 deletions Makefile
Expand Up @@ -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
3 changes: 3 additions & 0 deletions Makefile.tests
@@ -0,0 +1,3 @@

static-test:
./dist/tools/static-tests.sh
45 changes: 45 additions & 0 deletions dist/tools/static-tests.sh
@@ -0,0 +1,45 @@
#!/bin/bash
#
# Copyright (C) 2015 Lucas Jenß <lucas@x3ro.de>
#
# 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
82 changes: 61 additions & 21 deletions dist/tools/travis-scripts/build_and_test.sh
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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 $?
Expand All @@ -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

Expand All @@ -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

0 comments on commit 67e5174

Please sign in to comment.