summaryrefslogtreecommitdiff
path: root/libc/test/src/sys/utsname
diff options
context:
space:
mode:
authorSiva Chandra Reddy <sivachandra@google.com>2022-09-16 19:34:44 +0000
committerSiva Chandra Reddy <sivachandra@google.com>2022-09-16 21:21:29 +0000
commit7fb96fb5d33ee55fa5b65497c6074086f43babd2 (patch)
tree697fd0d9dcab3d0fb605790f8072f4b0e5ff556e /libc/test/src/sys/utsname
parent9050a59c6678789831b7286b8b68d18b966c4694 (diff)
[libc] Add implementation of POSIX "uname" function.
Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D134065
Diffstat (limited to 'libc/test/src/sys/utsname')
-rw-r--r--libc/test/src/sys/utsname/CMakeLists.txt15
-rw-r--r--libc/test/src/sys/utsname/uname_test.cpp26
2 files changed, 41 insertions, 0 deletions
diff --git a/libc/test/src/sys/utsname/CMakeLists.txt b/libc/test/src/sys/utsname/CMakeLists.txt
new file mode 100644
index 000000000000..a459820c86ea
--- /dev/null
+++ b/libc/test/src/sys/utsname/CMakeLists.txt
@@ -0,0 +1,15 @@
+add_libc_testsuite(libc_sys_utsname_unittests)
+
+add_libc_unittest(
+ uname_test
+ SUITE
+ libc_sys_utsname_unittests
+ SRCS
+ uname_test.cpp
+ DEPENDS
+ libc.include.errno
+ libc.include.sys_utsname
+ libc.src.__support.common
+ libc.src.sys.utsname.uname
+ libc.test.errno_setter_matcher
+)
diff --git a/libc/test/src/sys/utsname/uname_test.cpp b/libc/test/src/sys/utsname/uname_test.cpp
new file mode 100644
index 000000000000..1a1e4a77dae0
--- /dev/null
+++ b/libc/test/src/sys/utsname/uname_test.cpp
@@ -0,0 +1,26 @@
+//===-- Unittests for uname -----------------------------------------------===//
+//
+// 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/__support/CPP/string_view.h"
+#include "src/__support/architectures.h"
+#include "src/sys/utsname/uname.h"
+#include "test/ErrnoSetterMatcher.h"
+#include "utils/UnitTest/Test.h"
+
+#include <errno.h>
+#include <sys/utsname.h>
+
+TEST(LlvmLibcUnameTest, GetMachineName) {
+ struct utsname names;
+ ASSERT_GE(__llvm_libc::uname(&names), 0);
+#ifdef LLVM_LIBC_ARCH_X86_64
+ ASSERT_STREQ(names.machine, "x86_64");
+#elif defined(LLVM_LIBC_ARCH_AARCH64)
+ ASSERT_STREQ(names.machine, "aarch64");
+#endif
+}