summaryrefslogtreecommitdiff
path: root/libc/test
diff options
context:
space:
mode:
authorMichael Jones <michaelrj@google.com>2023-04-24 16:55:54 -0700
committerMichael Jones <michaelrj@google.com>2023-05-03 11:01:11 -0700
commitee17fd7d46a914bed4619f656cc9062c40951e5c (patch)
tree673605e2495245a9d0510202bc3996db907126ad /libc/test
parentfc19204918136074483e576177e05bccb2543d44 (diff)
downloadllvm-ee17fd7d46a914bed4619f656cc9062c40951e5c.tar.gz
[libc] add socket function
This patch adds the function "socket" from the header "sys/socket". It's a simple syscall wrapper, and I plan on adding the related functions in a followup patch. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D149622
Diffstat (limited to 'libc/test')
-rw-r--r--libc/test/src/sys/CMakeLists.txt1
-rw-r--r--libc/test/src/sys/socket/CMakeLists.txt3
-rw-r--r--libc/test/src/sys/socket/linux/CMakeLists.txt14
-rw-r--r--libc/test/src/sys/socket/linux/socket_test.cpp24
4 files changed, 42 insertions, 0 deletions
diff --git a/libc/test/src/sys/CMakeLists.txt b/libc/test/src/sys/CMakeLists.txt
index 94f62123d2c4..5ef97fe81770 100644
--- a/libc/test/src/sys/CMakeLists.txt
+++ b/libc/test/src/sys/CMakeLists.txt
@@ -3,6 +3,7 @@ add_subdirectory(random)
add_subdirectory(resource)
add_subdirectory(select)
add_subdirectory(sendfile)
+add_subdirectory(socket)
add_subdirectory(stat)
add_subdirectory(utsname)
add_subdirectory(wait)
diff --git a/libc/test/src/sys/socket/CMakeLists.txt b/libc/test/src/sys/socket/CMakeLists.txt
new file mode 100644
index 000000000000..b4bbe81c92ff
--- /dev/null
+++ b/libc/test/src/sys/socket/CMakeLists.txt
@@ -0,0 +1,3 @@
+if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
+ add_subdirectory(${LIBC_TARGET_OS})
+endif()
diff --git a/libc/test/src/sys/socket/linux/CMakeLists.txt b/libc/test/src/sys/socket/linux/CMakeLists.txt
new file mode 100644
index 000000000000..4380597e5515
--- /dev/null
+++ b/libc/test/src/sys/socket/linux/CMakeLists.txt
@@ -0,0 +1,14 @@
+add_custom_target(libc_sys_socket_unittests)
+
+add_libc_unittest(
+ socket_test
+ SUITE
+ libc_sys_socket_unittests
+ SRCS
+ socket_test.cpp
+ DEPENDS
+ libc.include.sys_socket
+ libc.src.errno.errno
+ libc.src.sys.socket.socket
+ libc.src.unistd.close
+)
diff --git a/libc/test/src/sys/socket/linux/socket_test.cpp b/libc/test/src/sys/socket/linux/socket_test.cpp
new file mode 100644
index 000000000000..6826594e52d7
--- /dev/null
+++ b/libc/test/src/sys/socket/linux/socket_test.cpp
@@ -0,0 +1,24 @@
+//===-- Unittests for socket ----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/sys/socket/socket.h"
+
+#include "src/unistd/close.h"
+
+#include "src/errno/libc_errno.h"
+#include "test/UnitTest/Test.h"
+
+#include <sys/socket.h> // For AF_LOCAL and SOCK_DGRAM
+
+TEST(LlvmLibcSocketTest, LocalSocket) {
+ int sock = __llvm_libc::socket(AF_LOCAL, SOCK_DGRAM, 0);
+ ASSERT_GE(sock, 0);
+ ASSERT_EQ(libc_errno, 0);
+
+ __llvm_libc::close(sock);
+}