summaryrefslogtreecommitdiff
path: root/js/test/Common/run.py
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2015-01-22 19:16:43 +0100
committerJose <jose@zeroc.com>2015-01-22 19:16:43 +0100
commitf623cdba8d3dcf801b1483e15b5f0cb19ac77b4a (patch)
tree6cf5de43bbad54c89ed9fe232180062d48dba5d2 /js/test/Common/run.py
parentICE-6279 OBjC: use servant factory methods (diff)
downloadice-f623cdba8d3dcf801b1483e15b5f0cb19ac77b4a.tar.bz2
ice-f623cdba8d3dcf801b1483e15b5f0cb19ac77b4a.tar.xz
ice-f623cdba8d3dcf801b1483e15b5f0cb19ac77b4a.zip
Port test controller server to Java
Diffstat (limited to 'js/test/Common/run.py')
-rwxr-xr-xjs/test/Common/run.py216
1 files changed, 0 insertions, 216 deletions
diff --git a/js/test/Common/run.py b/js/test/Common/run.py
deleted file mode 100755
index 686edf1f669..00000000000
--- a/js/test/Common/run.py
+++ /dev/null
@@ -1,216 +0,0 @@
-#!/usr/bin/env python
-# **********************************************************************
-#
-# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved.
-#
-# This copy of Ice is licensed to you under the terms described in the
-# ICE_LICENSE file included in this distribution.
-#
-# **********************************************************************
-
-import os, sys, threading, subprocess, getopt
-
-path = [ ".", "..", "../..", "../../..", "../../../.." ]
-head = os.path.dirname(sys.argv[0])
-if len(head) > 0:
- path = [os.path.join(head, p) for p in path]
-path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ]
-if len(path) == 0:
- raise RuntimeError("can't find toplevel directory!")
-sys.path.append(os.path.join(path[0], "scripts"))
-
-#
-# On OS X, provide an option to allow removing the trust settings
-#
-if sys.platform == "darwin":
- try:
- opts, args = getopt.getopt(sys.argv[1:], "", ["clean"])
- if ("--clean", "") in opts:
- serverCert = os.path.join(path[0], "certs", "s_rsa1024_pub.pem")
- if os.system("security verify-cert -c " + serverCert + " >& /dev/null") == 0:
- sys.stdout.write("removing trust settings for the HTTP server certificate... ")
- sys.stdout.flush()
- if os.system("security remove-trusted-cert " + serverCert) != 0:
- print("error: couldn't remove trust settings for the HTTP server certificate")
- print("ok")
- else:
- print("trust settings already removed")
- sys.exit(0)
- except getopt.GetoptError:
- pass
-
-#
-# Run the script with the environment correctly set.
-#
-if os.environ.get("RUNNING_TEST_CONTROLLER_WITH_ENV", "") == "":
- os.environ["TESTCONTROLLER"] = "yes" # Trick to prevent TestUtil.py from printing out diagnostic information
- import TestUtil
- del os.environ["TESTCONTROLLER"]
-
- #
- # Get environment to run Ice for Python script
- #
- env = TestUtil.getTestEnv("py", os.getcwd())
- env["RUNNING_TEST_CONTROLLER_WITH_ENV"] = "yes"
- try:
-
- #
- # The HttpServer relies on the ICE_HOME environment variable
- # to find the Ice for JavaScript installation so we make sure
- # here that ICE_HOME is set if we are running against a binary
- # distribution (i.e.: TestUtil.iceHome is not None)
- #
- if TestUtil.iceHome:
- env["ICE_HOME"] = TestUtil.iceHome
-
- if TestUtil.printenv:
- TestUtil.dumpenv(env, "py")
- args = [sys.executable, "run.py"]
- for a in sys.argv[1:]:
- args.append(a)
- sys.exit(os.spawnve(os.P_WAIT, sys.executable, args, env))
- except KeyboardInterrupt:
- sys.exit(0)
- finally:
- if sys.platform == "darwin":
- print("")
- print("To remove the certificate trust settings, run: `" + sys.argv[0] + " --clean'")
- sys.exit(1)
-
-import TestUtil, Ice, Expect
-Ice.loadSlice("\"" + os.path.join(TestUtil.toplevel, "js", "test", "Common", "Controller.ice") + "\"")
-import Test
-
-class ServerI(Test.Server):
- def __init__(self, name, process):
- self.name = name
- self.process = process
-
- def waitTestSuccess(self, current):
- if not self.process:
- return
- sys.stdout.write("waiting for " + self.name + " to terminate... ")
- sys.stdout.flush()
- self.process.waitTestSuccess()
- self.process = None
- try:
- current.adapter.remove(current.id)
- except:
- pass
- # Stop the WatchDog thread since we may not run any more tests
- # for an extended period of time
- TestUtil.stopWatchDog()
- print("ok")
-
- def terminate(self, current):
- if not self.process:
- return
- sys.stdout.write("terminating " + self.name + "... ")
- sys.stdout.flush()
- self.process.terminate()
- self.process = None
- try:
- current.adapter.remove(current.id)
- except:
- pass
- # Stop the WatchDog thread since we may not run any more tests
- # for an extended period of time
- TestUtil.stopWatchDog()
- print("ok")
-
-class ControllerI(Test.Controller):
- def __init__(self):
- self.currentServer = None
-
- def runServer(self, lang, name, protocol, host, options, current):
- # If server is still running, terminate it
- if self.currentServer:
- try:
- self.currentServer.terminate()
- except:
- pass
- self.currentServer = None
-
- pwd = os.getcwd()
- try:
- # Change current directory to the test directory
- testDir = 'test' if lang != 'java' else 'test/src/main/java/test'
- serverdir = os.path.join(TestUtil.toplevel, lang, testDir, name)
- os.chdir(serverdir)
- serverDesc = os.path.join(lang, 'test', name)
- lang = TestUtil.getDefaultMapping()
- server = TestUtil.getDefaultServerFile()
- if lang != "java":
- server = os.path.join(serverdir, server)
- serverenv = TestUtil.getTestEnv(lang, serverdir)
-
- sys.stdout.write("starting " + serverDesc + "... ")
- sys.stdout.flush()
- serverCfg = TestUtil.DriverConfig("server")
- serverCfg.protocol = protocol
- serverCfg.host = host
- server = TestUtil.getCommandLine(server, serverCfg, options)
- serverProc = TestUtil.spawnServer(server, env = serverenv, lang=serverCfg.lang, mx=serverCfg.mx)
- print("ok")
- finally:
- os.chdir(pwd)
-
- self.currentServer = Test.ServerPrx.uncheckedCast(current.adapter.addWithUUID(ServerI(serverDesc, serverProc)))
- return self.currentServer
-
-class Reader(threading.Thread):
- def __init__(self, p):
- self.p = p
- threading.Thread.__init__(self)
-
- def run(self):
- while True:
- line = self.p.stdout.readline()
- if self.p.poll() is not None and not line:
- #process terminated
- return self.p.poll()
- if type(line) != str:
- line = line.decode()
- sys.stdout.write(line)
- sys.stdout.flush()
-
-class Server(Ice.Application):
- def run(self, args):
- adapter = self.communicator().createObjectAdapter("ControllerAdapter")
- adapter.add(ControllerI(), self.communicator().stringToIdentity("controller"))
- adapter.activate()
- self.communicator().waitForShutdown()
- return 0
-
-app = Server()
-initData = Ice.InitializationData()
-initData.properties = Ice.createProperties();
-initData.properties.setProperty("Ice.Plugin.IceSSL", "IceSSL:createIceSSL")
-initData.properties.setProperty("IceSSL.DefaultDir", os.path.join(TestUtil.toplevel, "certs"))
-initData.properties.setProperty("IceSSL.CertAuthFile", "cacert.pem")
-initData.properties.setProperty("IceSSL.CertFile", "s_rsa1024_pub.pem")
-initData.properties.setProperty("IceSSL.KeyFile", "s_rsa1024_priv.pem")
-initData.properties.setProperty("IceSSL.Keychain", "test.keychain")
-initData.properties.setProperty("IceSSL.KeychainPassword", "password")
-initData.properties.setProperty("IceSSL.VerifyPeer", "0");
-initData.properties.setProperty("Ice.ThreadPool.Server.SizeMax", "10")
-#initData.properties.setProperty("Ice.Trace.Network", "3")
-#initData.properties.setProperty("Ice.Trace.Protocol", "1")
-initData.properties.setProperty("ControllerAdapter.Endpoints", "ws -p 12009:wss -p 12008")
-
-if TestUtil.isDarwin():
- #
- # On OS X, we set the trust settings on the certificate to prevent
- # the Web browsers from prompting the user about the unstrusted
- # certificate. Some browsers such as Chrome don't provide the
- # option to set this trust settings.
- #
- serverCert = os.path.join(TestUtil.toplevel, "certs", "s_rsa1024_pub.pem")
- if os.system("security verify-cert -c " + serverCert + " >& /dev/null") != 0:
- sys.stdout.write("adding trust settings for the HTTP server certificate... ")
- sys.stdout.flush()
- if os.system("security add-trusted-cert -r trustAsRoot " + serverCert) != 0:
- print("error: couldn't add trust settings for the HTTP server certificate")
- print("ok")
-
-sys.exit(app.main(sys.argv, initData=initData))