Skip to content

Commit 756cb37

Browse files
committed
Clean up tests, dependencies
1 parent 0e8b25c commit 756cb37

File tree

8 files changed

+15
-75
lines changed

8 files changed

+15
-75
lines changed

libc/src/stdio/printf_core/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ add_header_library(
4747
libc.include.inttypes
4848
libc.src.__support.CPP.string_view
4949
libc.src.__support.FPUtil.fp_bits
50-
libc.hdr.types.FILE
5150
libc.hdr.errno_macros
52-
libc.src.__support.File.file
5351
)
5452

5553
add_header_library(

libc/src/stdio/printf_core/core_structs.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@
1212
#include "src/__support/macros/config.h"
1313

1414
#include "hdr/errno_macros.h"
15-
#include "hdr/types/FILE.h"
1615
#include "src/__support/CPP/string_view.h"
1716
#include "src/__support/CPP/type_traits.h"
1817
#include "src/__support/FPUtil/FPBits.h"
19-
#include "src/__support/File/file.h"
2018
#include "src/stdio/printf_core/printf_config.h"
2119

2220
#include <inttypes.h>

libc/src/stdio/printf_core/fixed_converter.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef LLVM_LIBC_SRC_STDIO_PRINTF_CORE_FIXED_CONVERTER_H
1010
#define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_FIXED_CONVERTER_H
1111

12-
#include "hdr/errno_macros.h"
1312
#include "include/llvm-libc-macros/stdfix-macros.h"
1413
#include "src/__support/CPP/string_view.h"
1514
#include "src/__support/ctype_utils.h"

libc/src/stdio/printf_core/vfprintf_internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef LLVM_LIBC_SRC_STDIO_PRINTF_CORE_VFPRINTF_INTERNAL_H
1010
#define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_VFPRINTF_INTERNAL_H
1111

12-
#include "hdr/errno_macros.h"
1312
#include "src/__support/File/file.h"
1413
#include "src/__support/arg_list.h"
1514
#include "src/__support/error_or.h"

libc/test/src/stdio/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,6 @@ if(LLVM_LIBC_FULL_BUILD)
170170
libc.src.stdio.fopen
171171
libc.src.stdio.fread
172172
)
173-
if(${LIBC_TARGET_OS} STREQUAL "linux")
174-
list(APPEND fprintf_test_deps
175-
libc.src.stdio.fopencookie
176-
)
177-
endif()
178173
# This is to be used for tests which write to libc's platform streams
179174
# under full build but write to system-lib's streams otherwise.
180175
set(hermetic_test_only HERMETIC_TEST_ONLY)

libc/test/src/stdio/fprintf_test.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020
#include "test/UnitTest/ErrnoSetterMatcher.h"
2121
#include "test/UnitTest/Test.h"
2222

