Commit 091bd7f8 authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

#177 Valgrind: modify the script so that an error returns properly an error code.

parent 484209a9
import os
from run_valgrind_tools import buildAndRunValgrind
from run_valgrind_tools import RunValgrind
if __name__ == "__main__":
......@@ -11,4 +11,4 @@ if __name__ == "__main__":
lua_file = os.path.join(morefem_model_instances_dir, "Elasticity", "demo_2d_binary.lua")
#
buildAndRunValgrind("Sources/MoReFEM4Elasticity", lua_file, os.path.join(morefem_root_dir, "memcheck_elasticity.txt"))
RunValgrind("Sources/MoReFEM4Elasticity", lua_file, os.path.join(morefem_root_dir, "memcheck_elasticity.txt"))
import os
import sys
import shutil
import subprocess
def build(executable):
class RunValgrind:
"""Compile the sources related to one executable and then run the Valgrind analysis on the executable.
morefem_root_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..")
morefem_cmake_dir = os.path.join(morefem_root_dir, "cmake")
# build_directory = os.path.join(morefem_root_dir, "build4valgrind")
# os.chdir(morefem_root_dir)
#
# if os.path.exists(build_directory):
# shutil.rmtree(build_directory)
#
# os.mkdir(build_directory)
# os.chdir(build_directory)
cmd = "python {cmake_dir}/Scripts/configure_cmake.py --cache_file={cmake_dir}/PreCache/linux.cmake --cmake_args=\"-G Ninja\" --third_party_directory=/opt --mode=\"debug\"".format(cmake_dir = morefem_cmake_dir)
print(cmd)
subprocess.Popen(cmd, shell = True).communicate()
\param[in] executable Executable to compile (e.g. MoReFEM4Elasticity).
\param[in] lua_file Lua file with the data required to run the model.
\param[in] output File in which output of the Valgrind analysis is written.
"""
cmd = "ninja {}".format(executable)
subprocess.Popen(cmd, shell = True).communicate()
def __init__(self, executable, lua_file, output):
self.__executable = executable
self.__lua_file = lua_file
self.__output = output
try:
self._callCMake()
self._compile()
self._runValgrind()
except subprocess.CalledProcessError as e:
print("Error in process: {}".format(e))
sys.exit(e.returncode)
def _callCMake(self):
morefem_root_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..")
morefem_cmake_dir = os.path.join(morefem_root_dir, "cmake")
cmd = "python {cmake_dir}/Scripts/configure_cmake.py --cache_file={cmake_dir}/PreCache/linux.cmake --cmake_args=\"-G Ninja\" --third_party_directory=/opt --mode=\"debug\"".format(cmake_dir = morefem_cmake_dir)
subprocess.run(cmd, shell = True).check_returncode()
def runValgrind(executable, lua_file, output):
def _compile(self):
cmd = "ninja {}".format(self.__executable)
subprocess.run(cmd, shell = True).check_returncode()
# morefem_root_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..")
# build_directory = os.path.join(morefem_root_dir, "build4valgrind")
#
# os.chdir(build_directory)
#
def _runValgrind(self):
# --error-exitcode=1 --log-file=$OUTPUT --gen-suppressions=all --show-leak-kinds=all --show-reachable=yes --track-origins=yes --leak-check=full --errors-for-leak-kinds=all --suppressions=../ExternalTools/Valgrind/openmpi.suppr --suppressions=../ExternalTools/Valgrind/libgomp.suppr --suppressions=../ExternalTools/Valgrind/libc.suppr $EXECUTABLE -i $2 -e MOREFEM_RESULT_DIR=${PWD}
cmd = "valgrind --error-exitcode=1 --log-file={output} --gen-suppressions=all --show-leak-kinds=all --show-reachable=yes --track-origins=yes --leak-check=full --errors-for-leak-kinds=all --suppressions=../ExternalTools/Valgrind/openmpi.suppr --suppressions=../ExternalTools/Valgrind/libgomp.suppr --suppressions=../ExternalTools/Valgrind/libc.suppr {executable} -i {lua_file} --overwrite_directory -e MOREFEM_RESULT_DIR=Results".format(output = self.__output, lua_file = self.__lua_file, executable = self.__executable)
cmd = "valgrind --error-exitcode=1 --log-file={output} --gen-suppressions=all --show-leak-kinds=all --show-reachable=yes --track-origins=yes --leak-check=full --errors-for-leak-kinds=all --suppressions=../ExternalTools/Valgrind/openmpi.suppr --suppressions=../ExternalTools/Valgrind/libgomp.suppr --suppressions=../ExternalTools/Valgrind/libc.suppr {executable} -i {lua_file} -e MOREFEM_RESULT_DIR=Results".format(output = output, lua_file = lua_file, executable = executable)
subprocess.Popen(cmd, shell = True).communicate()
def buildAndRunValgrind(executable, lua_file, output):
build(executable)
runValgrind(executable, lua_file, output)
subprocess.run(cmd, shell = True).check_returncode()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment