Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mutation tests: make coverage gradual #2057

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ jobs:
mutation:
name: Mutation tests
runs-on: ubuntu-latest
strategy:
matrix:
mutation_mode: ['DIFF_COVERAGE', 'SAFETY_ONLY']
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
Expand All @@ -115,7 +118,7 @@ jobs:
run: eval "$BUILD"
- name: Mutation tests
timeout-minutes: 5
run: ${{ env.RUN }} "GIT_REF=${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && github.event.before || 'origin/master' }} cd tests/safety && ./mutation.sh"
run: ${{ env.RUN }} "GIT_REF=${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && github.event.before || 'origin/master' }} cd tests/safety && MUTATION_MODE=${{ matrix.mutation_mode }} ./mutation.sh"

static_analysis:
name: static analysis
Expand Down
40 changes: 32 additions & 8 deletions tests/safety/mutation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,43 @@ set -e
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
cd $DIR

$DIR/install_mull.sh
# TODO: add more ops from https://mull.readthedocs.io/en/latest/SupportedMutations.html
# Note that cxx_assign_const and cxx_init_const are currently broken
MUTATION_OPS="mutators: [cxx_increment, cxx_decrement, cxx_comparison, cxx_boundary, cxx_bitwise_assignment, cxx_bitwise, cxx_arithmetic_assignment, cxx_arithmetic]"

# TODO: add more files from board/safety
MUTATION_SAFETY_FILES=( safety_body.h safety_defaults.h safety_elm327.h )

# SAFETY_ONLY -> verify mutations on safety_xx.h with test_xx.py
# DIFF_COVERAGE -> verify mutations with test_xx.py on the intersection between its code coverage and the current git diff
MUTATION_MODE="${MUTATION_MODE:-DIFF_COVERAGE}"

GIT_REF="${GIT_REF:-origin/master}"
GIT_ROOT=$(git rev-parse --show-toplevel)
MULL_OPS="mutators: [cxx_increment, cxx_decrement, cxx_comparison, cxx_boundary, cxx_bitwise_assignment, cxx_bitwise, cxx_arithmetic_assignment, cxx_arithmetic]"
echo -e "$MULL_OPS" > $GIT_ROOT/mull.yml
GIT_MULL_CONFIG="gitDiffRef: $GIT_REF\ngitProjectRoot: $GIT_ROOT"

function write_conf() {
echo -e "timeout: 10000\n$MUTATION_OPS\n$1" > $GIT_ROOT/mull.yml
}

$DIR/install_mull.sh

write_conf
scons --mutation -j$(nproc) -D
echo -e "timeout: 10000\ngitDiffRef: $GIT_REF\ngitProjectRoot: $GIT_ROOT" >> $GIT_ROOT/mull.yml

SAFETY_MODELS=$(find * | grep "^test_.*\.py")
for safety_model in ${SAFETY_MODELS[@]}; do
SAFETY_TESTS=$(find * | grep "^test_.*\.py")
for SAFETY_TEST in ${SAFETY_TESTS[@]}; do
if [[ $MUTATION_MODE == "SAFETY_ONLY" ]]; then
SAFETY_MODE=$(echo $SAFETY_TEST | sed -e 's/test_/safety_/g' | sed -e 's/\.py/\.h/g')
if [[ ! " ${MUTATION_SAFETY_FILES[*]} " =~ [[:space:]]${SAFETY_MODE}[[:space:]] ]]; then
continue
fi
write_conf "includePaths:\n - $SAFETY_MODE"
else
write_conf "$GIT_MULL_CONFIG"
fi
echo ""
echo ""
echo -e "Testing mutations on : $safety_model"
mull-runner-17 --ld-search-path /lib/x86_64-linux-gnu/ ../libpanda/libpanda.so -test-program=./$safety_model
echo -e "Testing mutations on : $SAFETY_TEST"
mull-runner-17 --ld-search-path /lib/x86_64-linux-gnu/ ../libpanda/libpanda.so -test-program=./$SAFETY_TEST
done
Loading