mirror of
https://github.com/infiniteCable2/panda.git
synced 2026-02-18 17:23:52 +08:00
Make MISRA results consistent across cppcheck runs (#1867)
* fixed uninitialized data error * update ci * revert old changes * add styling * switch misra.py to misra * remove cache from mutation.py * works on local * jobs increased to 8 for mutation test * works locally * add env variable back * removed env variable * cleanup --------- Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
This commit is contained in:
1
tests/misra/.gitignore
vendored
1
tests/misra/.gitignore
vendored
@@ -1,4 +1,5 @@
|
||||
*.pdf
|
||||
*.txt
|
||||
.output.log
|
||||
new_table
|
||||
cppcheck/
|
||||
|
||||
@@ -29,16 +29,19 @@ if [ -z "${SKIP_BUILD}" ]; then
|
||||
fi
|
||||
|
||||
cppcheck() {
|
||||
hashed_args=$(echo -n "$@$DIR" | md5sum | awk '{print $1}')
|
||||
build_dir=/tmp/cppcheck_build/$hashed_args
|
||||
mkdir -p $build_dir
|
||||
|
||||
# note that cppcheck build cache results in inconsistent results as of v2.13.0
|
||||
OUTPUT=$DIR/.output.log
|
||||
$CPPCHECK_DIR/cppcheck --enable=all --force --inline-suppr -I $PANDA_DIR/board/ \
|
||||
-I $gcc_inc "$(arm-none-eabi-gcc -print-file-name=include)" \
|
||||
--suppressions-list=$DIR/suppressions.txt --suppress=*:*inc/* \
|
||||
--suppress=*:*include/* --error-exitcode=2 --addon=misra \
|
||||
--check-level=exhaustive --cppcheck-build-dir=$build_dir \
|
||||
"$@"
|
||||
--check-level=exhaustive "$@" |& tee $OUTPUT
|
||||
|
||||
# cppcheck bug: some MISRA errors won't result in the error exit code,
|
||||
# so check the output (https://trac.cppcheck.net/ticket/12440#no1)
|
||||
if grep "misra violation" $OUTPUT > /dev/null; then
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
printf "\n${GREEN}** PANDA F4 CODE **${NC}\n"
|
||||
|
||||
@@ -5,7 +5,6 @@ import pytest
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import hashlib
|
||||
import random
|
||||
|
||||
HERE = os.path.abspath(os.path.dirname(__file__))
|
||||
@@ -68,25 +67,18 @@ for p in patterns:
|
||||
|
||||
@pytest.mark.parametrize("fn, patch, should_fail", mutations)
|
||||
def test_misra_mutation(fn, patch, should_fail):
|
||||
key = hashlib.md5((str(fn) + str(patch)).encode()).hexdigest()
|
||||
tmp = os.path.join(tempfile.gettempdir(), key)
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
shutil.copytree(ROOT, tmp, dirs_exist_ok=True)
|
||||
|
||||
if os.path.exists(tmp):
|
||||
shutil.rmtree(tmp)
|
||||
shutil.copytree(ROOT, tmp)
|
||||
# apply patch
|
||||
if fn is not None:
|
||||
r = os.system(f"cd {tmp} && sed -i '{patch}' {fn}")
|
||||
assert r == 0
|
||||
|
||||
# apply patch
|
||||
if fn is not None:
|
||||
r = os.system(f"cd {tmp} && sed -i '{patch}' {fn}")
|
||||
assert r == 0
|
||||
|
||||
# run test
|
||||
env = {'SKIP_BUILD': '1'} | os.environ.copy()
|
||||
r = subprocess.run("tests/misra/test_misra.sh", cwd=tmp, shell=True, env=env)
|
||||
failed = r.returncode != 0
|
||||
assert failed == should_fail
|
||||
|
||||
shutil.rmtree(tmp)
|
||||
# run test
|
||||
r = subprocess.run("tests/misra/test_misra.sh", cwd=tmp, shell=True)
|
||||
failed = r.returncode != 0
|
||||
assert failed == should_fail
|
||||
|
||||
if __name__ == "__main__":
|
||||
pytest.main([__file__, "-n 8"])
|
||||
|
||||
Reference in New Issue
Block a user