23-
#if defined(LIBC_TARGET_OS_IS_LINUX) && \
24-
!defined(LIBC_COPT_STDIO_USE_SYSTEM_FILE)
25-
#include "src/stdio/fopencookie.h"
26-
#endif
27-
2823
namespace printf_test {
2924
#ifndef LIBC_COPT_STDIO_USE_SYSTEM_FILE
3025
using LIBC_NAMESPACE::fclose;
@@ -93,33 +88,6 @@ TEST(LlvmLibcFPrintfTest, WriteToFile) {
9388
ASSERT_EQ(printf_test::fclose(file), 0);
9489
}
9590

96-
#if !defined(LIBC_COPT_STDIO_USE_SYSTEM_FILE) && \
97-
defined(LIBC_TARGET_OS_IS_LINUX)
98-
TEST(LlvmLibcFPrintfTest, CharsWrittenOverflow) {
99-
struct NoopStream {};
100-
auto noop_write = [](void *, const char *, size_t size) -> ssize_t {
101-
return size;
102-
};
103-
104-
NoopStream stream;
105-
cookie_io_functions_t funcs = {nullptr, +noop_write, nullptr, nullptr};
106-
::FILE *file = LIBC_NAMESPACE::fopencookie(&stream, "w", funcs);
107-
ASSERT_NE(file, nullptr);
108-
109-
// Trigger an overflow in the return value of fprintf by writing more than
110-
// INT_MAX bytes. We do this by printing a string with precision INT_MAX, and
111-
// then one more character.
112-
int max_int = LIBC_NAMESPACE::cpp::numeric_limits<int>::max();
113-
int result = LIBC_NAMESPACE::fprintf(file, "%*sA", max_int, "");
114-
115-
EXPECT_LT(result, 0);
116-
ASSERT_ERRNO_EQ(EOVERFLOW);
117-
118-
EXPECT_EQ(printf_test::fclose(file), 0);
119-
}
120-
#endif // #if !defined(LIBC_COPT_STDIO_USE_SYSTEM_FILE) &&
121-
// defined(LIBC_TARGET_OS_IS_LINUX)
122-
12391
#ifndef LIBC_COPT_PRINTF_NO_NULLPTR_CHECKS
12492
TEST(LlvmLibcFPrintfTest, NullPtrCheck) {
12593
const char *FILENAME = APPEND_LIBC_TEST("fprintf_nullptr.test");

libc/test/src/stdio/snprintf_test.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88

99
#include "src/stdio/snprintf.h"
1010

11+
#include "test/UnitTest/ErrnoCheckingTest.h"
12+
#include "test/UnitTest/ErrnoSetterMatcher.h"
1113
#include "test/UnitTest/Test.h"
1214

15+
using LlvmLibcSNPrintfTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
16+
1317
// The sprintf test cases cover testing the shared printf functionality, so
1418
// these tests will focus on snprintf exclusive features.
1519

@@ -59,3 +63,14 @@ TEST(LlvmLibcSNPrintfTest, NoCutOff) {
5963
EXPECT_EQ(written, 10);
6064
ASSERT_STREQ(buff, "1234567890");
6165
}
66+
67+
TEST(LlvmLibcSNPrintfTest, CharsWrittenOverflow) {
68+
char buff[0];
69+
70+
// Trigger an overflow in the return value of snprintf by writing more than
71+
// INT_MAX bytes.
72+
int int_max = LIBC_NAMESPACE::cpp::numeric_limits<int>::max();
73+
int written = LIBC_NAMESPACE::snprintf(buff, 0, "%*stest", int_max, "");
74+
EXPECT_LT(written, 0);
75+
ASSERT_ERRNO_EQ(EOVERFLOW);
76+
}

libc/test/src/stdio/vfprintf_test.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@
2323
#include "test/UnitTest/ErrnoSetterMatcher.h"
2424
#include "test/UnitTest/Test.h"
2525

26-
#if defined(LIBC_TARGET_OS_IS_LINUX) && \
27-
!defined(LIBC_COPT_STDIO_USE_SYSTEM_FILE)
28-
#include "src/stdio/fopencookie.h"
29-
#endif
30-
3126
namespace printf_test {
3227
#ifndef LIBC_COPT_STDIO_USE_SYSTEM_FILE
3328
using LIBC_NAMESPACE::fclose;
@@ -103,30 +98,3 @@ TEST(LlvmLibcVFPrintfTest, WriteToFile) {
10398

10499
ASSERT_EQ(printf_test::fclose(file), 0);
105100
}
106-
107-
#if !defined(LIBC_COPT_STDIO_USE_SYSTEM_FILE) && \
108-
defined(LIBC_TARGET_OS_IS_LINUX)
109-
TEST(LlvmLibcVFPrintfTest, CharsWrittenOverflow) {
110-
struct NoopStream {};
111-
auto noop_write = [](void *, const char *, size_t size) -> ssize_t {
112-
return size;
113-
};
114-
115-
NoopStream stream;
116-
cookie_io_functions_t funcs = {nullptr, +noop_write, nullptr, nullptr};
117-
::FILE *file = LIBC_NAMESPACE::fopencookie(&stream, "w", funcs);
118-
ASSERT_NE(file, nullptr);
119-
120-
// Trigger an overflow in the return value of vfprintf by writing more than
121-
// INT_MAX bytes. We do this by printing a string with precision INT_MAX, and
122-
// then one more character.
123-
int max_int = LIBC_NAMESPACE::cpp::numeric_limits<int>::max();
124-
int result = call_vfprintf(file, "%*sA", max_int, "");
125-
126-
EXPECT_LT(result, 0);
127-
ASSERT_ERRNO_EQ(EOVERFLOW);
128-
129-
EXPECT_EQ(printf_test::fclose(file), 0);
130-
}
131-
#endif // !defined(LIBC_COPT_STDIO_USE_SYSTEM_FILE) &&
132-
// defined(LIBC_TARGET_OS_IS_LINUX)

0 commit comments

Comments
 (0)