diff options
author | Jose <jose@zeroc.com> | 2015-01-22 19:16:43 +0100 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2015-01-22 19:16:43 +0100 |
commit | f623cdba8d3dcf801b1483e15b5f0cb19ac77b4a (patch) | |
tree | 6cf5de43bbad54c89ed9fe232180062d48dba5d2 | |
parent | ICE-6279 OBjC: use servant factory methods (diff) | |
download | ice-f623cdba8d3dcf801b1483e15b5f0cb19ac77b4a.tar.bz2 ice-f623cdba8d3dcf801b1483e15b5f0cb19ac77b4a.tar.xz ice-f623cdba8d3dcf801b1483e15b5f0cb19ac77b4a.zip |
Port test controller server to Java
-rwxr-xr-x | cpp/test/Ice/echo/run.py | 2 | ||||
-rwxr-xr-x | cs/test/Ice/echo/run.py | 1 | ||||
-rw-r--r-- | java/settings.gradle | 2 | ||||
-rw-r--r-- | java/test/controller/build.gradle | 34 | ||||
-rw-r--r-- | java/test/controller/src/main/java/test/common/ControllerServer.java | 260 | ||||
-rw-r--r-- | java/test/controller/src/main/slice/Controller.ice | 33 | ||||
-rwxr-xr-x | java/test/src/main/java/test/Ice/echo/run.py | 1 | ||||
-rw-r--r-- | js/gulpfile.js | 15 | ||||
-rw-r--r-- | js/test/Common/Controller.ice | 13 | ||||
-rw-r--r-- | js/test/Common/TestSuite.js | 64 | ||||
-rw-r--r-- | js/test/Common/index.html | 239 | ||||
-rwxr-xr-x | js/test/Common/run.py | 216 | ||||
-rw-r--r-- | js/test/Ice/exceptionsBidir/Client.js | 2 | ||||
-rw-r--r-- | scripts/TestController.py | 83 | ||||
-rwxr-xr-x | scripts/TestUtil.py | 5 |
15 files changed, 701 insertions, 269 deletions
diff --git a/cpp/test/Ice/echo/run.py b/cpp/test/Ice/echo/run.py index 53567790d8e..06935984836 100755 --- a/cpp/test/Ice/echo/run.py +++ b/cpp/test/Ice/echo/run.py @@ -25,5 +25,5 @@ sys.stdout.flush() server = server = os.path.join(os.getcwd(), "server") p = TestUtil.startServer(server) print("ok") - +sys.stdout.flush() p.waitTestSuccess() diff --git a/cs/test/Ice/echo/run.py b/cs/test/Ice/echo/run.py index 0c8ce28f36f..fb06954a948 100755 --- a/cs/test/Ice/echo/run.py +++ b/cs/test/Ice/echo/run.py @@ -25,5 +25,6 @@ sys.stdout.flush() server = os.path.join(os.getcwd(), "server") p = TestUtil.startServer(server) print("ok") +sys.stdout.flush() p.waitTestSuccess() diff --git a/java/settings.gradle b/java/settings.gradle index 3726ae98899..61fd93e42d0 100644 --- a/java/settings.gradle +++ b/java/settings.gradle @@ -35,6 +35,8 @@ project(':ant-ice').projectDir = new File('src/ant-ice') include ':test' include ':testPlugins' project(':testPlugins').projectDir = new File('test/plugins') +include ':testController' +project(':testController').projectDir = new File('test/controller') // Map of dir->subdir for each of the demos. def demos = [ diff --git a/java/test/controller/build.gradle b/java/test/controller/build.gradle new file mode 100644 index 00000000000..1c292d9031a --- /dev/null +++ b/java/test/controller/build.gradle @@ -0,0 +1,34 @@ +// ********************************************************************** +// +// 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. +// +// ********************************************************************** + +sourceCompatibility = iceSourceCompatibility +targetCompatibility = iceTargetCompatibility + + + +dependencies { + compile project(':ice') +} + +apply plugin: 'slice' + +// Force the default source set. +slice +{ + java{ + args = "" + } +} + +jar { + manifest { + attributes("Main-Class": "test.common.ControllerServer") + attributes("Class-Path": configurations.runtime.resolve().collect { it.toURI() }.join(' ')) + } +}
\ No newline at end of file diff --git a/java/test/controller/src/main/java/test/common/ControllerServer.java b/java/test/controller/src/main/java/test/common/ControllerServer.java new file mode 100644 index 00000000000..11ca470af65 --- /dev/null +++ b/java/test/controller/src/main/java/test/common/ControllerServer.java @@ -0,0 +1,260 @@ +// ********************************************************************** +// +// 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. +// +// ********************************************************************** + +package test.common; + +import test.common._ControllerDisp; +import test.common._ServerDisp; +import test.common.ServerPrx; + +import java.io.File; +import java.io.BufferedReader; +import java.io.InputStreamReader; + +import java.util.regex.Pattern; + +public class ControllerServer extends Ice.Application +{ + class ServerI extends _ServerDisp + { + public ServerI(Process process, String name) + { + _process = process; + _name = name; + _started = 0; + + class Reader extends Thread + { + Reader(java.io.InputStream is) + { + _is = is; + } + + public void run() + { + try + { + final BufferedReader reader = new BufferedReader(new InputStreamReader(_is)); + + String line = null; + while((line = reader.readLine()) != null) + { + if(line.matches(Pattern.quote("starting server... ok")) || + line.matches(Pattern.quote("starting serveramd... ok")) || + line.matches("starting test.*" + Pattern.quote("Server... ok"))) + { + synchronized(ServerI.this) + { + _started++; + ServerI.this.notifyAll(); + } + } + System.out.println(line); + } + } + catch(java.io.IOException ex) + { + } + } + + private java.io.InputStream _is; + } + new Reader(_process.getInputStream()).start(); + } + + public synchronized void terminate(Ice.Current current) + { + try + { + _process.exitValue(); + return; + } + catch(IllegalThreadStateException ex) + { + // + // process is still running. + // + System.out.print("terminating " + _name + "... "); + System.out.flush(); + _process.destroy(); + + current.adapter.remove(current.id); + System.out.println("ok"); + } + } + + public void waitTestSuccess(Ice.Current current) + { + Process p = null; + synchronized(this) + { + p = _process; + } + if(p != null) + { + while(true) + { + try + { + p.waitFor(); + break; + } + catch(InterruptedException ex) + { + } + } + } + } + + public synchronized void waitForServer(Ice.Current current) + { + while(true) + { + try + { + if(_started > 0) + { + _started--; + break; + } + wait(); + } + catch(InterruptedException ex) + { + continue; + } + } + } + + private Process _process; + private String _name; + private int _started; + } + + public class ControllerI extends _ControllerDisp + { + @Override + public ServerPrx runServer(String lang, final String name, String protocol, String host, + boolean winrt, String[] options, Ice.Current current) + { + if(_server != null) + { + try + { + _server.terminate(); + } + catch(Ice.LocalException ex) + { + } + } + + String script = name.equals("Ice/echo") ? + (lang.equals("java") ? "java/test/src/main/java/" : "cpp/") + "test/Ice/echo/run.py" : + "allTests.py"; + + java.util.List<String> args = new java.util.ArrayList<String>(); + args.add("python"); + args.add(script); + args.add("--server"); + if(!name.equals("Ice/echo")) + { + args.add("--filter"); + args.add("^" + lang + "/test/" + name + "$"); + } + args.add("--protocol"); + args.add(protocol); + args.add("--host"); + args.add(host); + + if(winrt) + { + args.add("--winrt"); + } + + for(String option : options) + { + args.add("--arg"); + args.add(option); + } + + try + { + System.out.print("starting " + name + "... "); + System.out.flush(); + + final Process process = new ProcessBuilder(args) + .directory(_toplevel) + .redirectErrorStream(true) + .start(); + _server = ServerPrxHelper.uncheckedCast(current.adapter.addWithUUID(new ServerI(process, name))); + } + catch(java.io.IOException ex) + { + throw new RuntimeException("failed to start server `" + name + "'", ex); + } + return _server; + } + + private ServerPrx _server; + } + + @Override + public int + run(String[] args) + { + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("ControllerAdapter"); + adapter.add(new ControllerI(), communicator().stringToIdentity("controller")); + adapter.activate(); + communicator().waitForShutdown(); + return 0; + } + + public ControllerServer(File toplevel) + { + _toplevel = toplevel; + } + + public static void + main(String[] args) + { + try + { + File toplevel = new File( + new File(ControllerServer.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParent(), + "../../../../../"); + + ControllerServer app = new ControllerServer(toplevel); + + Ice.InitializationData initData = new Ice.InitializationData(); + initData.properties = Ice.Util.createProperties(args); + initData.properties.setProperty("Ice.Plugin.IceSSL", "IceSSL.PluginFactory"); + initData.properties.setProperty("IceSSL.DefaultDir", new File(toplevel, "certs").getCanonicalPath()); + initData.properties.setProperty("IceSSL.Keystore", "server.jks"); + initData.properties.setProperty("IceSSL.Password", "password"); + initData.properties.setProperty("IceSSL.VerifyPeer", "0"); + initData.properties.setProperty("Ice.ThreadPool.Server.SizeMax", "10"); + initData.properties.setProperty("ControllerAdapter.Endpoints", "ws -p 12009:wss -p 12008"); + + int status = app.main("ControllerServer", args, initData); + System.exit(status); + } + catch(java.net.URISyntaxException ex) + { + ex.printStackTrace(); + System.exit(1); + } + catch(java.io.IOException ex) + { + ex.printStackTrace(); + System.exit(1); + } + } + + private final File _toplevel; +} diff --git a/java/test/controller/src/main/slice/Controller.ice b/java/test/controller/src/main/slice/Controller.ice new file mode 100644 index 00000000000..5f89858a42d --- /dev/null +++ b/java/test/controller/src/main/slice/Controller.ice @@ -0,0 +1,33 @@ +// ********************************************************************** +// +// 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. +// +// ********************************************************************** + +module test +{ + +module common +{ + +interface Server +{ + void waitTestSuccess(); + void waitForServer(); + void terminate(); +}; + +sequence<string> StringSeq; + +interface Controller +{ + Server* runServer(string lang, string name, string protocol, string host, bool winrt, + StringSeq options); +}; + +}; + +}; diff --git a/java/test/src/main/java/test/Ice/echo/run.py b/java/test/src/main/java/test/Ice/echo/run.py index c7b4a614be1..da4269741aa 100755 --- a/java/test/src/main/java/test/Ice/echo/run.py +++ b/java/test/src/main/java/test/Ice/echo/run.py @@ -25,5 +25,6 @@ sys.stdout.write("starting server... ") sys.stdout.flush() p = TestUtil.startServer("test.Ice.echo.Server") print("ok") +sys.stdout.flush() p.waitTestSuccess() diff --git a/js/gulpfile.js b/js/gulpfile.js index dac9c6b6f7f..1e06d135585 100644 --- a/js/gulpfile.js +++ b/js/gulpfile.js @@ -225,6 +225,12 @@ gulp.task("common:slice", [], .pipe(gulp.dest("test/Common")); }); +gulp.task("common:slice:clean", [], + function() + { + del(["test/Common/Controller.js"]); + }); + gulp.task("common:slice:watch", ["common:slice"], function() { @@ -404,7 +410,8 @@ Object.keys(subprojects).forEach( ["common:css:watch", "common:js:watch"].concat(Object.keys(minDemos).map(minDemoWatchTaskName)))); gulp.task(group + ":clean", subprojects[group].map(groupCleanTask).concat( - group == "test" ? subprojects.test.map(testHtmlCleanTask) : ["demo_Ice_minimal:min:clean", "demo_ChatDemo:min:clean"])); + group == "test" ? subprojects.test.map(testHtmlCleanTask).concat(["common:slice:clean"]) : + ["demo_Ice_minimal:min:clean", "demo_ChatDemo:min:clean"])); }); function demoTaskName(name) { return "demo_" + name.replace("/", "_"); } @@ -460,8 +467,8 @@ gulp.task("test:run-with-browser", ["watch"].concat(useBinDist ? ["test", "demo" browserSync(); HttpServer(); - var p = require("child_process").spawn("python", ["test/Common/run.py"], {stdio: "inherit"}); - function exit() { p.exit(); } + var p = require("child_process").spawn("python", ["../scripts/TestController.py"], {stdio: "inherit"}); + function exit() { p.kill(); } process.on("SIGINT", exit); process.on("exit", exit); return gulp.src("./index.html").pipe(open("", {url: "http://127.0.0.1:8080/index.html"})); @@ -471,7 +478,7 @@ gulp.task("test:run-with-node", (useBinDist ? ["test"] : ["build"]), function() { var p = require("child_process").spawn("python", ["allTests.py", "--all"], {stdio: "inherit"}); - function exit() { p.exit(); } + function exit() { p.kill(); } process.on("SIGINT", exit); process.on("exit", exit); }); diff --git a/js/test/Common/Controller.ice b/js/test/Common/Controller.ice index 3925fcbdcf8..5f89858a42d 100644 --- a/js/test/Common/Controller.ice +++ b/js/test/Common/Controller.ice @@ -7,18 +7,27 @@ // // ********************************************************************** -module Test +module test +{ + +module common { interface Server { void waitTestSuccess(); + void waitForServer(); void terminate(); }; +sequence<string> StringSeq; + interface Controller { - Server* runServer(string lang, string name, string protocol, string host, string options); + Server* runServer(string lang, string name, string protocol, string host, bool winrt, + StringSeq options); +}; + }; }; diff --git a/js/test/Common/TestSuite.js b/js/test/Common/TestSuite.js index 0ebc24c0082..78c533d38cd 100644 --- a/js/test/Common/TestSuite.js +++ b/js/test/Common/TestSuite.js @@ -73,24 +73,20 @@ $(document).ready( { str = "controller:wss -h " + defaultHost + " -p 12008"; } - var controller = Test.ControllerPrx.uncheckedCast(communicator.stringToProxy(str)); + var controller = test.common.ControllerPrx.uncheckedCast(communicator.stringToProxy(str)); var p; var server; - var options = ""; + var options = []; if(typeof(__runServer__) !== "undefined" || typeof(__runEchoServer__) !== "undefined") { var srv; if(typeof(__runEchoServer__) !== "undefined") { srv = "Ice/echo"; - if(typeof(__runEchoServerOptions__) !== "undefined") + if(typeof(__runEchoServerOptions__) === "Array") { - options = __runEchoServerOptions__ || ""; - } - else - { - options = ""; + options = options.concat(__runEchoServerOptions__); } } @@ -99,19 +95,56 @@ $(document).ready( srv = current; } out.write("starting " + srv + " server... "); - p = controller.runServer(language, srv, protocol, defaultHost, options).then( + p = controller.runServer(language, srv, protocol, defaultHost, false, options).then( function(proxy) { - var ref = proxy.ice_getIdentity().name + ":" + protocol + " -h " + defaultHost + - " -p " + (protocol == "ws" ? "12009" : "12008"); + var ref = proxy.ice_getIdentity().name + ":" + protocol + " -h " + defaultHost + " -p " + + (protocol == "ws" ? "12009" : "12008"); out.writeLine("ok"); - server = Test.ServerPrx.uncheckedCast(communicator.stringToProxy(ref)); - return __test__(out, id); + server = test.common.ServerPrx.uncheckedCast(communicator.stringToProxy(ref)); + + var testCase = TestCases[current]; + if(testCase.configurations === undefined) + { + return server.waitForServer().then( + function() + { + return __test__(out, id); + }); + } + else + { + var prev = new Ice.Promise().succeed(); + testCase.configurations.forEach( + function(configuration) + { + if(configuration.langs && configuration.langs.indexOf(language) == -1) + { + return prev; + } + prev = prev.then( + function() + { + out.writeLine("Running test with " + configuration.name + "."); + return server.waitForServer().then( + function() + { + var initData = id.clone(); + if(configuration.args !== undefined) + { + initData.properties = Ice.createProperties(configuration.args, id.properties); + } + return __test__(out, initData); + }); + }); + }); + return prev; + } }, function(ex) { out.writeLine("failed! (" + ex + ")"); - return __test__(out, id); + throw ex; } ).then( function() @@ -140,8 +173,7 @@ $(document).ready( { throw ex; } - } - ); + }); } else { diff --git a/js/test/Common/index.html b/js/test/Common/index.html index d3ed34c615d..cad0af89f46 100644 --- a/js/test/Common/index.html +++ b/js/test/Common/index.html @@ -111,34 +111,215 @@ <script type="text/javascript"> /* jshint browser:true, jquery:true */ var TestCases = { - "Ice/acm": ["Test.js", "Client.js"], - "Ice/ami": ["Test.js", "Client.js"], - "Ice/binding": ["Test.js", "Client.js"], - "Ice/defaultValue": ["Test.js", "Client.js"], - "Ice/enums": ["Test.js", "Client.js"], - "Ice/exceptions": ["Test.js", "Client.js"], - "Ice/exceptionsBidir": ["Test.js", "TestAMD.js", "ThrowerI.js", "AMDThrowerI.js", - "../exceptions/Client.js", "Client.js"], - "Ice/facets": ["Test.js", "Client.js"], - "Ice/facetsBidir": ["Test.js", "TestI.js", "../facets/Client.js", "Client.js"], - "Ice/hold": ["Test.js", "Client.js"], - "Ice/inheritance": ["Test.js", "Client.js"], - "Ice/inheritanceBidir": ["Test.js", "InitialI.js", "../inheritance/Client.js", "Client.js"], - "Ice/operations": ["Test.js", "Twoways.js", "Oneways.js", "BatchOneways.js", "Client.js"], - "Ice/operationsBidir": ["Test.js", "TestAMD.js", "../operations/Twoways.js", "../operations/Oneways.js", - "../operations/BatchOneways.js", "MyDerivedClassI.js", "AMDMyDerivedClassI.js", - "../operations/Client.js", "Client.js"], - "Ice/objects": ["Test.js", "Client.js"], - "Ice/optional": ["Test.js", "Client.js"], - "Ice/optionalBidir": ["Test.js", "TestAMD.js", "InitialI.js", "AMDInitialI.js", - "../optional/Client.js", "Client.js"], - "Ice/promise": ["Client.js"], - "Ice/properties": ["Client.js"], - "Ice/proxy": ["Test.js", "Client.js"], - "Ice/retry": ["Test.js", "Client.js"], - "Ice/slicing/exceptions": ["Test.js", "Client.js"], - "Ice/slicing/objects": ["Test.js", "Client.js"], - "Ice/timeout": ["Test.js", "Client.js"] + "Ice/acm": + { + files: ["Test.js", "Client.js"] + }, + "Ice/ami": + { + files: ["Test.js", "Client.js"] + }, + "Ice/binding": + { + files: ["Test.js", "Client.js"] + }, + "Ice/defaultValue": + { + files: ["Test.js", "Client.js"] + }, + "Ice/enums": + { + files: ["Test.js", "Client.js"], + configurations: + [ + { + name: "1.0 encoding", args: ["--Ice.Default.EncodingVersion=1.0"] + }, + { + name: "1.1 encoding" + }, + ] + }, + "Ice/exceptions": + { + files: ["Test.js", "Client.js"], + configurations: + [ + { + name: "compact (default) format" + }, + { + name: "sliced format", args: ["--Ice.Default.SlicedFormat"] + }, + { + name: "1.0 encoding", args: ["--Ice.Default.EncodingVersion=1.0"] + }, + { + name: "compact (default) format and AMD server" + }, + { + name: "sliced format and AMD server.", args: ["--Ice.Default.SlicedFormat"] + }, + { + name: "1.0 encoding and AMD server", args: ["--Ice.Default.EncodingVersion=1.0"] + } + ] + }, + "Ice/exceptionsBidir": + { + files: ["Test.js", "TestAMD.js", "ThrowerI.js", "AMDThrowerI.js", + "../exceptions/Client.js", "Client.js"], + }, + "Ice/facets": + { + files: ["Test.js", "Client.js"] + }, + "Ice/facetsBidir": + { + files: ["Test.js", "TestI.js", "../facets/Client.js", "Client.js"] + }, + "Ice/hold": + { + files: ["Test.js", "Client.js"] + }, + "Ice/inheritance": + { + files: ["Test.js", "Client.js"] + }, + "Ice/inheritanceBidir": + { + files: ["Test.js", "InitialI.js", "../inheritance/Client.js", "Client.js"], + }, + "Ice/operations": + { + files: ["Test.js", "Twoways.js", "Oneways.js", "BatchOneways.js", "Client.js"], + configurations: + [ + { + name: "regular server" + }, + { + name: "AMD server" + }, + { + name: "TIE server", langs: ["java", "C#"] + }, + { + name: "AMD TIE server", langs: ["java", "C#"] + } + ] + }, + "Ice/operationsBidir": + { + files: ["Test.js", "TestAMD.js", "../operations/Twoways.js", "../operations/Oneways.js", + "../operations/BatchOneways.js", "MyDerivedClassI.js", "AMDMyDerivedClassI.js", + "../operations/Client.js", "Client.js"] + }, + "Ice/objects": + { + files: ["Test.js", "Client.js"], + configurations: + [ + { + name: "compact (default) format" + }, + { + name: "sliced format", args: ["--Ice.Default.SlicedFormat"] + }, + { + name: "1.0 encoding", args: ["--Ice.Default.EncodingVersion=1.0"] + } + ] + }, + "Ice/optional": + { + files: ["Test.js", "Client.js"], + configurations: + [ + { + name: "compact (default) format" + }, + { + name: "sliced format", args: ["--Ice.Default.SlicedFormat"] + }, + { + name: "AMD server" + } + ] + }, + "Ice/optionalBidir": + { + files: ["Test.js", "TestAMD.js", "InitialI.js", "AMDInitialI.js", "../optional/Client.js", + "Client.js"] + }, + "Ice/promise": + { + files: ["Client.js"] + }, + "Ice/properties": + { + files: ["Client.js"] + }, + "Ice/proxy": + { + files: ["Test.js", "Client.js"], + configurations: + [ + { + name: "regular server" + }, + { + name: "AMD server" + } + ] + + }, + "Ice/retry": + { + files: ["Test.js", "Client.js"] + }, + "Ice/slicing/exceptions": + { + files: ["Test.js", "Client.js"], + configurations: + [ + { + name: "sliced format" + }, + { + name: "1.0 encoding", args: ["--Ice.Default.EncodingVersion=1.0"] + }, + { + name: "sliced format and AMD server" + }, + { + name: "1.0 encoding and AMD server", args: ["--Ice.Default.EncodingVersion=1.0"] + } + ] + }, + "Ice/slicing/objects": + { + files: ["Test.js", "Client.js"], + configurations: + [ + { + name: "sliced format" + }, + { + name: "1.0 encoding", args: ["--Ice.Default.EncodingVersion=1.0"] + }, + { + name: "sliced format and AMD server" + }, + { + name: "1.0 encoding and AMD server", args: ["--Ice.Default.EncodingVersion=1.0"] + } + ] + }, + "Ice/timeout": + { + files: ["Test.js", "Client.js"] + } }; var current, next; @@ -167,7 +348,7 @@ basePath + "../lib/Ice.js" ]; - TestCases[current].forEach( + TestCases[current].files.forEach( function(script) { scripts.push(script); 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)) diff --git a/js/test/Ice/exceptionsBidir/Client.js b/js/test/Ice/exceptionsBidir/Client.js index cce9746bc73..61a4a319054 100644 --- a/js/test/Ice/exceptionsBidir/Client.js +++ b/js/test/Ice/exceptionsBidir/Client.js @@ -98,7 +98,7 @@ }; exports.__test__ = run; exports.__runEchoServer__ = true; - exports.__runEchoServerOptions__ = "--Ice.Warn.Dispatch=0 --Ice.Warn.Connections=0"; + exports.__runEchoServerOptions__ = ["--Ice.Warn.Dispatch=0", "--Ice.Warn.Connections=0"]; } (typeof(global) !== "undefined" && typeof(global.process) !== "undefined" ? module : undefined, typeof(global) !== "undefined" && typeof(global.process) !== "undefined" ? require : window.Ice.__require, diff --git a/scripts/TestController.py b/scripts/TestController.py new file mode 100644 index 00000000000..cb227108f99 --- /dev/null +++ b/scripts/TestController.py @@ -0,0 +1,83 @@ +#!/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, signal + +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")) +import TestUtil + +# +# On OS X, provide an option to allow removing the trust settings +# +if TestUtil.isDarwin(): + 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 + +version = "3.6b" +jar = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", + "java/test/controller/build/libs/testController-%(version)s.jar" % {"version": version}) +command = ("java -jar %(jar)s" % {"jar":jar}) + +p = subprocess.Popen(command, shell = True, stdin = subprocess.PIPE, stdout = subprocess.PIPE, + stderr = subprocess.STDOUT, bufsize = 0) + +def signal_handler(signal, frame): + if p: + p.terminate() +signal.signal(signal.SIGINT, signal_handler) + +while(True): + + c = p.stdout.read(1) + if not c: break + if c == '\r': continue + + # Depending on Python version and platform, the value c could be a + # string or a bytes object. + if type(c) != str: + c = c.decode() + sys.stdout.write(c) + sys.stdout.flush() + +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") diff --git a/scripts/TestUtil.py b/scripts/TestUtil.py index 9c67a18d863..883a7623e89 100755 --- a/scripts/TestUtil.py +++ b/scripts/TestUtil.py @@ -1458,6 +1458,7 @@ def clientServerTest(additionalServerOptions = "", additionalClientOptions = "", server = getCommandLine(server, serverCfg, additionalServerOptions) serverProc = spawnServer(server, env = serverenv, lang=serverCfg.lang, mx=serverCfg.mx) print("ok") + sys.stdout.flush() if not serverOnly: if clientLang == lang: @@ -1479,6 +1480,9 @@ def clientServerTest(additionalServerOptions = "", additionalClientOptions = "", appVerifierAfterTestEnd([clientExe, serverExe]) def collocatedTest(additionalOptions = ""): + if serverOnly: + print("** skipping collocated test") + return lang = getDefaultMapping() if len(cross) > 0 and cross[0] != lang: print("** skipping cross test") @@ -1589,6 +1593,7 @@ def clientEchoTest(additionalServerOptions = "", additionalClientOptions = "", server = getCommandLine(server, serverCfg, additionalServerOptions) serverProc = spawnServer(server, env = serverenv, lang=serverCfg.lang, mx=serverCfg.mx) print("ok") + sys.stdout.flush() if not serverOnly: if clientLang == lang: |