diff --git a/libc/utils/UnitTest/CMakeLists.txt b/libc/utils/UnitTest/CMakeLists.txt --- a/libc/utils/UnitTest/CMakeLists.txt +++ b/libc/utils/UnitTest/CMakeLists.txt @@ -2,7 +2,6 @@ LibcUnitTest Test.cpp Test.h - LINK_COMPONENTS Support ) target_include_directories(LibcUnitTest PUBLIC ${LIBC_SOURCE_DIR}) add_dependencies(LibcUnitTest libc.utils.CPP.standalone_cpp) diff --git a/libc/utils/testutils/ExecuteFunctionUnix.cpp b/libc/utils/testutils/ExecuteFunctionUnix.cpp --- a/libc/utils/testutils/ExecuteFunctionUnix.cpp +++ b/libc/utils/testutils/ExecuteFunctionUnix.cpp @@ -7,9 +7,10 @@ //===----------------------------------------------------------------------===// #include "ExecuteFunction.h" -#include "llvm/Support/raw_ostream.h" #include #include +#include +#include #include #include #include @@ -41,8 +42,8 @@ return ProcessStatus::Error("pipe(2) failed"); // Don't copy the buffers into the child process and print twice. - llvm::outs().flush(); - llvm::errs().flush(); + std::cout.flush(); + std::cerr.flush(); pid_t Pid = ::fork(); if (Pid == -1) return ProcessStatus::Error("fork(2) failed"); diff --git a/libc/utils/testutils/FDReaderUnix.cpp b/libc/utils/testutils/FDReaderUnix.cpp --- a/libc/utils/testutils/FDReaderUnix.cpp +++ b/libc/utils/testutils/FDReaderUnix.cpp @@ -7,9 +7,10 @@ //===----------------------------------------------------------------------===// #include "FDReader.h" -#include "llvm/Support/MemoryBuffer.h" +// #include "llvm/Support/MemoryBuffer.h" #include #include +#include #include namespace __llvm_libc { @@ -17,7 +18,9 @@ FDReader::FDReader() { if (::pipe(pipefd)) - llvm::report_fatal_error("pipe(2) failed"); + // llvm::report_fatal_error("pipe(2) failed"); + std::cerr << "pipe(2) failed"; + abort(); } FDReader::~FDReader() { @@ -26,15 +29,38 @@ } bool FDReader::matchWritten(const char *str) { - llvm::ErrorOr> bufOrErr = - llvm::MemoryBuffer::getOpenFile(pipefd[0], "", - /* FileSize (irrelevant) */ 0); - if (!bufOrErr) { - assert(0 && "Error reading from pipe"); - return false; + const ssize_t chunkSize = 4096 * 4; + // chunkSize stolen from MemoryBuffer.cpp and getMemoryBufferForStream + + char buffer[chunkSize]; + std::string pipeStr; + std::string inputStr(str); + int bytesRead; + + std::cout << str << std::endl; + + for (;;) { + bytesRead = read(pipefd[0], buffer, chunkSize); + if (bytesRead > 0) { + pipeStr.append(buffer); + } else if (bytesRead == 0) { + break; + } else { + assert(0 && "Error reading from pipe"); + return false; + } } - const llvm::MemoryBuffer &buf = **bufOrErr; - return !std::strncmp(buf.getBufferStart(), str, buf.getBufferSize()); + + return pipeStr.compare(inputStr) == 0; + // llvm::ErrorOr> bufOrErr = + // llvm::MemoryBuffer::getOpenFile(pipefd[0], "", + // /* FileSize (irrelevant) */ 0); + // if (!bufOrErr) { + // assert(0 && "Error reading from pipe"); + // return false; + // } + // const llvm::MemoryBuffer &buf = **bufOrErr; + // return !std::strncmp(buf.getBufferStart(), str, buf.getBufferSize()); } } // namespace testutils diff --git a/libc/utils/testutils/StreamWrapper.cpp b/libc/utils/testutils/StreamWrapper.cpp --- a/libc/utils/testutils/StreamWrapper.cpp +++ b/libc/utils/testutils/StreamWrapper.cpp @@ -7,19 +7,19 @@ //===----------------------------------------------------------------------===// #include "StreamWrapper.h" -#include "llvm/Support/raw_ostream.h" #include +#include #include #include namespace __llvm_libc { namespace testutils { -StreamWrapper outs() { return {std::addressof(llvm::outs())}; } +StreamWrapper outs() { return {std::addressof(std::cout)}; } template StreamWrapper &StreamWrapper::operator<<(T t) { assert(OS); - llvm::raw_ostream &Stream = *reinterpret_cast(OS); + std::ostream &Stream = *reinterpret_cast(OS); Stream << t; return *this; }