mirror of
https://github.com/infiniteCable2/panda.git
synced 2026-02-18 17:23:52 +08:00
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:
@@ -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
|
||||
|
||||
|
||||
@@ -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"])
|
||||
|
||||
Reference in New Issue
Block a user