Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Replace 're.sub' by more efficient 'str.replace'.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 17 Mar 2022 17:28:58 +0000 (18:28 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 17 Mar 2022 17:29:13 +0000 (18:29 +0100)
teshsuite/smpi/MBI/MBI.py
teshsuite/smpi/MBI/generator_utils.py
teshsuite/smpi/MBI/simgrid.py

index bed5d75..9c384a4 100755 (executable)
@@ -9,7 +9,6 @@
 
 import sys
 import os
-import re
 
 from MBIutils import *
 import simgrid
@@ -31,10 +30,10 @@ simgrid = simgrid.Tool()
 
 (name, path, binary, filename) = sys.argv
 for test in parse_one_code(filename):
-    execcmd = re.sub("mpirun", f"{path}/smpi_script/bin/smpirun -wrapper '{path}/bin/simgrid-mc --log=mc_safety.t:info' -platform ./cluster.xml -analyze --cfg=smpi/finalization-barrier:on --cfg=smpi/list-leaks:10 --cfg=model-check/max-depth:10000", test['cmd'])
-    execcmd = re.sub('\${EXE}', binary, execcmd)
-    execcmd = re.sub('\$zero_buffer', "--cfg=smpi/buffering:zero", execcmd)
-    execcmd = re.sub('\$infty_buffer', "--cfg=smpi/buffering:infty", execcmd)
+    execcmd = test['cmd'].replace("mpirun", f"{path}/smpi_script/bin/smpirun -wrapper '{path}/bin/simgrid-mc --log=mc_safety.t:info' -platform ./cluster.xml -analyze --cfg=smpi/finalization-barrier:on --cfg=smpi/list-leaks:10 --cfg=model-check/max-depth:10000")
+    execcmd = execcmd.replace('${EXE}', binary)
+    execcmd = execcmd.replace('$zero_buffer', "--cfg=smpi/buffering:zero")
+    execcmd = execcmd.replace('$infty_buffer', "--cfg=smpi/buffering:infty")
 
     if os.path.exists(f'{filename}.txt'):
         os.remove(f'{filename}.txt')
@@ -46,4 +45,4 @@ for test in parse_one_code(filename):
     if res_category != "TRUE_NEG" and res_category != "TRUE_POS":
         print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n")
         print(f"SimGrid gave the wrong result ({outcome} instead of {test['expect']}).")
-        sys.exit(1)
\ No newline at end of file
+        sys.exit(1)
index 6c96d66..3ef5d5c 100644 (file)
@@ -438,7 +438,7 @@ def find_line(content, target, filename):
 
 def make_file(template, filename, replace):
     output = template
-    filename = re.sub("_MPI_", "_", filename)
+    filename = filename.replace("_MPI_", "_")
     replace['filename'] = filename
     # Replace all variables that don't have a ':' in their name
     while re.search("@\{[^@:]*\}@", output):
index b4f4158..049ece1 100644 (file)
@@ -48,12 +48,12 @@ class Tool(AbstractTool):
                 outfile.write(' <cluster id="acme" prefix="node-" radical="0-99" suffix="" speed="1Gf" bw="125MBps" lat="50us"/>\n')
                 outfile.write('</platform>\n')
 
-        execcmd = re.sub("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", execcmd)
+        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")
         if re.search("Concurrency", binary):  # DPOR reduction in simgrid cannot deal with RMA calls as they contain mutexes
-            execcmd = re.sub("smpirun", "smpirun --cfg=model-check/reduction:none", execcmd)
-        execcmd = re.sub('\${EXE}', binary, execcmd)
-        execcmd = re.sub('\$zero_buffer', "--cfg=smpi/buffering:zero", execcmd)
-        execcmd = re.sub('\$infty_buffer', "--cfg=smpi/buffering:infty", execcmd)
+            execcmd = execcmd.replace("smpirun", "smpirun --cfg=model-check/reduction:none")
+        execcmd = execcmd.replace('${EXE}', binary)
+        execcmd = execcmd.replace('$zero_buffer', "--cfg=smpi/buffering:zero")
+        execcmd = execcmd.replace('$infty_buffer', "--cfg=smpi/buffering:infty")
 
         run_cmd(
             buildcmd=f"smpicc {filename} -trace-call-location -g -Wl,-znorelro -Wl,-znoseparate-code -o {binary}",