[libc-commits] [libc] 22bc0fd - [NFC][libc] Switch mem* tests from ArrayRef to span
Guillaume Chatelet via libc-commits
libc-commits at lists.llvm.org
Mon Aug 22 02:58:50 PDT 2022
Author: Guillaume Chatelet
Date: 2022-08-22T09:58:35Z
New Revision: 22bc0fde556ea94a9682b03dcb18c130dcaf071f
URL: https://github.com/llvm/llvm-project/commit/22bc0fde556ea94a9682b03dcb18c130dcaf071f
DIFF: https://github.com/llvm/llvm-project/commit/22bc0fde556ea94a9682b03dcb18c130dcaf071f.diff
LOG: [NFC][libc] Switch mem* tests from ArrayRef to span
Added:
Modified:
libc/test/src/string/bzero_test.cpp
libc/test/src/string/memccpy_test.cpp
libc/test/src/string/memcpy_test.cpp
libc/test/src/string/memmove_test.cpp
libc/test/src/string/memory_utils/backend_test.cpp
libc/test/src/string/memory_utils/elements_test.cpp
libc/test/src/string/memory_utils/memory_access_test.cpp
libc/test/src/string/memset_test.cpp
libc/test/src/string/strncpy_test.cpp
libc/utils/UnitTest/CMakeLists.txt
libc/utils/UnitTest/MemoryMatcher.cpp
libc/utils/UnitTest/MemoryMatcher.h
Removed:
################################################################################
diff --git a/libc/test/src/string/bzero_test.cpp b/libc/test/src/string/bzero_test.cpp
index beecf48920c06..5ae3a497ab2ca 100644
--- a/libc/test/src/string/bzero_test.cpp
+++ b/libc/test/src/string/bzero_test.cpp
@@ -6,18 +6,18 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/CPP/ArrayRef.h"
+#include "src/__support/CPP/span.h"
#include "src/string/bzero.h"
#include "utils/UnitTest/Test.h"
using __llvm_libc::cpp::array;
-using __llvm_libc::cpp::ArrayRef;
+using __llvm_libc::cpp::span;
using Data = array<char, 2048>;
-static const ArrayRef<char> k_deadcode("DEADC0DE", 8);
+static const span<const char> k_deadcode("DEADC0DE", 8);
// Returns a Data object filled with a repetition of `filler`.
-Data get_data(ArrayRef<char> filler) {
+Data get_data(span<const char> filler) {
Data out;
for (size_t i = 0; i < out.size(); ++i)
out[i] = filler[i % filler.size()];
diff --git a/libc/test/src/string/memccpy_test.cpp b/libc/test/src/string/memccpy_test.cpp
index ac11e33a3d63c..c5a32600dc393 100644
--- a/libc/test/src/string/memccpy_test.cpp
+++ b/libc/test/src/string/memccpy_test.cpp
@@ -6,17 +6,17 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/CPP/ArrayRef.h"
+#include "src/__support/CPP/span.h"
#include "src/string/memccpy.h"
#include "utils/UnitTest/Test.h"
#include <stddef.h> // For size_t.
class LlvmLibcMemccpyTest : public __llvm_libc::testing::Test {
public:
- void check_memccpy(__llvm_libc::cpp::MutableArrayRef<char> dst,
- const __llvm_libc::cpp::ArrayRef<char> src, int end,
+ void check_memccpy(__llvm_libc::cpp::span<char> dst,
+ const __llvm_libc::cpp::span<const char> src, int end,
size_t count,
- const __llvm_libc::cpp::ArrayRef<char> expected,
+ const __llvm_libc::cpp::span<const char> expected,
size_t expectedCopied, bool shouldReturnNull = false) {
// Making sure we don't overflow buffer.
ASSERT_GE(dst.size(), count);
diff --git a/libc/test/src/string/memcpy_test.cpp b/libc/test/src/string/memcpy_test.cpp
index 875927b15cc7e..5ccbb4dc45598 100644
--- a/libc/test/src/string/memcpy_test.cpp
+++ b/libc/test/src/string/memcpy_test.cpp
@@ -6,19 +6,19 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/CPP/ArrayRef.h"
+#include "src/__support/CPP/span.h"
#include "src/string/memcpy.h"
#include "utils/UnitTest/Test.h"
using __llvm_libc::cpp::array;
-using __llvm_libc::cpp::ArrayRef;
+using __llvm_libc::cpp::span;
using Data = array<char, 2048>;
-static const ArrayRef<char> k_numbers("0123456789", 10);
-static const ArrayRef<char> k_deadcode("DEADC0DE", 8);
+static const span<const char> k_numbers("0123456789", 10);
+static const span<const char> k_deadcode("DEADC0DE", 8);
// Returns a Data object filled with a repetition of `filler`.
-Data get_data(ArrayRef<char> filler) {
+Data get_data(span<const char> filler) {
Data out;
for (size_t i = 0; i < out.size(); ++i)
out[i] = filler[i % filler.size()];
diff --git a/libc/test/src/string/memmove_test.cpp b/libc/test/src/string/memmove_test.cpp
index 0b753cd6118cc..26b4d9e9d675d 100644
--- a/libc/test/src/string/memmove_test.cpp
+++ b/libc/test/src/string/memmove_test.cpp
@@ -6,14 +6,13 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/CPP/ArrayRef.h"
+#include "src/__support/CPP/span.h"
#include "src/string/memmove.h"
#include "utils/UnitTest/MemoryMatcher.h"
#include "utils/UnitTest/Test.h"
using __llvm_libc::cpp::array;
-using __llvm_libc::cpp::ArrayRef;
-using __llvm_libc::cpp::MutableArrayRef;
+using __llvm_libc::cpp::span;
TEST(LlvmLibcMemmoveTest, MoveZeroByte) {
char Buffer[] = {'a', 'b', 'y', 'z'};
@@ -86,7 +85,7 @@ char GetRandomChar() {
return Seed;
}
-void Randomize(MutableArrayRef<char> Buffer) {
+void Randomize(span<char> Buffer) {
for (auto ¤t : Buffer)
current = GetRandomChar();
}
diff --git a/libc/test/src/string/memory_utils/backend_test.cpp b/libc/test/src/string/memory_utils/backend_test.cpp
index 1ae33a663c1c2..72fb7c4cf53b1 100644
--- a/libc/test/src/string/memory_utils/backend_test.cpp
+++ b/libc/test/src/string/memory_utils/backend_test.cpp
@@ -6,9 +6,9 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/CPP/ArrayRef.h"
#include "src/__support/CPP/array.h"
#include "src/__support/CPP/bit.h"
+#include "src/__support/CPP/span.h"
#include "src/__support/architectures.h"
#include "src/string/memory_utils/backends.h"
#include "utils/UnitTest/Test.h"
@@ -30,7 +30,7 @@ static char GetRandomChar() {
return seed;
}
-static void Randomize(cpp::MutableArrayRef<char> buffer) {
+static void Randomize(cpp::span<char> buffer) {
for (auto ¤t : buffer)
current = GetRandomChar();
}
diff --git a/libc/test/src/string/memory_utils/elements_test.cpp b/libc/test/src/string/memory_utils/elements_test.cpp
index ef43475e5db1c..218700137c111 100644
--- a/libc/test/src/string/memory_utils/elements_test.cpp
+++ b/libc/test/src/string/memory_utils/elements_test.cpp
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/CPP/ArrayRef.h"
#include "src/__support/CPP/array.h"
+#include "src/__support/CPP/span.h"
#include "src/string/memory_utils/elements.h"
#include "utils/UnitTest/Test.h"
@@ -51,7 +51,7 @@ char GetRandomChar() {
return seed;
}
-void Randomize(cpp::MutableArrayRef<char> buffer) {
+void Randomize(cpp::span<char> buffer) {
for (auto ¤t : buffer)
current = GetRandomChar();
}
diff --git a/libc/test/src/string/memory_utils/memory_access_test.cpp b/libc/test/src/string/memory_utils/memory_access_test.cpp
index fe257bd2cbc53..b81700f0eb255 100644
--- a/libc/test/src/string/memory_utils/memory_access_test.cpp
+++ b/libc/test/src/string/memory_utils/memory_access_test.cpp
@@ -8,7 +8,6 @@
#define LLVM_LIBC_UNITTEST_OBSERVE 1
-#include "src/__support/CPP/ArrayRef.h"
#include "src/__support/CPP/array.h"
#include "src/string/memory_utils/elements.h"
#include "utils/UnitTest/Test.h"
diff --git a/libc/test/src/string/memset_test.cpp b/libc/test/src/string/memset_test.cpp
index b09a56a555c03..24c7c44a1649f 100644
--- a/libc/test/src/string/memset_test.cpp
+++ b/libc/test/src/string/memset_test.cpp
@@ -6,18 +6,18 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/CPP/ArrayRef.h"
+#include "src/__support/CPP/span.h"
#include "src/string/memset.h"
#include "utils/UnitTest/Test.h"
using __llvm_libc::cpp::array;
-using __llvm_libc::cpp::ArrayRef;
+using __llvm_libc::cpp::span;
using Data = array<char, 2048>;
-static const ArrayRef<char> k_deadcode("DEADC0DE", 8);
+static const span<const char> k_deadcode("DEADC0DE", 8);
// Returns a Data object filled with a repetition of `filler`.
-Data get_data(ArrayRef<char> filler) {
+Data get_data(span<const char> filler) {
Data out;
for (size_t i = 0; i < out.size(); ++i)
out[i] = filler[i % filler.size()];
diff --git a/libc/test/src/string/strncpy_test.cpp b/libc/test/src/string/strncpy_test.cpp
index 7bb70e9865a3e..6f08eecff8cb1 100644
--- a/libc/test/src/string/strncpy_test.cpp
+++ b/libc/test/src/string/strncpy_test.cpp
@@ -6,16 +6,16 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/CPP/ArrayRef.h"
+#include "src/__support/CPP/span.h"
#include "src/string/strncpy.h"
#include "utils/UnitTest/Test.h"
#include <stddef.h> // For size_t.
class LlvmLibcStrncpyTest : public __llvm_libc::testing::Test {
public:
- void check_strncpy(__llvm_libc::cpp::MutableArrayRef<char> dst,
- const __llvm_libc::cpp::ArrayRef<char> src, size_t n,
- const __llvm_libc::cpp::ArrayRef<char> expected) {
+ void check_strncpy(__llvm_libc::cpp::span<char> dst,
+ const __llvm_libc::cpp::span<const char> src, size_t n,
+ const __llvm_libc::cpp::span<const char> expected) {
// Making sure we don't overflow buffer.
ASSERT_GE(dst.size(), n);
// Making sure strncpy returns dst.
diff --git a/libc/utils/UnitTest/CMakeLists.txt b/libc/utils/UnitTest/CMakeLists.txt
index 34c49b9ec02a8..2f0fbd28db5e6 100644
--- a/libc/utils/UnitTest/CMakeLists.txt
+++ b/libc/utils/UnitTest/CMakeLists.txt
@@ -51,7 +51,7 @@ target_link_libraries(LibcMemoryHelpers LibcUnitTest)
add_dependencies(
LibcMemoryHelpers
LibcUnitTest
- libc.src.__support.CPP.array_ref
+ libc.src.__support.CPP.span
)
add_library(
diff --git a/libc/utils/UnitTest/MemoryMatcher.cpp b/libc/utils/UnitTest/MemoryMatcher.cpp
index 195516a7d7b29..5eab75808715d 100644
--- a/libc/utils/UnitTest/MemoryMatcher.cpp
+++ b/libc/utils/UnitTest/MemoryMatcher.cpp
@@ -12,9 +12,19 @@ namespace __llvm_libc {
namespace memory {
namespace testing {
+template <typename T>
+bool equals(const cpp::span<T> &Span1, const cpp::span<T> &Span2) {
+ if (Span1.size() != Span2.size())
+ return false;
+ for (size_t Index = 0; Index < Span1.size(); ++Index)
+ if (Span1[Index] != Span2[Index])
+ return false;
+ return true;
+}
+
bool MemoryMatcher::match(MemoryView actualValue) {
actual = actualValue;
- return expected.equals(actual);
+ return equals(expected, actual);
}
void display(testutils::StreamWrapper &Stream, char C) {
diff --git a/libc/utils/UnitTest/MemoryMatcher.h b/libc/utils/UnitTest/MemoryMatcher.h
index ea39ecb1c27aa..773a0a0a201be 100644
--- a/libc/utils/UnitTest/MemoryMatcher.h
+++ b/libc/utils/UnitTest/MemoryMatcher.h
@@ -9,7 +9,7 @@
#ifndef LLVM_LIBC_UTILS_UNITTEST_MEMORY_MATCHER_H
#define LLVM_LIBC_UTILS_UNITTEST_MEMORY_MATCHER_H
-#include "src/__support/CPP/ArrayRef.h"
+#include "src/__support/CPP/span.h"
#include "utils/UnitTest/Test.h"
@@ -17,7 +17,7 @@ namespace __llvm_libc {
namespace memory {
namespace testing {
-using MemoryView = __llvm_libc::cpp::ArrayRef<char>;
+using MemoryView = __llvm_libc::cpp::span<const char>;
class MemoryMatcher : public __llvm_libc::testing::Matcher<MemoryView> {
MemoryView expected;
More information about the libc-commits
mailing list