summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Laner <laner@itestra.de>2013-08-08 11:57:22 +0200
committerJohannes Schanda <schanda@itestra.de>2013-08-08 11:57:22 +0200
commitb4540c9d571710af286d93304ff0fa960a851f33 (patch)
tree6b2a472d3d4abaa1a3b59521b7d26928f185f549
parent3f07013210595189c54736a5a04581b2e93c2827 (diff)
downloadgenivi-common-api-runtime-b4540c9d571710af286d93304ff0fa960a851f33.tar.gz
Implemented test for checking method handling with sync call in
mainloops. Change-Id: If83380cd12e8f237c5d6705acbbe01b435cd83d4
-rw-r--r--org.genivi.commonapi.core.verification/Makefile.am8
-rw-r--r--org.genivi.commonapi.core.verification/README24
-rw-r--r--org.genivi.commonapi.core.verification/src/MainLoopTest.cpp61
-rw-r--r--org.genivi.commonapi.core.verification/src/VerificationTestStub.cpp20
-rw-r--r--org.genivi.commonapi.core.verification/src/VerificationTestStub.h12
5 files changed, 106 insertions, 19 deletions
diff --git a/org.genivi.commonapi.core.verification/Makefile.am b/org.genivi.commonapi.core.verification/Makefile.am
index 5d14f78..92af417 100644
--- a/org.genivi.commonapi.core.verification/Makefile.am
+++ b/org.genivi.commonapi.core.verification/Makefile.am
@@ -2,14 +2,18 @@ ACLOCAL_AMFLAGS = -I m4
AM_CPPFLAGS = \
-I$(top_srcdir)/src \
+ -I${GLUE_PATH}/src-gen \
-I$(includedir) \
${GLUE_CFLAGS} \
${COMMONAPI_CFLAGS} \
${GTEST_CPPFLAGS}
-bin_PROGRAMS = \
+check_PROGRAMS = \
verification
+
+TESTS = ${check_PROGRAMS}
+
verification_SOURCES = \
src/VerificationTestStub.h \
src/VerificationTestStub.cpp \
@@ -17,4 +21,4 @@ verification_SOURCES = \
verification_CPPFLAGS = ${AM_CPPFLAGS}
verification_LDADD = ${COMMONAPI_LIBS} ${GLUE_LIBS} ${GTEST_LIBS}
-verification_LDFLAGS = ${GLUE_LDFLAGS} \ No newline at end of file
+verification_LDFLAGS = ${GLUE_LDFLAGS}
diff --git a/org.genivi.commonapi.core.verification/README b/org.genivi.commonapi.core.verification/README
index 3cdd660..c034257 100644
--- a/org.genivi.commonapi.core.verification/README
+++ b/org.genivi.commonapi.core.verification/README
@@ -37,6 +37,8 @@ src directory within that project.
There are some configure options that allow you to define the binding that should be tested:
--with-gluecode-path=... specifies the path to your gluecode containing the directories src-gen and .libs.
+In the src-gen directory there must be the generated proxy and stub files (Common-API as well as binding specific ones) from
+the three .fidl files mentioned above. This includes the subdirectory structure src-gen/commonapi/tests
If you want the gluecode to be linked dynamically, use --with-gluecode-so-name=... to name the *.so file. The .so file must reside
within .libs in the gluecode path.
@@ -47,26 +49,30 @@ within .libs in the gluecode path. For statically linked gluecode you also have
statically (*.a) respectively. Use the full path to your binding.
If your binding needs additional libraries, use --binding-extra=... to specify them.
+GTest is needed to compile and run the test. Its confuguration script location must be available
+in the environment variable GTEST_CONFIG.
+
== Usage
1. Generate CommonAPI code for all .fidl files within /src using the code generator. After that you should find the generated files in /src-gen
2. Run autoreconf -i
3. Configure the project to find the gluecode (see also "Description")
+Ensure you have GTEST_CONFIG set to the correct location, e.g. GTEST_CONFIG=/home/user/work/gtest/scripts/gtest-config
Examples:
- a) configure --with-gluecode-path=~/CommonAPI-D-Bus-Tools/org.genivi.commonapi.dbus.verification \
+ a) configure --with-gluecode-path=/home/user/CommonAPI-D-Bus-Tools/org.genivi.commonapi.dbus.verification \
--with-gluecode-so-name=libDBusGlue.so
Uses dynamically linked gluecode file "libDBusGlue.so"
- b) configure --with-gluecode-path=~/CommonAPI-D-Bus-Tools/org.genivi.commonapi.dbus.verification \
+ b) configure --with-gluecode-path=/home/user/CommonAPI-D-Bus-Tools/org.genivi.commonapi.dbus.verification \
--with-gluecode-a-name=libDBusGlue.a \
- --with-binding-so=~/CommonAPI-D-Bus/.libs/libCommonAPI-DBus.so
+ --with-binding-so=/home/user/CommonAPI-D-Bus/.libs/libCommonAPI-DBus.so
Uses statically linked gluecode file "libDBusGlue.a" and dynamically linked binding
- "~/CommonAPI-D-Bus/.libs/libCommonAPI-DBus.so"
- c) configure --with-gluecode-path=~/CommonAPI-D-Bus-Tools/org.genivi.commonapi.dbus.verification \
+ "/home/user/CommonAPI-D-Bus/.libs/libCommonAPI-DBus.so"
+ c) configure --with-gluecode-path=/home/user/CommonAPI-D-Bus-Tools/org.genivi.commonapi.dbus.verification \
--with-gluecode-a-name=libDBusGlue.a \
- --with-binding-a=~/CommonAPI-D-Bus/.libs/libCommonAPI-DBus.a \
- --with-binding-extra=~/libdbus/dbus/.libs/libdbus-1.so
- Uses statically linked gluecode file "libDBusGlue.a" and staticalls linked binding "~/CommonAPI-D-Bus/.libs/libCommonAPI-DBus.a". The binding in this example needs an additional library "~/libdbus/dbus/.libs/libdbus-1.so".
+ --with-binding-a=/home/user/CommonAPI-D-Bus/.libs/libCommonAPI-DBus.a \
+ --with-binding-extra=/home/user/libdbus/dbus/.libs/libdbus-1.so
+ Uses statically linked gluecode file "libDBusGlue.a" and statically linked binding "/home/user/CommonAPI-D-Bus/.libs/libCommonAPI-DBus.a". The binding in this example needs an additional library "/home/user/libdbus/dbus/.libs/libdbus-1.so".
If you do not need that, you can omit the --with-binding-extra option
-4. Run make all
+4. Run make check (Ensure that any glue .so which may be required can be found, for example by setting the LD_LIBRARY_PATH variable)
5. Execute ./verification in order to run the test cases
\ No newline at end of file
diff --git a/org.genivi.commonapi.core.verification/src/MainLoopTest.cpp b/org.genivi.commonapi.core.verification/src/MainLoopTest.cpp
index 44388e7..bebee55 100644
--- a/org.genivi.commonapi.core.verification/src/MainLoopTest.cpp
+++ b/org.genivi.commonapi.core.verification/src/MainLoopTest.cpp
@@ -10,6 +10,7 @@
#include "VerificationMainLoop.h"
#include "commonapi/tests/TestInterfaceProxy.h"
#include "VerificationTestStub.h"
+#include <functional>
const std::string testAddress8 = "local:my.eigth.test:commonapi.address.eight";
@@ -39,6 +40,8 @@ protected:
servicePublisher_ = runtime_->getServicePublisher();
ASSERT_TRUE((bool) servicePublisher_);
callbackCalled = 0;
+ lastBroadcastNumber = 0;
+ outInt = 0;
}
void TearDown() {
@@ -58,6 +61,17 @@ protected:
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) {
@@ -115,19 +129,60 @@ TEST_F(MainLoopTest, VerifyTransportReadingWhenDispatchingWatches) {
// 1. just dispatch dispatchSources
mainLoopStub_->runVerification(15, false, true);
- ASSERT_EQ(stub->getCalled(), 0);
+ ASSERT_EQ(stub->getCalledTestDerivedTypeMethod(), 0);
// 2. just dispatch watches (reads transport)
mainLoopStub_->runVerification(20, true, false);
- ASSERT_EQ(stub->getCalled(), 0);
+ 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->getCalled(), 1);
+ 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/VerificationTestStub.cpp b/org.genivi.commonapi.core.verification/src/VerificationTestStub.cpp
index d1006a8..59b23f2 100644
--- a/org.genivi.commonapi.core.verification/src/VerificationTestStub.cpp
+++ b/org.genivi.commonapi.core.verification/src/VerificationTestStub.cpp
@@ -17,11 +17,27 @@ void VerificationTestStub::testDerivedTypeMethod(
commonapi::tests::DerivedTypeCollection::TestMap& testMapOutValue) {
testEnumExtended2OutValue = testEnumExtended2InValue;
testMapOutValue = testMapInValue;
- called++;
+ calledTestDerivedTypeMethod++;
}
VerificationTestStub::VerificationTestStub() :
- TestInterfaceStubDefault(), called(0) {
+ TestInterfaceStubDefault(), calledTestDerivedTypeMethod(0) {
+}
+
+void VerificationTestStub::testPredefinedTypeMethod(const CommonAPI::ClientId& clientId,
+ uint32_t uint32InValue,
+ std::string stringInValue,
+ uint32_t& uint32OutValue,
+ std::string& stringOutValue) {
+ uint32OutValue = 1;
+ int broadcastNumber = 1;
+
+ fireTestPredefinedTypeBroadcastEvent(broadcastNumber++, "");
+ fireTestPredefinedTypeBroadcastEvent(broadcastNumber++, "");
+ fireTestPredefinedTypeBroadcastEvent(broadcastNumber++, "");
+ fireTestPredefinedTypeBroadcastEvent(broadcastNumber++, "");
+ fireTestPredefinedTypeBroadcastEvent(broadcastNumber++, "");
+ sleep(10);
}
} /* namespace verification */
diff --git a/org.genivi.commonapi.core.verification/src/VerificationTestStub.h b/org.genivi.commonapi.core.verification/src/VerificationTestStub.h
index 8b5e8b1..4723d4b 100644
--- a/org.genivi.commonapi.core.verification/src/VerificationTestStub.h
+++ b/org.genivi.commonapi.core.verification/src/VerificationTestStub.h
@@ -17,8 +17,8 @@ class VerificationTestStub : public commonapi::tests::TestInterfaceStubDefault {
public:
VerificationTestStub();
- int getCalled() const {
- return called;
+ int getCalledTestDerivedTypeMethod() const {
+ return calledTestDerivedTypeMethod;
}
private:
virtual void testDerivedTypeMethod(
@@ -27,7 +27,13 @@ private:
commonapi::tests::DerivedTypeCollection::TestEnumExtended2& testEnumExtended2OutValue,
commonapi::tests::DerivedTypeCollection::TestMap& testMapOutValue);
- int called;
+ virtual void testPredefinedTypeMethod(const CommonAPI::ClientId& clientId,
+ uint32_t uint32InValue,
+ std::string stringInValue,
+ uint32_t& uint32OutValue,
+ std::string& stringOutValue);
+
+ int calledTestDerivedTypeMethod;
};
} /* namespace verification */