Commit 0f4c74d2 authored by legoc's avatar legoc
Browse files

moving tests to cameo-tests project

parent c8f6dbc4
......@@ -21,15 +21,6 @@ AC_PROG_LIBTOOL
AC_CONFIG_MACRO_DIR([m4])
AC_ARG_ENABLE(tests,
[ --enable-tests compile test applications],
[case "${enableval}" in
yes) tests=true ;;
no) tests=false ;;
*) AC_MSG_ERROR(bad value ${enableval} for --enable-tests) ;;
esac],[tests=false])
AM_CONDITIONAL([TESTS], [test "$tests" = true])
AC_SUBST(LIBRARY_VERSION)
# temporarily disabled
......@@ -65,5 +56,4 @@ top_srcdir=.
AC_OUTPUT([
Makefile
src/Makefile
src/test/Makefile
])
if TESTS
TESTSDIR = test
endif
SUBDIRS = . $(TESTSDIR)
SUBDIRS = .
INCLUDES = -I$(top_srcdir)/src
......
INCLUDES = -I$(top_srcdir)/src
bin_PROGRAMS = \
testcameo \
testbadendpoint \
teststate \
testpublisher \
testsubscriber \
testsubscriberandpublisher \
testresult \
teststartwithresult \
teststop \
teststartwithstop \
testpublisherloop \
testresponder \
testrequesterandresponder \
testcancel \
testtimeout \
testconnectionchecker \
testveryfast
testcameo_SOURCES = \
Test.cpp
testcameo_CPPFLAGS = $(CAMEO_CXXFLAGS)
testcameo_LDFLAGS = $(CAMEO_LDFLAGS)
testcameo_LDADD = ../libcameo.la $(CAMEO_LIBS)
testbadendpoint_SOURCES = \
TestBadEndpoint.cpp
testbadendpoint_CPPFLAGS = $(CAMEO_CXXFLAGS)
testbadendpoint_LDFLAGS = $(CAMEO_LDFLAGS)
testbadendpoint_LDADD = ../libcameo.la $(CAMEO_LIBS)
teststate_SOURCES = \
TestStateApplication.cpp
teststate_CPPFLAGS = $(CAMEO_CXXFLAGS)
teststate_LDFLAGS = $(CAMEO_LDFLAGS)
teststate_LDADD = ../libcameo.la $(CAMEO_LIBS)
testpublisher_SOURCES = \
TestPublisherApplication.cpp
testpublisher_CPPFLAGS = $(CAMEO_CXXFLAGS)
testpublisher_LDFLAGS = $(CAMEO_LDFLAGS)
testpublisher_LDADD = ../libcameo.la $(CAMEO_LIBS)
testsubscriber_SOURCES = \
TestSubscriberApplication.cpp
testsubscriber_CPPFLAGS = $(CAMEO_CXXFLAGS)
testsubscriber_LDFLAGS = $(CAMEO_LDFLAGS)
testsubscriber_LDADD = ../libcameo.la $(CAMEO_LIBS)
testsubscriberandpublisher_SOURCES = \
TestSubscriberAndPublisherApplication.cpp
testsubscriberandpublisher_CPPFLAGS = $(CAMEO_CXXFLAGS)
testsubscriberandpublisher_LDFLAGS = $(CAMEO_LDFLAGS)
testsubscriberandpublisher_LDADD = ../libcameo.la $(CAMEO_LIBS)
testresult_SOURCES = \
TestResultApplication.cpp
testresult_CPPFLAGS = $(CAMEO_CXXFLAGS)
testresult_LDFLAGS = $(CAMEO_LDFLAGS)
testresult_LDADD = ../libcameo.la $(CAMEO_LIBS)
teststartwithresult_SOURCES = \
TestStartWithResultApplication.cpp
teststartwithresult_CPPFLAGS = $(CAMEO_CXXFLAGS)
teststartwithresult_LDFLAGS = $(CAMEO_LDFLAGS)
teststartwithresult_LDADD = ../libcameo.la $(CAMEO_LIBS)
teststop_SOURCES = \
TestStopApplication.cpp
teststop_CPPFLAGS = $(CAMEO_CXXFLAGS)
teststop_LDFLAGS = $(CAMEO_LDFLAGS)
teststop_LDADD = ../libcameo.la $(CAMEO_LIBS)
teststartwithstop_SOURCES = \
TestStartWithStopApplication.cpp
teststartwithstop_CPPFLAGS = $(CAMEO_CXXFLAGS)
teststartwithstop_LDFLAGS = $(CAMEO_LDFLAGS)
teststartwithstop_LDADD = ../libcameo.la $(CAMEO_LIBS)
testpublisherloop_SOURCES = \
TestPublisherLoopApplication.cpp
testpublisherloop_CPPFLAGS = $(CAMEO_CXXFLAGS)
testpublisherloop_LDFLAGS = $(CAMEO_LDFLAGS)
testpublisherloop_LDADD = ../libcameo.la $(CAMEO_LIBS)
testresponder_SOURCES = \
TestResponderApplication.cpp
testresponder_CPPFLAGS = $(CAMEO_CXXFLAGS)
testresponder_LDFLAGS = $(CAMEO_LDFLAGS)
testresponder_LDADD = ../libcameo.la $(CAMEO_LIBS)
testrequesterandresponder_SOURCES = \
TestRequesterAndResponderApplication.cpp
testrequesterandresponder_CPPFLAGS = $(CAMEO_CXXFLAGS)
testrequesterandresponder_LDFLAGS = $(CAMEO_LDFLAGS)
testrequesterandresponder_LDADD = ../libcameo.la $(CAMEO_LIBS)
testcancel_SOURCES = \
TestCancelApplication.cpp
testcancel_CPPFLAGS = $(CAMEO_CXXFLAGS)
testcancel_LDFLAGS = $(CAMEO_LDFLAGS)
testcancel_LDADD = ../libcameo.la $(CAMEO_LIBS)
testtimeout_SOURCES = \
TestTimeoutApplication.cpp
testtimeout_CPPFLAGS = $(CAMEO_CXXFLAGS)
testtimeout_LDFLAGS = $(CAMEO_LDFLAGS)
testtimeout_LDADD = ../libcameo.la $(CAMEO_LIBS)
testconnectionchecker_SOURCES = \
TestConnectionCheckerApplication.cpp
testconnectionchecker_CPPFLAGS = $(CAMEO_CXXFLAGS)
testconnectionchecker_LDFLAGS = $(CAMEO_LDFLAGS)
testconnectionchecker_LDADD = ../libcameo.la $(CAMEO_LIBS)
testveryfast_SOURCES = \
TestVeryFast.cpp
testveryfast_CPPFLAGS = $(CAMEO_CXXFLAGS)
testveryfast_LDFLAGS = $(CAMEO_LDFLAGS)
testveryfast_LDADD = ../libcameo.la $(CAMEO_LIBS)
/*
* 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.
*/
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include "../cameo/cameo.h"
using namespace std;
using namespace cameo;
int N = -1;
void testFast(Server& server) {
server.killAllAndWaitFor("fast");
int i = 0;
while (N == -1 || i < N) {
auto_ptr<application::Instance> result = server.start("fast");
cout << "new application " << result->getNameId() << endl;
usleep(10000);
result->kill();
result->waitFor();
i++;
}
}
void testFastAsync(Server& server) {
server.killAllAndWaitFor("fast");
int i = 0;
while (N == -1 || i < N) {
auto_ptr<application::Instance> result = server.start("fast");
cout << "new application " << result->getNameId() << endl;
usleep(10000);
// replace the result to test the Instance of kill
result->kill();
result->waitFor();
i++;
}
}
void testFastRes(Server& server) {
server.killAllAndWaitFor("fastres");
int i = 0;
while (N == -1 || i < N) {
auto_ptr<application::Instance> res = server.start("fastres");
cout << "new application " << res->getNameId() << endl;
application::State state = res->waitFor();
if (state == application::SUCCESS) {
string result;
res->getResult(result);
istringstream buffer(result);
int id;
buffer >> id;
cout << "success " << (id / 11) << " = " << res->getId() << endl;
} else {
cout << "error" << endl;
}
i++;
}
}
void testFastResPar1(Server& server) {
server.killAllAndWaitFor("fastres");
const int M = 10;
auto_ptr<application::Instance> res[M];
// start in parallel
for (int j = 0; j < M; j++) {
res[j] = server.start("fastres");
cout << "new application " << res[j]->getNameId() << endl;
}
// process
for (int j = 0; j < M; j++) {
application::State state = res[j]->waitFor();
if (state == application::SUCCESS) {
string result;
res[j]->getResult(result);
istringstream buffer(result);
int id;
buffer >> id;
cout << "success " << (id / 11) << " = " << res[j]->getId() << endl;
} else {
cout << "error" << endl;
}
}
}
void testFastResPar(Server& server) {
int i = 0;
while (N == -1 || i < N) {
testFastResPar1(server);
i++;
}
}
void testFastConnect(Server& server) {
server.killAllAndWaitFor("fastpar");
int i = 0;
while (N == -1 || i < N) {
for (int j = 0; j < 10; j++) {
auto_ptr<application::Instance> result = server.start("fastpar");
cout << "new application " << result->getNameId() << endl;
}
usleep(10000);
application::InstanceArray rs = server.connectAll("fastpar");
// testing copy/transfer
application::InstanceArray results = rs;
for (int j = 0; j < results.size(); j++) {
results[j]->kill();
application::State state = results[j]->waitFor();
cout << "killed " << results[j]->getNameId()
<< " with initial state " << application::toString(results[j]->getInitialState())
<< " and final state " << application::toString(state) << endl;
}
i++;
}
}
void testNoApp(Server& server) {
int i = 0;
while (N == -1 || i < N) {
auto_ptr<application::Instance> result = server.start("noapp");
cout << "new application " << result->getNameId() << endl;
application::State state = result->waitFor();
if (state == application::SUCCESS) {
cout << "error, the application should fail" << endl;
} else {
cout << "ok, the application failed" << endl;
}
i++;
}
}
void testNoApp(Server& server, int time) {
int i = 0;
while (N == -1 || i < N) {
auto_ptr<application::Instance> result = server.start("noapp");
cout << "new application " << result->getNameId() << endl;
if (time > 0) {
usleep(time * 1000);
}
application::State state = result->waitFor();
if (state == application::SUCCESS) {
cout << "error, the application should fail" << endl;
} else {
cout << "ok, the application failed" << endl;
}
i++;
}
}
int main(int argc, char *argv[]) {
if (argc < 3) {
// ex: ./testcameo tcp://localhost:7000 fastout 1
cout << "syntax: testcameo <endpoint> <test>\n";
return -1;
}
Server server(argv[1]);
cout << "testing connection of " << argv[1] << endl;
// manage options
string testArg = argv[2];
if (argc >= 4) {
istringstream is(argv[3]);
is >> N;
}
// loop with fast application
if (server.isAvailable()) {
cout << "connection is ok" << endl;
} else {
cout << "no response from server" << endl;
return -1;
}
if (testArg == "fast") {
testFast(server);
} else if (testArg == "fastasync") {
testFastAsync(server);
} else if (testArg == "fastres") {
testFastRes(server);
} else if (testArg == "fastrespar1") {
testFastResPar1(server);
} else if (testArg == "fastrespar") {
testFastResPar(server);
} else if (testArg == "fastconnect") {
testFastConnect(server);
} else if (testArg == "noapp") {
testNoApp(server, 0);
} else if (testArg == "noapp100") {
testNoApp(server, 100);
}
return 0;
}
/*
* 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.
*/
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include "../cameo/cameo.h"
using namespace std;
using namespace cameo;
int main(int argc, char *argv[]) {
try {
Server server("tcp://bad:7000");
server.isAvailable(1000);
}
catch (SocketException const & e) {
cout << "Socket exception: " << e.what() << endl;
}
catch (exception const & e) {
cout << "The server has bad endpoint" << endl;
}
try {
Server server("tcp//bad:7000");
server.isAvailable(1000);
}
catch (exception const &) {
cout << "The server has bad endpoint" << endl;
}
return 0;
}
/*
* 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.
*/
#include <boost/bind.hpp>
#include <boost/thread.hpp>
#include <boost/shared_ptr.hpp>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include "../cameo/cameo.h"
using namespace std;
using namespace cameo;
using namespace boost;
void cancelAll() {
sleep(1);
application::This::cancelWaitings();
}
void cancelInstance(shared_ptr<application::Instance> instance) {
sleep(1);
instance->cancelWaitFor();
}
void cancelPublisher(shared_ptr<application::Publisher> publisher) {
sleep(1);
publisher->cancelWaitForSubscribers();
}
void killInstance(shared_ptr<application::Instance> instance) {
sleep(1);
instance->kill();
}
int main(int argc, char *argv[]) {
application::This::init(argc, argv);
// New block to ensure cameo objects are terminated before the application.
{
Server& server = application::This::getServer();
// Test the cancelWaitings function
{
cout << "starting stopcpp for cancelWaitings" << endl;
auto_ptr<application::Instance> stopApplication = server.start("stopcpp");
// Start thread
auto_ptr<thread> cancelThread(new thread(&cancelAll));
stopApplication->waitFor();
cout << "end of waitFor" << endl;
stopApplication->stop();
application::State state = stopApplication->waitFor();
cout << "end of stopcpp with state " << application::toString(state) << endl;
cancelThread->join();
}
// Test the cancel function
{
cout << "starting stopcpp for cancelWaitFor" << endl;
// Use a shared_ptr to use it in the thread and the main thread.
shared_ptr<application::Instance> stopApplication(server.start("stopcpp"));
// Start thread
auto_ptr<thread> cancelThread(new thread(bind(&cancelInstance, stopApplication)));
stopApplication->waitFor();
cout << "end of waitFor" << endl;
stopApplication->stop();
application::State state = stopApplication->waitFor();
cout << "end of stopcpp with state " << application::toString(state) << endl;
cancelThread->join();
}
// Test Publisher.cancelWaitForSubscribers
{
cout << "creating publisher and waiting for 1 subscriber..." << endl;
// Use a shared_ptr to use it in the thread and the main thread.
shared_ptr<application::Publisher> publisher(application::Publisher::create("publisher", 1));
// Start thread
auto_ptr<thread> cancelThread(new thread(bind(&cancelPublisher, publisher)));
bool synced = publisher->waitForSubscribers();
cancelThread->join();
cout << "synchronization with the subscriber synced ? " << synced << endl;
}