summaryrefslogtreecommitdiff
path: root/AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp')
-rw-r--r--AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp91
1 files changed, 27 insertions, 64 deletions
diff --git a/AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp b/AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp
index ef42d56..3fde011 100644
--- a/AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp
+++ b/AudioManagerUtilities/test/AmSocketHandlerTest/CAmSocketHandlerTest.cpp
@@ -22,6 +22,7 @@
#include "CAmSocketHandlerTest.h"
#include <cstdio>
+#include <cstring>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
@@ -57,12 +58,6 @@ struct TestUserData
float f;
};
-struct TestStressUserData
-{
- CAmSocketHandler &socket;
- std::vector<sh_pollHandle_t> &handles;
-};
-
MockIAmSignalHandler *pMockSignalHandler = NULL;
static void signalHandler(int sig, siginfo_t *siginfo, void *context)
{
@@ -317,26 +312,6 @@ void* threadCallbackUnixSocketAndTimers(void* data)
return sendTestData(sock, (struct sockaddr*)&servAddr, sizeof(servAddr), 500000);
}
-void* threadRaceFd(void* pData)
-{
- struct TestStressUserData data = *(struct TestStressUserData*)pData;
- usleep(50000);
- auto elem = data.handles.begin();
- std::advance(elem, data.handles.size() / 2);
- data.socket.removeFDPoll(*elem, sh_rmv_e::RMV_N_CLS);
- data.handles.erase(elem);
-
- return NULL;
-}
-void* threadEnd(void* pData)
-{
- struct TestStressUserData data = *(struct TestStressUserData*)pData;
- usleep(1000000);
- data.socket.exit_mainloop();
-
- return NULL;
-}
-
TEST(CAmSocketHandlerTest, stressTestUnixSocketAndTimers)
{
@@ -375,55 +350,41 @@ TEST(CAmSocketHandlerTest, stressTestUnixSocketAndTimers)
}
-TEST(CAmSocketHandlerTest, fdStressTest)
+TEST(CAmSocketHandlerTest, fdTest)
{
CAmSocketHandler myHandler;
ASSERT_FALSE(myHandler.fatalErrorOccurred());
- //Check unkonw systemd fd ids
- sh_pollHandle_t handle;
- EXPECT_EQ(myHandler.addFDPoll(100, 0, NULL, NULL, NULL, NULL, NULL, handle), E_NON_EXISTENT);
-
- int fd(-1);
- std::vector<sh_pollHandle_t> handles(10);
- for (auto& hndl : handles)
- {
- fd = eventfd(0, 0);
- ASSERT_EQ(myHandler.addFDPoll(fd, POLL_IN, NULL, NULL, NULL, NULL, NULL, hndl), E_OK);
- }
-
- // remove/add check
- ASSERT_EQ(myHandler.addFDPoll(fd, POLL_IN, NULL, NULL, NULL, NULL, NULL, handles.back()), E_ALREADY_EXISTS);
- ASSERT_EQ(myHandler.removeFDPoll(handles.back()), E_OK);
- ASSERT_EQ(myHandler.addFDPoll(fd, POLL_IN, NULL, NULL, NULL, NULL, NULL, handles.back()), E_OK);
-
- // create a copy to check if all handles are removed
- std::vector<sh_pollHandle_t> handlesCheckup(handles);
+ // for some simple fd tests
+ timespec endTime{0, 100000000}; // 0,1
+ timespec timeoutTime{0, 10000000}; // 0,01
- while (handles.size())
- {
- pthread_t tid1, tid2;
+ // check unknown system fd ids
+ sh_pollHandle_t handle;
+ ASSERT_EQ(myHandler.addFDPoll(100, 0, NULL, NULL, NULL, NULL, NULL, handle), E_NON_EXISTENT);
- // this removes an element before starting the socket handler and we
- // erase the last handle
- myHandler.removeFDPoll(handles.back(), sh_rmv_e::RMV_N_CLS);
- handles.erase(handles.end()-1);
+ // add/remove/add check of same fd
+ int fd = eventfd(0, 0);
+ ASSERT_EQ(myHandler.addFDPoll(fd, POLL_IN, NULL, NULL, NULL, NULL, NULL, handle), E_OK);
+ ASSERT_EQ(myHandler.addFDPoll(fd, POLL_IN, NULL, NULL, NULL, NULL, NULL, handle), E_ALREADY_EXISTS);
+ ASSERT_EQ(myHandler.removeFDPoll(handle), E_OK);
+ close(fd);
- TestStressUserData data = {myHandler, handles};
- pthread_create(&tid1, NULL, threadEnd, &data);
+ // Create x handles
+ TestUserData userData{1, 1.f};
+ CAmTimerStressTest timer(&myHandler, timeoutTime, 0);
- // erase the handle in the middle
- pthread_create(&tid2, NULL, threadRaceFd, &data);
+ ASSERT_EQ(myHandler.addTimer(timeoutTime, &timer.pTimerCallback, handle, &userData, true), E_OK);
+ EXPECT_CALL(timer, timerCallback(_,&userData)).Times(AnyNumber());
- myHandler.start_listenting();
+ // for some simple fd tests
+ CAmTimerSockethandlerController endCallback(&myHandler, endTime);
+ ASSERT_EQ(myHandler.addTimer(endTime, &endCallback.pTimerCallback, handle, NULL), E_OK);
+ EXPECT_CALL(endCallback,timerCallback(handle,NULL)).Times(Exactly(1));
- pthread_join(tid2, NULL);
- pthread_join(tid1, NULL);
- }
+ myHandler.start_listenting();
- // now do the check
- for (auto& hndl : handlesCheckup)
- EXPECT_EQ(myHandler.removeFDPoll(hndl), E_UNKNOWN) << "Handle " << hndl << " not correctly removed before";
+ ASSERT_FALSE(myHandler.fatalErrorOccurred());
}
TEST(CAmSocketHandlerTest, timersOneshot)
@@ -614,6 +575,8 @@ TEST(CAmSocketHandlerTest, timersStressTest)
{
delete timer, timer = NULL;
}
+
+ EXPECT_FALSE(myHandler.fatalErrorOccurred());
}