checkall 2.3 KB
Newer Older
1
#!/bin/bash
2
ERR=()
3
run_rc() {
4 5 6
    CHECK=$1
    shift
    echo -e "\n\e[32mRunning '$1'\e[0m"
7
    eval $1
8
    if [ $? != 0 ]; then
9 10
        echo -e "\e[31m$CHECK FAILED\e[0m"
        ERR+=("$CHECK")
11
        [ ! "$SELF_CHECK_CONTINUOUS" ] && exit 1
12 13
    else
        echo -e "\e[32m$CHECK PASSED\e[0m\n"
14
    fi
15
}
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39


parallel_selftests() {
    local START=$(date +%s)
    local ERR=0
    # Use sort -R to randomize the order as longer tests seems to be likely in the same file
    local ALL=($(./contrib/scripts/avocado-find-unittests selftests/*/*.py | sort -R))
    [ ${#ALL[@]} -eq 0 ] && return 0
    local NO_WORKERS=$(($(cat /proc/cpuinfo | grep -c processor) * 2))
    local PER_SLICE=$((${#ALL[@]} / $NO_WORKERS))
    [ $PER_SLICE -eq 0 ] && PER_SLICE=1
    local PIDS=()
    local TMPS=()
    for I in $(seq 0 $PER_SLICE $((${#ALL[@]} - 1))); do
        TMP=$(mktemp /tmp/avocado_parallel_unittest_output_XXXXXX)
        TMPS+=("$TMP")
        python -m unittest ${ALL[@]:$I:$PER_SLICE} &> $TMP &
        PIDS+=("$!")
    done
    for I in $(seq 0 $((${#PIDS[@]} - 1))); do
        wait ${PIDS[$I]}
        RET=$?
        if [ $RET -ne 0 ]; then
            ERR=1
40
            echo python -m unittest ${ALL[@]:$(($I * $PER_SLICE)):$PER_SLICE}
41 42 43 44 45 46 47 48 49 50 51
            cat ${TMPS[$I]}
        fi
        rm ${TMPS[$I]}
    done
    echo
    echo ----------------------------------------------------------------------
    echo Ran ${#ALL[@]} tests in $(($(date +%s) - START))s
    return $ERR
}


52 53 54 55
run_rc lint 'inspekt --exclude=.git lint'
run_rc indent 'inspekt --exclude=.git indent'
run_rc style 'inspekt --exclude=.git style'
run_rc boundaries 'selftests/modules_boundaries'
56 57 58
if [ "$AVOCADO_PARALLEL_CHECK" ]; then
    run_rc selftests parallel_selftests
elif [ -z "$AVOCADO_SELF_CHECK" ]; then
59
    run_rc selftests selftests/run
60
else
61 62 63
    CMD='scripts/avocado run `./contrib/scripts/avocado-find-unittests selftests/{unit,functional,doc}/*.py | xargs` --external-runner="/usr/bin/env python -m unittest"'
    [ ! $SELF_CHECK_CONTINUOUS ] && CMD+=" --failfast on"
    run_rc selftests "$CMD"
64
fi
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79

if [ "$ERR" ]; then
    echo -e "\e[31m"
    echo "Checks:"
    for CHECK in "${ERR[@]}"; do
        echo -e " * $CHECK FAILED"
    done
    echo -ne "\e[0m"
else
    echo -e "\e[32mAll checks PASSED\e[0m"
fi
if [ "$ERR" ]; then
    exit 1
fi
exit 0