generate_config.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. configurations = [
  9. ('Java', None, ['Linux'], ['json']),
  10. ('Java', 'Ebean', ['Linux'], ['db', 'query']),
  11. ('Java', 'JPA', ['Linux'], ['db', 'query']),
  12. ('Scala', None, ['Linux'], ['json']),
  13. ('Scala', 'Anorm', ['Linux', 'Windows'], ['db', 'query', 'fortune', 'update']),
  14. ('Scala', 'Slick', ['Linux'], ['db', 'query', 'fortune', 'update']),
  15. ]
  16. # All play2 test applications must use the same URLs.
  17. test_urls = {
  18. 'json': '/json',
  19. 'db': '/db',
  20. 'query': '/queries?queries=',
  21. 'fortune': '/fortunes',
  22. 'update': '/update?queries=',
  23. }
  24. langs = {
  25. 'Java': ['Java', 'play2-java'],
  26. 'Scala': ['Scala', 'play2-scala']
  27. }
  28. def pathForLang(lang):
  29. return os.path.join(frameworksPath(), *langs[lang])
  30. def frameworksPath():
  31. 'Get the absolute path of ROOT/frameworks'
  32. return os.path.abspath(os.path.join(__file__, '..', '..', '..'))
  33. lang_test_configs = {}
  34. for lang, _ in langs.iteritems():
  35. lang_test_configs[lang] = collections.OrderedDict()
  36. for lang, orm, opsyses, tests in configurations:
  37. dir_name = 'play2-' + lang.lower() + (('-'+orm.lower()) if orm else '')
  38. setup_name = 'setup_' + lang.lower() + (('_'+orm.lower()) if orm else '')
  39. setup_path = os.path.join(pathForLang(lang), setup_name+'.py')
  40. print 'Generating', setup_path
  41. with open(setup_path, 'w') as f:
  42. f.write(textwrap.dedent("""
  43. # This file was generated by frameworks/Java/play2-java/generate_config.py.
  44. # Do not edit this file directly, use the script to regenerate.
  45. from .setup_common import make_setup_for_dir
  46. make_setup_for_dir(globals(), '"""+dir_name+"""')
  47. """))
  48. for opsys in opsyses:
  49. if len(opsyses) == 1:
  50. test_name = lang.lower() + (('-'+orm.lower()) if orm else '')
  51. else:
  52. test_name = lang.lower() + (('-'+orm.lower()) if orm else '') + '-'+opsys.lower()
  53. test_config_json = collections.OrderedDict([
  54. ('display_name', 'play2-'+test_name),
  55. ('setup_file', setup_name),
  56. ('framework', 'play2'),
  57. ('language', lang),
  58. ('orm', 'Full' if orm else 'Raw'),
  59. ('os', opsys),
  60. ('database', 'MySQL' if orm else 'None'),
  61. ('approach', 'Realistic'),
  62. ('classification', 'Fullstack'),
  63. ('platform', 'Netty'),
  64. ('webserver', 'None'),
  65. ('database_os', 'Linux'),
  66. ('notes', ''),
  67. ('versus', 'netty'),
  68. ('port', '9000'),
  69. ])
  70. for test in tests:
  71. test_config_json[test+'_url'] = test_urls[test]
  72. lang_test_configs[lang][test_name] = test_config_json
  73. for lang, _ in langs.iteritems():
  74. benchmark_config_path = os.path.join(pathForLang(lang), 'benchmark_config')
  75. print 'Generating', benchmark_config_path
  76. with open(benchmark_config_path, 'w') as f:
  77. json_str = json.dumps({
  78. 'framework': 'play2',
  79. 'tests': [lang_test_configs[lang]]
  80. }, indent=2)
  81. f.write(json_str)