Skip to content

Commit

Permalink
murdock: implement test result caching
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspar030 committed Apr 4, 2019
1 parent 8817169 commit 513c882
Showing 1 changed file with 48 additions and 4 deletions.
52 changes: 48 additions & 4 deletions .murdock
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ export RIOT_CI_BUILD=1
export STATIC_TESTS=${STATIC_TESTS:-1}
export CFLAGS_DBG=""
export DLCACHE_DIR=${DLCACHE_DIR:-~/.dlcache}
export ENABLE_TEST_CACHE=${ENABLE_TEST_CACHE:-1}

NIGHTLY=${NIGHTLY:-0}
RUN_TESTS=${RUN_TESTS:-${NIGHTLY}}

DWQ_ENV="-E BOARDS -E APPS -E NIGHTLY -E RUN_TESTS"
DWQ_ENV="-E BOARDS -E APPS -E NIGHTLY -E RUN_TESTS -E ENABLE_TEST_CACHE -E TEST_HASH"

check_label() {
local label="${1}"
Expand All @@ -24,6 +25,10 @@ check_label() {
check_label "CI: run tests" && RUN_TESTS=1
}

[ "$ENABLE_TEST_CACHE" = "1" ] && {
check_label "CI: disable test cache" && export ENABLE_TEST_CACHE=0
}

error() {
echo "$@"
exit 1
Expand Down Expand Up @@ -138,6 +143,30 @@ print_worker() {
echo "-- running on worker ${DWQ_WORKER} thread ${DWQ_WORKER_THREAD}, build number $DWQ_WORKER_BUILDNUM."
}

test_hash_calc() {
local bindir=$1

# Why two times cut?
# "test-input-hash.sha1" contains a list of lines containing
# "<hash> <filename>" on each line.
# We need to filter out the filename, as it contains the full path name,
# which differs depending on the build machine.
#
# After piping through sha1sum, we get "<hash> -". " -" has to go so we save the
# hassle of escaping the resulting hash.

cat ${bindir}/test-input-hash.sha1 | cut -f1 -d' ' | sha1sum | cut -f1 -d' '
}

test_cache_get() {
test "${ENABLE_TEST_CACHE}" = "1" || return 1
test -n "$(redis-cli get $1)" > /dev/null
}

test_cache_put() {
redis-cli set "$1" ok
}

# compile one app for one board with one toolchain. delete intermediates.
compile() {
local appdir=$1
Expand Down Expand Up @@ -167,7 +196,7 @@ compile() {

# compile
CCACHE_BASEDIR="$(pwd)" BOARD=$board TOOLCHAIN=$toolchain RIOT_CI_BUILD=1 \
make -C${appdir} clean all -j${JOBS:-4}
make -C${appdir} clean all test-input-hash -j${JOBS:-4}
RES=$?

# run tests
Expand All @@ -178,8 +207,15 @@ compile() {
BOARD=$board make -C${appdir} test
RES=$?
elif is_in_list "$board" "$TEST_BOARDS_AVAILABLE"; then
BOARD=$board TOOLCHAIN=$toolchain make -C${appdir} test-murdock
RES=$?
test_hash=$(test_hash_calc "$BINDIR")
echo "-- test_hash=$test_hash"
if test_cache_get $test_hash; then
echo "-- skipping test due to positive cache hit"
else
BOARD=$board TOOLCHAIN=$toolchain TEST_HASH=$test_hash \
make -C${appdir} test-murdock
RES=$?
fi
fi
fi
fi
Expand Down Expand Up @@ -224,6 +260,14 @@ run_test() {
echo "-- executing tests for $appdir on $board (compiled with $toolchain toolchain):"
hook run_test_pre
BOARD=$board TOOLCHAIN=${toolchain} make -C$appdir flash-only test
RES=$?

if [ $RES -eq 0 -a -n "$TEST_HASH" ]; then
echo -n "-- saving test result to cache: "
test_cache_put $TEST_HASH
fi

return $RES
}

# execute static tests
Expand Down

0 comments on commit 513c882

Please sign in to comment.