From 44ba139bba2b8da20b6619e75f3cf67cba08e0bf Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Fri, 4 Nov 2016 08:40:30 -0700 Subject: [PATCH] libcutils: sockets_test breaks MAC build - Neuter SOCK_NONBLOCK and SOCK_CLOEXEC if they are not defined. - F_SETFL O_NONBLOCK after socket() call. - Correct environment reference (we recently changed handler to replace non-ascii and non-numericals with '_' for env tag). Test: libcutils_test32 --gtest_filter=SocketsTest.android_get_control_socket Bug: 32450474 Change-Id: I409a8c2c78e5f057af5fd6251cbd8657018be22b --- libcutils/tests/sockets_test.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libcutils/tests/sockets_test.cpp b/libcutils/tests/sockets_test.cpp index 82961a48f..adfbf4ad3 100644 --- a/libcutils/tests/sockets_test.cpp +++ b/libcutils/tests/sockets_test.cpp @@ -190,8 +190,16 @@ TEST(SocketsTest, TestSocketSendBuffersFailure) { EXPECT_EQ(-1, socket_send_buffers(INVALID_SOCKET, nullptr, 0)); } +#ifndef SOCK_NONBLOCK +#define SOCK_NONBLOCK 0 +#endif + +#ifndef SOCK_CLOEXEC +#define SOCK_CLOEXEC 0 +#endif + TEST(SocketsTest, android_get_control_socket) { - static const char key[] = ANDROID_SOCKET_ENV_PREFIX "SocketsTest.android_get_control_socket"; + static const char key[] = ANDROID_SOCKET_ENV_PREFIX "SocketsTest_android_get_control_socket"; static const char* name = key + strlen(ANDROID_SOCKET_ENV_PREFIX); EXPECT_EQ(unsetenv(key), 0); @@ -199,6 +207,11 @@ TEST(SocketsTest, android_get_control_socket) { int fd; ASSERT_GE(fd = socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0), 0); +#ifdef F_GETFL + int flags; + ASSERT_GE(flags = fcntl(fd, F_GETFL), 0); + ASSERT_GE(fcntl(fd, F_SETFL, flags | O_NONBLOCK), 0); +#endif EXPECT_EQ(android_get_control_socket(name), -1); struct sockaddr_un addr;