Logo AND Algorithmique Numérique Distribuée

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