mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-09-29 19:24:25 +03:00
Merge branch 'develop' into wip-cppcheck271-part2
This commit is contained in:
@@ -62,7 +62,7 @@ u32 our_clzll(u64a x) {
|
||||
TEST(BitUtils, findAndClearLSB32_1) {
|
||||
// test that it can find every single-bit case
|
||||
for (unsigned int i = 0; i < 32; i++) {
|
||||
u32 input = 1 << i;
|
||||
u32 input = 1U << i;
|
||||
u32 idx = findAndClearLSB_32(&input);
|
||||
EXPECT_EQ(i, idx);
|
||||
EXPECT_EQ(0U, input);
|
||||
@@ -112,7 +112,7 @@ TEST(BitUtils, findAndClearLSB64_2) {
|
||||
TEST(BitUtils, findAndClearMSB32_1) {
|
||||
// test that it can find every single-bit case
|
||||
for (unsigned int i = 0; i < 32; i++) {
|
||||
u32 input = 1 << i;
|
||||
u32 input = 1U << i;
|
||||
u32 idx = findAndClearMSB_32(&input);
|
||||
EXPECT_EQ(i, idx);
|
||||
EXPECT_EQ(0U, input);
|
||||
|
@@ -61,10 +61,10 @@ using namespace ue2;
|
||||
#define CHECK_WITH_TEDDY_OK_TO_FAIL(fdr, hint) \
|
||||
{ \
|
||||
auto descr = getTeddyDescription(hint); \
|
||||
if (descr && fdr == nullptr) { \
|
||||
if (descr && fdr.get() == nullptr) { \
|
||||
return; /* cannot build Teddy for this set of literals */ \
|
||||
} else { \
|
||||
ASSERT_TRUE(fdr != nullptr); \
|
||||
ASSERT_TRUE(fdr.get() != nullptr); \
|
||||
} \
|
||||
}
|
||||
#endif
|
||||
@@ -145,7 +145,7 @@ bytecode_ptr<FDR> buildFDREngineHinted(std::vector<hwlmLiteral> &lits,
|
||||
auto proto = fdrBuildProtoHinted(HWLM_ENGINE_FDR, lits, make_small, hint,
|
||||
target, grey);
|
||||
if (!proto) {
|
||||
return nullptr;
|
||||
return ue2::bytecode_ptr<FDR>(nullptr);
|
||||
}
|
||||
return fdrBuildTable(*proto, grey);
|
||||
}
|
||||
@@ -156,7 +156,7 @@ bytecode_ptr<FDR> buildFDREngine(std::vector<hwlmLiteral> &lits,
|
||||
const Grey &grey) {
|
||||
auto proto = fdrBuildProto(HWLM_ENGINE_FDR, lits, make_small, target, grey);
|
||||
if (!proto) {
|
||||
return nullptr;
|
||||
return bytecode_ptr<FDR>(nullptr);
|
||||
}
|
||||
return fdrBuildTable(*proto, grey);
|
||||
}
|
||||
@@ -421,7 +421,7 @@ TEST_P(FDRp, moveByteStream) {
|
||||
size_t size = fdrSize(fdrTable0.get());
|
||||
|
||||
auto fdrTable = make_bytecode_ptr<FDR>(size, 64);
|
||||
EXPECT_NE(nullptr, fdrTable);
|
||||
EXPECT_NE(nullptr, fdrTable.get());
|
||||
|
||||
memcpy(fdrTable.get(), fdrTable0.get(), size);
|
||||
|
||||
@@ -706,7 +706,7 @@ TEST(FDR, FDRTermS) {
|
||||
lits.push_back(hwlmLiteral("ff", 0, 1));
|
||||
|
||||
auto fdr = buildFDREngine(lits, false, get_current_target(), Grey());
|
||||
ASSERT_TRUE(fdr != nullptr);
|
||||
ASSERT_TRUE(fdr.get() != nullptr);
|
||||
|
||||
// check matches
|
||||
|
||||
@@ -729,7 +729,7 @@ TEST(FDR, FDRTermB) {
|
||||
lits.push_back(hwlmLiteral("ff", 0, 1));
|
||||
|
||||
auto fdr = buildFDREngine(lits, false, get_current_target(), Grey());
|
||||
ASSERT_TRUE(fdr != nullptr);
|
||||
ASSERT_TRUE(fdr.get() != nullptr);
|
||||
|
||||
// check matches
|
||||
struct hs_scratch scratch;
|
||||
|
@@ -55,10 +55,10 @@ using namespace ue2;
|
||||
#define CHECK_WITH_TEDDY_OK_TO_FAIL(fdr, hint) \
|
||||
{ \
|
||||
auto descr = getTeddyDescription(hint); \
|
||||
if (descr && fdr != nullptr) { \
|
||||
if (descr && fdr.get() != nullptr) { \
|
||||
return; \
|
||||
} else { \
|
||||
ASSERT_TRUE(fdr != nullptr); \
|
||||
ASSERT_TRUE(fdr.get() != nullptr); \
|
||||
} \
|
||||
}
|
||||
#endif
|
||||
@@ -154,7 +154,7 @@ TEST_P(FDRFloodp, NoMask) {
|
||||
|
||||
struct hs_scratch scratch;
|
||||
scratch.fdr_conf = NULL;
|
||||
while (1) {
|
||||
while (c != 255) {
|
||||
SCOPED_TRACE((unsigned int)c);
|
||||
u8 bit = 1 << (c & 0x7);
|
||||
u8 cAlt = c ^ bit;
|
||||
@@ -233,9 +233,7 @@ TEST_P(FDRFloodp, NoMask) {
|
||||
}
|
||||
matchesCounts.clear();
|
||||
|
||||
if (++c == 0) {
|
||||
break;
|
||||
}
|
||||
++c;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,7 +246,7 @@ TEST_P(FDRFloodp, WithMask) {
|
||||
|
||||
struct hs_scratch scratch;
|
||||
scratch.fdr_conf = NULL;
|
||||
while (1) {
|
||||
while (c != 255) {
|
||||
u8 bit = 1 << (c & 0x7);
|
||||
u8 cAlt = c ^ bit;
|
||||
SCOPED_TRACE((unsigned int)c);
|
||||
@@ -396,9 +394,7 @@ TEST_P(FDRFloodp, WithMask) {
|
||||
}
|
||||
matchesCounts.clear();
|
||||
|
||||
if (++c == '\0') {
|
||||
break;
|
||||
}
|
||||
++c;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -414,7 +410,7 @@ TEST_P(FDRFloodp, StreamingMask) {
|
||||
|
||||
struct hs_scratch scratch;
|
||||
scratch.fdr_conf = NULL;
|
||||
while (1) {
|
||||
while (c != 255) {
|
||||
u8 bit = 1 << (c & 0x7);
|
||||
u8 cAlt = c ^ bit;
|
||||
SCOPED_TRACE((unsigned int)c);
|
||||
@@ -488,7 +484,6 @@ TEST_P(FDRFloodp, StreamingMask) {
|
||||
Grey());
|
||||
CHECK_WITH_TEDDY_OK_TO_FAIL(fdr, hint);
|
||||
|
||||
hwlm_error_t fdrStatus;
|
||||
const u32 cnt4 = dataSize - 4 + 1;
|
||||
|
||||
for (u32 streamChunk = 1; streamChunk <= 16; streamChunk *= 2) {
|
||||
@@ -496,7 +491,7 @@ TEST_P(FDRFloodp, StreamingMask) {
|
||||
const u8 *d = data.data();
|
||||
// reference past the end of fake history to allow headroom
|
||||
const u8 *fhist = fake_history.data() + fake_history_size;
|
||||
fdrStatus = fdrExecStreaming(fdr.get(), fhist, 0, d, streamChunk, 0,
|
||||
hwlm_error_t fdrStatus = fdrExecStreaming(fdr.get(), fhist, 0, d, streamChunk, 0,
|
||||
countCallback, &scratch,
|
||||
HWLM_ALL_GROUPS);
|
||||
ASSERT_EQ(0, fdrStatus);
|
||||
@@ -549,9 +544,7 @@ TEST_P(FDRFloodp, StreamingMask) {
|
||||
}
|
||||
}
|
||||
|
||||
if (++c == '\0') {
|
||||
break;
|
||||
}
|
||||
++c;
|
||||
}
|
||||
matchesCounts.clear();
|
||||
}
|
||||
|
@@ -48,9 +48,7 @@ std::ostream &operator<<(std::ostream &os, const flat_set<T> &f) {
|
||||
os << "{";
|
||||
for (auto it = begin(f); it != end(f); ++it) {
|
||||
os << *it;
|
||||
if (it != end(f)) {
|
||||
os << ", ";
|
||||
}
|
||||
os << ", ";
|
||||
}
|
||||
os << "}";
|
||||
return os;
|
||||
|
@@ -149,9 +149,7 @@ std::ostream &operator<<(std::ostream &os, const insertion_ordered_set<K> &s) {
|
||||
os << "{";
|
||||
for (auto it = begin(s); it != end(s); ++it) {
|
||||
os << *it;
|
||||
if (it != end(s)) {
|
||||
os << ", ";
|
||||
}
|
||||
os << ", ";
|
||||
}
|
||||
os << "}";
|
||||
return os;
|
||||
|
@@ -98,7 +98,7 @@ protected:
|
||||
ParsedExpression parsed(0, pattern.c_str(), flags, 0);
|
||||
auto built_expr = buildGraph(rm, cc, parsed);
|
||||
const auto &g = built_expr.g;
|
||||
ASSERT_TRUE(g != nullptr);
|
||||
ASSERT_TRUE(static_cast<bool>(g));
|
||||
clearReports(*g);
|
||||
|
||||
rm.setProgramOffset(0, MATCH_REPORT);
|
||||
@@ -106,7 +106,7 @@ protected:
|
||||
/* LBR triggered by dot */
|
||||
vector<vector<CharReach>> triggers = {{CharReach::dot()}};
|
||||
nfa = constructLBR(*g, triggers, cc, rm);
|
||||
ASSERT_TRUE(nfa != nullptr);
|
||||
ASSERT_TRUE(static_cast<bool>(nfa));
|
||||
|
||||
full_state = make_bytecode_ptr<char>(nfa->scratchStateSize, 64);
|
||||
stream_state = make_bytecode_ptr<char>(nfa->streamStateSize);
|
||||
|
@@ -87,7 +87,7 @@ protected:
|
||||
|
||||
nfa = constructNFA(*g, &rm, fixed_depth_tops, triggers, compress_state,
|
||||
fast_nfa, type, cc);
|
||||
ASSERT_TRUE(nfa != nullptr);
|
||||
ASSERT_TRUE(nfa.get() != nullptr);
|
||||
|
||||
full_state = make_bytecode_ptr<char>(nfa->scratchStateSize, 64);
|
||||
stream_state = make_bytecode_ptr<char>(nfa->streamStateSize);
|
||||
@@ -134,7 +134,7 @@ INSTANTIATE_TEST_CASE_P(
|
||||
Range((int)LIMEX_NFA_32, (int)LIMEX_NFA_512));
|
||||
|
||||
TEST_P(LimExModelTest, StateSize) {
|
||||
ASSERT_TRUE(nfa != nullptr);
|
||||
ASSERT_TRUE(nfa.get() != nullptr);
|
||||
|
||||
hs_platform_info plat;
|
||||
hs_error_t err = hs_populate_platform(&plat);
|
||||
@@ -150,7 +150,7 @@ TEST_P(LimExModelTest, StateSize) {
|
||||
}
|
||||
|
||||
TEST_P(LimExModelTest, QueueExec) {
|
||||
ASSERT_TRUE(nfa != nullptr);
|
||||
ASSERT_TRUE(nfa.get() != nullptr);
|
||||
initQueue();
|
||||
nfaQueueInitState(nfa.get(), &q);
|
||||
|
||||
@@ -165,7 +165,7 @@ TEST_P(LimExModelTest, QueueExec) {
|
||||
}
|
||||
|
||||
TEST_P(LimExModelTest, CompressExpand) {
|
||||
ASSERT_TRUE(nfa != nullptr);
|
||||
ASSERT_TRUE(nfa.get() != nullptr);
|
||||
|
||||
u32 real_state_size = nfa->scratchStateSize;
|
||||
/* Only look at 8 bytes for limex 64 (rather than the padding) */
|
||||
@@ -197,7 +197,7 @@ TEST_P(LimExModelTest, CompressExpand) {
|
||||
}
|
||||
|
||||
TEST_P(LimExModelTest, InitCompressedState0) {
|
||||
ASSERT_TRUE(nfa != nullptr);
|
||||
ASSERT_TRUE(nfa.get() != nullptr);
|
||||
|
||||
// 64-bit NFAs assume during compression that they have >= 5 bytes of
|
||||
// compressed NFA state, which isn't true for our 8-state test pattern. We
|
||||
@@ -212,7 +212,7 @@ TEST_P(LimExModelTest, InitCompressedState0) {
|
||||
}
|
||||
|
||||
TEST_P(LimExModelTest, QueueExecToMatch) {
|
||||
ASSERT_TRUE(nfa != nullptr);
|
||||
ASSERT_TRUE(nfa.get() != nullptr);
|
||||
initQueue();
|
||||
nfaQueueInitState(nfa.get(), &q);
|
||||
|
||||
@@ -256,7 +256,7 @@ TEST_P(LimExModelTest, QueueExecToMatch) {
|
||||
}
|
||||
|
||||
TEST_P(LimExModelTest, QueueExecRose) {
|
||||
ASSERT_TRUE(nfa != nullptr);
|
||||
ASSERT_TRUE(nfa.get() != nullptr);
|
||||
initQueue();
|
||||
|
||||
// For rose, there's no callback or context.
|
||||
@@ -277,7 +277,7 @@ TEST_P(LimExModelTest, QueueExecRose) {
|
||||
}
|
||||
|
||||
TEST_P(LimExModelTest, CheckFinalState) {
|
||||
ASSERT_TRUE(nfa != nullptr);
|
||||
ASSERT_TRUE(nfa.get() != nullptr);
|
||||
initQueue();
|
||||
nfaQueueInitState(nfa.get(), &q);
|
||||
|
||||
@@ -321,7 +321,7 @@ protected:
|
||||
}
|
||||
|
||||
nfa = constructReversedNFA(g_rev, type, cc);
|
||||
ASSERT_TRUE(nfa != nullptr);
|
||||
ASSERT_TRUE(nfa.get() != nullptr);
|
||||
}
|
||||
|
||||
// NFA type (enum NFAEngineType)
|
||||
@@ -338,7 +338,7 @@ INSTANTIATE_TEST_CASE_P(LimExReverse, LimExReverseTest,
|
||||
Range((int)LIMEX_NFA_32, (int)LIMEX_NFA_512));
|
||||
|
||||
TEST_P(LimExReverseTest, BlockExecReverse) {
|
||||
ASSERT_TRUE(nfa != nullptr);
|
||||
ASSERT_TRUE(nfa.get() != nullptr);
|
||||
|
||||
u64a offset = 0;
|
||||
const u8 *buf = (const u8 *)SCAN_DATA.c_str();
|
||||
@@ -381,7 +381,7 @@ protected:
|
||||
|
||||
nfa = constructNFA(*g, &rm, fixed_depth_tops, triggers, compress_state,
|
||||
fast_nfa, type, cc);
|
||||
ASSERT_TRUE(nfa != nullptr);
|
||||
ASSERT_TRUE(nfa.get() != nullptr);
|
||||
|
||||
full_state = make_bytecode_ptr<char>(nfa->scratchStateSize, 64);
|
||||
stream_state = make_bytecode_ptr<char>(nfa->streamStateSize);
|
||||
@@ -427,7 +427,7 @@ INSTANTIATE_TEST_CASE_P(LimExZombie, LimExZombieTest,
|
||||
Range((int)LIMEX_NFA_32, (int)LIMEX_NFA_512));
|
||||
|
||||
TEST_P(LimExZombieTest, GetZombieStatus) {
|
||||
ASSERT_TRUE(nfa != nullptr);
|
||||
ASSERT_TRUE(nfa.get() != nullptr);
|
||||
ASSERT_TRUE(nfa->flags & NFA_ZOMBIE);
|
||||
|
||||
initQueue();
|
||||
|
@@ -46,7 +46,7 @@ UNUSED
|
||||
static
|
||||
void mmbit_display(const u8 *bits, u32 total_bits) {
|
||||
for (u32 i = 0; i < mmbit_size(total_bits); i += 8) {
|
||||
printf("block %d:", i / 8);
|
||||
printf("block %u:", i / 8);
|
||||
for (s32 j = 7; j >= 0; j--) {
|
||||
u8 a = (*(bits + i + j));
|
||||
printf(" %02x", a);
|
||||
@@ -72,7 +72,7 @@ UNUSED
|
||||
static
|
||||
void mmbit_display_comp(const u8 *bits, u32 comp_size) {
|
||||
for (u32 i = 0; i < comp_size; i += 8) {
|
||||
printf("block %d:", i / 8);
|
||||
printf("block %u:", i / 8);
|
||||
for (s32 j = 7; j >= 0; j--) {
|
||||
u8 a = (*(bits + i + j));
|
||||
printf(" %02x", a);
|
||||
@@ -401,7 +401,6 @@ TEST_P(MultiBitCompTest, CompCompressDecompressDense) {
|
||||
|
||||
TEST(MultiBitComp, CompIntegration1) {
|
||||
// 256 + 1 --> smallest 2-level mmbit
|
||||
u32 total_size = mmbit_size(257);
|
||||
mmbit_holder ba(257);
|
||||
|
||||
//-------------------- 1 -----------------------//
|
||||
@@ -516,7 +515,6 @@ TEST(MultiBitComp, CompIntegration1) {
|
||||
|
||||
TEST(MultiBitComp, CompIntegration2) {
|
||||
// 64^2 + 1 --> smallest 3-level mmbit
|
||||
u32 total_size = mmbit_size(4097);
|
||||
mmbit_holder ba(4097);
|
||||
|
||||
//-------------------- 1 -----------------------//
|
||||
@@ -645,7 +643,6 @@ TEST(MultiBitComp, CompIntegration2) {
|
||||
|
||||
TEST(MultiBitComp, CompIntegration3) {
|
||||
// 64^3 + 1 --> smallest 4-level mmbit
|
||||
u32 total_size = mmbit_size(262145);
|
||||
mmbit_holder ba(262145);
|
||||
|
||||
//-------------------- 1 -----------------------//
|
||||
|
@@ -41,7 +41,7 @@ namespace ue2 {
|
||||
// Helper function: construct a graph from an expression, flags and context.
|
||||
inline
|
||||
std::unique_ptr<NGHolder> constructGraphWithCC(const std::string &expr,
|
||||
CompileContext &cc,
|
||||
const CompileContext &cc,
|
||||
unsigned flags) {
|
||||
ReportManager rm(cc.grey);
|
||||
ParsedExpression parsed(0, expr.c_str(), flags, 0);
|
||||
|
@@ -70,7 +70,7 @@ void noodleMatch(const u8 *data, size_t data_len, const char *lit_str,
|
||||
u32 id = 1000;
|
||||
hwlmLiteral lit(std::string(lit_str, lit_len), nocase, id);
|
||||
auto n = noodBuildTable(lit);
|
||||
ASSERT_TRUE(n != nullptr);
|
||||
ASSERT_TRUE(static_cast<bool>(n));
|
||||
|
||||
hwlm_error_t rv;
|
||||
struct hs_scratch scratch;
|
||||
|
@@ -245,7 +245,7 @@ TEST(pqueue, queue1) {
|
||||
u32 in[] = {1, 2, 3, 4, 5, 6, 7, 8};
|
||||
u32 expected[] = {4, 5, 6, 7, 8, 3, 2, 1};
|
||||
u32 temp[ARRAY_LENGTH(in)];
|
||||
u32 output[ARRAY_LENGTH(in)];
|
||||
u32 output[ARRAY_LENGTH(in)] = {0};
|
||||
|
||||
u32 queue_size = 0;
|
||||
u32 i = 0, o = 0;
|
||||
@@ -275,7 +275,7 @@ TEST(pqueue, queue2) {
|
||||
u32 in[] = {8, 7, 6, 5, 4, 3, 2, 1};
|
||||
u32 expected[] = {8, 7, 6, 5, 4, 3, 2, 1};
|
||||
u32 temp[ARRAY_LENGTH(in)];
|
||||
u32 output[ARRAY_LENGTH(in)];
|
||||
u32 output[ARRAY_LENGTH(in)] = {0};
|
||||
|
||||
u32 queue_size = 0;
|
||||
u32 i = 0, o = 0;
|
||||
@@ -301,7 +301,7 @@ TEST(pqueue, queue3) {
|
||||
u32 in[] = {1, 8, 2, 7, 3, 6, 4, 5};
|
||||
u32 expected[] = {8, 7, 6, 4, 5, 3, 2, 1};
|
||||
u32 temp[ARRAY_LENGTH(in)];
|
||||
u32 output[ARRAY_LENGTH(in)];
|
||||
u32 output[ARRAY_LENGTH(in)] = {0};
|
||||
|
||||
u32 queue_size = 0;
|
||||
u32 i = 0, o = 0;
|
||||
|
@@ -277,10 +277,9 @@ TEST_P(RepeatTest, FillRing) {
|
||||
}
|
||||
|
||||
// We should be able to see matches for all of these (beyond the last top offset).
|
||||
enum TriggerResult rv;
|
||||
for (u64a i = offset + info.repeatMax;
|
||||
i <= offset + info.repeatMax + info.repeatMin; i++) {
|
||||
rv = processTugTrigger(&info, ctrl, state, i);
|
||||
enum TriggerResult rv = processTugTrigger(&info, ctrl, state, i);
|
||||
if (rv == TRIGGER_SUCCESS_CACHE) {
|
||||
rv = TRIGGER_SUCCESS;
|
||||
}
|
||||
@@ -998,16 +997,14 @@ TEST_P(SparseOptimalTest, FillTops) {
|
||||
repeatStore(info, ctrl, state, offset, 0);
|
||||
ASSERT_EQ(offset, repeatLastTop(info, ctrl, state));
|
||||
|
||||
u64a offset2;
|
||||
for (u32 i = min_period; i < patch_count * patch_size; i += min_period) {
|
||||
offset2 = offset + i;
|
||||
u64a offset2 = offset + i;
|
||||
repeatStore(info, ctrl, state, offset2, 1);
|
||||
ASSERT_EQ(offset2, repeatLastTop(info, ctrl, state));
|
||||
}
|
||||
|
||||
u64a exit2;
|
||||
for (u32 i = 0; i < patch_count * patch_size; i += min_period) {
|
||||
exit2 = exit + i;
|
||||
u64a exit2 = exit + i;
|
||||
for (u32 j = exit2 + info->repeatMin;
|
||||
j <= offset + info->repeatMax; j++) {
|
||||
ASSERT_EQ(REPEAT_MATCH, repeatHasMatch(info, ctrl, state, j));
|
||||
|
@@ -87,12 +87,11 @@ static int initLegalValidMasks(u64a validMasks[]) {
|
||||
*/
|
||||
static int initLegalNegMasks(u64a negMasks[]) {
|
||||
u64a data = 0;
|
||||
u64a offset;
|
||||
int num = 0;
|
||||
while (data != ONES64) {
|
||||
negMasks[num] = data;
|
||||
num++;
|
||||
offset = (data | (data +1)) ^ data;
|
||||
u64a offset = (data | (data +1)) ^ data;
|
||||
data += 0xfeULL * offset + 1;
|
||||
}
|
||||
negMasks[num] = data;
|
||||
|
@@ -194,10 +194,9 @@ TEST(ValidateMask32, testMask32_3) {
|
||||
u32 valid_mask = ONES32 << (left + right) >> left;
|
||||
for (int i = 0; i < test_len; i++) {
|
||||
const auto &t = testBasic[i];
|
||||
int bool_result;
|
||||
for (int j = 0; j < 5000; j++) {
|
||||
u32 neg_mask = neg_mask_rand.Generate(1u << 31);
|
||||
bool_result = (neg_mask & valid_mask) ==
|
||||
int bool_result = (neg_mask & valid_mask) ==
|
||||
(t.neg_mask & valid_mask);
|
||||
EXPECT_EQ(bool_result, validateMask32(t.data.a256,
|
||||
valid_mask,
|
||||
|
709
unit/internal/sheng.cpp
Normal file
709
unit/internal/sheng.cpp
Normal file
@@ -0,0 +1,709 @@
|
||||
/*
|
||||
* Copyright (c) 2024, Arm ltd
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "nfa/shengcompile.h"
|
||||
#include "nfa/rdfa.h"
|
||||
#include "util/bytecode_ptr.h"
|
||||
#include "util/compile_context.h"
|
||||
#include "util/report_manager.h"
|
||||
|
||||
extern "C" {
|
||||
#include "hs_compile.h"
|
||||
#include "nfa/nfa_api.h"
|
||||
#include "nfa/nfa_api_queue.h"
|
||||
#include "nfa/nfa_api_util.h"
|
||||
#include "nfa/nfa_internal.h"
|
||||
#include "nfa/rdfa.h"
|
||||
#include "nfa/sheng.h"
|
||||
#include "ue2common.h"
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
struct callback_context {
|
||||
unsigned int period;
|
||||
unsigned int match_count;
|
||||
unsigned int pattern_length;
|
||||
};
|
||||
|
||||
int dummy_callback(u64a start, u64a end, ReportID id, void *context) {
|
||||
(void) context;
|
||||
printf("callback %llu %llu %u\n", start, end, id);
|
||||
return 1; /* 0 stops matching, !0 continue */
|
||||
}
|
||||
|
||||
int periodic_pattern_callback(u64a start, u64a end, ReportID id, void *raw_context) {
|
||||
struct callback_context *context = (struct callback_context*) raw_context;
|
||||
(void) start;
|
||||
(void) id;
|
||||
EXPECT_EQ(context->period * context->match_count, end - context->pattern_length);
|
||||
context->match_count++;
|
||||
return 1; /* 0 stops matching, !0 continue */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Fill the state matrix with a diagonal pattern: accept the Nth character to go to the N+1 state
|
||||
*/
|
||||
static void fill_straight_regex_sequence(struct ue2::raw_dfa *dfa, int start_state, int end_state, int state_count)
|
||||
{
|
||||
for (int state = start_state; state < end_state; state++) {
|
||||
dfa->states[state].next.assign(state_count ,1);
|
||||
dfa->states[state].next[0] = 2;
|
||||
dfa->states[state].next[1] = 2;
|
||||
dfa->states[state].next[state] = state+1;
|
||||
}
|
||||
}
|
||||
|
||||
static void init_raw_dfa16(struct ue2::raw_dfa *dfa, const ReportID rID)
|
||||
{
|
||||
dfa->start_anchored = 1;
|
||||
dfa->start_floating = 1;
|
||||
dfa->alpha_size = 8;
|
||||
|
||||
int nb_state = 8;
|
||||
for(int i = 0; i < nb_state; i++) {
|
||||
struct ue2::dstate state(dfa->alpha_size);
|
||||
state.next = std::vector<ue2::dstate_id_t>(nb_state);
|
||||
state.daddy = 0;
|
||||
state.impl_id = i; /* id of the state */
|
||||
state.reports = ue2::flat_set<ReportID>();
|
||||
state.reports_eod = ue2::flat_set<ReportID>();
|
||||
dfa->states.push_back(state);
|
||||
}
|
||||
|
||||
/* add a report to every accept state */
|
||||
dfa->states[7].reports.insert(rID);
|
||||
|
||||
/**
|
||||
* [a,b][c-e]{3}of
|
||||
* (1) -a,b-> (2) -c,d,e-> (3) -c,d,e-> (4) -c,d,e-> (5) -o-> (6) -f-> ((7))
|
||||
* (0) = dead
|
||||
*/
|
||||
|
||||
for(int i = 0; i < ue2::ALPHABET_SIZE; i++) {
|
||||
dfa->alpha_remap[i] = 0;
|
||||
}
|
||||
|
||||
dfa->alpha_remap['a'] = 0;
|
||||
dfa->alpha_remap['b'] = 1;
|
||||
dfa->alpha_remap['c'] = 2;
|
||||
dfa->alpha_remap['d'] = 3;
|
||||
dfa->alpha_remap['e'] = 4;
|
||||
dfa->alpha_remap['o'] = 5;
|
||||
dfa->alpha_remap['f'] = 6;
|
||||
dfa->alpha_remap[256] = 7; /* for some reason there's a check that run on dfa->alpha_size-1 */
|
||||
|
||||
/* a b c d e o f */
|
||||
dfa->states[0].next = {0,0,0,0,0,0,0};
|
||||
dfa->states[1].next = {2,2,1,1,1,1,1}; /* nothing */
|
||||
dfa->states[2].next = {2,2,3,3,3,1,1}; /* [a,b] */
|
||||
dfa->states[3].next = {2,2,4,4,4,1,1}; /* [a,b][c-e]{1} */
|
||||
dfa->states[4].next = {2,2,5,5,5,1,1}; /* [a,b][c-e]{2} */
|
||||
fill_straight_regex_sequence(dfa, 5, 7, 7); /* [a,b][c-e]{3}o */
|
||||
dfa->states[7].next = {2,2,1,1,1,1,1}; /* [a,b][c-e]{3}of */
|
||||
}
|
||||
|
||||
#if defined(HAVE_AVX512VBMI) || defined(HAVE_SVE)
|
||||
/* We need more than 16 states to run sheng32, so make the graph longer */
|
||||
static void init_raw_dfa32(struct ue2::raw_dfa *dfa, const ReportID rID)
|
||||
{
|
||||
dfa->start_anchored = 1;
|
||||
dfa->start_floating = 1;
|
||||
dfa->alpha_size = 18;
|
||||
|
||||
int nb_state = 18;
|
||||
for(int i = 0; i < nb_state; i++) {
|
||||
struct ue2::dstate state(dfa->alpha_size);
|
||||
state.next = std::vector<ue2::dstate_id_t>(nb_state);
|
||||
state.daddy = 0;
|
||||
state.impl_id = i; /* id of the state */
|
||||
state.reports = ue2::flat_set<ReportID>();
|
||||
state.reports_eod = ue2::flat_set<ReportID>();
|
||||
dfa->states.push_back(state);
|
||||
}
|
||||
|
||||
/* add a report to every accept state */
|
||||
dfa->states[17].reports.insert(rID);
|
||||
|
||||
/**
|
||||
* [a,b][c-e]{3}of0123456789
|
||||
* (1) -a,b-> (2) -c,d,e-> (3) -c,d,e-> (4) -c,d,e-> (5) -o-> (6) -f-> (7) -<numbers>-> ((17))
|
||||
* (0) = dead
|
||||
*/
|
||||
|
||||
for(int i = 0; i < ue2::ALPHABET_SIZE; i++) {
|
||||
dfa->alpha_remap[i] = 0;
|
||||
}
|
||||
|
||||
dfa->alpha_remap['a'] = 0;
|
||||
dfa->alpha_remap['b'] = 1;
|
||||
dfa->alpha_remap['c'] = 2;
|
||||
dfa->alpha_remap['d'] = 3;
|
||||
dfa->alpha_remap['e'] = 4;
|
||||
dfa->alpha_remap['o'] = 5;
|
||||
dfa->alpha_remap['f'] = 6;
|
||||
// maps 0 to 9
|
||||
for (int i = 0; i < 10; i ++) {
|
||||
dfa->alpha_remap[i + '0'] = i + 7;
|
||||
}
|
||||
dfa->alpha_remap[256] = 17; /* for some reason there's a check that run on dfa->alpha_size-1 */
|
||||
|
||||
/* a b c d e o f 0 1 2 3 4 5 6 7 8 9 */
|
||||
dfa->states[0].next = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
dfa->states[1].next = {2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; /* nothing */
|
||||
dfa->states[2].next = {2,2,3,3,3,1,1,1,1,1,1,1,1,1,1,1,1}; /* [a,b] */
|
||||
dfa->states[3].next = {2,2,4,4,4,1,1,1,1,1,1,1,1,1,1,1,1}; /* [a,b][c-e]{1} */
|
||||
dfa->states[4].next = {2,2,5,5,5,1,1,1,1,1,1,1,1,1,1,1,1}; /* [a,b][c-e]{2} */
|
||||
fill_straight_regex_sequence(dfa, 5, 17, 17); /* [a,b][c-e]{3}of012345678 */
|
||||
dfa->states[17].next = {2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; /* [a,b][c-e]{3}of0123456789 */
|
||||
}
|
||||
#endif /* defined(HAVE_AVX512VBMI) || defined(HAVE_SVE) */
|
||||
|
||||
typedef ue2::bytecode_ptr<NFA> (*sheng_compile_ptr)(ue2::raw_dfa&,
|
||||
const ue2::CompileContext&,
|
||||
const ue2::ReportManager&,
|
||||
bool,
|
||||
std::set<ue2::dstate_id_t>*);
|
||||
|
||||
typedef void (*init_raw_dfa_ptr)(struct ue2::raw_dfa*, const ReportID);
|
||||
|
||||
|
||||
static inline void init_nfa(struct NFA **out_nfa, sheng_compile_ptr compile_function, init_raw_dfa_ptr init_dfa_function) {
|
||||
ue2::Grey *g = new ue2::Grey();
|
||||
hs_platform_info plat_info = {0, 0, 0, 0};
|
||||
ue2::CompileContext *cc = new ue2::CompileContext(false, false, ue2::target_t(plat_info), *g);
|
||||
ue2::ReportManager *rm = new ue2::ReportManager(*g);
|
||||
ue2::Report *report = new ue2::Report(ue2::EXTERNAL_CALLBACK, 0);
|
||||
ReportID rID = rm->getInternalId(*report);
|
||||
rm->setProgramOffset(0, 0);
|
||||
|
||||
struct ue2::raw_dfa *dfa = new ue2::raw_dfa(ue2::NFA_OUTFIX);
|
||||
init_dfa_function(dfa, rID);
|
||||
|
||||
*out_nfa = (compile_function(*dfa, *cc, *rm, false, nullptr)).release();
|
||||
ASSERT_NE(nullptr, *out_nfa);
|
||||
|
||||
delete report;
|
||||
delete rm;
|
||||
delete cc;
|
||||
delete g;
|
||||
}
|
||||
|
||||
static void init_nfa16(struct NFA **out_nfa) {
|
||||
init_nfa(out_nfa, ue2::shengCompile, init_raw_dfa16);
|
||||
}
|
||||
|
||||
#if defined(HAVE_AVX512VBMI) || defined(HAVE_SVE)
|
||||
static void init_nfa32(struct NFA **out_nfa) {
|
||||
init_nfa(out_nfa, ue2::sheng32Compile, init_raw_dfa32);
|
||||
}
|
||||
#endif /* defined(HAVE_AVX512VBMI) || defined(HAVE_SVE) */
|
||||
|
||||
static char state_buffer;
|
||||
|
||||
static inline void init_sheng_queue(struct mq **out_q, uint8_t *buffer, size_t max_size, void (*init_nfa_func)(struct NFA **out_nfa) ) {
|
||||
struct NFA* nfa;
|
||||
init_nfa_func(&nfa);
|
||||
assert(nfa);
|
||||
|
||||
struct mq *q = new mq();
|
||||
|
||||
memset(q, 0, sizeof(struct mq));
|
||||
q->nfa = nfa;
|
||||
q->state = &state_buffer;
|
||||
q->cb = dummy_callback;
|
||||
q->buffer = buffer;
|
||||
q->length = max_size; /* setting this as the max length scanable */
|
||||
|
||||
if (nfa != q->nfa) {
|
||||
printf("Something went wrong while initializing sheng.\n");
|
||||
}
|
||||
nfaQueueInitState(nfa, q);
|
||||
pushQueueAt(q, 0, MQE_START, 0);
|
||||
pushQueueAt(q, 1, MQE_END, q->length );
|
||||
|
||||
*out_q = q;
|
||||
}
|
||||
|
||||
static void init_sheng_queue16(struct mq **out_q, uint8_t *buffer ,size_t max_size) {
|
||||
init_sheng_queue(out_q, buffer, max_size, init_nfa16);
|
||||
}
|
||||
|
||||
#if defined(HAVE_AVX512VBMI) || defined(HAVE_SVE)
|
||||
static void init_sheng_queue32(struct mq **out_q, uint8_t *buffer, size_t max_size) {
|
||||
init_sheng_queue(out_q, buffer, max_size, init_nfa32);
|
||||
}
|
||||
#endif /* defined(HAVE_AVX512VBMI) || defined(HAVE_SVE) */
|
||||
|
||||
static
|
||||
void fill_pattern(u8* buf, size_t buffer_size, unsigned int start_offset, unsigned int period, const char *pattern, unsigned int pattern_length) {
|
||||
memset(buf, '_', buffer_size);
|
||||
|
||||
for (unsigned int i = 0; i < buffer_size - 8; i+= 8) {
|
||||
/* filling with some junk, including some character used for a valid state, to prevent the use of shufti */
|
||||
memcpy(buf + i, "jgohcxbf", 8);
|
||||
}
|
||||
|
||||
for (unsigned int i = start_offset; i < buffer_size - pattern_length; i += period) {
|
||||
memcpy(buf + i, pattern, pattern_length);
|
||||
}
|
||||
}
|
||||
|
||||
/* Generate ground truth to compare to */
|
||||
struct NFA *get_expected_nfa_header(u8 type, unsigned int length, unsigned int nposition) {
|
||||
struct NFA *expected_nfa_header = new struct NFA();
|
||||
memset(expected_nfa_header, 0, sizeof(struct NFA));
|
||||
expected_nfa_header->length = length;
|
||||
expected_nfa_header->type = type;
|
||||
expected_nfa_header->nPositions = nposition;
|
||||
expected_nfa_header->scratchStateSize = 1;
|
||||
expected_nfa_header->streamStateSize = 1;
|
||||
return expected_nfa_header;
|
||||
}
|
||||
|
||||
struct NFA *get_expected_nfa16_header() {
|
||||
return get_expected_nfa_header(SHENG_NFA, 4736, 8);
|
||||
}
|
||||
|
||||
#if defined(HAVE_AVX512VBMI) || defined(HAVE_SVE)
|
||||
struct NFA *get_expected_nfa32_header() {
|
||||
return get_expected_nfa_header(SHENG_NFA_32, 17216, 18);
|
||||
}
|
||||
#endif /* defined(HAVE_AVX512VBMI) || defined(HAVE_SVE) */
|
||||
|
||||
void test_nfa_equal(const NFA& l, const NFA& r)
|
||||
{
|
||||
EXPECT_EQ(l.flags, r.flags);
|
||||
EXPECT_EQ(l.length, r.length);
|
||||
EXPECT_EQ(l.type, r.type);
|
||||
EXPECT_EQ(l.rAccelType, r.rAccelType);
|
||||
EXPECT_EQ(l.rAccelOffset, r.rAccelOffset);
|
||||
EXPECT_EQ(l.maxBiAnchoredWidth, r.maxBiAnchoredWidth);
|
||||
EXPECT_EQ(l.rAccelData.dc, r.rAccelData.dc);
|
||||
EXPECT_EQ(l.queueIndex, r.queueIndex);
|
||||
EXPECT_EQ(l.nPositions, r.nPositions);
|
||||
EXPECT_EQ(l.scratchStateSize, r.scratchStateSize);
|
||||
EXPECT_EQ(l.streamStateSize, r.streamStateSize);
|
||||
EXPECT_EQ(l.maxWidth, r.maxWidth);
|
||||
EXPECT_EQ(l.minWidth, r.minWidth);
|
||||
EXPECT_EQ(l.maxOffset, r.maxOffset);
|
||||
}
|
||||
|
||||
/* Start of actual tests */
|
||||
|
||||
/*
|
||||
* Runs shengCompile and compares its outputs to previously recorded outputs.
|
||||
*/
|
||||
TEST(Sheng16, std_compile_header) {
|
||||
|
||||
ue2::Grey *g = new ue2::Grey();
|
||||
hs_platform_info plat_info = {0, 0, 0, 0};
|
||||
ue2::CompileContext *cc = new ue2::CompileContext(false, false, ue2::target_t(plat_info), *g);
|
||||
ue2::ReportManager *rm = new ue2::ReportManager(*g);
|
||||
ue2::Report *report = new ue2::Report(ue2::EXTERNAL_CALLBACK, 0);
|
||||
ReportID rID = rm->getInternalId(*report);
|
||||
rm->setProgramOffset(0, 0);
|
||||
|
||||
struct ue2::raw_dfa *dfa = new ue2::raw_dfa(ue2::NFA_OUTFIX);
|
||||
init_raw_dfa16(dfa, rID);
|
||||
|
||||
struct NFA *nfa = (shengCompile(*dfa, *cc, *rm, false)).release();
|
||||
EXPECT_NE(nullptr, nfa);
|
||||
|
||||
EXPECT_NE(0, nfa->length);
|
||||
EXPECT_EQ(SHENG_NFA, nfa->type);
|
||||
|
||||
struct NFA *expected_nfa = get_expected_nfa16_header();
|
||||
test_nfa_equal(*expected_nfa, *nfa);
|
||||
|
||||
delete expected_nfa;
|
||||
delete report;
|
||||
delete rm;
|
||||
delete cc;
|
||||
delete g;
|
||||
}
|
||||
|
||||
/*
|
||||
* nfaExecSheng_B is the most basic of the sheng variants. It simply calls the core of the algorithm.
|
||||
* We test it with a buffer having a few matches at fixed intervals and check that it finds them all.
|
||||
*/
|
||||
TEST(Sheng16, std_run_B) {
|
||||
struct mq *q;
|
||||
unsigned int pattern_length = 6;
|
||||
unsigned int period = 128;
|
||||
const size_t buf_size = 200;
|
||||
unsigned int expected_matches = buf_size/128 + 1;
|
||||
u8 buf[buf_size];
|
||||
struct callback_context context = {period, 0, pattern_length};
|
||||
|
||||
struct NFA* nfa;
|
||||
init_nfa16(&nfa);
|
||||
ASSERT_NE(nullptr, nfa);
|
||||
fill_pattern(buf, buf_size, 0, period, "acecof", pattern_length);
|
||||
char ret_val;
|
||||
unsigned int offset = 0;
|
||||
unsigned int loop_count = 0;
|
||||
for (; loop_count < expected_matches + 1; loop_count++) {
|
||||
ASSERT_LT(offset, buf_size);
|
||||
ret_val = nfaExecSheng_B(nfa,
|
||||
offset,
|
||||
buf + offset,
|
||||
(s64a) buf_size - offset,
|
||||
periodic_pattern_callback,
|
||||
&context);
|
||||
offset = (context.match_count - 1) * context.period + context.pattern_length;
|
||||
if(unlikely(ret_val != MO_ALIVE)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*check normal return*/
|
||||
EXPECT_EQ(MO_ALIVE, ret_val);
|
||||
|
||||
/*check that we don't find additional match nor crash when no match are found*/
|
||||
EXPECT_EQ(expected_matches + 1, loop_count);
|
||||
|
||||
/*check that we have all the matches*/
|
||||
EXPECT_EQ(expected_matches, context.match_count);
|
||||
}
|
||||
|
||||
/*
|
||||
* nfaExecSheng_Q runs like the _B version (callback), but exercises the message queue logic.
|
||||
* We test it with a buffer having a few matches at fixed intervals and check that it finds them all.
|
||||
*/
|
||||
TEST(Sheng16, std_run_Q) {
|
||||
struct mq *q;
|
||||
unsigned int pattern_length = 6;
|
||||
unsigned int period = 128;
|
||||
const size_t buf_size = 200;
|
||||
unsigned int expected_matches = buf_size/128 + 1;
|
||||
u8 buf[buf_size];
|
||||
struct callback_context context = {period, 0, pattern_length};
|
||||
|
||||
init_sheng_queue16(&q, buf, buf_size);
|
||||
fill_pattern(buf, buf_size, 0, period, "acecof", pattern_length);
|
||||
q->cur = 0;
|
||||
q->items[q->cur].location = 0;
|
||||
q->context = &context;
|
||||
q->cb = periodic_pattern_callback;
|
||||
|
||||
nfaExecSheng_Q(q->nfa, q, (s64a) buf_size);
|
||||
/*check that we have all the matches*/
|
||||
EXPECT_EQ(expected_matches, context.match_count);
|
||||
|
||||
delete q;
|
||||
}
|
||||
|
||||
/*
|
||||
* nfaExecSheng_Q2 uses the message queue, but stops at match instead of using a callback.
|
||||
* We test it with a buffer having a few matches at fixed intervals and check that it finds them all.
|
||||
*/
|
||||
TEST(Sheng16, std_run_Q2) {
|
||||
struct mq *q;
|
||||
unsigned int pattern_length = 6;
|
||||
unsigned int period = 128;
|
||||
const size_t buf_size = 200;
|
||||
unsigned int expected_matches = buf_size/128 + 1;
|
||||
u8 buf[buf_size];
|
||||
|
||||
init_sheng_queue16(&q, buf, buf_size);
|
||||
fill_pattern(buf, buf_size, 0, period, "acecof", pattern_length);
|
||||
q->cur = 0;
|
||||
q->items[q->cur].location = 0;
|
||||
|
||||
char ret_val;
|
||||
int location;
|
||||
unsigned int loop_count = 0;
|
||||
do {
|
||||
ret_val = nfaExecSheng_Q2(q->nfa, q, (s64a) buf_size);
|
||||
location = q->items[q->cur].location;
|
||||
loop_count++;
|
||||
} while(likely((ret_val == MO_MATCHES_PENDING) && (location < (int)buf_size) && ((location % period) == pattern_length)));
|
||||
|
||||
/*check if it's a spurious match*/
|
||||
EXPECT_EQ(0, (ret_val == MO_MATCHES_PENDING) && ((location % period) != pattern_length));
|
||||
|
||||
/*check that we have all the matches*/
|
||||
EXPECT_EQ(expected_matches, loop_count-1);
|
||||
|
||||
delete q;
|
||||
}
|
||||
|
||||
/*
|
||||
* The message queue can also run on the "history" buffer. We test it the same way as the normal
|
||||
* buffer, expecting the same behavior.
|
||||
* We test it with a buffer having a few matches at fixed intervals and check that it finds them all.
|
||||
*/
|
||||
TEST(Sheng16, history_run_Q2) {
|
||||
struct mq *q;
|
||||
unsigned int pattern_length = 6;
|
||||
unsigned int period = 128;
|
||||
const size_t buf_size = 200;
|
||||
unsigned int expected_matches = buf_size/128 + 1;
|
||||
u8 buf[buf_size];
|
||||
|
||||
init_sheng_queue16(&q, buf, buf_size);
|
||||
fill_pattern(buf, buf_size, 0, period, "acecof", pattern_length);
|
||||
q->history = buf;
|
||||
q->hlength = buf_size;
|
||||
q->cur = 0;
|
||||
q->items[q->cur].location = -200;
|
||||
|
||||
char ret_val;
|
||||
int location;
|
||||
unsigned int loop_count = 0;
|
||||
do {
|
||||
ret_val = nfaExecSheng_Q2(q->nfa, q, 0);
|
||||
location = q->items[q->cur].location;
|
||||
loop_count++;
|
||||
} while(likely((ret_val == MO_MATCHES_PENDING) && (location > -(int)buf_size) && (location < 0) && (((buf_size + location) % period) == pattern_length)));
|
||||
|
||||
/*check if it's a spurious match*/
|
||||
EXPECT_EQ(0, (ret_val == MO_MATCHES_PENDING) && (((buf_size + location) % period) != pattern_length));
|
||||
|
||||
/*check that we have all the matches*/
|
||||
EXPECT_EQ(expected_matches, loop_count-1);
|
||||
|
||||
delete q;
|
||||
}
|
||||
|
||||
/**
|
||||
* Those tests only covers the basic paths. More tests can cover:
|
||||
* - running for history buffer to current buffer in Q2
|
||||
* - running while expecting no match
|
||||
* - nfaExecSheng_QR
|
||||
* - run sheng when it should call an accelerator and confirm it call them
|
||||
*/
|
||||
|
||||
#if defined(HAVE_AVX512VBMI) || defined(HAVE_SVE)
|
||||
|
||||
/*
|
||||
* Runs sheng32Compile and compares its outputs to previously recorded outputs.
|
||||
*/
|
||||
TEST(Sheng32, std_compile_header) {
|
||||
#if defined(HAVE_SVE)
|
||||
if(svcntb()<32) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
ue2::Grey *g = new ue2::Grey();
|
||||
hs_platform_info plat_info = {0, 0, 0, 0};
|
||||
ue2::CompileContext *cc = new ue2::CompileContext(false, false, ue2::target_t(plat_info), *g);
|
||||
ue2::ReportManager *rm = new ue2::ReportManager(*g);
|
||||
ue2::Report *report = new ue2::Report(ue2::EXTERNAL_CALLBACK, 0);
|
||||
ReportID rID = rm->getInternalId(*report);
|
||||
rm->setProgramOffset(0, 0);
|
||||
|
||||
struct ue2::raw_dfa *dfa = new ue2::raw_dfa(ue2::NFA_OUTFIX);
|
||||
init_raw_dfa32(dfa, rID);
|
||||
|
||||
struct NFA *nfa = (sheng32Compile(*dfa, *cc, *rm, false)).release();
|
||||
EXPECT_NE(nullptr, nfa);
|
||||
|
||||
EXPECT_NE(0, nfa->length);
|
||||
EXPECT_EQ(SHENG_NFA_32, nfa->type);
|
||||
|
||||
struct NFA *expected_nfa = get_expected_nfa32_header();
|
||||
test_nfa_equal(*expected_nfa, *nfa);
|
||||
|
||||
delete expected_nfa;
|
||||
delete report;
|
||||
delete rm;
|
||||
delete cc;
|
||||
delete g;
|
||||
}
|
||||
|
||||
/*
|
||||
* nfaExecSheng32_B is the most basic of the sheng variants. It simply calls the core of the algorithm.
|
||||
* We test it with a buffer having a few matches at fixed intervals and check that it finds them all.
|
||||
*/
|
||||
TEST(Sheng32, std_run_B) {
|
||||
#if defined(HAVE_SVE)
|
||||
if(svcntb()<32) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
struct mq *q;
|
||||
unsigned int pattern_length = 16;
|
||||
unsigned int period = 128;
|
||||
const size_t buf_size = 200;
|
||||
unsigned int expected_matches = buf_size/128 + 1;
|
||||
u8 buf[buf_size];
|
||||
struct callback_context context = {period, 0, pattern_length};
|
||||
|
||||
struct NFA* nfa;
|
||||
init_nfa32(&nfa);
|
||||
ASSERT_NE(nullptr, nfa);
|
||||
fill_pattern(buf, buf_size, 0, period, "acecof0123456789", pattern_length);
|
||||
char ret_val;
|
||||
unsigned int offset = 0;
|
||||
unsigned int loop_count = 0;
|
||||
for (; loop_count < expected_matches + 1; loop_count++) {
|
||||
ASSERT_LT(offset, buf_size);
|
||||
ret_val = nfaExecSheng32_B(nfa,
|
||||
offset,
|
||||
buf + offset,
|
||||
(s64a) buf_size - offset,
|
||||
periodic_pattern_callback,
|
||||
&context);
|
||||
offset = (context.match_count - 1) * context.period + context.pattern_length;
|
||||
if(unlikely(ret_val != MO_ALIVE)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*check normal return*/
|
||||
EXPECT_EQ(MO_ALIVE, ret_val);
|
||||
|
||||
/*check that we don't find additional match nor crash when no match are found*/
|
||||
EXPECT_EQ(expected_matches + 1, loop_count);
|
||||
|
||||
/*check that we have all the matches*/
|
||||
EXPECT_EQ(expected_matches, context.match_count);
|
||||
}
|
||||
|
||||
/*
|
||||
* nfaExecSheng32_Q runs like the _B version (callback), but exercises the message queue logic.
|
||||
* We test it with a buffer having a few matches at fixed intervals and check that it finds them all.
|
||||
*/
|
||||
TEST(Sheng32, std_run_Q) {
|
||||
#if defined(HAVE_SVE)
|
||||
if(svcntb()<32) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
struct mq *q;
|
||||
unsigned int pattern_length = 16;
|
||||
unsigned int period = 128;
|
||||
const size_t buf_size = 200;
|
||||
unsigned int expected_matches = buf_size/128 + 1;
|
||||
u8 buf[buf_size];
|
||||
struct callback_context context = {period, 0, pattern_length};
|
||||
|
||||
init_sheng_queue32(&q, buf, buf_size);
|
||||
fill_pattern(buf, buf_size, 0, period, "acecof0123456789", pattern_length);
|
||||
q->cur = 0;
|
||||
q->items[q->cur].location = 0;
|
||||
q->context = &context;
|
||||
q->cb = periodic_pattern_callback;
|
||||
|
||||
nfaExecSheng32_Q(q->nfa, q, (s64a) buf_size);
|
||||
/*check that we have all the matches*/
|
||||
EXPECT_EQ(expected_matches, context.match_count);
|
||||
|
||||
delete q;
|
||||
}
|
||||
|
||||
/*
|
||||
* nfaExecSheng32_Q2 uses the message queue, but stops at match instead of using a callback.
|
||||
* We test it with a buffer having a few matches at fixed intervals and check that it finds them all.
|
||||
*/
|
||||
TEST(Sheng32, std_run_Q2) {
|
||||
#if defined(HAVE_SVE)
|
||||
if(svcntb()<32) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
struct mq *q;
|
||||
unsigned int pattern_length = 16;
|
||||
unsigned int period = 128;
|
||||
const size_t buf_size = 200;
|
||||
unsigned int expected_matches = buf_size/128 + 1;
|
||||
u8 buf[buf_size];
|
||||
|
||||
init_sheng_queue32(&q, buf, buf_size);
|
||||
fill_pattern(buf, buf_size, 0, period, "acecof0123456789", pattern_length);
|
||||
q->cur = 0;
|
||||
q->items[q->cur].location = 0;
|
||||
|
||||
char ret_val;
|
||||
int location;
|
||||
unsigned int loop_count = 0;
|
||||
do {
|
||||
ret_val = nfaExecSheng32_Q2(q->nfa, q, (s64a) buf_size);
|
||||
location = q->items[q->cur].location;
|
||||
loop_count++;
|
||||
} while(likely((ret_val == MO_MATCHES_PENDING) && (location < (int)buf_size) && ((location % period) == pattern_length)));
|
||||
|
||||
/*check if it's a spurious match*/
|
||||
EXPECT_EQ(0, (ret_val == MO_MATCHES_PENDING) && ((location % period) != pattern_length));
|
||||
|
||||
/*check that we have all the matches*/
|
||||
EXPECT_EQ(expected_matches, loop_count-1);
|
||||
|
||||
delete q;
|
||||
}
|
||||
|
||||
/*
|
||||
* The message queue can also runs on the "history" buffer. We test it the same way as the normal
|
||||
* buffer, expecting the same behavior.
|
||||
* We test it with a buffer having a few matches at fixed intervals and check that it finds them all.
|
||||
*/
|
||||
TEST(Sheng32, history_run_Q2) {
|
||||
#if defined(HAVE_SVE)
|
||||
if(svcntb()<32) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
struct mq *q;
|
||||
unsigned int pattern_length = 16;
|
||||
unsigned int period = 128;
|
||||
const size_t buf_size = 200;
|
||||
unsigned int expected_matches = buf_size/128 + 1;
|
||||
u8 buf[buf_size];
|
||||
|
||||
init_sheng_queue32(&q, buf, buf_size);
|
||||
fill_pattern(buf, buf_size, 0, period, "acecof0123456789", pattern_length);
|
||||
q->history = buf;
|
||||
q->hlength = buf_size;
|
||||
q->cur = 0;
|
||||
q->items[q->cur].location = -200;
|
||||
|
||||
char ret_val;
|
||||
int location;
|
||||
unsigned int loop_count = 0;
|
||||
do {
|
||||
ret_val = nfaExecSheng32_Q2(q->nfa, q, 0);
|
||||
location = q->items[q->cur].location;
|
||||
loop_count++;
|
||||
} while(likely((ret_val == MO_MATCHES_PENDING) && (location > -(int)buf_size) && (location < 0) && (((buf_size + location) % period) == pattern_length)));
|
||||
|
||||
/*check if it's a spurious match*/
|
||||
EXPECT_EQ(0, (ret_val == MO_MATCHES_PENDING) && (((buf_size + location) % period) != pattern_length));
|
||||
|
||||
/*check that we have all the matches*/
|
||||
EXPECT_EQ(expected_matches, loop_count-1);
|
||||
|
||||
delete q;
|
||||
}
|
||||
#endif /* defined(HAVE_AVX512VBMI) || defined(HAVE_SVE) */
|
||||
|
||||
} /* namespace */
|
@@ -210,14 +210,14 @@ TEST(Shuffle, PackedExtract_templatized_128_1) {
|
||||
SuperVector<16> permute = SuperVector<16>::Zeroes();
|
||||
SuperVector<16> compare = SuperVector<16>::Zeroes();
|
||||
build_pshufb_masks_onebit(i, &permute.u.v128[0], &compare.u.v128[0]);
|
||||
EXPECT_EQ(1U, packedExtract<16>(setbit<m128>(i), permute, compare));
|
||||
EXPECT_EQ(1U, packedExtract<16>(SuperVector<16>(setbit<m128>(i)), permute, compare));
|
||||
EXPECT_EQ(1U, packedExtract<16>(SuperVector<16>::Ones(), permute, compare));
|
||||
// we should get zero out of these cases
|
||||
EXPECT_EQ(0U, packedExtract<16>(SuperVector<16>::Zeroes(), permute, compare));
|
||||
EXPECT_EQ(0U, packedExtract<16>(not128(setbit<m128>(i)), permute, compare));
|
||||
EXPECT_EQ(0U, packedExtract<16>(SuperVector<16>(not128(setbit<m128>(i))), permute, compare));
|
||||
// we should get zero out of all the other bit positions
|
||||
for (unsigned int j = 0; (j != i && j < 128); j++) {
|
||||
EXPECT_EQ(0U, packedExtract<16>(setbit<m128>(j), permute, compare));
|
||||
EXPECT_EQ(0U, packedExtract<16>(SuperVector<16>(setbit<m128>(j)), permute, compare));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -251,14 +251,14 @@ TEST(Shuffle, PackedExtract_templatized_256_1) {
|
||||
SuperVector<32> permute = SuperVector<32>::Zeroes();
|
||||
SuperVector<32> compare = SuperVector<32>::Zeroes();
|
||||
build_pshufb_masks_onebit(i, &permute.u.v256[0], &compare.u.v256[0]);
|
||||
EXPECT_EQ(1U, packedExtract<32>(setbit<m256>(i), permute, compare));
|
||||
EXPECT_EQ(1U, packedExtract<32>(SuperVector<32>(setbit<m256>(i)), permute, compare));
|
||||
EXPECT_EQ(1U, packedExtract<32>(SuperVector<32>::Ones(), permute, compare));
|
||||
// we should get zero out of these cases
|
||||
EXPECT_EQ(0U, packedExtract<32>(SuperVector<32>::Zeroes(), permute, compare));
|
||||
EXPECT_EQ(0U, packedExtract<32>(not256(setbit<m256>(i)), permute, compare));
|
||||
EXPECT_EQ(0U, packedExtract<32>(SuperVector<32>(not256(setbit<m256>(i))), permute, compare));
|
||||
// we should get zero out of all the other bit positions
|
||||
for (unsigned int j = 0; (j != i && j < 256); j++) {
|
||||
EXPECT_EQ(0U, packedExtract<32>(setbit<m256>(j), permute, compare));
|
||||
EXPECT_EQ(0U, packedExtract<32>(SuperVector<32>(setbit<m256>(j)), permute, compare));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -291,14 +291,14 @@ TEST(Shuffle, PackedExtract_templatized_512_1) {
|
||||
SuperVector<64> permute = SuperVector<64>::Zeroes();
|
||||
SuperVector<64> compare = SuperVector<64>::Zeroes();
|
||||
build_pshufb_masks_onebit(i, &permute.u.v512[0], &compare.u.v512[0]);
|
||||
EXPECT_EQ(1U, packedExtract<64>(setbit<m512>(i), permute, compare));
|
||||
EXPECT_EQ(1U, packedExtract<64>(SuperVector<64>(setbit<m512>(i)), permute, compare));
|
||||
EXPECT_EQ(1U, packedExtract<64>(SuperVector<64>::Ones(), permute, compare));
|
||||
// we should get zero out of these cases
|
||||
EXPECT_EQ(0U, packedExtract<64>(SuperVector<64>::Zeroes(), permute, compare));
|
||||
EXPECT_EQ(0U, packedExtract<64>(not512(setbit<m512>(i)), permute, compare));
|
||||
EXPECT_EQ(0U, packedExtract<64>(SuperVector<64>(not512(setbit<m512>(i))), permute, compare));
|
||||
// we should get zero out of all the other bit positions
|
||||
for (unsigned int j = 0; (j != i && j < 512); j++) {
|
||||
EXPECT_EQ(0U, packedExtract<64>(setbit<m512>(j), permute, compare));
|
||||
EXPECT_EQ(0U, packedExtract<64>(SuperVector<64>(setbit<m512>(j)), permute, compare));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -79,8 +79,8 @@ TEST(Shufti, BuildMask2) {
|
||||
int ret = shuftiBuildMasks(chars, (u8 *)&lomask, (u8 *)&himask);
|
||||
ASSERT_NE(-1, ret);
|
||||
|
||||
u8 *lo = (u8 *)&lomask;
|
||||
u8 *hi = (u8 *)&himask;
|
||||
const u8 *lo = (u8 *)&lomask;
|
||||
const u8 *hi = (u8 *)&himask;
|
||||
ASSERT_TRUE(lo['a' % 16] & hi['a' >> 4]);
|
||||
ASSERT_TRUE(lo['B' % 16] & hi['B' >> 4]);
|
||||
ASSERT_FALSE(lo['a' % 16] & hi['B' >> 4]);
|
||||
@@ -100,8 +100,8 @@ TEST(Shufti, BuildMask4) {
|
||||
int ret = shuftiBuildMasks(chars, (u8 *)&lomask, (u8 *)&himask);
|
||||
ASSERT_NE(-1, ret);
|
||||
|
||||
u8 *lo = (u8 *)&lomask;
|
||||
u8 *hi = (u8 *)&himask;
|
||||
const u8 *lo = (u8 *)&lomask;
|
||||
const u8 *hi = (u8 *)&himask;
|
||||
ASSERT_TRUE(lo['a' % 16] & hi['a' >> 4]);
|
||||
ASSERT_TRUE(lo['A' % 16] & hi['A' >> 4]);
|
||||
ASSERT_TRUE(lo['b' % 16] & hi['b' >> 4]);
|
||||
@@ -331,10 +331,10 @@ TEST(DoubleShufti, BuildMask2) {
|
||||
(u8 *)&lo2m, (u8 *)&hi2m);
|
||||
ASSERT_TRUE(ret);
|
||||
|
||||
u8 *lo1 = (u8 *)&lo1m;
|
||||
u8 *lo2 = (u8 *)&lo2m;
|
||||
u8 *hi1 = (u8 *)&hi1m;
|
||||
u8 *hi2 = (u8 *)&hi2m;
|
||||
const u8 *lo1 = (u8 *)&lo1m;
|
||||
const u8 *lo2 = (u8 *)&lo2m;
|
||||
const u8 *hi1 = (u8 *)&hi1m;
|
||||
const u8 *hi2 = (u8 *)&hi2m;
|
||||
ASSERT_NE(0xff,
|
||||
lo1['a' % 16] | hi1['a' >> 4] | lo2['z' % 16] | hi2['z' >> 4]);
|
||||
ASSERT_NE(0xff,
|
||||
@@ -359,10 +359,10 @@ TEST(DoubleShufti, BuildMask4) {
|
||||
(u8 *)&lo2m, (u8 *)&hi2m);
|
||||
ASSERT_TRUE(ret);
|
||||
|
||||
u8 *lo1 = (u8 *)&lo1m;
|
||||
u8 *lo2 = (u8 *)&lo2m;
|
||||
u8 *hi1 = (u8 *)&hi1m;
|
||||
u8 *hi2 = (u8 *)&hi2m;
|
||||
const u8 *lo1 = (u8 *)&lo1m;
|
||||
const u8 *lo2 = (u8 *)&lo2m;
|
||||
const u8 *hi1 = (u8 *)&hi1m;
|
||||
const u8 *hi2 = (u8 *)&hi2m;
|
||||
ASSERT_NE(0xff,
|
||||
lo1['a' % 16] | hi1['a' >> 4] | lo2['z' % 16] | hi2['z' >> 4]);
|
||||
ASSERT_NE(0xff,
|
||||
@@ -388,10 +388,10 @@ TEST(DoubleShufti, BuildMask5) {
|
||||
(u8 *)&lo2m, (u8 *)&hi2m);
|
||||
ASSERT_TRUE(ret);
|
||||
|
||||
u8 *lo1 = (u8 *)&lo1m;
|
||||
u8 *lo2 = (u8 *)&lo2m;
|
||||
u8 *hi1 = (u8 *)&hi1m;
|
||||
u8 *hi2 = (u8 *)&hi2m;
|
||||
const u8 *lo1 = (u8 *)&lo1m;
|
||||
const u8 *lo2 = (u8 *)&lo2m;
|
||||
const u8 *hi1 = (u8 *)&hi1m;
|
||||
const u8 *hi2 = (u8 *)&hi2m;
|
||||
ASSERT_NE(0xff,
|
||||
lo1['a' % 16] | hi1['a' >> 4] | lo2['z' % 16] | hi2['z' >> 4]);
|
||||
ASSERT_EQ(0xff,
|
||||
@@ -426,10 +426,10 @@ TEST(DoubleShufti, BuildMask6) {
|
||||
(u8 *)&lo2m, (u8 *)&hi2m);
|
||||
ASSERT_TRUE(ret);
|
||||
|
||||
u8 *lo1 = (u8 *)&lo1m;
|
||||
u8 *lo2 = (u8 *)&lo2m;
|
||||
u8 *hi1 = (u8 *)&hi1m;
|
||||
u8 *hi2 = (u8 *)&hi2m;
|
||||
const u8 *lo1 = (u8 *)&lo1m;
|
||||
const u8 *lo2 = (u8 *)&lo2m;
|
||||
const u8 *hi1 = (u8 *)&hi1m;
|
||||
const u8 *hi2 = (u8 *)&hi2m;
|
||||
ASSERT_NE(0xff,
|
||||
lo1['a' % 16] | hi1['a' >> 4] | lo2['z' % 16] | hi2['z' >> 4]);
|
||||
ASSERT_NE(0xff,
|
||||
|
@@ -152,7 +152,7 @@ TEST(state_compress, m128_1) {
|
||||
TEST(state_compress, m128_2) {
|
||||
char buf[sizeof(m128)] = { 0 };
|
||||
|
||||
char val_raw[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
|
||||
const char val_raw[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
|
||||
m128 val;
|
||||
memcpy(&val, val_raw, sizeof(val));
|
||||
@@ -180,7 +180,7 @@ TEST(state_compress, m128_2) {
|
||||
loadcompressed128(&val_out, &buf, &mask, 0);
|
||||
EXPECT_TRUE(!diff128(and128(val, mask), val_out));
|
||||
|
||||
mask_raw[j] = 0x7f;
|
||||
mask_raw[j] = 0x7f; // cppcheck-suppress unreadVariable
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -228,7 +228,7 @@ TEST(state_compress, m256_1) {
|
||||
TEST(state_compress, m256_2) {
|
||||
char buf[sizeof(m256)] = { 0 };
|
||||
|
||||
char val_raw[32] = { '0', '1', '2', '3', '4', '5', '6', '7',
|
||||
const char val_raw[32] = { '0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
||||
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P' };
|
||||
@@ -258,7 +258,7 @@ TEST(state_compress, m256_2) {
|
||||
loadcompressed256(&val_out, &buf, &mask, 0);
|
||||
EXPECT_TRUE(!diff256(and256(val, mask), val_out));
|
||||
|
||||
mask_raw[j] = 0x7f;
|
||||
mask_raw[j] = 0x7f; // cppcheck-suppress unreadVariable
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -306,7 +306,7 @@ TEST(state_compress, m384_1) {
|
||||
TEST(state_compress, m384_2) {
|
||||
char buf[sizeof(m384)] = { 0 };
|
||||
|
||||
char val_raw[48] = { '0', '1', '2', '3', '4', '5', '6', '7',
|
||||
const char val_raw[48] = { '0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
||||
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
||||
@@ -338,7 +338,7 @@ TEST(state_compress, m384_2) {
|
||||
loadcompressed384(&val_out, &buf, &mask, 0);
|
||||
EXPECT_TRUE(!diff384(and384(val, mask), val_out));
|
||||
|
||||
mask_raw[j] = 0x7f;
|
||||
mask_raw[j] = 0x7f; // cppcheck-suppress unreadVariable
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -386,7 +386,7 @@ TEST(state_compress, m512_1) {
|
||||
TEST(state_compress, m512_2) {
|
||||
char buf[sizeof(m512)] = { 0 };
|
||||
|
||||
char val_raw[64] = { '0', '1', '2', '3', '4', '5', '6', '7',
|
||||
const char val_raw[64] = { '0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
||||
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
||||
@@ -419,7 +419,7 @@ TEST(state_compress, m512_2) {
|
||||
loadcompressed512(&val_out, &buf, &mask, 0);
|
||||
EXPECT_TRUE(!diff512(and512(val, mask), val_out));
|
||||
|
||||
mask_raw[j] = 0x7f;
|
||||
mask_raw[j] = 0x7f; // cppcheck-suppress unreadVariable
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -508,7 +508,7 @@ TEST(SuperVectorUtilsTest,Movemask256c){
|
||||
u8 vec2[32] = {0};
|
||||
u32 r = rand() % 100 + 1;
|
||||
for(int i=0; i<32; i++) {
|
||||
if (r & (1 << i)) {
|
||||
if (r & (1U << i)) {
|
||||
vec[i] = 0xff;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user