Re: [Lldb-commits] [PATCH] Add Socket::Get[Remote/Local]IpAddress and unit tests
Replace strtoul with ConvertString::ToUInt32 Socket::DecodeHostAndPort was accepting negative port numbers and numbers 65535, fixed http://reviews.llvm.org/D6917 Files: gtest/gtest.xcodeproj/project.pbxproj gtest/unittest/Host/ gtest/unittest/Host/Makefile gtest/unittest/Host/SocketAddressTest.cpp gtest/unittest/Host/SocketTest.cpp gtest/unittest/Host/SocketTestMock.cpp include/lldb/Host/Socket.h include/lldb/Host/SocketAddress.h source/Host/common/Socket.cpp source/Host/common/SocketAddress.cpp source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp EMAIL PREFERENCES http://reviews.llvm.org/settings/panel/emailpreferences/ Index: gtest/gtest.xcodeproj/project.pbxproj === --- gtest/gtest.xcodeproj/project.pbxproj +++ gtest/gtest.xcodeproj/project.pbxproj @@ -12,14 +12,19 @@ 236ED33619D490B0008CA7D7 /* Makefile.rules */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Makefile.rules; sourceTree = group; }; 33064C981A5C7A1A0033D415 /* UriParserTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UriParserTest.cpp; path = Utility/UriParserTest.cpp; sourceTree = group; }; 33064C9D1A5C7AC90033D415 /* do-gtest.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = do-gtest.py; sourceTree = group; }; + 330E475C1A609CF600FD2884 /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; name = Makefile; path = Host/Makefile; sourceTree = group; }; + 330E475D1A609CF600FD2884 /* SocketTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SocketTest.cpp; path = Host/SocketTest.cpp; sourceTree = group; }; + 330E475E1A60B31F00FD2884 /* SocketTestMock.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SocketTestMock.cpp; path = Host/SocketTestMock.cpp; sourceTree = group; }; + 330E47621A62451800FD2884 /* SocketAddressTest.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = SocketAddressTest.cpp; path = Host/SocketAddressTest.cpp; sourceTree = group; }; 338C47F41A1E67B900B46077 /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; name = Makefile; path = Utility/Makefile; sourceTree = group; }; 338C47F51A1E67B900B46077 /* StringExtractorTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StringExtractorTest.cpp; path = Utility/StringExtractorTest.cpp; sourceTree = group; }; /* End PBXFileReference section */ /* Begin PBXGroup section */ 236ED32F19D4901D008CA7D7 /* unittest */ = { isa = PBXGroup; children = ( +330E475B1A609CDF00FD2884 /* Host */, 338C47F31A1E677900B46077 /* Utility */, 236ED33019D4903E008CA7D7 /* Plugins */, ); @@ -68,6 +73,17 @@ ); sourceTree = group; }; + 330E475B1A609CDF00FD2884 /* Host */ = { + isa = PBXGroup; + children = ( +330E475E1A60B31F00FD2884 /* SocketTestMock.cpp */, +330E475C1A609CF600FD2884 /* Makefile */, +330E475D1A609CF600FD2884 /* SocketTest.cpp */, +330E47621A62451800FD2884 /* SocketAddressTest.cpp */, + ); + name = Host; + sourceTree = group; + }; 338C47F31A1E677900B46077 /* Utility */ = { isa = PBXGroup; children = ( Index: gtest/unittest/Host/Makefile === --- /dev/null +++ gtest/unittest/Host/Makefile @@ -0,0 +1,32 @@ +THIS_FILE_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST/ + +LEVEL := $(realpath $(THIS_FILE_DIR)../../make) + +CFLAGS_EXTRAS := -D__STDC_LIMIT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_CONSTANT_MACROS +ENABLE_THREADS := YES +# the fact that we need all of these source files to compile Socket.cpp +# is a good indication that we need some refactoring +CXX_SOURCES := $(wildcard *.cpp) \ +$(realpath $(LEVEL)/../../source/Core/Error.cpp) \ +$(realpath $(LEVEL)/../../source/Core/RegularExpression.cpp) \ +$(realpath $(LEVEL)/../../source/Core/Stream.cpp) \ +$(realpath $(LEVEL)/../../source/Core/StreamString.cpp) \ +$(realpath $(LEVEL)/../../source/Host/common/Socket.cpp) \ +$(realpath $(LEVEL)/../../source/Host/common/SocketAddress.cpp) \ +$(realpath $(LEVEL)/../../source/Host/common/StringConvert.cpp) \ +$(realpath $(LEVEL)/../../source/Host/common/TimeValue.cpp) + +OS := $(shell uname -s) +ifeq ($(OS),Windows) +CXX_SOURCES := $(CXX_SOURCES) \ +$(LEVEL)/../../source/Host/windows/Condition.cpp \ +$(LEVEL)/../../source/Host/windows/Mutex.cpp +else +CXX_SOURCES := $(CXX_SOURCES) \ +$(LEVEL)/../../source/Host/common/Condition.cpp \ +$(LEVEL)/../../source/Host/common/Mutex.cpp +endif + +MAKE_DSYM := NO + +include $(LEVEL)/Makefile.rules Index: gtest/unittest/Host/SocketAddressTest.cpp
Re: [Lldb-commits] [PATCH] Add Socket::Get[Remote/Local]IpAddress and unit tests
You removed a comment from line 1 of source/Host/common/Socket.cpp. Fix that and it will be good to go. http://reviews.llvm.org/D6917 EMAIL PREFERENCES http://reviews.llvm.org/settings/panel/emailpreferences/ ___ lldb-commits mailing list lldb-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits
Re: [Lldb-commits] [PATCH] Add Socket::Get[Remote/Local]IpAddress and unit tests
REPOSITORY rL LLVM http://reviews.llvm.org/D6917 Files: lldb/trunk/gtest/gtest.xcodeproj/project.pbxproj lldb/trunk/gtest/unittest/Host/Makefile lldb/trunk/gtest/unittest/Host/SocketAddressTest.cpp lldb/trunk/gtest/unittest/Host/SocketTest.cpp lldb/trunk/gtest/unittest/Host/SocketTestMock.cpp lldb/trunk/include/lldb/Host/Socket.h lldb/trunk/include/lldb/Host/SocketAddress.h lldb/trunk/source/Host/common/Socket.cpp lldb/trunk/source/Host/common/SocketAddress.cpp lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp EMAIL PREFERENCES http://reviews.llvm.org/settings/panel/emailpreferences/ Index: lldb/trunk/gtest/unittest/Host/SocketTest.cpp === --- lldb/trunk/gtest/unittest/Host/SocketTest.cpp +++ lldb/trunk/gtest/unittest/Host/SocketTest.cpp @@ -0,0 +1,132 @@ +//===-- SocketTest.cpp --*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#include thread + +#include gtest/gtest.h + +#include lldb/Host/Socket.h + +class SocketTest: public ::testing::Test +{ +}; + +using namespace lldb_private; + +void AcceptThread (Socket* listen_socket, + const char* listen_remote_address, + bool child_processes_inherit, + Socket** accept_socket, + Error* error) +{ +*error = listen_socket-BlockingAccept (listen_remote_address, child_processes_inherit, *accept_socket); +} + +void CreateConnectedSockets (std::unique_ptrSocket* a_up, std::unique_ptrSocket* b_up) +{ +Predicateuint16_t port_predicate; +// Used when binding to port zero to wait for the thread +// that creates the socket, binds and listens to resolve +// the port number. + +port_predicate.SetValue (0, eBroadcastNever); + +bool child_processes_inherit = false; +Socket *socket = nullptr; +const char* listen_remote_address = localhost:0; +Error error = Socket::TcpListen (listen_remote_address, child_processes_inherit, socket, port_predicate); +std::unique_ptrSocket listen_socket_up (socket); +socket = nullptr; +EXPECT_FALSE (error.Fail ()); +EXPECT_NE (nullptr, listen_socket_up.get ()); +EXPECT_TRUE (listen_socket_up-IsValid ()); + +Error accept_error; +Socket* accept_socket; +std::thread accept_thread (AcceptThread, + listen_socket_up.get (), + listen_remote_address, + child_processes_inherit, + accept_socket, + accept_error); + +char connect_remote_address[64]; +snprintf (connect_remote_address, sizeof (connect_remote_address), localhost:%u, port_predicate.GetValue ()); +error = Socket::TcpConnect (connect_remote_address, child_processes_inherit, socket); +a_up-reset (socket); +socket = nullptr; +EXPECT_TRUE (error.Success ()); +EXPECT_NE (nullptr, a_up-get ()); +EXPECT_TRUE ((*a_up)-IsValid ()); + +accept_thread.join (); +b_up-reset (accept_socket); +EXPECT_TRUE (accept_error.Success ()); +EXPECT_NE (nullptr, b_up-get ()); +EXPECT_TRUE ((*b_up)-IsValid ()); + +listen_socket_up.reset (); +} + +TEST_F (SocketTest, DecodeHostAndPort) +{ +std::string host_str; +std::string port_str; +int32_t port; +Error error; +EXPECT_TRUE (Socket::DecodeHostAndPort (localhost:1138, host_str, port_str, port, error)); +EXPECT_STREQ (localhost, host_str.c_str ()); +EXPECT_STREQ (1138, port_str.c_str ()); +EXPECT_EQ (1138, port); +EXPECT_TRUE (error.Success ()); + +EXPECT_FALSE (Socket::DecodeHostAndPort (google.com:65536, host_str, port_str, port, error)); +EXPECT_TRUE (error.Fail ()); +EXPECT_STREQ (invalid host:port specification: 'google.com:65536', error.AsCString ()); + +EXPECT_FALSE (Socket::DecodeHostAndPort (google.com:-1138, host_str, port_str, port, error)); +EXPECT_TRUE (error.Fail ()); +EXPECT_STREQ (invalid host:port specification: 'google.com:-1138', error.AsCString ()); + +EXPECT_TRUE (Socket::DecodeHostAndPort (12345, host_str, port_str, port, error)); +EXPECT_STREQ (, host_str.c_str ()); +EXPECT_STREQ (12345, port_str.c_str ()); +EXPECT_EQ (12345, port); +EXPECT_TRUE (error.Success ()); + +EXPECT_TRUE (Socket::DecodeHostAndPort (*:0, host_str, port_str, port, error)); +EXPECT_STREQ (*, host_str.c_str ()); +EXPECT_STREQ (0, port_str.c_str ()); +EXPECT_EQ (0, port); +EXPECT_TRUE (error.Success ()); + +} + +TEST_F (SocketTest, Listen0ConnectAccept) +{ +std::unique_ptrSocket socket_a_up; +std::unique_ptrSocket socket_b_up;
Re: [Lldb-commits] [PATCH] Add Socket::Get[Remote/Local]IpAddress and unit tests
The other option is to move all static Args::StringTo* calls into the Host layer at an appropriate place. Changes should be: - please use Args::StringTo calls instead of manual strtoul() calls so we have a common codebase and so people don't start using strtoul() on their own in other places f the code - optionally move the static Args::StringTo* calls into the Host layer REPOSITORY rL LLVM http://reviews.llvm.org/D6917 EMAIL PREFERENCES http://reviews.llvm.org/settings/panel/emailpreferences/ ___ lldb-commits mailing list lldb-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits