Don't copy CMake scripts to install folder
[junction.git] / samples / MapMemoryBench / 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']),
12     ('linear', 'junction/extra/impl/MapAdapter_Linear.h', []),
13     ('leapfrog', 'junction/extra/impl/MapAdapter_LeapFrog.h', []),
14     ('grampa', 'junction/extra/impl/MapAdapter_Grampa.h', []),
15     ('stdmap', 'junction/extra/impl/MapAdapter_StdMap.h', []),
16     ('folly', 'junction/extra/impl/MapAdapter_Folly.h', ['-DJUNCTION_WITH_FOLLY=1', '-DTURF_WITH_EXCEPTIONS=1']),
17     ('nbds', 'junction/extra/impl/MapAdapter_NBDS.h', ['-DJUNCTION_WITH_NBDS=1']),
18     ('tbb', 'junction/extra/impl/MapAdapter_TBB.h', ['-DJUNCTION_WITH_TBB=1']),
19     ('tervel', 'junction/extra/impl/MapAdapter_Tervel.h', ['-DJUNCTION_WITH_TERVEL=1']),
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 in ALL_MAPS:
36     subdir = "build-%s" % suffix
37     if not os.path.exists(subdir):
38         os.mkdir(subdir)
39     os.chdir(subdir)
40     print("Configuring in %s..." % subdir)
41     with open('junction_userconfig.h.in', 'w') as f:
42         f.write('#define JUNCTION_IMPL_MAPADAPTER_PATH "%s"\n' % include)
43
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_INSTALL_PREFIX=TestAllMapsInstallFolder', '-DCMAKE_BUILD_TYPE=RelWithDebInfo', '-DTURF_USE_DLMALLOC=1', '-DTURF_DLMALLOC_FAST_STATS=1',
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', 'MapMemoryBench')])
52         with open('results.txt', 'wb') as f:
53             f.write(results)
54     os.chdir("..")