summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksandar Donchev <Aleksander.Donchev@partner.bmw.de>2017-09-25 17:01:18 +0200
committerJacqueline Molz <Jacqueline.Molz@bmw.de>2018-02-13 12:47:47 +0100
commitcfe0e77aaf87a0590ceea42f6afa62b0c7d95e80 (patch)
treeb6b83b5bd2b2f2bb98303e52a186d55b0d5af0cb
parentbcaeed20bbbb4375ae925d507821d2bef64e737b (diff)
downloadaudiomanager-cfe0e77aaf87a0590ceea42f6afa62b0c7d95e80.tar.gz
Timer fd is closed at the beginning of the next iteration + some unit tests.
Signed-off-by: Christian Linke <christian.linke@bmw.de> Change-Id: I8c5d3c436ac9fad62c76a26145c731b538abb1e7
-rw-r--r--AudioManagerUtilities/include/CAmSocketHandler.h11
-rw-r--r--AudioManagerUtilities/src/CAmSocketHandler.cpp103
-rw-r--r--AudioManagerUtilities/test/AmSerializerTest/CAmSerializerTest.cpp7
-rw-r--r--AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp229
-rw-r--r--AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.h72
5 files changed, 378 insertions, 44 deletions
diff --git a/AudioManagerUtilities/include/CAmSocketHandler.h b/AudioManagerUtilities/include/CAmSocketHandler.h
index 717f792..7baa496 100644
--- a/AudioManagerUtilities/include/CAmSocketHandler.h
+++ b/AudioManagerUtilities/include/CAmSocketHandler.h
@@ -244,10 +244,11 @@ class CAmSocketHandler
sh_timer_s() :
handle(0)
#ifdef WITH_TIMERFD
- , fd(0)
+ , fd(-1)
#endif
, countdown(), callback(), userData(0)
{}
+
};
struct sh_signal_s
@@ -291,7 +292,11 @@ class CAmSocketHandler
VectorListPoll_t mListPoll; //!<list that holds all information for the ppoll
sh_identifier_s mSetTimerKeys; //!A set of all used timer keys
std::list<sh_timer_s> mListTimer; //!<list of all timers
+#ifndef WITH_TIMERFD
std::list<sh_timer_s> mListActiveTimer; //!<list of all currently active timers
+#else
+ std::list<sh_timer_s> mListRemovedTimers;
+#endif
sh_identifier_s mSetSignalhandlerKeys; //!A set of all used signal handler keys
VectorSignalHandlers_t mSignalHandlers;
bool mRecreatePollfds; //!<when this is true, the poll list needs to be recreated
@@ -306,7 +311,7 @@ private:
timespec* insertTime(timespec& buffertime);
#ifdef WITH_TIMERFD
am_Error_e createTimeFD(const itimerspec & timeouts, int & fd);
-
+ void closeRemovedTimers();
#else
void timerUp();
void timerCorrection();
@@ -446,7 +451,7 @@ private:
bool nextHandle(sh_identifier_s & handle);
am_Error_e getFDPollData(const sh_pollHandle_t handle, sh_poll_s & outPollData);
-
+
public:
CAmSocketHandler();
diff --git a/AudioManagerUtilities/src/CAmSocketHandler.cpp b/AudioManagerUtilities/src/CAmSocketHandler.cpp
index fad60e5..943a80c 100644
--- a/AudioManagerUtilities/src/CAmSocketHandler.cpp
+++ b/AudioManagerUtilities/src/CAmSocketHandler.cpp
@@ -44,20 +44,24 @@ namespace am
CAmSocketHandler::CAmSocketHandler() :
mPipe(), //
- mDispatchDone(true), //
- mSetPollKeys(MAX_POLLHANDLE), //
- mListPoll(), //
- mSetTimerKeys(MAX_TIMERHANDLE),
- mListTimer(), //
- mListActiveTimer(), //
- mSetSignalhandlerKeys(MAX_POLLHANDLE), //
- mSignalHandlers(), //
- mRecreatePollfds(true),
- mInternalCodes(internal_codes_e::NO_ERROR),
- mSignalFdHandle(0)
-#ifndef WITH_TIMERFD
-,mStartTime() //
-#endif
+ mDispatchDone(true), //
+ mSetPollKeys(MAX_POLLHANDLE), //
+ mListPoll(), //
+ mSetTimerKeys(MAX_TIMERHANDLE),
+ mListTimer(), //
+ #ifndef WITH_TIMERFD
+ mListActiveTimer(), //
+ #else
+ mListRemovedTimers(),
+ #endif
+ mSetSignalhandlerKeys(MAX_POLLHANDLE), //
+ mSignalHandlers(), //
+ mRecreatePollfds(true),
+ mInternalCodes(internal_codes_e::NO_ERROR),
+ mSignalFdHandle(0)
+ #ifndef WITH_TIMERFD
+ ,mStartTime() //
+ #endif
{
if (pipe(mPipe) == -1)
{
@@ -80,6 +84,9 @@ CAmSocketHandler::CAmSocketHandler() :
CAmSocketHandler::~CAmSocketHandler()
{
+#ifdef WITH_TIMERFD
+ closeRemovedTimers();
+#endif
for (auto it : mListPoll)
{
close(it.pollfdValue.fd);
@@ -118,6 +125,9 @@ void CAmSocketHandler::start_listenting()
{
if (mRecreatePollfds)
{
+ #ifdef WITH_TIMERFD
+ closeRemovedTimers();
+ #endif
fdPollingArray.clear();
//freeze mListPoll by copying it - otherwise we get problems when we want to manipulate it during the next lines
cloneListPoll = mListPoll;
@@ -350,9 +360,14 @@ am_Error_e CAmSocketHandler::listenToSignals(const std::vector<uint8_t> & listSi
* @return E_OK if the descriptor was added, E_NON_EXISTENT if the fd is not valid
*/
-am_Error_e CAmSocketHandler::addFDPoll(const int fd, const short event, std::function<void(const sh_pollHandle_t handle, void* userData)> prepare,
- std::function<void(const pollfd pollfd, const sh_pollHandle_t handle, void* userData)> fired, std::function<bool(const sh_pollHandle_t handle, void* userData)> check,
- std::function<bool(const sh_pollHandle_t handle, void* userData)> dispatch, void* userData, sh_pollHandle_t& handle)
+am_Error_e CAmSocketHandler::addFDPoll(const int fd,
+ const short event,
+ std::function<void(const sh_pollHandle_t handle, void* userData)> prepare,
+ std::function<void(const pollfd pollfd, const sh_pollHandle_t handle, void* userData)> fired,
+ std::function<bool(const sh_pollHandle_t handle, void* userData)> check,
+ std::function<bool(const sh_pollHandle_t handle, void* userData)> dispatch,
+ void* userData,
+ sh_pollHandle_t& handle)
{
if (!fdIsValid(fd))
return (E_NON_EXISTENT);
@@ -533,7 +548,6 @@ am_Error_e CAmSocketHandler::addTimer(const timespec & timeouts, std::function<v
clock_gettime(CLOCK_MONOTONIC, &currentTime);
if (!mDispatchDone)//the mainloop is started
timerItem.countdown = timespecAdd(timeouts, timespecSub(currentTime, mStartTime));
- mListTimer.push_back(timerItem);
mListActiveTimer.push_back(timerItem);
mListActiveTimer.sort(compareCountdown);
return (E_OK);
@@ -569,12 +583,17 @@ am_Error_e CAmSocketHandler::addTimer(const timespec & timeouts, std::function<v
}
};
- err = addFDPoll(timerItem.fd, POLLIN, NULL, actionPoll, [callback](const sh_pollHandle_t handle, void* userData)->bool
- {
- callback(handle, userData);
- return false;
- },
- NULL, userData, handle);
+ err = addFDPoll(timerItem.fd,
+ POLLIN,
+ NULL,
+ actionPoll,
+ [callback](const sh_pollHandle_t handle, void* userData)->bool{
+ callback(handle, userData);
+ return false;
+ },
+ NULL,
+ userData,
+ handle);
if (E_OK == err)
{
timerItem.handle = handle;
@@ -608,20 +627,22 @@ am_Error_e CAmSocketHandler::removeTimer(const sh_timerHandle_t handle)
if (it == mListTimer.end())
return (E_NON_EXISTENT);
- close(it->fd);
+ mListRemovedTimers.push_back(*it);
mListTimer.erase(it);
return removeFDPoll(handle);
#else
stopTimer(handle);
std::list<sh_timer_s>::iterator it(mListTimer.begin());
- for (; it != mListTimer.end(); ++it)
+ while (it != mListTimer.end())
{
if (it->handle == handle)
{
- it = mListTimer.erase(it);
+ it = mListTimer.erase(it);
mSetTimerKeys.pollHandles.erase(handle);
return (E_OK);
}
+ else
+ ++it;
}
return (E_UNKNOWN);
#endif
@@ -657,7 +678,7 @@ am_Error_e CAmSocketHandler::updateTimer(const sh_timerHandle_t handle, const ti
}
else
{
- if (timerfd_settime(it->fd, 0, &it->countdown, NULL))
+ if (timerfd_settime(it->fd, 0, &it->countdown, NULL)<0)
{
logError("Failed to set timer duration");
return E_NOT_POSSIBLE;
@@ -737,7 +758,7 @@ am_Error_e CAmSocketHandler::restartTimer(const sh_timerHandle_t handle)
}
else
{
- if (timerfd_settime(it->fd, 0, &it->countdown, NULL))
+ if (timerfd_settime(it->fd, 0, &it->countdown, NULL)<0)
{
logError("Failed to set timer duration");
return E_NOT_POSSIBLE;
@@ -811,7 +832,7 @@ am_Error_e CAmSocketHandler::stopTimer(const sh_timerHandle_t handle)
countdown.it_value.tv_nsec = 0;
countdown.it_value.tv_sec = 0;
- if (timerfd_settime(it->fd, 0, &countdown, NULL))
+ if (timerfd_settime(it->fd, 0, &countdown, NULL)<0)
{
logError("Failed to set timer duration");
return E_NOT_POSSIBLE;
@@ -820,13 +841,16 @@ am_Error_e CAmSocketHandler::stopTimer(const sh_timerHandle_t handle)
#else
//go through the list and remove the timer with the handle
std::list<sh_timer_s>::iterator it(mListActiveTimer.begin());
- for (; it != mListActiveTimer.end(); ++it)
+
+ while (it != mListActiveTimer.end())
{
if (it->handle == handle)
{
it = mListActiveTimer.erase(it);
return (E_OK);
}
+ else
+ it++;
}
return (E_NON_EXISTENT);
#endif
@@ -1031,19 +1055,32 @@ inline timespec* CAmSocketHandler::insertTime(timespec& buffertime)
am_Error_e CAmSocketHandler::createTimeFD(const itimerspec & timeouts, int & fd)
{
fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC);
- if (fd <= 0)
+ if (fd < 0)
{
logError("Failed to create timer");
return E_NOT_POSSIBLE;
}
- if (timerfd_settime(fd, 0, &timeouts, NULL))
+ if (timerfd_settime(fd, 0, &timeouts, NULL) < 0)
{
logError("Failed to set timer duration");
return E_NOT_POSSIBLE;
}
return E_OK;
}
+
+void CAmSocketHandler::closeRemovedTimers()
+{
+ std::list<sh_timer_s>::iterator it(mListRemovedTimers.begin());
+ while (it != mListRemovedTimers.end())
+ {
+ if( it->fd > -1 )
+ close( it->fd );
+ ++it;
+ }
+ mListRemovedTimers.clear();
+}
+
#endif
void CAmSocketHandler::callTimer(sh_timer_s& a)
diff --git a/AudioManagerUtilities/test/AmSerializerTest/CAmSerializerTest.cpp b/AudioManagerUtilities/test/AmSerializerTest/CAmSerializerTest.cpp
index 49c6738..b18b284 100644
--- a/AudioManagerUtilities/test/AmSerializerTest/CAmSerializerTest.cpp
+++ b/AudioManagerUtilities/test/AmSerializerTest/CAmSerializerTest.cpp
@@ -79,6 +79,8 @@ struct SerializerData
V2::CAmSerializer *pSerializer;
};
+#define ASYNCLOOP 100
+
void* ptSerializerSync(void* data)
{
SerializerData *pData = (SerializerData*) data;
@@ -96,6 +98,7 @@ void* ptSerializerSync(void* data)
return (NULL);
}
+
void* ptSerializerASync(void* data)
{
SerializerData *pData = (SerializerData*) data;
@@ -106,7 +109,7 @@ void* ptSerializerASync(void* data)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
- for (uint32_t i = 0; i < 5; i++)
+ for (uint32_t i = 0; i < ASYNCLOOP; i++)
{
testStr = pData->testStr;
pData->pSerializer->asyncCall(pData->pSerCb, &MockIAmSerializerCb::dispatchData, i, testStr);
@@ -191,7 +194,7 @@ TEST(CAmSerializerTest, asyncTest)
EXPECT_CALL(serCb,check()).Times(2);
EXPECT_CALL(serCb,checkInt()).Times(1).WillRepeatedly(Return(100));
- for (int i = 0; i < 5; i++)
+ for (int i = 0; i < ASYNCLOOP; i++)
EXPECT_CALL(serCb,dispatchData(i,testStr)).WillOnce(DoAll(ActionDispatchData(), Return(true)));
myHandler.start_listenting();
diff --git a/AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp b/AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp
index ecd38fe..129f896 100644
--- a/AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp
+++ b/AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp
@@ -38,7 +38,8 @@
#define SOCK_PATH "/tmp/mysock"
-#define SOCKET_TEST_LOOPS_COUNT 1000
+#define SOCKET_TEST_LOOPS_COUNT 10
+#define TIMERS_TO_TEST 500
using namespace testing;
using namespace am;
@@ -48,6 +49,11 @@ static const char * TEST_SOCKET_DATA_FINAL = "finish!";
static const std::chrono::time_point<std::chrono::high_resolution_clock> TP_ZERO;
+struct TestUserData
+{
+ int i;
+ float f;
+};
MockIAmSignalHandler *pMockSignalHandler = NULL;
static void signalHandler(int sig, siginfo_t *siginfo, void *context)
@@ -149,6 +155,41 @@ void am::CAmTimer::timerCallback(sh_timerHandle_t handle, void* userData)
}
}
+CAmTimerStressTest::CAmTimerStressTest(CAmSocketHandler *myHandler, const timespec &timeout, const int32_t repeats) :
+ MockIAmTimerCb(), mpSocketHandler(myHandler), mUpdateTimeout(timeout), pTimerCallback(this, &CAmTimerStressTest::timerCallback), mRepeats(repeats), mId(0), mHandle(0)
+{
+}
+
+am::CAmTimerStressTest::~CAmTimerStressTest()
+{
+}
+
+void am::CAmTimerStressTest::timerCallback(sh_timerHandle_t handle, void* pUserData)
+{
+ mpSocketHandler->removeTimer(handle);
+ MockIAmTimerCb::timerCallback(handle, pUserData);
+ sh_timerHandle_t handle1;
+ mpSocketHandler->addTimer(mUpdateTimeout, &pTimerCallback, handle1, &(*((TestUserData*)pUserData)), true);
+}
+
+CAmTimerStressTest2::CAmTimerStressTest2(CAmSocketHandler *myHandler, const timespec &timeout, const int32_t repeats) :
+ MockIAmTimerCb(), mpSocketHandler(myHandler), mUpdateTimeout(timeout), pTimerCallback(this, &CAmTimerStressTest2::timerCallback), mRepeats(repeats), mId(0)
+{
+}
+
+am::CAmTimerStressTest2::~CAmTimerStressTest2()
+{
+}
+
+void am::CAmTimerStressTest2::timerCallback(sh_timerHandle_t handle, void* pUserData)
+{
+ #ifdef ENABLED_SOCKETHANDLER_TEST_OUTPUT
+ std::cout<<"timerCallback handle=" << handle <<std::endl;
+ #endif
+ MockIAmTimerCb::timerCallback(handle, pUserData);
+}
+
+
CAmTimerMeasurment::CAmTimerMeasurment(CAmSocketHandler *myHandler, const timespec &timeout, const std::string & label, const int32_t repeats, void * userData) :
MockIAmTimerCb(), pTimerCallback(this, &CAmTimerMeasurment::timerCallback), //
mSocketHandler(myHandler), mUpdateTimeout(timeout), mUpdateTimePoint(std::chrono::seconds
@@ -220,6 +261,66 @@ void* playWithUnixSocketServer(void* data)
return (NULL);
}
+void* threadCallbackUnixSocketAndTimers(void* data)
+{
+ int socket_ = *((int*)data);
+ struct sockaddr_un servAddr;
+ memset(&servAddr, 0, sizeof(servAddr));
+ strcpy(servAddr.sun_path, SOCK_PATH);
+ servAddr.sun_family = AF_UNIX;
+ sleep(1);
+ if (connect(socket_, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0)
+ {
+ std::cout << "ERROR: connect() failed\n" << std::endl;
+ }
+
+ for (int i = 1; i <= SOCKET_TEST_LOOPS_COUNT; i++)
+ {
+ std::string stringToSend(TEST_SOCKET_DATA);
+ usleep(500000);
+ send(socket_, stringToSend.c_str(), stringToSend.size(), 0);
+ }
+ std::string stringToSend(TEST_SOCKET_DATA_FINAL);
+ send(socket_, stringToSend.c_str(), stringToSend.size(), 0);
+
+ return (NULL);
+}
+
+TEST(CAmSocketHandlerTest, stressTestUnixSocketAndTimers)
+{
+
+ pthread_t serverThread;
+
+ int socket_;
+
+ CAmSocketHandler myHandler;
+ ASSERT_FALSE(myHandler.fatalErrorOccurred());
+ CAmSamplePluginStressTest::sockType_e type = CAmSamplePlugin::UNIX;
+ CAmSamplePluginStressTest myplugin(&myHandler, type);
+
+ EXPECT_CALL(myplugin,receiveData(_,_,_)).Times(SOCKET_TEST_LOOPS_COUNT + 1);
+ EXPECT_CALL(myplugin,dispatchData(_,_)).Times(SOCKET_TEST_LOOPS_COUNT + 1);
+ EXPECT_CALL(myplugin,check(_,_)).Times(SOCKET_TEST_LOOPS_COUNT + 1);
+
+ for(int i=0;i<myplugin.getTimers().size();i++)
+ {
+ EXPECT_CALL(*myplugin.getTimers()[i],timerCallback(_,_)).Times(AnyNumber());
+ }
+
+
+ if ((socket_ = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
+ {
+ std::cout << "socket problem" << std::endl;
+ }
+
+ //creates a thread that handles the serverpart
+ pthread_create(&serverThread, NULL, threadCallbackUnixSocketAndTimers, &socket_);
+
+ myHandler.start_listenting();
+
+ pthread_join(serverThread, NULL);
+}
+
TEST(CAmSocketHandlerTest, timersOneshot)
{
CAmSocketHandler myHandler;
@@ -347,6 +448,73 @@ TEST(CAmSocketHandlerTest, timersGeneral)
myHandler.start_listenting();
}
+TEST(CAmSocketHandlerTest, timersStressTest)
+{
+ CAmSocketHandler myHandler;
+ ASSERT_FALSE(myHandler.fatalErrorOccurred());
+
+ sh_timerHandle_t handle;
+ TestUserData userData;
+ userData.i = 1;
+ userData.f = 1.f;
+
+ timespec timeout4;
+ timeout4.tv_nsec = 0;
+ timeout4.tv_sec = 60;
+
+ timespec timeoutTime;
+ timeoutTime.tv_sec = 0;
+ timeoutTime.tv_nsec = 50000000;// 0,05
+
+ std::vector<CAmTimerStressTest*> timers;
+
+ for(int i=0;i<TIMERS_TO_TEST;i++)
+ {
+ CAmTimerStressTest *ptestCallback1 = new CAmTimerStressTest(&myHandler, timeoutTime, 0);
+ ptestCallback1->setId(i);
+ timers.push_back( ptestCallback1 );
+ myHandler.addTimer(timeoutTime, &(ptestCallback1->pTimerCallback), handle, &userData, true);
+ EXPECT_CALL(*ptestCallback1,timerCallback(_,&userData)).Times(AnyNumber());
+ }
+
+ timespec timeoutTime11, timeout12, timeout13;
+ timeoutTime11.tv_sec = 1;
+ timeoutTime11.tv_nsec = 34000000;
+ CAmTimerMeasurment testCallback11(&myHandler, timeoutTime11, "repeatedCallback 1", std::numeric_limits<int32_t>::max());
+
+ timeout12.tv_nsec = 2000000;
+ timeout12.tv_sec = 0;
+ CAmTimerMeasurment testCallback12(&myHandler, timeout12, "repeatedCallback 2", std::numeric_limits<int32_t>::max());
+
+ timeout13.tv_nsec = 333000000;
+ timeout13.tv_sec = 3;
+ CAmTimerMeasurment testCallback13(&myHandler, timeout13, "oneshotCallback 3");
+
+ myHandler.addTimer(timeoutTime, &testCallback11.pTimerCallback, handle, NULL, true);
+ EXPECT_CALL(testCallback11,timerCallback(_,NULL)).Times(AnyNumber());
+
+ myHandler.addTimer(timeout12, &testCallback12.pTimerCallback, handle, NULL, true);
+ EXPECT_CALL(testCallback12,timerCallback(_,NULL)).Times(AnyNumber());
+
+ myHandler.addTimer(timeout13, &testCallback13.pTimerCallback, handle, NULL);
+ EXPECT_CALL(testCallback13,timerCallback(_,NULL)).Times(AnyNumber());
+
+
+ CAmTimerSockethandlerController testCallback4(&myHandler, timeout4);
+
+ myHandler.addTimer(timeout4, &testCallback4.pTimerCallback, handle, NULL);
+
+ EXPECT_CALL(testCallback4,timerCallback(_,NULL)).Times(1);
+ myHandler.start_listenting();
+
+ for(int i=0;i<TIMERS_TO_TEST;i++)
+ {
+ if(timers[i])
+ delete timers[i], timers[i]=NULL;
+ }
+}
+
+
TEST(CAmSocketHandlerTest,playWithTimers)
{
CAmSocketHandler myHandler;
@@ -719,3 +887,62 @@ bool am::CAmSamplePlugin::check(const sh_pollHandle_t handle, void *userData)
return false;
}
+CAmSamplePluginStressTest::CAmSamplePluginStressTest(CAmSocketHandler *mySocketHandler, sockType_e socketType):CAmSamplePlugin(mySocketHandler,socketType)
+, mTimers()
+{
+ sh_timerHandle_t handle;
+ TestUserData userData;
+ userData.i = 1;
+ userData.f = 1.f;
+ timespec timeoutTime;
+ timeoutTime.tv_sec = 0;
+ timeoutTime.tv_nsec = 500000000;// 0,5
+ for(int i=0;i<TIMERS_TO_TEST;i++)
+ {
+ CAmTimerStressTest2 *ptestCallback1 = new CAmTimerStressTest2(mySocketHandler, timeoutTime, 0);
+ ptestCallback1->setId(i);
+ if(E_OK==mySocketHandler->addTimer(timeoutTime, &(ptestCallback1->pTimerCallback), handle, &userData, true))
+ {
+ mTimers.push_back( ptestCallback1 );
+ ptestCallback1->setHandle(handle);
+ }
+
+ EXPECT_CALL(*ptestCallback1,timerCallback(_,&userData)).Times(AnyNumber());
+ }
+}
+
+CAmSamplePluginStressTest::~CAmSamplePluginStressTest()
+{
+ for(int i=0;i<mTimers.size();i++)
+ {
+ if(mTimers[i])
+ delete mTimers[i], mTimers[i]=NULL;
+ }
+}
+
+void CAmSamplePluginStressTest::receiveData(const pollfd pollfd, const sh_pollHandle_t handle, void* userData)
+{
+ CAmSamplePlugin::receiveData(pollfd, handle, userData);
+
+ sh_timerHandle_t handle1;
+ for(int i=0;i<mTimers.size();i++)
+ {
+ am_Error_e resultRemove = mSocketHandler->removeTimer(mTimers[i]->getHandle());
+ am_Error_e resultAdd = mSocketHandler->addTimer(mTimers[i]->getUpdateTimeout(), &(mTimers[i]->pTimerCallback), handle1, NULL, true);
+ #ifdef ENABLED_SOCKETHANDLER_TEST_OUTPUT
+ std::cout << "receiveData return removeTimer=" << resultRemove << " return addTimer=" << resultAdd <<std::endl;
+ #endif
+ mTimers[i]->setHandle(handle1);
+ }
+}
+
+bool CAmSamplePluginStressTest::dispatchData(const sh_pollHandle_t handle, void* userData)
+{
+ return CAmSamplePlugin::dispatchData( handle, userData);
+}
+
+bool CAmSamplePluginStressTest::check(const sh_pollHandle_t handle, void* userData)
+{
+ return CAmSamplePlugin::check( handle, userData);
+}
+
diff --git a/AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.h b/AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.h
index ba2bf51..269e5da 100644
--- a/AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.h
+++ b/AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.h
@@ -101,20 +101,20 @@ namespace am
UNIX, INET
};
CAmSamplePlugin(CAmSocketHandler *mySocketHandler, sockType_e socketType);
- ~CAmSamplePlugin()
+ virtual ~CAmSamplePlugin()
{
}
;
void connectSocket(const pollfd pollfd, const sh_pollHandle_t handle, void* userData);
- void receiveData(const pollfd pollfd, const sh_pollHandle_t handle, void* userData);
- bool dispatchData(const sh_pollHandle_t handle, void* userData);
- bool check(const sh_pollHandle_t handle, void* userData);
+ virtual void receiveData(const pollfd pollfd, const sh_pollHandle_t handle, void* userData);
+ virtual bool dispatchData(const sh_pollHandle_t handle, void* userData);
+ virtual bool check(const sh_pollHandle_t handle, void* userData);
TAmShPollFired<CAmSamplePlugin> connectFiredCB;
TAmShPollFired<CAmSamplePlugin> receiveFiredCB;
TAmShPollDispatch<CAmSamplePlugin> sampleDispatchCB;
TAmShPollCheck<CAmSamplePlugin> sampleCheckCB;
- private:
+ protected:
CAmSocketHandler *mSocketHandler;
sh_pollHandle_t mConnecthandle, mReceiveHandle;
std::queue<std::string> msgList;
@@ -162,6 +162,54 @@ namespace am
TAmShTimerCallBack<CAmTimer> pTimerCallback;
};
+ class CAmTimerStressTest: public MockIAmTimerCb
+ {
+ CAmSocketHandler *mpSocketHandler;
+ timespec mUpdateTimeout;
+ int32_t mRepeats;
+ int32_t mId;
+ int32_t mHandle;
+ public:
+ explicit CAmTimerStressTest(CAmSocketHandler *SocketHandler, const timespec &timeout, const int32_t repeats = 0u);
+ virtual ~CAmTimerStressTest();
+
+ int32_t getId() { return mId; }
+ void setId(const int32_t id) { mId=id; }
+
+ int32_t getHandle() { return mHandle; }
+ void setHandle(const int32_t id) { mHandle=id; }
+
+ timespec getUpdateTimeout( ) { return mUpdateTimeout; }
+
+ void timerCallback(sh_timerHandle_t handle, void * userData);
+
+ TAmShTimerCallBack<CAmTimerStressTest> pTimerCallback;
+ };
+
+ class CAmTimerStressTest2: public MockIAmTimerCb
+ {
+ CAmSocketHandler *mpSocketHandler;
+ timespec mUpdateTimeout;
+ int32_t mRepeats;
+ int32_t mId;
+ int32_t mHandle;
+ public:
+ explicit CAmTimerStressTest2(CAmSocketHandler *SocketHandler, const timespec &timeout, const int32_t repeats = 0u);
+ virtual ~CAmTimerStressTest2();
+
+ int32_t getId() { return mId; }
+ void setId(const int32_t id) { mId=id; }
+
+ int32_t getHandle() { return mHandle; }
+ void setHandle(const int32_t id) { mHandle=id; }
+
+ timespec getUpdateTimeout( ) { return mUpdateTimeout; }
+
+ void timerCallback(sh_timerHandle_t handle, void * userData);
+
+ TAmShTimerCallBack<CAmTimerStressTest2> pTimerCallback;
+ };
+
class CAmTimerMeasurment: public MockIAmTimerCb
{
CAmSocketHandler *mSocketHandler;
@@ -188,6 +236,20 @@ namespace am
void SetUp();
void TearDown();
};
+
+ class CAmSamplePluginStressTest: public CAmSamplePlugin
+ {
+ std::vector<CAmTimerStressTest2*> mTimers;
+ public:
+ CAmSamplePluginStressTest(CAmSocketHandler *mySocketHandler, sockType_e socketType);
+ ~CAmSamplePluginStressTest();
+
+ virtual void receiveData(const pollfd pollfd, const sh_pollHandle_t handle, void* userData);
+ virtual bool dispatchData(const sh_pollHandle_t handle, void* userData);
+ virtual bool check(const sh_pollHandle_t handle, void* userData);
+
+ std::vector<CAmTimerStressTest2*> & getTimers() { return mTimers; }
+ };
} /* namespace am */
#endif /* SOCKETHANDLERTEST_H_ */