1*f6b4c34dSMichael Jones //===-- Unittests for socketpair ------------------------------------------===// 2*f6b4c34dSMichael Jones // 3*f6b4c34dSMichael Jones // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*f6b4c34dSMichael Jones // See https://llvm.org/LICENSE.txt for license information. 5*f6b4c34dSMichael Jones // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*f6b4c34dSMichael Jones // 7*f6b4c34dSMichael Jones //===----------------------------------------------------------------------===// 8*f6b4c34dSMichael Jones 9*f6b4c34dSMichael Jones #include "src/sys/socket/socketpair.h" 10*f6b4c34dSMichael Jones 11*f6b4c34dSMichael Jones #include "src/unistd/close.h" 12*f6b4c34dSMichael Jones 13*f6b4c34dSMichael Jones #include "src/errno/libc_errno.h" 14*f6b4c34dSMichael Jones #include "test/UnitTest/Test.h" 15*f6b4c34dSMichael Jones 16*f6b4c34dSMichael Jones #include <sys/socket.h> // For AF_UNIX and SOCK_DGRAM 17*f6b4c34dSMichael Jones 18*f6b4c34dSMichael Jones TEST(LlvmLibcSocketPairTest, LocalSocket) { 19*f6b4c34dSMichael Jones int sockpair[2] = {-1, -1}; 20*f6b4c34dSMichael Jones int result = LIBC_NAMESPACE::socketpair(AF_UNIX, SOCK_DGRAM, 0, sockpair); 21*f6b4c34dSMichael Jones ASSERT_EQ(result, 0); 22*f6b4c34dSMichael Jones ASSERT_ERRNO_SUCCESS(); 23*f6b4c34dSMichael Jones 24*f6b4c34dSMichael Jones ASSERT_GE(sockpair[0], 0); 25*f6b4c34dSMichael Jones ASSERT_GE(sockpair[1], 0); 26*f6b4c34dSMichael Jones 27*f6b4c34dSMichael Jones LIBC_NAMESPACE::close(sockpair[0]); 28*f6b4c34dSMichael Jones LIBC_NAMESPACE::close(sockpair[1]); 29*f6b4c34dSMichael Jones ASSERT_ERRNO_SUCCESS(); 30*f6b4c34dSMichael Jones } 31*f6b4c34dSMichael Jones 32*f6b4c34dSMichael Jones TEST(LlvmLibcSocketPairTest, SocketFails) { 33*f6b4c34dSMichael Jones int sockpair[2] = {-1, -1}; 34*f6b4c34dSMichael Jones int result = LIBC_NAMESPACE::socketpair(-1, -1, -1, sockpair); 35*f6b4c34dSMichael Jones ASSERT_EQ(result, -1); 36*f6b4c34dSMichael Jones ASSERT_ERRNO_FAILURE(); 37*f6b4c34dSMichael Jones } 38