[libc] Make errno asserts noop on gpu targets (#166606)

This patch defines errno unit and integration test asserts as noop on
GPU targets. Checking for errnos is tests has caused build breakages in
previous patches.
This commit is contained in:
Marcell Leleszi
2025-11-05 20:17:13 +01:00
committed by GitHub
parent 28a279ce14
commit 3d0a3674d9
4 changed files with 16 additions and 0 deletions

View File

@@ -14,5 +14,6 @@ add_object_library(
libc.hdr.stdint_proxy
libc.src.__support.OSUtil.osutil
libc.src.__support.CPP.atomic
libc.src.__support.macros.properties.architectures
${arch_specific_deps}
)

View File

@@ -11,6 +11,7 @@
#include "src/__support/OSUtil/exit.h"
#include "src/__support/OSUtil/io.h"
#include "src/__support/macros/properties/architectures.h"
#define __AS_STRING(val) #val
#define __CHECK_TRUE(file, line, val, should_exit) \
@@ -68,9 +69,15 @@
////////////////////////////////////////////////////////////////////////////////
// Errno checks.
#ifdef LIBC_TARGET_ARCH_IS_GPU
#define ASSERT_ERRNO_EQ(VAL)
#define ASSERT_ERRNO_SUCCESS()
#define ASSERT_ERRNO_FAILURE()
#else
#define ASSERT_ERRNO_EQ(VAL) ASSERT_EQ(VAL, static_cast<int>(errno))
#define ASSERT_ERRNO_SUCCESS() ASSERT_EQ(0, static_cast<int>(errno))
#define ASSERT_ERRNO_FAILURE() ASSERT_NE(0, static_cast<int>(errno))
#endif
// Integration tests are compiled with -ffreestanding which stops treating
// the main function as a non-overloadable special function. Hence, we use a

View File

@@ -204,5 +204,6 @@ add_header_library(
ErrnoCheckingTest.h
DEPENDS
libc.src.__support.common
libc.src.__support.macros.properties.architectures
libc.src.errno.errno
)

View File

@@ -11,11 +11,17 @@
#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/architectures.h"
#include "test/UnitTest/Test.h"
// Define macro to validate the value stored in the errno and restore it
// to zero.
#ifdef LIBC_TARGET_ARCH_IS_GPU
#define ASSERT_ERRNO_EQ(VAL)
#define ASSERT_ERRNO_SUCCESS()
#define ASSERT_ERRNO_FAILURE()
#else
#define ASSERT_ERRNO_EQ(VAL) \
do { \
ASSERT_EQ(VAL, static_cast<int>(libc_errno)); \
@@ -27,6 +33,7 @@
ASSERT_NE(0, static_cast<int>(libc_errno)); \
libc_errno = 0; \
} while (0)
#endif
namespace LIBC_NAMESPACE_DECL {
namespace testing {