#!/usr/bin/env python import collections, json, os, textwrap # This script generates the benchmark_config and setup_*.py files. # To add new tests, modify the `configurations` and `test_urls` tables. # Each line corresponds to a test application. # Format is: (language, orm, (opsys, ...), (test, ...)) # See the dir_name logic below to see the directory name for each test application. Config = collections.namedtuple('Config', ['lang', 'orm', 'db', 'operatingSystems', 'tests', 'shouldIncludeResults']) configurations = [ # Plain Java test Config( 'Java', None, None, operatingSystems = ['Linux'], tests = ['json'], shouldIncludeResults = True ), # Java database tests Config( 'Java', 'Ebean', 'MySQL', operatingSystems = ['Linux'], tests = ['db', 'query'], shouldIncludeResults = True ), Config( 'Java', 'JPA', 'MySQL', operatingSystems = ['Linux'], tests = ['db', 'query', 'fortune', 'update', 'plaintext'], shouldIncludeResults = True ), Config( 'Java', 'JPA HikariCP', 'MySQL', operatingSystems = ['Linux'], tests = ['db', 'query', 'fortune', 'update', 'plaintext'], shouldIncludeResults = True ), # Plain Scala test Config( 'Scala', None, None, operatingSystems = ['Linux'], tests = ['json'], shouldIncludeResults = True ), # Scala database tests Config( 'Scala', 'Activate', 'MySQL', operatingSystems = ['Linux'], tests = ['db', 'query', 'fortune', 'update'], shouldIncludeResults = False # Uses old versions of Play and Activate ), Config( 'Scala', 'Anorm', 'MySQL', operatingSystems = ['Linux', 'Windows'], tests = ['db', 'query', 'fortune', 'update'], shouldIncludeResults = True ), Config( 'Scala', 'ReactiveMongo', 'MongoDB', operatingSystems = ['Linux'], tests = ['db', 'query'], shouldIncludeResults = True # Updated to Play 2.3 and ReactiveMongo 0.10, but no maintainer ), Config( 'Scala', 'Slick', 'MySQL', operatingSystems = ['Linux'], tests = ['db', 'query', 'fortune', 'update'], shouldIncludeResults = True ) ] # All play2 test applications must use the same URLs. test_urls = { 'json': '/json', 'db': '/db', 'query': '/queries?queries=', 'fortune': '/fortunes', 'update': '/update?queries=', 'plaintext': '/plaintext', } langs = { 'Java': ['Java', 'play2-java'], 'Scala': ['Scala', 'play2-scala'] } def pathForLang(lang): return os.path.join(frameworksPath(), *langs[lang]) def frameworksPath(): 'Get the absolute path of ROOT/frameworks' return os.path.abspath(os.path.join(__file__, '..', '..', '..')) def maybe(item): 'Maps None => [] and item => [item]' if item is None: return [] else: return [item] def namify(bits, sep): 'Joins a list of bits together then replaces spaces with sep.' return ' '.join(bits).replace(' ', sep).lower() lang_test_configs = {} for lang, _ in langs.iteritems(): lang_test_configs[lang] = collections.OrderedDict() for config in configurations: core_name_bits = [config.lang] + maybe(config.orm) dir_name = namify(['play2'] + core_name_bits, '-') setup_name = namify(['setup'] + core_name_bits, '_') setup_path = os.path.join(pathForLang(config.lang), setup_name+'.py') print 'Generating', setup_path with open(setup_path, 'w') as f: f.write(textwrap.dedent(""" # This file was generated by frameworks/Java/play2-java/generate_config.py. # Do not edit this file directly, use the script to regenerate. from .setup_common import make_setup_for_dir make_setup_for_dir(globals(), '"""+dir_name+"""') """)) # We make a separate test config entry for each operating system # that the test runs on. for opsys in config.operatingSystems: # Note the test name may differ from the directory name because # it may have the OS name or a word to show that results shouldn't # be included. # If there is more than one OS then add the current OS to the test name # so we can distinguish between the tests. opsys_name_bit = [] if len(config.operatingSystems) == 1 else [opsys] # If the test is out of date then add 'do not include' to the end of the # test name to make it harder to accidentally include in final results. tags_bit = [] if config.shouldIncludeResults else ['do not include'] test_name_bits = core_name_bits + opsys_name_bit + tags_bit test_config_json = collections.OrderedDict([ ('display_name', namify(['play2'] + test_name_bits, '-')), ('setup_file', setup_name), ('framework', 'play2'), ('language', config.lang), ('orm', 'Full' if config.orm else 'Raw'), ('os', opsys), ('database', config.db if config.db else 'None'), ('approach', 'Realistic'), ('classification', 'Fullstack'), ('platform', 'Netty'), ('webserver', 'None'), ('database_os', 'Linux'), ('notes', ''), ('versus', 'netty'), ('port', '9000'), ]) for test in config.tests: test_config_json[test+'_url'] = test_urls[test] lang_test_configs[config.lang][namify(test_name_bits, '-')] = test_config_json for lang, _ in langs.iteritems(): benchmark_config_path = os.path.join(pathForLang(lang), 'benchmark_config') print 'Generating', benchmark_config_path with open(benchmark_config_path, 'w') as f: json_str = json.dumps({ 'framework': 'play2', 'tests': [lang_test_configs[lang]] }, indent=2) f.write(json_str)