literal matchers: change context passed to callback to scratch

This commit is contained in:
Wang, Xiang W
2017-07-04 12:24:11 -04:00
committed by Matthew Barr
parent bc232d272f
commit 67a8f43355
17 changed files with 203 additions and 188 deletions

View File

@@ -36,6 +36,7 @@
#include "fdr/fdr_engine_description.h"
#include "fdr/teddy_compile.h"
#include "fdr/teddy_engine_description.h"
#include "scratch.h"
#include "util/alloc.h"
#include "util/bitutils.h"
@@ -94,13 +95,13 @@ T &operator<<(T &a, const vector<match> &b) {
return a;
}
map<u32, int> matchesCounts;
extern "C" {
static hwlmcb_rv_t countCallback(UNUSED size_t end, u32 id, void *cntxt) {
if (cntxt) {
map<u32, int> *matchesCounts = (map<u32, int> *)cntxt;
(*matchesCounts)[id]++;
}
static hwlmcb_rv_t countCallback(UNUSED size_t end, u32 id,
UNUSED struct hs_scratch *scratch) {
matchesCounts[id]++;
return HWLM_CONTINUE_MATCHING;
}
@@ -140,6 +141,7 @@ TEST_P(FDRFloodp, NoMask) {
vector<u8> data(dataSize);
u8 c = 0;
struct hs_scratch scratch;
while (1) {
SCOPED_TRACE((unsigned int)c);
u8 bit = 1 << (c & 0x7);
@@ -171,10 +173,8 @@ TEST_P(FDRFloodp, NoMask) {
Grey());
CHECK_WITH_TEDDY_OK_TO_FAIL(fdr, hint);
map<u32, int> matchesCounts;
hwlm_error_t fdrStatus = fdrExec(fdr.get(), &data[0], dataSize,
0, countCallback, (void *)&matchesCounts, HWLM_ALL_GROUPS);
0, countCallback, &scratch, HWLM_ALL_GROUPS);
ASSERT_EQ(0, fdrStatus);
for (u8 i = 0; i < 4; i++) {
@@ -199,7 +199,7 @@ TEST_P(FDRFloodp, NoMask) {
matchesCounts.clear();
memset(&data[0], cAlt, dataSize);
fdrStatus = fdrExec(fdr.get(), &data[0], dataSize,
0, countCallback, (void *)&matchesCounts, HWLM_ALL_GROUPS);
0, countCallback, &scratch, HWLM_ALL_GROUPS);
ASSERT_EQ(0, fdrStatus);
for (u8 i = 0; i < 4; i++) {
@@ -219,6 +219,7 @@ TEST_P(FDRFloodp, NoMask) {
ASSERT_EQ(0, matchesCounts[i * 8 + 6]);
}
}
matchesCounts.clear();
if (++c == 0) {
break;
@@ -233,6 +234,7 @@ TEST_P(FDRFloodp, WithMask) {
vector<u8> data(dataSize);
u8 c = '\0';
struct hs_scratch scratch;
while (1) {
u8 bit = 1 << (c & 0x7);
u8 cAlt = c ^ bit;
@@ -307,10 +309,8 @@ TEST_P(FDRFloodp, WithMask) {
Grey());
CHECK_WITH_TEDDY_OK_TO_FAIL(fdr, hint);
map <u32, int> matchesCounts;
hwlm_error_t fdrStatus = fdrExec(fdr.get(), &data[0], dataSize,
0, countCallback, &matchesCounts, HWLM_ALL_GROUPS);
0, countCallback, &scratch, HWLM_ALL_GROUPS);
ASSERT_EQ(0, fdrStatus);
const u32 cnt4 = dataSize - 4 + 1;
@@ -348,7 +348,7 @@ TEST_P(FDRFloodp, WithMask) {
memset(&data[0], cAlt, dataSize);
matchesCounts.clear();
fdrStatus = fdrExec(fdr.get(), &data[0], dataSize,
0, countCallback, &matchesCounts, HWLM_ALL_GROUPS);
0, countCallback, &scratch, HWLM_ALL_GROUPS);
ASSERT_EQ(0, fdrStatus);
for (u8 i = 0; i < 4; i++) {
@@ -381,6 +381,7 @@ TEST_P(FDRFloodp, WithMask) {
ASSERT_EQ(0, matchesCounts[i * 12 + 11]);
}
}
matchesCounts.clear();
if (++c == '\0') {
break;
@@ -398,6 +399,7 @@ TEST_P(FDRFloodp, StreamingMask) {
vector<u8> tempdata(dataSize + fake_history_size); // headroom
u8 c = '\0';
struct hs_scratch scratch;
while (1) {
u8 bit = 1 << (c & 0x7);
u8 cAlt = c ^ bit;
@@ -472,7 +474,6 @@ TEST_P(FDRFloodp, StreamingMask) {
Grey());
CHECK_WITH_TEDDY_OK_TO_FAIL(fdr, hint);
map <u32, int> matchesCounts;
hwlm_error_t fdrStatus;
const u32 cnt4 = dataSize - 4 + 1;
@@ -482,7 +483,7 @@ TEST_P(FDRFloodp, StreamingMask) {
// 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,
countCallback, &matchesCounts,
countCallback, &scratch,
HWLM_ALL_GROUPS);
ASSERT_EQ(0, fdrStatus);
for (u32 j = streamChunk; j < dataSize; j += streamChunk) {
@@ -493,13 +494,11 @@ TEST_P(FDRFloodp, StreamingMask) {
const u8 *tmp_d = tempdata.data() + fake_history_size;
fdrStatus = fdrExecStreaming(fdr.get(), tmp_d, j, tmp_d + j,
streamChunk, 0, countCallback,
&matchesCounts,
HWLM_ALL_GROUPS);
&scratch, HWLM_ALL_GROUPS);
} else {
fdrStatus = fdrExecStreaming(fdr.get(), d + j - 8, 8, d + j,
streamChunk, 0, countCallback,
&matchesCounts,
HWLM_ALL_GROUPS);
&scratch, HWLM_ALL_GROUPS);
}
ASSERT_EQ(0, fdrStatus);
}
@@ -540,6 +539,7 @@ TEST_P(FDRFloodp, StreamingMask) {
break;
}
}
matchesCounts.clear();
}
INSTANTIATE_TEST_CASE_P(FDRFlood, FDRFloodp, ValuesIn(getValidFdrEngines()));