Enable cache for MISRA mutation test (#1799)

* work with 1 cache

* enable cache in mutation

* name to hash

* cleanup

---------

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
This commit is contained in:
Hoang Bui
2024-01-15 17:40:19 -05:00
committed by GitHub
parent 6ae65db44a
commit d854abedff
2 changed files with 18 additions and 12 deletions

View File

@@ -27,7 +27,7 @@ cd $PANDA_DIR
scons -j8
cppcheck() {
hashed_args=$(echo -n "$@" | md5sum | awk '{print $1}')
hashed_args=$(echo -n "$@$DIR" | md5sum | awk '{print $1}')
build_dir=/tmp/cppcheck_build/$hashed_args
mkdir -p $build_dir

View File

@@ -4,6 +4,7 @@ import pytest
import shutil
import subprocess
import tempfile
import hashlib
HERE = os.path.abspath(os.path.dirname(__file__))
ROOT = os.path.join(HERE, "../../")
@@ -23,19 +24,24 @@ mutations = [
@pytest.mark.parametrize("fn, patch, should_fail", mutations)
def test_misra_mutation(fn, patch, should_fail):
with tempfile.TemporaryDirectory() as tmp:
shutil.copytree(ROOT, tmp, dirs_exist_ok=True)
key = hashlib.md5((str(fn) + str(patch)).encode()).hexdigest()
tmp = os.path.join(tempfile.gettempdir(), key)
# apply patch
if fn is not None:
r = os.system(f"cd {tmp} && sed -i '{patch}' {fn}")
assert r == 0
if os.path.exists(tmp):
shutil.rmtree(tmp)
shutil.copytree(ROOT, tmp)
# run test
r = subprocess.run("tests/misra/test_misra.sh", cwd=tmp, shell=True,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
failed = r.returncode != 0
assert failed == should_fail
# apply patch
if fn is not None:
r = os.system(f"cd {tmp} && sed -i '{patch}' {fn}")
assert r == 0
# run test
r = subprocess.run("tests/misra/test_misra.sh", cwd=tmp, shell=True)
failed = r.returncode != 0
assert failed == should_fail
shutil.rmtree(tmp)
if __name__ == "__main__":
pytest.main([__file__, "-n 4"])