[libc-commits] [libc] [libc] Use `LIBC_COPT_PUBLIC_PACKAGING` for hermetic and integration tests. (PR #79319)
via libc-commits
libc-commits at lists.llvm.org
Thu Jan 25 23:26:08 PST 2024
https://github.com/lntue updated https://github.com/llvm/llvm-project/pull/79319
>From bfad737530ec00a5c380b4855daaa6dc31896749 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue at google.com>
Date: Wed, 24 Jan 2024 10:51:48 -0500
Subject: [PATCH 1/4] [libc] Use `LIBC_COPT_PUBLIC_PACKAGING` for hermetic and
integration tests.
---
libc/cmake/modules/LLVMLibCTestRules.cmake | 20 ++++++++++++-------
libc/test/integration/startup/CMakeLists.txt | 2 +-
.../math/differential_testing/CMakeLists.txt | 2 +-
3 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 46ffc8316fc822..3b1293e271f0f5 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -5,6 +5,7 @@
# Usage:
# get_object_files_for_test(<result var>
# <skipped_entrypoints_var>
+# <internal_obj>
# <target0> [<target1> ...])
#
# The list of object files is collected in <result_var>.
@@ -12,7 +13,8 @@
# set to a true value.
# targetN is either an "add_entrypoint_target" target or an
# "add_object_library" target.
-function(get_object_files_for_test result skipped_entrypoints_list)
+# If internal_obj is TRUE, then we collect `target.__internal__` for entry points.
+function(get_object_files_for_test result skipped_entrypoints_list internal_obj)
set(object_files "")
set(skipped_list "")
set(checked_list "")
@@ -49,7 +51,7 @@ function(get_object_files_for_test result skipped_entrypoints_list)
set(dep_skip "")
get_target_property(indirect_deps ${dep} "DEPS")
- get_object_files_for_test(dep_obj dep_skip ${indirect_deps})
+ get_object_files_for_test(dep_obj dep_skip ${internal_obj} ${indirect_deps})
if(${dep_type} STREQUAL ${OBJECT_LIBRARY_TARGET_TYPE})
get_target_property(dep_object_files ${dep} "OBJECT_FILES")
@@ -62,7 +64,11 @@ function(get_object_files_for_test result skipped_entrypoints_list)
list(APPEND dep_skip ${dep})
list(REMOVE_ITEM dep_obj ${dep})
endif()
- get_target_property(object_file_raw ${dep} "OBJECT_FILE_RAW")
+ if(${internal_obj})
+ get_target_property(object_file_raw ${dep} "OBJECT_FILE_RAW")
+ else()
+ get_target_property(object_file_raw ${dep} "OBJECT_FILE")
+ endif()
if(object_file_raw)
list(APPEND dep_obj ${object_file_raw})
endif()
@@ -130,7 +136,7 @@ function(create_libc_unittest fq_target_name)
libc.test.UnitTest.ErrnoSetterMatcher)
list(REMOVE_DUPLICATES fq_deps_list)
get_object_files_for_test(
- link_object_files skipped_entrypoints_list ${fq_deps_list})
+ link_object_files skipped_entrypoints_list TRUE ${fq_deps_list})
if(skipped_entrypoints_list)
# If a test is OS/target machine independent, it has to be skipped if the
# OS/target machine combination does not provide any dependent entrypoints.
@@ -388,7 +394,7 @@ function(add_libc_fuzzer target_name)
get_fq_target_name(${target_name} fq_target_name)
get_fq_deps_list(fq_deps_list ${LIBC_FUZZER_DEPENDS})
get_object_files_for_test(
- link_object_files skipped_entrypoints_list ${fq_deps_list})
+ link_object_files skipped_entrypoints_list TRUE ${fq_deps_list})
if(skipped_entrypoints_list)
if(LIBC_CMAKE_VERBOSE_LOGGING)
set(msg "Skipping fuzzer target ${fq_target_name} as it has missing deps: "
@@ -518,7 +524,7 @@ function(add_integration_test test_name)
# TODO: Instead of gathering internal object files from entrypoints,
# collect the object files with public names of entrypoints.
get_object_files_for_test(
- link_object_files skipped_entrypoints_list ${fq_deps_list})
+ link_object_files skipped_entrypoints_list FALSE ${fq_deps_list})
if(skipped_entrypoints_list)
if(LIBC_CMAKE_VERBOSE_LOGGING)
set(msg "Skipping unittest ${fq_target_name} as it has missing deps: "
@@ -702,7 +708,7 @@ function(add_libc_hermetic_test test_name)
# TODO: Instead of gathering internal object files from entrypoints,
# collect the object files with public names of entrypoints.
get_object_files_for_test(
- link_object_files skipped_entrypoints_list ${fq_deps_list})
+ link_object_files skipped_entrypoints_list FALSE ${fq_deps_list})
if(skipped_entrypoints_list)
set(msg "Skipping unittest ${fq_target_name} as it has missing deps: "
"${skipped_entrypoints_list}.")
diff --git a/libc/test/integration/startup/CMakeLists.txt b/libc/test/integration/startup/CMakeLists.txt
index fb5d6bc787cc26..8bdb841faf74f3 100644
--- a/libc/test/integration/startup/CMakeLists.txt
+++ b/libc/test/integration/startup/CMakeLists.txt
@@ -38,7 +38,7 @@ function(add_startup_test target_name)
if(ADD_STARTUP_TEST_DEPENDS)
get_fq_deps_list(fq_deps_list ${ADD_STARTUP_TEST_DEPENDS})
add_dependencies(${fq_target_name} ${fq_deps_list})
- get_object_files_for_test(link_object_files has_skipped_entrypoint_list ${fq_deps_list})
+ get_object_files_for_test(link_object_files has_skipped_entrypoint_list TRUE ${fq_deps_list})
target_link_libraries(${fq_target_name} ${link_object_files})
endif()
diff --git a/libc/test/src/math/differential_testing/CMakeLists.txt b/libc/test/src/math/differential_testing/CMakeLists.txt
index 72bc2f8fb16aaa..41e1f2bcdca494 100644
--- a/libc/test/src/math/differential_testing/CMakeLists.txt
+++ b/libc/test/src/math/differential_testing/CMakeLists.txt
@@ -27,7 +27,7 @@ function(add_diff_binary target_name)
get_fq_target_name(${target_name} fq_target_name)
get_fq_deps_list(fq_deps_list ${DIFF_DEPENDS})
get_object_files_for_test(
- link_object_files skipped_entrypoints_list ${fq_deps_list})
+ link_object_files skipped_entrypoints_list TRUE ${fq_deps_list})
if(skipped_entrypoints_list)
if(LIBC_CMAKE_VERBOSE_LOGGING)
set(msg "Will not build ${fq_target_name} as it has missing deps: "
>From 3f54aacf77be63b407a1c6933730f5d64432012c Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue at google.com>
Date: Wed, 24 Jan 2024 15:15:22 -0500
Subject: [PATCH 2/4] Update get_object_files_for_test caching to take
internal_obj into consideration.
---
libc/cmake/modules/LLVMLibCTestRules.cmake | 62 +++++++++++++++++++---
1 file changed, 54 insertions(+), 8 deletions(-)
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 3b1293e271f0f5..f4be1615f7bde9 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -19,6 +19,11 @@ function(get_object_files_for_test result skipped_entrypoints_list internal_obj)
set(skipped_list "")
set(checked_list "")
set(unchecked_list "${ARGN}")
+
+ set(check_obj_for_tests "CHECK_OBJ_FOR_TESTS_${internal_obj}")
+ set(object_files_for_tests "OBJECT_FILES_FOR_TESTS_${internal_obj}")
+ set(skipped_list_for_tests "SKIPPED_LIST_FOR_TESTS_${internal_obj}")
+
list(REMOVE_DUPLICATES unchecked_list)
foreach(dep IN LISTS unchecked_list)
@@ -39,12 +44,12 @@ function(get_object_files_for_test result skipped_entrypoints_list internal_obj)
continue()
endif()
- get_target_property(dep_checked ${dep} "CHECK_OBJ_FOR_TESTS")
+ get_target_property(dep_checked ${dep} ${check_obj_for_tests})
if(dep_checked)
# Target full dependency has already been checked. Just use the results.
- get_target_property(dep_obj ${dep} "OBJECT_FILES_FOR_TESTS")
- get_target_property(dep_skip ${dep} "SKIPPED_LIST_FOR_TESTS")
+ get_target_property(dep_obj ${dep} ${object_files_for_tests})
+ get_target_property(dep_skip ${dep} ${skipped_list_for_tests})
else()
# Target full dependency hasn't been checked. Recursively check its DEPS.
set(dep_obj "${dep}")
@@ -79,9 +84,9 @@ function(get_object_files_for_test result skipped_entrypoints_list internal_obj)
endif()
set_target_properties(${dep} PROPERTIES
- OBJECT_FILES_FOR_TESTS "${dep_obj}"
- SKIPPED_LIST_FOR_TESTS "${dep_skip}"
- CHECK_OBJ_FOR_TESTS "YES"
+ "${object_files_for_tests}" "${dep_obj}"
+ "${skipped_list_for_tests}" "${dep_skip}"
+ "${check_obj_for_tests}" "YES"
)
endif()
@@ -166,7 +171,7 @@ function(create_libc_unittest fq_target_name)
if(SHOW_INTERMEDIATE_OBJECTS)
message(STATUS "Adding unit test ${fq_target_name}")
if(${SHOW_INTERMEDIATE_OBJECTS} STREQUAL "DEPS")
- foreach(dep IN LISTS ADD_OBJECT_DEPENDS)
+ foreach(dep IN LISTS LIBC_UNITTEST_DEPENDS)
message(STATUS " ${fq_target_name} depends on ${dep}")
endforeach()
endif()
@@ -498,6 +503,16 @@ function(add_integration_test test_name)
get_fq_target_name(${test_name}.libc fq_libc_target_name)
get_fq_deps_list(fq_deps_list ${INTEGRATION_TEST_DEPENDS})
+
+ if(SHOW_INTERMEDIATE_OBJECTS)
+ message(STATUS "Adding integration test ${fq_target_name}")
+ if(${SHOW_INTERMEDIATE_OBJECTS} STREQUAL "DEPS")
+ foreach(dep IN LISTS fq_deps_list)
+ message(STATUS " ${fq_target_name} depends on ${dep}")
+ endforeach()
+ endif()
+ endif()
+
list(APPEND fq_deps_list
# All integration tests use the operating system's startup object with the
# integration test object and need to inherit the same dependencies.
@@ -505,6 +520,7 @@ function(add_integration_test test_name)
libc.test.IntegrationTest.test
# We always add the memory functions objects. This is because the
# compiler's codegen can emit calls to the C memory functions.
+ libc.src.stdlib.atexit
libc.src.string.bcmp
libc.src.string.bzero
libc.src.string.memcmp
@@ -525,6 +541,16 @@ function(add_integration_test test_name)
# collect the object files with public names of entrypoints.
get_object_files_for_test(
link_object_files skipped_entrypoints_list FALSE ${fq_deps_list})
+
+ if(SHOW_INTERMEDIATE_OBJECTS)
+ message(STATUS "Get objects for test ${fq_target_name}")
+ if(${SHOW_INTERMEDIATE_OBJECTS} STREQUAL "DEPS")
+ foreach(dep IN LISTS link_object_files)
+ message(STATUS " ${fq_target_name} need object ${dep}")
+ endforeach()
+ endif()
+ endif()
+
if(skipped_entrypoints_list)
if(LIBC_CMAKE_VERBOSE_LOGGING)
set(msg "Skipping unittest ${fq_target_name} as it has missing deps: "
@@ -677,6 +703,16 @@ function(add_libc_hermetic_test test_name)
get_fq_target_name(${test_name}.libc fq_libc_target_name)
get_fq_deps_list(fq_deps_list ${HERMETIC_TEST_DEPENDS})
+
+ if(SHOW_INTERMEDIATE_OBJECTS)
+ message(STATUS "Adding hermetic test ${fq_target_name}")
+ if(${SHOW_INTERMEDIATE_OBJECTS} STREQUAL "DEPS")
+ foreach(dep IN LISTS fq_deps_list)
+ message(STATUS " ${fq_target_name} depends on ${dep}")
+ endforeach()
+ endif()
+ endif()
+
list(APPEND fq_deps_list
# Hermetic tests use the platform's startup object. So, their deps also
# have to be collected.
@@ -709,7 +745,17 @@ function(add_libc_hermetic_test test_name)
# collect the object files with public names of entrypoints.
get_object_files_for_test(
link_object_files skipped_entrypoints_list FALSE ${fq_deps_list})
- if(skipped_entrypoints_list)
+
+ if(SHOW_INTERMEDIATE_OBJECTS)
+ message(STATUS "Get objects for test ${fq_target_name}")
+ if(${SHOW_INTERMEDIATE_OBJECTS} STREQUAL "DEPS")
+ foreach(dep IN LISTS link_object_files)
+ message(STATUS " ${fq_target_name} need object ${dep}")
+ endforeach()
+ endif()
+ endif()
+
+ if(skipped_entrypoints_list)
set(msg "Skipping unittest ${fq_target_name} as it has missing deps: "
"${skipped_entrypoints_list}.")
message(STATUS ${msg})
>From 19b918a45ba2f2539645c46d3851ad81baba43cb Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue at google.com>
Date: Fri, 26 Jan 2024 02:21:44 -0500
Subject: [PATCH 3/4] Remove extra C functions in LibcTest.cpp,
HermeticTestUtils.cpp, and test.cpp that are not needed anymore.
---
libc/test/IntegrationTest/test.cpp | 41 ------------------------
libc/test/UnitTest/CMakeLists.txt | 9 +++++-
libc/test/UnitTest/HermeticTestUtils.cpp | 37 ---------------------
libc/test/UnitTest/LibcTest.cpp | 15 +++------
4 files changed, 12 insertions(+), 90 deletions(-)
diff --git a/libc/test/IntegrationTest/test.cpp b/libc/test/IntegrationTest/test.cpp
index 3bdbe89a3fb62d..b5cdaa7fdf9247 100644
--- a/libc/test/IntegrationTest/test.cpp
+++ b/libc/test/IntegrationTest/test.cpp
@@ -9,47 +9,6 @@
#include <stddef.h>
#include <stdint.h>
-// Integration tests rely on the following memory functions. This is because the
-// compiler code generation can emit calls to them. We want to map the external
-// entrypoint to the internal implementation of the function used for testing.
-// This is done manually as not all targets support aliases.
-
-namespace LIBC_NAMESPACE {
-
-int bcmp(const void *lhs, const void *rhs, size_t count);
-void bzero(void *ptr, size_t count);
-int memcmp(const void *lhs, const void *rhs, size_t count);
-void *memcpy(void *__restrict, const void *__restrict, size_t);
-void *memmove(void *dst, const void *src, size_t count);
-void *memset(void *ptr, int value, size_t count);
-int atexit(void (*func)(void));
-
-} // namespace LIBC_NAMESPACE
-
-extern "C" {
-
-int bcmp(const void *lhs, const void *rhs, size_t count) {
- return LIBC_NAMESPACE::bcmp(lhs, rhs, count);
-}
-void bzero(void *ptr, size_t count) { LIBC_NAMESPACE::bzero(ptr, count); }
-int memcmp(const void *lhs, const void *rhs, size_t count) {
- return LIBC_NAMESPACE::memcmp(lhs, rhs, count);
-}
-void *memcpy(void *__restrict dst, const void *__restrict src, size_t count) {
- return LIBC_NAMESPACE::memcpy(dst, src, count);
-}
-void *memmove(void *dst, const void *src, size_t count) {
- return LIBC_NAMESPACE::memmove(dst, src, count);
-}
-void *memset(void *ptr, int value, size_t count) {
- return LIBC_NAMESPACE::memset(ptr, value, count);
-}
-
-// This is needed if the test was compiled with '-fno-use-cxa-atexit'.
-int atexit(void (*func)(void)) { return LIBC_NAMESPACE::atexit(func); }
-
-} // extern "C"
-
// Integration tests cannot use the SCUDO standalone allocator as SCUDO pulls
// various other parts of the libc. Since SCUDO development does not use
// LLVM libc build rules, it is very hard to keep track or pull all that SCUDO
diff --git a/libc/test/UnitTest/CMakeLists.txt b/libc/test/UnitTest/CMakeLists.txt
index 9baa41874a83db..baa1b2fd73d3f0 100644
--- a/libc/test/UnitTest/CMakeLists.txt
+++ b/libc/test/UnitTest/CMakeLists.txt
@@ -18,6 +18,11 @@ function(add_unittest_framework_library name)
set(library_type STATIC)
endif()
+ set(clock_target "")
+ if(TARGET libc.src.time.clock)
+ set(clock_target libc.src.time.clock)
+ endif()
+
foreach(lib IN ITEMS ${name}.unit ${name}.hermetic)
add_library(
${lib}
@@ -28,7 +33,7 @@ function(add_unittest_framework_library name)
)
target_include_directories(${lib} PUBLIC ${LIBC_SOURCE_DIR})
target_compile_options(${lib} PRIVATE -fno-exceptions -fno-rtti)
- if(TARGET libc.src.time.clock)
+ if(${clock_target})
target_compile_definitions(${lib} PRIVATE TARGET_SUPPORTS_CLOCK)
endif()
endforeach()
@@ -70,6 +75,7 @@ add_unittest_framework_library(
libc.src.__support.CPP.type_traits
libc.src.__support.OSUtil.osutil
libc.src.__support.uint128
+ ${clock_target}
)
set(libc_death_test_srcs LibcDeathTestExecutors.cpp)
@@ -114,6 +120,7 @@ add_unittest_framework_library(
libc.src.__support.FPUtil.fpbits_str
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.rounding_mode
+ libc.src.errno.errno
)
add_unittest_framework_library(
diff --git a/libc/test/UnitTest/HermeticTestUtils.cpp b/libc/test/UnitTest/HermeticTestUtils.cpp
index 349c182ff2379f..145683976268a1 100644
--- a/libc/test/UnitTest/HermeticTestUtils.cpp
+++ b/libc/test/UnitTest/HermeticTestUtils.cpp
@@ -9,18 +9,6 @@
#include <stddef.h>
#include <stdint.h>
-namespace LIBC_NAMESPACE {
-
-int bcmp(const void *lhs, const void *rhs, size_t count);
-void bzero(void *ptr, size_t count);
-int memcmp(const void *lhs, const void *rhs, size_t count);
-void *memcpy(void *__restrict, const void *__restrict, size_t);
-void *memmove(void *dst, const void *src, size_t count);
-void *memset(void *ptr, int value, size_t count);
-int atexit(void (*func)(void));
-
-} // namespace LIBC_NAMESPACE
-
namespace {
// Integration tests cannot use the SCUDO standalone allocator as SCUDO pulls
@@ -37,31 +25,6 @@ static uint8_t *ptr = memory;
extern "C" {
-// Hermetic tests rely on the following memory functions. This is because the
-// compiler code generation can emit calls to them. We want to map the external
-// entrypoint to the internal implementation of the function used for testing.
-// This is done manually as not all targets support aliases.
-
-int bcmp(const void *lhs, const void *rhs, size_t count) {
- return LIBC_NAMESPACE::bcmp(lhs, rhs, count);
-}
-void bzero(void *ptr, size_t count) { LIBC_NAMESPACE::bzero(ptr, count); }
-int memcmp(const void *lhs, const void *rhs, size_t count) {
- return LIBC_NAMESPACE::memcmp(lhs, rhs, count);
-}
-void *memcpy(void *__restrict dst, const void *__restrict src, size_t count) {
- return LIBC_NAMESPACE::memcpy(dst, src, count);
-}
-void *memmove(void *dst, const void *src, size_t count) {
- return LIBC_NAMESPACE::memmove(dst, src, count);
-}
-void *memset(void *ptr, int value, size_t count) {
- return LIBC_NAMESPACE::memset(ptr, value, count);
-}
-
-// This is needed if the test was compiled with '-fno-use-cxa-atexit'.
-int atexit(void (*func)(void)) { return LIBC_NAMESPACE::atexit(func); }
-
constexpr uint64_t ALIGNMENT = alignof(uintptr_t);
void *malloc(size_t s) {
diff --git a/libc/test/UnitTest/LibcTest.cpp b/libc/test/UnitTest/LibcTest.cpp
index 201b40a178dca0..095c2feb803e69 100644
--- a/libc/test/UnitTest/LibcTest.cpp
+++ b/libc/test/UnitTest/LibcTest.cpp
@@ -13,17 +13,6 @@
#include "src/__support/UInt128.h"
#include "test/UnitTest/TestLogger.h"
-#if __STDC_HOSTED__
-#include <time.h>
-#define LIBC_TEST_USE_CLOCK
-#elif defined(TARGET_SUPPORTS_CLOCK)
-#include <time.h>
-
-#include "src/time/clock.h"
-extern "C" clock_t clock() noexcept { return LIBC_NAMESPACE::clock(); }
-#define LIBC_TEST_USE_CLOCK
-#endif
-
namespace LIBC_NAMESPACE {
namespace testing {
@@ -126,13 +115,17 @@ int Test::runTests(const char *TestFilter) {
continue;
}
tlog << GREEN << "[ RUN ] " << RESET << TestName << '\n';
+#ifdef LIBC_TEST_USE_CLOCK
[[maybe_unused]] const auto start_time = clock();
+#endif
RunContext Ctx;
T->SetUp();
T->setContext(&Ctx);
T->Run();
T->TearDown();
+#ifdef LIBC_TEST_USE_CLOCK
[[maybe_unused]] const auto end_time = clock();
+#endif // LIBC_TEST_USE_CLOCK
switch (Ctx.status()) {
case RunContext::RunResult::Fail:
tlog << RED << "[ FAILED ] " << RESET << TestName << '\n';
>From c0bb6b562c095e0b2d4d5d842f05afec190ce362 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue at google.com>
Date: Fri, 26 Jan 2024 02:24:54 -0500
Subject: [PATCH 4/4] Update libc_errno to work correctly for both overlay and
full build modes.
---
libc/src/errno/CMakeLists.txt | 7 ++
libc/src/errno/libc_errno.cpp | 56 +++++----
libc/src/errno/libc_errno.h | 42 ++-----
.../src/pthread/pthread_create_test.cpp | 52 ++++----
.../src/pthread/pthread_join_test.cpp | 4 +-
.../integration/src/unistd/getcwd_test.cpp | 2 +-
libc/test/src/dirent/dirent_test.cpp | 6 +-
libc/test/src/errno/errno_test.cpp | 2 +-
libc/test/src/fcntl/creat_test.cpp | 4 +-
libc/test/src/fcntl/openat_test.cpp | 4 +-
libc/test/src/sched/get_priority_test.cpp | 28 ++---
.../src/sched/param_and_scheduler_test.cpp | 34 +++---
.../src/sched/sched_rr_get_interval_test.cpp | 14 +--
libc/test/src/sched/yield_test.cpp | 2 +-
libc/test/src/stdio/fgets_test.cpp | 6 +-
libc/test/src/stdio/fileop_test.cpp | 6 +-
libc/test/src/stdio/fopencookie_test.cpp | 6 +-
libc/test/src/stdio/remove_test.cpp | 2 +-
libc/test/src/stdio/setvbuf_test.cpp | 2 +-
libc/test/src/stdio/unlocked_fileop_test.cpp | 4 +-
libc/test/src/stdlib/StrtolTest.h | 114 +++++++++---------
libc/test/src/stdlib/strtof_test.cpp | 2 +-
libc/test/src/stdlib/strtold_test.cpp | 2 +-
libc/test/src/string/strdup_test.cpp | 6 +-
libc/test/src/sys/mman/linux/madvise_test.cpp | 2 +-
libc/test/src/sys/mman/linux/mmap_test.cpp | 2 +-
.../test/src/sys/mman/linux/mprotect_test.cpp | 2 +-
.../src/sys/mman/linux/posix_madvise_test.cpp | 2 +-
libc/test/src/sys/prctl/linux/prctl_test.cpp | 2 +-
.../sys/resource/getrlimit_setrlimit_test.cpp | 12 +-
libc/test/src/sys/sendfile/sendfile_test.cpp | 8 +-
libc/test/src/sys/socket/linux/bind_test.cpp | 4 +-
.../test/src/sys/socket/linux/socket_test.cpp | 2 +-
libc/test/src/sys/stat/chmod_test.cpp | 8 +-
libc/test/src/sys/stat/fchmod_test.cpp | 10 +-
libc/test/src/sys/stat/fchmodat_test.cpp | 8 +-
libc/test/src/sys/stat/fstat_test.cpp | 2 +-
libc/test/src/sys/stat/lstat_test.cpp | 2 +-
libc/test/src/sys/stat/stat_test.cpp | 2 +-
libc/test/src/termios/termios_test.cpp | 4 +-
libc/test/src/time/asctime_r_test.cpp | 6 +-
libc/test/src/time/asctime_test.cpp | 10 +-
libc/test/src/time/gmtime_test.cpp | 4 +-
libc/test/src/time/nanosleep_test.cpp | 2 +-
libc/test/src/unistd/access_test.cpp | 16 +--
libc/test/src/unistd/chdir_test.cpp | 4 +-
libc/test/src/unistd/dup2_test.cpp | 8 +-
libc/test/src/unistd/dup3_test.cpp | 8 +-
libc/test/src/unistd/dup_test.cpp | 8 +-
libc/test/src/unistd/fchdir_test.cpp | 8 +-
libc/test/src/unistd/ftruncate_test.cpp | 8 +-
libc/test/src/unistd/isatty_test.cpp | 4 +-
libc/test/src/unistd/link_test.cpp | 4 +-
libc/test/src/unistd/linkat_test.cpp | 4 +-
libc/test/src/unistd/lseek_test.cpp | 4 +-
libc/test/src/unistd/pread_pwrite_test.cpp | 6 +-
libc/test/src/unistd/read_write_test.cpp | 4 +-
libc/test/src/unistd/readlink_test.cpp | 2 +-
libc/test/src/unistd/readlinkat_test.cpp | 2 +-
libc/test/src/unistd/symlink_test.cpp | 4 +-
libc/test/src/unistd/symlinkat_test.cpp | 4 +-
libc/test/src/unistd/syscall_test.cpp | 32 ++---
libc/test/src/unistd/truncate_test.cpp | 6 +-
libc/test/src/unistd/unlink_test.cpp | 2 +-
libc/test/src/unistd/unlinkat_test.cpp | 6 +-
65 files changed, 320 insertions(+), 325 deletions(-)
diff --git a/libc/src/errno/CMakeLists.txt b/libc/src/errno/CMakeLists.txt
index e8868dc48c5e97..368c67df2f165e 100644
--- a/libc/src/errno/CMakeLists.txt
+++ b/libc/src/errno/CMakeLists.txt
@@ -1,9 +1,16 @@
+set(full_build_flag "")
+if(LLVM_LIBC_FULL_BUILD)
+ set(full_build_flag "-DLIBC_FULL_BUILD")
+endif()
+
add_entrypoint_object(
errno
SRCS
libc_errno.cpp
HDRS
libc_errno.h # Include this
+ COMPILE_OPTIONS
+ ${full_build_flag}
DEPENDS
libc.include.errno
libc.src.__support.common
diff --git a/libc/src/errno/libc_errno.cpp b/libc/src/errno/libc_errno.cpp
index c8f0bffd0962e9..82632a8496de9b 100644
--- a/libc/src/errno/libc_errno.cpp
+++ b/libc/src/errno/libc_errno.cpp
@@ -11,30 +11,44 @@
namespace LIBC_NAMESPACE {
-#ifdef LIBC_TARGET_ARCH_IS_GPU
-struct ErrnoConsumer {
- void operator=(int) {}
+struct Errno {
+ void operator=(int);
+ operator int();
};
-#endif
-extern "C" {
-#ifdef LIBC_COPT_PUBLIC_PACKAGING
-// TODO: Declare __llvmlibc_errno only under LIBC_COPT_PUBLIC_PACKAGING and
-// __llvmlibc_internal_errno otherwise.
-// In overlay mode, this will be an unused thread local variable as libc_errno
-// will resolve to errno from the system libc's errno.h. In full build mode
-// however, libc_errno will resolve to this thread local variable via the errno
-// macro defined in LLVM libc's public errno.h header file.
-// TODO: Use a macro to distinguish full build and overlay build which can be
-// used to exclude __llvmlibc_errno under overlay build.
+} // namespace LIBC_NAMESPACE
+
#ifdef LIBC_TARGET_ARCH_IS_GPU
-ErrnoConsumer __llvmlibc_errno;
-#else
+// If we are targeting the GPU we currently don't support 'errno'. We simply
+// consume it.
+void LIBC_NAMESPACE::Errno::operator=(int) {}
+LIBC_NAMESPACE::Errno::operator int() { return 0; }
+
+#elif !defined(LIBC_COPT_PUBLIC_PACKAGING)
+// This mode is for unit testing. We just use another internal errno.
+LIBC_THREAD_LOCAL int __llvmlibc_internal_errno;
+
+void LIBC_NAMESPACE::Errno::operator=(int a) { __llvmlibc_internal_errno = a; }
+LIBC_NAMESPACE::Errno::operator int() { return __llvmlibc_internal_errno; }
+
+#elif defined(LIBC_FULL_BUILD)
+// This mode is for public libc archive, hermetic, and integration tests.
+// In full build mode, we provide all the errno storage ourselves.
+extern "C" {
LIBC_THREAD_LOCAL int __llvmlibc_errno;
-#endif // LIBC_TARGET_ARCH_IS_GPU
+}
+
+void LIBC_NAMESPACE::Errno::operator=(int a) { __llvmlibc_errno = a; }
+LIBC_NAMESPACE::Errno::operator int() { return __llvmlibc_errno; }
+
#else
-LIBC_THREAD_LOCAL int __llvmlibc_internal_errno;
-#endif
-} // extern "C"
+// In overlay mode, we simply use the system errno.
+#include <errno.h>
-} // namespace LIBC_NAMESPACE
+void LIBC_NAMESPACE::Errno::operator=(int a) { errno = a; }
+LIBC_NAMESPACE::Errno::operator int() { return errno; }
+
+#endif // LIBC_FULL_BUILD
+
+// Define the global `libc_errno` instance.
+LIBC_NAMESPACE::Errno libc_errno;
diff --git a/libc/src/errno/libc_errno.h b/libc/src/errno/libc_errno.h
index fbcd1c3395cd1f..b0bfcddeb25910 100644
--- a/libc/src/errno/libc_errno.h
+++ b/libc/src/errno/libc_errno.h
@@ -14,43 +14,17 @@
#include <errno.h>
-// If we are targeting the GPU we currently don't support 'errno'. We simply
-// consume it.
-#ifdef LIBC_TARGET_ARCH_IS_GPU
+// This header is to be consumed by internal implementations, in which all of
+// them should refer to `libc_errno` instead of using `errno` directly from
+// <errno.h> header.
+
namespace LIBC_NAMESPACE {
-struct ErrnoConsumer {
- void operator=(int) {}
+struct Errno {
+ void operator=(int);
+ operator int();
};
} // namespace LIBC_NAMESPACE
-#endif
-
-// All of the libc runtime and test code should use the "libc_errno" macro. They
-// should not refer to the "errno" macro directly.
-#ifdef LIBC_COPT_PUBLIC_PACKAGING
-#ifdef LIBC_TARGET_ARCH_IS_GPU
-extern "C" LIBC_NAMESPACE::ErrnoConsumer __llvmlibc_errno;
-#define libc_errno __llvmlibc_errno
-#else
-// This macro will resolve to errno from the errno.h file included above. Under
-// full build, this will be LLVM libc's errno. In overlay build, it will be
-// system libc's errno.
-#define libc_errno errno
-#endif
-#else
-namespace LIBC_NAMESPACE {
-// TODO: On the GPU build this will be mapped to a single global value. We need
-// to ensure that tests are not run with multiple threads that depend on errno
-// until we have true 'thread_local' support on the GPU.
-extern "C" LIBC_THREAD_LOCAL int __llvmlibc_internal_errno;
-
-// TODO: After all of libc/src and libc/test are switched over to use
-// libc_errno, this header file will be "shipped" via an add_entrypoint_object
-// target. At which point libc_errno, should point to __llvmlibc_internal_errno
-// if LIBC_COPT_PUBLIC_PACKAGING is not defined.
-#define libc_errno LIBC_NAMESPACE::__llvmlibc_internal_errno
-
-} // namespace LIBC_NAMESPACE
-#endif
+extern LIBC_NAMESPACE::Errno libc_errno;
#endif // LLVM_LIBC_SRC_ERRNO_LIBC_ERRNO_H
diff --git a/libc/test/integration/src/pthread/pthread_create_test.cpp b/libc/test/integration/src/pthread/pthread_create_test.cpp
index 6a9b44cc1422cc..cd4d7988405409 100644
--- a/libc/test/integration/src/pthread/pthread_create_test.cpp
+++ b/libc/test/integration/src/pthread/pthread_create_test.cpp
@@ -47,7 +47,7 @@ static void *successThread(void *Arg) {
pthread_t th = LIBC_NAMESPACE::pthread_self();
auto *thread = reinterpret_cast<LIBC_NAMESPACE::Thread *>(&th);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_TRUE(thread);
ASSERT_TRUE(thread->attrib);
@@ -62,22 +62,22 @@ static void *successThread(void *Arg) {
ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_getstack(expec_attrs, &expec_stack,
&expec_stacksize),
0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(
LIBC_NAMESPACE::pthread_attr_getstacksize(expec_attrs, &expec_stacksize2),
0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(
LIBC_NAMESPACE::pthread_attr_getguardsize(expec_attrs, &expec_guardsize),
0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(
LIBC_NAMESPACE::pthread_attr_getdetachstate(expec_attrs, &expec_detached),
0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(expec_stacksize, expec_stacksize2);
@@ -125,7 +125,7 @@ static void *successThread(void *Arg) {
// permissions. Maybe we can read from /proc/{self}/map?
ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_destroy(expec_attrs), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
// Arg is malloced, so free.
delete th_arg;
@@ -140,13 +140,13 @@ static void run_success_config(int detachstate, size_t guardsize,
pthread_attr_t *attr = &(th_arg->attrs);
ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_init(attr), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_setdetachstate(attr, detachstate), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_setguardsize(attr, guardsize), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
void *Stack = nullptr;
if (customstack) {
@@ -154,20 +154,20 @@ static void run_success_config(int detachstate, size_t guardsize,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
ASSERT_NE(Stack, MAP_FAILED);
ASSERT_NE(Stack, static_cast<void *>(nullptr));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_setstack(attr, Stack, stacksize), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
} else {
ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_setstacksize(attr, stacksize), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
}
void *expec_ret = nullptr;
if (detachstate == PTHREAD_CREATE_JOINABLE) {
ASSERT_EQ(LIBC_NAMESPACE::getrandom(&expec_ret, sizeof(expec_ret), 0),
static_cast<ssize_t>(sizeof(expec_ret)));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
}
th_arg->ret = expec_ret;
@@ -178,17 +178,17 @@ static void run_success_config(int detachstate, size_t guardsize,
ASSERT_EQ(LIBC_NAMESPACE::pthread_create(&tid, attr, successThread,
reinterpret_cast<void *>(th_arg)),
0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
if (detachstate == PTHREAD_CREATE_JOINABLE) {
void *th_ret;
ASSERT_EQ(LIBC_NAMESPACE::pthread_join(tid, &th_ret), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(th_ret, expec_ret);
if (customstack) {
ASSERT_EQ(LIBC_NAMESPACE::munmap(Stack, stacksize), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
}
} else {
ASSERT_FALSE(customstack);
@@ -260,23 +260,23 @@ static void create_and_check_failure_thread(pthread_attr_t *attr) {
// was just really larger we failed mmap.
ASSERT_TRUE(result == EINVAL || result == EAGAIN);
// pthread_create should NOT set errno on error
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_destroy(attr), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
}
static void run_failure_config(size_t guardsize, size_t stacksize) {
pthread_attr_t attr;
guardsize &= -EXEC_PAGESIZE;
ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_init(&attr), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_setguardsize(&attr, guardsize), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_setstacksize(&attr, stacksize), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
create_and_check_failure_thread(&attr);
}
@@ -301,32 +301,32 @@ static void run_failure_tests() {
// Stacksize too small.
ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_init(&attr), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
attr.__stacksize = PTHREAD_STACK_MIN - 16;
create_and_check_failure_thread(&attr);
// Stack misaligned.
ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_init(&attr), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
attr.__stack = reinterpret_cast<void *>(1);
create_and_check_failure_thread(&attr);
// Stack + stacksize misaligned.
ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_init(&attr), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
attr.__stacksize = PTHREAD_STACK_MIN + 1;
attr.__stack = reinterpret_cast<void *>(16);
create_and_check_failure_thread(&attr);
// Guardsize misaligned.
ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_init(&attr), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
attr.__guardsize = EXEC_PAGESIZE / 2;
create_and_check_failure_thread(&attr);
// Detachstate is unknown.
ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_init(&attr), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
attr.__detachstate = -1;
create_and_check_failure_thread(&attr);
}
diff --git a/libc/test/integration/src/pthread/pthread_join_test.cpp b/libc/test/integration/src/pthread/pthread_join_test.cpp
index f4126357a0579d..bff5a486b5ffdf 100644
--- a/libc/test/integration/src/pthread/pthread_join_test.cpp
+++ b/libc/test/integration/src/pthread/pthread_join_test.cpp
@@ -19,9 +19,9 @@ static void nullJoinTest() {
pthread_t Tid;
ASSERT_EQ(LIBC_NAMESPACE::pthread_create(&Tid, nullptr, simpleFunc, nullptr),
0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(LIBC_NAMESPACE::pthread_join(Tid, nullptr), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
}
TEST_MAIN() {
diff --git a/libc/test/integration/src/unistd/getcwd_test.cpp b/libc/test/integration/src/unistd/getcwd_test.cpp
index 3d8f5821a69efc..6b3bbdd32845b6 100644
--- a/libc/test/integration/src/unistd/getcwd_test.cpp
+++ b/libc/test/integration/src/unistd/getcwd_test.cpp
@@ -30,7 +30,7 @@ TEST_MAIN(int argc, char **argv, char **envp) {
// Bad size
cwd = LIBC_NAMESPACE::getcwd(buffer, 0);
ASSERT_TRUE(cwd == nullptr);
- ASSERT_EQ(libc_errno, EINVAL);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
libc_errno = 0;
// Insufficient size
diff --git a/libc/test/src/dirent/dirent_test.cpp b/libc/test/src/dirent/dirent_test.cpp
index ff1a30a2639fe2..08e57711884618 100644
--- a/libc/test/src/dirent/dirent_test.cpp
+++ b/libc/test/src/dirent/dirent_test.cpp
@@ -44,7 +44,7 @@ TEST(LlvmLibcDirentTest, SimpleOpenAndRead) {
}
// Verify that we don't break out of the above loop in error.
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_TRUE(file1 != nullptr);
ASSERT_TRUE(file2 != nullptr);
@@ -58,7 +58,7 @@ TEST(LlvmLibcDirentTest, OpenNonExistentDir) {
libc_errno = 0;
::DIR *dir = LIBC_NAMESPACE::opendir("___xyz123__.non_existent__");
ASSERT_TRUE(dir == nullptr);
- ASSERT_EQ(libc_errno, ENOENT);
+ ASSERT_EQ(static_cast<int>(libc_errno), ENOENT);
libc_errno = 0;
}
@@ -66,6 +66,6 @@ TEST(LlvmLibcDirentTest, OpenFile) {
libc_errno = 0;
::DIR *dir = LIBC_NAMESPACE::opendir("testdata/file1.txt");
ASSERT_TRUE(dir == nullptr);
- ASSERT_EQ(libc_errno, ENOTDIR);
+ ASSERT_EQ(static_cast<int>(libc_errno), ENOTDIR);
libc_errno = 0;
}
diff --git a/libc/test/src/errno/errno_test.cpp b/libc/test/src/errno/errno_test.cpp
index 33185c2bcf6f54..6e08a79a109c92 100644
--- a/libc/test/src/errno/errno_test.cpp
+++ b/libc/test/src/errno/errno_test.cpp
@@ -12,5 +12,5 @@
TEST(LlvmLibcErrnoTest, Basic) {
int test_val = 123;
libc_errno = test_val;
- ASSERT_EQ(test_val, libc_errno);
+ ASSERT_EQ(static_cast<int>(libc_errno), test_val);
}
diff --git a/libc/test/src/fcntl/creat_test.cpp b/libc/test/src/fcntl/creat_test.cpp
index ef30d8862c45f2..472f2ccabe246b 100644
--- a/libc/test/src/fcntl/creat_test.cpp
+++ b/libc/test/src/fcntl/creat_test.cpp
@@ -19,12 +19,12 @@ TEST(LlvmLibcCreatTest, CreatAndOpen) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/creat.test";
int fd = LIBC_NAMESPACE::creat(TEST_FILE, S_IRWXU);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(fd, 0);
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
fd = LIBC_NAMESPACE::open(TEST_FILE, O_RDONLY);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(fd, 0);
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
diff --git a/libc/test/src/fcntl/openat_test.cpp b/libc/test/src/fcntl/openat_test.cpp
index b95f3f21272011..b91799875f6520 100644
--- a/libc/test/src/fcntl/openat_test.cpp
+++ b/libc/test/src/fcntl/openat_test.cpp
@@ -21,13 +21,13 @@ TEST(LlvmLibcUniStd, OpenAndReadTest) {
constexpr const char *TEST_DIR = "testdata";
constexpr const char *TEST_FILE = "openat.test";
int dir_fd = LIBC_NAMESPACE::open(TEST_DIR, O_DIRECTORY);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(dir_fd, 0);
constexpr const char TEST_MSG[] = "openat test";
constexpr int TEST_MSG_SIZE = sizeof(TEST_MSG) - 1;
int read_fd = LIBC_NAMESPACE::openat(dir_fd, TEST_FILE, O_RDONLY);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(read_fd, 0);
char read_buf[TEST_MSG_SIZE];
ASSERT_THAT(LIBC_NAMESPACE::read(read_fd, read_buf, TEST_MSG_SIZE),
diff --git a/libc/test/src/sched/get_priority_test.cpp b/libc/test/src/sched/get_priority_test.cpp
index 3a79a67802cf3e..4287e11b919dcf 100644
--- a/libc/test/src/sched/get_priority_test.cpp
+++ b/libc/test/src/sched/get_priority_test.cpp
@@ -20,40 +20,40 @@ TEST(LlvmLibcSchedGetPriorityTest, HandleBadPolicyTest) {
int policy = -1;
int max_priority = LIBC_NAMESPACE::sched_get_priority_max(policy);
ASSERT_EQ(max_priority, -1);
- ASSERT_EQ(libc_errno, EINVAL);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
int min_priority = LIBC_NAMESPACE::sched_get_priority_min(policy);
ASSERT_EQ(min_priority, -1);
- ASSERT_EQ(libc_errno, EINVAL);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
}
{
int policy = 30;
int max_priority = LIBC_NAMESPACE::sched_get_priority_max(policy);
ASSERT_EQ(max_priority, -1);
- ASSERT_EQ(libc_errno, EINVAL);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
int min_priority = LIBC_NAMESPACE::sched_get_priority_min(policy);
ASSERT_EQ(min_priority, -1);
- ASSERT_EQ(libc_errno, EINVAL);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
}
{
int policy = 80;
int max_priority = LIBC_NAMESPACE::sched_get_priority_max(policy);
ASSERT_EQ(max_priority, -1);
- ASSERT_EQ(libc_errno, EINVAL);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
int min_priority = LIBC_NAMESPACE::sched_get_priority_min(policy);
ASSERT_EQ(min_priority, -1);
- ASSERT_EQ(libc_errno, EINVAL);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
}
{
int policy = 110;
int max_priority = LIBC_NAMESPACE::sched_get_priority_max(policy);
ASSERT_EQ(max_priority, -1);
- ASSERT_EQ(libc_errno, EINVAL);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
int min_priority = LIBC_NAMESPACE::sched_get_priority_min(policy);
ASSERT_EQ(min_priority, -1);
- ASSERT_EQ(libc_errno, EINVAL);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
}
}
@@ -68,10 +68,10 @@ TEST(LlvmLibcSchedGetPriorityTest, SmokeTest) {
int policy = SCHED_OTHER;
int max_priority = LIBC_NAMESPACE::sched_get_priority_max(policy);
ASSERT_GE(max_priority, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
int min_priority = LIBC_NAMESPACE::sched_get_priority_min(policy);
ASSERT_GE(min_priority, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_LE(max_priority, 99);
ASSERT_GE(min_priority, 0);
@@ -82,10 +82,10 @@ TEST(LlvmLibcSchedGetPriorityTest, SmokeTest) {
int policy = SCHED_FIFO;
int max_priority = LIBC_NAMESPACE::sched_get_priority_max(policy);
ASSERT_GE(max_priority, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
int min_priority = LIBC_NAMESPACE::sched_get_priority_min(policy);
ASSERT_GE(min_priority, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_LE(max_priority, 99);
ASSERT_GE(min_priority, 0);
@@ -96,10 +96,10 @@ TEST(LlvmLibcSchedGetPriorityTest, SmokeTest) {
int policy = SCHED_RR;
int max_priority = LIBC_NAMESPACE::sched_get_priority_max(policy);
ASSERT_GE(max_priority, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
int min_priority = LIBC_NAMESPACE::sched_get_priority_min(policy);
ASSERT_GE(min_priority, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_LE(max_priority, 99);
ASSERT_GE(min_priority, 0);
diff --git a/libc/test/src/sched/param_and_scheduler_test.cpp b/libc/test/src/sched/param_and_scheduler_test.cpp
index 8c6485f0789712..448106fbb90816 100644
--- a/libc/test/src/sched/param_and_scheduler_test.cpp
+++ b/libc/test/src/sched/param_and_scheduler_test.cpp
@@ -41,35 +41,35 @@ class SchedTest : public LIBC_NAMESPACE::testing::Test {
int init_policy = LIBC_NAMESPACE::sched_getscheduler(0);
ASSERT_GE(init_policy, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
int max_priority = LIBC_NAMESPACE::sched_get_priority_max(policy);
ASSERT_GE(max_priority, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
int min_priority = LIBC_NAMESPACE::sched_get_priority_min(policy);
ASSERT_GE(min_priority, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
struct sched_param param = {min_priority};
// Negative pid
ASSERT_EQ(LIBC_NAMESPACE::sched_setscheduler(-1, policy, ¶m), -1);
- ASSERT_EQ(libc_errno, EINVAL);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
libc_errno = 0;
ASSERT_EQ(LIBC_NAMESPACE::sched_getscheduler(-1), -1);
- ASSERT_EQ(libc_errno, EINVAL);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
libc_errno = 0;
// Invalid Policy
ASSERT_EQ(LIBC_NAMESPACE::sched_setscheduler(0, policy | 128, ¶m), -1);
- ASSERT_EQ(libc_errno, EINVAL);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
libc_errno = 0;
// Out of bounds priority
param.sched_priority = min_priority - 1;
ASSERT_EQ(LIBC_NAMESPACE::sched_setscheduler(0, policy, ¶m), -1);
- ASSERT_EQ(libc_errno, EINVAL);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
libc_errno = 0;
param.sched_priority = max_priority + 1;
@@ -90,33 +90,33 @@ class SchedTest : public LIBC_NAMESPACE::testing::Test {
ASSERT_EQ(LIBC_NAMESPACE::sched_getscheduler(0),
can_set ? policy : init_policy);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
// Out of bounds priority
param.sched_priority = -1;
ASSERT_EQ(LIBC_NAMESPACE::sched_setparam(0, ¶m), -1);
- ASSERT_EQ(libc_errno, EINVAL);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
libc_errno = 0;
param.sched_priority = max_priority + 1;
ASSERT_EQ(LIBC_NAMESPACE::sched_setparam(0, ¶m), -1);
- ASSERT_EQ(libc_errno, EINVAL);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
libc_errno = 0;
for (int priority = min_priority; priority <= max_priority; ++priority) {
ASSERT_EQ(LIBC_NAMESPACE::sched_getparam(0, ¶m), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
int init_priority = param.sched_priority;
param.sched_priority = priority;
// Negative pid
ASSERT_EQ(LIBC_NAMESPACE::sched_setparam(-1, ¶m), -1);
- ASSERT_EQ(libc_errno, EINVAL);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
libc_errno = 0;
ASSERT_EQ(LIBC_NAMESPACE::sched_getparam(-1, ¶m), -1);
- ASSERT_EQ(libc_errno, EINVAL);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
libc_errno = 0;
// Success / missing permissions
@@ -126,14 +126,14 @@ class SchedTest : public LIBC_NAMESPACE::testing::Test {
libc_errno = 0;
ASSERT_EQ(LIBC_NAMESPACE::sched_getparam(0, ¶m), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(param.sched_priority, can_set ? priority : init_priority);
}
// Null test
ASSERT_EQ(LIBC_NAMESPACE::sched_setscheduler(0, policy, nullptr), -1);
- ASSERT_EQ(libc_errno, EINVAL);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
libc_errno = 0;
}
};
@@ -155,10 +155,10 @@ TEST(LlvmLibcSchedParamAndSchedulerTest, NullParamTest) {
libc_errno = 0;
ASSERT_EQ(LIBC_NAMESPACE::sched_setparam(0, nullptr), -1);
- ASSERT_EQ(libc_errno, EINVAL);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
libc_errno = 0;
ASSERT_EQ(LIBC_NAMESPACE::sched_getparam(0, nullptr), -1);
- ASSERT_EQ(libc_errno, EINVAL);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
libc_errno = 0;
}
diff --git a/libc/test/src/sched/sched_rr_get_interval_test.cpp b/libc/test/src/sched/sched_rr_get_interval_test.cpp
index 10010007950416..c438d40638174d 100644
--- a/libc/test/src/sched/sched_rr_get_interval_test.cpp
+++ b/libc/test/src/sched/sched_rr_get_interval_test.cpp
@@ -21,11 +21,11 @@ TEST(LlvmLibcSchedRRGetIntervalTest, SmokeTest) {
auto SetSched = [&](int policy) {
int min_priority = LIBC_NAMESPACE::sched_get_priority_min(policy);
ASSERT_GE(min_priority, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
struct sched_param param;
param.sched_priority = min_priority;
ASSERT_EQ(LIBC_NAMESPACE::sched_setscheduler(0, policy, ¶m), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
};
auto TimespecToNs = [](struct timespec t) {
@@ -41,13 +41,13 @@ TEST(LlvmLibcSchedRRGetIntervalTest, SmokeTest) {
int cur_policy = LIBC_NAMESPACE::sched_getscheduler(0);
ASSERT_GE(cur_policy, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
// We can actually run meaningful tests.
if (cur_policy == SCHED_RR) {
// Success
ASSERT_EQ(LIBC_NAMESPACE::sched_rr_get_interval(0, &ts), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
// Check that numbers make sense (liberal bound of 10ns - 30sec)
constexpr uint64_t tenNs = 10UL;
@@ -57,19 +57,19 @@ TEST(LlvmLibcSchedRRGetIntervalTest, SmokeTest) {
// Null timespec
ASSERT_EQ(LIBC_NAMESPACE::sched_rr_get_interval(0, nullptr), -1);
- ASSERT_EQ(libc_errno, EFAULT);
+ ASSERT_EQ(static_cast<int>(libc_errno), EFAULT);
libc_errno = 0;
// Negative pid
ASSERT_EQ(LIBC_NAMESPACE::sched_rr_get_interval(-1, &ts), -1);
- ASSERT_EQ(libc_errno, EINVAL);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
libc_errno = 0;
}
// Negative tests don't have SCHED_RR set
SetSched(SCHED_OTHER);
ASSERT_EQ(LIBC_NAMESPACE::sched_rr_get_interval(0, &ts), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
libc_errno = 0;
// TODO: Missing unkown pid -> ESRCH. This is read only so safe to try a few
diff --git a/libc/test/src/sched/yield_test.cpp b/libc/test/src/sched/yield_test.cpp
index 45b7a7d2d81e47..982a923bfbf95c 100644
--- a/libc/test/src/sched/yield_test.cpp
+++ b/libc/test/src/sched/yield_test.cpp
@@ -15,5 +15,5 @@ TEST(LlvmLibcSchedYieldTest, SmokeTest) {
// sched_yield() always succeeds, just do a basic test that errno/ret are
// properly 0.
ASSERT_EQ(LIBC_NAMESPACE::sched_yield(), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
}
diff --git a/libc/test/src/stdio/fgets_test.cpp b/libc/test/src/stdio/fgets_test.cpp
index 9f9841c901f4ed..8333376caf62c7 100644
--- a/libc/test/src/stdio/fgets_test.cpp
+++ b/libc/test/src/stdio/fgets_test.cpp
@@ -48,7 +48,7 @@ TEST(LlvmLibcFgetsTest, WriteAndReadCharacters) {
output = LIBC_NAMESPACE::fgets(buff, 1, file);
ASSERT_TRUE(output == buff);
ASSERT_EQ(buff[0], '\0');
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
// If we request less than 1 byte, it should do nothing and return nullptr.
// This is also implementation defined.
@@ -76,13 +76,13 @@ TEST(LlvmLibcFgetsTest, WriteAndReadCharacters) {
// fails to read anything.
ASSERT_NE(LIBC_NAMESPACE::feof(file), 0);
ASSERT_EQ(LIBC_NAMESPACE::ferror(file), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
// Reading more should be an EOF, but not an error.
output = LIBC_NAMESPACE::fgets(buff, 8, file);
ASSERT_TRUE(output == nullptr);
ASSERT_NE(LIBC_NAMESPACE::feof(file), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(0, LIBC_NAMESPACE::fclose(file));
}
diff --git a/libc/test/src/stdio/fileop_test.cpp b/libc/test/src/stdio/fileop_test.cpp
index d5478e58eecbf9..be491311385ad2 100644
--- a/libc/test/src/stdio/fileop_test.cpp
+++ b/libc/test/src/stdio/fileop_test.cpp
@@ -121,16 +121,16 @@ TEST(LlvmLibcFILETest, SimpleFileOperations) {
// libc_errno = 0;
// ASSERT_NE(LIBC_NAMESPACE::fseek(file, 0, SEEK_SET), 0);
- // EXPECT_NE(libc_errno, 0);
+ // EXPECT_NE(static_cast<int>(libc_errno), 0);
// libc_errno = 0;
// ASSERT_NE(LIBC_NAMESPACE::fclose(file), 0);
- // EXPECT_NE(libc_errno, 0);
+ // EXPECT_NE(static_cast<int>(libc_errno), 0);
// libc_errno = 0;
// ASSERT_EQ(LIBC_NAMESPACE::fopen("INVALID FILE NAME", "r"),
// static_cast<FILE *>(nullptr));
- // EXPECT_NE(libc_errno, 0);
+ // EXPECT_NE(static_cast<int>(libc_errno), 0);
}
TEST(LlvmLibcFILETest, FFlush) {
diff --git a/libc/test/src/stdio/fopencookie_test.cpp b/libc/test/src/stdio/fopencookie_test.cpp
index 6f3c2910cfd823..1671547742bdbc 100644
--- a/libc/test/src/stdio/fopencookie_test.cpp
+++ b/libc/test/src/stdio/fopencookie_test.cpp
@@ -114,7 +114,7 @@ TEST(LlvmLibcFOpenCookie, ReadOnlyCookieTest) {
// Should be an error to write.
ASSERT_EQ(size_t(0), LIBC_NAMESPACE::fwrite(CONTENT, 1, sizeof(CONTENT), f));
ASSERT_NE(LIBC_NAMESPACE::ferror(f), 0);
- ASSERT_NE(libc_errno, 0);
+ ASSERT_NE(static_cast<int>(libc_errno), 0);
libc_errno = 0;
LIBC_NAMESPACE::clearerr(f);
@@ -148,7 +148,7 @@ TEST(LlvmLibcFOpenCookie, WriteOnlyCookieTest) {
ASSERT_EQ(size_t(0),
LIBC_NAMESPACE::fread(read_data, 1, sizeof(WRITE_DATA), f));
ASSERT_NE(LIBC_NAMESPACE::ferror(f), 0);
- ASSERT_EQ(libc_errno, EBADF);
+ ASSERT_EQ(static_cast<int>(libc_errno), EBADF);
libc_errno = 0;
LIBC_NAMESPACE::clearerr(f);
@@ -177,7 +177,7 @@ TEST(LlvmLibcFOpenCookie, AppendOnlyCookieTest) {
// This is not a readable file.
ASSERT_EQ(LIBC_NAMESPACE::fread(read_data, 1, READ_SIZE, f), size_t(0));
ASSERT_NE(LIBC_NAMESPACE::ferror(f), 0);
- EXPECT_NE(libc_errno, 0);
+ EXPECT_NE(static_cast<int>(libc_errno), 0);
libc_errno = 0;
LIBC_NAMESPACE::clearerr(f);
diff --git a/libc/test/src/stdio/remove_test.cpp b/libc/test/src/stdio/remove_test.cpp
index ce4a1352d1cc1a..c665c6feb6b85e 100644
--- a/libc/test/src/stdio/remove_test.cpp
+++ b/libc/test/src/stdio/remove_test.cpp
@@ -25,7 +25,7 @@ TEST(LlvmLibcRemoveTest, CreateAndRemoveFile) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/remove.test.file";
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(fd, 0);
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
diff --git a/libc/test/src/stdio/setvbuf_test.cpp b/libc/test/src/stdio/setvbuf_test.cpp
index 2faa01a15ec108..6b357fe9ebb61f 100644
--- a/libc/test/src/stdio/setvbuf_test.cpp
+++ b/libc/test/src/stdio/setvbuf_test.cpp
@@ -100,7 +100,7 @@ TEST(LlvmLibcSetbufTest, InvalidBufferMode) {
char buf[BUFSIZ];
ASSERT_NE(LIBC_NAMESPACE::setvbuf(f, buf, _IOFBF + _IOLBF + _IONBF, BUFSIZ),
0);
- ASSERT_EQ(libc_errno, EINVAL);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
libc_errno = 0;
ASSERT_EQ(0, LIBC_NAMESPACE::fclose(f));
diff --git a/libc/test/src/stdio/unlocked_fileop_test.cpp b/libc/test/src/stdio/unlocked_fileop_test.cpp
index cf51e8caa6a550..14f61053344b7b 100644
--- a/libc/test/src/stdio/unlocked_fileop_test.cpp
+++ b/libc/test/src/stdio/unlocked_fileop_test.cpp
@@ -36,7 +36,7 @@ TEST(LlvmLibcFILETest, UnlockedReadAndWrite) {
ASSERT_EQ(size_t(0),
LIBC_NAMESPACE::fread_unlocked(data, 1, sizeof(READ_SIZE), f));
ASSERT_NE(LIBC_NAMESPACE::ferror_unlocked(f), 0);
- ASSERT_NE(libc_errno, 0);
+ ASSERT_NE(static_cast<int>(libc_errno), 0);
libc_errno = 0;
LIBC_NAMESPACE::clearerr_unlocked(f);
@@ -57,7 +57,7 @@ TEST(LlvmLibcFILETest, UnlockedReadAndWrite) {
ASSERT_EQ(size_t(0),
LIBC_NAMESPACE::fwrite_unlocked(CONTENT, 1, sizeof(CONTENT), f));
ASSERT_NE(LIBC_NAMESPACE::ferror_unlocked(f), 0);
- ASSERT_NE(libc_errno, 0);
+ ASSERT_NE(static_cast<int>(libc_errno), 0);
libc_errno = 0;
LIBC_NAMESPACE::clearerr_unlocked(f);
diff --git a/libc/test/src/stdlib/StrtolTest.h b/libc/test/src/stdlib/StrtolTest.h
index 11794c4bfe05f8..5078ce117b35ea 100644
--- a/libc/test/src/stdlib/StrtolTest.h
+++ b/libc/test/src/stdlib/StrtolTest.h
@@ -38,7 +38,7 @@ struct StrtoTest : public LIBC_NAMESPACE::testing::Test {
const char *ten = "10";
libc_errno = 0;
ASSERT_EQ(func(ten, nullptr, -1), ReturnT(0));
- ASSERT_EQ(libc_errno, EINVAL);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
}
void CleanBaseTenDecode(FunctionT func) {
@@ -48,23 +48,23 @@ struct StrtoTest : public LIBC_NAMESPACE::testing::Test {
const char *ten = "10";
libc_errno = 0;
ASSERT_EQ(func(ten, &str_end, 10), ReturnT(10));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - ten, ptrdiff_t(2));
libc_errno = 0;
ASSERT_EQ(func(ten, nullptr, 10), ReturnT(10));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
const char *hundred = "100";
libc_errno = 0;
ASSERT_EQ(func(hundred, &str_end, 10), ReturnT(100));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - hundred, ptrdiff_t(3));
const char *big_number = "1234567890";
libc_errno = 0;
ASSERT_EQ(func(big_number, &str_end, 10), ReturnT(1234567890));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - big_number, ptrdiff_t(10));
// This number is larger than 2^32, meaning that if long is only 32 bits
@@ -73,24 +73,24 @@ struct StrtoTest : public LIBC_NAMESPACE::testing::Test {
libc_errno = 0;
if constexpr (sizeof(ReturnT) < 8) {
ASSERT_EQ(func(bigger_number, &str_end, 10), T_MAX);
- ASSERT_EQ(libc_errno, ERANGE);
+ ASSERT_EQ(static_cast<int>(libc_errno), ERANGE);
} else {
ASSERT_EQ(func(bigger_number, &str_end, 10), ReturnT(12345678900));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
}
EXPECT_EQ(str_end - bigger_number, ptrdiff_t(11));
const char *too_big_number = "123456789012345678901";
libc_errno = 0;
ASSERT_EQ(func(too_big_number, &str_end, 10), T_MAX);
- ASSERT_EQ(libc_errno, ERANGE);
+ ASSERT_EQ(static_cast<int>(libc_errno), ERANGE);
EXPECT_EQ(str_end - too_big_number, ptrdiff_t(21));
const char *long_number_range_test =
"10000000000000000000000000000000000000000000000000";
libc_errno = 0;
ASSERT_EQ(func(long_number_range_test, &str_end, 10), T_MAX);
- ASSERT_EQ(libc_errno, ERANGE);
+ ASSERT_EQ(static_cast<int>(libc_errno), ERANGE);
EXPECT_EQ(str_end - long_number_range_test, ptrdiff_t(50));
// For most negative numbers, the unsigned functions treat it the same as
@@ -98,13 +98,13 @@ struct StrtoTest : public LIBC_NAMESPACE::testing::Test {
const char *negative = "-100";
libc_errno = 0;
ASSERT_EQ(func(negative, &str_end, 10), ReturnT(-100));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - negative, ptrdiff_t(4));
const char *big_negative_number = "-1234567890";
libc_errno = 0;
ASSERT_EQ(func(big_negative_number, &str_end, 10), ReturnT(-1234567890));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - big_negative_number, ptrdiff_t(11));
const char *too_big_negative_number = "-123456789012345678901";
@@ -118,7 +118,7 @@ struct StrtoTest : public LIBC_NAMESPACE::testing::Test {
// Note that 0 is not on that list.
ASSERT_EQ(func(too_big_negative_number, &str_end, 10),
(is_signed_v<ReturnT> ? T_MIN : T_MAX));
- ASSERT_EQ(libc_errno, ERANGE);
+ ASSERT_EQ(static_cast<int>(libc_errno), ERANGE);
EXPECT_EQ(str_end - too_big_negative_number, ptrdiff_t(22));
}
@@ -128,73 +128,73 @@ struct StrtoTest : public LIBC_NAMESPACE::testing::Test {
const char *spaces_before = " 10";
libc_errno = 0;
ASSERT_EQ(func(spaces_before, &str_end, 10), ReturnT(10));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - spaces_before, ptrdiff_t(7));
const char *spaces_after = "10 ";
libc_errno = 0;
ASSERT_EQ(func(spaces_after, &str_end, 10), ReturnT(10));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - spaces_after, ptrdiff_t(2));
const char *word_before = "word10";
libc_errno = 0;
ASSERT_EQ(func(word_before, &str_end, 10), ReturnT(0));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - word_before, ptrdiff_t(0));
const char *word_after = "10word";
libc_errno = 0;
ASSERT_EQ(func(word_after, &str_end, 10), ReturnT(10));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - word_after, ptrdiff_t(2));
const char *two_numbers = "10 999";
libc_errno = 0;
ASSERT_EQ(func(two_numbers, &str_end, 10), ReturnT(10));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - two_numbers, ptrdiff_t(2));
const char *two_signs = "--10 999";
libc_errno = 0;
ASSERT_EQ(func(two_signs, &str_end, 10), ReturnT(0));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - two_signs, ptrdiff_t(0));
const char *sign_before = "+2=4";
libc_errno = 0;
ASSERT_EQ(func(sign_before, &str_end, 10), ReturnT(2));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - sign_before, ptrdiff_t(2));
const char *sign_after = "2+2=4";
libc_errno = 0;
ASSERT_EQ(func(sign_after, &str_end, 10), ReturnT(2));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - sign_after, ptrdiff_t(1));
const char *tab_before = "\t10";
libc_errno = 0;
ASSERT_EQ(func(tab_before, &str_end, 10), ReturnT(10));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - tab_before, ptrdiff_t(3));
const char *all_together = "\t -12345and+67890";
libc_errno = 0;
ASSERT_EQ(func(all_together, &str_end, 10), ReturnT(-12345));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - all_together, ptrdiff_t(9));
const char *just_spaces = " ";
libc_errno = 0;
ASSERT_EQ(func(just_spaces, &str_end, 10), ReturnT(0));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - just_spaces, ptrdiff_t(0));
const char *just_space_and_sign = " +";
libc_errno = 0;
ASSERT_EQ(func(just_space_and_sign, &str_end, 10), ReturnT(0));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - just_space_and_sign, ptrdiff_t(0));
}
@@ -213,11 +213,11 @@ struct StrtoTest : public LIBC_NAMESPACE::testing::Test {
libc_errno = 0;
ASSERT_EQ(func(small_string, nullptr, base),
static_cast<ReturnT>(first_digit));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
} else {
libc_errno = 0;
ASSERT_EQ(func(small_string, nullptr, base), ReturnT(0));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
}
}
}
@@ -232,16 +232,16 @@ struct StrtoTest : public LIBC_NAMESPACE::testing::Test {
ASSERT_EQ(
func(small_string, nullptr, base),
static_cast<ReturnT>(second_digit + (first_digit * base)));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
} else if (first_digit < base) {
libc_errno = 0;
ASSERT_EQ(func(small_string, nullptr, base),
static_cast<ReturnT>(first_digit));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
} else {
libc_errno = 0;
ASSERT_EQ(func(small_string, nullptr, base), ReturnT(0));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
}
}
}
@@ -262,13 +262,13 @@ struct StrtoTest : public LIBC_NAMESPACE::testing::Test {
static_cast<ReturnT>(third_digit +
(second_digit * base) +
(first_digit * base * base)));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
} else if (first_digit < base && second_digit < base) {
libc_errno = 0;
ASSERT_EQ(
func(small_string, nullptr, base),
static_cast<ReturnT>(second_digit + (first_digit * base)));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
} else if (first_digit < base) {
// if the base is 16 there is a special case for the prefix 0X.
// The number is treated as a one digit hexadecimal.
@@ -277,22 +277,22 @@ struct StrtoTest : public LIBC_NAMESPACE::testing::Test {
libc_errno = 0;
ASSERT_EQ(func(small_string, nullptr, base),
static_cast<ReturnT>(third_digit));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
} else {
libc_errno = 0;
ASSERT_EQ(func(small_string, nullptr, base), ReturnT(0));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
}
} else {
libc_errno = 0;
ASSERT_EQ(func(small_string, nullptr, base),
static_cast<ReturnT>(first_digit));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
}
} else {
libc_errno = 0;
ASSERT_EQ(func(small_string, nullptr, base), ReturnT(0));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
}
}
}
@@ -306,19 +306,19 @@ struct StrtoTest : public LIBC_NAMESPACE::testing::Test {
const char *no_prefix = "123abc";
libc_errno = 0;
ASSERT_EQ(func(no_prefix, &str_end, 16), ReturnT(0x123abc));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - no_prefix, ptrdiff_t(6));
const char *yes_prefix = "0x456def";
libc_errno = 0;
ASSERT_EQ(func(yes_prefix, &str_end, 16), ReturnT(0x456def));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - yes_prefix, ptrdiff_t(8));
const char *letter_after_prefix = "0xabc123";
libc_errno = 0;
ASSERT_EQ(func(letter_after_prefix, &str_end, 16), ReturnT(0xabc123));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - letter_after_prefix, ptrdiff_t(8));
// These tests check what happens when the number passed is exactly the max
@@ -332,7 +332,7 @@ struct StrtoTest : public LIBC_NAMESPACE::testing::Test {
((is_signed_v<ReturnT> && sizeof(ReturnT) == 4)
? T_MAX
: ReturnT(0xFFFFFFFF)));
- ASSERT_EQ(libc_errno,
+ ASSERT_EQ(static_cast<int>(libc_errno),
is_signed_v<ReturnT> && sizeof(ReturnT) == 4 ? ERANGE : 0);
EXPECT_EQ(str_end - max_32_bit_value, ptrdiff_t(10));
@@ -342,7 +342,7 @@ struct StrtoTest : public LIBC_NAMESPACE::testing::Test {
((is_signed_v<ReturnT> && sizeof(ReturnT) == 4)
? T_MIN
: -ReturnT(0xFFFFFFFF)));
- ASSERT_EQ(libc_errno,
+ ASSERT_EQ(static_cast<int>(libc_errno),
is_signed_v<ReturnT> && sizeof(ReturnT) == 4 ? ERANGE : 0);
EXPECT_EQ(str_end - negative_max_32_bit_value, ptrdiff_t(11));
@@ -351,14 +351,14 @@ struct StrtoTest : public LIBC_NAMESPACE::testing::Test {
const char *max_31_bit_value = "0x7FFFFFFF";
libc_errno = 0;
ASSERT_EQ(func(max_31_bit_value, &str_end, 0), ReturnT(0x7FFFFFFF));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - max_31_bit_value, ptrdiff_t(10));
const char *negative_max_31_bit_value = "-0x7FFFFFFF";
libc_errno = 0;
ASSERT_EQ(func(negative_max_31_bit_value, &str_end, 0),
-ReturnT(0x7FFFFFFF));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - negative_max_31_bit_value, ptrdiff_t(11));
// Max size for unsigned 64 bit numbers
@@ -369,7 +369,7 @@ struct StrtoTest : public LIBC_NAMESPACE::testing::Test {
(is_signed_v<ReturnT> || sizeof(ReturnT) < 8
? T_MAX
: ReturnT(0xFFFFFFFFFFFFFFFF)));
- ASSERT_EQ(libc_errno,
+ ASSERT_EQ(static_cast<int>(libc_errno),
(is_signed_v<ReturnT> || sizeof(ReturnT) < 8 ? ERANGE : 0));
EXPECT_EQ(str_end - max_64_bit_value, ptrdiff_t(18));
@@ -382,7 +382,7 @@ struct StrtoTest : public LIBC_NAMESPACE::testing::Test {
(is_signed_v<ReturnT>
? T_MIN
: (sizeof(ReturnT) < 8 ? T_MAX : -ReturnT(0xFFFFFFFFFFFFFFFF))));
- ASSERT_EQ(libc_errno,
+ ASSERT_EQ(static_cast<int>(libc_errno),
(is_signed_v<ReturnT> || sizeof(ReturnT) < 8 ? ERANGE : 0));
EXPECT_EQ(str_end - negative_max_64_bit_value, ptrdiff_t(19));
@@ -392,7 +392,7 @@ struct StrtoTest : public LIBC_NAMESPACE::testing::Test {
libc_errno = 0;
ASSERT_EQ(func(max_63_bit_value, &str_end, 0),
(sizeof(ReturnT) < 8 ? T_MAX : ReturnT(0x7FFFFFFFFFFFFFFF)));
- ASSERT_EQ(libc_errno, sizeof(ReturnT) < 8 ? ERANGE : 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), sizeof(ReturnT) < 8 ? ERANGE : 0);
EXPECT_EQ(str_end - max_63_bit_value, ptrdiff_t(18));
const char *negative_max_63_bit_value = "-0x7FFFFFFFFFFFFFFF";
@@ -400,7 +400,7 @@ struct StrtoTest : public LIBC_NAMESPACE::testing::Test {
ASSERT_EQ(func(negative_max_63_bit_value, &str_end, 0),
(sizeof(ReturnT) >= 8 ? -ReturnT(0x7FFFFFFFFFFFFFFF)
: (is_signed_v<ReturnT> ? T_MIN : T_MAX)));
- ASSERT_EQ(libc_errno, sizeof(ReturnT) < 8 ? ERANGE : 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), sizeof(ReturnT) < 8 ? ERANGE : 0);
EXPECT_EQ(str_end - negative_max_63_bit_value, ptrdiff_t(19));
}
@@ -410,23 +410,23 @@ struct StrtoTest : public LIBC_NAMESPACE::testing::Test {
const char *just_prefix = "0x";
libc_errno = 0;
ASSERT_EQ(func(just_prefix, &str_end, 16), ReturnT(0));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - just_prefix, ptrdiff_t(1));
libc_errno = 0;
ASSERT_EQ(func(just_prefix, &str_end, 0), ReturnT(0));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - just_prefix, ptrdiff_t(1));
const char *prefix_with_x_after = "0xx";
libc_errno = 0;
ASSERT_EQ(func(prefix_with_x_after, &str_end, 16), ReturnT(0));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - prefix_with_x_after, ptrdiff_t(1));
libc_errno = 0;
ASSERT_EQ(func(prefix_with_x_after, &str_end, 0), ReturnT(0));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - prefix_with_x_after, ptrdiff_t(1));
}
@@ -436,43 +436,43 @@ struct StrtoTest : public LIBC_NAMESPACE::testing::Test {
const char *base_ten = "12345";
libc_errno = 0;
ASSERT_EQ(func(base_ten, &str_end, 0), ReturnT(12345));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - base_ten, ptrdiff_t(5));
const char *base_sixteen_no_prefix = "123abc";
libc_errno = 0;
ASSERT_EQ(func(base_sixteen_no_prefix, &str_end, 0), ReturnT(123));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - base_sixteen_no_prefix, ptrdiff_t(3));
const char *base_sixteen_with_prefix = "0x456def";
libc_errno = 0;
ASSERT_EQ(func(base_sixteen_with_prefix, &str_end, 0), ReturnT(0x456def));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - base_sixteen_with_prefix, ptrdiff_t(8));
const char *base_eight_with_prefix = "012345";
libc_errno = 0;
ASSERT_EQ(func(base_eight_with_prefix, &str_end, 0), ReturnT(012345));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - base_eight_with_prefix, ptrdiff_t(6));
const char *just_zero = "0";
libc_errno = 0;
ASSERT_EQ(func(just_zero, &str_end, 0), ReturnT(0));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - just_zero, ptrdiff_t(1));
const char *just_zero_x = "0x";
libc_errno = 0;
ASSERT_EQ(func(just_zero_x, &str_end, 0), ReturnT(0));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - just_zero_x, ptrdiff_t(1));
const char *just_zero_eight = "08";
libc_errno = 0;
ASSERT_EQ(func(just_zero_eight, &str_end, 0), ReturnT(0));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_EQ(str_end - just_zero_eight, ptrdiff_t(1));
}
};
diff --git a/libc/test/src/stdlib/strtof_test.cpp b/libc/test/src/stdlib/strtof_test.cpp
index 31b3f69f63a0c7..638b8d720d0ccd 100644
--- a/libc/test/src/stdlib/strtof_test.cpp
+++ b/libc/test/src/stdlib/strtof_test.cpp
@@ -49,7 +49,7 @@ class LlvmLibcStrToFTest : public LIBC_NAMESPACE::testing::Test,
EXPECT_EQ(str_end - inputString, expectedStrLen);
EXPECT_FP_EQ(result, expected_fp.get_val());
- EXPECT_EQ(libc_errno, expectedErrno);
+ EXPECT_EQ(static_cast<int>(libc_errno), expectedErrno);
}
};
diff --git a/libc/test/src/stdlib/strtold_test.cpp b/libc/test/src/stdlib/strtold_test.cpp
index 51f9975772aa5e..4e0da66c284bca 100644
--- a/libc/test/src/stdlib/strtold_test.cpp
+++ b/libc/test/src/stdlib/strtold_test.cpp
@@ -91,7 +91,7 @@ class LlvmLibcStrToLDTest : public LIBC_NAMESPACE::testing::Test {
EXPECT_EQ(actual_fp.is_neg(), expected_fp.is_neg());
EXPECT_EQ(actual_fp.get_exponent(), expected_fp.get_exponent());
EXPECT_EQ(actual_fp.get_mantissa(), expected_fp.get_mantissa());
- EXPECT_EQ(libc_errno, expected_errno);
+ EXPECT_EQ(static_cast<int>(libc_errno), expected_errno);
}
};
diff --git a/libc/test/src/string/strdup_test.cpp b/libc/test/src/string/strdup_test.cpp
index b1d4df31603c4b..f5f44ec48209dd 100644
--- a/libc/test/src/string/strdup_test.cpp
+++ b/libc/test/src/string/strdup_test.cpp
@@ -17,7 +17,7 @@ TEST(LlvmLibcStrDupTest, EmptyString) {
libc_errno = 0;
char *result = LIBC_NAMESPACE::strdup(empty);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_NE(result, static_cast<char *>(nullptr));
ASSERT_NE(empty, const_cast<const char *>(result));
@@ -30,7 +30,7 @@ TEST(LlvmLibcStrDupTest, AnyString) {
libc_errno = 0;
char *result = LIBC_NAMESPACE::strdup(abc);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_NE(result, static_cast<char *>(nullptr));
ASSERT_NE(abc, const_cast<const char *>(result));
@@ -41,7 +41,7 @@ TEST(LlvmLibcStrDupTest, AnyString) {
TEST(LlvmLibcStrDupTest, NullPtr) {
libc_errno = 0;
char *result = LIBC_NAMESPACE::strdup(nullptr);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(result, static_cast<char *>(nullptr));
}
diff --git a/libc/test/src/sys/mman/linux/madvise_test.cpp b/libc/test/src/sys/mman/linux/madvise_test.cpp
index 83c73f5454de1b..bef4024580b23a 100644
--- a/libc/test/src/sys/mman/linux/madvise_test.cpp
+++ b/libc/test/src/sys/mman/linux/madvise_test.cpp
@@ -23,7 +23,7 @@ TEST(LlvmLibcMadviseTest, NoError) {
libc_errno = 0;
void *addr = LIBC_NAMESPACE::mmap(nullptr, alloc_size, PROT_READ,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
- EXPECT_EQ(0, libc_errno);
+ EXPECT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_NE(addr, MAP_FAILED);
EXPECT_THAT(LIBC_NAMESPACE::madvise(addr, alloc_size, MADV_RANDOM),
diff --git a/libc/test/src/sys/mman/linux/mmap_test.cpp b/libc/test/src/sys/mman/linux/mmap_test.cpp
index 9b13b8bd8057f2..230fe47c1bff04 100644
--- a/libc/test/src/sys/mman/linux/mmap_test.cpp
+++ b/libc/test/src/sys/mman/linux/mmap_test.cpp
@@ -22,7 +22,7 @@ TEST(LlvmLibcMMapTest, NoError) {
libc_errno = 0;
void *addr = LIBC_NAMESPACE::mmap(nullptr, alloc_size, PROT_READ,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
- EXPECT_EQ(0, libc_errno);
+ EXPECT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_NE(addr, MAP_FAILED);
int *array = reinterpret_cast<int *>(addr);
diff --git a/libc/test/src/sys/mman/linux/mprotect_test.cpp b/libc/test/src/sys/mman/linux/mprotect_test.cpp
index 7127f77714d642..4f8155569bb9a1 100644
--- a/libc/test/src/sys/mman/linux/mprotect_test.cpp
+++ b/libc/test/src/sys/mman/linux/mprotect_test.cpp
@@ -24,7 +24,7 @@ TEST(LlvmLibcMProtectTest, NoError) {
libc_errno = 0;
void *addr = LIBC_NAMESPACE::mmap(nullptr, alloc_size, PROT_READ,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
- EXPECT_EQ(0, libc_errno);
+ EXPECT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_NE(addr, MAP_FAILED);
int *array = reinterpret_cast<int *>(addr);
diff --git a/libc/test/src/sys/mman/linux/posix_madvise_test.cpp b/libc/test/src/sys/mman/linux/posix_madvise_test.cpp
index 59cf01ac746959..f5a617fa8de45f 100644
--- a/libc/test/src/sys/mman/linux/posix_madvise_test.cpp
+++ b/libc/test/src/sys/mman/linux/posix_madvise_test.cpp
@@ -23,7 +23,7 @@ TEST(LlvmLibcPosixMadviseTest, NoError) {
libc_errno = 0;
void *addr = LIBC_NAMESPACE::mmap(nullptr, alloc_size, PROT_READ,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
- EXPECT_EQ(0, libc_errno);
+ EXPECT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_NE(addr, MAP_FAILED);
EXPECT_EQ(LIBC_NAMESPACE::posix_madvise(addr, alloc_size, POSIX_MADV_RANDOM),
diff --git a/libc/test/src/sys/prctl/linux/prctl_test.cpp b/libc/test/src/sys/prctl/linux/prctl_test.cpp
index 643c9513b36eb9..12d826220998f0 100644
--- a/libc/test/src/sys/prctl/linux/prctl_test.cpp
+++ b/libc/test/src/sys/prctl/linux/prctl_test.cpp
@@ -36,7 +36,7 @@ TEST(LlvmLibcSysPrctlTest, GetTHPDisable) {
// covered in ErrnoSetterMatcher.
libc_errno = 0;
int ret = LIBC_NAMESPACE::prctl(PR_GET_THP_DISABLE, 0, 0, 0, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
// PR_GET_THP_DISABLE return (as the function result) the current
// setting of the "THP disable" flag for the calling thread, which
// is either 1, if the flag is set; or 0, if it is not.
diff --git a/libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp b/libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp
index 0870deeeb5d801..5cf4a3d5dd8f01 100644
--- a/libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp
+++ b/libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp
@@ -33,10 +33,10 @@ TEST(LlvmLibcResourceLimitsTest, SetNoFileLimit) {
int fd1 = LIBC_NAMESPACE::open(TEST_FILE1, O_CREAT | O_WRONLY, S_IRWXU);
ASSERT_GT(fd1, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
int fd2 = LIBC_NAMESPACE::open(TEST_FILE2, O_CREAT | O_WRONLY, S_IRWXU);
ASSERT_GT(fd2, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_THAT(LIBC_NAMESPACE::close(fd1), Succeeds(0));
ASSERT_THAT(LIBC_NAMESPACE::close(fd2), Succeeds(0));
@@ -49,20 +49,20 @@ TEST(LlvmLibcResourceLimitsTest, SetNoFileLimit) {
// One can now only open one of the files successfully.
fd1 = LIBC_NAMESPACE::open(TEST_FILE1, O_RDONLY);
ASSERT_GT(fd1, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
fd2 = LIBC_NAMESPACE::open(TEST_FILE2, O_RDONLY);
ASSERT_LT(fd2, 0);
- ASSERT_NE(libc_errno, 0);
+ ASSERT_NE(static_cast<int>(libc_errno), 0);
libc_errno = 0;
ASSERT_THAT(LIBC_NAMESPACE::close(fd1), Succeeds(0));
fd2 = LIBC_NAMESPACE::open(TEST_FILE2, O_RDONLY);
ASSERT_GT(fd2, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
fd1 = LIBC_NAMESPACE::open(TEST_FILE1, O_RDONLY);
ASSERT_LT(fd1, 0);
- ASSERT_NE(libc_errno, 0);
+ ASSERT_NE(static_cast<int>(libc_errno), 0);
libc_errno = 0;
ASSERT_THAT(LIBC_NAMESPACE::close(fd2), Succeeds(0));
diff --git a/libc/test/src/sys/sendfile/sendfile_test.cpp b/libc/test/src/sys/sendfile/sendfile_test.cpp
index 6e4665a1bb96b1..449a4b1e0b66bb 100644
--- a/libc/test/src/sys/sendfile/sendfile_test.cpp
+++ b/libc/test/src/sys/sendfile/sendfile_test.cpp
@@ -39,16 +39,16 @@ TEST(LlvmLibcSendfileTest, CreateAndTransfer) {
int in_fd = LIBC_NAMESPACE::open(IN_FILE, O_CREAT | O_WRONLY, S_IRWXU);
ASSERT_GT(in_fd, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(LIBC_NAMESPACE::write(in_fd, IN_DATA, IN_SIZE), IN_SIZE);
ASSERT_THAT(LIBC_NAMESPACE::close(in_fd), Succeeds(0));
in_fd = LIBC_NAMESPACE::open(IN_FILE, O_RDONLY);
ASSERT_GT(in_fd, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
int out_fd = LIBC_NAMESPACE::open(OUT_FILE, O_CREAT | O_WRONLY, S_IRWXU);
ASSERT_GT(out_fd, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ssize_t size = LIBC_NAMESPACE::sendfile(in_fd, out_fd, nullptr, IN_SIZE);
ASSERT_EQ(size, IN_SIZE);
ASSERT_THAT(LIBC_NAMESPACE::close(in_fd), Succeeds(0));
@@ -56,7 +56,7 @@ TEST(LlvmLibcSendfileTest, CreateAndTransfer) {
out_fd = LIBC_NAMESPACE::open(OUT_FILE, O_RDONLY);
ASSERT_GT(out_fd, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
char buf[IN_SIZE];
ASSERT_EQ(IN_SIZE, LIBC_NAMESPACE::read(out_fd, buf, IN_SIZE));
ASSERT_EQ(cpp::string_view(buf), cpp::string_view(IN_DATA));
diff --git a/libc/test/src/sys/socket/linux/bind_test.cpp b/libc/test/src/sys/socket/linux/bind_test.cpp
index 5a3a1c227c9b58..43406266a708a3 100644
--- a/libc/test/src/sys/socket/linux/bind_test.cpp
+++ b/libc/test/src/sys/socket/linux/bind_test.cpp
@@ -25,7 +25,7 @@ TEST(LlvmLibcSocketTest, BindLocalSocket) {
int sock = LIBC_NAMESPACE::socket(AF_UNIX, SOCK_DGRAM, 0);
ASSERT_GE(sock, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
struct sockaddr_un my_addr;
@@ -47,7 +47,7 @@ TEST(LlvmLibcSocketTest, BindLocalSocket) {
sizeof(struct sockaddr_un));
ASSERT_EQ(result, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
LIBC_NAMESPACE::close(sock);
diff --git a/libc/test/src/sys/socket/linux/socket_test.cpp b/libc/test/src/sys/socket/linux/socket_test.cpp
index 9d5bfacde0a409..d3a72ed8d690c3 100644
--- a/libc/test/src/sys/socket/linux/socket_test.cpp
+++ b/libc/test/src/sys/socket/linux/socket_test.cpp
@@ -18,7 +18,7 @@
TEST(LlvmLibcSocketTest, LocalSocket) {
int sock = LIBC_NAMESPACE::socket(AF_UNIX, SOCK_DGRAM, 0);
ASSERT_GE(sock, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
LIBC_NAMESPACE::close(sock);
}
diff --git a/libc/test/src/sys/stat/chmod_test.cpp b/libc/test/src/sys/stat/chmod_test.cpp
index c476b92b5e4379..c8047ca2f9bb3a 100644
--- a/libc/test/src/sys/stat/chmod_test.cpp
+++ b/libc/test/src/sys/stat/chmod_test.cpp
@@ -32,25 +32,25 @@ TEST(LlvmLibcChmodTest, ChangeAndOpen) {
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_APPEND | O_WRONLY);
ASSERT_GT(fd, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(LIBC_NAMESPACE::write(fd, WRITE_DATA, sizeof(WRITE_DATA)),
WRITE_SIZE);
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
fd = LIBC_NAMESPACE::open(TEST_FILE, O_PATH);
ASSERT_GT(fd, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
EXPECT_THAT(LIBC_NAMESPACE::chmod(TEST_FILE, S_IRUSR), Succeeds(0));
// Opening for writing should fail.
EXPECT_EQ(LIBC_NAMESPACE::open(TEST_FILE, O_APPEND | O_WRONLY), -1);
- EXPECT_NE(libc_errno, 0);
+ EXPECT_NE(static_cast<int>(libc_errno), 0);
libc_errno = 0;
// But opening for reading should succeed.
fd = LIBC_NAMESPACE::open(TEST_FILE, O_APPEND | O_RDONLY);
EXPECT_GT(fd, 0);
- EXPECT_EQ(libc_errno, 0);
+ EXPECT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
EXPECT_THAT(LIBC_NAMESPACE::chmod(TEST_FILE, S_IRWXU), Succeeds(0));
diff --git a/libc/test/src/sys/stat/fchmod_test.cpp b/libc/test/src/sys/stat/fchmod_test.cpp
index 5a32b5c973db9b..4b89d917a831b9 100644
--- a/libc/test/src/sys/stat/fchmod_test.cpp
+++ b/libc/test/src/sys/stat/fchmod_test.cpp
@@ -32,25 +32,25 @@ TEST(LlvmLibcChmodTest, ChangeAndOpen) {
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_APPEND | O_WRONLY);
ASSERT_GT(fd, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(LIBC_NAMESPACE::write(fd, WRITE_DATA, sizeof(WRITE_DATA)),
WRITE_SIZE);
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
fd = LIBC_NAMESPACE::open(TEST_FILE, O_APPEND | O_WRONLY);
ASSERT_GT(fd, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_THAT(LIBC_NAMESPACE::fchmod(fd, S_IRUSR), Succeeds(0));
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
// Opening for writing should fail.
EXPECT_EQ(LIBC_NAMESPACE::open(TEST_FILE, O_APPEND | O_WRONLY), -1);
- EXPECT_NE(libc_errno, 0);
+ EXPECT_NE(static_cast<int>(libc_errno), 0);
libc_errno = 0;
// But opening for reading should succeed.
fd = LIBC_NAMESPACE::open(TEST_FILE, O_APPEND | O_RDONLY);
EXPECT_GT(fd, 0);
- EXPECT_EQ(libc_errno, 0);
+ EXPECT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_THAT(LIBC_NAMESPACE::fchmod(fd, S_IRWXU), Succeeds(0));
EXPECT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
@@ -59,6 +59,6 @@ TEST(LlvmLibcChmodTest, ChangeAndOpen) {
TEST(LlvmLibcChmodTest, NonExistentFile) {
libc_errno = 0;
ASSERT_EQ(LIBC_NAMESPACE::fchmod(-1, S_IRUSR), -1);
- ASSERT_NE(libc_errno, 0);
+ ASSERT_NE(static_cast<int>(libc_errno), 0);
libc_errno = 0;
}
diff --git a/libc/test/src/sys/stat/fchmodat_test.cpp b/libc/test/src/sys/stat/fchmodat_test.cpp
index 077d21df15af3c..726e4643a0c514 100644
--- a/libc/test/src/sys/stat/fchmodat_test.cpp
+++ b/libc/test/src/sys/stat/fchmodat_test.cpp
@@ -34,26 +34,26 @@ TEST(LlvmLibcFchmodatTest, ChangeAndOpen) {
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_WRONLY, S_IRWXU);
ASSERT_GT(fd, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(LIBC_NAMESPACE::write(fd, WRITE_DATA, sizeof(WRITE_DATA)),
WRITE_SIZE);
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
int dirfd = LIBC_NAMESPACE::open(TEST_DIR, O_DIRECTORY);
ASSERT_GT(dirfd, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_THAT(LIBC_NAMESPACE::fchmodat(dirfd, TEST_FILE_BASENAME, S_IRUSR, 0),
Succeeds(0));
// Opening for writing should fail.
EXPECT_EQ(LIBC_NAMESPACE::open(TEST_FILE, O_APPEND | O_WRONLY), -1);
- EXPECT_NE(libc_errno, 0);
+ EXPECT_NE(static_cast<int>(libc_errno), 0);
libc_errno = 0;
// But opening for reading should succeed.
fd = LIBC_NAMESPACE::open(TEST_FILE, O_APPEND | O_RDONLY);
EXPECT_GT(fd, 0);
- EXPECT_EQ(libc_errno, 0);
+ EXPECT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
EXPECT_THAT(LIBC_NAMESPACE::fchmodat(dirfd, TEST_FILE_BASENAME, S_IRWXU, 0),
diff --git a/libc/test/src/sys/stat/fstat_test.cpp b/libc/test/src/sys/stat/fstat_test.cpp
index 22e407f6d791b8..6e7bb69b030114 100644
--- a/libc/test/src/sys/stat/fstat_test.cpp
+++ b/libc/test/src/sys/stat/fstat_test.cpp
@@ -30,7 +30,7 @@ TEST(LlvmLibcFStatTest, CreatAndReadMode) {
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_WRONLY, S_IRWXU);
ASSERT_GT(fd, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
struct stat statbuf;
ASSERT_THAT(LIBC_NAMESPACE::fstat(fd, &statbuf), Succeeds(0));
diff --git a/libc/test/src/sys/stat/lstat_test.cpp b/libc/test/src/sys/stat/lstat_test.cpp
index 6eae08daeb1cff..9ce1b6d87b2547 100644
--- a/libc/test/src/sys/stat/lstat_test.cpp
+++ b/libc/test/src/sys/stat/lstat_test.cpp
@@ -30,7 +30,7 @@ TEST(LlvmLibcLStatTest, CreatAndReadMode) {
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_WRONLY, S_IRWXU);
ASSERT_GT(fd, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
struct stat statbuf;
diff --git a/libc/test/src/sys/stat/stat_test.cpp b/libc/test/src/sys/stat/stat_test.cpp
index 1711c860df269d..3d6a014870abbd 100644
--- a/libc/test/src/sys/stat/stat_test.cpp
+++ b/libc/test/src/sys/stat/stat_test.cpp
@@ -30,7 +30,7 @@ TEST(LlvmLibcStatTest, CreatAndReadMode) {
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_WRONLY, S_IRWXU);
ASSERT_GT(fd, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
struct stat statbuf;
diff --git a/libc/test/src/termios/termios_test.cpp b/libc/test/src/termios/termios_test.cpp
index 3048f9cda1e059..14a33d4c40438c 100644
--- a/libc/test/src/termios/termios_test.cpp
+++ b/libc/test/src/termios/termios_test.cpp
@@ -48,7 +48,7 @@ TEST(LlvmLibcTermiosTest, GetAttrSmokeTest) {
int fd = LIBC_NAMESPACE::open("/dev/tty", O_RDONLY);
if (fd < 0)
return; // When /dev/tty is not available, no point continuing.
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_THAT(LIBC_NAMESPACE::tcgetattr(fd, &t), Succeeds(0));
ASSERT_EQ(LIBC_NAMESPACE::close(fd), 0);
}
@@ -58,7 +58,7 @@ TEST(LlvmLibcTermiosTest, TcGetSidSmokeTest) {
int fd = LIBC_NAMESPACE::open("/dev/tty", O_RDONLY);
if (fd < 0)
return; // When /dev/tty is not available, no point continuing.
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(LIBC_NAMESPACE::tcgetsid(fd), pid_t(0));
ASSERT_EQ(LIBC_NAMESPACE::close(fd), 0);
}
diff --git a/libc/test/src/time/asctime_r_test.cpp b/libc/test/src/time/asctime_r_test.cpp
index 1abaa135350c13..b2995384ee3e7c 100644
--- a/libc/test/src/time/asctime_r_test.cpp
+++ b/libc/test/src/time/asctime_r_test.cpp
@@ -27,17 +27,17 @@ static inline char *call_asctime_r(struct tm *tm_data, int year, int month,
TEST(LlvmLibcAsctimeR, Nullptr) {
char *result;
result = LIBC_NAMESPACE::asctime_r(nullptr, nullptr);
- ASSERT_EQ(EINVAL, libc_errno);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
ASSERT_STREQ(nullptr, result);
char buffer[TimeConstants::ASCTIME_BUFFER_SIZE];
result = LIBC_NAMESPACE::asctime_r(nullptr, buffer);
- ASSERT_EQ(EINVAL, libc_errno);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
ASSERT_STREQ(nullptr, result);
struct tm tm_data;
result = LIBC_NAMESPACE::asctime_r(&tm_data, nullptr);
- ASSERT_EQ(EINVAL, libc_errno);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
ASSERT_STREQ(nullptr, result);
}
diff --git a/libc/test/src/time/asctime_test.cpp b/libc/test/src/time/asctime_test.cpp
index 4b5ceb596aa467..e19186eda89b55 100644
--- a/libc/test/src/time/asctime_test.cpp
+++ b/libc/test/src/time/asctime_test.cpp
@@ -22,7 +22,7 @@ static inline char *call_asctime(struct tm *tm_data, int year, int month,
TEST(LlvmLibcAsctime, Nullptr) {
char *result;
result = LIBC_NAMESPACE::asctime(nullptr);
- ASSERT_EQ(EINVAL, libc_errno);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
ASSERT_STREQ(nullptr, result);
}
@@ -40,7 +40,7 @@ TEST(LlvmLibcAsctime, InvalidWday) {
0, // sec
-1, // wday
0); // yday
- ASSERT_EQ(EINVAL, libc_errno);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
// Test with wday = 7.
call_asctime(&tm_data,
@@ -52,7 +52,7 @@ TEST(LlvmLibcAsctime, InvalidWday) {
0, // sec
7, // wday
0); // yday
- ASSERT_EQ(EINVAL, libc_errno);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
}
// Months are from January to December. Test passing invalid value in month.
@@ -69,7 +69,7 @@ TEST(LlvmLibcAsctime, InvalidMonth) {
0, // sec
4, // wday
0); // yday
- ASSERT_EQ(EINVAL, libc_errno);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
// Test with month = 13.
call_asctime(&tm_data,
@@ -81,7 +81,7 @@ TEST(LlvmLibcAsctime, InvalidMonth) {
0, // sec
4, // wday
0); // yday
- ASSERT_EQ(EINVAL, libc_errno);
+ ASSERT_EQ(static_cast<int>(libc_errno), EINVAL);
}
TEST(LlvmLibcAsctime, ValidWeekdays) {
diff --git a/libc/test/src/time/gmtime_test.cpp b/libc/test/src/time/gmtime_test.cpp
index 6b1d029a693c38..feface86082194 100644
--- a/libc/test/src/time/gmtime_test.cpp
+++ b/libc/test/src/time/gmtime_test.cpp
@@ -27,7 +27,7 @@ TEST(LlvmLibcGmTime, OutOfRange) {
TimeConstants::NUMBER_OF_SECONDS_IN_LEAP_YEAR);
struct tm *tm_data = LIBC_NAMESPACE::gmtime(&seconds);
EXPECT_TRUE(tm_data == nullptr);
- EXPECT_EQ(libc_errno, EOVERFLOW);
+ EXPECT_EQ(static_cast<int>(libc_errno), EOVERFLOW);
libc_errno = 0;
seconds = INT_MIN * static_cast<int64_t>(
@@ -35,7 +35,7 @@ TEST(LlvmLibcGmTime, OutOfRange) {
1;
tm_data = LIBC_NAMESPACE::gmtime(&seconds);
EXPECT_TRUE(tm_data == nullptr);
- EXPECT_EQ(libc_errno, EOVERFLOW);
+ EXPECT_EQ(static_cast<int>(libc_errno), EOVERFLOW);
}
TEST(LlvmLibcGmTime, InvalidSeconds) {
diff --git a/libc/test/src/time/nanosleep_test.cpp b/libc/test/src/time/nanosleep_test.cpp
index 2826ed14dfedab..e3dafca6ba7355 100644
--- a/libc/test/src/time/nanosleep_test.cpp
+++ b/libc/test/src/time/nanosleep_test.cpp
@@ -23,6 +23,6 @@ TEST(LlvmLibcNanosleep, SmokeTest) {
struct timespec tim = {1, 500};
struct timespec tim2 = {0, 0};
int ret = LIBC_NAMESPACE::nanosleep(&tim, &tim2);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(ret, 0);
}
diff --git a/libc/test/src/unistd/access_test.cpp b/libc/test/src/unistd/access_test.cpp
index 7d4b3be443fed4..df70f6aa3cc988 100644
--- a/libc/test/src/unistd/access_test.cpp
+++ b/libc/test/src/unistd/access_test.cpp
@@ -24,29 +24,29 @@ TEST(LlvmLibcAccessTest, CreateAndTest) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/access.test";
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(fd, 0);
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
ASSERT_EQ(LIBC_NAMESPACE::access(TEST_FILE, F_OK), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(LIBC_NAMESPACE::access(TEST_FILE, X_OK | W_OK | R_OK), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_THAT(LIBC_NAMESPACE::unlink(TEST_FILE), Succeeds(0));
fd = LIBC_NAMESPACE::open(TEST_FILE, O_WRONLY | O_CREAT, S_IXUSR);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(fd, 0);
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
ASSERT_EQ(LIBC_NAMESPACE::access(TEST_FILE, F_OK), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(LIBC_NAMESPACE::access(TEST_FILE, X_OK), 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(LIBC_NAMESPACE::access(TEST_FILE, R_OK), -1);
- ASSERT_EQ(libc_errno, EACCES);
+ ASSERT_EQ(static_cast<int>(libc_errno), EACCES);
libc_errno = 0;
ASSERT_EQ(LIBC_NAMESPACE::access(TEST_FILE, W_OK), -1);
- ASSERT_EQ(libc_errno, EACCES);
+ ASSERT_EQ(static_cast<int>(libc_errno), EACCES);
libc_errno = 0;
ASSERT_THAT(LIBC_NAMESPACE::unlink(TEST_FILE), Succeeds(0));
}
diff --git a/libc/test/src/unistd/chdir_test.cpp b/libc/test/src/unistd/chdir_test.cpp
index dfdeacdc8e42af..82193bf286a6f3 100644
--- a/libc/test/src/unistd/chdir_test.cpp
+++ b/libc/test/src/unistd/chdir_test.cpp
@@ -28,13 +28,13 @@ TEST(LlvmLibcChdirTest, ChangeAndOpen) {
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_PATH);
ASSERT_GT(fd, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
ASSERT_THAT(LIBC_NAMESPACE::chdir(TEST_DIR), Succeeds(0));
fd = LIBC_NAMESPACE::open(TEST_FILE_BASE, O_PATH);
ASSERT_GT(fd, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
}
diff --git a/libc/test/src/unistd/dup2_test.cpp b/libc/test/src/unistd/dup2_test.cpp
index d46c4b919ce72c..38015c4374e0f0 100644
--- a/libc/test/src/unistd/dup2_test.cpp
+++ b/libc/test/src/unistd/dup2_test.cpp
@@ -24,10 +24,10 @@ TEST(LlvmLibcdupTest, ReadAndWriteViaDup) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/dup2.test";
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(fd, 0);
int dupfd = LIBC_NAMESPACE::dup2(fd, DUPFD);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(dupfd, DUPFD);
// Write something via the dup
@@ -39,10 +39,10 @@ TEST(LlvmLibcdupTest, ReadAndWriteViaDup) {
// Reopen the file for reading and create a dup.
fd = LIBC_NAMESPACE::open(TEST_FILE, O_RDONLY);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(fd, 0);
dupfd = LIBC_NAMESPACE::dup2(fd, DUPFD);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(dupfd, DUPFD);
// Read the file content via the dup.
diff --git a/libc/test/src/unistd/dup3_test.cpp b/libc/test/src/unistd/dup3_test.cpp
index d2d544d5d9a12f..19b37190098c26 100644
--- a/libc/test/src/unistd/dup3_test.cpp
+++ b/libc/test/src/unistd/dup3_test.cpp
@@ -30,10 +30,10 @@ TEST(LlvmLibcdupTest, ReadAndWriteViaDup) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/dup3.test";
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(fd, 0);
int dupfd = LIBC_NAMESPACE::dup3(fd, DUPFD, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(dupfd, DUPFD);
// Write something via the dup
@@ -45,10 +45,10 @@ TEST(LlvmLibcdupTest, ReadAndWriteViaDup) {
// Reopen the file for reading and create a dup.
fd = LIBC_NAMESPACE::open(TEST_FILE, O_RDONLY);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(fd, 0);
dupfd = LIBC_NAMESPACE::dup3(fd, DUPFD, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(dupfd, DUPFD);
// Read the file content via the dup.
diff --git a/libc/test/src/unistd/dup_test.cpp b/libc/test/src/unistd/dup_test.cpp
index 856b004fbe65d5..5cd0b08dfabeb7 100644
--- a/libc/test/src/unistd/dup_test.cpp
+++ b/libc/test/src/unistd/dup_test.cpp
@@ -23,10 +23,10 @@ TEST(LlvmLibcdupTest, ReadAndWriteViaDup) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/dup.test";
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(fd, 0);
int dupfd = LIBC_NAMESPACE::dup(fd);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(dupfd, 0);
// Write something via the dup
@@ -38,10 +38,10 @@ TEST(LlvmLibcdupTest, ReadAndWriteViaDup) {
// Reopen the file for reading and create a dup.
fd = LIBC_NAMESPACE::open(TEST_FILE, O_RDONLY);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(fd, 0);
dupfd = LIBC_NAMESPACE::dup(fd);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(dupfd, 0);
// Read the file content via the dup.
diff --git a/libc/test/src/unistd/fchdir_test.cpp b/libc/test/src/unistd/fchdir_test.cpp
index 27d4489f6447ea..dcaa903faee7c5 100644
--- a/libc/test/src/unistd/fchdir_test.cpp
+++ b/libc/test/src/unistd/fchdir_test.cpp
@@ -28,16 +28,16 @@ TEST(LlvmLibcChdirTest, ChangeAndOpen) {
int dir_fd = LIBC_NAMESPACE::open(TEST_DIR, O_DIRECTORY);
ASSERT_GT(dir_fd, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
int file_fd = LIBC_NAMESPACE::open(TEST_FILE, O_PATH);
ASSERT_GT(file_fd, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_THAT(LIBC_NAMESPACE::close(file_fd), Succeeds(0));
ASSERT_THAT(LIBC_NAMESPACE::fchdir(dir_fd), Succeeds(0));
file_fd = LIBC_NAMESPACE::open(TEST_FILE_BASE, O_PATH);
ASSERT_GT(file_fd, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_THAT(LIBC_NAMESPACE::close(file_fd), Succeeds(0));
ASSERT_THAT(LIBC_NAMESPACE::close(dir_fd), Succeeds(0));
}
@@ -46,6 +46,6 @@ TEST(LlvmLibcChdirTest, ChangeToNonExistentDir) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
libc_errno = 0;
ASSERT_EQ(LIBC_NAMESPACE::fchdir(0), -1);
- ASSERT_NE(libc_errno, 0);
+ ASSERT_NE(static_cast<int>(libc_errno), 0);
libc_errno = 0;
}
diff --git a/libc/test/src/unistd/ftruncate_test.cpp b/libc/test/src/unistd/ftruncate_test.cpp
index fc68348e32ec66..9c6b88028dff5a 100644
--- a/libc/test/src/unistd/ftruncate_test.cpp
+++ b/libc/test/src/unistd/ftruncate_test.cpp
@@ -35,14 +35,14 @@ TEST(LlvmLibcFtruncateTest, CreateAndTruncate) {
// 4. Try to read more than 1 byte and fail.
libc_errno = 0;
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(fd, 0);
ASSERT_EQ(ssize_t(WRITE_SIZE),
LIBC_NAMESPACE::write(fd, WRITE_DATA, WRITE_SIZE));
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
fd = LIBC_NAMESPACE::open(TEST_FILE, O_RDONLY);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(fd, 0);
ASSERT_EQ(ssize_t(WRITE_SIZE), LIBC_NAMESPACE::read(fd, buf, WRITE_SIZE));
ASSERT_EQ(cpp::string_view(buf), cpp::string_view(WRITE_DATA));
@@ -52,12 +52,12 @@ TEST(LlvmLibcFtruncateTest, CreateAndTruncate) {
// writing.
fd = LIBC_NAMESPACE::open(TEST_FILE, O_WRONLY);
ASSERT_GT(fd, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_THAT(LIBC_NAMESPACE::ftruncate(fd, off_t(1)), Succeeds(0));
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
fd = LIBC_NAMESPACE::open(TEST_FILE, O_RDONLY);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(fd, 0);
ASSERT_EQ(ssize_t(1), LIBC_NAMESPACE::read(fd, buf, WRITE_SIZE));
ASSERT_EQ(buf[0], WRITE_DATA[0]);
diff --git a/libc/test/src/unistd/isatty_test.cpp b/libc/test/src/unistd/isatty_test.cpp
index 7bf8dd708bfa6f..1515c758667416 100644
--- a/libc/test/src/unistd/isatty_test.cpp
+++ b/libc/test/src/unistd/isatty_test.cpp
@@ -43,7 +43,7 @@ TEST(LlvmLibcIsATTYTest, DevTTYTest) {
libc_errno = 0;
int fd = LIBC_NAMESPACE::open(TTY_FILE, O_RDONLY);
if (fd > 0) {
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
EXPECT_THAT(LIBC_NAMESPACE::isatty(fd), Succeeds(1));
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
}
@@ -53,7 +53,7 @@ TEST(LlvmLibcIsATTYTest, FileTest) {
constexpr const char *TEST_FILE = "testdata/isatty.test";
libc_errno = 0;
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(fd, 0);
EXPECT_THAT(LIBC_NAMESPACE::isatty(fd), Fails(ENOTTY, 0));
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
diff --git a/libc/test/src/unistd/link_test.cpp b/libc/test/src/unistd/link_test.cpp
index 2d5aa7588b08b9..a30221b9505855 100644
--- a/libc/test/src/unistd/link_test.cpp
+++ b/libc/test/src/unistd/link_test.cpp
@@ -28,14 +28,14 @@ TEST(LlvmLibcLinkTest, CreateAndUnlink) {
// 4. Cleanup the file and its link.
libc_errno = 0;
int write_fd = LIBC_NAMESPACE::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(write_fd, 0);
ASSERT_THAT(LIBC_NAMESPACE::close(write_fd), Succeeds(0));
ASSERT_THAT(LIBC_NAMESPACE::link(TEST_FILE, TEST_FILE_LINK), Succeeds(0));
int link_fd = LIBC_NAMESPACE::open(TEST_FILE_LINK, O_PATH);
ASSERT_GT(link_fd, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_THAT(LIBC_NAMESPACE::close(link_fd), Succeeds(0));
ASSERT_THAT(LIBC_NAMESPACE::unlink(TEST_FILE), Succeeds(0));
diff --git a/libc/test/src/unistd/linkat_test.cpp b/libc/test/src/unistd/linkat_test.cpp
index d1ffe37d63b48c..303a4af687c6be 100644
--- a/libc/test/src/unistd/linkat_test.cpp
+++ b/libc/test/src/unistd/linkat_test.cpp
@@ -32,7 +32,7 @@ TEST(LlvmLibcLinkatTest, CreateAndUnlink) {
libc_errno = 0;
int write_fd =
LIBC_NAMESPACE::open(TEST_FILE_PATH, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(write_fd, 0);
ASSERT_THAT(LIBC_NAMESPACE::close(write_fd), Succeeds(0));
@@ -43,7 +43,7 @@ TEST(LlvmLibcLinkatTest, CreateAndUnlink) {
int link_fd = LIBC_NAMESPACE::open(TEST_FILE_LINK_PATH, O_PATH);
ASSERT_GT(link_fd, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_THAT(LIBC_NAMESPACE::close(link_fd), Succeeds(0));
ASSERT_THAT(LIBC_NAMESPACE::unlink(TEST_FILE_PATH), Succeeds(0));
diff --git a/libc/test/src/unistd/lseek_test.cpp b/libc/test/src/unistd/lseek_test.cpp
index 1a13d54dbc2328..2e93730ce8e268 100644
--- a/libc/test/src/unistd/lseek_test.cpp
+++ b/libc/test/src/unistd/lseek_test.cpp
@@ -20,7 +20,7 @@ TEST(LlvmLibcUniStd, LseekTest) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/lseek.test";
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_RDONLY);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(fd, 0);
constexpr const char LSEEK_TEST[] = "lseek test";
constexpr int LSEEK_TEST_SIZE = sizeof(LSEEK_TEST) - 1;
@@ -54,7 +54,7 @@ TEST(LlvmLibcUniStd, LseekFailsTest) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/lseek.test";
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_RDONLY);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(fd, 0);
EXPECT_THAT(LIBC_NAMESPACE::lseek(fd, -1, SEEK_CUR), Fails(EINVAL));
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
diff --git a/libc/test/src/unistd/pread_pwrite_test.cpp b/libc/test/src/unistd/pread_pwrite_test.cpp
index f90d1341c20108..1a5bcc5579b8b1 100644
--- a/libc/test/src/unistd/pread_pwrite_test.cpp
+++ b/libc/test/src/unistd/pread_pwrite_test.cpp
@@ -34,7 +34,7 @@ TEST(LlvmLibcUniStd, PWriteAndPReadBackTest) {
constexpr const char *TEST_FILE = "testdata/pread_pwrite.test";
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(fd, 0);
ASSERT_THAT(LIBC_NAMESPACE::write(fd, HELLO, HELLO_SIZE),
Succeeds(HELLO_SIZE));
@@ -42,7 +42,7 @@ TEST(LlvmLibcUniStd, PWriteAndPReadBackTest) {
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
fd = LIBC_NAMESPACE::open(TEST_FILE, O_WRONLY);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(fd, 0);
ASSERT_THAT(LIBC_NAMESPACE::pwrite(fd, HELLO, HELLO_SIZE, OFFSET),
Succeeds(HELLO_SIZE));
@@ -50,7 +50,7 @@ TEST(LlvmLibcUniStd, PWriteAndPReadBackTest) {
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
fd = LIBC_NAMESPACE::open(TEST_FILE, O_RDONLY);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(fd, 0);
char read_buf[OFFSET_TEXT_SIZE];
ASSERT_THAT(LIBC_NAMESPACE::pread(fd, read_buf, HELLO_SIZE, OFFSET),
diff --git a/libc/test/src/unistd/read_write_test.cpp b/libc/test/src/unistd/read_write_test.cpp
index 3007d4c3871157..77912abee6b478 100644
--- a/libc/test/src/unistd/read_write_test.cpp
+++ b/libc/test/src/unistd/read_write_test.cpp
@@ -21,7 +21,7 @@ TEST(LlvmLibcUniStd, WriteAndReadBackTest) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "__unistd_read_write.test";
int write_fd = LIBC_NAMESPACE::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(write_fd, 0);
constexpr const char HELLO[] = "hello";
constexpr int HELLO_SIZE = sizeof(HELLO);
@@ -31,7 +31,7 @@ TEST(LlvmLibcUniStd, WriteAndReadBackTest) {
ASSERT_THAT(LIBC_NAMESPACE::close(write_fd), Succeeds(0));
int read_fd = LIBC_NAMESPACE::open(TEST_FILE, O_RDONLY);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(read_fd, 0);
char read_buf[10];
ASSERT_THAT(LIBC_NAMESPACE::read(read_fd, read_buf, HELLO_SIZE),
diff --git a/libc/test/src/unistd/readlink_test.cpp b/libc/test/src/unistd/readlink_test.cpp
index b2d018a50ec793..1064ea8c1d5485 100644
--- a/libc/test/src/unistd/readlink_test.cpp
+++ b/libc/test/src/unistd/readlink_test.cpp
@@ -30,7 +30,7 @@ TEST(LlvmLibcReadlinkTest, CreateAndUnlink) {
char buf[sizeof(LINK_VAL)];
ssize_t len = LIBC_NAMESPACE::readlink(LINK, buf, sizeof(buf));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(cpp::string_view(buf, len), cpp::string_view(LINK_VAL));
ASSERT_THAT(LIBC_NAMESPACE::unlink(LINK), Succeeds(0));
diff --git a/libc/test/src/unistd/readlinkat_test.cpp b/libc/test/src/unistd/readlinkat_test.cpp
index 19f0ceec3cf7c5..491ff3072fd90b 100644
--- a/libc/test/src/unistd/readlinkat_test.cpp
+++ b/libc/test/src/unistd/readlinkat_test.cpp
@@ -32,7 +32,7 @@ TEST(LlvmLibcReadlinkatTest, CreateAndUnlink) {
char buf[sizeof(LINK_VAL)];
ssize_t len = LIBC_NAMESPACE::readlinkat(AT_FDCWD, LINK, buf, sizeof(buf));
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_EQ(cpp::string_view(buf, len), cpp::string_view(LINK_VAL));
ASSERT_THAT(LIBC_NAMESPACE::unlink(LINK), Succeeds(0));
diff --git a/libc/test/src/unistd/symlink_test.cpp b/libc/test/src/unistd/symlink_test.cpp
index b25cfa4f857699..8d62cadc1dfbdc 100644
--- a/libc/test/src/unistd/symlink_test.cpp
+++ b/libc/test/src/unistd/symlink_test.cpp
@@ -29,7 +29,7 @@ TEST(LlvmLibcSymlinkTest, CreateAndUnlink) {
// 4. Cleanup the file and its symlink.
libc_errno = 0;
int write_fd = LIBC_NAMESPACE::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(write_fd, 0);
ASSERT_THAT(LIBC_NAMESPACE::close(write_fd), Succeeds(0));
@@ -38,7 +38,7 @@ TEST(LlvmLibcSymlinkTest, CreateAndUnlink) {
int symlink_fd = LIBC_NAMESPACE::open(TEST_FILE_LINK, O_PATH);
ASSERT_GT(symlink_fd, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_THAT(LIBC_NAMESPACE::close(symlink_fd), Succeeds(0));
ASSERT_THAT(LIBC_NAMESPACE::unlink(TEST_FILE), Succeeds(0));
diff --git a/libc/test/src/unistd/symlinkat_test.cpp b/libc/test/src/unistd/symlinkat_test.cpp
index 8aba2daee8cf38..17f48c6dc3f540 100644
--- a/libc/test/src/unistd/symlinkat_test.cpp
+++ b/libc/test/src/unistd/symlinkat_test.cpp
@@ -32,7 +32,7 @@ TEST(LlvmLibcSymlinkatTest, CreateAndUnlink) {
libc_errno = 0;
int write_fd =
LIBC_NAMESPACE::open(TEST_FILE_PATH, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(write_fd, 0);
ASSERT_THAT(LIBC_NAMESPACE::close(write_fd), Succeeds(0));
@@ -42,7 +42,7 @@ TEST(LlvmLibcSymlinkatTest, CreateAndUnlink) {
int link_fd = LIBC_NAMESPACE::open(TEST_FILE_LINK_PATH, O_PATH);
ASSERT_GT(link_fd, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_THAT(LIBC_NAMESPACE::close(link_fd), Succeeds(0));
ASSERT_THAT(LIBC_NAMESPACE::close(dir_fd), Succeeds(0));
diff --git a/libc/test/src/unistd/syscall_test.cpp b/libc/test/src/unistd/syscall_test.cpp
index 6a5ca47f8d494a..6889f0daf70f86 100644
--- a/libc/test/src/unistd/syscall_test.cpp
+++ b/libc/test/src/unistd/syscall_test.cpp
@@ -30,7 +30,7 @@ TEST(LlvmLibcSyscallTest, TrivialCall) {
libc_errno = 0;
ASSERT_GE(LIBC_NAMESPACE::syscall(SYS_gettid), 0l);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
}
TEST(LlvmLibcSyscallTest, SymlinkCreateDestroy) {
@@ -45,7 +45,7 @@ TEST(LlvmLibcSyscallTest, SymlinkCreateDestroy) {
#else
#error "symlink and symlinkat syscalls not available."
#endif
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
char buf[sizeof(LINK_VAL)];
@@ -56,7 +56,7 @@ TEST(LlvmLibcSyscallTest, SymlinkCreateDestroy) {
LIBC_NAMESPACE::syscall(SYS_readlinkat, AT_FDCWD, LINK, buf, sizeof(buf)),
0l);
#endif
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
#ifdef SYS_unlink
ASSERT_GE(LIBC_NAMESPACE::syscall(SYS_unlink, LINK), 0l);
@@ -65,7 +65,7 @@ TEST(LlvmLibcSyscallTest, SymlinkCreateDestroy) {
#else
#error "unlink and unlinkat syscalls not available."
#endif
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
}
TEST(LlvmLibcSyscallTest, FileReadWrite) {
@@ -84,17 +84,17 @@ TEST(LlvmLibcSyscallTest, FileReadWrite) {
#error "open and openat syscalls not available."
#endif
ASSERT_GT(fd, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GE(LIBC_NAMESPACE::syscall(SYS_pwrite64, fd, HELLO, HELLO_SIZE, 0),
0l);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GE(LIBC_NAMESPACE::syscall(SYS_fsync, fd), 0l);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GE(LIBC_NAMESPACE::syscall(SYS_close, fd), 0l);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
}
TEST(LlvmLibcSyscallTest, FileLinkCreateDestroy) {
@@ -121,10 +121,10 @@ TEST(LlvmLibcSyscallTest, FileLinkCreateDestroy) {
#error "open and openat syscalls not available."
#endif
ASSERT_GT(write_fd, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GE(LIBC_NAMESPACE::syscall(SYS_close, write_fd), 0l);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
#ifdef SYS_open
int dir_fd = LIBC_NAMESPACE::syscall(SYS_open, TEST_DIR, O_DIRECTORY, 0);
@@ -135,12 +135,12 @@ TEST(LlvmLibcSyscallTest, FileLinkCreateDestroy) {
#error "open and openat syscalls not available."
#endif
ASSERT_GT(dir_fd, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GE(LIBC_NAMESPACE::syscall(SYS_linkat, dir_fd, TEST_FILE, dir_fd,
TEST_FILE_LINK, 0),
0l);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
#ifdef SYS_open
int link_fd =
LIBC_NAMESPACE::syscall(SYS_open, TEST_FILE_LINK_PATH, O_PATH, 0);
@@ -151,7 +151,7 @@ TEST(LlvmLibcSyscallTest, FileLinkCreateDestroy) {
#error "open and openat syscalls not available."
#endif
ASSERT_GT(link_fd, 0);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
#ifdef SYS_unlink
ASSERT_GE(LIBC_NAMESPACE::syscall(SYS_unlink, TEST_FILE_PATH), 0l);
@@ -161,7 +161,7 @@ TEST(LlvmLibcSyscallTest, FileLinkCreateDestroy) {
#else
#error "unlink and unlinkat syscalls not available."
#endif
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
#ifdef SYS_unlink
ASSERT_GE(LIBC_NAMESPACE::syscall(SYS_unlink, TEST_FILE_LINK_PATH), 0l);
@@ -172,8 +172,8 @@ TEST(LlvmLibcSyscallTest, FileLinkCreateDestroy) {
#else
#error "unlink and unlinkat syscalls not available."
#endif
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GE(LIBC_NAMESPACE::syscall(SYS_close, dir_fd), 0l);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
}
diff --git a/libc/test/src/unistd/truncate_test.cpp b/libc/test/src/unistd/truncate_test.cpp
index 6d8a3b8e53f728..5c76d9f18dd8a5 100644
--- a/libc/test/src/unistd/truncate_test.cpp
+++ b/libc/test/src/unistd/truncate_test.cpp
@@ -35,14 +35,14 @@ TEST(LlvmLibcTruncateTest, CreateAndTruncate) {
// 4. Try to read more than 1 byte and fail.
libc_errno = 0;
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(fd, 0);
ASSERT_EQ(ssize_t(WRITE_SIZE),
LIBC_NAMESPACE::write(fd, WRITE_DATA, WRITE_SIZE));
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
fd = LIBC_NAMESPACE::open(TEST_FILE, O_RDONLY);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(fd, 0);
ASSERT_EQ(ssize_t(WRITE_SIZE), LIBC_NAMESPACE::read(fd, buf, WRITE_SIZE));
ASSERT_EQ(cpp::string_view(buf), cpp::string_view(WRITE_DATA));
@@ -51,7 +51,7 @@ TEST(LlvmLibcTruncateTest, CreateAndTruncate) {
ASSERT_THAT(LIBC_NAMESPACE::truncate(TEST_FILE, off_t(1)), Succeeds(0));
fd = LIBC_NAMESPACE::open(TEST_FILE, O_RDONLY);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(fd, 0);
ASSERT_EQ(ssize_t(1), LIBC_NAMESPACE::read(fd, buf, WRITE_SIZE));
ASSERT_EQ(buf[0], WRITE_DATA[0]);
diff --git a/libc/test/src/unistd/unlink_test.cpp b/libc/test/src/unistd/unlink_test.cpp
index 77f65b5ecc6a1a..1be577995e28b0 100644
--- a/libc/test/src/unistd/unlink_test.cpp
+++ b/libc/test/src/unistd/unlink_test.cpp
@@ -19,7 +19,7 @@ TEST(LlvmLibcUnlinkTest, CreateAndUnlink) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/unlink.test";
int write_fd = LIBC_NAMESPACE::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(write_fd, 0);
ASSERT_THAT(LIBC_NAMESPACE::close(write_fd), Succeeds(0));
ASSERT_THAT(LIBC_NAMESPACE::unlink(TEST_FILE), Succeeds(0));
diff --git a/libc/test/src/unistd/unlinkat_test.cpp b/libc/test/src/unistd/unlinkat_test.cpp
index 22a20bc6ad07bc..4fbf8fea589292 100644
--- a/libc/test/src/unistd/unlinkat_test.cpp
+++ b/libc/test/src/unistd/unlinkat_test.cpp
@@ -21,11 +21,11 @@ TEST(LlvmLibcUnlinkatTest, CreateAndDeleteTest) {
constexpr const char *TEST_DIR = "testdata";
constexpr const char *TEST_FILE = "openat.test";
int dir_fd = LIBC_NAMESPACE::open(TEST_DIR, O_DIRECTORY);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(dir_fd, 0);
int write_fd =
LIBC_NAMESPACE::openat(dir_fd, TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(write_fd, 0);
ASSERT_THAT(LIBC_NAMESPACE::close(write_fd), Succeeds(0));
ASSERT_THAT(LIBC_NAMESPACE::unlinkat(dir_fd, TEST_FILE, 0), Succeeds(0));
@@ -35,7 +35,7 @@ TEST(LlvmLibcUnlinkatTest, CreateAndDeleteTest) {
TEST(LlvmLibcUnlinkatTest, UnlinkatNonExistentFile) {
constexpr const char *TEST_DIR = "testdata";
int dir_fd = LIBC_NAMESPACE::open(TEST_DIR, O_DIRECTORY);
- ASSERT_EQ(libc_errno, 0);
+ ASSERT_EQ(static_cast<int>(libc_errno), 0);
ASSERT_GT(dir_fd, 0);
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
More information about the libc-commits
mailing list