summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schanda <schanda@itestra.de>2013-11-11 17:00:05 +0100
committerGerrit Code Review <qqmthk1@lpmodthk02.bmwgroup.net>2013-11-11 17:00:05 +0100
commitd66bfcf350c247f0410d108b914f158c467730f8 (patch)
treefe26af310614393007c9d55598f856d99fe00eb0
parent24ecb0641e6d59f23b35791f5ebcb808df3c61df (diff)
parent74053809a1964a14c1c19b935115bb088085c422 (diff)
downloadgenivi-common-api-runtime-d66bfcf350c247f0410d108b914f158c467730f8.tar.gz
Merge "extended verification tests regarding dynamic loading and mainloops"
-rw-r--r--org.genivi.commonapi.core.verification/Makefile.am35
-rw-r--r--org.genivi.commonapi.core.verification/configure.ac177
-rw-r--r--org.genivi.commonapi.core.verification/src/DynamicLoadingVerification.cpp.in158
-rw-r--r--org.genivi.commonapi.core.verification/src/MainLoopTest.cpp189
-rw-r--r--org.genivi.commonapi.core.verification/src/MainLoopVerification.cpp461
-rw-r--r--org.genivi.commonapi.core.verification/src/utils/VerificationMainLoop.h (renamed from org.genivi.commonapi.core.verification/src/VerificationMainLoop.h)14
-rw-r--r--org.genivi.commonapi.core.verification/src/utils/VerificationTestStub.cpp (renamed from org.genivi.commonapi.core.verification/src/VerificationTestStub.cpp)6
-rw-r--r--org.genivi.commonapi.core.verification/src/utils/VerificationTestStub.h (renamed from org.genivi.commonapi.core.verification/src/VerificationTestStub.h)3
8 files changed, 771 insertions, 272 deletions
diff --git a/org.genivi.commonapi.core.verification/Makefile.am b/org.genivi.commonapi.core.verification/Makefile.am
index 92af417..5b4f211 100644
--- a/org.genivi.commonapi.core.verification/Makefile.am
+++ b/org.genivi.commonapi.core.verification/Makefile.am
@@ -1,24 +1,39 @@
ACLOCAL_AMFLAGS = -I m4
+GLUE_LDFLAGS_FOR_A="-Wl,--whole-archive,${GLUECODE_A},${BINDING_A},--no-whole-archive,${BINDING_EXTRA}"
+GLUE_LDFLAGS_FOR_SO="-Wl,--no-as-needed,${GLUECODE_SO},${BINDING_SO},--as-needed,${BINDING_EXTRA}"
+
AM_CPPFLAGS = \
-I$(top_srcdir)/src \
- -I${GLUE_PATH}/src-gen \
+ -I./src-gen \
-I$(includedir) \
- ${GLUE_CFLAGS} \
${COMMONAPI_CFLAGS} \
${GTEST_CPPFLAGS}
check_PROGRAMS = \
- verification
+ DynamicLoadingVerification \
+ MainLoopVerification
+generated = \
+ src-gen/commonapi/tests/DerivedTypeCollection.cpp \
+ src-gen/commonapi/tests/TestInterfaceStubDefault.cpp
TESTS = ${check_PROGRAMS}
-verification_SOURCES = \
- src/VerificationTestStub.h \
- src/VerificationTestStub.cpp \
- src/MainLoopTest.cpp
+DynamicLoadingVerification_SOURCES = \
+ ${generated} \
+ src/utils/VerificationTestStub.cpp \
+ src/DynamicLoadingVerification.cpp
+
+MainLoopVerification_SOURCES = \
+ ${generated} \
+ src/utils/VerificationTestStub.cpp \
+ src/MainLoopVerification.cpp
+
+DynamicLoadingVerification_CPPFLAGS = ${AM_CPPFLAGS}
+DynamicLoadingVerification_LDADD = ${COMMONAPI_LIBS} ${GTEST_LIBS}
+DynamicLoadingVerification_LDFLAGS = ${GLUE_LDFLAGS_FOR_SO}
-verification_CPPFLAGS = ${AM_CPPFLAGS}
-verification_LDADD = ${COMMONAPI_LIBS} ${GLUE_LIBS} ${GTEST_LIBS}
-verification_LDFLAGS = ${GLUE_LDFLAGS}
+MainLoopVerification_CPPFLAGS = ${AM_CPPFLAGS}
+MainLoopVerification_LDADD = ${COMMONAPI_LIBS} ${BINDING_A} ${GTEST_LIBS}
+MainLoopVerification_LDFLAGS = ${GLUE_LDFLAGS_FOR_A}
diff --git a/org.genivi.commonapi.core.verification/configure.ac b/org.genivi.commonapi.core.verification/configure.ac
index 14e4cdb..2758998 100644
--- a/org.genivi.commonapi.core.verification/configure.ac
+++ b/org.genivi.commonapi.core.verification/configure.ac
@@ -5,53 +5,104 @@ AC_CONFIG_MACRO_DIR([m4])
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_HEADERS([build-aux/config.h])
+AC_CONFIG_FILES([
+ Makefile
+ DynamicLoadingVerification.conf
+ src/DynamicLoadingVerification.cpp
+ ])
AC_CANONICAL_SYSTEM
AM_INIT_AUTOMAKE([foreign])
-AC_ARG_WITH([gluecode-path], [path to gluecode containing directories src-gen and .libs], [
- GLUE_PATH=${withval}
-], [])
-
-AC_ARG_WITH([gluecode-so-name], [name of gluecode .so file within directory .libs], [
- GLUE_SHARED=true
- GLUE_SO=${withval}
- GLUE_LIBS=${GLUE_PATH}/.libs/${GLUE_SO}
-], [])
-
-AC_ARG_WITH([binding-a], [full path to binding .a file if gluecode is linked statically], [
- BINDING_A=${withval}
-], [])
-
-AC_ARG_WITH([binding-so], [full path to binding .so file if gluecode is linked statically], [
- BINDING_SO=${withval}
-], [])
-
-AC_ARG_WITH([binding-extra], [full path to additional .so files required by statically linked binding], [
- BINDING_EXTRA=${withval}
-], [])
-
-AS_IF([test "${BINDING_A}" != ""], [
- BINDING="--whole-archive,${BINDING_A},--no-whole-archive"
-]
-, [
- BINDING=${BINDING_SO}
-])
-AC_ARG_WITH([gluecode-a-name], [name of gluecode .a file within direcotry .libs], [
- GLUE_SHARED=true
- GLUE_A=${withval}
- GLUE_LDFLAGS="-Wl,--whole-archive,${GLUE_PATH}/.libs/${GLUE_A},--no-whole-archive,${BINDING},${BINDING_EXTRA}"
-], [])
+### Binding definitions ###
-GLUE_CFLAGS=-I${GLUE_PATH}/src-gen
+# Well known binding name
+AC_MSG_CHECKING(Well known name of the binding that is to be tested)
+AC_ARG_WITH([binding-name], [Well known name of the binding that is to be tested], [
+ BINDING_NAME=${withval}
+ AC_MSG_RESULT(${BINDING_NAME})
+],[
+ AC_MSG_RESULT(no)
+ AC_MSG_ERROR([A binding that shall be verified needs to be specified! Use '--with-binding=' to do so.])
+])
-AC_SUBST(GLUE_CFLAGS)
-AC_SUBST(GLUE_LIBS)
-AC_SUBST(GLUE_PATH)
-AC_SUBST(GLUE_SO)
-AC_SUBST(GLUE_LDFLAGS)
+# Path to binding libraries
+AC_ARG_WITH([binding], [full path to binding library, including name, excluding file ending. The .a and .so files with the given fqn will be used if present and when needed.], [
+ BINDING_FQN=${withval}
+
+ AC_MSG_CHECKING(.a binding library)
+ AS_IF([test -f "${BINDING_FQN}.a"], [
+ BINDING_A="${BINDING_FQN}.a"
+ AC_MSG_RESULT(yes)
+ ], [
+ AC_MSG_RESULT(no)
+ ]
+ )
+
+ AC_MSG_CHECKING(.so binding library)
+ AS_IF([test -f "${BINDING_FQN}.so"], [
+ BINDING_SO="${BINDING_FQN}.so"
+ AC_MSG_RESULT(yes)
+ ], [
+ AC_MSG_RESULT(no)
+ ]
+ )
+], [AC_MSG_ERROR([A binding that shall be verified needs to be specified! Use '--with-binding=' to do so.])])
+
+
+# Additional libraries required by the binding
+AC_ARG_WITH([binding-extra], [full path to additional library required by statically linked binding], [
+ AC_MSG_CHECKING(required additional libraries for the binding)
+ AS_IF([test -f "${withval}"], [
+ BINDING_EXTRA="${withval}"
+ AC_MSG_RESULT(yes)
+ ], [
+ AC_MSG_RESULT(no)
+ ]
+ )
+],[])
+
+
+AM_CONDITIONAL(STATICALLY_LINKED_BINDING, [test -f "${GTEST_CONFIG}" && ${TESTS_CAN_BE_EXECUTED}])
+AM_CONDITIONAL(DYNAMICALLY_LINKED_BINDING, [test -f "${GTEST_CONFIG}" && ${TESTS_CAN_BE_EXECUTED}])
+
+
+#Libraries containing binding specific gluecode
+AC_ARG_WITH([gluecode], [full path to gluecode libraries, including name, excluding file ending. The .a and .so files with the given name will be used if present and when needed.], [
+ GLUECODE_FQN=${withval}
+
+ AC_MSG_CHECKING(.a gluecode library)
+ AS_IF([test -f "${GLUECODE_FQN}.a"], [
+ GLUECODE_A="${GLUECODE_FQN}.a"
+ AC_MSG_RESULT(yes)
+ ], [
+ AC_MSG_RESULT(no)
+ ]
+ )
+
+ AC_MSG_CHECKING(.so gluecode library)
+ AS_IF([test -f "${GLUECODE_FQN}.so"], [
+ GLUECODE_SO="${GLUECODE_FQN}.so"
+ AC_MSG_RESULT(yes)
+ ], [
+ AC_MSG_RESULT(no)
+ ]
+ )
+], [AC_MSG_WARN([No path to binding specific gluecode library specified. Is this correct? If not, do so with '--with-gluecode='.])])
+
+
+#Substitutions
+AC_SUBST(BINDING_NAME)
+AC_SUBST(BINDING_SO)
+AC_SUBST(BINDING_A)
+AC_SUBST(BINDING_EXTRA)
+AC_SUBST(GLUECODE_SO)
+AC_SUBST(GLUECODE_A)
+
+
+#Configurations
AC_PROG_CXX
AC_LANG([C++])
AX_CXX_COMPILE_STDCXX_11([noext])
@@ -59,8 +110,10 @@ AX_CXX_COMPILE_STDCXX_11([noext])
LT_PREREQ(2.2)
LT_INIT
+
+#Dependencies
PKG_PROG_PKG_CONFIG
-PKG_CHECK_MODULES(COMMONAPI, [CommonAPI >= 0.7])
+PKG_CHECK_MODULES(COMMONAPI, [CommonAPI >= 2.0])
GTEST_MIN_VERSION="1.6.0"
GTEST_URL="http://code.google.com/p/googletest"
@@ -72,34 +125,38 @@ AC_ARG_VAR([GTEST_LDFLAGS], [Linker path and option flags for Google Test.])
AC_ARG_VAR([GTEST_LIBS], [Library linking flags for Google Test.])
AC_ARG_VAR([GTEST_VERSION], [The available version of Google Test.])
-AS_IF([test -f "${GTEST_CONFIG}"],
- [AS_IF([${GTEST_CONFIG} --min-version=${GTEST_MIN_VERSION}],
- [],
- [AC_MSG_ERROR([dnl
- Found Google Test Version ${GTEST_VERSION}. However ${GTEST_MIN_VERSION} is
- required. Please refer to ${GTEST_URL} for a more recent version.])])
- [GTEST_CPPFLAGS=`${GTEST_CONFIG} --cppflags`]
- [GTEST_CXXFLAGS=`${GTEST_CONFIG} --cxxflags`]
- [GTEST_LDFLAGS=`${GTEST_CONFIG} --ldflags`]
- [GTEST_LIBS=`${GTEST_CONFIG} --libs`]
- [GTEST_VERSION=`${GTEST_CONFIG} --version`]
+AS_IF([test -f "${GTEST_CONFIG}"], [
+ AS_IF([${GTEST_CONFIG} --min-version=${GTEST_MIN_VERSION}],
+ [],
+ [AC_MSG_ERROR([Found Google Test Version ${GTEST_VERSION}. However ${GTEST_MIN_VERSION} is
+ required. Please refer to ${GTEST_URL} for a more recent version.])])
+ [GTEST_CPPFLAGS=`${GTEST_CONFIG} --cppflags`]
+ [GTEST_CXXFLAGS=`${GTEST_CONFIG} --cxxflags`]
+ [GTEST_LDFLAGS=`${GTEST_CONFIG} --ldflags`]
+ [GTEST_LIBS=`${GTEST_CONFIG} --libs`]
+ [GTEST_VERSION=`${GTEST_CONFIG} --version`]
+ ], [
+ AC_MSG_ERROR([Google Test could not be found! Please provide an environment variable 'GTEST_CONFIG'
+ pointing to the location of Google Test's 'gtest-config' script])
]
- []
)
+
+#Result
AC_MSG_RESULT([
$PACKAGE_NAME v$VERSION
- enable docs: ${ENABLE_DOCS}
-
COMMONAPI_CFLAGS: ${COMMONAPI_CFLAGS}
COMMONAPI_LIBS: ${COMMONAPI_LIBS}
- GLUE_CFLAGS: ${GLUE_CFLAGS}
- GLUE_LIBS: ${GLUE_LIBS}
- GLUE_SO: ${GLUE_SO}
- GLUE_A: ${GLUE_A}
- GLUE_PATH: ${GLUE_PATH}
+ BINDING_FQN: ${BINDING_FQN}
+ BINDING_SO: ${BINDING_SO}
+ BINDING_A: ${BINDING_A}
+ BINDING_EXTRA: ${BINDING_EXTRA}
+
+ GLUECODE_FQN: ${GLUECODE_FQN}
+ GLUECODE_SO: ${GLUECODE_SO}
+ GLUECODE_A: ${GLUECODE_A}
GTEST_CONFIG: ${GTEST_CONFIG}
GTEST_CPPFLAGS: ${GTEST_CPPFLAGS}
@@ -108,10 +165,8 @@ AC_MSG_RESULT([
GTEST_LIBS: ${GTEST_LIBS}
GTEST_VERSION: ${GTEST_VERSION}
- prefix: ${prefix}
CXXFLAGS: ${CXXFLAGS}
LDFLAGS: ${LDFLAGS}
])
-AC_CONFIG_FILES(Makefile)
AC_OUTPUT \ No newline at end of file
diff --git a/org.genivi.commonapi.core.verification/src/DynamicLoadingVerification.cpp.in b/org.genivi.commonapi.core.verification/src/DynamicLoadingVerification.cpp.in
new file mode 100644
index 0000000..ba9b971
--- /dev/null
+++ b/org.genivi.commonapi.core.verification/src/DynamicLoadingVerification.cpp.in
@@ -0,0 +1,158 @@
+/* Copyright (C) 2013 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <functional>
+#include <fstream>
+#include <gtest/gtest.h>
+#include "CommonAPI/CommonAPI.h"
+#include "utils/VerificationMainLoop.h"
+#include "commonapi/tests/TestInterfaceProxy.h"
+#include "utils/VerificationTestStub.h"
+
+const std::string testAddress = "local:my.test:commonapi.address";
+
+const std::string configString =
+ "{binding:@BINDING_NAME@}\n"
+ "libpath=@BINDING_SO@\n"
+ "alias=TestAlias\n"
+ "genpath=@GLUECODE_SO@\n"
+ "default"
+;
+
+const std::string COMMONAPI_CONFIG_SUFFIX = ".conf";
+
+
+
+class Environment: public ::testing::Environment {
+public:
+ virtual ~Environment() {
+ }
+
+ virtual void SetUp() {
+ configFileName_ = CommonAPI::getCurrentBinaryFileFQN();
+ configFileName_ += COMMONAPI_CONFIG_SUFFIX;
+ std::ofstream configFile(configFileName_);
+ ASSERT_TRUE(configFile.is_open());
+ configFile << configString;
+ configFile.close();
+ }
+
+ virtual void TearDown() {
+ std::remove(configFileName_.c_str());
+ }
+
+ std::string configFileName_;
+};
+
+
+
+
+class DynamicLoadingTest: public ::testing::Test {
+
+protected:
+ void SetUp() {
+ }
+
+ void TearDown() {
+ }
+
+ std::string configFileName_;
+};
+
+
+TEST_F(DynamicLoadingTest, LoadsDefaultRuntime) {
+ std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load();
+ ASSERT_TRUE((bool)runtime);
+}
+
+TEST_F(DynamicLoadingTest, LoadsRuntimeByBindingName) {
+ std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load("@BINDING_NAME@");
+ ASSERT_TRUE((bool)runtime);
+}
+
+TEST_F(DynamicLoadingTest, LoadsRuntimeByAlias) {
+ std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load("TestAlias");
+ ASSERT_TRUE((bool)runtime);
+}
+
+TEST_F(DynamicLoadingTest, LoadedRuntimeCanCreateFactory) {
+ std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load("TestAlias");
+ ASSERT_TRUE((bool)runtime);
+
+ std::shared_ptr<CommonAPI::Factory> factory = runtime->createFactory();
+ ASSERT_TRUE((bool)factory);
+}
+
+TEST_F(DynamicLoadingTest, LoadedRuntimeCanBuildProxiesAndStubs) {
+ std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load("TestAlias");
+ ASSERT_TRUE((bool)runtime);
+
+ std::shared_ptr<CommonAPI::Factory> factoryProxy = runtime->createFactory();
+ ASSERT_TRUE((bool)factoryProxy);
+
+ std::shared_ptr<CommonAPI::Factory> factoryStub = runtime->createFactory();
+ ASSERT_TRUE((bool)factoryStub);
+
+ auto proxy = factoryProxy->buildProxy<commonapi::tests::TestInterfaceProxy>(testAddress);
+ ASSERT_TRUE((bool)proxy);
+
+ auto servicePublisher = runtime->getServicePublisher();
+ ASSERT_TRUE((bool) servicePublisher);
+
+ auto stub = std::make_shared<commonapi::verification::VerificationTestStub>();
+ ASSERT_TRUE(servicePublisher->registerService(stub, testAddress, factoryStub));
+
+ servicePublisher->unregisterService(testAddress);
+ sleep(2);
+}
+
+TEST_F(DynamicLoadingTest, LoadedRuntimeCanBuildProxiesAndStubsThatCommunicate) {
+ std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load("TestAlias");
+ ASSERT_TRUE((bool)runtime);
+
+ std::shared_ptr<CommonAPI::Factory> factoryProxy = runtime->createFactory();
+ ASSERT_TRUE((bool)factoryProxy);
+
+ std::shared_ptr<CommonAPI::Factory> factoryStub = runtime->createFactory();
+ ASSERT_TRUE((bool)factoryStub);
+
+ auto proxy = factoryProxy->buildProxy<commonapi::tests::TestInterfaceProxy>(testAddress);
+ ASSERT_TRUE((bool)proxy);
+
+ auto servicePublisher = runtime->getServicePublisher();
+ ASSERT_TRUE((bool) servicePublisher);
+
+ auto stub = std::make_shared<commonapi::verification::VerificationTestStub>();
+ ASSERT_TRUE(servicePublisher->registerService(stub, testAddress, factoryStub));
+
+ CommonAPI::CallStatus callStatus;
+ std::string outString;
+ uint32_t outInt = 0;
+
+ for(int i=0; i<10; i++)
+ {
+ if(proxy->isAvailable()) {
+ break;
+ }
+
+ usleep(50);
+ }
+
+ ASSERT_TRUE(proxy->isAvailable());
+
+ proxy->testPredefinedTypeMethod(0, "", callStatus, outInt, outString);
+ ASSERT_EQ(1, outInt);
+
+ servicePublisher->unregisterService(testAddress);
+ sleep(2);
+}
+
+int main(int argc, char** argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ ::testing::AddGlobalTestEnvironment(new Environment());
+ return RUN_ALL_TESTS();
+}
diff --git a/org.genivi.commonapi.core.verification/src/MainLoopTest.cpp b/org.genivi.commonapi.core.verification/src/MainLoopTest.cpp
deleted file mode 100644
index bebee55..0000000
--- a/org.genivi.commonapi.core.verification/src/MainLoopTest.cpp
+++ /dev/null
@@ -1,189 +0,0 @@
-/* Copyright (C) 2013 BMW Group
- * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
- * Author: Juergen Gehring (juergen.gehring@bmw.de)
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <gtest/gtest.h>
-#include "CommonAPI/CommonAPI.h"
-#include "VerificationMainLoop.h"
-#include "commonapi/tests/TestInterfaceProxy.h"
-#include "VerificationTestStub.h"
-#include <functional>
-
-const std::string testAddress8 = "local:my.eigth.test:commonapi.address.eight";
-
-class MainLoopTest: public ::testing::Test {
-
-protected:
- void SetUp() {
-
- runtime_ = CommonAPI::Runtime::load();
- ASSERT_TRUE((bool) runtime_);
-
- contextProxy_ = runtime_->getNewMainLoopContext();
- contextStub_ = runtime_->getNewMainLoopContext();
- ASSERT_TRUE((bool) contextProxy_);
- ASSERT_TRUE((bool) contextStub_);
- ASSERT_FALSE(contextProxy_ == contextStub_);
-
- mainLoopProxy_ = new CommonAPI::VerificationMainLoop(contextProxy_);
- mainLoopStub_ = new CommonAPI::VerificationMainLoop(contextStub_);
-
- mainloopFactoryProxy_ = runtime_->createFactory(contextProxy_);
- mainloopFactoryStub_ = runtime_->createFactory(contextStub_);
- ASSERT_TRUE((bool) mainloopFactoryProxy_);
- ASSERT_TRUE((bool) mainloopFactoryStub_);
- ASSERT_FALSE(mainloopFactoryProxy_ == mainloopFactoryStub_);
-
- servicePublisher_ = runtime_->getServicePublisher();
- ASSERT_TRUE((bool) servicePublisher_);
- callbackCalled = 0;
- lastBroadcastNumber = 0;
- outInt = 0;
- }
-
- void TearDown() {
- delete mainLoopProxy_;
- delete mainLoopStub_;
- }
-
- std::shared_ptr<CommonAPI::Runtime> runtime_;
-
- std::shared_ptr<CommonAPI::MainLoopContext> contextProxy_;
- std::shared_ptr<CommonAPI::MainLoopContext> contextStub_;
- std::shared_ptr<CommonAPI::Factory> mainloopFactoryProxy_;
- std::shared_ptr<CommonAPI::Factory> mainloopFactoryStub_;
- std::shared_ptr<CommonAPI::ServicePublisher> servicePublisher_;
-
- CommonAPI::VerificationMainLoop* mainLoopProxy_;
- CommonAPI::VerificationMainLoop* mainLoopStub_;
-
- int callbackCalled;
- int lastBroadcastNumber;
- uint32_t outInt;
-
-public:
- void broadcastCallback(uint32_t intValue, std::string stringValue) {
- // check correct order
- lastBroadcastNumber++;
- ASSERT_EQ(lastBroadcastNumber, intValue);
- // check, if broadcast is handled after method call
- ASSERT_EQ(outInt, 1);
- }
-};
-
-TEST_F(MainLoopTest, VerifyTransportReadingWhenDispatchingWatches) {
- std::shared_ptr<commonapi::verification::VerificationTestStub> stub = std::make_shared<commonapi::verification::VerificationTestStub>();
- ASSERT_TRUE(servicePublisher_->registerService(stub, testAddress8, mainloopFactoryStub_));
-
- auto proxy = mainloopFactoryProxy_->buildProxy<commonapi::tests::TestInterfaceProxy>(testAddress8);
- ASSERT_TRUE((bool) proxy);
-
- std::thread stubThread = std::thread([&](){ mainLoopStub_->run(); });
- stubThread.detach();
-
- while (!proxy->isAvailable()) {
- mainLoopProxy_->doSingleIteration();
- usleep(50000);
- }
-
- ASSERT_TRUE(proxy->isAvailable());
-
- mainLoopStub_->stop();
-
-
- uint32_t uint32Value = 42;
- std::string stringValue = "Hai :)";
- bool running = true;
-
- commonapi::tests::DerivedTypeCollection::TestEnumExtended2 testEnumExtended2InValue =
- commonapi::tests::DerivedTypeCollection::TestEnumExtended2::E_OK;
- commonapi::tests::DerivedTypeCollection::TestMap testMapInValue;
-
- // Estimated amount of data (differring padding at beginning/end of Map/Array etc. not taken into account):
- // 4 + 4 + 500 * (4 + (4 + 4 + 100 * (11 + 1 + 4)) + 4 ) = 811008
- for (uint32_t i = 0; i < 500; ++i) {
- commonapi::tests::DerivedTypeCollection::TestArrayTestStruct testArrayTestStruct;
- for (uint32_t j = 0; j < 100; ++j) {
- commonapi::tests::DerivedTypeCollection::TestStruct testStruct("Hai all (:", j);
- testArrayTestStruct.push_back(testStruct);
- }
- testMapInValue.insert( {i, testArrayTestStruct});
- }
-
- std::future<CommonAPI::CallStatus> futureStatus =
- proxy->testDerivedTypeMethodAsync(
- testEnumExtended2InValue,
- testMapInValue,
- [&] (const CommonAPI::CallStatus& status,
- commonapi::tests::DerivedTypeCollection::TestEnumExtended2 testEnumExtended2OutValue,
- commonapi::tests::DerivedTypeCollection::TestMap testMapOutValue) {
- mainLoopProxy_->stop();
- callbackCalled++;
- }
- );
-
- mainLoopProxy_->runVerification(15, true, true);
-
- // 1. just dispatch dispatchSources
- mainLoopStub_->runVerification(15, false, true);
- ASSERT_EQ(stub->getCalledTestDerivedTypeMethod(), 0);
-
- // 2. just dispatch watches (reads transport)
- mainLoopStub_->runVerification(20, true, false);
- ASSERT_EQ(stub->getCalledTestDerivedTypeMethod(), 0);
-
- // 3. just dispatch dispatchSources again. This should dispatch the messages already read from transport in 2.
- mainLoopStub_->doVerificationIteration(false, true);
- ASSERT_EQ(stub->getCalledTestDerivedTypeMethod(), 1);
-
- servicePublisher_->unregisterService(testAddress8);
-}
-
-TEST_F(MainLoopTest, VerifySyncCallMessageHandlingOrder) {
- std::shared_ptr<commonapi::verification::VerificationTestStub> stub = std::make_shared<commonapi::verification::VerificationTestStub>();
- ASSERT_TRUE(servicePublisher_->registerService(stub, testAddress8, mainloopFactoryStub_));
-
- auto proxy = mainloopFactoryProxy_->buildProxy<commonapi::tests::TestInterfaceProxy>(testAddress8);
- ASSERT_TRUE((bool) proxy);
-
- std::thread stubThread = std::thread([&](){ mainLoopStub_->run(); });
- stubThread.detach();
-
- /*std::thread proxyThread = std::thread([&](){ mainLoopProxy_->run(); });
- proxyThread.detach();*/
-
- for (int i = 0; i < 10000; i++) {
- mainLoopProxy_->doSingleIteration(100);
- }
-
- ASSERT_TRUE(proxy->isAvailable());
-
- auto& broadcastEvent = proxy->getTestPredefinedTypeBroadcastEvent();
- broadcastEvent.subscribe(std::bind(&MainLoopTest::broadcastCallback, this, std::placeholders::_1, std::placeholders::_2));
-
- CommonAPI::CallStatus callStatus;
- std::string outString;
-
- proxy->testPredefinedTypeMethod(0, "", callStatus, outInt, outString);
- ASSERT_EQ(outInt, 1);
-
- for (int i = 0; i < 10000; i++) {
- mainLoopProxy_->doSingleIteration(100);
- }
-
- sleep(10);
-
- mainLoopProxy_->stop();
- mainLoopStub_->stop();
-
- // in total 5 broadcasts should have been arrived
- ASSERT_EQ(lastBroadcastNumber, 5);
-}
-
-int main(int argc, char** argv) {
- ::testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/org.genivi.commonapi.core.verification/src/MainLoopVerification.cpp b/org.genivi.commonapi.core.verification/src/MainLoopVerification.cpp
new file mode 100644
index 0000000..7387f95
--- /dev/null
+++ b/org.genivi.commonapi.core.verification/src/MainLoopVerification.cpp
@@ -0,0 +1,461 @@
+/* Copyright (C) 2013 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <gtest/gtest.h>
+#include "CommonAPI/CommonAPI.h"
+#include "utils/VerificationMainLoop.h"
+#include "commonapi/tests/TestInterfaceProxy.h"
+#include "utils/VerificationTestStub.h"
+#include <functional>
+
+const std::string testAddress6 = "local:my.eigth.test:commonapi.address.six";
+const std::string testAddress7 = "local:my.eigth.test:commonapi.address.seven";
+const std::string testAddress8 = "local:my.eigth.test:commonapi.address.eight";
+
+class PingPongTestStub : public commonapi::tests::TestInterfaceStubDefault {
+ virtual void testPredefinedTypeMethod(const std::shared_ptr<CommonAPI::ClientId> clientId,
+ uint32_t uint32InValue,
+ std::string stringInValue,
+ uint32_t& uint32OutValue,
+ std::string& stringOutValue) {
+ stringOutValue = stringInValue;
+ uint32OutValue = uint32InValue;
+ }
+};
+
+class MainLoopTest: public ::testing::Test {
+
+protected:
+ void SetUp() {
+
+ runtime_ = CommonAPI::Runtime::load();
+ ASSERT_TRUE((bool) runtime_);
+
+ contextForProxy_ = runtime_->getNewMainLoopContext();
+ contextForStub_ = runtime_->getNewMainLoopContext();
+ ASSERT_TRUE((bool) contextForProxy_);
+ ASSERT_TRUE((bool) contextForStub_);
+ ASSERT_FALSE(contextForProxy_ == contextForStub_);
+
+ mainLoopForProxy_ = new CommonAPI::VerificationMainLoop(contextForProxy_);
+ mainLoopForStub_ = new CommonAPI::VerificationMainLoop(contextForStub_);
+
+ mainloopFactoryProxy_ = runtime_->createFactory(contextForProxy_);
+ mainloopFactoryStub_ = runtime_->createFactory(contextForStub_);
+ ASSERT_TRUE((bool) mainloopFactoryProxy_);
+ ASSERT_TRUE((bool) mainloopFactoryStub_);
+ ASSERT_FALSE(mainloopFactoryProxy_ == mainloopFactoryStub_);
+
+ servicePublisher_ = runtime_->getServicePublisher();
+ ASSERT_TRUE((bool) servicePublisher_);
+
+ stub_ = std::make_shared<commonapi::verification::VerificationTestStub>();
+ ASSERT_TRUE(servicePublisher_->registerService(stub_, testAddress8, mainloopFactoryStub_));
+
+ callbackCalled = 0;
+ lastBroadcastNumber = 0;
+ outInt = 0;
+ }
+
+ void TearDown() {
+ servicePublisher_->unregisterService(testAddress8);
+ mainLoopForProxy_->stop();
+ mainLoopForStub_->stop();
+ usleep(200);
+ delete mainLoopForProxy_;
+ delete mainLoopForStub_;
+ }
+
+ std::shared_ptr<CommonAPI::Runtime> runtime_;
+
+ std::shared_ptr<CommonAPI::MainLoopContext> contextForProxy_;
+ std::shared_ptr<CommonAPI::MainLoopContext> contextForStub_;
+ std::shared_ptr<CommonAPI::Factory> mainloopFactoryProxy_;
+ std::shared_ptr<CommonAPI::Factory> mainloopFactoryStub_;
+ std::shared_ptr<CommonAPI::ServicePublisher> servicePublisher_;
+ std::shared_ptr<commonapi::verification::VerificationTestStub> stub_;
+
+ CommonAPI::VerificationMainLoop* mainLoopForProxy_;
+ CommonAPI::VerificationMainLoop* mainLoopForStub_;
+
+ int callbackCalled;
+ int lastBroadcastNumber;
+ uint32_t outInt;
+ CommonAPI::CallStatus callStatus;
+
+public:
+ void broadcastCallback(uint32_t intValue, std::string stringValue) {
+ // check correct order
+ lastBroadcastNumber++;
+ ASSERT_EQ(lastBroadcastNumber, intValue);
+ // check, if broadcast is handled after method call
+ ASSERT_EQ(outInt, 1);
+ }
+};
+
+TEST_F(MainLoopTest, VerifyTransportReadingWhenDispatchingWatches) {
+ auto proxy = mainloopFactoryProxy_->buildProxy<commonapi::tests::TestInterfaceProxy>(testAddress8);
+ ASSERT_TRUE((bool) proxy);
+
+ std::thread stubThread = std::thread([&](){ mainLoopForStub_->run(); });
+
+ while (!proxy->isAvailable()) {
+ mainLoopForProxy_->doSingleIteration();
+ usleep(500);
+ }
+
+ ASSERT_TRUE(proxy->isAvailable());
+
+ mainLoopForStub_->stop();
+ stubThread.join();
+
+ uint32_t uint32Value = 42;
+ std::string stringValue = "Hai :)";
+ bool running = true;
+
+ commonapi::tests::DerivedTypeCollection::TestEnumExtended2 testEnumExtended2InValue =
+ commonapi::tests::DerivedTypeCollection::TestEnumExtended2::E_OK;
+ commonapi::tests::DerivedTypeCollection::TestMap testMapInValue;
+
+ // Estimated amount of data (differring padding at beginning/end of Map/Array etc. not taken into account):
+ // 4 + 4 + 500 * (4 + (4 + 4 + 100 * (11 + 1 + 4)) + 4 ) = 811008
+ for (uint32_t i = 0; i < 500; ++i) {
+ commonapi::tests::DerivedTypeCollection::TestArrayTestStruct testArrayTestStruct;
+ for (uint32_t j = 0; j < 100; ++j) {
+ commonapi::tests::DerivedTypeCollection::TestStruct testStruct("Hai all (:", j);
+ testArrayTestStruct.push_back(testStruct);
+ }
+ testMapInValue.insert( {i, testArrayTestStruct});
+ }
+
+ std::future<CommonAPI::CallStatus> futureStatus =
+ proxy->testDerivedTypeMethodAsync(
+ testEnumExtended2InValue,
+ testMapInValue,
+ [&] (const CommonAPI::CallStatus& status,
+ commonapi::tests::DerivedTypeCollection::TestEnumExtended2 testEnumExtended2OutValue,
+ commonapi::tests::DerivedTypeCollection::TestMap testMapOutValue) {
+ mainLoopForProxy_->stop();
+ callbackCalled++;
+ }
+ );
+
+ mainLoopForProxy_->runVerification(15, true, true);
+
+ // 1. just dispatch dispatchSources
+ mainLoopForStub_->runVerification(15, false, true);
+ EXPECT_EQ(stub_->getCalledTestDerivedTypeMethod(), 0);
+
+ // 2. just dispatch watches (reads transport)
+ mainLoopForStub_->runVerification(20, true, false);
+ EXPECT_EQ(stub_->getCalledTestDerivedTypeMethod(), 0);
+
+ // 3. just dispatch dispatchSources again. This should dispatch the messages already read from transport in 2.
+ mainLoopForStub_->doVerificationIteration(false, true);
+ EXPECT_EQ(stub_->getCalledTestDerivedTypeMethod(), 1);
+}
+
+TEST_F(MainLoopTest, VerifySyncCallMessageHandlingOrder) {
+ auto proxy = mainloopFactoryProxy_->buildProxy<commonapi::tests::TestInterfaceProxy>(testAddress8);
+ ASSERT_TRUE((bool) proxy);
+
+ std::thread stubThread = std::thread([&](){ mainLoopForStub_->run(); });
+
+ while (!proxy->isAvailable()) {
+ mainLoopForProxy_->doSingleIteration();
+ usleep(500);
+ }
+
+ ASSERT_TRUE(proxy->isAvailable());
+
+ auto& broadcastEvent = proxy->getTestPredefinedTypeBroadcastEvent();
+ broadcastEvent.subscribe(std::bind(&MainLoopTest::broadcastCallback, this, std::placeholders::_1, std::placeholders::_2));
+
+ CommonAPI::CallStatus callStatus;
+ std::string outString;
+
+ proxy->testPredefinedTypeMethod(0, "", callStatus, outInt, outString);
+ ASSERT_EQ(outInt, 1);
+
+ for (int i = 0; i < 10000; i++) {
+ mainLoopForProxy_->doSingleIteration(100);
+ }
+
+ sleep(10);
+
+ mainLoopForProxy_->stop();
+ mainLoopForStub_->stop();
+
+ stubThread.join();
+
+ // in total 5 broadcasts should have been arrived
+ ASSERT_EQ(lastBroadcastNumber, 5);
+}
+
+TEST_F(MainLoopTest, SyncCallsDoNotDeadlock) {
+ auto proxy = mainloopFactoryProxy_->buildProxy<commonapi::tests::TestInterfaceProxy>(testAddress8);
+ ASSERT_TRUE((bool) proxy);
+
+ std::thread stubThread = std::thread([&]() {mainLoopForStub_->run();});
+
+ // let the proxy become available
+ while (!proxy->isAvailable()) {
+ mainLoopForProxy_->doSingleIteration();
+ usleep(500);
+ }
+
+ uint32_t inInt, outInt;
+ std::string inStr, outStr;
+ inInt = 1;
+ outInt = 0;
+
+ callStatus = CommonAPI::CallStatus::REMOTE_ERROR;
+
+ std::thread syncCallThread = std::thread(
+ [&]() {proxy->testPredefinedTypeMethod(inInt, inStr, callStatus, outInt, outStr);}
+ );
+
+ sleep(10);
+
+ ASSERT_EQ(CommonAPI::CallStatus::SUCCESS, callStatus);
+
+ if (callStatus != CommonAPI::CallStatus::SUCCESS) {
+ mainLoopForProxy_->runVerification(10, true, true); // run the mainloop again in order to give the syncCallThread a chance to return
+ }
+ mainLoopForStub_->stop();
+ stubThread.join();
+ syncCallThread.join();
+}
+
+class MainLoopThreadContext {
+public:
+ void setupRuntime(std::promise<bool>& p) {
+ runtime_ = CommonAPI::Runtime::load();
+ p.set_value(true);
+ }
+
+ void setupMainLoopContext(std::promise<bool>& p) {
+ mainLoopContext_ = runtime_->getNewMainLoopContext();
+ mainLoop_ = new CommonAPI::VerificationMainLoop(mainLoopContext_);
+ p.set_value(true);
+ }
+
+ void setupFactory(std::promise<bool>& p) {
+ factory_ = runtime_->createFactory(mainLoopContext_);
+ servicePublisher_ = runtime_->getServicePublisher();
+ p.set_value(true);
+ }
+
+ void setAddresses(const std::string own, const std::string other, const std::string thirdParty) {
+ ownAddress_ = own;
+ otherAddress_ = other;
+ thirdPartyAddress_ = thirdParty;
+ }
+
+ void createProxyAndStub() {
+ stub_ = std::make_shared<PingPongTestStub>();
+ ASSERT_TRUE(servicePublisher_->registerService(stub_, ownAddress_, factory_));
+ proxy_ = factory_->buildProxy<commonapi::tests::TestInterfaceProxy>(otherAddress_);
+ ASSERT_TRUE((bool)proxy_);
+ proxyThirdParty_ = factory_->buildProxy<commonapi::tests::TestInterfaceProxy>(thirdPartyAddress_);
+ ASSERT_TRUE((bool)proxyThirdParty_);
+ }
+
+ std::shared_ptr<CommonAPI::Runtime> runtime_;
+ std::shared_ptr<CommonAPI::MainLoopContext> mainLoopContext_;
+ std::shared_ptr<CommonAPI::Factory> factory_;
+ std::shared_ptr<CommonAPI::ServicePublisher> servicePublisher_;
+ std::string ownAddress_, otherAddress_, thirdPartyAddress_;
+ std::shared_ptr<PingPongTestStub> stub_;
+ std::shared_ptr<commonapi::tests::TestInterfaceProxy<>> proxy_, proxyThirdParty_;
+
+ CommonAPI::VerificationMainLoop* mainLoop_;
+};
+
+class MainLoopIndependenceTest: public ::testing::Test {
+protected:
+ void SetUp() {
+ std::shared_ptr<CommonAPI::Runtime> runtimePtr1_, runtimePtr2_;
+
+ std::promise<bool> promiseRuntime1, promiseRuntime2;
+ std::future<bool> futureRuntime1 = promiseRuntime1.get_future();
+ std::future<bool> futureRuntime2 = promiseRuntime2.get_future();
+
+ mainLoopThread1_ = std::thread(
+ std::bind(&MainLoopThreadContext::setupRuntime, &threadCtx1_, std::move(promiseRuntime1)));
+ mainLoopThread2_ = std::thread(
+ std::bind(&MainLoopThreadContext::setupRuntime, &threadCtx2_, std::move(promiseRuntime2)));
+
+ mainLoopThread1_.detach();
+ mainLoopThread2_.detach();
+
+ futureRuntime1.wait_for(std::chrono::milliseconds(200));
+ futureRuntime2.wait_for(std::chrono::milliseconds(200));
+
+ // check that both threads have a runtime and it is the same
+ ASSERT_TRUE((bool)threadCtx1_.runtime_);
+ ASSERT_TRUE((bool)threadCtx2_.runtime_);
+ ASSERT_EQ(threadCtx1_.runtime_, threadCtx2_.runtime_);
+
+ std::promise<bool> promiseContext1, promiseContext2;
+ std::future<bool> futureContext1 = promiseContext1.get_future();
+ std::future<bool> futureContext2 = promiseContext2.get_future();
+
+ mainLoopThread1_ = std::thread(
+ std::bind(
+ &MainLoopThreadContext::setupMainLoopContext,
+ &threadCtx1_,
+ std::move(promiseContext1)));
+ mainLoopThread2_ = std::thread(
+ std::bind(
+ &MainLoopThreadContext::setupMainLoopContext,
+ &threadCtx2_,
+ std::move(promiseContext2)));
+
+ mainLoopThread1_.detach();
+ mainLoopThread2_.detach();
+
+ futureContext1.wait_for(std::chrono::milliseconds(200));
+ futureContext2.wait_for(std::chrono::milliseconds(200));
+
+ // check that both threads have an own mainloop context
+ ASSERT_TRUE((bool)threadCtx1_.mainLoopContext_);
+ ASSERT_TRUE((bool)threadCtx2_.mainLoopContext_);
+ ASSERT_NE(threadCtx1_.mainLoopContext_, threadCtx2_.mainLoopContext_);
+
+ std::promise<bool> promiseFactory1, promiseFactory2;
+ std::future<bool> futureFactory1 = promiseFactory1.get_future();
+ std::future<bool> futureFactory2 = promiseFactory2.get_future();
+
+ mainLoopThread1_ = std::thread(
+ std::bind(&MainLoopThreadContext::setupFactory, &threadCtx1_, std::move(promiseFactory1)));
+ mainLoopThread2_ = std::thread(
+ std::bind(&MainLoopThreadContext::setupFactory, &threadCtx2_, std::move(promiseFactory2)));
+
+ mainLoopThread1_.detach();
+ mainLoopThread2_.detach();
+
+ futureFactory1.wait_for(std::chrono::milliseconds(200));
+ futureFactory2.wait_for(std::chrono::milliseconds(200));
+
+ // check that both threads have a factory and a service publisher
+ ASSERT_TRUE((bool)threadCtx1_.factory_);
+ ASSERT_TRUE((bool)threadCtx2_.factory_);
+ ASSERT_TRUE((bool)threadCtx1_.servicePublisher_);
+ ASSERT_TRUE((bool)threadCtx2_.servicePublisher_);
+
+ // set addresses
+ threadCtx1_.setAddresses(testAddress7, testAddress8, testAddress6);
+ threadCtx2_.setAddresses(testAddress8, testAddress7, testAddress6);
+
+ threadCtx1_.createProxyAndStub();
+ threadCtx2_.createProxyAndStub();
+
+ mainLoopThread1_ = std::thread([&]() {threadCtx1_.mainLoop_->run();});
+ mainLoopThread2_ = std::thread([&]() {threadCtx2_.mainLoop_->run();});
+
+ usleep(200000);
+
+ ASSERT_TRUE(threadCtx1_.proxy_->isAvailable());
+ ASSERT_TRUE(threadCtx2_.proxy_->isAvailable());
+
+ threadCtx1_.mainLoop_->stop();
+ threadCtx2_.mainLoop_->stop();
+
+ mainLoopThread1_.join();
+ mainLoopThread2_.join();
+ }
+
+ void TearDown() {
+ threadCtx1_.servicePublisher_->unregisterService(testAddress6);
+ threadCtx1_.servicePublisher_->unregisterService(testAddress7);
+ threadCtx2_.servicePublisher_->unregisterService(testAddress8);
+ usleep(2000);
+ threadCtx1_.mainLoop_->stop();
+ threadCtx2_.mainLoop_->stop();
+
+ if (mainLoopThread1_.joinable()) {
+ mainLoopThread1_.join();
+ }
+ if (mainLoopThread2_.joinable()) {
+ mainLoopThread2_.join();
+ }
+ }
+
+ MainLoopThreadContext threadCtx1_, threadCtx2_;
+ std::thread mainLoopThread1_, mainLoopThread2_;
+};
+
+TEST_F(MainLoopIndependenceTest, ProxyReceivesAnswerOnlyIfStubMainLoopRuns) {
+ CommonAPI::CallStatus callStatus;
+
+ uint32_t inInt, outInt;
+ std::string inStr, outStr;
+ inInt = 1;
+ outInt = 0;
+
+ std::thread mainLoopRunnerProxy([&]() {threadCtx1_.mainLoop_->runVerification(5, true, true);});
+ mainLoopRunnerProxy.detach();
+
+ mainLoopThread1_ = std::thread([&]() {threadCtx1_.proxy_->testPredefinedTypeMethod(inInt, inStr, callStatus, outInt, outStr);});
+ mainLoopThread1_.detach();
+
+ sleep(1);
+ // proxy should not receive answer, if the stub mainloop does not run
+ ASSERT_EQ(0, outInt);
+
+ mainLoopThread2_ = std::thread([&]() {threadCtx2_.mainLoop_->run();});
+ mainLoopThread2_.detach();
+
+ sleep(1);
+
+ // now the stub mainloop also runs, so the proxy should receive the answer
+ ASSERT_EQ(1, outInt);
+}
+
+TEST_F(MainLoopIndependenceTest, ProxyReceivesJustHisOwnAnswers) {
+ std::shared_ptr<PingPongTestStub> stubThirdParty = std::make_shared<PingPongTestStub>();
+ auto runtime = CommonAPI::Runtime::load();
+ ASSERT_TRUE(runtime->getServicePublisher()->registerService(
+ stubThirdParty,
+ testAddress6,
+ runtime->createFactory()));
+
+ CommonAPI::CallStatus callStatusProxy1, callStatusProxy2;
+
+ uint32_t inIntProxy1, outIntProxy1, inIntProxy2, outIntProxy2;
+ std::string inStrProxy1, outStrProxy1, inStrProxy2, outStrProxy2;
+ inIntProxy1 = 1;
+ inIntProxy2 = 2;
+ outIntProxy1 = outIntProxy2 = 0;
+
+ std::thread mainLoopRunnerProxy1([&]() {threadCtx1_.mainLoop_->run();});
+ std::thread mainLoopRunnerProxy2([&]() {threadCtx2_.mainLoop_->run();});
+ mainLoopRunnerProxy1.detach();
+ mainLoopRunnerProxy2.detach();
+
+ while (!(threadCtx1_.proxyThirdParty_->isAvailable() && threadCtx2_.proxyThirdParty_->isAvailable())) {
+ usleep(5000);
+ }
+
+ mainLoopThread1_ = std::thread([&]() {threadCtx1_.proxyThirdParty_->testPredefinedTypeMethod(inIntProxy1, inStrProxy1, callStatusProxy1, outIntProxy1, outStrProxy1);});
+ mainLoopThread2_ = std::thread([&]() {threadCtx2_.proxyThirdParty_->testPredefinedTypeMethod(inIntProxy2, inStrProxy2, callStatusProxy2, outIntProxy2, outStrProxy2);});
+ mainLoopThread1_.detach();
+ mainLoopThread2_.detach();
+
+ sleep(5);
+ // now each proxy should have received the answer to his own request
+ ASSERT_EQ(1, outIntProxy1);
+ ASSERT_EQ(2, outIntProxy2);
+
+ sleep(1);
+}
+
+int main(int argc, char** argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
diff --git a/org.genivi.commonapi.core.verification/src/VerificationMainLoop.h b/org.genivi.commonapi.core.verification/src/utils/VerificationMainLoop.h
index 836f922..0c29589 100644
--- a/org.genivi.commonapi.core.verification/src/VerificationMainLoop.h
+++ b/org.genivi.commonapi.core.verification/src/utils/VerificationMainLoop.h
@@ -38,7 +38,7 @@ class VerificationMainLoop {
explicit VerificationMainLoop(std::shared_ptr<MainLoopContext> context) :
context_(context), currentMinimalTimeoutInterval_(TIMEOUT_INFINITE), running_(false), breakLoop_(false), dispatchWatchesTooLong(false) {
wakeFd_.fd = eventfd(0, EFD_SEMAPHORE | EFD_NONBLOCK);
- wakeFd_.events = POLLIN | POLLOUT;
+ wakeFd_.events = POLLIN;
assert(wakeFd_.fd != -1);
registerFileDescriptor(wakeFd_);
@@ -80,8 +80,6 @@ class VerificationMainLoop {
}
}
-
-
void runVerification(const int64_t& timeoutInterval, bool dispatchTimeoutAndWatches = false, bool dispatchDispatchSources = false) {
running_ = true;
clock_t start = clock();
@@ -204,7 +202,6 @@ class VerificationMainLoop {
}
}
-
for(auto dispatchSourceIterator = registeredDispatchSources_.begin(); dispatchSourceIterator != registeredDispatchSources_.end(); ++dispatchSourceIterator) {
if((std::get<1>(*dispatchSourceIterator))->check()) {
sourcesToDispatch_.insert( {std::get<0>(*dispatchSourceIterator), std::get<1>(*dispatchSourceIterator)});
@@ -227,8 +224,8 @@ class VerificationMainLoop {
bool dispatchWatchesTooLong;
void wakeup() {
- uint32_t wake = 1;
- ::write(wakeFd_.fd, &wake, sizeof(uint32_t));
+ int64_t wake = 1;
+ ::write(wakeFd_.fd, &wake, sizeof(int64_t));
}
void dispatchTimeouts()
@@ -325,7 +322,6 @@ class VerificationMainLoop {
registeredWatches_.erase(watchIterator);
}
}
-
}
void registerTimeout(Timeout* timeout, const DispatchPriority dispatchPriority) {
@@ -345,8 +341,8 @@ class VerificationMainLoop {
}
void acknowledgeWakeup() {
- uint32_t buffer;
- while (::read(wakeFd_.fd, &buffer, sizeof(uint32_t)) == sizeof(buffer));
+ int64_t buffer;
+ while (::read(wakeFd_.fd, &buffer, sizeof(int64_t)) == sizeof(buffer));
}
std::shared_ptr<MainLoopContext> context_;
diff --git a/org.genivi.commonapi.core.verification/src/VerificationTestStub.cpp b/org.genivi.commonapi.core.verification/src/utils/VerificationTestStub.cpp
index f03416d..6a17823 100644
--- a/org.genivi.commonapi.core.verification/src/VerificationTestStub.cpp
+++ b/org.genivi.commonapi.core.verification/src/utils/VerificationTestStub.cpp
@@ -6,6 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "VerificationTestStub.h"
+#include <unistd.h>
namespace commonapi {
namespace verification {
@@ -24,7 +25,8 @@ VerificationTestStub::VerificationTestStub() :
TestInterfaceStubDefault(), calledTestDerivedTypeMethod(0) {
}
-void VerificationTestStub::testPredefinedTypeMethod(uint32_t uint32InValue,
+void VerificationTestStub::testPredefinedTypeMethod(const std::shared_ptr<CommonAPI::ClientId> clientId,
+ uint32_t uint32InValue,
std::string stringInValue,
uint32_t& uint32OutValue,
std::string& stringOutValue) {
@@ -36,7 +38,7 @@ void VerificationTestStub::testPredefinedTypeMethod(uint32_t uint32InValue,
fireTestPredefinedTypeBroadcastEvent(broadcastNumber++, "");
fireTestPredefinedTypeBroadcastEvent(broadcastNumber++, "");
fireTestPredefinedTypeBroadcastEvent(broadcastNumber++, "");
- sleep(10);
+ sleep(5);
}
} /* namespace verification */
diff --git a/org.genivi.commonapi.core.verification/src/VerificationTestStub.h b/org.genivi.commonapi.core.verification/src/utils/VerificationTestStub.h
index 609dc48..09d9b14 100644
--- a/org.genivi.commonapi.core.verification/src/VerificationTestStub.h
+++ b/org.genivi.commonapi.core.verification/src/utils/VerificationTestStub.h
@@ -27,7 +27,8 @@ private:
commonapi::tests::DerivedTypeCollection::TestEnumExtended2& testEnumExtended2OutValue,
commonapi::tests::DerivedTypeCollection::TestMap& testMapOutValue);
- virtual void testPredefinedTypeMethod(uint32_t uint32InValue,
+ virtual void testPredefinedTypeMethod(const std::shared_ptr<CommonAPI::ClientId> clientId,
+ uint32_t uint32InValue,
std::string stringInValue,
uint32_t& uint32OutValue,
std::string& stringOutValue);