summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
author郑超 <[email protected]>2024-03-27 11:19:39 +0000
committerliuwentan <[email protected]>2024-03-27 11:19:39 +0000
commit99f98abbcdf6a9ae2da51b99aaa8dbf70568a4ff (patch)
treedd7b00ac76051ca16936a42eaa9e4f61a68ed043 /test
parent35d60d06b5bf18a8adf95cb4cfb00df5ab3c02da (diff)
Feature/scan ip port together support endpoint objectv4.1.32
Diffstat (limited to 'test')
-rw-r--r--test/CMakeLists.txt15
-rw-r--r--test/benchmark/benchmark_hs_gtest.cpp125
-rw-r--r--test/benchmark/benchmark_rs_gtest.cpp114
-rw-r--r--test/benchmark/benchmark_table_info.conf20
-rw-r--r--test/file_test_tableinfo.conf4
-rw-r--r--test/group_exclude/group_exclude_gtest.cpp4
-rw-r--r--test/ipport_plugin/ipport_plugin_gtest.cpp6
-rw-r--r--test/maat_ex_data_gtest.cpp14
-rw-r--r--test/maat_framework_gtest.cpp495
-rw-r--r--test/maat_framework_perf_gtest.cpp355
-rw-r--r--test/maat_input_mode_gtest.cpp32
-rw-r--r--test/maat_json.json149
-rw-r--r--test/table_info.conf20
-rw-r--r--test/test_utils.cpp303
-rw-r--r--test/test_utils.h37
-rw-r--r--test/tsg_table_info.conf3
16 files changed, 765 insertions, 931 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 9d31201..7115bc8 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -16,10 +16,10 @@ target_link_libraries(rcu_hash_gtest maat_frame_static gtest_static)
add_executable(maat_input_mode_gtest maat_input_mode_gtest.cpp)
target_link_libraries(maat_input_mode_gtest maat_frame_static gtest_static)
-add_executable(maat_framework_gtest maat_framework_gtest.cpp)
+add_executable(maat_framework_gtest maat_framework_gtest.cpp test_utils.cpp)
target_link_libraries(maat_framework_gtest maat_frame_static gtest_static)
-add_executable(maat_framework_perf_gtest maat_framework_perf_gtest.cpp)
+add_executable(maat_framework_perf_gtest maat_framework_perf_gtest.cpp test_utils.cpp)
target_link_libraries(maat_framework_perf_gtest maat_frame_static gtest_static)
add_executable(expr_matcher_gtest expr_matcher_gtest.cpp)
@@ -41,11 +41,12 @@ add_subdirectory(group_exclude)
add_subdirectory(ipport_plugin)
add_subdirectory(benchmark)
-file(COPY table_info.conf DESTINATION ./)
-file(COPY tsg_table_info.conf DESTINATION ./)
-file(COPY file_test_tableinfo.conf DESTINATION ./)
-file(COPY expr_matcher.conf DESTINATION ./)
-file(COPY maat_json.json DESTINATION ./)
+configure_file(table_info.conf table_info.conf COPYONLY)
+configure_file(tsg_table_info.conf tsg_table_info.conf COPYONLY)
+configure_file(file_test_tableinfo.conf file_test_tableinfo.conf COPYONLY)
+configure_file(expr_matcher.conf expr_matcher.conf COPYONLY)
+configure_file(maat_json.json maat_json.json COPYONLY)
+
file(COPY ntcrule DESTINATION ./)
file(COPY tsgrule DESTINATION ./)
file(COPY testdata DESTINATION ./)
diff --git a/test/benchmark/benchmark_hs_gtest.cpp b/test/benchmark/benchmark_hs_gtest.cpp
index 289af24..87633cd 100644
--- a/test/benchmark/benchmark_hs_gtest.cpp
+++ b/test/benchmark/benchmark_hs_gtest.cpp
@@ -27,7 +27,7 @@
#define PERF_THREAD_NUM 5
#define MAX_SCAN_TIMES 1000000
-const char *table_info_path = "./benchmark_table_info.conf";
+const char *g_table_info_path = "./benchmark_table_info.conf";
struct log_handle *g_logger = NULL;
struct thread_param {
@@ -547,11 +547,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -639,11 +638,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -731,11 +729,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -823,11 +820,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -915,11 +911,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1007,11 +1002,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1099,11 +1093,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1191,11 +1184,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1283,11 +1275,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1375,11 +1366,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1468,11 +1458,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1561,11 +1550,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1654,11 +1642,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1747,11 +1734,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1840,11 +1826,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1933,11 +1918,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2026,11 +2010,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2119,11 +2102,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2212,11 +2194,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2302,11 +2283,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2392,11 +2372,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2482,11 +2461,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2572,11 +2550,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2662,11 +2639,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2752,11 +2728,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2842,11 +2817,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2932,9 +2906,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3023,9 +2996,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3114,9 +3086,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3205,9 +3176,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3296,9 +3266,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3387,9 +3356,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3478,9 +3446,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3569,9 +3536,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3660,9 +3626,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3751,9 +3716,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3842,9 +3806,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3933,9 +3896,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -4024,9 +3986,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -4115,9 +4076,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -4206,9 +4166,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
diff --git a/test/benchmark/benchmark_rs_gtest.cpp b/test/benchmark/benchmark_rs_gtest.cpp
index 0432dac..48f2954 100644
--- a/test/benchmark/benchmark_rs_gtest.cpp
+++ b/test/benchmark/benchmark_rs_gtest.cpp
@@ -27,7 +27,7 @@
#define PERF_THREAD_NUM 5
#define MAX_scan_times 1000000
-const char *table_info_path = "./benchmark_table_info.conf";
+const char *g_table_info_path = "./benchmark_table_info.conf";
struct log_handle *g_logger = NULL;
struct thread_param {
@@ -547,11 +547,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -639,11 +638,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -731,11 +729,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -824,11 +821,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -917,11 +913,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1009,12 +1004,11 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
- maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
+ maat_options_set_iris(opts, "./", "./");
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1103,11 +1097,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1196,11 +1189,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1289,11 +1281,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1382,11 +1373,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1475,11 +1465,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1567,12 +1556,11 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
- maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
+ maat_options_set_iris(opts, "./", "./");
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1658,11 +1646,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1748,11 +1735,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1838,11 +1824,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1928,11 +1913,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2018,11 +2002,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2108,11 +2091,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2198,11 +2180,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2287,12 +2268,11 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
- maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
+ maat_options_set_iris(opts, "./", "./");
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2380,12 +2360,11 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
- maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
+ maat_options_set_iris(opts, "./", "./");
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2474,11 +2453,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2566,12 +2544,11 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
- maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
+ maat_options_set_iris(opts, "./", "./");
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2660,11 +2637,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2753,11 +2729,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2846,11 +2821,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2939,11 +2913,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3032,10 +3005,9 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3124,11 +3096,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3217,11 +3188,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3310,11 +3280,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3403,11 +3372,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3496,11 +3464,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3589,11 +3556,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
diff --git a/test/benchmark/benchmark_table_info.conf b/test/benchmark/benchmark_table_info.conf
index 89485e7..051dcf7 100644
--- a/test/benchmark/benchmark_table_info.conf
+++ b/test/benchmark/benchmark_table_info.conf
@@ -128,7 +128,7 @@
{
"table_id":10,
"table_name":"IP_1K",
- "table_type":"ip_plus",
+ "table_type":"ip",
"valid_column":11,
"custom": {
"item_id":1,
@@ -146,7 +146,7 @@
{
"table_id":11,
"table_name":"IP_5K",
- "table_type":"ip_plus",
+ "table_type":"ip",
"valid_column":11,
"custom": {
"item_id":1,
@@ -164,7 +164,7 @@
{
"table_id":12,
"table_name":"IP_10K",
- "table_type":"ip_plus",
+ "table_type":"ip",
"valid_column":11,
"custom": {
"item_id":1,
@@ -182,7 +182,7 @@
{
"table_id":13,
"table_name":"IP_50K",
- "table_type":"ip_plus",
+ "table_type":"ip",
"valid_column":11,
"custom": {
"item_id":1,
@@ -200,7 +200,7 @@
{
"table_id":14,
"table_name":"IP_100K",
- "table_type":"ip_plus",
+ "table_type":"ip",
"valid_column":11,
"custom": {
"item_id":1,
@@ -218,7 +218,7 @@
{
"table_id":15,
"table_name":"IP_500K",
- "table_type":"ip_plus",
+ "table_type":"ip",
"valid_column":11,
"custom": {
"item_id":1,
@@ -236,7 +236,7 @@
{
"table_id":16,
"table_name":"IP_1M",
- "table_type":"ip_plus",
+ "table_type":"ip",
"valid_column":11,
"custom": {
"item_id":1,
@@ -254,7 +254,7 @@
{
"table_id":17,
"table_name":"IP_2M",
- "table_type":"ip_plus",
+ "table_type":"ip",
"valid_column":11,
"custom": {
"item_id":1,
@@ -272,7 +272,7 @@
{
"table_id":18,
"table_name":"IP_5M",
- "table_type":"ip_plus",
+ "table_type":"ip",
"valid_column":11,
"custom": {
"item_id":1,
@@ -290,7 +290,7 @@
{
"table_id":19,
"table_name":"IP_10M",
- "table_type":"ip_plus",
+ "table_type":"ip",
"valid_column":11,
"custom": {
"item_id":1,
diff --git a/test/file_test_tableinfo.conf b/test/file_test_tableinfo.conf
index 404de30..c3dff0a 100644
--- a/test/file_test_tableinfo.conf
+++ b/test/file_test_tableinfo.conf
@@ -62,7 +62,7 @@
{
"table_id":5,
"table_name":"NTC_UNIVERSAL_IP",
- "table_type":"ip_plus",
+ "table_type":"ip",
"valid_column":7,
"custom": {
"item_id":1,
@@ -88,7 +88,7 @@
{
"table_id":7,
"table_name":"WHITE_LIST_IP",
- "table_type":"ip_plus",
+ "table_type":"ip",
"valid_column":7,
"custom": {
"item_id":1,
diff --git a/test/group_exclude/group_exclude_gtest.cpp b/test/group_exclude/group_exclude_gtest.cpp
index 21ec5b0..ac69ff2 100644
--- a/test/group_exclude/group_exclude_gtest.cpp
+++ b/test/group_exclude/group_exclude_gtest.cpp
@@ -15,7 +15,7 @@
#define WAIT_FOR_EFFECTIVE_S 2
#define MAX_G2G_SCAN_TIMES (1000 * 1000)
-const char *table_info_path = "./group_exclude_table_info.conf";
+const char *g_table_info_path = "./group_exclude_table_info.conf";
const char *log_file = "./group_exclude_gtest.log";
struct group_item {
@@ -127,7 +127,7 @@ protected:
logger = log_handle_create(log_file, 0);
garbage_bin = maat_garbage_bin_new(60);
- int ret = load_file_to_memory(table_info_path, &json_buff, &json_buff_size);
+ int ret = load_file_to_memory(g_table_info_path, &json_buff, &json_buff_size);
if (ret < 0) {
log_fatal(logger, MODULE_GROUP_EXCLUDE_GTEST, "load_file_to_memory failed.");
assert(0);
diff --git a/test/ipport_plugin/ipport_plugin_gtest.cpp b/test/ipport_plugin/ipport_plugin_gtest.cpp
index 229bf5b..392de72 100644
--- a/test/ipport_plugin/ipport_plugin_gtest.cpp
+++ b/test/ipport_plugin/ipport_plugin_gtest.cpp
@@ -13,7 +13,7 @@
#define ARRAY_SIZE 10
#define PERF_scan_times 1000 * 1000
-const char *table_info_path = "./ipport_plugin_table_info.conf";
+const char *g_table_info_path = "./ipport_plugin_table_info.conf";
const char *log_file = "./ipport_plugin_gtest.log";
const char *g_ip_str = "116.71.169.140";
@@ -376,7 +376,7 @@ TEST_F(IPPortPluginTable, WITHOUT_SAME_IP) {
maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_rule_update_checking_interval_ms(opts, 100);
- struct maat *maat_inst = maat_new(opts, table_info_path);
+ struct maat *maat_inst = maat_new(opts, g_table_info_path);
assert(maat_inst);
maat_options_free(opts);
@@ -445,7 +445,7 @@ TEST_F(IPPortPluginTable, WITH_256SAME_IP) {
maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_rule_update_checking_interval_ms(opts, 100);
- struct maat *maat_inst = maat_new(opts, table_info_path);
+ struct maat *maat_inst = maat_new(opts, g_table_info_path);
assert(maat_inst);
maat_options_free(opts);
diff --git a/test/maat_ex_data_gtest.cpp b/test/maat_ex_data_gtest.cpp
index 0cf2965..93898f0 100644
--- a/test/maat_ex_data_gtest.cpp
+++ b/test/maat_ex_data_gtest.cpp
@@ -9,8 +9,8 @@
#include <gtest/gtest.h>
#include <limits.h>
-const char *table_info_path = "./table_info.conf";
-const char *json_filename = "maat_json.json";
+const char *g_table_info_path = "./table_info.conf";
+const char *g_json_filename = "maat_json.json";
struct log_handle *g_logger = NULL;
struct maat *g_maat_inst = NULL;
@@ -133,7 +133,7 @@ int main(int argc, char ** argv)
char json_iris_path[NAME_MAX] = {0};
char tmp_iris_path[PATH_MAX] = {0};
- snprintf(json_iris_path, sizeof(json_iris_path), "./%s_iris_tmp", json_filename);
+ snprintf(json_iris_path, sizeof(json_iris_path), "./%s_iris_tmp", g_json_filename);
if ((access(json_iris_path, F_OK)) == 0) {
system_cmd_rmdir(json_iris_path);
}
@@ -142,10 +142,10 @@ int main(int argc, char ** argv)
char *json_buff = NULL;
size_t json_buff_sz = 0;
- int ret = load_file_to_memory(json_filename, (unsigned char**)&json_buff, &json_buff_sz);
+ int ret = load_file_to_memory(g_json_filename, (unsigned char**)&json_buff, &json_buff_sz);
EXPECT_NE(ret, -1);
- ret = json2iris(json_buff, json_filename, NULL, tmp_iris_path, sizeof(tmp_iris_path),
+ ret = json2iris(json_buff, g_json_filename, NULL, tmp_iris_path, sizeof(tmp_iris_path),
NULL, NULL, g_logger);
FREE(json_buff);
EXPECT_NE(ret, -1);
@@ -153,10 +153,10 @@ int main(int argc, char ** argv)
struct maat_options *opts = maat_options_new();
char json_path[PATH_MAX] = {0};
- snprintf(json_path, sizeof(json_path), "./%s", json_filename);
+ snprintf(json_path, sizeof(json_path), "./%s", g_json_filename);
maat_options_set_json_file(opts, json_path);
- g_maat_inst = maat_new(opts, table_info_path);
+ g_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
EXPECT_TRUE(g_maat_inst != NULL);
diff --git a/test/maat_framework_gtest.cpp b/test/maat_framework_gtest.cpp
index 56603c4..3c74a01 100644
--- a/test/maat_framework_gtest.cpp
+++ b/test/maat_framework_gtest.cpp
@@ -2,6 +2,7 @@
#include <dirent.h>
#include <openssl/md5.h>
+#include "test_utils.h"
#include "maat.h"
#include "maat_rule.h"
#include "maat_utils.h"
@@ -18,286 +19,12 @@
#define HIT_PATH_SIZE 128
#define WAIT_FOR_EFFECTIVE_S 2
-const char *table_info_path = "./table_info.conf";
-const char *json_path ="./maat_json.json";
-const char *json_filename = "maat_json.json";
+const char *g_table_info_path = "./table_info.conf";
+const char *g_json_filename = "maat_json.json";
size_t g_thread_num = 4;
-int count_line_num_cb(const char *table_name, const char *line, void *u_para)
-{
- (*((unsigned int *)u_para))++;
- return 0;
-}
-
-int line_idx = 0;
-long long absolute_expire_time = 0;
-int make_serial_rule(const char *table_name, const char *line, void *u_para)
-{
- struct serial_rule *s_rule=(struct serial_rule *)u_para;
- redisContext *ctx = s_rule->ref_ctx;
- char *buff = ALLOC(char, strlen(line) + 1);
-
- memcpy(buff, line, strlen(line) + 1);
- while (buff[strlen(line) - 1] == '\n' || buff[strlen(line) - 1] == '\t') {
- buff[strlen(line) - 1] = '\0';
- }
-
- const char *redis_rule_key = "TEST_RULE_KEY";
- redisReply *reply = maat_wrap_redis_command(ctx, NULL, "INCRBY %s %d",
- redis_rule_key, 1);
- if (reply->type == REDIS_REPLY_NIL) {
- printf("incrby redis_rule_key:%s failed.", redis_rule_key);
- return -1;
- } else {
- s_rule->rule_id = maat_read_redis_integer(reply);
- freeReplyObject(reply);
- reply = NULL;
- }
-
- maat_set_serial_rule(s_rule + line_idx, MAAT_OP_ADD, s_rule->rule_id,
- table_name, buff, absolute_expire_time);
- (s_rule + line_idx)->ref_ctx = ctx;
- line_idx++;
-
- FREE(buff);
-
- return 0;
-}
-
-int write_config_to_redis(char *redis_ip, int redis_port, int redis_db,
- struct log_handle *logger)
-{
- char json_iris_path[512] = {0};
-
- snprintf(json_iris_path, sizeof(json_iris_path), "./%s_iris_tmp",
- json_filename);
-
- redisContext *c = maat_connect_redis(redis_ip, redis_port, redis_db, logger);
- if (NULL == c) {
- return -1;
- }
-
- redisReply *reply = maat_wrap_redis_command(c, logger, "flushdb");
- if (NULL == reply) {
- return -1;
- } else {
- freeReplyObject(reply);
- reply = NULL;
- }
-
- if (0 == access(json_iris_path, F_OK)) {
- system_cmd_rmdir(json_iris_path);
- }
-
- if (access(json_iris_path, F_OK) < 0) {
- char tmp_iris_path[128] = {0};
- char *json_buff = NULL;
- size_t json_buff_sz = 0;
-
- int ret = load_file_to_memory(json_filename, (unsigned char **)&json_buff,
- &json_buff_sz);
- if (ret < 0) {
- return -1;
- }
-
- ret = json2iris(json_buff, json_filename, c, tmp_iris_path,
- sizeof(tmp_iris_path), NULL, NULL, logger);
- FREE(json_buff);
- if (ret < 0) {
- return -1;
- }
- }
-
- size_t total_line_cnt = 0;
- char tmp_iris_full_idx_path[PATH_MAX] = {0};
- snprintf(tmp_iris_full_idx_path, sizeof(tmp_iris_full_idx_path), "%s/index",
- json_iris_path);
- config_monitor_traverse(0, tmp_iris_full_idx_path, NULL, count_line_num_cb,
- NULL, &total_line_cnt, NULL, logger);
-
- struct serial_rule *s_rule = ALLOC(struct serial_rule, total_line_cnt);
- s_rule->ref_ctx = c;
- long long server_time = maat_redis_server_time_s(c);
- if (server_time < 0) {
- return -1;
- }
- absolute_expire_time = server_time + 300;
- config_monitor_traverse(0, tmp_iris_full_idx_path, NULL, make_serial_rule,
- NULL, s_rule, NULL, logger);
- s_rule->ref_ctx = NULL;
- line_idx = 0;
- absolute_expire_time = 0;
-
- int success_cnt = 0;
- do {
- success_cnt = maat_cmd_write_rule(c, s_rule, total_line_cnt,
- server_time, logger);
- } while (success_cnt < 0);
-
- EXPECT_EQ(success_cnt, (int)total_line_cnt);
-
- for (size_t i = 0; i < total_line_cnt; i++) {
- maat_clear_rule_cache(s_rule + i);
- }
- FREE(s_rule);
- redisFree(c);
-
- return 0;
-}
-
-int compile_table_set_line(struct maat *maat_inst, const char *table_name,
- enum maat_operation op, long long compile_id,
- const char *user_region, int clause_num,
- int expire_after)
-{
- char table_line[1024 * 16] = {0};
- sprintf(table_line, "%lld\t0\t0\t0\t0\t0\t%s\t%d\t%d\t0.0",
- compile_id, user_region, clause_num, op);
-
- struct maat_cmd_line line_rule;
- line_rule.rule_id = compile_id;
- line_rule.table_line = table_line;
- line_rule.table_name = table_name;
- line_rule.expire_after = expire_after;
-
- return maat_cmd_set_line(maat_inst, &line_rule);
-}
-
-#define TO_GROUP2X_KEY(group_id, parent_id, clause_index) (((unsigned long)group_id<<32|parent_id) + clause_index)
-
-int group2compile_table_set_line(struct maat *maat_inst, const char *table_name,
- enum maat_operation op, long long group_id,
- long long compile_id, int not_flag,
- const char *vtable_name, int clause_index,
- int expire_after)
-{
- char table_line[128] = {0};
- sprintf(table_line, "%lld\t%lld\t%d\t%s\t%d\t%d",
- group_id, compile_id, not_flag, vtable_name, clause_index, op);
-
- struct maat_cmd_line line_rule;
- line_rule.rule_id = TO_GROUP2X_KEY(group_id, compile_id, clause_index);
- line_rule.table_line = table_line;
- line_rule.table_name = table_name;
- line_rule.expire_after = expire_after;
-
- return maat_cmd_set_line(maat_inst, &line_rule);
-}
-
-int group2group_table_set_line(struct maat *maat_inst, const char *table_name,
- enum maat_operation op, long long group_id,
- long long sub_group_id, int expire_after)
-{
- char table_line[128] = {0};
- sprintf(table_line, "%lld\t%lld\t%s\t%d", group_id, sub_group_id,
- "null", op);
-
- struct maat_cmd_line line_rule;
- line_rule.rule_id = TO_GROUP2X_KEY(group_id, sub_group_id, 0);
- line_rule.table_line = table_line;
- line_rule.table_name = table_name;
- line_rule.expire_after = expire_after;
-
- return maat_cmd_set_line(maat_inst, &line_rule);
-}
-
-int expr_table_set_line(struct maat *maat_inst, const char *table_name,
- enum maat_operation op, long long item_id,
- long long group_id, const char *keywords,
- const char *district, int expr_type,
- int match_method, int is_hexbin, int expire_after)
-{
- char table_line[1024] = {0};
- int table_id = maat_get_table_id(maat_inst, table_name);
- if (table_id < 0) {
- return 0;
- }
-
- enum table_type table_type = table_manager_get_table_type(maat_inst->tbl_mgr,
- table_id);
- assert(table_type == TABLE_TYPE_EXPR || table_type == TABLE_TYPE_EXPR_PLUS);
-
- if (table_type == TABLE_TYPE_EXPR_PLUS) {
- sprintf(table_line, "%lld\t%lld\t%s\t%s\t%d\t%d\t%d\t%d",
- item_id, group_id, district, keywords, expr_type,
- match_method, is_hexbin, op);
- } else {
- sprintf(table_line, "%lld\t%lld\t%s\t%d\t%d\t%d\t%d",
- item_id, group_id, keywords, expr_type,
- match_method, is_hexbin, op);
- }
-
- struct maat_cmd_line line_rule;
- line_rule.rule_id = item_id;
- line_rule.table_line = table_line;
- line_rule.table_name = table_name;
- line_rule.expire_after = expire_after;
-
- return maat_cmd_set_line(maat_inst, &line_rule);
-}
-
-int
-interval_table_set_line(struct maat *maat_inst, const char *table_name,
- enum maat_operation op, long long item_id, long long group_id,
- unsigned int low_boundary, unsigned int up_boundary,
- const char *district, int expire_after)
-{
- char table_line[1024] = {0};
- int table_id = maat_get_table_id(maat_inst, table_name);
- if (table_id < 0) {
- return 0;
- }
-
- enum table_type table_type = table_manager_get_table_type(maat_inst->tbl_mgr,
- table_id);
- assert(table_type == TABLE_TYPE_INTERVAL || table_type == TABLE_TYPE_INTERVAL_PLUS);
-
- if (table_type == TABLE_TYPE_INTERVAL_PLUS) {
- sprintf(table_line, "%lld\t%lld\t%s\t%u\t%u\t%d",
- item_id, group_id, district, low_boundary, up_boundary, op);
- } else {
- sprintf(table_line, "%lld\t%lld\t%u\t%u\t%d",
- item_id, group_id, low_boundary, up_boundary, op);
- }
-
- struct maat_cmd_line line_rule;
- line_rule.rule_id = item_id;
- line_rule.table_line = table_line;
- line_rule.table_name = table_name;
- line_rule.expire_after = expire_after;
-
- return maat_cmd_set_line(maat_inst, &line_rule);
-}
-
-int ip_table_set_line(struct maat *maat_inst, const char *table_name,
- enum maat_operation op, long long item_id,
- long long group_id, enum IP_TYPE type, const char *ip1,
- const char *ip2, int expire_after)
-{
- char table_line[1024] = {0};
- int table_id = maat_get_table_id(maat_inst, table_name);
- if (table_id < 0) {
- return 0;
- }
-
- int ip_type = IPV4;
- if (type == IPv6) {
- ip_type = IPV6;
- }
-
- sprintf(table_line, "%lld\t%lld\t%d\t%s\t%s\t%s\t%d",
- item_id, group_id, ip_type, "range", ip1, ip2, op);
- struct maat_cmd_line line_rule;
-
- line_rule.rule_id = item_id;
- line_rule.table_line = table_line;
- line_rule.table_name = table_name;
- line_rule.expire_after = expire_after;
-
- return maat_cmd_set_line(maat_inst, &line_rule);
-}
int test_add_expr_command(struct maat *maat_inst, const char *expr_table,
long long compile_id, int timeout,
@@ -369,7 +96,7 @@ protected:
maat_options_set_json_file_decrypt_key(opts, json_decrypt_key);
maat_options_set_rule_update_checking_interval_ms(opts, scan_interval_ms);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -467,7 +194,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__);
@@ -481,7 +208,7 @@ protected:
maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_hit_path_enabled(opts);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -773,7 +500,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -789,7 +516,7 @@ protected:
maat_options_set_hit_path_enabled(opts);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -1685,7 +1412,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -1701,7 +1428,7 @@ protected:
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
maat_options_set_hit_path_enabled(opts);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -2607,18 +2334,17 @@ protected:
maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
assert(_shared_maat_inst != NULL);
maat_cmd_flushDB(_shared_maat_inst);
maat_free(_shared_maat_inst);
maat_options_set_foreign_cont_dir(opts, "./foreign_files/");
- maat_options_set_rule_effect_interval_ms(opts, 0);
maat_options_set_gc_timeout_ms(opts, 0); // start GC immediately
maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2721,19 +2447,18 @@ protected:
maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
assert(_shared_maat_inst != NULL);
maat_cmd_flushDB(_shared_maat_inst);
maat_free(_shared_maat_inst);
maat_options_set_foreign_cont_dir(opts, "./foreign_files/");
- maat_options_set_rule_effect_interval_ms(opts, 0);
maat_options_set_gc_timeout_ms(opts, 0); // start GC immediately
maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2828,7 +2553,7 @@ TEST_F(MaatRsStreamScan, dynamic_config) {
state = NULL;
}
-class MaatIPScan : public testing::Test
+class IPScan : public testing::Test
{
protected:
static void SetUpTestCase() {
@@ -2839,7 +2564,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -2853,11 +2578,11 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
- "[%s:%d] create maat instance in MaatIPScan failed.",
+ "[%s:%d] create maat instance in IPScan failed.",
__FUNCTION__, __LINE__);
}
}
@@ -2871,12 +2596,12 @@ protected:
static struct maat *_shared_maat_inst;
};
-struct maat *MaatIPScan::_shared_maat_inst;
-struct log_handle *MaatIPScan::logger;
+struct maat *IPScan::_shared_maat_inst;
+struct log_handle *IPScan::logger;
-TEST_F(MaatIPScan, IPv4ScanDataFull_0) {
+TEST_F(IPScan, IPv4Unspecified) {
const char *table_name = "IP_PLUS_CONFIG";
- struct maat *maat_inst = MaatIPScan::_shared_maat_inst;
+ struct maat *maat_inst = IPScan::_shared_maat_inst;
int thread_id = 0;
int table_id = maat_get_table_id(maat_inst, table_name);
@@ -2903,9 +2628,9 @@ TEST_F(MaatIPScan, IPv4ScanDataFull_0) {
state = NULL;
}
-TEST_F(MaatIPScan, IPv4ScanDataFull_1) {
+TEST_F(IPScan, IPv4Broadcast) {
const char *table_name = "IP_PLUS_CONFIG";
- struct maat *maat_inst = MaatIPScan::_shared_maat_inst;
+ struct maat *maat_inst = IPScan::_shared_maat_inst;
int thread_id = 0;
int table_id = maat_get_table_id(maat_inst, table_name);
@@ -2932,9 +2657,9 @@ TEST_F(MaatIPScan, IPv4ScanDataFull_1) {
state = NULL;
}
-TEST_F(MaatIPScan, IPv4RuleFull_0) {
+TEST_F(IPScan, MatchSingleIPv4) {
const char *table_name = "IP_PLUS_CONFIG";
- struct maat *maat_inst = MaatIPScan::_shared_maat_inst;
+ struct maat *maat_inst = IPScan::_shared_maat_inst;
int thread_id = 0;
int table_id = maat_get_table_id(maat_inst, table_name);
@@ -2962,9 +2687,9 @@ TEST_F(MaatIPScan, IPv4RuleFull_0) {
state = NULL;
}
-TEST_F(MaatIPScan, IPv6ScanDataFull_0) {
+TEST_F(IPScan, IPv6Unspecified) {
const char *table_name = "IP_PLUS_CONFIG";
- struct maat *maat_inst = MaatIPScan::_shared_maat_inst;
+ struct maat *maat_inst = IPScan::_shared_maat_inst;
int thread_id = 0;
int table_id = maat_get_table_id(maat_inst, table_name);
@@ -2991,9 +2716,9 @@ TEST_F(MaatIPScan, IPv6ScanDataFull_0) {
maat_state_free(state);
}
-TEST_F(MaatIPScan, IPv6ScanDataFull_1) {
+TEST_F(IPScan, IPv6Broadcast) {
const char *table_name = "IP_PLUS_CONFIG";
- struct maat *maat_inst = MaatIPScan::_shared_maat_inst;
+ struct maat *maat_inst = IPScan::_shared_maat_inst;
int thread_id = 0;
int table_id = maat_get_table_id(maat_inst, table_name);
@@ -3019,9 +2744,9 @@ TEST_F(MaatIPScan, IPv6ScanDataFull_1) {
maat_state_free(state);
}
-TEST_F(MaatIPScan, IPv6RuleFull_0) {
+TEST_F(IPScan, MatchSingleIPv6) {
const char *table_name = "IP_PLUS_CONFIG";
- struct maat *maat_inst = MaatIPScan::_shared_maat_inst;
+ struct maat *maat_inst = IPScan::_shared_maat_inst;
int thread_id = 0;
int table_id = maat_get_table_id(maat_inst, table_name);
@@ -3050,9 +2775,9 @@ TEST_F(MaatIPScan, IPv6RuleFull_0) {
state = NULL;
}
-TEST_F(MaatIPScan, IPv4_IPPort) {
+TEST_F(IPScan, MatchIPv4Range) {
const char *table_name = "IP_PLUS_CONFIG";
- struct maat *maat_inst = MaatIPScan::_shared_maat_inst;
+ struct maat *maat_inst = IPScan::_shared_maat_inst;
int thread_id = 0;
int table_id = maat_get_table_id(maat_inst, table_name);
@@ -3080,10 +2805,39 @@ TEST_F(MaatIPScan, IPv4_IPPort) {
maat_state_free(state);
state = NULL;
}
+TEST_F(IPScan, MatchIPv4Port) {
+ const char *table_name = "IP_PLUS_CONFIG";
+ struct maat *maat_inst = IPScan::_shared_maat_inst;
+ int thread_id = 0;
+
+ int table_id = maat_get_table_id(maat_inst, table_name);
+ ASSERT_GT(table_id, 0);
+
+ char ip_str[32] = "192.168.30.44";
+ uint32_t sip;
+ int ret = inet_pton(AF_INET, ip_str, &sip);
+ EXPECT_EQ(ret, 1);
+
+ long long results[ARRAY_SIZE] = {0};
+ size_t n_hit_result = 0;
+ struct maat_state *state = maat_state_new(maat_inst, thread_id);
+ ret = maat_scan_ipv4_port(maat_inst, table_id, sip, 443, results, ARRAY_SIZE,
+ &n_hit_result, state);
+ EXPECT_EQ(ret, MAAT_SCAN_OK);
+ EXPECT_EQ(n_hit_result, 0);
-TEST_F(MaatIPScan, IPv6_IPPort) {
+ ret = maat_scan_ipv4_port(maat_inst, table_id, sip, 80, results, ARRAY_SIZE,
+ &n_hit_result, state);
+ EXPECT_EQ(ret, MAAT_SCAN_HIT);
+ EXPECT_EQ(n_hit_result, 1);
+ EXPECT_EQ(results[0], 232);
+
+ maat_state_free(state);
+ state = NULL;
+}
+TEST_F(IPScan, MatchIPv6Range) {
const char *table_name = "IP_PLUS_CONFIG";
- struct maat *maat_inst = MaatIPScan::_shared_maat_inst;
+ struct maat *maat_inst = IPScan::_shared_maat_inst;
int thread_id = 0;
int table_id = maat_get_table_id(maat_inst, table_name);
@@ -3109,10 +2863,43 @@ TEST_F(MaatIPScan, IPv6_IPPort) {
maat_state_free(state);
state = NULL;
}
+TEST_F(IPScan, MatchIPv6Port) {
+ const char *table_name = "IP_PLUS_CONFIG";
+ struct maat *maat_inst = IPScan::_shared_maat_inst;
+ int thread_id = 0;
+
+ int table_id = maat_get_table_id(maat_inst, table_name);
+ char ip_str[32] = "2607:5d00:2:2::32:28";
+ int port=443;
+ uint8_t sip[16];
+ int ret = inet_pton(AF_INET6, ip_str, &sip);
+ EXPECT_EQ(ret, 1);
-TEST_F(MaatIPScan, BugReport20210515) {
+ long long results[ARRAY_SIZE] = {0};
+ size_t n_hit_result = 0;
+ struct maat_state *state = maat_state_new(maat_inst, thread_id);
+ ret = maat_scan_ipv6_port(maat_inst, table_id, sip, port, results, ARRAY_SIZE,
+ &n_hit_result, state);
+ EXPECT_EQ(ret, MAAT_SCAN_HIT);
+ EXPECT_EQ(n_hit_result, 2);
+ EXPECT_EQ(results[0], 230);
+ EXPECT_EQ(results[1], 210);
+
+ maat_state_reset(state);
+ //If the port is not present, should not match rules with port range. In this case, only rule 210 "::/0" should match.
+ ret = maat_scan_ipv6(maat_inst, table_id, sip, results, ARRAY_SIZE,
+ &n_hit_result, state);
+ EXPECT_EQ(ret, MAAT_SCAN_HIT);
+ EXPECT_EQ(n_hit_result, 1);
+ EXPECT_EQ(results[0], 210);
+
+ maat_state_free(state);
+ state = NULL;
+}
+
+TEST_F(IPScan, BugReport20210515) {
const char *table_name = "IP_CONFIG";
- struct maat *maat_inst = MaatIPScan::_shared_maat_inst;
+ struct maat *maat_inst = IPScan::_shared_maat_inst;
int thread_id = 0;
int table_id = maat_get_table_id(maat_inst, table_name);
@@ -3136,9 +2923,9 @@ TEST_F(MaatIPScan, BugReport20210515) {
state = NULL;
}
-TEST_F(MaatIPScan, dynamic_config) {
+TEST_F(IPScan, RuleUpdates) {
const char *table_name = "IP_PLUS_CONFIG";
- struct maat *maat_inst = MaatIPScan::_shared_maat_inst;
+ struct maat *maat_inst = IPScan::_shared_maat_inst;
int thread_id = 0;
int table_id = maat_get_table_id(maat_inst, table_name);
@@ -3236,7 +3023,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__);
@@ -3249,7 +3036,7 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -3372,7 +3159,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__);
@@ -3385,7 +3172,7 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -3471,7 +3258,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -3485,7 +3272,7 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -4730,7 +4517,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -4744,7 +4531,7 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -5117,7 +4904,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -5131,7 +4918,7 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_DEBUG);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -5381,7 +5168,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -5395,7 +5182,7 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -5521,7 +5308,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -5535,7 +5322,7 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -5661,7 +5448,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -5675,7 +5462,7 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -5832,7 +5619,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -5846,7 +5633,7 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -5919,7 +5706,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -5933,7 +5720,7 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -5985,7 +5772,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -6000,7 +5787,7 @@ protected:
maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_hit_path_enabled(opts);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -6138,7 +5925,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -6153,7 +5940,7 @@ protected:
maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_hit_path_enabled(opts);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -6320,7 +6107,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -6335,7 +6122,7 @@ protected:
maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_hit_path_enabled(opts);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -6732,7 +6519,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -6746,7 +6533,7 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -6806,8 +6593,6 @@ protected:
static void SetUpTestCase() {
const char *rule_folder = "./ntcrule/full/index";
const char *table_info = "./file_test_tableinfo.conf";
- int scan_interval_ms = 500;
- int effective_interval_ms = 0;
struct maat_options *opts = maat_options_new();
maat_options_set_caller_thread_number(opts, g_thread_num);
@@ -6815,8 +6600,7 @@ protected:
maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
maat_options_set_iris(opts, rule_folder, rule_folder);
- maat_options_set_rule_update_checking_interval_ms(opts, scan_interval_ms);
- maat_options_set_rule_effect_interval_ms(opts, effective_interval_ms);
+ maat_options_set_rule_update_checking_interval_ms(opts, 500);
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
_shared_maat_inst = maat_new(opts, table_info);
@@ -6909,7 +6693,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -6923,7 +6707,7 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -7282,15 +7066,14 @@ protected:
maat_options_set_hit_path_enabled(opts);
maat_options_set_hit_group_enabled(opts);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
assert(_shared_maat_inst != NULL);
maat_cmd_flushDB(_shared_maat_inst);
maat_free(_shared_maat_inst);
maat_options_set_foreign_cont_dir(opts, "./foreign_files/");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
_ex_data_counter = ALLOC(int, 1);
@@ -11207,7 +10990,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__);
@@ -11220,7 +11003,7 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -11368,7 +11151,7 @@ TEST_F(MaatRollbackTest, FullConfigRollback) {
ret = clear_config_in_redis(c, logger);
EXPECT_EQ(ret, 0);
- ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
EXPECT_EQ(ret, 0);
ret = rollback_redis_version(c, logger);
@@ -11428,7 +11211,7 @@ TEST_F(MaatRollbackTest, FullConfigRollbackWhenScanUnfinished) {
ret = clear_config_in_redis(c, logger);
EXPECT_EQ(ret, 0);
- ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
EXPECT_EQ(ret, 0);
ret = rollback_redis_version(c, logger);
diff --git a/test/maat_framework_perf_gtest.cpp b/test/maat_framework_perf_gtest.cpp
index 8c1fded..d7f3181 100644
--- a/test/maat_framework_perf_gtest.cpp
+++ b/test/maat_framework_perf_gtest.cpp
@@ -1,5 +1,6 @@
#include <gtest/gtest.h>
+#include "test_utils.h"
#include "log/log.h"
#include "maat.h"
#include "maat_rule.h"
@@ -17,8 +18,8 @@
#define PERF_THREAD_NUM 5
#define PERF_SCAN_TIMES 1000 * 1000
-const char *table_info_path = "./table_info.conf";
-const char *json_filename = "maat_json.json";
+const char *g_table_info_path = "./table_info.conf";
+const char *g_json_filename = "maat_json.json";
struct thread_param {
int thread_id;
@@ -40,282 +41,7 @@ void random_keyword_generate(char *keyword_buf, size_t sz)
keyword_buf[i] = '\0';
}
-int count_line_num_cb(const char *table_name, const char *line, void *u_para)
-{
- (*((unsigned int *)u_para))++;
- return 0;
-}
-
-int line_idx = 0;
-long long absolute_expire_time=0;
-int make_serial_rule(const char *table_name, const char *line, void *u_para)
-{
- struct serial_rule *s_rule=(struct serial_rule *)u_para;
- long long rule_id = 0;
- char *buff = ALLOC(char, strlen(line) + 1);
-
- memcpy(buff, line, strlen(line) + 1);
- while (buff[strlen(buff) - 1] == '\n' || buff[strlen(buff) - 1] == '\t') {
- buff[strlen(buff) - 1] = '\0';
- }
-
- int j = 0;
- char *str1 = NULL;
- char *token = NULL;
- char *saveptr1 = NULL;
-
- for (j = 0,str1 = buff; ; j++, str1 = NULL) {
- token = strtok_r(str1, "\t ", &saveptr1);
- if (token == NULL)
- break;
- if (j == 0) {
- sscanf(token,"%lld", &rule_id);
- }
- }
-
- memcpy(buff, line, strlen(line)+1);
- while(buff[strlen(buff)-1]=='\n'||buff[strlen(buff)-1]=='\t') {
- buff[strlen(buff)-1]='\0';
- }
-
- maat_set_serial_rule(s_rule + line_idx, MAAT_OP_ADD, rule_id, table_name,
- buff, absolute_expire_time);
- line_idx++;
-
- FREE(buff);
-
- return 0;
-}
-
-static int
-write_config_to_redis(const char *json_iris_path,
- char *redis_ip, int redis_port,
- int redis_db, struct log_handle *logger)
-{
- redisContext *c =
- maat_connect_redis(redis_ip, redis_port, redis_db, logger);
- if (NULL == c) {
- return -1;
- }
-
- redisReply *reply = maat_wrap_redis_command(c, logger, "flushdb");
- if (NULL == reply) {
- return -1;
- } else {
- freeReplyObject(reply);
- reply = NULL;
- }
-
- if (access(json_iris_path, F_OK) < 0) {
- char tmp_iris_path[128] = {0};
- char *json_buff = NULL;
- size_t json_buff_sz = 0;
-
- int ret = load_file_to_memory(json_filename,
- (unsigned char **)&json_buff,
- &json_buff_sz);
- if (ret < 0) {
- return -1;
- }
-
- ret = json2iris(json_buff, json_filename, c, tmp_iris_path,
- sizeof(tmp_iris_path), NULL, NULL, logger);
- FREE(json_buff);
- if (ret < 0) {
- return -1;
- }
- }
-
- size_t total_line_cnt = 0;
- char tmp_iris_full_idx_path[PATH_MAX] = {0};
- snprintf(tmp_iris_full_idx_path, sizeof(tmp_iris_full_idx_path),
- "%s/index", json_iris_path);
-
- config_monitor_traverse(0, tmp_iris_full_idx_path, NULL,
- count_line_num_cb, NULL, &total_line_cnt,
- NULL, logger);
-
- struct serial_rule *s_rule = ALLOC(struct serial_rule, total_line_cnt);
- long long server_time = maat_redis_server_time_s(c);
- if (server_time < 0) {
- return -1;
- }
-
- //absolute_expire_time = server_time + 300;
- config_monitor_traverse(0, tmp_iris_full_idx_path, NULL,
- make_serial_rule, NULL, s_rule,
- NULL, logger);
- line_idx = 0;
- absolute_expire_time = 0;
-
- int success_cnt = 0;
- do {
- success_cnt = maat_cmd_write_rule(c, s_rule, total_line_cnt,
- server_time, logger);
- } while (success_cnt < 0);
-
- EXPECT_EQ(success_cnt, (int)total_line_cnt);
-
- for (size_t i = 0; i < total_line_cnt; i++) {
- maat_clear_rule_cache(s_rule + i);
- }
- FREE(s_rule);
- redisFree(c);
-
- return 0;
-}
-
-static int
-compile_table_set_line(struct maat *maat_inst, const char *table_name,
- enum maat_operation op, long long compile_id,
- const char *user_region, int clause_num,
- int expire_after)
-{
- char table_line[1024 * 16] = {0};
- sprintf(table_line, "%lld\t0\t0\t0\t0\t0\t%s\t%d\t%d\t0.0",
- compile_id, user_region, clause_num, op);
-
- struct maat_cmd_line line_rule;
- line_rule.rule_id = compile_id;
- line_rule.table_line = table_line;
- line_rule.table_name = table_name;
- line_rule.expire_after = expire_after;
-
- return maat_cmd_set_line(maat_inst, &line_rule);
-}
-static int
-group2compile_table_set_line(struct maat *maat_inst, const char *table_name,
- enum maat_operation op, long long group_id,
- long long compile_id, int not_flag,
- const char *vtable_name, int clause_index,
- int expire_after)
-{
- char table_line[128] = {0};
- sprintf(table_line, "%lld\t%lld\t%d\t%s\t%d\t%d",
- group_id, compile_id, not_flag, vtable_name, clause_index, op);
-
- struct maat_cmd_line line_rule;
- line_rule.rule_id = group_id;
- line_rule.table_line = table_line;
- line_rule.table_name = table_name;
- line_rule.expire_after = expire_after;
-
- return maat_cmd_set_line(maat_inst, &line_rule);
-}
-
-static int
-expr_table_set_line(struct maat *maat_inst, const char *table_name,
- enum maat_operation op, long long item_id,
- long long group_id, const char *keywords,
- const char *district, int expr_type,
- int match_method, int is_hexbin, int expire_after)
-{
- char table_line[1024] = {0};
- int table_id = maat_get_table_id(maat_inst, table_name);
- if (table_id < 0) {
- return 0;
- }
-
- enum table_type table_type =
- table_manager_get_table_type(maat_inst->tbl_mgr, table_id);
- assert(table_type == TABLE_TYPE_EXPR || table_type == TABLE_TYPE_EXPR_PLUS);
-
- if (table_type == TABLE_TYPE_EXPR_PLUS) {
- sprintf(table_line, "%lld\t%lld\t%s\t%s\t%d\t%d\t%d\t%d",
- item_id, group_id, district, keywords, expr_type,
- match_method, is_hexbin, op);
- } else {
- sprintf(table_line, "%lld\t%lld\t%s\t%d\t%d\t%d\t%d",
- item_id, group_id, keywords, expr_type,
- match_method, is_hexbin, op);
- }
-
- struct maat_cmd_line line_rule;
- line_rule.rule_id = item_id;
- line_rule.table_line = table_line;
- line_rule.table_name = table_name;
- line_rule.expire_after = expire_after;
-
- return maat_cmd_set_line(maat_inst, &line_rule);
-}
-
-static int
-ip_table_set_line(struct maat *maat_inst, const char *table_name,
- enum maat_operation op, long long item_id,
- long long group_id, enum IP_TYPE type,
- const char *ip1, const char *ip2, int expire_after)
-{
- char table_line[1024] = {0};
- int table_id = maat_get_table_id(maat_inst, table_name);
- if (table_id < 0) {
- return 0;
- }
-
- int ip_type = IPV4;
- if (type == IPv6) {
- ip_type = IPV6;
- }
-
- sprintf(table_line, "%lld\t%lld\t%d\t%s\t%s\t%s\t%d",
- item_id, group_id, ip_type, "range", ip1, ip2, op);
- struct maat_cmd_line line_rule;
-
- line_rule.rule_id = item_id;
- line_rule.table_line = table_line;
- line_rule.table_name = table_name;
- line_rule.expire_after = expire_after;
-
- return maat_cmd_set_line(maat_inst, &line_rule);
-}
-
-static int
-integer_table_set_line(struct maat *maat_inst, const char *table_name,
- enum maat_operation op, long long item_id,
- long long group_id, int low_boundary,
- int up_boundary, int expire_after)
-{
- char table_line[1024] = {0};
- int table_id = maat_get_table_id(maat_inst, table_name);
- if (table_id < 0) {
- return 0;
- }
-
- sprintf(table_line, "%lld\t%lld\t%d\t%d\t%d",
- item_id, group_id, low_boundary, up_boundary, op);
- struct maat_cmd_line line_rule;
-
- line_rule.rule_id = item_id;
- line_rule.table_line = table_line;
- line_rule.table_name = table_name;
- line_rule.expire_after = expire_after;
-
- return maat_cmd_set_line(maat_inst, &line_rule);
-}
-
-static int
-flag_table_set_line(struct maat *maat_inst, const char *table_name,
- enum maat_operation op, long long item_id,
- long long group_id, long long flag,
- long long flag_mask, int expire_after)
-{
- char table_line[1024] = {0};
- int table_id = maat_get_table_id(maat_inst, table_name);
- if (table_id < 0) {
- return 0;
- }
-
- sprintf(table_line, "%lld\t%lld\t%lld\t%lld\t%d",
- item_id, group_id, flag, flag_mask, op);
- struct maat_cmd_line line_rule;
-
- line_rule.rule_id = item_id;
- line_rule.table_line = table_line;
- line_rule.table_name = table_name;
- line_rule.expire_after = expire_after;
-
- return maat_cmd_set_line(maat_inst, &line_rule);
-}
static void
test_add_expr_command(struct maat *maat_inst, const char *table_name,
@@ -378,8 +104,8 @@ test_add_integer_command(struct maat *maat_inst, const char *table_name,
EXPECT_EQ(ret, 1);
long long item_id = maat_cmd_incrby(maat_inst, "SEQUENCE_REGION", 1);
- ret = integer_table_set_line(maat_inst, table_name, MAAT_OP_ADD, item_id,
- group_id, low_boundary, up_boundary, 0);
+ ret = interval_table_set_line(maat_inst, table_name, MAAT_OP_ADD, item_id,
+ group_id, low_boundary, up_boundary, NULL, 0);
EXPECT_EQ(ret, 1);
}
@@ -415,12 +141,9 @@ protected:
char redis_ip[64] = "127.0.0.1";
int redis_port = 6379;
int redis_db = 0;
- char json_iris_path[512] = {0};
- snprintf(json_iris_path, sizeof(json_iris_path),
- "./%s_iris_tmp", json_filename);
logger = log_handle_create("./maat_framework_perf_gtest.log", 0);
- int ret = write_config_to_redis(json_iris_path, redis_ip, redis_port,
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port,
redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -437,7 +160,7 @@ protected:
maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_caller_thread_number(opts, 5);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -573,12 +296,9 @@ protected:
char redis_ip[64] = "127.0.0.1";
int redis_port = 6379;
int redis_db = 0;
- char json_iris_path[512] = {0};
-
- snprintf(json_iris_path, sizeof(json_iris_path),
- "./%s_iris_tmp", json_filename);
+
logger = log_handle_create("./maat_framework_perf_gtest.log", 0);
- int ret = write_config_to_redis(json_iris_path, redis_ip, redis_port,
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port,
redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -595,7 +315,7 @@ protected:
maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_caller_thread_number(opts, 5);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -786,12 +506,9 @@ protected:
char redis_ip[64] = "127.0.0.1";
int redis_port = 6379;
int redis_db = 0;
- char json_iris_path[512] = {0};
-
- snprintf(json_iris_path, sizeof(json_iris_path),
- "./%s_iris_tmp", json_filename);
+\
logger = log_handle_create("./maat_framework_perf_gtest.log", 0);
- int ret = write_config_to_redis(json_iris_path, redis_ip, redis_port,
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port,
redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -808,7 +525,7 @@ protected:
maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_caller_thread_number(opts, 5);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -924,12 +641,9 @@ protected:
char redis_ip[64] = "127.0.0.1";
int redis_port = 6379;
int redis_db = 0;
- char json_iris_path[512] = {0};
- snprintf(json_iris_path, sizeof(json_iris_path),
- "./%s_iris_tmp", json_filename);
logger = log_handle_create("./maat_framework_perf_gtest.log", 0);
- int ret = write_config_to_redis(json_iris_path, redis_ip, redis_port,
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port,
redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -946,7 +660,7 @@ protected:
maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_caller_thread_number(opts, 5);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -1096,12 +810,9 @@ protected:
char redis_ip[64] = "127.0.0.1";
int redis_port = 6379;
int redis_db = 0;
- char json_iris_path[512] = {0};
- snprintf(json_iris_path, sizeof(json_iris_path),
- "./%s_iris_tmp", json_filename);
logger = log_handle_create("./maat_framework_perf_gtest.log", 0);
- int ret = write_config_to_redis(json_iris_path, redis_ip, redis_port,
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port,
redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -1118,7 +829,7 @@ protected:
maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_caller_thread_number(opts, 5);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -1198,12 +909,9 @@ protected:
char redis_ip[64] = "127.0.0.1";
int redis_port = 6379;
int redis_db = 0;
- char json_iris_path[512] = {0};
- snprintf(json_iris_path, sizeof(json_iris_path),
- "./%s_iris_tmp", json_filename);
logger = log_handle_create("./maat_framework_perf_gtest.log", 0);
- int ret = write_config_to_redis(json_iris_path, redis_ip, redis_port,
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port,
redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -1220,7 +928,7 @@ protected:
maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_caller_thread_number(opts, 5);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -1353,12 +1061,9 @@ protected:
char redis_ip[64] = "127.0.0.1";
int redis_port = 6379;
int redis_db = 0;
- char json_iris_path[512] = {0};
- snprintf(json_iris_path, sizeof(json_iris_path),
- "./%s_iris_tmp", json_filename);
logger = log_handle_create("./maat_framework_perf_gtest.log", 0);
- int ret = write_config_to_redis(json_iris_path, redis_ip, redis_port,
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port,
redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -1375,7 +1080,7 @@ protected:
maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_caller_thread_number(opts, 5);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -1591,12 +1296,9 @@ protected:
char redis_ip[64] = "127.0.0.1";
int redis_port = 6379;
int redis_db = 0;
- char json_iris_path[512] = {0};
- snprintf(json_iris_path, sizeof(json_iris_path),
- "./%s_iris_tmp", json_filename);
logger = log_handle_create("./maat_framework_perf_gtest.log", 0);
- int ret = write_config_to_redis(json_iris_path, redis_ip, redis_port,
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port,
redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -1613,7 +1315,7 @@ protected:
maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_caller_thread_number(opts, 5);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -1949,12 +1651,10 @@ protected:
char redis_ip[64] = "127.0.0.1";
int redis_port = 6379;
int redis_db = 0;
- char json_iris_path[512] = {0};
const char *tsg_table_info = "./tsg_table_info.conf";
- snprintf(json_iris_path, sizeof(json_iris_path), "./tsgrule");
logger = log_handle_create("./maat_framework_perf_gtest.log", 0);
- int ret = write_config_to_redis(json_iris_path, redis_ip, redis_port,
+ int ret = write_iris_to_redis("./tsgrule", redis_ip, redis_port,
redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -2026,12 +1726,9 @@ protected:
char redis_ip[64] = "127.0.0.1";
int redis_port = 6379;
int redis_db = 0;
- char json_iris_path[512] = {0};
- snprintf(json_iris_path, sizeof(json_iris_path),
- "./%s_iris_tmp", json_filename);
logger = log_handle_create("./maat_framework_perf_gtest.log", 0);
- int ret = write_config_to_redis(json_iris_path, redis_ip, redis_port,
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port,
redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -2048,7 +1745,7 @@ protected:
maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_caller_thread_number(opts, 5);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
diff --git a/test/maat_input_mode_gtest.cpp b/test/maat_input_mode_gtest.cpp
index bc56414..ade4371 100644
--- a/test/maat_input_mode_gtest.cpp
+++ b/test/maat_input_mode_gtest.cpp
@@ -10,26 +10,26 @@
#define MODULE_INPUT_MODE_GTEST module_name_str("maat.input_mode_gtest")
-const char *table_info_path = "./table_info.conf";
-const char *json_filename = "maat_json.json";
+const char *g_table_info_path = "./table_info.conf";
+const char *g_json_filename = "maat_json.json";
struct log_handle *g_logger = NULL;
TEST(json_mode, maat_scan_string) {
char tmp_iris_path[PATH_MAX] = {0};
char json_iris_path[PATH_MAX] = {0};
snprintf(json_iris_path, sizeof(json_iris_path),
- "./%s_iris_tmp", json_filename);
+ "./%s_iris_tmp", g_json_filename);
if (access(json_iris_path, F_OK) < 0) {
char *json_buff = NULL;
size_t json_buff_sz = 0;
- int ret = load_file_to_memory(json_filename,
+ int ret = load_file_to_memory(g_json_filename,
(unsigned char**)&json_buff,
&json_buff_sz);
EXPECT_NE(ret, -1);
- ret = json2iris(json_buff, json_filename, NULL, tmp_iris_path,
+ ret = json2iris(json_buff, g_json_filename, NULL, tmp_iris_path,
sizeof(tmp_iris_path), NULL, NULL, g_logger);
FREE(json_buff);
EXPECT_NE(ret, -1);
@@ -37,13 +37,13 @@ TEST(json_mode, maat_scan_string) {
struct maat_options *opts = maat_options_new();
char json_path[PATH_MAX] = {0};
- snprintf(json_path, sizeof(json_path), "./%s", json_filename);
+ snprintf(json_path, sizeof(json_path), "./%s", g_json_filename);
maat_options_set_json_file(opts, json_path);
maat_options_set_stat_on(opts);
maat_options_set_perf_on(opts);
maat_options_set_logger(opts, "./maat_input_mode_gtest.log", LOG_LEVEL_INFO);
- struct maat *maat_inst = maat_new(opts, table_info_path);
+ struct maat *maat_inst = maat_new(opts, g_table_info_path);
EXPECT_TRUE(maat_inst != NULL);
const char *table_name = "KEYWORDS_TABLE";
@@ -70,18 +70,18 @@ TEST(iris_mode, maat_scan_string) {
char tmp_iris_path[512] = {0};
char json_iris_path[512] = {0};
snprintf(json_iris_path, sizeof(json_iris_path),
- "./%s_iris_tmp", json_filename);
+ "./%s_iris_tmp", g_json_filename);
if (access(json_iris_path, F_OK) < 0) {
char *json_buff = NULL;
size_t json_buff_sz = 0;
- int ret = load_file_to_memory(json_filename,
+ int ret = load_file_to_memory(g_json_filename,
(unsigned char**)&json_buff,
&json_buff_sz);
EXPECT_NE(ret, -1);
- ret = json2iris(json_buff, json_filename, NULL, tmp_iris_path,
+ ret = json2iris(json_buff, g_json_filename, NULL, tmp_iris_path,
sizeof(tmp_iris_path), NULL, NULL, g_logger);
FREE(json_buff);
EXPECT_NE(ret, -1);
@@ -100,7 +100,7 @@ TEST(iris_mode, maat_scan_string) {
maat_options_set_iris(opts, tmp_iris_full_idx_path, tmp_iris_inc_idx_path);
maat_options_set_logger(opts, "./maat_input_mode_gtest.log", LOG_LEVEL_INFO);
- struct maat *maat_inst = maat_new(opts, table_info_path);
+ struct maat *maat_inst = maat_new(opts, g_table_info_path);
EXPECT_TRUE(maat_inst != NULL);
const char *table_name = "KEYWORDS_TABLE";
@@ -171,7 +171,7 @@ TEST(redis_mode, maat_scan_string) {
int redis_db = 0;
snprintf(json_iris_path, sizeof(json_iris_path),
- "./%s_iris_tmp", json_filename);
+ "./%s_iris_tmp", g_json_filename);
redisContext *c =
maat_connect_redis(redis_ip, redis_port, redis_db, g_logger);
@@ -187,12 +187,12 @@ TEST(redis_mode, maat_scan_string) {
char *json_buff = NULL;
size_t json_buff_sz = 0;
- int ret = load_file_to_memory(json_filename,
+ int ret = load_file_to_memory(g_json_filename,
(unsigned char **)&json_buff,
&json_buff_sz);
EXPECT_NE(ret, -1);
- ret = json2iris(json_buff, json_filename, c, tmp_iris_path,
+ ret = json2iris(json_buff, g_json_filename, c, tmp_iris_path,
sizeof(tmp_iris_path), NULL, NULL, g_logger);
FREE(json_buff);
EXPECT_NE(ret, -1);
@@ -235,7 +235,7 @@ TEST(redis_mode, maat_scan_string) {
maat_options_set_logger(opts, "./maat_input_mode_gtest.log",
LOG_LEVEL_INFO);
- struct maat *maat_inst = maat_new(opts, table_info_path);
+ struct maat *maat_inst = maat_new(opts, g_table_info_path);
const char *table_name = "KEYWORDS_TABLE";
int table_id = maat_get_table_id(maat_inst, table_name);
char scan_data[128] =
@@ -264,7 +264,7 @@ int main(int argc, char ** argv)
char json_iris_path[NAME_MAX] = {0};
snprintf(json_iris_path, sizeof(json_iris_path),
- "./%s_iris_tmp", json_filename);
+ "./%s_iris_tmp", g_json_filename);
if ((access(json_iris_path, F_OK)) == 0) {
system_cmd_rmdir(json_iris_path);
}
diff --git a/test/maat_json.json b/test/maat_json.json
index 66f6a86..98e4586 100644
--- a/test/maat_json.json
+++ b/test/maat_json.json
@@ -104,7 +104,7 @@
"group_id": 7,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -151,7 +151,7 @@
"group_id": 10,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -167,7 +167,7 @@
"group_id": 11,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -184,7 +184,7 @@
"regions": [
{
"table_name": "IP_CONFIG",
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_content": {
"addr_type": "ipv4",
"addr_format": "mask",
@@ -200,7 +200,7 @@
"regions": [
{
"table_name": "IP_PLUS_CONFIG",
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_content": {
"addr_type": "ipv4",
"addr_format": "mask",
@@ -216,7 +216,7 @@
"regions": [
{
"table_name": "IP_PLUS_CONFIG",
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_content": {
"addr_type": "ipv4",
"addr_format": "mask",
@@ -260,7 +260,7 @@
"regions": [
{
"table_name": "IP_CONFIG",
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_content": {
"addr_type": "ipv4",
"addr_format": "mask",
@@ -270,7 +270,7 @@
},
{
"table_name": "IP_CONFIG",
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_content": {
"addr_type": "ipv6",
"addr_format": "mask",
@@ -1384,7 +1384,7 @@
"not_flag": 0,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -1413,7 +1413,7 @@
"not_flag": 0,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv6",
@@ -1498,7 +1498,7 @@
"group_id": 149,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -1526,7 +1526,7 @@
"group_id": 150,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv6",
@@ -1737,7 +1737,7 @@
"not_flag": 0,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -1856,7 +1856,7 @@
"not_flag" : 0,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -1885,7 +1885,7 @@
"not_flag": 0,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -1914,7 +1914,7 @@
"not_flag": 0,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -2103,7 +2103,7 @@
"regions": [
{
"table_name": "IP_CONFIG",
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_content": {
"addr_type": "ipv6",
"addr_format": "mask",
@@ -2190,7 +2190,7 @@
"not_flag": 0,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -2237,7 +2237,7 @@
"not_flag": 0,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -2284,7 +2284,7 @@
"not_flag": 0,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -2740,7 +2740,7 @@
"is_exclude": 0,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -2757,7 +2757,7 @@
"is_exclude": 1,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -2774,7 +2774,7 @@
"is_exclude": 1,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -2806,7 +2806,7 @@
"regions": [
{
"table_name": "IP_PLUS_CONFIG",
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_content": {
"addr_type": "ipv4",
"addr_format": "range",
@@ -2825,7 +2825,7 @@
"regions": [
{
"table_name": "IP_PLUS_CONFIG",
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_content": {
"addr_type": "ipv4",
"addr_format": "range",
@@ -2896,7 +2896,7 @@
"regions": [
{
"table_name": "IP_PLUS_CONFIG",
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_content": {
"addr_type": "ipv4",
"addr_format": "range",
@@ -2915,7 +2915,7 @@
"regions": [
{
"table_name": "IP_PLUS_CONFIG",
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_content": {
"addr_type": "ipv4",
"addr_format": "range",
@@ -3091,7 +3091,7 @@
"not_flag": 0,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -3146,7 +3146,7 @@
"group_id": 215,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv6",
@@ -3175,7 +3175,7 @@
"not_flag": 0,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PERF_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -3958,7 +3958,7 @@
"regions": [
{
"table_name": "IP_CONFIG",
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_content": {
"addr_type": "ipv4",
"addr_format": "mask",
@@ -3997,6 +3997,93 @@
]
}
]
+ },
+ {
+ "compile_id": 230,
+ "service": 0,
+ "action": 0,
+ "do_blacklist": 0,
+ "do_log": 0,
+ "user_region": "ipv6_::",
+ "is_valid": "yes",
+ "groups": [
+ {
+ "virtual_table": "IP_PLUS_CONFIG",
+ "group_name": "230_IP_group",
+ "group_id": 256,
+ "regions": [
+ {
+ "table_type":"ip",
+ "table_name": "IP_PLUS_CONFIG",
+ "table_content": {
+ "addr_type": "ipv6",
+ "addr_format": "CIDR",
+ "ip1": "2607:5d00:2:2::32:28",
+ "ip2": "128",
+ "port":"80-443"
+ }
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "compile_id": 231,
+ "service": 0,
+ "action": 0,
+ "do_blacklist": 0,
+ "do_log": 0,
+ "user_region": "should_not_hit",
+ "is_valid": "yes",
+ "groups": [
+ {
+ "virtual_table": "IP_PLUS_CONFIG",
+ "group_name": "231_IP_group",
+ "group_id": 257,
+ "regions": [
+ {
+ "table_type":"ip",
+ "table_name": "IP_PLUS_CONFIG",
+ "table_content": {
+ "addr_type": "ipv6",
+ "addr_format": "CIDR",
+ "ip1": "2607:5d00:2:2::32:28",
+ "ip2": "128",
+ "port":"80"
+ }
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "compile_id": 232,
+ "service": 0,
+ "action": 0,
+ "do_blacklist": 0,
+ "do_log": 0,
+ "user_region": "should_not_hit",
+ "is_valid": "yes",
+ "groups": [
+ {
+ "virtual_table": "IP_PLUS_CONFIG",
+ "group_name": "232_IP_group",
+ "group_id": 258,
+ "regions": [
+ {
+ "table_type":"ip",
+ "table_name": "IP_PLUS_CONFIG",
+ "table_content": {
+ "addr_type": "ipv4",
+ "addr_format": "CIDR",
+ "ip1": "192.168.30.44",
+ "ip2": "32",
+ "port": "80"
+ }
+ }
+ ]
+ }
+ ]
}
],
"plugin_table": [
diff --git a/test/table_info.conf b/test/table_info.conf
index 1792213..902ae53 100644
--- a/test/table_info.conf
+++ b/test/table_info.conf
@@ -137,7 +137,7 @@
"schema_tag": "{\"http_region\": \"expr\"}",
"custom": {
"item_id":1,
- "group_id":2,
+ "group_id":2,
"keywords":3,
"expr_type":4,
"match_method":5,
@@ -161,8 +161,8 @@
{
"table_id":12,
"table_name":"IP_CONFIG",
- "table_type":"ip_plus",
- "valid_column":7,
+ "table_type":"ip",
+ "valid_column":8,
"custom": {
"item_id":1,
"group_id":2,
@@ -322,15 +322,16 @@
{
"table_id":24,
"table_name":"IP_PLUS_CONFIG",
- "table_type":"ip_plus",
- "valid_column":7,
+ "table_type":"ip",
+ "valid_column":8,
"custom": {
"item_id":1,
"group_id":2,
"addr_type":3,
"addr_format":4,
"ip1":5,
- "ip2":6
+ "ip2":6,
+ "port":7
}
},
{
@@ -565,15 +566,16 @@
{
"table_id":47,
"table_name":"IP_PERF_CONFIG",
- "table_type":"ip_plus",
- "valid_column":7,
+ "table_type":"ip",
+ "valid_column":8,
"custom": {
"item_id":1,
"group_id":2,
"addr_type":3,
"addr_format":4,
"ip1":5,
- "ip2":6
+ "ip2":6,
+ "port":7
}
},
{
diff --git a/test/test_utils.cpp b/test/test_utils.cpp
new file mode 100644
index 0000000..0f5234a
--- /dev/null
+++ b/test/test_utils.cpp
@@ -0,0 +1,303 @@
+#include "test_utils.h"
+#include "maat_redis_monitor.h"
+#include "maat_utils.h"
+#include "maat_table.h"
+#include "maat_rule.h"
+#include "maat_config_monitor.h"
+#include "json2iris.h"
+
+#include <assert.h>
+#include <unistd.h>
+
+int count_line_num_cb(const char *table_name, const char *line, void *u_para)
+{
+ (*((unsigned int *)u_para))++;
+ return 0;
+}
+
+int line_idx = 0;
+long long absolute_expire_time = 0;
+int make_serial_rule(const char *table_name, const char *line, void *u_para)
+{
+ struct serial_rule *s_rule=(struct serial_rule *)u_para;
+ redisContext *ctx = s_rule->ref_ctx;
+ char *buff = ALLOC(char, strlen(line) + 1);
+
+ memcpy(buff, line, strlen(line) + 1);
+ while (buff[strlen(line) - 1] == '\n' || buff[strlen(line) - 1] == '\t') {
+ buff[strlen(line) - 1] = '\0';
+ }
+
+ const char *redis_rule_key = "TEST_RULE_KEY";
+ redisReply *reply = maat_wrap_redis_command(ctx, NULL, "INCRBY %s %d",
+ redis_rule_key, 1);
+ if (reply->type == REDIS_REPLY_NIL) {
+ printf("incrby redis_rule_key:%s failed.", redis_rule_key);
+ return -1;
+ } else {
+ s_rule->rule_id = maat_read_redis_integer(reply);
+ freeReplyObject(reply);
+ reply = NULL;
+ }
+
+ maat_set_serial_rule(s_rule + line_idx, MAAT_OP_ADD, s_rule->rule_id,
+ table_name, buff, absolute_expire_time);
+ (s_rule + line_idx)->ref_ctx = ctx;
+ line_idx++;
+
+ FREE(buff);
+
+ return 0;
+}
+int write_json_to_iris(const char* json_fn, char *iris_path, size_t path_sz, struct log_handle *logger)
+{
+
+ char *json_buff = NULL;
+ size_t json_buff_sz = 0;
+
+ int ret = load_file_to_memory(json_fn, (unsigned char **)&json_buff,
+ &json_buff_sz);
+ if (ret < 0) {
+ return -1;
+ }
+
+ ret = json2iris(json_buff, json_fn, NULL, iris_path,
+ path_sz, NULL, NULL, logger);
+ FREE(json_buff);
+ if (ret < 0) {
+ return -1;
+ }
+
+ return 0;
+}
+int write_iris_to_redis(const char* iris_path, char *redis_ip, int redis_port, int redis_db,
+ struct log_handle *logger)
+{
+ redisContext *c = maat_connect_redis(redis_ip, redis_port, redis_db, logger);
+ if (NULL == c) {
+ return -1;
+ }
+
+ redisReply *reply = maat_wrap_redis_command(c, logger, "flushdb");
+ if (NULL == reply) {
+ return -1;
+ } else {
+ freeReplyObject(reply);
+ reply = NULL;
+ }
+
+ size_t total_line_cnt = 0;
+ config_monitor_traverse(0, iris_path, NULL, count_line_num_cb,
+ NULL, &total_line_cnt, NULL, logger);
+
+ struct serial_rule *s_rule = ALLOC(struct serial_rule, total_line_cnt);
+ s_rule->ref_ctx = c;
+ long long server_time = maat_redis_server_time_s(c);
+ if (server_time < 0) {
+ return -1;
+ }
+
+ absolute_expire_time = server_time + 300;
+ config_monitor_traverse(0, iris_path, NULL, make_serial_rule,
+ NULL, s_rule, NULL, logger);
+ s_rule->ref_ctx = NULL;
+ line_idx = 0;
+ absolute_expire_time = 0;
+
+ int success_cnt = 0;
+ do {
+ success_cnt = maat_cmd_write_rule(c, s_rule, total_line_cnt,
+ server_time, logger);
+ } while (success_cnt < 0);
+
+ assert(success_cnt == (int)total_line_cnt);
+
+ for (size_t i = 0; i < total_line_cnt; i++) {
+ maat_clear_rule_cache(s_rule + i);
+ }
+ FREE(s_rule);
+ redisFree(c);
+ return 0;
+}
+int write_json_to_redis(const char* json_filename, char *redis_ip, int redis_port, int redis_db,
+ struct log_handle *logger)
+{
+ char iris_path[512] = {0};
+ write_json_to_iris(json_filename, iris_path, sizeof(iris_path), logger);
+ write_iris_to_redis(iris_path, redis_ip, redis_port, redis_db, logger);
+
+ return 0;
+}
+
+int compile_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long compile_id,
+ const char *user_region, int clause_num,
+ int expire_after)
+{
+ char table_line[1024 * 16] = {0};
+ sprintf(table_line, "%lld\t0\t0\t0\t0\t0\t%s\t%d\t%d\t0.0",
+ compile_id, user_region, clause_num, op);
+
+ struct maat_cmd_line line_rule;
+ line_rule.rule_id = compile_id;
+ line_rule.table_line = table_line;
+ line_rule.table_name = table_name;
+ line_rule.expire_after = expire_after;
+
+ return maat_cmd_set_line(maat_inst, &line_rule);
+}
+
+#define TO_GROUP2X_KEY(group_id, parent_id, clause_index) (((unsigned long)group_id<<32|parent_id) + clause_index)
+
+int group2compile_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long group_id,
+ long long compile_id, int not_flag,
+ const char *vtable_name, int clause_index,
+ int expire_after)
+{
+ char table_line[128] = {0};
+ sprintf(table_line, "%lld\t%lld\t%d\t%s\t%d\t%d",
+ group_id, compile_id, not_flag, vtable_name, clause_index, op);
+
+ struct maat_cmd_line line_rule;
+ line_rule.rule_id = TO_GROUP2X_KEY(group_id, compile_id, clause_index);
+ line_rule.table_line = table_line;
+ line_rule.table_name = table_name;
+ line_rule.expire_after = expire_after;
+
+ return maat_cmd_set_line(maat_inst, &line_rule);
+}
+
+int group2group_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long group_id,
+ long long sub_group_id, int expire_after)
+{
+ char table_line[128] = {0};
+ sprintf(table_line, "%lld\t%lld\t%s\t%d", group_id, sub_group_id,
+ "null", op);
+
+ struct maat_cmd_line line_rule;
+ line_rule.rule_id = TO_GROUP2X_KEY(group_id, sub_group_id, 0);
+ line_rule.table_line = table_line;
+ line_rule.table_name = table_name;
+ line_rule.expire_after = expire_after;
+
+ return maat_cmd_set_line(maat_inst, &line_rule);
+}
+
+int expr_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long item_id,
+ long long group_id, const char *keywords,
+ const char *district, int expr_type,
+ int match_method, int is_hexbin, int expire_after)
+{
+ char table_line[1024] = {0};
+ int table_id = maat_get_table_id(maat_inst, table_name);
+ if (table_id < 0) {
+ return 0;
+ }
+
+ enum table_type table_type = table_manager_get_table_type(maat_inst->tbl_mgr,
+ table_id);
+ assert(table_type == TABLE_TYPE_EXPR || table_type == TABLE_TYPE_EXPR_PLUS);
+
+ if (table_type == TABLE_TYPE_EXPR_PLUS) {
+ sprintf(table_line, "%lld\t%lld\t%s\t%s\t%d\t%d\t%d\t%d",
+ item_id, group_id, district, keywords, expr_type,
+ match_method, is_hexbin, op);
+ } else {
+ sprintf(table_line, "%lld\t%lld\t%s\t%d\t%d\t%d\t%d",
+ item_id, group_id, keywords, expr_type,
+ match_method, is_hexbin, op);
+ }
+
+ struct maat_cmd_line line_rule;
+ line_rule.rule_id = item_id;
+ line_rule.table_line = table_line;
+ line_rule.table_name = table_name;
+ line_rule.expire_after = expire_after;
+
+ return maat_cmd_set_line(maat_inst, &line_rule);
+}
+
+int interval_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long item_id, long long group_id,
+ unsigned int low_boundary, unsigned int up_boundary,
+ const char *district, int expire_after)
+{
+ char table_line[1024] = {0};
+ int table_id = maat_get_table_id(maat_inst, table_name);
+ if (table_id < 0) {
+ return 0;
+ }
+
+ enum table_type table_type = table_manager_get_table_type(maat_inst->tbl_mgr,
+ table_id);
+ assert(table_type == TABLE_TYPE_INTERVAL || table_type == TABLE_TYPE_INTERVAL_PLUS);
+
+ if (table_type == TABLE_TYPE_INTERVAL_PLUS) {
+ sprintf(table_line, "%lld\t%lld\t%s\t%u\t%u\t%d",
+ item_id, group_id, district, low_boundary, up_boundary, op);
+ } else {
+ sprintf(table_line, "%lld\t%lld\t%u\t%u\t%d",
+ item_id, group_id, low_boundary, up_boundary, op);
+ }
+
+ struct maat_cmd_line line_rule;
+ line_rule.rule_id = item_id;
+ line_rule.table_line = table_line;
+ line_rule.table_name = table_name;
+ line_rule.expire_after = expire_after;
+
+ return maat_cmd_set_line(maat_inst, &line_rule);
+}
+
+int ip_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long item_id,
+ long long group_id, enum IP_TYPE type, const char *ip1,
+ const char *ip2, int expire_after)
+{
+ char table_line[1024] = {0};
+ int table_id = maat_get_table_id(maat_inst, table_name);
+ if (table_id < 0) {
+ return 0;
+ }
+
+ int ip_type = IPV4;
+ if (type == IPv6) {
+ ip_type = IPV6;
+ }
+
+ sprintf(table_line, "%lld\t%lld\t%d\trange\t%s\t%s\t0-65535\t%d",
+ item_id, group_id, ip_type, ip1, ip2, op);
+ struct maat_cmd_line line_rule;
+
+ line_rule.rule_id = item_id;
+ line_rule.table_line = table_line;
+ line_rule.table_name = table_name;
+ line_rule.expire_after = expire_after;
+
+ return maat_cmd_set_line(maat_inst, &line_rule);
+}
+int flag_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long item_id,
+ long long group_id, long long flag,
+ long long flag_mask, int expire_after)
+{
+ char table_line[1024] = {0};
+ int table_id = maat_get_table_id(maat_inst, table_name);
+ if (table_id < 0) {
+ return 0;
+ }
+
+ sprintf(table_line, "%lld\t%lld\t%lld\t%lld\t%d",
+ item_id, group_id, flag, flag_mask, op);
+ struct maat_cmd_line line_rule;
+
+ line_rule.rule_id = item_id;
+ line_rule.table_line = table_line;
+ line_rule.table_name = table_name;
+ line_rule.expire_after = expire_after;
+
+ return maat_cmd_set_line(maat_inst, &line_rule);
+} \ No newline at end of file
diff --git a/test/test_utils.h b/test/test_utils.h
new file mode 100644
index 0000000..6049c91
--- /dev/null
+++ b/test/test_utils.h
@@ -0,0 +1,37 @@
+#pragma once
+#include "maat_utils.h"
+#include "maat_command.h"
+#include "ip_matcher.h"
+int write_json_to_redis(const char* json_filename, char *redis_ip, int redis_port, int redis_db,
+ struct log_handle *logger);
+int write_iris_to_redis(const char* iris_path, char *redis_ip, int redis_port, int redis_db,
+ struct log_handle *logger);
+int compile_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long compile_id,
+ const char *user_region, int clause_num,
+ int expire_after);
+int group2compile_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long group_id,
+ long long compile_id, int not_flag,
+ const char *vtable_name, int clause_index,
+ int expire_after);
+int group2group_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long group_id,
+ long long sub_group_id, int expire_after);
+int expr_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long item_id,
+ long long group_id, const char *keywords,
+ const char *district, int expr_type,
+ int match_method, int is_hexbin, int expire_after);
+int interval_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long item_id, long long group_id,
+ unsigned int low_boundary, unsigned int up_boundary,
+ const char *district, int expire_after);
+int ip_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long item_id,
+ long long group_id, enum IP_TYPE type, const char *ip1,
+ const char *ip2, int expire_after);
+int flag_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long item_id,
+ long long group_id, long long flag,
+ long long flag_mask, int expire_after); \ No newline at end of file
diff --git a/test/tsg_table_info.conf b/test/tsg_table_info.conf
index 53a03c5..0632c13 100644
--- a/test/tsg_table_info.conf
+++ b/test/tsg_table_info.conf
@@ -8,8 +8,7 @@
"item_id":1,
"ip_type":3,
"start_ip":4,
- "end_ip":5,
- "addr_format":7
+ "end_ip":5
}
},
{