generate_config.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #!/usr/bin/env python
  2. import collections, json, os, textwrap
  3. # This script generates the benchmark_config and setup_*.py files.
  4. # To add new tests, modify the `configurations` and `test_urls` tables.
  5. # Each line corresponds to a test application.
  6. # Format is: (language, orm, (opsys, ...), (test, ...))
  7. # See the dir_name logic below to see the directory name for each test application.
  8. Config = collections.namedtuple('Config', ['lang', 'orm', 'db', 'operatingSystems', 'tests', 'shouldIncludeResults'])
  9. configurations = [
  10. # Plain Java test
  11. Config(
  12. 'Java', None, None,
  13. operatingSystems = ['Linux'],
  14. tests = ['json'],
  15. shouldIncludeResults = True
  16. ),
  17. # Java database tests
  18. Config(
  19. 'Java', 'Ebean', 'MySQL',
  20. operatingSystems = ['Linux'],
  21. tests = ['db', 'query'],
  22. shouldIncludeResults = True
  23. ),
  24. Config(
  25. 'Java', 'JPA', 'MySQL',
  26. operatingSystems = ['Linux'],
  27. tests = ['db', 'query', 'fortune', 'update', 'plaintext'],
  28. shouldIncludeResults = True
  29. ),
  30. Config(
  31. 'Java', 'JPA HikariCP', 'MySQL',
  32. operatingSystems = ['Linux'],
  33. tests = ['db', 'query', 'fortune', 'update', 'plaintext'],
  34. shouldIncludeResults = True
  35. ),
  36. # Plain Scala test
  37. Config(
  38. 'Scala', None, None,
  39. operatingSystems = ['Linux'],
  40. tests = ['json'],
  41. shouldIncludeResults = True
  42. ),
  43. # Scala database tests
  44. Config(
  45. 'Scala', 'Activate', 'MySQL',
  46. operatingSystems = ['Linux'],
  47. tests = ['db', 'query', 'fortune', 'update'],
  48. shouldIncludeResults = False # Uses old versions of Play and Activate
  49. ),
  50. Config(
  51. 'Scala', 'Anorm', 'MySQL',
  52. operatingSystems = ['Linux', 'Windows'],
  53. tests = ['db', 'query', 'fortune', 'update'],
  54. shouldIncludeResults = True
  55. ),
  56. Config(
  57. 'Scala', 'ReactiveMongo', 'MongoDB',
  58. operatingSystems = ['Linux'],
  59. tests = ['db', 'query'],
  60. shouldIncludeResults = True # Updated to Play 2.3 and ReactiveMongo 0.10, but no maintainer
  61. ),
  62. Config(
  63. 'Scala', 'Slick', 'MySQL',
  64. operatingSystems = ['Linux'],
  65. tests = ['db', 'query', 'fortune', 'update'],
  66. shouldIncludeResults = True
  67. )
  68. ]
  69. # All play2 test applications must use the same URLs.
  70. test_urls = {
  71. 'json': '/json',
  72. 'db': '/db',
  73. 'query': '/queries?queries=',
  74. 'fortune': '/fortunes',
  75. 'update': '/update?queries=',
  76. 'plaintext': '/plaintext',
  77. }
  78. langs = {
  79. 'Java': ['Java', 'play2-java'],
  80. 'Scala': ['Scala', 'play2-scala']
  81. }
  82. def pathForLang(lang):
  83. return os.path.join(frameworksPath(), *langs[lang])
  84. def frameworksPath():
  85. 'Get the absolute path of ROOT/frameworks'
  86. return os.path.abspath(os.path.join(__file__, '..', '..', '..'))
  87. def maybe(item):
  88. 'Maps None => [] and item => [item]'
  89. if item is None:
  90. return []
  91. else:
  92. return [item]
  93. def namify(bits, sep):
  94. 'Joins a list of bits together then replaces spaces with sep.'
  95. return ' '.join(bits).replace(' ', sep).lower()
  96. lang_test_configs = {}
  97. for lang, _ in langs.iteritems():
  98. lang_test_configs[lang] = collections.OrderedDict()
  99. for config in configurations:
  100. core_name_bits = [config.lang] + maybe(config.orm)
  101. dir_name = namify(['play2'] + core_name_bits, '-')
  102. setup_name = namify(['setup'] + core_name_bits, '_')
  103. setup_path = os.path.join(pathForLang(config.lang), setup_name+'.py')
  104. print 'Generating', setup_path
  105. with open(setup_path, 'w') as f:
  106. f.write(textwrap.dedent("""
  107. # This file was generated by frameworks/Java/play2-java/generate_config.py.
  108. # Do not edit this file directly, use the script to regenerate.
  109. from .setup_common import make_setup_for_dir
  110. make_setup_for_dir(globals(), '"""+dir_name+"""')
  111. """))
  112. # We make a separate test config entry for each operating system
  113. # that the test runs on.
  114. for opsys in config.operatingSystems:
  115. # Note the test name may differ from the directory name because
  116. # it may have the OS name or a word to show that results shouldn't
  117. # be included.
  118. # If there is more than one OS then add the current OS to the test name
  119. # so we can distinguish between the tests.
  120. opsys_name_bit = [] if len(config.operatingSystems) == 1 else [opsys]
  121. # If the test is out of date then add 'do not include' to the end of the
  122. # test name to make it harder to accidentally include in final results.
  123. tags_bit = [] if config.shouldIncludeResults else ['do not include']
  124. test_name_bits = core_name_bits + opsys_name_bit + tags_bit
  125. test_config_json = collections.OrderedDict([
  126. ('display_name', namify(['play2'] + test_name_bits, '-')),
  127. ('setup_file', setup_name),
  128. ('framework', 'play2'),
  129. ('language', config.lang),
  130. ('orm', 'Full' if config.orm else 'Raw'),
  131. ('os', opsys),
  132. ('database', config.db if config.db else 'None'),
  133. ('approach', 'Realistic'),
  134. ('classification', 'Fullstack'),
  135. ('platform', 'Netty'),
  136. ('webserver', 'None'),
  137. ('database_os', 'Linux'),
  138. ('notes', ''),
  139. ('versus', 'netty'),
  140. ('port', '9000'),
  141. ])
  142. for test in config.tests:
  143. test_config_json[test+'_url'] = test_urls[test]
  144. lang_test_configs[config.lang][namify(test_name_bits, '-')] = test_config_json
  145. for lang, _ in langs.iteritems():
  146. benchmark_config_path = os.path.join(pathForLang(lang), 'benchmark_config')
  147. print 'Generating', benchmark_config_path
  148. with open(benchmark_config_path, 'w') as f:
  149. json_str = json.dumps({
  150. 'framework': 'play2',
  151. 'tests': [lang_test_configs[lang]]
  152. }, indent=2)
  153. f.write(json_str)