-
Notifications
You must be signed in to change notification settings - Fork 10.8k
/
bcmp_test.cpp
58 lines (49 loc) · 1.72 KB
/
bcmp_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//===-- Unittests for bcmp ------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "memory_utils/memory_check_utils.h"
#include "src/string/bcmp.h"
#include "utils/UnitTest/Test.h"
namespace __llvm_libc {
TEST(LlvmLibcBcmpTest, CmpZeroByte) {
const char *lhs = "ab";
const char *rhs = "bc";
ASSERT_EQ(__llvm_libc::bcmp(lhs, rhs, 0), 0);
}
TEST(LlvmLibcBcmpTest, LhsRhsAreTheSame) {
const char *lhs = "ab";
const char *rhs = "ab";
ASSERT_EQ(__llvm_libc::bcmp(lhs, rhs, 2), 0);
}
TEST(LlvmLibcBcmpTest, LhsBeforeRhsLexically) {
const char *lhs = "ab";
const char *rhs = "ac";
ASSERT_NE(__llvm_libc::bcmp(lhs, rhs, 2), 0);
}
TEST(LlvmLibcBcmpTest, LhsAfterRhsLexically) {
const char *lhs = "ac";
const char *rhs = "ab";
ASSERT_NE(__llvm_libc::bcmp(lhs, rhs, 2), 0);
}
// Adapt CheckBcmp signature to op implementation signatures.
template <auto FnImpl>
int CmpAdaptor(cpp::span<char> p1, cpp::span<char> p2, size_t size) {
return FnImpl(p1.begin(), p2.begin(), size);
}
TEST(LlvmLibcBcmpTest, SizeSweep) {
static constexpr size_t kMaxSize = 1024;
static constexpr auto Impl = CmpAdaptor<__llvm_libc::bcmp>;
Buffer Buffer1(kMaxSize);
Buffer Buffer2(kMaxSize);
Randomize(Buffer1.span());
for (size_t size = 0; size < kMaxSize; ++size) {
auto span1 = Buffer1.span().subspan(0, size);
auto span2 = Buffer2.span().subspan(0, size);
ASSERT_TRUE((CheckBcmp<Impl>(span1, span2, size)));
}
}
} // namespace __llvm_libc