/indra/newview/tests/test_llxmlrpc_peer.py
Python | 81 lines | 29 code | 8 blank | 44 comment | 1 complexity | 62ae78c760dd81fe0b4f9a9a800c0264 MD5 | raw file
Possible License(s): LGPL-2.1
1#!/usr/bin/env python 2"""\ 3@file test_llxmlrpc_peer.py 4@author Nat Goodspeed 5@date 2008-10-09 6@brief This script asynchronously runs the executable (with args) specified on 7 the command line, returning its result code. While that executable is 8 running, we provide dummy local services for use by C++ tests. 9 10$LicenseInfo:firstyear=2008&license=viewerlgpl$ 11Second Life Viewer Source Code 12Copyright (C) 2010, Linden Research, Inc. 13 14This library is free software; you can redistribute it and/or 15modify it under the terms of the GNU Lesser General Public 16License as published by the Free Software Foundation; 17version 2.1 of the License only. 18 19This library is distributed in the hope that it will be useful, 20but WITHOUT ANY WARRANTY; without even the implied warranty of 21MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22Lesser General Public License for more details. 23 24You should have received a copy of the GNU Lesser General Public 25License along with this library; if not, write to the Free Software 26Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 28Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA 29$/LicenseInfo$ 30""" 31 32import os 33import sys 34from threading import Thread 35from SimpleXMLRPCServer import SimpleXMLRPCServer 36 37mydir = os.path.dirname(__file__) # expected to be .../indra/newview/tests/ 38sys.path.insert(0, os.path.join(mydir, os.pardir, os.pardir, "lib", "python")) 39sys.path.insert(1, os.path.join(mydir, os.pardir, os.pardir, "llmessage", "tests")) 40from testrunner import freeport, run, debug 41 42class TestServer(SimpleXMLRPCServer): 43 def _dispatch(self, method, params): 44 try: 45 func = getattr(self, method) 46 except AttributeError: 47 raise Exception('method "%s" is not supported' % method) 48 else: 49 # LLXMLRPCListener constructs XMLRPC parameters that arrive as a 50 # 1-tuple containing a dict. 51 return func(**(params[0])) 52 53 def hello(self, who): 54 # LLXMLRPCListener expects a dict return. 55 return {"hi_there": "Hello, %s!" % who} 56 57 def getdict(self): 58 return dict(nested_dict=dict(a=17, b=5)) 59 60 def log_request(self, code, size=None): 61 # For present purposes, we don't want the request splattered onto 62 # stderr, as it would upset devs watching the test run 63 pass 64 65 def log_error(self, format, *args): 66 # Suppress error output as well 67 pass 68 69if __name__ == "__main__": 70 # Instantiate a TestServer on the first free port in the specified port 71 # range. Doing this inline is better than in a daemon thread: if it blows 72 # up here, we'll get a traceback. If it blew up in some other thread, the 73 # traceback would get eaten and we'd run the subject test program anyway. 74 xmlrpcd, port = freeport(xrange(8000, 8020), 75 lambda port: TestServer(('127.0.0.1', port))) 76 # Pass the selected port number to the subject test program via the 77 # environment. We don't want to impose requirements on the test program's 78 # command-line parsing -- and anyway, for C++ integration tests, that's 79 # performed in TUT code rather than our own. 80 os.environ["PORT"] = str(port) 81 sys.exit(run(server=Thread(name="xmlrpc", target=xmlrpcd.serve_forever), *sys.argv[1:]))