[libc-commits] [libc] a417ee9 - [libc] Remove use of 'assert' from the string tests
Joseph Huber via libc-commits
libc-commits at lists.llvm.org
Tue May 2 16:51:19 PDT 2023
Author: Joseph Huber
Date: 2023-05-02T18:51:10-05:00
New Revision: a417ee9ccfbc59ac8910e77d3138985240d78e28
URL: https://github.com/llvm/llvm-project/commit/a417ee9ccfbc59ac8910e77d3138985240d78e28
DIFF: https://github.com/llvm/llvm-project/commit/a417ee9ccfbc59ac8910e77d3138985240d78e28.diff
LOG: [libc] Remove use of 'assert' from the string tests
Currently we use `assert` as a stand-in for the typical test assertions.
This is because these functions exist outside of the base test class so
we can't use the typical assertion methods. The presence of these
asserts makes it difficult to compile these tests in a standalone
format. This patch removes all occurrences.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D149656
Added:
Modified:
libc/test/src/string/bzero_test.cpp
libc/test/src/string/memory_utils/memory_check_utils.h
libc/test/src/string/memory_utils/op_tests.cpp
Removed:
################################################################################
diff --git a/libc/test/src/string/bzero_test.cpp b/libc/test/src/string/bzero_test.cpp
index a476c43bdf6e6..e809506386132 100644
--- a/libc/test/src/string/bzero_test.cpp
+++ b/libc/test/src/string/bzero_test.cpp
@@ -15,7 +15,6 @@ namespace __llvm_libc {
// Adapt CheckMemset signature to op implementation signatures.
template <auto FnImpl>
void BzeroAdaptor(cpp::span<char> p1, uint8_t value, size_t size) {
- assert(value == 0);
FnImpl(p1.begin(), size);
}
diff --git a/libc/test/src/string/memory_utils/memory_check_utils.h b/libc/test/src/string/memory_utils/memory_check_utils.h
index 46c362d6b3701..c2b910edd952a 100644
--- a/libc/test/src/string/memory_utils/memory_check_utils.h
+++ b/libc/test/src/string/memory_utils/memory_check_utils.h
@@ -12,7 +12,6 @@
#include "src/__support/CPP/span.h"
#include "src/__support/macros/sanitizer.h"
#include "src/string/memory_utils/utils.h"
-#include <assert.h> // assert
#include <stddef.h> // size_t
#include <stdint.h> // uintxx_t
#include <stdlib.h> // malloc/free
@@ -24,7 +23,6 @@ namespace __llvm_libc {
// This is a utility class to be used by Buffer below, do not use directly.
struct PoisonedBuffer {
PoisonedBuffer(size_t size) : ptr((char *)malloc(size)) {
- assert(ptr);
ASAN_POISON_MEMORY_REGION(ptr, size);
}
~PoisonedBuffer() { free(ptr); }
@@ -45,11 +43,8 @@ struct Buffer : private PoisonedBuffer {
: PoisonedBuffer(size + kLeeway), size(size) {
offset_ptr = ptr;
offset_ptr += distance_to_next_aligned<kAlign>(ptr);
- assert((uintptr_t)(offset_ptr) % kAlign == 0);
if (aligned == Aligned::NO)
++offset_ptr;
- assert(offset_ptr > ptr);
- assert((offset_ptr + size) < (ptr + size + kLeeway));
ASAN_UNPOISON_MEMORY_REGION(offset_ptr, size);
}
cpp::span<char> span() { return cpp::span<char>(offset_ptr, size); }
@@ -77,7 +72,6 @@ static inline void Randomize(cpp::span<char> buffer) {
// Copy one span to another.
static inline void ReferenceCopy(cpp::span<char> dst,
const cpp::span<char> src) {
- assert(dst.size() == src.size());
for (size_t i = 0; i < dst.size(); ++i)
dst[i] = src[i];
}
@@ -85,8 +79,6 @@ static inline void ReferenceCopy(cpp::span<char> dst,
// Checks that FnImpl implements the memcpy semantic.
template <auto FnImpl>
bool CheckMemcpy(cpp::span<char> dst, cpp::span<char> src, size_t size) {
- assert(dst.size() == src.size());
- assert(dst.size() == size);
Randomize(dst);
FnImpl(dst, src, size);
for (size_t i = 0; i < size; ++i)
@@ -109,7 +101,6 @@ bool CheckMemset(cpp::span<char> dst, uint8_t value, size_t size) {
// Checks that FnImpl implements the bcmp semantic.
template <auto FnImpl>
bool CheckBcmp(cpp::span<char> span1, cpp::span<char> span2, size_t size) {
- assert(span1.size() == span2.size());
ReferenceCopy(span2, span1);
// Compare equal
if (int cmp = FnImpl(span1, span2, size); cmp != 0)
@@ -129,7 +120,6 @@ bool CheckBcmp(cpp::span<char> span1, cpp::span<char> span2, size_t size) {
// Checks that FnImpl implements the memcmp semantic.
template <auto FnImpl>
bool CheckMemcmp(cpp::span<char> span1, cpp::span<char> span2, size_t size) {
- assert(span1.size() == span2.size());
ReferenceCopy(span2, span1);
// Compare equal
if (int cmp = FnImpl(span1, span2, size); cmp != 0)
diff --git a/libc/test/src/string/memory_utils/op_tests.cpp b/libc/test/src/string/memory_utils/op_tests.cpp
index f845f49a01d90..e38edc54e8a9f 100644
--- a/libc/test/src/string/memory_utils/op_tests.cpp
+++ b/libc/test/src/string/memory_utils/op_tests.cpp
@@ -13,8 +13,6 @@
#include "src/string/memory_utils/op_x86.h"
#include "test/UnitTest/Test.h"
-#include <assert.h>
-
#if defined(LIBC_TARGET_ARCH_IS_X86_64) || defined(LIBC_TARGET_ARCH_IS_AARCH64)
#define LLVM_LIBC_HAS_UINT64
#endif
@@ -75,7 +73,6 @@ void CopyAdaptor(cpp::span<char> dst, cpp::span<char> src, size_t size) {
}
template <size_t Size, auto FnImpl>
void CopyBlockAdaptor(cpp::span<char> dst, cpp::span<char> src, size_t size) {
- assert(size == Size);
FnImpl(as_byte(dst), as_byte(src));
}
@@ -157,7 +154,6 @@ void SetAdaptor(cpp::span<char> dst, uint8_t value, size_t size) {
}
template <size_t Size, auto FnImpl>
void SetBlockAdaptor(cpp::span<char> dst, uint8_t value, size_t size) {
- assert(size == Size);
FnImpl(as_byte(dst), value);
}
@@ -235,7 +231,6 @@ int CmpAdaptor(cpp::span<char> p1, cpp::span<char> p2, size_t size) {
}
template <size_t Size, auto FnImpl>
int CmpBlockAdaptor(cpp::span<char> p1, cpp::span<char> p2, size_t size) {
- assert(size == Size);
return (int)FnImpl(as_byte(p1), as_byte(p2));
}
More information about the libc-commits
mailing list