checkall 3.4 KB
Newer Older
1
#!/bin/bash
2
ERR=()
3 4 5 6
RESULTS_DIR=$(./scripts/avocado config | grep datadir.paths.logs_dir | awk '{print $2}')
# Very basic version of expanduser
RESULTS_DIR="${RESULTS_DIR/#\~/$HOME}"

7
run_rc() {
8 9 10
    CHECK=$1
    shift
    echo -e "\n\e[32mRunning '$1'\e[0m"
11
    eval $*
12
    if [ $? != 0 ]; then
13 14
        echo -e "\e[31m$CHECK FAILED\e[0m"
        ERR+=("$CHECK")
15
        [ ! "$SELF_CHECK_CONTINUOUS" ] && exit 1
16 17
    else
        echo -e "\e[32m$CHECK PASSED\e[0m\n"
18
    fi
19
}
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43


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
44
            echo python -m unittest ${ALL[@]:$(($I * $PER_SLICE)):$PER_SLICE}
45 46 47 48 49 50 51 52 53 54 55
            cat ${TMPS[$I]}
        fi
        rm ${TMPS[$I]}
    done
    echo
    echo ----------------------------------------------------------------------
    echo Ran ${#ALL[@]} tests in $(($(date +%s) - START))s
    return $ERR
}


56 57 58 59 60 61 62 63 64
signed_off_check() {
    AUTHOR="$(git log -1 --pretty='format:%aN <%aE>')"
    git log -1 --pretty=format:%B | grep "Signed-off-by: $AUTHOR"
    if [ $? != 0 ]; then
        echo "The commit message does not contain author's signature (Signed-off-by: $AUTHOR)"
        return 1
    fi
}

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80

results_dir_content() {
    NOW="$(ls $RESULTS_DIR)"
    if [ "$(echo $* | xargs)" != "$(echo $NOW | xargs)" ]; then
        echo "The output of '$RESULTS_DIR' is not the same as before running the checks"
        echo "ORIGINAL:"
        echo "$*"
        echo "NOW:"
        echo "$NOW"
        return 1
    else:
        echo "No extra files were created in '$RESULTS_DIR'"
        return 0
    fi
}

81
[ "$SKIP_RESULTSDIR_CHECK" ] || RESULTS_DIR_CONTENT="$(ls $RESULTS_DIR 2> /dev/null)"
82 83
run_rc lint 'inspekt --exclude=.git lint'
run_rc indent 'inspekt --exclude=.git indent'
84
run_rc style 'inspekt --exclude=.git style --disable E501,E265,W601,E402,E722'
85
run_rc boundaries 'selftests/modules_boundaries'
86
run_rc signed-off-by signed_off_check
87 88 89
if [ "$AVOCADO_PARALLEL_CHECK" ]; then
    run_rc selftests parallel_selftests
elif [ -z "$AVOCADO_SELF_CHECK" ]; then
90
    run_rc selftests selftests/run
91
else
92 93 94
    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"
95
fi
96
[ "$SKIP_RESULTSDIR_CHECK" ] || run_rc job-results results_dir_content "$RESULTS_DIR_CONTENT"
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111

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