This repository was archived by the owner on Apr 16, 2018. It is now read-only.
Add test for recv and send methods for Socket#8
Merged
agauniyal merged 3 commits intofeature/socketfrom Mar 21, 2017
Merged
Conversation
agauniyal
suggested changes
Mar 20, 2017
test/socket_recv_test.cpp
Outdated
| using namespace net; | ||
| using namespace std::chrono_literals; | ||
|
|
||
| auto msgLen2 = 15000; |
Member
There was a problem hiding this comment.
There shouldn't be any global variables, make them const if possible and move them under appropriate function or atleast some namespace.
test/socket_recv_test.cpp
Outdated
| for (int i = 1; i <= 1; i++) { | ||
| auto res = serverSocket.recv(msgLen2, [](AddrIPv4 &s) { | ||
| std::string str(100, ' '); | ||
| auto ptr = inet_ntop(AF_INET, &s.sin_addr.s_addr, &str.front(), |
test/socket_recv_test.cpp
Outdated
| void udpIPv4ServerProcessing(Socket &serverSocket) | ||
| { | ||
| for (int i = 1; i <= 1; i++) { | ||
| auto res = serverSocket.recv(msgLen2, [](AddrIPv4 &s) { |
Member
There was a problem hiding this comment.
provide some sort of assertion for res too
test/socket_recv_test.cpp
Outdated
| for (int i = 1; i <= 1; i++) { | ||
| auto res = serverSocket.recv(msgLen2, [](AddrIPv6 &s) { | ||
| std::string str(100, ' '); | ||
| auto ptr = inet_ntop(AF_INET6, &s.sin6_addr.s6_addr, &str.front(), |
test/socket_recv_test.cpp
Outdated
| struct sockaddr_in actualPeerIp; | ||
| socklen_t actualPeerIpLen = sizeof(actualPeerIp); | ||
|
|
||
| auto status = getpeername(peer.getSocket(), (sockaddr *) &actualPeerIp, |
test/socket_recv_test.cpp
Outdated
| actualIp.end()); | ||
| return actualIp; | ||
| } else | ||
| throw std::runtime_error("Error in getPeerIp"); |
Member
There was a problem hiding this comment.
Better error message - what is exact error?
test/socket_recv_test.cpp
Outdated
| actualIp.erase(std::remove(actualIp.begin(), actualIp.end(), ' '), | ||
| actualIp.end()); | ||
| return actualIp; | ||
| } else |
test/socket_recv_test.cpp
Outdated
|
|
||
| void tcpIPv4ServerProcessing(Socket &serverSocket) | ||
| { | ||
| for (int i = 1; i <= 1; i++) { |
test/socket_recv_test.cpp
Outdated
| void tcpIPv4ServerProcessing(Socket &serverSocket) | ||
| { | ||
| for (int i = 1; i <= 1; i++) { | ||
| auto peer = serverSocket.accept(); |
test/socket_recv_test.cpp
Outdated
| auto peer = serverSocket.accept(); | ||
|
|
||
| auto msg = peer.read(msgLen2); | ||
| if (msg == msg1) |
Member
|
@tkhurana96 see failing tests Running main() from gtest_main.cc
[==========] Running 14 tests from 3 test cases.
[----------] Global test environment set-up.
[----------] 5 tests from Socket
[ RUN ] Socket.bind
[ OK ] Socket.bind (0 ms)
[ RUN ] Socket.ConstructorRaw
[ OK ] Socket.ConstructorRaw (0 ms)
[ RUN ] Socket.getSocket
[ OK ] Socket.getSocket (1 ms)
[ RUN ] Socket.IPv4Send
../test/socket_send_test.cpp:129: Failure
Expected: (client1.read(5)) != (std::to_string(msgLen)), actual: "15000" vs "15000"
[ FAILED ] Socket.IPv4Send (2000 ms)
[ RUN ] Socket.IPv6Send
../test/socket_send_test.cpp:163: Failure
Expected: (client2.read(5)) != (std::to_string(msgLen)), actual: "15000" vs "15000"
[ FAILED ] Socket.IPv6Send (2001 ms)
[----------] 5 tests from Socket (4002 ms total)
[----------] 1 test from socket
[ RUN ] socket.constructor
[ OK ] socket.constructor (37 ms)
[----------] 1 test from socket (37 ms total)
[----------] 8 tests from SocketOptions
[ RUN ] SocketOptions.getType
[ OK ] SocketOptions.getType (1 ms)
[ RUN ] SocketOptions.CastError
[ OK ] SocketOptions.CastError (0 ms)
[ RUN ] SocketOptions.Broadcast
[ OK ] SocketOptions.Broadcast (0 ms)
[ RUN ] SocketOptions.Linger
[ OK ] SocketOptions.Linger (0 ms)
[ RUN ] SocketOptions.DontRoute
[ OK ] SocketOptions.DontRoute (0 ms)
[ RUN ] SocketOptions.KeepAlive
[ OK ] SocketOptions.KeepAlive (0 ms)
[ RUN ] SocketOptions.OOBInline
[ OK ] SocketOptions.OOBInline (0 ms)
[ RUN ] SocketOptions.RCVLOWAT
[ OK ] SocketOptions.RCVLOWAT (0 ms)
[----------] 8 tests from SocketOptions (1 ms total)
[----------] Global test environment tear-down
[==========] 14 tests from 3 test cases ran. (4040 ms total)
[ PASSED ] 12 tests.
[ FAILED ] 2 tests, listed below:
[ FAILED ] Socket.IPv4Send
[ FAILED ] Socket.IPv6Send
2 FAILED TESTS |
Member
|
@tkhurana96 see memory leaks - ==20839== Syscall param unlink(pathname) points to uninitialised byte(s)
==20839== at 0x56EDEA7: unlink (syscall-template.S:84)
==20839== by 0x40A17A: net::Socket::~Socket() (socket.hpp:869)
==20839== by 0x4130E1: Socket_GetSocket_Test::TestBody() (socket_getSocket_test.cpp:18)
==20839== by 0x43F6BD: void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (gtest.cc:2078)
==20839== by 0x43A942: void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (gtest.cc:2114)
==20839== by 0x420B71: testing::Test::Run() (gtest.cc:2151)
==20839== by 0x4213B3: testing::TestInfo::Run() (gtest.cc:2326)
==20839== by 0x421A10: testing::TestCase::Run() (gtest.cc:2444)
==20839== by 0x4288CF: testing::internal::UnitTestImpl::RunAllTests() (gtest.cc:4315)
==20839== by 0x440602: bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) (gtest.cc:2078)
==20839== by 0x43B782: bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) (gtest.cc:2114)
==20839== by 0x4274CB: testing::UnitTest::Run() (gtest.cc:3926)
==20839== Address 0xffeffffe2 is on thread 1's stack
==20839== in frame #2, created by Socket_GetSocket_Test::TestBody() (socket_getSocket_test.cpp:7)
==20839==
[ OK ] Socket.GetSocket (13 ms)
[ RUN ] Socket.IPv4Send
../test/socket_send_test.cpp:129: Failure
Expected: (client1.read(5)) != (std::to_string(msgLen)), actual: "15000" vs "15000"
[ FAILED ] Socket.IPv4Send (2110 ms)
[ RUN ] Socket.IPv6Send
==20839== Syscall param socketcall.sendto(to.sin_addr) points to uninitialised byte(s)
==20839== at 0x53E9AD3: ??? (syscall-template.S:84)
==20839== by 0x41773E: auto net::Socket::low_write<long (&)(int, void const*, unsigned long, int, sockaddr const*, unsigned int), int const&, sockaddr*, unsigned long>(long (&)(int, void const*, unsigned long, int, sockaddr const*, unsigned int), std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int const&, sockaddr*&&, unsigned long&&) const (socket.hpp:50)
==20839== by 0x4163E4: decltype (({parm#2}((declval<sockaddr_in6&>)())),((void)())) const net::Socket::send<Socket_IPv6Send_Test::TestBody()::{lambda(sockaddr_in6&)#1}>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Socket_IPv6Send_Test::TestBody()::{lambda(sockaddr_in6&)#1}, net::Send, bool*) const (socket.hpp:575)
==20839== by 0x41565D: Socket_IPv6Send_Test::TestBody() (socket_send_test.cpp:157)
==20839== by 0x43F6BD: void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (gtest.cc:2078)
==20839== by 0x43A942: void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (gtest.cc:2114)
==20839== by 0x420B71: testing::Test::Run() (gtest.cc:2151)
==20839== by 0x4213B3: testing::TestInfo::Run() (gtest.cc:2326)
==20839== by 0x421A10: testing::TestCase::Run() (gtest.cc:2444)
==20839== by 0x4288CF: testing::internal::UnitTestImpl::RunAllTests() (gtest.cc:4315)
==20839== by 0x440602: bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) (gtest.cc:2078)
==20839== by 0x43B782: bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) (gtest.cc:2114)
==20839== Address 0xffefffe14 is on thread 1's stack
==20839== in frame #2, created by decltype (({parm#2}((declval<sockaddr_in6&>)())),((void)())) const net::Socket::send<Socket_IPv6Send_Test::TestBody()::{lambda(sockaddr_in6&)#1}>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Socket_IPv6Send_Test::TestBody()::{lambda(sockaddr_in6&)#1}, net::Send, bool*) const (socket.hpp:560)
==20839==
../test/socket_send_test.cpp:163: Failure
Expected: (client2.read(5)) != (std::to_string(msgLen)), actual: "15000" vs "15000"
[ FAILED ] Socket.IPv6Send (2026 ms)
[ RUN ] Socket.Connectv4
[ OK ] Socket.Connectv4 (1011 ms)
==20839== Thread 2:
==20839== Invalid read of size 4
==20839== at 0x44B6B1: net::Socket::accept(bool*) const (socket.cpp:168)
==20839== by 0x4197C4: (anonymous namespace)::runServer(net::Socket&, unsigned int) (socket_connect_test.cpp:24)
==20839== by 0x41AB04: void std::_Bind_simple<void (*(std::reference_wrapper<net::Socket>, int))(net::Socket&, unsigned int)>::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) (functional:1400)
==20839== by 0x41A9EB: std::_Bind_simple<void (*(std::reference_wrapper<net::Socket>, int))(net::Socket&, unsigned int)>::operator()() (functional:1389)
==20839== by 0x41A91F: std::thread::_State_impl<std::_Bind_simple<void (*(std::reference_wrapper<net::Socket>, int))(net::Socket&, unsigned int)> >::_M_run() (thread:196)
==20839== by 0x4EF554E: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22)
==20839== by 0x53E06B9: start_thread (pthread_create.c:333)
==20839== by 0x56FC82C: clone (clone.S:109)
==20839== Address 0xfff000068 is on thread 1's stack
==20839== 184 bytes below stack pointer
==20839==
==20839== Invalid read of size 4
==20839== at 0x44B6BE: net::Socket::accept(bool*) const (socket.cpp:168)
==20839== by 0x4197C4: (anonymous namespace)::runServer(net::Socket&, unsigned int) (socket_connect_test.cpp:24)
==20839== by 0x41AB04: void std::_Bind_simple<void (*(std::reference_wrapper<net::Socket>, int))(net::Socket&, unsigned int)>::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) (functional:1400)
==20839== by 0x41A9EB: std::_Bind_simple<void (*(std::reference_wrapper<net::Socket>, int))(net::Socket&, unsigned int)>::operator()() (functional:1389)
==20839== by 0x41A91F: std::thread::_State_impl<std::_Bind_simple<void (*(std::reference_wrapper<net::Socket>, int))(net::Socket&, unsigned int)> >::_M_run() (thread:196)
==20839== by 0x4EF554E: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22)
==20839== by 0x53E06B9: start_thread (pthread_create.c:333)
==20839== by 0x56FC82C: clone (clone.S:109)
==20839== Address 0xfff000064 is on thread 1's stack
==20839== 188 bytes below stack pointer
==20839== |
agauniyal
approved these changes
Mar 21, 2017
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.