test.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env python
  2. import os
  3. import os.path
  4. import sys
  5. import subprocess
  6. AB_TESTS_ENV = os.getenv("AB_TESTS_ENV")
  7. AB_TESTS_PRIV = os.getenv("AB_TESTS_PRIV")
  8. VIRTUALENV_URL = 'https://raw.github.com/pypa/virtualenv/master/virtualenv.py'
  9. VIRTUALENV_BIN = os.path.join(AB_TESTS_ENV, "virtualenv.py")
  10. INSTALL_BIN = os.path.join(AB_TESTS_ENV, "bin", "easy_install")
  11. def activate_env(env):
  12. """
  13. See 'Using Virtualenv without bin/python' at http://www.virtualenv.org
  14. """
  15. activate_this = os.path.join(env, 'bin', 'activate_this.py')
  16. exec(compile(open(activate_this).read(), activate_this, 'exec'),
  17. dict(__file__=activate_this))
  18. def install_env(env):
  19. """
  20. Install a new virtualenv at a path and also install the Autobahn package.
  21. """
  22. os.makedirs(env) if not os.path.isdir(env) else None
  23. subprocess.check_call(["curl", "-sS", VIRTUALENV_URL, "-o", VIRTUALENV_BIN])
  24. subprocess.check_call(["python", VIRTUALENV_BIN, env])
  25. activate_env(env)
  26. subprocess.check_call([INSTALL_BIN, "http://pypi.python.org/packages/2.7/a/autobahntestsuite/autobahntestsuite-0.5.2-py2.7.egg#md5=f7480d4ca6ce4954ac05f59778de4bda"])
  27. def client_config():
  28. """
  29. See comment on SUPPORTED_SPEC_VERSIONS in Autobahn/.../websocket.py
  30. """
  31. base = {
  32. 'options': {'failByDrop': False},
  33. 'enable-ssl': False,
  34. 'servers': [{
  35. 'agent': 'Cowboy/10',
  36. 'url': 'ws://localhost:33080/echo',
  37. 'options': {'version': 10}}, # hybi-10
  38. {'agent': 'Cowboy/18',
  39. 'url': 'ws://localhost:33080/echo',
  40. 'options': {'version': 18}} # RFC6455
  41. ],
  42. 'cases': ['*'],
  43. 'exclude-cases': [] }
  44. return base
  45. def run_test(env, config):
  46. activate_env(env)
  47. from twisted.python import log
  48. from twisted.internet import reactor
  49. from autobahntestsuite.fuzzing import FuzzingClientFactory
  50. os.chdir(AB_TESTS_PRIV)
  51. log.startLogging(sys.stdout)
  52. fuzzer = FuzzingClientFactory(config)
  53. return reactor.run()
  54. def main():
  55. cmd = sys.argv[1]
  56. if cmd == 'setup':
  57. install_env(AB_TESTS_ENV)
  58. print('AB-TESTS-SETUP-OK')
  59. elif cmd == 'test':
  60. run_test(AB_TESTS_ENV, client_config())
  61. print('AB-TESTS-TEST-OK')
  62. else:
  63. return 1
  64. if __name__ == '__main__':
  65. main()