Commit 1e40ca03 authored by legoc's avatar legoc

Cleaned tests

parent 94bb3188
......@@ -95,77 +95,22 @@ target_link_libraries(publisherloop PUBLIC cameo zmq)
add_executable(testcancel src/tests/TestCancel.cpp)
target_link_libraries(testcancel PUBLIC cameo zmq pthread)
add_executable(openport src/tests/OpenPort.cpp)
target_link_libraries(openport PUBLIC cameo zmq)
add_executable(testcameo src/tests/Test.cpp)
target_link_libraries(testcameo PUBLIC cameo zmq)
add_executable(testbadendpoint src/tests/TestBadEndpoint.cpp)
target_link_libraries(testbadendpoint PUBLIC cameo zmq)
add_executable(teststate src/tests/TestStateApplication.cpp)
target_link_libraries(teststate PUBLIC cameo zmq)
add_executable(testpublishertwo src/tests/TestPublisherTwoApplication.cpp)
target_link_libraries(testpublishertwo PUBLIC cameo zmq)
add_executable(testsubscriberandpublishertwo src/tests/TestSubscriberAndPublisherTwoApplication.cpp)
target_link_libraries(testsubscriberandpublishertwo PUBLIC cameo zmq)
add_executable(comport src/tests/ComPort.cpp)
target_link_libraries(comport PUBLIC cameo zmq)
add_executable(testcomport src/tests/TestComPort.cpp)
target_link_libraries(testcomport PUBLIC cameo zmq)
add_executable(stream src/tests/Stream.cpp)
target_link_libraries(stream PUBLIC cameo zmq)
add_executable(teststream src/tests/TestStream.cpp)
target_link_libraries(teststream PUBLIC cameo zmq pthread)
add_executable(testtimeout src/tests/TestTimeoutApplication.cpp)
target_link_libraries(testtimeout PUBLIC cameo zmq)
add_executable(testconnectionchecker src/tests/TestConnectionCheckerApplication.cpp)
target_link_libraries(testconnectionchecker PUBLIC cameo zmq)
add_executable(testfaststream src/tests/TestFastStream.cpp)
target_link_libraries(testfaststream PUBLIC cameo zmq)
add_executable(testinputstream src/tests/TestInputStream.cpp)
target_link_libraries(testinputstream PUBLIC cameo zmq)
add_executable(teststoptimeout src/tests/TestStopTimeoutApplication.cpp)
target_link_libraries(teststoptimeout PUBLIC cameo zmq)
add_executable(teststream src/tests/TestStreamApplication.cpp)
target_link_libraries(teststream PUBLIC cameo zmq)
add_executable(teststartstream src/tests/TestStartStreamApplication.cpp)
target_link_libraries(teststartstream PUBLIC cameo zmq pthread)
add_executable(testresponderserver src/tests/TestResponderServer.cpp)
target_link_libraries(testresponderserver PUBLIC cameo zmq)
add_executable(testrequesterclient src/tests/TestRequesterClient.cpp)
target_link_libraries(testrequesterclient PUBLIC cameo zmq)
add_executable(testcomport src/tests/TestComPortApplication.cpp)
target_link_libraries(testcomport PUBLIC cameo zmq)
add_executable(teststartcomport src/tests/TestStartWithComPortApplication.cpp)
target_link_libraries(teststartcomport PUBLIC cameo zmq)
# Examples
add_executable(responderapp src/examples/ResponderApp.cpp)
......
......@@ -103,8 +103,8 @@ public class TestSelector {
apps.add("testsubscriberjava");
apps.add("testresponderjava");
apps.add("testrequesterjava");
apps.add("canceljava");
apps.add("testcanceljava");
apps.add("testcomportjava");
return apps;
}
......@@ -124,6 +124,7 @@ public class TestSelector {
apps.add("testrespondercpp");
apps.add("testrequestercpp");
apps.add("testcancelcpp");
apps.add("testcomportcpp");
return apps;
}
......
......@@ -19,28 +19,28 @@ package fr.ill.ics.cameo.test;
import fr.ill.ics.cameo.Application;
public class TestComPortApplication {
public class ComPort {
public static void main(String[] args) {
Application.This.init(args);
int port1 = Application.This.getCom().requestPort();
System.out.println("received port1 " + port1);
System.out.println("Received port1 " + port1);
Application.This.getCom().setPortUnavailable(port1);
System.out.println("set port " + port1 + " unavailable");
System.out.println("Set port " + port1 + " unavailable");
int port2 = Application.This.getCom().requestPort();
System.out.println("received port2 " + port2);
System.out.println("Received port2 " + port2);
Application.This.getCom().releasePort(port2);
System.out.println("released port2 " + port2);
System.out.println("Released port2 " + port2);
port2 = Application.This.getCom().requestPort();
System.out.println("received port2 " + port2);
System.out.println("Received port2 " + port2);
System.out.println("finished the application");
System.out.println("Finished the application");
Application.This.terminate();
}
......
/*
* Copyright 2015 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package fr.ill.ics.cameo.test;
public class ErrorApplication {
public static void main(String[] args) throws Exception {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
}
System.err.println("error");
throw new Exception("error");
}
}
\ No newline at end of file
/*
* Copyright 2015 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package fr.ill.ics.cameo.test;
public class FastApplication {
public static void main(String[] args) {
int i = 0;
int M = -1;
if (args.length > 0) {
M = Integer.parseInt(args[0]);
}
while (M == -1 || i < M) {
i++;
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
System.out.println("step " + i);
}
}
}
\ No newline at end of file
/*
* Copyright 2015 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package fr.ill.ics.cameo.test;
import fr.ill.ics.cameo.Application;
public class FastResultApplication {
public static void main(String[] args) {
Application.This.init(args);
String result = "";
result += Application.This.getId() * 11;
Application.This.setResult(result);
Application.This.terminate();
}
}
\ No newline at end of file
/*
* Copyright 2015 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package fr.ill.ics.cameo.test;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
public class ProcessErrorApplication {
public static void write(String content, File file) {
try {
file.createNewFile();
PrintWriter writer = new PrintWriter(file, "UTF-8");
writer.println(content);
writer.close();
} catch (IOException e) {
System.err.println("Cannot create file " + file);
}
}
/**
* args[0] = application id
* args[1] = error code
* @param args
*/
public static void main(String[] args) {
System.out.println("error " + args[1] + " for application " + args[0]);
}
}
\ No newline at end of file
/*
* Copyright 2015 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package fr.ill.ics.cameo.test;
import java.util.LinkedList;
import java.util.List;
import fr.ill.ics.cameo.Application;
import fr.ill.ics.cameo.Application.Instance;
import fr.ill.ics.cameo.Option;
import fr.ill.ics.cameo.OutputPrintThread;
import fr.ill.ics.cameo.OutputStreamSocket;
import fr.ill.ics.cameo.Server;
public class Test {
public static void testFast(Server server) {
server.killAllAndWaitFor("fast");
int i = 1;
while (i > 0) {
final Instance result = server.start("fast");
if (result.exists()) {
System.out.println("new application " + result.getNameId());
} else {
System.err.println("cannot start application");
return;
}
// test the kill in parallel
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
}
result.kill();
}
}).start();
result.waitFor();
i++;
}
}
public static void testFastAsync(Server server) {
server.killAllAndWaitFor("fast");
int i = 1;
while (i > 0) {
Instance result = server.start("fast");
if (result.exists()) {
System.out.println("new application " + result.getNameId());
} else {
System.err.println("cannot start application");
return;
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
}
// replace the result
result.kill();
result.waitFor();
i++;
}
}
public static void testFastOut(Server server, int sleep) {
server.killAllAndWaitFor("fastout");
int i = 1;
while (i > 0) {
Instance result = server.start("fastout", Option.OUTPUTSTREAM);
if (result.exists()) {
System.out.println("new application " + result.getNameId());
} else {
System.err.println("cannot start application");
return;
}
// start output thread
OutputStreamSocket streamSocket = result.getOutputStreamSocket();
// the socket can be null if the application is already terminated
if (streamSocket == null) {
System.out.println("cannot get output stream");
continue;
}
OutputPrintThread outputThread = new OutputPrintThread(streamSocket);
outputThread.start();
try {
Thread.sleep(sleep);
} catch (InterruptedException e) {
}
result.kill();
result.waitFor();
outputThread.waitFor();
i++;
}
}
public static void testFastParallel(Server server, int numberOfThreads) {
server.killAllAndWaitFor("fastpar");
final Server localServer = server;
List<Thread> threads = new LinkedList<Thread>();
// start 10 threads
for (int i = 0; i < numberOfThreads; ++i) {
Thread thread = new Thread(new Runnable()
{
@Override
public void run() {
System.out.println("started thread " + this);
int i = 1;
while (i > 0) {
Instance result = localServer.start("fastpar");
if (result.exists()) {
System.out.println("new application " + result.getNameId());
} else {
System.err.println("cannot start application");
return;
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
}
result.kill();
result.waitFor();
i++;
}
}
});
thread.start();
threads.add(thread);
}
for (Thread t : threads) {
try {
t.join();
} catch (InterruptedException e) {
}
}
}
public static void testFastConnect(Server server) {
server.killAllAndWaitFor("fastpar");
int i = 1;
while (i > 0) {
for (int j = 0; j < 10; ++j) {
Instance result = server.start("fastpar");
System.out.println("new application " + result.getNameId());
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
// connect and kill
List<Instance> results = server.connectAll("fastpar");
for (Instance result : results) {
result.kill();
int state = result.waitFor();
System.out.println("killed " + result.getNameId()
+ " with final state " + Application.State.toString(state));
}
i++;
}
}
public static void testError(Server server) {
server.killAllAndWaitFor("error");
int i = 1;
while (i > 0) {
Instance result = server.start("error");
if (result.exists()) {
System.out.println("new application " + result.getNameId());
} else {
System.err.println("cannot start application");
return;
}
int state = result.waitFor();
if (state == Application.State.SUCCESS) {
System.out.println("error, the application should fail");
} else {
System.out.println("ok, the application failed");
}
i++;
}
}
public static void testNoApp(Server server) {
int i = 1;
while (i > 0) {
Instance result = server.start("noapp");
if (result.exists()) {
System.out.println("new application " + result.getNameId());
} else {
System.err.println("cannot start application");
return;
}
int state = result.waitFor();
if (state == Application.State.SUCCESS) {
System.out.println("error, the application should fail");
} else {
System.out.println("ok, the application failed");
}
i++;
}
}
public static void main(String[] args) {
// ex: tcp://localhost:7000 fastout1000
if (args.length < 2) {
System.out.printf("syntax: test <endpoint> <test>\n");
return;
}
Server server = new Server(args[0]);
// loop with fast application
try {
if (!server.isAvailable()) {
System.out.println("no connection to server");
return;
}
// manage options
String testArg = args[1];
if (testArg.equals("fast")) {
testFast(server);
} else if (testArg.equals("fastasync")) {
testFastAsync(server);
} else if (testArg.equals("fastout10")) {
testFastOut(server, 10);
} else if (testArg.equals("fastout1000")) {
testFastOut(server, 1000);
} else if (testArg.equals("fastparallel")) {
int numberOfThreads = 10;
if (args.length > 2) {
numberOfThreads = Integer.parseInt(args[2]);
}
testFastParallel(server, numberOfThreads);
} else if (testArg.equals("fastconnect")) {
testFastConnect(server);
} else if (testArg.equals("error")) {
testError(server);
} else if (testArg.equals("noapp")) {
testNoApp(server);