Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
pedantic is now implied by -analyze
[simgrid.git] / teshsuite / smpi / MBI / simgrid.py
1 # Copyright 2021-2022. The MBI project. All rights reserved.
2 # This program is free software; you can redistribute it and/or modify it under the terms of the license (GNU GPL).
3
4 import re
5 import os
6 from MBIutils import *
7
8 class Tool(AbstractTool):
9     def identify(self):
10         return "SimGrid wrapper"
11
12     def build(self, rootdir, cached=True):
13         if cached and (os.path.exists(f"{rootdir}/builds/SimGrid/bin/smpicc") or os.path.exists('/usr/bin/simgrid-mc')):
14             return
15
16         here = os.getcwd() # Save where we were
17         os.chdir(rootdir)
18         # Get a GIT checkout. Either create it, or refresh it
19         if os.path.exists("tools/simgrid/.git"):
20             subprocess.run("cd tools/simgrid && git pull &&  cd ../..", shell=True, check=True)
21         else:
22             subprocess.run("rm -rf tools/simgrid && git clone --depth=1 https://framagit.org/simgrid/simgrid.git tools/simgrid", shell=True, check=True)
23
24         # Build and install it
25         os.chdir("tools/simgrid")
26         subprocess.run(f"cmake -DCMAKE_INSTALL_PREFIX={rootdir}/builds/SimGrid -Denable_model-checking=ON .", shell=True, check=True)
27         subprocess.run("make -j$(nproc) install VERBOSE=1", shell=True, check=True)
28
29         # Back to our previous directory
30         os.chdir(here)
31
32
33     def ensure_image(self):
34         AbstractTool.ensure_image(self, "-x simgrid")
35
36     def setup(self, rootdir):
37         os.environ['PATH'] = os.environ['PATH'] + ":" + rootdir + "/builds/SimGrid/bin"
38         os.environ['VERBOSE'] = '1'
39
40     def run(self, execcmd, filename, binary, id, timeout, batchinfo):
41         cachefile = f'{binary}_{id}'
42
43         if not os.path.exists("cluster.xml"):
44             with open('cluster.xml', 'w') as outfile:
45                 outfile.write("<?xml version='1.0'?>\n")
46                 outfile.write("<!DOCTYPE platform SYSTEM \"https://simgrid.org/simgrid.dtd\">\n")
47                 outfile.write('<platform version="4.1">\n')
48                 outfile.write(' <cluster id="acme" prefix="node-" radical="0-99" suffix="" speed="1Gf" bw="125MBps" lat="50us"/>\n')
49                 outfile.write('</platform>\n')
50
51         execcmd = execcmd.replace("mpirun", "smpirun -wrapper simgrid-mc -platform ./cluster.xml -analyze --cfg=smpi/finalization-barrier:on --cfg=smpi/list-leaks:10 --cfg=model-check/max-depth:10000")
52         execcmd = execcmd.replace('${EXE}', binary)
53         execcmd = execcmd.replace('$zero_buffer', "--cfg=smpi/buffering:zero")
54         execcmd = execcmd.replace('$infty_buffer', "--cfg=smpi/buffering:infty")
55
56         run_cmd(
57             buildcmd=f"smpicc {filename} -trace-call-location -g -Wl,-znorelro -Wl,-znoseparate-code -o {binary}",
58             execcmd=execcmd,
59             cachefile=cachefile,
60             filename=filename,
61             binary=binary,
62             timeout=timeout,
63             batchinfo=batchinfo)
64
65     def teardown(self):
66         subprocess.run("find -type f -a -executable | xargs rm -f", shell=True, check=True) # Remove generated cruft (binary files)
67         subprocess.run("rm -f smpitmp-* core", shell=True, check=True) 
68
69     def parse(self, cachefile):
70         if os.path.exists(f'{cachefile}.timeout') or os.path.exists(f'logs/simgrid/{cachefile}.timeout'):
71             return 'timeout'
72         if not (os.path.exists(f'{cachefile}.txt') or os.path.exists(f'logs/simgrid/{cachefile}.txt')):
73             return 'failure'
74
75         with open(f'{cachefile}.txt' if os.path.exists(f'{cachefile}.txt') else f'logs/simgrid/{cachefile}.txt', 'r') as infile:
76             output = infile.read()
77
78         if re.search('Compilation of .*? raised an error \(retcode: ', output):
79             return 'UNIMPLEMENTED'
80
81         if re.search('MBI_MSG_RACE', output):
82             return 'MBI_MSG_RACE'
83
84         if re.search('MC is currently not supported here', output):
85             return 'failure'
86
87         if re.search('Collective communication mismatch', output):
88             return 'Collective mismatch'
89
90         if re.search('DEADLOCK DETECTED', output):
91             return 'deadlock'
92         if re.search('returned MPI_ERR', output):
93             return 'mpierr'
94         if re.search('Not yet implemented', output):
95             return 'UNIMPLEMENTED'
96         if re.search('CRASH IN THE PROGRAM', output):
97             return 'failure'
98         if re.search('Probable memory leaks in your code: SMPI detected', output):
99             return 'resleak'
100         if re.search('DFS exploration ended.', output):
101             return 'OK'
102
103         print (f">>>>[ INCONCLUSIVE ]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ({cachefile})")
104         print(output)
105         print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
106         return 'other'