aboutsummaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorGuillaume Chatelet <gchatelet@google.com>2022-06-29 12:28:00 +0000
committerGuillaume Chatelet <gchatelet@google.com>2022-06-29 14:53:53 +0000
commit292b281caf8c3750cc0796b971af2ca24236a926 (patch)
tree64cb967e13fa1fe5112d4b729644b47cc433babc /libc
parent0fb24a85cb7e91b23ad0e72590d2fcc814dc5c48 (diff)
downloadllvm-292b281caf8c3750cc0796b971af2ca24236a926.zip
llvm-292b281caf8c3750cc0796b971af2ca24236a926.tar.gz
llvm-292b281caf8c3750cc0796b971af2ca24236a926.tar.bz2
[libc][test] Remove dependency on sstream in algorithm_test.cpp
Bots have been failing in full build mode because ´#include <sstream>´ would pull pthread which is not possible when code is compiled with ´-freestanding´. Differential Revision: https://reviews.llvm.org/D128809
Diffstat (limited to 'libc')
-rw-r--r--libc/test/src/string/memory_utils/CMakeLists.txt3
-rw-r--r--libc/test/src/string/memory_utils/algorithm_test.cpp47
2 files changed, 40 insertions, 10 deletions
diff --git a/libc/test/src/string/memory_utils/CMakeLists.txt b/libc/test/src/string/memory_utils/CMakeLists.txt
index df481ee15..9b777a7 100644
--- a/libc/test/src/string/memory_utils/CMakeLists.txt
+++ b/libc/test/src/string/memory_utils/CMakeLists.txt
@@ -4,7 +4,7 @@ add_libc_unittest(
libc_string_unittests
SRCS
address_test.cpp
- # algorithm_test.cpp
+ algorithm_test.cpp
backend_test.cpp
elements_test.cpp
memory_access_test.cpp
@@ -12,7 +12,6 @@ add_libc_unittest(
COMPILE_OPTIONS
${LIBC_COMPILE_OPTIONS_NATIVE}
-ffreestanding
- -pthread
DEPENDS
libc.src.string.memory_utils.memory_utils
libc.src.__support.CPP.array
diff --git a/libc/test/src/string/memory_utils/algorithm_test.cpp b/libc/test/src/string/memory_utils/algorithm_test.cpp
index 3c6303a..aeadafd 100644
--- a/libc/test/src/string/memory_utils/algorithm_test.cpp
+++ b/libc/test/src/string/memory_utils/algorithm_test.cpp
@@ -6,7 +6,9 @@
#include <src/string/memory_utils/algorithm.h>
#include <src/string/memory_utils/backends.h>
-#include <sstream>
+#include <string>
+#include <type_traits>
+#include <vector>
namespace __llvm_libc {
@@ -23,7 +25,26 @@ struct alignas(64) Buffer : cpp::Array<char, 128> {
static Buffer buffer1;
static Buffer buffer2;
-static std::ostringstream LOG;
+struct Logger {
+ Logger &operator<<(const char *str) {
+ Buffer.append(str);
+ return *this;
+ }
+ Logger &operator<<(char c) {
+ Buffer.push_back(c);
+ return *this;
+ }
+ template <typename Scalar>
+ std::enable_if_t<std::is_integral<Scalar>::value, Logger &>
+ operator<<(Scalar number) {
+ Buffer.append(std::to_string(number));
+ return *this;
+ }
+ const std::string &str() const { return Buffer; }
+
+private:
+ std::string Buffer;
+} LOG;
struct TestBackend {
static constexpr bool IS_BACKEND_TYPE = true;
@@ -72,7 +93,7 @@ struct TestBackend {
struct LlvmLibcAlgorithm : public testing::Test {
void SetUp() override {
- LOG = std::ostringstream();
+ LOG = Logger();
LOG << '\n';
}
@@ -91,11 +112,20 @@ struct LlvmLibcAlgorithm : public testing::Test {
return trace_.c_str();
}
- const char *stripComments(const char *expected) {
+ const char *stripComments(std::string expected) {
expected_.clear();
- std::stringstream ss(expected);
- std::string line;
- while (std::getline(ss, line, '\n')) {
+ // split expected by lines
+ std::vector<std::string> lines;
+ lines.emplace_back();
+ for (const char c : expected) {
+ if (c == '\n') {
+ lines.emplace_back();
+ } else {
+ lines.back().push_back(c);
+ }
+ }
+ // strip comment for each lines
+ for (const std::string &line : lines) {
const auto pos = line.find('#');
if (pos == std::string::npos) {
expected_ += line;
@@ -105,7 +135,8 @@ struct LlvmLibcAlgorithm : public testing::Test {
log.pop_back();
expected_ += log;
}
- expected_ += '\n';
+ if (expected_.back() != '\n')
+ expected_.push_back('\n');
}
return expected_.c_str();
}