generate_config.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/usr/bin/env python
  2. import collections, json, 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, (os, ...), (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. ('Scala', None, ['Linux'], ['json']),
  11. ('Java', 'Ebean', ['Linux'], ['db', 'query']),
  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. tests_config_json = collections.OrderedDict()
  23. for lang, orm, oses, tests in configurations:
  24. dir_name = 'play2-' + lang.lower() + (('-'+orm.lower()) if orm else '')
  25. print 'Generating tests for test application '+dir_name
  26. setup_name = 'setup_' + lang.lower() + (('_'+orm.lower()) if orm else '')
  27. for os in oses:
  28. if len(oses) == 1:
  29. test_name = lang.lower() + (('-'+orm.lower()) if orm else '')
  30. else:
  31. test_name = lang.lower() + (('-'+orm.lower()) if orm else '') + '-'+os.lower()
  32. test_config_json = collections.OrderedDict([
  33. ('display_name', 'play2-'+test_name),
  34. ('setup_file', setup_name),
  35. ('framework', 'play2'),
  36. ('language', lang),
  37. ('orm', orm if orm else 'Raw'),
  38. ('os', os),
  39. ('database', 'MySQL' if orm else 'None'),
  40. ('approach', 'Realistic'),
  41. ('classification', 'Fullstack'),
  42. ('platform', 'Netty'),
  43. ('webserver', 'None'),
  44. ('database_os', 'Linux'),
  45. ('notes', ''),
  46. ('versus', 'netty'),
  47. ('port', '9000'),
  48. ])
  49. for test in tests:
  50. test_config_json[test+'_url'] = test_urls[test]
  51. tests_config_json[test_name] = test_config_json
  52. with open(setup_name+'.py', 'w') as f:
  53. f.write(textwrap.dedent("""
  54. # This file was generated by generate_config.py.
  55. # Do not edit this file directly.
  56. from .setup_common import make_setup_for_dir
  57. make_setup_for_dir(globals(), '"""+dir_name+"""')
  58. """))
  59. with open('benchmark_config', 'w') as f:
  60. json_str = json.dumps({
  61. 'framework': 'play2',
  62. 'tests': [tests_config_json]
  63. }, indent=2)
  64. f.write(json_str)