Skip to content
Snippets Groups Projects

TEST: Test fslStartup logic

Merged Paul McCarthy requested to merge test/fslstartup into master
2 files
+ 38
23
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -6,12 +6,25 @@ import tempfile
@@ -6,12 +6,25 @@ import tempfile
import subprocess as sp
import subprocess as sp
def run(cmd, **kwargs):
def run(cmd, ompthreads=None, blasthreads=None, fslskipglobal=None, keepenv=False):
 
 
env = os.environ.copy()
 
 
if not keepenv:
 
blacklist = ['OMP', 'GOTO', 'BLAS', 'FSL']
 
 
for varname in list(env.keys()):
 
if any(b in varname for b in blacklist):
 
env.pop(varname)
 
 
if ompthreads is not None: env['OMP_NUM_THREADS'] = str(ompthreads)
 
if blasthreads is not None: env['BLAS_NUM_THREADS'] = str(blasthreads)
 
if fslskipglobal is not None: env['FSL_SKIP_GLOBAL'] = str(fslskipglobal)
result = sp.run(shlex.split(cmd), check=True, text=True,
result = sp.run(shlex.split(cmd), check=True, text=True,
stdout=sp.PIPE, stderr=sp.STDOUT, **kwargs)
stdout=sp.PIPE, stderr=sp.STDOUT, env=env)
print(f'Called {cmd}')
print(f'Called {cmd} {ompthreads} {blasthreads} {fslskipglobal}')
print(f' exit code: {result.returncode}')
print(f' exit code: {result.returncode}')
print(f' stdout: {result.stdout.strip()}')
print(f' stdout: {result.stdout.strip()}')
@@ -20,23 +33,17 @@ def run(cmd, **kwargs):
@@ -20,23 +33,17 @@ def run(cmd, **kwargs):
def main():
def main():
blacklist = ['OMP', 'GOTO', 'BLAS', 'FSL']
run('make', keepenv=True)
env = os.environ.copy()
for varname in list(env.keys()):
if any(b in varname for b in blacklist):
env.pop(varname)
env['OMP_NUM_THREADS'] = '8'
env['BLAS_NUM_THREADS'] = '8'
run('make')
# Default behaviour should be: OMP multi-threaded, BLAS single threaded.
# Default behaviour should be: OMP multi-threaded, BLAS single threaded.
assert run('./test_fslStartup', env=env) == '8 1 8'
assert run('./test_fslStartup', 8, 8) == '8 1 8'
 
assert run('./test_fslStartup', 4, 4) == '4 1 4'
 
assert run('./test_fslStartup', 1, 1) == '1 1 1'
# With FSL_SKIP_GLOBAL, BLAS should be multi-threaded
# With FSL_SKIP_GLOBAL, BLAS should be multi-threaded
env['FSL_SKIP_GLOBAL'] = '1'
assert run('./test_fslStartup', 8, 8, 1) == '8 8 8'
assert run('./test_fslStartup', env=env) == '8 8 8'
assert run('./test_fslStartup', 4, 4, 1) == '4 4 4'
 
assert run('./test_fslStartup', 1, 1, 1) == '1 1 1'
if __name__ == '__main__':
if __name__ == '__main__':
Loading