diff --git a/wstest/Makefile b/wstest/Makefile index b1a51eee..1d155b8a 100644 --- a/wstest/Makefile +++ b/wstest/Makefile @@ -6,7 +6,7 @@ default: clean: -rm -rf ./reports - -rm -rf ./downloads + #-rm -rf ./downloads -rm -rf ./venv* -rm -rf ./wstest @@ -33,7 +33,7 @@ build_wstest: build_pypy2: mkdir -p ./pypy2 tar xvf ./downloads/pypy2-v5.7.0-linux64.tar.bz2 --strip-components=1 -C ./pypy2 - cd ./pypy2/bin && ln -s pypy python && cd ../.. + #cd ./pypy2/bin && ln -s pypy python && cd ../.. ./pypy2/bin/python ./downloads/get-pip.py ./pypy2/bin/pip install virtualenv ./pypy2/bin/python -V @@ -41,7 +41,7 @@ build_pypy2: build_pypy3: mkdir -p ./pypy3 tar xvf ./downloads/pypy3-v5.7.0-linux64.tar.bz2 --strip-components=1 -C ./pypy3 - cd ./pypy3/bin && ln -s pypy3 python && cd ../.. + #cd ./pypy3/bin && ln -s pypy3 python && cd ../.. ./pypy3/bin/python ./downloads/get-pip.py ./pypy3/bin/pip install virtualenv ./pypy3/bin/python -V @@ -72,6 +72,13 @@ build: build_wstest \ build_cpy3 +versions: + ./cpy2/bin/python -V + ./cpy3/bin/python -V + ./pypy2/bin/python -V + ./pypy3/bin/python -V + + setup_pypy2_tx: ./pypy2/bin/virtualenv ./venv_pypy2_tx ./venv_pypy2_tx/bin/pip install -e ..[twisted] @@ -154,3 +161,7 @@ test_aio_client: \ test_pypy3_aio_client \ test_cpy2_aio_client \ test_cpy3_aio_client + +test_client: \ + test_tx_client \ + test_aio_client diff --git a/wstest/README.md b/wstest/README.md new file mode 100644 index 00000000..4b42f7c9 --- /dev/null +++ b/wstest/README.md @@ -0,0 +1,29 @@ + + + +```console +make downloads +``` + +```console +make build +``` + +```console +oberstet@office-corei7:~/scm/crossbario/autobahn-python/wstest$ make versions +./cpy2/bin/python -V +Python 2.7.13 +./cpy3/bin/python -V +Python 3.6.0 +./pypy2/bin/python -V +Python 2.7.13 (fa3249d55d15, Mar 19 2017, 20:21:48) +[PyPy 5.7.0 with GCC 6.2.0 20160901] +./pypy3/bin/python -V +Python 3.5.3 (b16a4363e930, Mar 20 2017, 16:13:46) +[PyPy 5.7.0-beta0 with GCC 6.2.0 20160901] +``` + +```console +make setup +``` + diff --git a/wstest/testee_client_aio.py b/wstest/testee_client_aio.py index 764ca43f..55a676e0 100644 --- a/wstest/testee_client_aio.py +++ b/wstest/testee_client_aio.py @@ -24,6 +24,8 @@ # ############################################################################### +import argparse + import txaio txaio.use_asyncio() @@ -34,6 +36,8 @@ except ImportError: import autobahn +from autobahn.websocket.util import parse_url + from autobahn.asyncio.websocket import WebSocketClientProtocol, \ WebSocketClientFactory @@ -60,14 +64,17 @@ class TesteeClientProtocol(WebSocketClientProtocol): else: self.sendMessage(msg, binary) + def onClose(self, wasClean, code, reason): + txaio.resolve(self.factory._done, None) + class TesteeClientFactory(WebSocketClientFactory): protocol = TesteeClientProtocol - def __init__(self, url): - self.agent = autobahn.asyncio.__ident__ - WebSocketClientFactory.__init__(self, url, useragent=self.agent) + def __init__(self, url, agent): + self.agent = agent + WebSocketClientFactory.__init__(self, url, useragent=agent) self.setProtocolOptions(failByDrop=False) # spec conformance @@ -81,39 +88,42 @@ class TesteeClientFactory(WebSocketClientFactory): self.setProtocolOptions(perMessageCompressionAccept=accept) - # setup client testee stuff - self.endCaseId = None - self.currentCaseId = 0 - self.updateReports = True - self.resource = "/getCaseCount" - - # FIXME: port to asyncio - def clientConnectionLost(self, connector, reason): - self.currentCaseId += 1 - if self.currentCaseId <= self.endCaseId: - self.resource = "/runCase?case={}&agent={}".format(self.currentCaseId, self.agent) - connector.connect() - elif self.updateReports: - self.resource = "/updateReports?agent={}".format(self.agent) - self.updateReports = False - connector.connect() - else: - reactor.stop() - - # FIXME: port to asyncio - def clientConnectionFailed(self, connector, reason): - self.log.info("Connection to {url} failed: {error_message}", url=self.url, error_message=reason.getErrorMessage()) - reactor.stop() - if __name__ == '__main__': - txaio.start_logging(level='info') + parser = argparse.ArgumentParser(description='Autobahn Testee Client (Twisted)') + parser.add_argument('--url', dest='url', type=str, default=u'ws://127.0.0.1:9001', help='The WebSocket fuzzing server URL.') + parser.add_argument('--loglevel', dest='loglevel', type=str, default=u'info', help='Log level, eg "info" or "debug".') - factory = TesteeClientFactory(u"ws://127.0.0.1:9001") + options = parser.parse_args() + + txaio.start_logging(level=options.loglevel) + + factory = TesteeClientFactory(options.url, autobahn.asyncio.__ident__) + + _, host, port, _, _, _ = parse_url(options.url) loop = asyncio.get_event_loop() - coro = loop.create_connection(factory, '127.0.0.1', 9001) - loop.run_until_complete(coro) - loop.run_forever() + + factory.resource = u'/getCaseCount' + factory.endCaseId = None + factory.currentCaseId = 0 + factory.updateReports = True + + while True: + + factory._done = txaio.create_future() + coro = loop.create_connection(factory, host, port) + loop.run_until_complete(coro) + loop.run_until_complete(factory._done) + + factory.currentCaseId += 1 + if factory.currentCaseId <= factory.endCaseId: + factory.resource = u"/runCase?case={}&agent={}".format(factory.currentCaseId, factory.agent) + elif factory.updateReports: + factory.resource = u"/updateReports?agent={}".format(factory.agent) + factory.updateReports = False + else: + break + loop.close() diff --git a/wstest/testee_client_tx.py b/wstest/testee_client_tx.py index 698b11a6..fa28b135 100644 --- a/wstest/testee_client_tx.py +++ b/wstest/testee_client_tx.py @@ -24,6 +24,8 @@ # ############################################################################### +import argparse + import txaio txaio.use_twisted() @@ -103,9 +105,15 @@ class TesteeClientFactory(WebSocketClientFactory): if __name__ == '__main__': - txaio.start_logging(level='info') + parser = argparse.ArgumentParser(description='Autobahn Testee Client (Twisted)') + parser.add_argument('--url', dest='url', type=str, default=u'ws://127.0.0.1:9001', help='The WebSocket fuzzing server URL.') + parser.add_argument('--loglevel', dest='loglevel', type=str, default=u'info', help='Log level, eg "info" or "debug".') - factory = TesteeClientFactory(u"ws://127.0.0.1:9001") + options = parser.parse_args() + + txaio.start_logging(level=options.loglevel) + + factory = TesteeClientFactory(options.url) connectWS(factory) reactor.run()