run_valgrind_tools.py 2.96 KB
Newer Older
1
import os
2
import sys
3
4
5
6
import shutil
import subprocess


7
8
class RunValgrind:
    """Compile the sources related to one executable and then run the Valgrind analysis on the executable.
9
    
10
11
12
13
    \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.
    """
14

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
    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()
37
38


39
40
41
42
    def _compile(self):
        cmd = "ninja {}".format(self.__executable)
        subprocess.run(cmd, shell = True).check_returncode()
        
43
    
44
    def _runValgrind(self):
45

46
        cmd = "MOREFEM_ROOT={}/Codes/MoReFEM 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(os.environ["HOME"], output = self.__output, lua_file = self.__lua_file, executable = self.__executable)
47

48
        subprocess.run(cmd, shell = True).check_returncode()
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64



# runValgrind MoReFEMTestPetscMatrixOperations ../Sources/Test/ThirdParty/PETSc/MatrixOperations/demo.lua memcheck_matrix_operations.txt
#
# runValgrind MoReFEM4Elasticity ../Sources/ModelInstances/Elasticity/demo_2d_binary.lua memcheck_elasticity.txt
#
# runValgrind MoReFEM4Heat ../Sources/ModelInstances/Heat/demo_input_heat.lua memcheck_heat.txt
#
# runValgrind MoReFEM4Hyperelasticity ../Sources/ModelInstances/Hyperelasticity/demo_input_hyperelasticity.lua memcheck_hyperelasticity.txt
#
# runValgrind MoReFEM4Laplacian ../Sources/ModelInstances/Laplacian/demo_input_laplacian.lua memcheck_laplacian.txt
#
# runValgrind MoReFEM4RivlinCube ../Sources/ModelInstances/RivlinCube/demo_input_rivlin_cube_hexahedra.lua memcheck_rivlin_cube.txt
#
# runValgrind MoReFEM4Stokes ../Sources/ModelInstances/Stokes/demo.lua memcheck_stokes.txt