generate_config.py 3.1 KB

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