Add support for approximate matching in other tools

This commit is contained in:
Anatoly Burakov 2017-02-10 15:45:09 +00:00 committed by Matthew Barr
parent 9f72dede5c
commit ebe849603b
3 changed files with 22 additions and 4 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, Intel Corporation * Copyright (c) 2016-2017, Intel Corporation
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -38,5 +38,7 @@ extern bool saveDatabases;
extern bool loadDatabases; extern bool loadDatabases;
extern std::string serializePath; extern std::string serializePath;
extern unsigned int somPrecisionMode; extern unsigned int somPrecisionMode;
extern bool forceEditDistance;
extern unsigned editDistance;
#endif // COMMON_H #endif // COMMON_H

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, Intel Corporation * Copyright (c) 2016-2017, Intel Corporation
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -289,6 +289,10 @@ buildEngineHyperscan(const ExpressionMap &expressions, ScanMode scan_mode,
m.first); m.first);
return nullptr; return nullptr;
} }
if (forceEditDistance) {
extparam.flags |= HS_EXT_FLAG_EDIT_DISTANCE;
extparam.edit_distance = editDistance;
}
exprs.push_back(expr); exprs.push_back(expr);
ids.push_back(m.first); ids.push_back(m.first);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, Intel Corporation * Copyright (c) 2016-2017, Intel Corporation
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -72,6 +72,8 @@ bool saveDatabases = false;
bool loadDatabases = false; bool loadDatabases = false;
string serializePath(""); string serializePath("");
unsigned int somPrecisionMode = HS_MODE_SOM_HORIZON_LARGE; unsigned int somPrecisionMode = HS_MODE_SOM_HORIZON_LARGE;
bool forceEditDistance = false;
unsigned editDistance = 0;
namespace /* anonymous */ { namespace /* anonymous */ {
@ -169,6 +171,8 @@ void usage(const char *error) {
" instead.\n"); " instead.\n");
printf(" -w DIR After compiling, save to files in DIR.\n"); printf(" -w DIR After compiling, save to files in DIR.\n");
printf(" -d NUMBER Set SOM precision mode (default: 8 (large)).\n"); printf(" -d NUMBER Set SOM precision mode (default: 8 (large)).\n");
printf(" -E DISTANCE Match all patterns within edit distance"
" DISTANCE.\n");
printf("\n"); printf("\n");
printf(" --per-scan Display per-scan Mbit/sec results.\n"); printf(" --per-scan Display per-scan Mbit/sec results.\n");
printf(" --echo-matches Display all matches that occur during scan.\n"); printf(" --echo-matches Display all matches that occur during scan.\n");
@ -191,7 +195,7 @@ struct BenchmarkSigs {
static static
void processArgs(int argc, char *argv[], vector<BenchmarkSigs> &sigSets, void processArgs(int argc, char *argv[], vector<BenchmarkSigs> &sigSets,
UNUSED Grey &grey) { UNUSED Grey &grey) {
const char options[] = "-b:c:Cd:e:G:hi:n:No:p:sT:Vw:z:"; const char options[] = "-b:c:Cd:e:E:G:hi:n:No:p:sT:Vw:z:";
int in_sigfile = 0; int in_sigfile = 0;
int do_per_scan = 0; int do_per_scan = 0;
int do_echo_matches = 0; int do_echo_matches = 0;
@ -237,6 +241,14 @@ void processArgs(int argc, char *argv[], vector<BenchmarkSigs> &sigSets,
case 'e': case 'e':
exprPath.assign(optarg); exprPath.assign(optarg);
break; break;
case 'E':
if (!fromString(optarg, editDistance)) {
usage("Couldn't parse argument to -E flag, should be"
" a non-negative integer.");
exit(1);
}
forceEditDistance = true;
break;
#ifndef RELEASE_BUILD #ifndef RELEASE_BUILD
case 'G': case 'G':
applyGreyOverrides(&grey, string(optarg)); applyGreyOverrides(&grey, string(optarg));