Initial commit
[junction.git] / samples / MapScalabilityTests / TestAllMaps.py
1 #!/usr/bin/env python
2 import os
3 import subprocess
4 import sys
5
6 # Default CMake command is just 'cmake' but you can override it by setting
7 # the CMAKE environment variable:
8 CMAKE = os.getenv('CMAKE', 'cmake')
9
10 ALL_MAPS = [
11     ('michael', 'junction/extra/impl/MapAdapter_CDS_Michael.h', ['-DJUNCTION_WITH_CDS=1', '-DTURF_WITH_EXCEPTIONS=1'], ['-i10000', '-c200']),
12     ('linear', 'junction/extra/impl/MapAdapter_Linear.h', [], ['-i10000', '-c200']),
13     ('leapfrog', 'junction/extra/impl/MapAdapter_LeapFrog.h', [], ['-i10000', '-c200']),
14     ('grampa', 'junction/extra/impl/MapAdapter_Grampa.h', [], ['-i10000', '-c200']),
15     ('stdmap', 'junction/extra/impl/MapAdapter_StdMap.h', [], ['-i10000', '-c10']),
16     ('folly', 'junction/extra/impl/MapAdapter_Folly.h', ['-DJUNCTION_WITH_FOLLY=1', '-DTURF_WITH_EXCEPTIONS=1'], ['-i2000', '-c1']),
17     ('nbds', 'junction/extra/impl/MapAdapter_NBDS.h', ['-DJUNCTION_WITH_NBDS=1'], ['-i10000', '-c200']),
18     ('tbb', 'junction/extra/impl/MapAdapter_TBB.h', ['-DJUNCTION_WITH_TBB=1'], ['-i10000', '-c200']),
19     ('tervel', 'junction/extra/impl/MapAdapter_Tervel.h', ['-DJUNCTION_WITH_TERVEL=1'], ['-i1000', '-c20']),
20 ]
21
22 # Scan arguments for path to CMakeLists.txt and args to pass through.
23 passThroughArgs = []
24 pathArgs = []
25 for arg in sys.argv[1:]:
26     if arg.startswith('-'):
27         passThroughArgs.append(arg)
28     else:
29         pathArgs.append(arg)
30 if len(pathArgs) != 1:
31     sys.stderr.write('You must provide exactly one path argument.\n')
32     exit(1)
33
34 listFilePath = os.path.abspath(pathArgs[0])
35 for suffix, include, cmakeOpts, runtimeOpts in ALL_MAPS:
36     success = True
37     subdir = 'build-%s' % suffix
38     if not os.path.exists(subdir):
39         os.mkdir(subdir)
40     os.chdir(subdir)
41     print('Configuring in %s...' % subdir)
42     with open('junction_userconfig.h.in', 'w') as f:
43         f.write('#define JUNCTION_IMPL_MAPADAPTER_PATH "%s"\n' % include)
44     userConfigCMakePath = os.path.abspath('junction_userconfig.h.in')
45     if os.sep != '/':
46         userConfigCMakePath = userConfigCMakePath.replace(os.sep, '/')
47     if subprocess.call([CMAKE, listFilePath, '-DCMAKE_BUILD_TYPE=RelWithDebInfo', '-DCMAKE_INSTALL_PREFIX=TestAllMapsInstallFolder',
48                        '-DJUNCTION_USERCONFIG=%s' % userConfigCMakePath] + passThroughArgs + cmakeOpts) == 0:
49         subprocess.check_call([CMAKE, '--build', '.', '--target', 'install', '--config', 'RelWithDebInfo'])
50         print('Running in %s...' % subdir)
51         results = subprocess.check_output([os.path.join('TestAllMapsInstallFolder', 'bin', 'MapScalabilityTests')] + runtimeOpts)
52         with open('results.txt', 'wb') as f:
53             f.write(results)
54     os.chdir('..')