Skip to content

Commit

Permalink
Armed UniqueSocket in file/line grab for creation location
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikołaj Małecki committed Feb 28, 2024
1 parent 278fc72 commit 085043a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
11 changes: 9 additions & 2 deletions test/test_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,22 @@ class TestInit
class UniqueSocket
{
int32_t sock;
std::string lab, f;
int l;

public:
UniqueSocket(int32_t s): sock(s)
UniqueSocket(int32_t s, const char* label, const char* file, int line): sock(s)
{
if (s == -1)
throw std::invalid_argument("Invalid socket");
lab = label;
f = file;
l = line;
}

UniqueSocket(): sock(-1)
#define MAKE_UNIQUE_SOCK(name, label, expr) srt::UniqueSocket name (expr, label, __FILE__, __LINE__)

UniqueSocket(): sock(-1), l(0)
{
}

Expand Down
22 changes: 11 additions & 11 deletions test/test_epoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ TEST(CEPoll, WaitEmptyCall)
{
srt::TestInit srtinit;

srt::UniqueSocket client_sock = srt_create_socket();
MAKE_UNIQUE_SOCK(client_sock, "client", srt_create_socket());
ASSERT_NE(client_sock, SRT_ERROR);

const int no = 0;
Expand All @@ -89,7 +89,7 @@ TEST(CEPoll, UWaitEmptyCall)
{
srt::TestInit srtinit;

srt::UniqueSocket client_sock = srt_create_socket();
MAKE_UNIQUE_SOCK(client_sock, "client", srt_create_socket());
ASSERT_NE(client_sock, SRT_ERROR);

const int no = 0;
Expand All @@ -112,7 +112,7 @@ TEST(CEPoll, WaitAllSocketsInEpollReleased)
{
srt::TestInit srtinit;

srt::UniqueSocket client_sock = srt_create_socket();
MAKE_UNIQUE_SOCK(client_sock, "client", srt_create_socket());
ASSERT_NE(client_sock, SRT_ERROR);

const int yes = 1;
Expand Down Expand Up @@ -146,7 +146,7 @@ TEST(CEPoll, WaitAllSocketsInEpollReleased2)
{
srt::TestInit srtinit;

srt::UniqueSocket client_sock = srt_create_socket();
MAKE_UNIQUE_SOCK(client_sock, "client", srt_create_socket());
ASSERT_NE(client_sock, SRT_ERROR);

const int yes = 1;
Expand Down Expand Up @@ -174,7 +174,7 @@ TEST(CEPoll, WrongEpoll_idOnAddUSock)
{
srt::TestInit srtinit;

srt::UniqueSocket client_sock = srt_create_socket();
MAKE_UNIQUE_SOCK(client_sock, "client", srt_create_socket());
ASSERT_NE(client_sock, SRT_ERROR);

const int no = 0;
Expand All @@ -197,7 +197,7 @@ TEST(CEPoll, HandleEpollEvent)
{
srt::TestInit srtinit;

srt::UniqueSocket client_sock = srt_create_socket();
MAKE_UNIQUE_SOCK(client_sock, "client", srt_create_socket());
EXPECT_NE(client_sock, SRT_ERROR);

const int yes = 1;
Expand Down Expand Up @@ -258,7 +258,7 @@ TEST(CEPoll, NotifyConnectionBreak)
srt::TestInit srtinit;

// 1. Prepare client
srt::UniqueSocket client_sock = srt_create_socket();
MAKE_UNIQUE_SOCK(client_sock, "client", srt_create_socket());
ASSERT_NE(client_sock, SRT_ERROR);

const int yes SRT_ATR_UNUSED = 1;
Expand All @@ -280,7 +280,7 @@ TEST(CEPoll, NotifyConnectionBreak)
ASSERT_EQ(inet_pton(AF_INET, "127.0.0.1", &sa_client.sin_addr), 1);

// 2. Prepare server
srt::UniqueSocket server_sock = srt_create_socket();
MAKE_UNIQUE_SOCK(server_sock, "server_sock", srt_create_socket());
ASSERT_NE(server_sock, SRT_ERROR);

ASSERT_NE(srt_setsockopt(server_sock, 0, SRTO_RCVSYN, &no, sizeof no), SRT_ERROR); // for async connect
Expand Down Expand Up @@ -372,7 +372,7 @@ TEST(CEPoll, HandleEpollEvent2)
{
srt::TestInit srtinit;

srt::UniqueSocket client_sock = srt_create_socket();
MAKE_UNIQUE_SOCK(client_sock, "client", srt_create_socket());
EXPECT_NE(client_sock, SRT_ERROR);

const int yes = 1;
Expand Down Expand Up @@ -433,7 +433,7 @@ TEST(CEPoll, HandleEpollNoEvent)
{
srt::TestInit srtinit;

srt::UniqueSocket client_sock = srt_create_socket();
MAKE_UNIQUE_SOCK(client_sock, "client", srt_create_socket());
EXPECT_NE(client_sock, SRT_ERROR);

const int yes = 1;
Expand Down Expand Up @@ -483,7 +483,7 @@ TEST(CEPoll, ThreadedUpdate)
{
srt::TestInit srtinit;

srt::UniqueSocket client_sock = srt_create_socket();
MAKE_UNIQUE_SOCK(client_sock, "client", srt_create_socket());
EXPECT_NE(client_sock, SRT_ERROR);

const int no = 0;
Expand Down
2 changes: 1 addition & 1 deletion test/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ sockaddr_any CreateAddr(const std::string& name, unsigned short port, int pref_f

UniqueSocket::~UniqueSocket()
{
EXPECT_NE(srt_close(sock), SRT_ERROR);
EXPECT_NE(srt_close(sock), SRT_ERROR) << lab << " CREATED:"<< f << ":" << l;
}

}
5 changes: 3 additions & 2 deletions test/test_reuseaddr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ class ReuseAddr : public srt::Test

void testAccept(SRTSOCKET bindsock, std::string ip, int port, bool expect_success)
{
srt::UniqueSocket client_sock = srt_create_socket();
MAKE_UNIQUE_SOCK(client_sock, "[T/C]connect", srt_create_socket());

auto run = [this, &client_sock, ip, port, expect_success]() { clientSocket(client_sock, ip, port, expect_success); };

Expand Down Expand Up @@ -346,7 +346,8 @@ class ReuseAddr : public srt::Test

{
sockaddr_any scl;
srt::UniqueSocket accepted_sock = srt_accept(bindsock, scl.get(), &scl.len);
MAKE_UNIQUE_SOCK(accepted_sock, "[T/S]accept", srt_accept(bindsock, scl.get(), &scl.len));

if (accepted_sock == -1)
{
std::cout << "srt_accept: " << srt_getlasterror_str() << std::endl;
Expand Down

0 comments on commit 085043a

Please sign in to comment.