generate_config.py 3.0 KB

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