diff --git a/tools/hsbench/common.h b/tools/hsbench/common.h index a4d60021..efff3f99 100644 --- a/tools/hsbench/common.h +++ b/tools/hsbench/common.h @@ -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 * modification, are permitted provided that the following conditions are met: @@ -38,5 +38,7 @@ extern bool saveDatabases; extern bool loadDatabases; extern std::string serializePath; extern unsigned int somPrecisionMode; +extern bool forceEditDistance; +extern unsigned editDistance; #endif // COMMON_H diff --git a/tools/hsbench/engine_hyperscan.cpp b/tools/hsbench/engine_hyperscan.cpp index f5abb9fa..eadc1cc4 100644 --- a/tools/hsbench/engine_hyperscan.cpp +++ b/tools/hsbench/engine_hyperscan.cpp @@ -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 * modification, are permitted provided that the following conditions are met: @@ -289,6 +289,10 @@ buildEngineHyperscan(const ExpressionMap &expressions, ScanMode scan_mode, m.first); return nullptr; } + if (forceEditDistance) { + extparam.flags |= HS_EXT_FLAG_EDIT_DISTANCE; + extparam.edit_distance = editDistance; + } exprs.push_back(expr); ids.push_back(m.first); diff --git a/tools/hsbench/main.cpp b/tools/hsbench/main.cpp index 4298963b..a99760a2 100644 --- a/tools/hsbench/main.cpp +++ b/tools/hsbench/main.cpp @@ -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 * modification, are permitted provided that the following conditions are met: @@ -72,6 +72,8 @@ bool saveDatabases = false; bool loadDatabases = false; string serializePath(""); unsigned int somPrecisionMode = HS_MODE_SOM_HORIZON_LARGE; +bool forceEditDistance = false; +unsigned editDistance = 0; namespace /* anonymous */ { @@ -169,6 +171,8 @@ void usage(const char *error) { " instead.\n"); printf(" -w DIR After compiling, save to files in DIR.\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(" --per-scan Display per-scan Mbit/sec results.\n"); printf(" --echo-matches Display all matches that occur during scan.\n"); @@ -191,7 +195,7 @@ struct BenchmarkSigs { static void processArgs(int argc, char *argv[], vector &sigSets, 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 do_per_scan = 0; int do_echo_matches = 0; @@ -237,6 +241,14 @@ void processArgs(int argc, char *argv[], vector &sigSets, case 'e': exprPath.assign(optarg); 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 case 'G': applyGreyOverrides(&grey, string(optarg));