test.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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.3-py2.7.egg"])
  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',
  36. 'url': 'ws://localhost:33080/echo',
  37. 'options': {'version': 18} # RFC6455
  38. }],
  39. 'cases': ['*'],
  40. 'exclude-cases': [] }
  41. return base
  42. def run_test(env, config):
  43. activate_env(env)
  44. from twisted.python import log
  45. from twisted.internet import reactor
  46. from autobahntestsuite.fuzzing import FuzzingClientFactory
  47. os.chdir(AB_TESTS_PRIV)
  48. log.startLogging(sys.stdout)
  49. fuzzer = FuzzingClientFactory(config)
  50. return reactor.run()
  51. def main():
  52. cmd = sys.argv[1]
  53. if cmd == 'setup':
  54. install_env(AB_TESTS_ENV)
  55. print('AB-TESTS-SETUP-OK')
  56. elif cmd == 'test':
  57. run_test(AB_TESTS_ENV, client_config())
  58. print('AB-TESTS-TEST-OK')
  59. else:
  60. return 1
  61. if __name__ == '__main__':
  62. main()