Skip to content

Commit

Permalink
[libc][NFC] Switch string and errno tests to libc_errno.
Browse files Browse the repository at this point in the history
  • Loading branch information
Siva Chandra Reddy committed Mar 13, 2023
1 parent adff2b2 commit 30d8942
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions libc/test/src/__support/CMakeLists.txt
Expand Up @@ -40,6 +40,7 @@ add_libc_unittest(
DEPENDS
libc.src.__support.str_to_float
libc.src.__support.uint128
libc.src.errno.errno
)

add_libc_unittest(
Expand Down
7 changes: 4 additions & 3 deletions libc/test/src/__support/str_to_float_test.cpp
Expand Up @@ -9,6 +9,7 @@
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/UInt128.h"
#include "src/__support/str_to_float.h"
#include "src/errno/libc_errno.h"

#include "test/UnitTest/Test.h"

Expand Down Expand Up @@ -78,7 +79,7 @@ class LlvmLibcStrToFloatTest : public __llvm_libc::testing::Test {
typename __llvm_libc::fputil::FPBits<T>::UIntType actual_output_mantissa =
0;
uint32_t actual_output_exp2 = 0;
errno = 0;
libc_errno = 0;

auto result = __llvm_libc::internal::simple_decimal_conversion<T>(numStart);

Expand Down Expand Up @@ -250,7 +251,7 @@ TEST(LlvmLibcStrToFloatTest, SimpleDecimalConversionExtraTypes) {
uint32_t float_output_mantissa = 0;
uint32_t output_exp2 = 0;

errno = 0;
libc_errno = 0;
auto float_result = __llvm_libc::internal::simple_decimal_conversion<float>(
"123456789012345678900");
float_output_mantissa = float_result.num.mantissa;
Expand All @@ -262,7 +263,7 @@ TEST(LlvmLibcStrToFloatTest, SimpleDecimalConversionExtraTypes) {
uint64_t double_output_mantissa = 0;
output_exp2 = 0;

errno = 0;
libc_errno = 0;
auto double_result = __llvm_libc::internal::simple_decimal_conversion<double>(
"123456789012345678900");

Expand Down
6 changes: 3 additions & 3 deletions libc/test/src/errno/errno_test.cpp
Expand Up @@ -6,11 +6,11 @@
//
//===----------------------------------------------------------------------===//

#include "src/errno/llvmlibc_errno.h"
#include "src/errno/libc_errno.h"
#include "test/UnitTest/Test.h"

TEST(LlvmLibcErrnoTest, Basic) {
int test_val = 123;
llvmlibc_errno = test_val;
ASSERT_EQ(test_val, llvmlibc_errno);
libc_errno = test_val;
ASSERT_EQ(test_val, libc_errno);
}
1 change: 0 additions & 1 deletion libc/test/src/string/CMakeLists.txt
Expand Up @@ -161,7 +161,6 @@ add_libc_unittest(
SRCS
strdup_test.cpp
DEPENDS
libc.include.errno
libc.include.stdlib
libc.src.string.strdup
libc.src.errno.errno
Expand Down
14 changes: 7 additions & 7 deletions libc/test/src/string/strdup_test.cpp
Expand Up @@ -6,18 +6,18 @@
//
//===----------------------------------------------------------------------===//

#include "src/errno/libc_errno.h"
#include "src/string/strdup.h"
#include "test/UnitTest/Test.h"

#include <errno.h>
#include <stdlib.h>

TEST(LlvmLibcStrDupTest, EmptyString) {
const char *empty = "";

errno = 0;
libc_errno = 0;
char *result = __llvm_libc::strdup(empty);
ASSERT_EQ(errno, 0);
ASSERT_EQ(libc_errno, 0);

ASSERT_NE(result, static_cast<char *>(nullptr));
ASSERT_NE(empty, const_cast<const char *>(result));
Expand All @@ -28,9 +28,9 @@ TEST(LlvmLibcStrDupTest, EmptyString) {
TEST(LlvmLibcStrDupTest, AnyString) {
const char *abc = "abc";

errno = 0;
libc_errno = 0;
char *result = __llvm_libc::strdup(abc);
ASSERT_EQ(errno, 0);
ASSERT_EQ(libc_errno, 0);

ASSERT_NE(result, static_cast<char *>(nullptr));
ASSERT_NE(abc, const_cast<const char *>(result));
Expand All @@ -39,9 +39,9 @@ TEST(LlvmLibcStrDupTest, AnyString) {
}

TEST(LlvmLibcStrDupTest, NullPtr) {
errno = 0;
libc_errno = 0;
char *result = __llvm_libc::strdup(nullptr);
ASSERT_EQ(errno, 0);
ASSERT_EQ(libc_errno, 0);

ASSERT_EQ(result, static_cast<char *>(nullptr));
}

0 comments on commit 30d8942

Please sign in to comment.