summaryrefslogtreecommitdiffstats
path: root/libc/test
diff options
context:
space:
mode:
authorSiva Chandra Reddy <sivachandra@google.com>2020-01-03 12:00:45 -0800
committerSiva Chandra Reddy <sivachandra@google.com>2020-01-06 10:14:43 -0800
commit5b24c088171d3bd7a8ff559c82926e5d4b04f032 (patch)
tree54ac5d666fef87a0e6337e388f6f5087c18e9ef9 /libc/test
parent0239526cccf8aa708e29eeb7e49de8f6dc6c1a5f (diff)
downloadbcm5719-llvm-5b24c088171d3bd7a8ff559c82926e5d4b04f032.tar.gz
bcm5719-llvm-5b24c088171d3bd7a8ff559c82926e5d4b04f032.zip
[libc] Move all tests to a top level `test` directory.
A toplevel target, `check-libc` has also been added. Reviewers: abrachet, phosek Tags: #libc-project Differential Revision: https://reviews.llvm.org/D72177
Diffstat (limited to 'libc/test')
-rw-r--r--libc/test/CMakeLists.txt4
-rw-r--r--libc/test/config/CMakeLists.txt1
-rw-r--r--libc/test/config/linux/CMakeLists.txt4
-rw-r--r--libc/test/config/linux/x86_64/CMakeLists.txt11
-rw-r--r--libc/test/config/linux/x86_64/syscall_test.cpp40
-rw-r--r--libc/test/src/CMakeLists.txt3
-rw-r--r--libc/test/src/errno/CMakeLists.txt12
-rw-r--r--libc/test/src/errno/errno_test.cpp17
-rw-r--r--libc/test/src/string/CMakeLists.txt23
-rw-r--r--libc/test/src/string/strcat_test.cpp39
-rw-r--r--libc/test/src/string/strcpy_test.cpp36
-rw-r--r--libc/test/src/sys/CMakeLists.txt1
-rw-r--r--libc/test/src/sys/mman/CMakeLists.txt14
-rw-r--r--libc/test/src/sys/mman/mmap_test.cpp48
14 files changed, 253 insertions, 0 deletions
diff --git a/libc/test/CMakeLists.txt b/libc/test/CMakeLists.txt
new file mode 100644
index 00000000000..fa7f29e1d2a
--- /dev/null
+++ b/libc/test/CMakeLists.txt
@@ -0,0 +1,4 @@
+add_custom_target(check_libc)
+
+add_subdirectory(config)
+add_subdirectory(src)
diff --git a/libc/test/config/CMakeLists.txt b/libc/test/config/CMakeLists.txt
new file mode 100644
index 00000000000..a1034f99547
--- /dev/null
+++ b/libc/test/config/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory(linux)
diff --git a/libc/test/config/linux/CMakeLists.txt b/libc/test/config/linux/CMakeLists.txt
new file mode 100644
index 00000000000..5a20f90881f
--- /dev/null
+++ b/libc/test/config/linux/CMakeLists.txt
@@ -0,0 +1,4 @@
+add_custom_target(libc_linux_tests)
+add_dependencies(check_libc libc_linux_tests)
+
+add_subdirectory(x86_64)
diff --git a/libc/test/config/linux/x86_64/CMakeLists.txt b/libc/test/config/linux/x86_64/CMakeLists.txt
new file mode 100644
index 00000000000..370073cd1cf
--- /dev/null
+++ b/libc/test/config/linux/x86_64/CMakeLists.txt
@@ -0,0 +1,11 @@
+add_custom_target(libc_linux_x86_64_tests)
+add_dependencies(libc_linux_tests libc_linux_x86_64_tests)
+
+add_libc_unittest(
+ libc_linux_x86_64_syscall_unittest
+ SUITE libc_linux_x86_64_tests
+ SRCS syscall_test.cpp
+ DEPENDS
+ syscall_impl_h
+ support_common_h
+)
diff --git a/libc/test/config/linux/x86_64/syscall_test.cpp b/libc/test/config/linux/x86_64/syscall_test.cpp
new file mode 100644
index 00000000000..6a92142625c
--- /dev/null
+++ b/libc/test/config/linux/x86_64/syscall_test.cpp
@@ -0,0 +1,40 @@
+//===------------------ Unittests for x86_64 syscalls ---------------------===//
+//
+// 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/unistd/syscall.h"
+
+#include "gtest/gtest.h"
+
+#include <functional>
+
+TEST(X86_64_SyscallTest, APITest) {
+ // We only do a signature test here. Actual functionality tests are
+ // done by the unit tests of the syscall wrappers like mmap.
+
+ std::function<long(long)> f([](long n) { return __llvm_libc::syscall(n); });
+ std::function<long(long, long)> f1(
+ [](long n, long a1) { return __llvm_libc::syscall(n, a1); });
+ std::function<long(long, long, long)> f2(
+ [](long n, long a1, long a2) { return __llvm_libc::syscall(n, a1, a2); });
+ std::function<long(long, long, long, long)> f3(
+ [](long n, long a1, long a2, long a3) {
+ return __llvm_libc::syscall(n, a1, a2, a3);
+ });
+ std::function<long(long, long, long, long, long)> f4(
+ [](long n, long a1, long a2, long a3, long a4) {
+ return __llvm_libc::syscall(n, a1, a2, a3, a4);
+ });
+ std::function<long(long, long, long, long, long, long)> f5(
+ [](long n, long a1, long a2, long a3, long a4, long a5) {
+ return __llvm_libc::syscall(n, a1, a2, a3, a4, a5);
+ });
+ std::function<long(long, long, long, long, long, long, long)> f6(
+ [](long n, long a1, long a2, long a3, long a4, long a5, long a6) {
+ return __llvm_libc::syscall(n, a1, a2, a3, a4, a5, a6);
+ });
+}
diff --git a/libc/test/src/CMakeLists.txt b/libc/test/src/CMakeLists.txt
new file mode 100644
index 00000000000..daf0f1ce57c
--- /dev/null
+++ b/libc/test/src/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_subdirectory(errno)
+add_subdirectory(string)
+add_subdirectory(sys)
diff --git a/libc/test/src/errno/CMakeLists.txt b/libc/test/src/errno/CMakeLists.txt
new file mode 100644
index 00000000000..6c21da5701b
--- /dev/null
+++ b/libc/test/src/errno/CMakeLists.txt
@@ -0,0 +1,12 @@
+add_custom_target(libc_errno_unittests)
+add_dependencies(check_libc libc_errno_unittests)
+
+add_libc_unittest(
+ errno_test
+ SUITE
+ libc_errno_unittests
+ SRCS
+ errno_test.cpp
+ DEPENDS
+ __errno_location
+)
diff --git a/libc/test/src/errno/errno_test.cpp b/libc/test/src/errno/errno_test.cpp
new file mode 100644
index 00000000000..1ca61d5c625
--- /dev/null
+++ b/libc/test/src/errno/errno_test.cpp
@@ -0,0 +1,17 @@
+//===---------------------- Unittests for errno --------------------------===//
+//
+// 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/errno/llvmlibc_errno.h"
+
+#include "gtest/gtest.h"
+
+TEST(ErrnoTest, Basic) {
+ int test_val = 123;
+ llvmlibc_errno = test_val;
+ ASSERT_EQ(test_val, llvmlibc_errno);
+}
diff --git a/libc/test/src/string/CMakeLists.txt b/libc/test/src/string/CMakeLists.txt
new file mode 100644
index 00000000000..bc5c088d169
--- /dev/null
+++ b/libc/test/src/string/CMakeLists.txt
@@ -0,0 +1,23 @@
+add_custom_target(libc_string_unittests)
+add_dependencies(check_libc libc_string_unittests)
+
+add_libc_unittest(
+ strcat_test
+ SUITE
+ libc_string_unittests
+ SRCS
+ strcat_test.cpp
+ DEPENDS
+ strcat
+ strcpy
+)
+
+add_libc_unittest(
+ strcpy_test
+ SUITE
+ libc_string_unittests
+ SRCS
+ strcpy_test.cpp
+ DEPENDS
+ strcpy
+)
diff --git a/libc/test/src/string/strcat_test.cpp b/libc/test/src/string/strcat_test.cpp
new file mode 100644
index 00000000000..3b8a7a7e447
--- /dev/null
+++ b/libc/test/src/string/strcat_test.cpp
@@ -0,0 +1,39 @@
+//===---------------------- Unittests for strcat --------------------------===//
+//
+// 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 <string>
+
+#include "src/string/strcat/strcat.h"
+#include "gtest/gtest.h"
+
+TEST(StrCatTest, EmptyDest) {
+ std::string abc = "abc";
+ char dest[4];
+
+ dest[0] = '\0';
+
+ char *result = __llvm_libc::strcat(dest, abc.c_str());
+ ASSERT_EQ(dest, result);
+ ASSERT_EQ(std::string(dest), abc);
+ ASSERT_EQ(std::string(dest).size(), abc.size());
+}
+
+TEST(StrCatTest, NonEmptyDest) {
+ std::string abc = "abc";
+ char dest[7];
+
+ dest[0] = 'x';
+ dest[1] = 'y';
+ dest[2] = 'z';
+ dest[3] = '\0';
+
+ char *result = __llvm_libc::strcat(dest, abc.c_str());
+ ASSERT_EQ(dest, result);
+ ASSERT_EQ(std::string(dest), std::string("xyz") + abc);
+ ASSERT_EQ(std::string(dest).size(), abc.size() + 3);
+}
diff --git a/libc/test/src/string/strcpy_test.cpp b/libc/test/src/string/strcpy_test.cpp
new file mode 100644
index 00000000000..e68ea5103db
--- /dev/null
+++ b/libc/test/src/string/strcpy_test.cpp
@@ -0,0 +1,36 @@
+//===----------------------- Unittests for strcpy -------------------------===//
+//
+// 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 <string>
+
+#include "src/string/strcpy/strcpy.h"
+#include "gtest/gtest.h"
+
+TEST(StrCpyTest, EmptyDest) {
+ std::string abc = "abc";
+ char dest[4];
+
+ char *result = __llvm_libc::strcpy(dest, abc.c_str());
+ ASSERT_EQ(dest, result);
+ ASSERT_EQ(std::string(dest), abc);
+ ASSERT_EQ(std::string(dest).size(), abc.size());
+}
+
+TEST(StrCpyTest, OffsetDest) {
+ std::string abc = "abc";
+ char dest[7];
+
+ dest[0] = 'x';
+ dest[1] = 'y';
+ dest[2] = 'z';
+
+ char *result = __llvm_libc::strcpy(dest + 3, abc.c_str());
+ ASSERT_EQ(dest + 3, result);
+ ASSERT_EQ(std::string(dest), std::string("xyz") + abc);
+ ASSERT_EQ(std::string(dest).size(), abc.size() + 3);
+}
diff --git a/libc/test/src/sys/CMakeLists.txt b/libc/test/src/sys/CMakeLists.txt
new file mode 100644
index 00000000000..03c59bfc4a0
--- /dev/null
+++ b/libc/test/src/sys/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory(mman)
diff --git a/libc/test/src/sys/mman/CMakeLists.txt b/libc/test/src/sys/mman/CMakeLists.txt
new file mode 100644
index 00000000000..3e153eb1134
--- /dev/null
+++ b/libc/test/src/sys/mman/CMakeLists.txt
@@ -0,0 +1,14 @@
+add_custom_target(libc_sys_mman_unittests)
+add_dependencies(check_libc libc_sys_mman_unittests)
+
+add_libc_unittest(
+ mmap_test
+ SUITE
+ libc_sys_mman_unittests
+ SRCS
+ mmap_test.cpp
+ DEPENDS
+ mmap
+ munmap
+ __errno_location
+)
diff --git a/libc/test/src/sys/mman/mmap_test.cpp b/libc/test/src/sys/mman/mmap_test.cpp
new file mode 100644
index 00000000000..ab2e6ceb4a9
--- /dev/null
+++ b/libc/test/src/sys/mman/mmap_test.cpp
@@ -0,0 +1,48 @@
+//===------------------ Unittests for mmap and munmap ---------------------===//
+//
+// 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/errno/llvmlibc_errno.h"
+#include "src/sys/mman/mmap.h"
+#include "src/sys/mman/munmap.h"
+
+#include "gtest/gtest.h"
+
+#include "errno.h"
+#include "sys/mman.h"
+
+TEST(MMapTest, NoError) {
+ size_t alloc_size = 128;
+ llvmlibc_errno = 0;
+ void *addr = __llvm_libc::mmap(nullptr, alloc_size, PROT_READ,
+ MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ EXPECT_EQ(0, llvmlibc_errno);
+ EXPECT_NE(addr, MAP_FAILED);
+
+ int *array = reinterpret_cast<int *>(addr);
+ // Reading from the memory should not crash the test.
+ // Since we used the MAP_ANONYMOUS flag, the contents of the newly
+ // allocated memory should be initialized to zero.
+ EXPECT_EQ(array[0], 0);
+
+ int ret_val = __llvm_libc::munmap(addr, alloc_size);
+ EXPECT_EQ(0, ret_val);
+ EXPECT_EQ(0, llvmlibc_errno);
+}
+
+TEST(MMapTest, Error_InvalidSize) {
+ llvmlibc_errno = 0;
+ void *addr = __llvm_libc::mmap(nullptr, 0, PROT_READ,
+ MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ EXPECT_EQ(EINVAL, llvmlibc_errno);
+ EXPECT_EQ(addr, MAP_FAILED);
+
+ llvmlibc_errno = 0;
+ int ret_val = __llvm_libc::munmap(0, 0);
+ EXPECT_EQ(-1, ret_val);
+ EXPECT_EQ(EINVAL, llvmlibc_errno);
+}
OpenPOWER on IntegriCloud