diff options
| author | liuwentan <[email protected]> | 2024-04-03 16:47:30 +0800 |
|---|---|---|
| committer | liuwentan <[email protected]> | 2024-04-03 16:47:30 +0800 |
| commit | 7e25f48fdd7f08d80d2eeaee654c48e21f686ab6 (patch) | |
| tree | 6c64febed55d04d70c623da498f8844c35a02c30 /test | |
| parent | cbabcbd6b0afd766c11b67f6732093819b82da55 (diff) | |
[PATCH]delete useless codev4.1.34
Diffstat (limited to 'test')
| -rw-r--r-- | test/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | test/benchmark/CMakeLists.txt | 7 | ||||
| -rw-r--r-- | test/benchmark/benchmark_gtest.cpp (renamed from test/benchmark/benchmark_hs_gtest.cpp) | 2449 | ||||
| -rw-r--r-- | test/benchmark/benchmark_rs_gtest.cpp | 3638 | ||||
| -rw-r--r-- | test/expr_matcher_gtest.cpp | 154 | ||||
| -rw-r--r-- | test/group_nesting/group_nesting_gtest.cpp | 3 | ||||
| -rw-r--r-- | test/ipport_plugin/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | test/ipport_plugin/ipport_plugin_gtest.cpp | 140 | ||||
| -rw-r--r-- | test/maat_ex_data_gtest.cpp | 35 | ||||
| -rw-r--r-- | test/maat_framework_gtest.cpp | 13 | ||||
| -rw-r--r-- | test/maat_framework_perf_gtest.cpp | 85 | ||||
| -rw-r--r-- | test/maat_input_mode_gtest.cpp | 224 | ||||
| -rw-r--r-- | test/test_utils.cpp | 87 | ||||
| -rw-r--r-- | test/test_utils.h | 38 |
14 files changed, 2447 insertions, 4430 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 286551f..2dd8a2a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -13,7 +13,7 @@ include_directories(${PROJECT_SOURCE_DIR}/scanner/bool_matcher) add_executable(rcu_hash_gtest rcu_hash_gtest.cpp) target_link_libraries(rcu_hash_gtest maat_frame_static gtest_static) -add_executable(maat_input_mode_gtest maat_input_mode_gtest.cpp) +add_executable(maat_input_mode_gtest maat_input_mode_gtest.cpp test_utils.cpp) target_link_libraries(maat_input_mode_gtest maat_frame_static gtest_static) add_executable(maat_framework_gtest maat_framework_gtest.cpp test_utils.cpp) diff --git a/test/benchmark/CMakeLists.txt b/test/benchmark/CMakeLists.txt index d62c4e6..8d9fdbc 100644 --- a/test/benchmark/CMakeLists.txt +++ b/test/benchmark/CMakeLists.txt @@ -1,7 +1,4 @@ include_directories(${PROJECT_SOURCE_DIR}/src/inc_internal) -add_executable(benchmark_hs_gtest benchmark_hs_gtest.cpp) -target_link_libraries(benchmark_hs_gtest maat_frame_static gtest_static) - -add_executable(benchmark_rs_gtest benchmark_rs_gtest.cpp) -target_link_libraries(benchmark_rs_gtest maat_frame_static gtest_static)
\ No newline at end of file +add_executable(benchmark_gtest benchmark_gtest.cpp ../test_utils.cpp) +target_link_libraries(benchmark_gtest maat_frame_static gtest_static)
\ No newline at end of file diff --git a/test/benchmark/benchmark_hs_gtest.cpp b/test/benchmark/benchmark_gtest.cpp index 87633cd..c216a5a 100644 --- a/test/benchmark/benchmark_hs_gtest.cpp +++ b/test/benchmark/benchmark_gtest.cpp @@ -5,6 +5,7 @@ #include "json2iris.h" #include "ip_matcher.h" #include "maat_table.h" +#include "../test_utils.h" #include "maat_config_monitor.h" #include <gtest/gtest.h> @@ -40,19 +41,7 @@ struct thread_param { struct log_handle *logger; }; -static void random_keyword_generate(char *keyword_buf, size_t sz) -{ -#define MIN_KEYWORD_LEN 4 - size_t i = 0, len = 0; - len = random() % (sz - 1 - MIN_KEYWORD_LEN) + MIN_KEYWORD_LEN; - - for (i = 0; i < len; i++) { - keyword_buf[i] = 'a' + random() % ('z' - 'a'); - } - keyword_buf[i] = '\0'; -} - -void generate_expr_sample(const char *table_name, int sample_count) +static void generate_expr_sample(const char *table_name, int sample_count) { FILE *fp = fopen(table_name, "w+"); if (NULL == fp) { @@ -72,7 +61,7 @@ void generate_expr_sample(const char *table_name, int sample_count) fclose(fp); } -void generate_ip_sample(const char *table_name, int sample_count) +static void generate_ip_sample(const char *table_name, int sample_count) { FILE *fp = fopen(table_name, "w+"); if (NULL == fp) { @@ -95,7 +84,7 @@ void generate_ip_sample(const char *table_name, int sample_count) fclose(fp); } -void generate_integer_sample(const char *table_name, int sample_count) +static void generate_integer_sample(const char *table_name, int sample_count) { FILE *fp = fopen(table_name, "w+"); if (NULL == fp) { @@ -525,11 +514,11 @@ void *perf_flag_update_thread(void *arg) return is_all_hit; } -class Regex100BenchmarkGTest : public ::testing::Test +class HsRegex100BenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); FILE *fp = fopen("full_config_index.0000001", "w+"); if (NULL == fp) { @@ -545,7 +534,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "REGEX_100", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS); @@ -557,6 +546,82 @@ protected: static void TearDownTestCase() { maat_free(_shared_maat_inst); log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *HsRegex100BenchmarkGTest::_shared_maat_inst; +struct log_handle *HsRegex100BenchmarkGTest::logger; + +TEST_F(HsRegex100BenchmarkGTest, LiteralScan) { + const char *table_name = "REGEX_100"; + struct maat *maat_inst = HsRegex100BenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_times = MAX_SCAN_TIMES; + thread_params[i].rule_count = 100; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_regex_scan_thread, thread_params+i); + } else { + thread_params[i].test_times = 0; + pthread_create(&threads[i], NULL, perf_regex_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_times = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_times += thread_params[i].test_times; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_times * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "HsRegex100Scan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class RsRegex100BenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_gtest.log", 0); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); + 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, g_table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); system_cmd_rmdir("./COMPILE_PERF"); system_cmd_rmdir("./GROUP2COMPILE_PERF"); } @@ -565,12 +630,12 @@ protected: static struct maat *_shared_maat_inst; }; -struct maat *Regex100BenchmarkGTest::_shared_maat_inst; -struct log_handle *Regex100BenchmarkGTest::logger; +struct maat *RsRegex100BenchmarkGTest::_shared_maat_inst; +struct log_handle *RsRegex100BenchmarkGTest::logger; -TEST_F(Regex100BenchmarkGTest, LiteralScan) { +TEST_F(RsRegex100BenchmarkGTest, LiteralScan) { const char *table_name = "REGEX_100"; - struct maat *maat_inst = Regex100BenchmarkGTest::_shared_maat_inst; + struct maat *maat_inst = RsRegex100BenchmarkGTest::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); @@ -612,15 +677,15 @@ TEST_F(Regex100BenchmarkGTest, LiteralScan) { scan_per_second = scan_times * 1000 / time_elapse_ms; log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Regex100Scan match rate on %d-threads speed %lld lookups/s/thread", + "RsRegex100Scan match rate on %d-threads speed %lld lookups/s/thread", PERF_THREAD_NUM, scan_per_second); } -class Regex200BenchmarkGTest : public ::testing::Test +class HsRegex200BenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); FILE *fp = fopen("full_config_index.0000001", "w+"); if (NULL == fp) { @@ -636,7 +701,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "REGEX_200", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS); @@ -648,6 +713,82 @@ protected: static void TearDownTestCase() { maat_free(_shared_maat_inst); log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *HsRegex200BenchmarkGTest::_shared_maat_inst; +struct log_handle *HsRegex200BenchmarkGTest::logger; + +TEST_F(HsRegex200BenchmarkGTest, LiteralScan) { + const char *table_name = "REGEX_200"; + struct maat *maat_inst = HsRegex200BenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_times = MAX_SCAN_TIMES; + thread_params[i].rule_count = 200; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_regex_scan_thread, thread_params+i); + } else { + thread_params[i].test_times = 0; + pthread_create(&threads[i], NULL, perf_regex_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_times = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_times += thread_params[i].test_times; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_times * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "HsRegex200Scan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class RsRegex200BenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_gtest.log", 0); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); + 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, g_table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); system_cmd_rmdir("./COMPILE_PERF"); system_cmd_rmdir("./GROUP2COMPILE_PERF"); } @@ -656,12 +797,12 @@ protected: static struct maat *_shared_maat_inst; }; -struct maat *Regex200BenchmarkGTest::_shared_maat_inst; -struct log_handle *Regex200BenchmarkGTest::logger; +struct maat *RsRegex200BenchmarkGTest::_shared_maat_inst; +struct log_handle *RsRegex200BenchmarkGTest::logger; -TEST_F(Regex200BenchmarkGTest, LiteralScan) { +TEST_F(RsRegex200BenchmarkGTest, LiteralScan) { const char *table_name = "REGEX_200"; - struct maat *maat_inst = Regex200BenchmarkGTest::_shared_maat_inst; + struct maat *maat_inst = RsRegex200BenchmarkGTest::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); @@ -703,15 +844,15 @@ TEST_F(Regex200BenchmarkGTest, LiteralScan) { scan_per_second = scan_times * 1000 / time_elapse_ms; log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Regex200Scan match rate on %d-threads speed %lld lookups/s/thread", + "RsRegex200Scan match rate on %d-threads speed %lld lookups/s/thread", PERF_THREAD_NUM, scan_per_second); } -class Regex300BenchmarkGTest : public ::testing::Test +class HsRegex300BenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); FILE *fp = fopen("full_config_index.0000001", "w+"); if (NULL == fp) { @@ -727,7 +868,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "REGEX_300", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS); @@ -739,6 +880,82 @@ protected: static void TearDownTestCase() { maat_free(_shared_maat_inst); log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *HsRegex300BenchmarkGTest::_shared_maat_inst; +struct log_handle *HsRegex300BenchmarkGTest::logger; + +TEST_F(HsRegex300BenchmarkGTest, LiteralScan) { + const char *table_name = "REGEX_300"; + struct maat *maat_inst = HsRegex300BenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_times = MAX_SCAN_TIMES; + thread_params[i].rule_count = 300; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_regex_scan_thread, thread_params+i); + } else { + thread_params[i].test_times = 0; + pthread_create(&threads[i], NULL, perf_regex_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_times = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_times += thread_params[i].test_times; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_times * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "HsRegex300Scan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class RsRegex300BenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_gtest.log", 0); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); + 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, g_table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); system_cmd_rmdir("./COMPILE_PERF"); system_cmd_rmdir("./GROUP2COMPILE_PERF"); } @@ -747,12 +964,12 @@ protected: static struct maat *_shared_maat_inst; }; -struct maat *Regex300BenchmarkGTest::_shared_maat_inst; -struct log_handle *Regex300BenchmarkGTest::logger; +struct maat *RsRegex300BenchmarkGTest::_shared_maat_inst; +struct log_handle *RsRegex300BenchmarkGTest::logger; -TEST_F(Regex300BenchmarkGTest, LiteralScan) { +TEST_F(RsRegex300BenchmarkGTest, LiteralScan) { const char *table_name = "REGEX_300"; - struct maat *maat_inst = Regex300BenchmarkGTest::_shared_maat_inst; + struct maat *maat_inst = RsRegex300BenchmarkGTest::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); @@ -794,15 +1011,15 @@ TEST_F(Regex300BenchmarkGTest, LiteralScan) { scan_per_second = scan_times * 1000 / time_elapse_ms; log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Regex300Scan match rate on %d-threads speed %lld lookups/s/thread", + "RsRegex300Scan match rate on %d-threads speed %lld lookups/s/thread", PERF_THREAD_NUM, scan_per_second); } -class Regex500BenchmarkGTest : public ::testing::Test +class HsRegex500BenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); FILE *fp = fopen("full_config_index.0000001", "w+"); if (NULL == fp) { @@ -818,7 +1035,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "REGEX_500", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS); @@ -830,6 +1047,82 @@ protected: static void TearDownTestCase() { maat_free(_shared_maat_inst); log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *HsRegex500BenchmarkGTest::_shared_maat_inst; +struct log_handle *HsRegex500BenchmarkGTest::logger; + +TEST_F(HsRegex500BenchmarkGTest, LiteralScan) { + const char *table_name = "REGEX_500"; + struct maat *maat_inst = HsRegex500BenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_times = MAX_SCAN_TIMES; + thread_params[i].rule_count = 500; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_regex_scan_thread, thread_params+i); + } else { + thread_params[i].test_times = 0; + pthread_create(&threads[i], NULL, perf_regex_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_times = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_times += thread_params[i].test_times; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_times * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "HsRegex500Scan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class RsRegex500BenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_gtest.log", 0); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); + 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, g_table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); system_cmd_rmdir("./COMPILE_PERF"); system_cmd_rmdir("./GROUP2COMPILE_PERF"); } @@ -838,12 +1131,12 @@ protected: static struct maat *_shared_maat_inst; }; -struct maat *Regex500BenchmarkGTest::_shared_maat_inst; -struct log_handle *Regex500BenchmarkGTest::logger; +struct maat *RsRegex500BenchmarkGTest::_shared_maat_inst; +struct log_handle *RsRegex500BenchmarkGTest::logger; -TEST_F(Regex500BenchmarkGTest, LiteralScan) { +TEST_F(RsRegex500BenchmarkGTest, LiteralScan) { const char *table_name = "REGEX_500"; - struct maat *maat_inst = Regex500BenchmarkGTest::_shared_maat_inst; + struct maat *maat_inst = RsRegex500BenchmarkGTest::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); @@ -885,15 +1178,15 @@ TEST_F(Regex500BenchmarkGTest, LiteralScan) { scan_per_second = scan_times * 1000 / time_elapse_ms; log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Regex500Scan match rate on %d-threads speed %lld lookups/s/thread", + "RsRegex500Scan match rate on %d-threads speed %lld lookups/s/thread", PERF_THREAD_NUM, scan_per_second); } -class Regex1KBenchmarkGTest : public ::testing::Test +class HsRegex1KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); FILE *fp = fopen("full_config_index.0000001", "w+"); if (NULL == fp) { @@ -909,7 +1202,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "REGEX_1K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS); @@ -921,6 +1214,82 @@ protected: static void TearDownTestCase() { maat_free(_shared_maat_inst); log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *HsRegex1KBenchmarkGTest::_shared_maat_inst; +struct log_handle *HsRegex1KBenchmarkGTest::logger; + +TEST_F(HsRegex1KBenchmarkGTest, LiteralScan) { + const char *table_name = "REGEX_1K"; + struct maat *maat_inst = HsRegex1KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_times = MAX_SCAN_TIMES; + thread_params[i].rule_count = 1000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_regex_scan_thread, thread_params+i); + } else { + thread_params[i].test_times = 0; + pthread_create(&threads[i], NULL, perf_regex_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_times = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_times += thread_params[i].test_times; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_times * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "HsRegex1KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class RsRegex1KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_gtest.log", 0); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); + 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, g_table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); system_cmd_rmdir("./COMPILE_PERF"); system_cmd_rmdir("./GROUP2COMPILE_PERF"); } @@ -929,12 +1298,12 @@ protected: static struct maat *_shared_maat_inst; }; -struct maat *Regex1KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Regex1KBenchmarkGTest::logger; +struct maat *RsRegex1KBenchmarkGTest::_shared_maat_inst; +struct log_handle *RsRegex1KBenchmarkGTest::logger; -TEST_F(Regex1KBenchmarkGTest, LiteralScan) { +TEST_F(RsRegex1KBenchmarkGTest, LiteralScan) { const char *table_name = "REGEX_1K"; - struct maat *maat_inst = Regex1KBenchmarkGTest::_shared_maat_inst; + struct maat *maat_inst = RsRegex1KBenchmarkGTest::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); @@ -976,15 +1345,15 @@ TEST_F(Regex1KBenchmarkGTest, LiteralScan) { scan_per_second = scan_times * 1000 / time_elapse_ms; log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Regex1KScan match rate on %d-threads speed %lld lookups/s/thread", + "RsRegex1KScan match rate on %d-threads speed %lld lookups/s/thread", PERF_THREAD_NUM, scan_per_second); } -class Regex2KBenchmarkGTest : public ::testing::Test +class HsRegex2KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); FILE *fp = fopen("full_config_index.0000001", "w+"); if (NULL == fp) { @@ -1000,7 +1369,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "REGEX_2K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS); @@ -1012,6 +1381,82 @@ protected: static void TearDownTestCase() { maat_free(_shared_maat_inst); log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *HsRegex2KBenchmarkGTest::_shared_maat_inst; +struct log_handle *HsRegex2KBenchmarkGTest::logger; + +TEST_F(HsRegex2KBenchmarkGTest, LiteralScan) { + const char *table_name = "REGEX_2K"; + struct maat *maat_inst = HsRegex2KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_times = MAX_SCAN_TIMES; + thread_params[i].rule_count = 2000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_regex_scan_thread, thread_params+i); + } else { + thread_params[i].test_times = 0; + pthread_create(&threads[i], NULL, perf_regex_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_times = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_times += thread_params[i].test_times; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_times * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "HsRegex2KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class RsRegex2KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_gtest.log", 0); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); + 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, g_table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); system_cmd_rmdir("./COMPILE_PERF"); system_cmd_rmdir("./GROUP2COMPILE_PERF"); } @@ -1020,12 +1465,12 @@ protected: static struct maat *_shared_maat_inst; }; -struct maat *Regex2KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Regex2KBenchmarkGTest::logger; +struct maat *RsRegex2KBenchmarkGTest::_shared_maat_inst; +struct log_handle *RsRegex2KBenchmarkGTest::logger; -TEST_F(Regex2KBenchmarkGTest, LiteralScan) { +TEST_F(RsRegex2KBenchmarkGTest, LiteralScan) { const char *table_name = "REGEX_2K"; - struct maat *maat_inst = Regex2KBenchmarkGTest::_shared_maat_inst; + struct maat *maat_inst = RsRegex2KBenchmarkGTest::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); @@ -1067,15 +1512,15 @@ TEST_F(Regex2KBenchmarkGTest, LiteralScan) { scan_per_second = scan_times * 1000 / time_elapse_ms; log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Regex2KScan match rate on %d-threads speed %lld lookups/s/thread", + "RsRegex2KScan match rate on %d-threads speed %lld lookups/s/thread", PERF_THREAD_NUM, scan_per_second); } -class Regex3KBenchmarkGTest : public ::testing::Test +class HsRegex3KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); FILE *fp = fopen("full_config_index.0000001", "w+"); if (NULL == fp) { @@ -1091,7 +1536,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "REGEX_3K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS); @@ -1103,6 +1548,82 @@ protected: static void TearDownTestCase() { maat_free(_shared_maat_inst); log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *HsRegex3KBenchmarkGTest::_shared_maat_inst; +struct log_handle *HsRegex3KBenchmarkGTest::logger; + +TEST_F(HsRegex3KBenchmarkGTest, LiteralScan) { + const char *table_name = "REGEX_3K"; + struct maat *maat_inst = HsRegex3KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_times = MAX_SCAN_TIMES; + thread_params[i].rule_count = 3000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_regex_scan_thread, thread_params+i); + } else { + thread_params[i].test_times = 0; + pthread_create(&threads[i], NULL, perf_regex_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_times = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_times += thread_params[i].test_times; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_times * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "HsRegex3KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class RsRegex3KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_gtest.log", 0); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); + 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, g_table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); system_cmd_rmdir("COMPILE_PERF"); system_cmd_rmdir("GROUP2COMPILE_PERF"); } @@ -1111,12 +1632,12 @@ protected: static struct maat *_shared_maat_inst; }; -struct maat *Regex3KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Regex3KBenchmarkGTest::logger; +struct maat *RsRegex3KBenchmarkGTest::_shared_maat_inst; +struct log_handle *RsRegex3KBenchmarkGTest::logger; -TEST_F(Regex3KBenchmarkGTest, LiteralScan) { +TEST_F(RsRegex3KBenchmarkGTest, LiteralScan) { const char *table_name = "REGEX_3K"; - struct maat *maat_inst = Regex3KBenchmarkGTest::_shared_maat_inst; + struct maat *maat_inst = RsRegex3KBenchmarkGTest::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); @@ -1158,15 +1679,15 @@ TEST_F(Regex3KBenchmarkGTest, LiteralScan) { scan_per_second = scan_times * 1000 / time_elapse_ms; log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Regex3KScan match rate on %d-threads speed %lld lookups/s/thread", + "RsRegex3KScan match rate on %d-threads speed %lld lookups/s/thread", PERF_THREAD_NUM, scan_per_second); } -class Regex5KBenchmarkGTest : public ::testing::Test +class HsRegex5KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); FILE *fp = fopen("full_config_index.0000001", "w+"); if (NULL == fp) { @@ -1182,7 +1703,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "REGEX_5K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS); @@ -1194,6 +1715,82 @@ protected: static void TearDownTestCase() { maat_free(_shared_maat_inst); log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *HsRegex5KBenchmarkGTest::_shared_maat_inst; +struct log_handle *HsRegex5KBenchmarkGTest::logger; + +TEST_F(HsRegex5KBenchmarkGTest, LiteralScan) { + const char *table_name = "REGEX_5K"; + struct maat *maat_inst = HsRegex5KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_times = MAX_SCAN_TIMES; + thread_params[i].rule_count = 5000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_regex_scan_thread, thread_params+i); + } else { + thread_params[i].test_times = 0; + pthread_create(&threads[i], NULL, perf_regex_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_times = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_times += thread_params[i].test_times; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_times * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "HsRegex5KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class RsRegex5KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_gtest.log", 0); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); + 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, g_table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); system_cmd_rmdir("COMPILE_PERF"); system_cmd_rmdir("GROUP2COMPILE_PERF"); } @@ -1202,12 +1799,12 @@ protected: static struct maat *_shared_maat_inst; }; -struct maat *Regex5KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Regex5KBenchmarkGTest::logger; +struct maat *RsRegex5KBenchmarkGTest::_shared_maat_inst; +struct log_handle *RsRegex5KBenchmarkGTest::logger; -TEST_F(Regex5KBenchmarkGTest, LiteralScan) { +TEST_F(RsRegex5KBenchmarkGTest, LiteralScan) { const char *table_name = "REGEX_5K"; - struct maat *maat_inst = Regex5KBenchmarkGTest::_shared_maat_inst; + struct maat *maat_inst = RsRegex5KBenchmarkGTest::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); @@ -1249,15 +1846,15 @@ TEST_F(Regex5KBenchmarkGTest, LiteralScan) { scan_per_second = scan_times * 1000 / time_elapse_ms; log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Regex5KScan match rate on %d-threads speed %lld lookups/s/thread", + "RsRegex5KScan match rate on %d-threads speed %lld lookups/s/thread", PERF_THREAD_NUM, scan_per_second); } -class Regex10KBenchmarkGTest : public ::testing::Test +class HsRegex10KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); FILE *fp = fopen("full_config_index.0000001", "w+"); if (NULL == fp) { @@ -1273,7 +1870,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "REGEX_10K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS); @@ -1285,6 +1882,82 @@ protected: static void TearDownTestCase() { maat_free(_shared_maat_inst); log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *HsRegex10KBenchmarkGTest::_shared_maat_inst; +struct log_handle *HsRegex10KBenchmarkGTest::logger; + +TEST_F(HsRegex10KBenchmarkGTest, LiteralScan) { + const char *table_name = "REGEX_10K"; + struct maat *maat_inst = HsRegex10KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_times = MAX_SCAN_TIMES; + thread_params[i].rule_count = 10000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_regex_scan_thread, thread_params+i); + } else { + thread_params[i].test_times = 0; + pthread_create(&threads[i], NULL, perf_regex_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_times = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_times += thread_params[i].test_times; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_times * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "HsRegex10KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class RsRegex10KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_gtest.log", 0); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); + 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, g_table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); system_cmd_rmdir("COMPILE_PERF"); system_cmd_rmdir("GROUP2COMPILE_PERF"); } @@ -1293,12 +1966,12 @@ protected: static struct maat *_shared_maat_inst; }; -struct maat *Regex10KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Regex10KBenchmarkGTest::logger; +struct maat *RsRegex10KBenchmarkGTest::_shared_maat_inst; +struct log_handle *RsRegex10KBenchmarkGTest::logger; -TEST_F(Regex10KBenchmarkGTest, LiteralScan) { +TEST_F(RsRegex10KBenchmarkGTest, LiteralScan) { const char *table_name = "REGEX_10K"; - struct maat *maat_inst = Regex10KBenchmarkGTest::_shared_maat_inst; + struct maat *maat_inst = RsRegex10KBenchmarkGTest::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); @@ -1340,15 +2013,15 @@ TEST_F(Regex10KBenchmarkGTest, LiteralScan) { scan_per_second = scan_times * 1000 / time_elapse_ms; log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Regex10KScan match rate on %d-threads speed %lld lookups/s/thread", + "RsRegex10KScan match rate on %d-threads speed %lld lookups/s/thread", PERF_THREAD_NUM, scan_per_second); } -class Regex15KBenchmarkGTest : public ::testing::Test +class HsRegex15KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); FILE *fp = fopen("full_config_index.0000001", "w+"); if (NULL == fp) { @@ -1364,7 +2037,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "REGEX_15K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS); @@ -1376,6 +2049,82 @@ protected: static void TearDownTestCase() { maat_free(_shared_maat_inst); log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *HsRegex15KBenchmarkGTest::_shared_maat_inst; +struct log_handle *HsRegex15KBenchmarkGTest::logger; + +TEST_F(HsRegex15KBenchmarkGTest, LiteralScan) { + const char *table_name = "REGEX_15K"; + struct maat *maat_inst = HsRegex15KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_times = MAX_SCAN_TIMES; + thread_params[i].rule_count = 15000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_regex_scan_thread, thread_params+i); + } else { + thread_params[i].test_times = 0; + pthread_create(&threads[i], NULL, perf_regex_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_times = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_times += thread_params[i].test_times; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_times * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "HsRegex15KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class RsRegex15KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_gtest.log", 0); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); + 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, g_table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); system_cmd_rmdir("COMPILE_PERF"); system_cmd_rmdir("GROUP2COMPILE_PERF"); } @@ -1384,12 +2133,12 @@ protected: static struct maat *_shared_maat_inst; }; -struct maat *Regex15KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Regex15KBenchmarkGTest::logger; +struct maat *RsRegex15KBenchmarkGTest::_shared_maat_inst; +struct log_handle *RsRegex15KBenchmarkGTest::logger; -TEST_F(Regex15KBenchmarkGTest, LiteralScan) { +TEST_F(RsRegex15KBenchmarkGTest, LiteralScan) { const char *table_name = "REGEX_15K"; - struct maat *maat_inst = Regex15KBenchmarkGTest::_shared_maat_inst; + struct maat *maat_inst = RsRegex15KBenchmarkGTest::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); @@ -1431,15 +2180,15 @@ TEST_F(Regex15KBenchmarkGTest, LiteralScan) { scan_per_second = scan_times * 1000 / time_elapse_ms; log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Regex15KScan match rate on %d-threads speed %lld lookups/s/thread", + "RsRegex15KScan match rate on %d-threads speed %lld lookups/s/thread", PERF_THREAD_NUM, scan_per_second); } -class Expr1KBenchmarkGTest : public ::testing::Test +class HsExpr1KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_expr_sample("EXPR_LITERAL_1K", 1000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -1456,7 +2205,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "EXPR_LITERAL_1K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS); @@ -1468,6 +2217,82 @@ protected: static void TearDownTestCase() { maat_free(_shared_maat_inst); log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *HsExpr1KBenchmarkGTest::_shared_maat_inst; +struct log_handle *HsExpr1KBenchmarkGTest::logger; + +TEST_F(HsExpr1KBenchmarkGTest, LiteralScan) { + const char *table_name = "EXPR_LITERAL_1K"; + struct maat *maat_inst = HsExpr1KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_times = MAX_SCAN_TIMES; + thread_params[i].rule_count = 1000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); + } else { + thread_params[i].test_times = 0; + pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_times = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_times += thread_params[i].test_times; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_times * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "HsExpr1KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class RsExpr1KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_gtest.log", 0); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); + 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, g_table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); system_cmd_rmdir("COMPILE_PERF"); system_cmd_rmdir("GROUP2COMPILE_PERF"); } @@ -1476,12 +2301,12 @@ protected: static struct maat *_shared_maat_inst; }; -struct maat *Expr1KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Expr1KBenchmarkGTest::logger; +struct maat *RsExpr1KBenchmarkGTest::_shared_maat_inst; +struct log_handle *RsExpr1KBenchmarkGTest::logger; -TEST_F(Expr1KBenchmarkGTest, LiteralScan) { +TEST_F(RsExpr1KBenchmarkGTest, LiteralScan) { const char *table_name = "EXPR_LITERAL_1K"; - struct maat *maat_inst = Expr1KBenchmarkGTest::_shared_maat_inst; + struct maat *maat_inst = RsExpr1KBenchmarkGTest::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); @@ -1523,15 +2348,15 @@ TEST_F(Expr1KBenchmarkGTest, LiteralScan) { scan_per_second = scan_times * 1000 / time_elapse_ms; log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Expr1KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + "RsExpr1KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", PERF_THREAD_NUM, scan_per_second); } -class Expr5KBenchmarkGTest : public ::testing::Test +class HsExpr5KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_expr_sample("EXPR_LITERAL_5K", 5000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -1548,7 +2373,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "EXPR_LITERAL_5K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS); @@ -1560,6 +2385,82 @@ protected: static void TearDownTestCase() { maat_free(_shared_maat_inst); log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *HsExpr5KBenchmarkGTest::_shared_maat_inst; +struct log_handle *HsExpr5KBenchmarkGTest::logger; + +TEST_F(HsExpr5KBenchmarkGTest, LiteralScan) { + const char *table_name = "EXPR_LITERAL_5K"; + struct maat *maat_inst = HsExpr5KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_times = MAX_SCAN_TIMES; + thread_params[i].rule_count = 5000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); + } else { + thread_params[i].test_times = 0; + pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_times = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_times += thread_params[i].test_times; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_times * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "HsExpr5KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class RsExpr5KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_gtest.log", 0); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); + 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, g_table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); system_cmd_rmdir("COMPILE_PERF"); system_cmd_rmdir("GROUP2COMPILE_PERF"); } @@ -1568,12 +2469,12 @@ protected: static struct maat *_shared_maat_inst; }; -struct maat *Expr5KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Expr5KBenchmarkGTest::logger; +struct maat *RsExpr5KBenchmarkGTest::_shared_maat_inst; +struct log_handle *RsExpr5KBenchmarkGTest::logger; -TEST_F(Expr5KBenchmarkGTest, LiteralScan) { +TEST_F(RsExpr5KBenchmarkGTest, LiteralScan) { const char *table_name = "EXPR_LITERAL_5K"; - struct maat *maat_inst = Expr5KBenchmarkGTest::_shared_maat_inst; + struct maat *maat_inst = RsExpr5KBenchmarkGTest::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); @@ -1615,15 +2516,15 @@ TEST_F(Expr5KBenchmarkGTest, LiteralScan) { scan_per_second = scan_times * 1000 / time_elapse_ms; log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Expr5KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + "RsExpr5KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", PERF_THREAD_NUM, scan_per_second); } -class Expr10KBenchmarkGTest : public ::testing::Test +class HsExpr10KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_expr_sample("EXPR_LITERAL_10K", 10000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -1640,7 +2541,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "EXPR_LITERAL_10K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS); @@ -1652,6 +2553,82 @@ protected: static void TearDownTestCase() { maat_free(_shared_maat_inst); log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *HsExpr10KBenchmarkGTest::_shared_maat_inst; +struct log_handle *HsExpr10KBenchmarkGTest::logger; + +TEST_F(HsExpr10KBenchmarkGTest, LiteralScan) { + const char *table_name = "EXPR_LITERAL_10K"; + struct maat *maat_inst = HsExpr10KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_times = MAX_SCAN_TIMES; + thread_params[i].rule_count = 10000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); + } else { + thread_params[i].test_times = 0; + pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_times = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_times += thread_params[i].test_times; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_times * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "HsExpr10KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class RsExpr10KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_gtest.log", 0); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); + 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, g_table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); system_cmd_rmdir("COMPILE_PERF"); system_cmd_rmdir("GROUP2COMPILE_PERF"); } @@ -1660,12 +2637,12 @@ protected: static struct maat *_shared_maat_inst; }; -struct maat *Expr10KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Expr10KBenchmarkGTest::logger; +struct maat *RsExpr10KBenchmarkGTest::_shared_maat_inst; +struct log_handle *RsExpr10KBenchmarkGTest::logger; -TEST_F(Expr10KBenchmarkGTest, LiteralScan) { +TEST_F(RsExpr10KBenchmarkGTest, LiteralScan) { const char *table_name = "EXPR_LITERAL_10K"; - struct maat *maat_inst = Expr10KBenchmarkGTest::_shared_maat_inst; + struct maat *maat_inst = RsExpr10KBenchmarkGTest::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); @@ -1707,15 +2684,15 @@ TEST_F(Expr10KBenchmarkGTest, LiteralScan) { scan_per_second = scan_times * 1000 / time_elapse_ms; log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Expr10KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + "RsExpr10KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", PERF_THREAD_NUM, scan_per_second); } -class Expr50KBenchmarkGTest : public ::testing::Test +class HsExpr50KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_expr_sample("EXPR_LITERAL_50K", 50000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -1732,7 +2709,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "EXPR_LITERAL_50K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS); @@ -1744,6 +2721,82 @@ protected: static void TearDownTestCase() { maat_free(_shared_maat_inst); log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *HsExpr50KBenchmarkGTest::_shared_maat_inst; +struct log_handle *HsExpr50KBenchmarkGTest::logger; + +TEST_F(HsExpr50KBenchmarkGTest, LiteralScan) { + const char *table_name = "EXPR_LITERAL_50K"; + struct maat *maat_inst = HsExpr50KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_times = MAX_SCAN_TIMES; + thread_params[i].rule_count = 50000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); + } else { + thread_params[i].test_times = 0; + pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_times = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_times += thread_params[i].test_times; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_times * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "HsExpr50KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class RsExpr50KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_gtest.log", 0); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); + 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, g_table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); system_cmd_rmdir("COMPILE_PERF"); system_cmd_rmdir("GROUP2COMPILE_PERF"); } @@ -1752,12 +2805,12 @@ protected: static struct maat *_shared_maat_inst; }; -struct maat *Expr50KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Expr50KBenchmarkGTest::logger; +struct maat *RsExpr50KBenchmarkGTest::_shared_maat_inst; +struct log_handle *RsExpr50KBenchmarkGTest::logger; -TEST_F(Expr50KBenchmarkGTest, LiteralScan) { +TEST_F(RsExpr50KBenchmarkGTest, LiteralScan) { const char *table_name = "EXPR_LITERAL_50K"; - struct maat *maat_inst = Expr50KBenchmarkGTest::_shared_maat_inst; + struct maat *maat_inst = RsExpr50KBenchmarkGTest::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); @@ -1799,15 +2852,15 @@ TEST_F(Expr50KBenchmarkGTest, LiteralScan) { scan_per_second = scan_times * 1000 / time_elapse_ms; log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Expr50KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + "RsExpr50KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", PERF_THREAD_NUM, scan_per_second); } -class Expr100KBenchmarkGTest : public ::testing::Test +class HsExpr100KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_expr_sample("EXPR_LITERAL_100K", 100000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -1824,7 +2877,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "EXPR_LITERAL_100K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS); @@ -1836,6 +2889,82 @@ protected: static void TearDownTestCase() { maat_free(_shared_maat_inst); log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *HsExpr100KBenchmarkGTest::_shared_maat_inst; +struct log_handle *HsExpr100KBenchmarkGTest::logger; + +TEST_F(HsExpr100KBenchmarkGTest, LiteralScan) { + const char *table_name = "EXPR_LITERAL_100K"; + struct maat *maat_inst = HsExpr100KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_times = MAX_SCAN_TIMES; + thread_params[i].rule_count = 100000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); + } else { + thread_params[i].test_times = 0; + pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_times = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_times += thread_params[i].test_times; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_times * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "HsExpr100KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class RsExpr100KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_gtest.log", 0); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); + 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, g_table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); system_cmd_rmdir("COMPILE_PERF"); system_cmd_rmdir("GROUP2COMPILE_PERF"); } @@ -1844,12 +2973,12 @@ protected: static struct maat *_shared_maat_inst; }; -struct maat *Expr100KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Expr100KBenchmarkGTest::logger; +struct maat *RsExpr100KBenchmarkGTest::_shared_maat_inst; +struct log_handle *RsExpr100KBenchmarkGTest::logger; -TEST_F(Expr100KBenchmarkGTest, LiteralScan) { +TEST_F(RsExpr100KBenchmarkGTest, LiteralScan) { const char *table_name = "EXPR_LITERAL_100K"; - struct maat *maat_inst = Expr100KBenchmarkGTest::_shared_maat_inst; + struct maat *maat_inst = RsExpr100KBenchmarkGTest::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); @@ -1891,15 +3020,15 @@ TEST_F(Expr100KBenchmarkGTest, LiteralScan) { scan_per_second = scan_times * 1000 / time_elapse_ms; log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Expr100KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + "RsExpr100KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", PERF_THREAD_NUM, scan_per_second); } -class Expr500KBenchmarkGTest : public ::testing::Test +class HsExpr500KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_expr_sample("EXPR_LITERAL_500K", 500000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -1916,7 +3045,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "EXPR_LITERAL_500K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS); @@ -1928,6 +3057,82 @@ protected: static void TearDownTestCase() { maat_free(_shared_maat_inst); log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *HsExpr500KBenchmarkGTest::_shared_maat_inst; +struct log_handle *HsExpr500KBenchmarkGTest::logger; + +TEST_F(HsExpr500KBenchmarkGTest, LiteralScan) { + const char *table_name = "EXPR_LITERAL_500K"; + struct maat *maat_inst = HsExpr500KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_times = MAX_SCAN_TIMES; + thread_params[i].rule_count = 500000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); + } else { + thread_params[i].test_times = 0; + pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_times = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_times += thread_params[i].test_times; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_times * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "HsExpr500KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class RsExpr500KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_gtest.log", 0); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); + 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, g_table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); system_cmd_rmdir("COMPILE_PERF"); system_cmd_rmdir("GROUP2COMPILE_PERF"); } @@ -1936,12 +3141,12 @@ protected: static struct maat *_shared_maat_inst; }; -struct maat *Expr500KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Expr500KBenchmarkGTest::logger; +struct maat *RsExpr500KBenchmarkGTest::_shared_maat_inst; +struct log_handle *RsExpr500KBenchmarkGTest::logger; -TEST_F(Expr500KBenchmarkGTest, LiteralScan) { +TEST_F(RsExpr500KBenchmarkGTest, LiteralScan) { const char *table_name = "EXPR_LITERAL_500K"; - struct maat *maat_inst = Expr500KBenchmarkGTest::_shared_maat_inst; + struct maat *maat_inst = RsExpr500KBenchmarkGTest::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); @@ -1983,15 +3188,15 @@ TEST_F(Expr500KBenchmarkGTest, LiteralScan) { scan_per_second = scan_times * 1000 / time_elapse_ms; log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Expr500KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + "RsExpr500KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", PERF_THREAD_NUM, scan_per_second); } -class Expr1MBenchmarkGTest : public ::testing::Test +class HsExpr1MBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_expr_sample("EXPR_LITERAL_1M", 1000000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -2008,7 +3213,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "EXPR_LITERAL_1M", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS); @@ -2020,6 +3225,82 @@ protected: static void TearDownTestCase() { maat_free(_shared_maat_inst); log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *HsExpr1MBenchmarkGTest::_shared_maat_inst; +struct log_handle *HsExpr1MBenchmarkGTest::logger; + +TEST_F(HsExpr1MBenchmarkGTest, LiteralScan) { + const char *table_name = "EXPR_LITERAL_1M"; + struct maat *maat_inst = HsExpr1MBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_times = MAX_SCAN_TIMES; + thread_params[i].rule_count = 1000000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); + } else { + thread_params[i].test_times = 0; + pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_times = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_times += thread_params[i].test_times; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_times * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "HsExpr1MLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class RsExpr1MBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_gtest.log", 0); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); + 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, g_table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); system_cmd_rmdir("COMPILE_PERF"); system_cmd_rmdir("GROUP2COMPILE_PERF"); } @@ -2028,12 +3309,12 @@ protected: static struct maat *_shared_maat_inst; }; -struct maat *Expr1MBenchmarkGTest::_shared_maat_inst; -struct log_handle *Expr1MBenchmarkGTest::logger; +struct maat *RsExpr1MBenchmarkGTest::_shared_maat_inst; +struct log_handle *RsExpr1MBenchmarkGTest::logger; -TEST_F(Expr1MBenchmarkGTest, LiteralScan) { +TEST_F(RsExpr1MBenchmarkGTest, LiteralScan) { const char *table_name = "EXPR_LITERAL_1M"; - struct maat *maat_inst = Expr1MBenchmarkGTest::_shared_maat_inst; + struct maat *maat_inst = RsExpr1MBenchmarkGTest::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); @@ -2075,15 +3356,15 @@ TEST_F(Expr1MBenchmarkGTest, LiteralScan) { scan_per_second = scan_times * 1000 / time_elapse_ms; log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Expr1MLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + "RsExpr1MLiteralScan match rate on %d-threads speed %lld lookups/s/thread", PERF_THREAD_NUM, scan_per_second); } -class Expr2MBenchmarkGTest : public ::testing::Test +class HsExpr2MBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_expr_sample("EXPR_LITERAL_2M", 2000000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -2100,7 +3381,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "EXPR_LITERAL_2M", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS); @@ -2112,6 +3393,82 @@ protected: static void TearDownTestCase() { maat_free(_shared_maat_inst); log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *HsExpr2MBenchmarkGTest::_shared_maat_inst; +struct log_handle *HsExpr2MBenchmarkGTest::logger; + +TEST_F(HsExpr2MBenchmarkGTest, LiteralScan) { + const char *table_name = "EXPR_LITERAL_2M"; + struct maat *maat_inst = HsExpr2MBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_times = MAX_SCAN_TIMES; + thread_params[i].rule_count = 2000000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); + } else { + thread_params[i].test_times = 0; + pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_times = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_times += thread_params[i].test_times; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_times * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "HsExpr2MLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class RsExpr2MBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_gtest.log", 0); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); + 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, g_table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); system_cmd_rmdir("COMPILE_PERF"); system_cmd_rmdir("GROUP2COMPILE_PERF"); } @@ -2120,12 +3477,12 @@ protected: static struct maat *_shared_maat_inst; }; -struct maat *Expr2MBenchmarkGTest::_shared_maat_inst; -struct log_handle *Expr2MBenchmarkGTest::logger; +struct maat *RsExpr2MBenchmarkGTest::_shared_maat_inst; +struct log_handle *RsExpr2MBenchmarkGTest::logger; -TEST_F(Expr2MBenchmarkGTest, LiteralScan) { +TEST_F(RsExpr2MBenchmarkGTest, LiteralScan) { const char *table_name = "EXPR_LITERAL_2M"; - struct maat *maat_inst = Expr2MBenchmarkGTest::_shared_maat_inst; + struct maat *maat_inst = RsExpr2MBenchmarkGTest::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); @@ -2167,15 +3524,15 @@ TEST_F(Expr2MBenchmarkGTest, LiteralScan) { scan_per_second = scan_times * 1000 / time_elapse_ms; log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Expr2MLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + "RsExpr2MLiteralScan match rate on %d-threads speed %lld lookups/s/thread", PERF_THREAD_NUM, scan_per_second); } -class Stream1KBenchmarkGTest : public ::testing::Test +class HsStream1KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_expr_sample("STREAM_1K", 1000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -2192,7 +3549,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "STREAM_1K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS); @@ -2204,6 +3561,79 @@ protected: static void TearDownTestCase() { maat_free(_shared_maat_inst); log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *HsStream1KBenchmarkGTest::_shared_maat_inst; +struct log_handle *HsStream1KBenchmarkGTest::logger; + +TEST_F(HsStream1KBenchmarkGTest, LiteralScan) { + const char *table_name = "STREAM_1K"; + struct maat *maat_inst = HsStream1KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM]; + struct thread_param thread_params[PERF_THREAD_NUM]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_times = MAX_SCAN_TIMES; + thread_params[i].rule_count = 1000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_times = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_times += thread_params[i].test_times; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_times * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "HsStream1KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class RsStream1KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_gtest.log", 0); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); + 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, g_table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); system_cmd_rmdir("COMPILE_PERF"); system_cmd_rmdir("GROUP2COMPILE_PERF"); } @@ -2212,12 +3642,12 @@ protected: static struct maat *_shared_maat_inst; }; -struct maat *Stream1KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Stream1KBenchmarkGTest::logger; +struct maat *RsStream1KBenchmarkGTest::_shared_maat_inst; +struct log_handle *RsStream1KBenchmarkGTest::logger; -TEST_F(Stream1KBenchmarkGTest, LiteralScan) { +TEST_F(RsStream1KBenchmarkGTest, LiteralScan) { const char *table_name = "STREAM_1K"; - struct maat *maat_inst = Stream1KBenchmarkGTest::_shared_maat_inst; + struct maat *maat_inst = RsStream1KBenchmarkGTest::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); @@ -2256,15 +3686,15 @@ TEST_F(Stream1KBenchmarkGTest, LiteralScan) { scan_per_second = scan_times * 1000 / time_elapse_ms; log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Stream1KScan match rate on %d-threads speed %lld lookups/s/thread", + "RsStream1KScan match rate on %d-threads speed %lld lookups/s/thread", PERF_THREAD_NUM, scan_per_second); } -class Stream5KBenchmarkGTest : public ::testing::Test +class HsStream5KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_expr_sample("STREAM_5K", 5000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -2281,7 +3711,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "STREAM_5K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS); @@ -2293,6 +3723,79 @@ protected: static void TearDownTestCase() { maat_free(_shared_maat_inst); log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *HsStream5KBenchmarkGTest::_shared_maat_inst; +struct log_handle *HsStream5KBenchmarkGTest::logger; + +TEST_F(HsStream5KBenchmarkGTest, LiteralScan) { + const char *table_name = "STREAM_5K"; + struct maat *maat_inst = HsStream5KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM]; + struct thread_param thread_params[PERF_THREAD_NUM]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_times = MAX_SCAN_TIMES; + thread_params[i].rule_count = 5000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_times = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_times += thread_params[i].test_times; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_times * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "HsStream5KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class RsStream5KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_gtest.log", 0); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); + 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, g_table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); system_cmd_rmdir("COMPILE_PERF"); system_cmd_rmdir("GROUP2COMPILE_PERF"); } @@ -2301,12 +3804,12 @@ protected: static struct maat *_shared_maat_inst; }; -struct maat *Stream5KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Stream5KBenchmarkGTest::logger; +struct maat *RsStream5KBenchmarkGTest::_shared_maat_inst; +struct log_handle *RsStream5KBenchmarkGTest::logger; -TEST_F(Stream5KBenchmarkGTest, LiteralScan) { +TEST_F(RsStream5KBenchmarkGTest, LiteralScan) { const char *table_name = "STREAM_5K"; - struct maat *maat_inst = Stream5KBenchmarkGTest::_shared_maat_inst; + struct maat *maat_inst = RsStream5KBenchmarkGTest::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); @@ -2345,15 +3848,15 @@ TEST_F(Stream5KBenchmarkGTest, LiteralScan) { scan_per_second = scan_times * 1000 / time_elapse_ms; log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Stream5KScan match rate on %d-threads speed %lld lookups/s/thread", + "RsStream5KScan match rate on %d-threads speed %lld lookups/s/thread", PERF_THREAD_NUM, scan_per_second); } -class Stream10KBenchmarkGTest : public ::testing::Test +class HsStream10KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_expr_sample("STREAM_10K", 10000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -2370,7 +3873,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "STREAM_10K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS); @@ -2382,6 +3885,79 @@ protected: static void TearDownTestCase() { maat_free(_shared_maat_inst); log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *HsStream10KBenchmarkGTest::_shared_maat_inst; +struct log_handle *HsStream10KBenchmarkGTest::logger; + +TEST_F(HsStream10KBenchmarkGTest, LiteralScan) { + const char *table_name = "STREAM_10K"; + struct maat *maat_inst = HsStream10KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM]; + struct thread_param thread_params[PERF_THREAD_NUM]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_times = MAX_SCAN_TIMES; + thread_params[i].rule_count = 10000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_times = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_times += thread_params[i].test_times; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_times * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "HsStream10KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class RsStream10KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_gtest.log", 0); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); + 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, g_table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); system_cmd_rmdir("COMPILE_PERF"); system_cmd_rmdir("GROUP2COMPILE_PERF"); } @@ -2390,12 +3966,12 @@ protected: static struct maat *_shared_maat_inst; }; -struct maat *Stream10KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Stream10KBenchmarkGTest::logger; +struct maat *RsStream10KBenchmarkGTest::_shared_maat_inst; +struct log_handle *RsStream10KBenchmarkGTest::logger; -TEST_F(Stream10KBenchmarkGTest, LiteralScan) { +TEST_F(RsStream10KBenchmarkGTest, LiteralScan) { const char *table_name = "STREAM_10K"; - struct maat *maat_inst = Stream10KBenchmarkGTest::_shared_maat_inst; + struct maat *maat_inst = RsStream10KBenchmarkGTest::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); @@ -2434,15 +4010,15 @@ TEST_F(Stream10KBenchmarkGTest, LiteralScan) { scan_per_second = scan_times * 1000 / time_elapse_ms; log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Stream10KScan match rate on %d-threads speed %lld lookups/s/thread", + "RsStream10KScan match rate on %d-threads speed %lld lookups/s/thread", PERF_THREAD_NUM, scan_per_second); } -class Stream50KBenchmarkGTest : public ::testing::Test +class HsStream50KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_expr_sample("STREAM_50K", 50000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -2459,7 +4035,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "STREAM_50K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS); @@ -2471,6 +4047,79 @@ protected: static void TearDownTestCase() { maat_free(_shared_maat_inst); log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *HsStream50KBenchmarkGTest::_shared_maat_inst; +struct log_handle *HsStream50KBenchmarkGTest::logger; + +TEST_F(HsStream50KBenchmarkGTest, LiteralScan) { + const char *table_name = "STREAM_50K"; + struct maat *maat_inst = HsStream50KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM]; + struct thread_param thread_params[PERF_THREAD_NUM]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_times = MAX_SCAN_TIMES; + thread_params[i].rule_count = 50000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_times = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_times += thread_params[i].test_times; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_times * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "HsStream50KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class RsStream50KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_gtest.log", 0); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); + 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, g_table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); system_cmd_rmdir("COMPILE_PERF"); system_cmd_rmdir("GROUP2COMPILE_PERF"); } @@ -2479,12 +4128,12 @@ protected: static struct maat *_shared_maat_inst; }; -struct maat *Stream50KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Stream50KBenchmarkGTest::logger; +struct maat *RsStream50KBenchmarkGTest::_shared_maat_inst; +struct log_handle *RsStream50KBenchmarkGTest::logger; -TEST_F(Stream50KBenchmarkGTest, LiteralScan) { +TEST_F(RsStream50KBenchmarkGTest, LiteralScan) { const char *table_name = "STREAM_50K"; - struct maat *maat_inst = Stream50KBenchmarkGTest::_shared_maat_inst; + struct maat *maat_inst = RsStream50KBenchmarkGTest::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); @@ -2523,15 +4172,15 @@ TEST_F(Stream50KBenchmarkGTest, LiteralScan) { scan_per_second = scan_times * 1000 / time_elapse_ms; log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Stream50KScan match rate on %d-threads speed %lld lookups/s/thread", + "RsStream50KScan match rate on %d-threads speed %lld lookups/s/thread", PERF_THREAD_NUM, scan_per_second); } -class Stream100KBenchmarkGTest : public ::testing::Test +class HsStream100KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_expr_sample("STREAM_100K", 100000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -2548,7 +4197,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "STREAM_100K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS); @@ -2560,6 +4209,79 @@ protected: static void TearDownTestCase() { maat_free(_shared_maat_inst); log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *HsStream100KBenchmarkGTest::_shared_maat_inst; +struct log_handle *HsStream100KBenchmarkGTest::logger; + +TEST_F(HsStream100KBenchmarkGTest, LiteralScan) { + const char *table_name = "STREAM_100K"; + struct maat *maat_inst = HsStream100KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM]; + struct thread_param thread_params[PERF_THREAD_NUM]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_times = MAX_SCAN_TIMES; + thread_params[i].rule_count = 100000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_times = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_times += thread_params[i].test_times; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_times * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "HsStream100KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class RsStream100KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_gtest.log", 0); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); + 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, g_table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); system_cmd_rmdir("COMPILE_PERF"); system_cmd_rmdir("GROUP2COMPILE_PERF"); } @@ -2568,12 +4290,12 @@ protected: static struct maat *_shared_maat_inst; }; -struct maat *Stream100KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Stream100KBenchmarkGTest::logger; +struct maat *RsStream100KBenchmarkGTest::_shared_maat_inst; +struct log_handle *RsStream100KBenchmarkGTest::logger; -TEST_F(Stream100KBenchmarkGTest, LiteralScan) { +TEST_F(RsStream100KBenchmarkGTest, LiteralScan) { const char *table_name = "STREAM_100K"; - struct maat *maat_inst = Stream100KBenchmarkGTest::_shared_maat_inst; + struct maat *maat_inst = RsStream100KBenchmarkGTest::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); @@ -2612,15 +4334,15 @@ TEST_F(Stream100KBenchmarkGTest, LiteralScan) { scan_per_second = scan_times * 1000 / time_elapse_ms; log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Stream100KScan match rate on %d-threads speed %lld lookups/s/thread", + "RsStream100KScan match rate on %d-threads speed %lld lookups/s/thread", PERF_THREAD_NUM, scan_per_second); } -class Stream500KBenchmarkGTest : public ::testing::Test +class HsStream500KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_expr_sample("STREAM_500K", 500000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -2637,7 +4359,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "STREAM_500K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS); @@ -2649,6 +4371,79 @@ protected: static void TearDownTestCase() { maat_free(_shared_maat_inst); log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *HsStream500KBenchmarkGTest::_shared_maat_inst; +struct log_handle *HsStream500KBenchmarkGTest::logger; + +TEST_F(HsStream500KBenchmarkGTest, LiteralScan) { + const char *table_name = "STREAM_500K"; + struct maat *maat_inst = HsStream500KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM]; + struct thread_param thread_params[PERF_THREAD_NUM]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_times = MAX_SCAN_TIMES; + thread_params[i].rule_count = 500000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_times = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_times += thread_params[i].test_times; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_times * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "HsStream500KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class RsStream500KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_gtest.log", 0); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); + 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, g_table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); system_cmd_rmdir("COMPILE_PERF"); system_cmd_rmdir("GROUP2COMPILE_PERF"); } @@ -2657,12 +4452,12 @@ protected: static struct maat *_shared_maat_inst; }; -struct maat *Stream500KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Stream500KBenchmarkGTest::logger; +struct maat *RsStream500KBenchmarkGTest::_shared_maat_inst; +struct log_handle *RsStream500KBenchmarkGTest::logger; -TEST_F(Stream500KBenchmarkGTest, LiteralScan) { +TEST_F(RsStream500KBenchmarkGTest, LiteralScan) { const char *table_name = "STREAM_500K"; - struct maat *maat_inst = Stream500KBenchmarkGTest::_shared_maat_inst; + struct maat *maat_inst = RsStream500KBenchmarkGTest::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); @@ -2701,15 +4496,15 @@ TEST_F(Stream500KBenchmarkGTest, LiteralScan) { scan_per_second = scan_times * 1000 / time_elapse_ms; log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Stream500KScan match rate on %d-threads speed %lld lookups/s/thread", + "RsStream500KScan match rate on %d-threads speed %lld lookups/s/thread", PERF_THREAD_NUM, scan_per_second); } -class Stream1MBenchmarkGTest : public ::testing::Test +class HsStream1MBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_expr_sample("STREAM_1M", 1000000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -2726,7 +4521,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "STREAM_1M", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS); @@ -2738,6 +4533,79 @@ protected: static void TearDownTestCase() { maat_free(_shared_maat_inst); log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *HsStream1MBenchmarkGTest::_shared_maat_inst; +struct log_handle *HsStream1MBenchmarkGTest::logger; + +TEST_F(HsStream1MBenchmarkGTest, LiteralScan) { + const char *table_name = "STREAM_1M"; + struct maat *maat_inst = HsStream1MBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM]; + struct thread_param thread_params[PERF_THREAD_NUM]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_times = MAX_SCAN_TIMES; + thread_params[i].rule_count = 1000000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_times = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_times += thread_params[i].test_times; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_times * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "HsStream1MScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class RsStream1MBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_gtest.log", 0); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); + 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, g_table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); system_cmd_rmdir("COMPILE_PERF"); system_cmd_rmdir("GROUP2COMPILE_PERF"); } @@ -2746,12 +4614,12 @@ protected: static struct maat *_shared_maat_inst; }; -struct maat *Stream1MBenchmarkGTest::_shared_maat_inst; -struct log_handle *Stream1MBenchmarkGTest::logger; +struct maat *RsStream1MBenchmarkGTest::_shared_maat_inst; +struct log_handle *RsStream1MBenchmarkGTest::logger; -TEST_F(Stream1MBenchmarkGTest, LiteralScan) { +TEST_F(RsStream1MBenchmarkGTest, LiteralScan) { const char *table_name = "STREAM_1M"; - struct maat *maat_inst = Stream1MBenchmarkGTest::_shared_maat_inst; + struct maat *maat_inst = RsStream1MBenchmarkGTest::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); @@ -2790,15 +4658,15 @@ TEST_F(Stream1MBenchmarkGTest, LiteralScan) { scan_per_second = scan_times * 1000 / time_elapse_ms; log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Stream1MScan match rate on %d-threads speed %lld lookups/s/thread", + "RsStream1MScan match rate on %d-threads speed %lld lookups/s/thread", PERF_THREAD_NUM, scan_per_second); } -class Stream2MBenchmarkGTest : public ::testing::Test +class HsStream2MBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_expr_sample("STREAM_2M", 2000000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -2815,7 +4683,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "STREAM_2M", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS); @@ -2827,6 +4695,79 @@ protected: static void TearDownTestCase() { maat_free(_shared_maat_inst); log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *HsStream2MBenchmarkGTest::_shared_maat_inst; +struct log_handle *HsStream2MBenchmarkGTest::logger; + +TEST_F(HsStream2MBenchmarkGTest, LiteralScan) { + const char *table_name = "STREAM_2M"; + struct maat *maat_inst = HsStream2MBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM]; + struct thread_param thread_params[PERF_THREAD_NUM]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_times = MAX_SCAN_TIMES; + thread_params[i].rule_count = 2000000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_times = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_times += thread_params[i].test_times; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_times * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "HsStream2MScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class RsStream2MBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_gtest.log", 0); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); + 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, g_table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); system_cmd_rmdir("COMPILE_PERF"); system_cmd_rmdir("GROUP2COMPILE_PERF"); } @@ -2835,12 +4776,12 @@ protected: static struct maat *_shared_maat_inst; }; -struct maat *Stream2MBenchmarkGTest::_shared_maat_inst; -struct log_handle *Stream2MBenchmarkGTest::logger; +struct maat *RsStream2MBenchmarkGTest::_shared_maat_inst; +struct log_handle *RsStream2MBenchmarkGTest::logger; -TEST_F(Stream2MBenchmarkGTest, LiteralScan) { +TEST_F(RsStream2MBenchmarkGTest, LiteralScan) { const char *table_name = "STREAM_2M"; - struct maat *maat_inst = Stream2MBenchmarkGTest::_shared_maat_inst; + struct maat *maat_inst = RsStream2MBenchmarkGTest::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); @@ -2879,7 +4820,7 @@ TEST_F(Stream2MBenchmarkGTest, LiteralScan) { scan_per_second = scan_times * 1000 / time_elapse_ms; log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Stream2MScan match rate on %d-threads speed %lld lookups/s/thread", + "RsStream2MScan match rate on %d-threads speed %lld lookups/s/thread", PERF_THREAD_NUM, scan_per_second); } @@ -2887,7 +4828,7 @@ class IP1KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_ip_sample("IP_1K", 1000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -2904,7 +4845,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "IP_1K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); _shared_maat_inst = maat_new(opts, g_table_info_path); @@ -2977,7 +4918,7 @@ class IP5KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_ip_sample("IP_5K", 5000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -2994,7 +4935,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "IP_5K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); _shared_maat_inst = maat_new(opts, g_table_info_path); @@ -3067,7 +5008,7 @@ class IP10KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_ip_sample("IP_10K", 10000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -3084,7 +5025,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "IP_10K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); _shared_maat_inst = maat_new(opts, g_table_info_path); @@ -3157,7 +5098,7 @@ class IP50KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_ip_sample("IP_50K", 50000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -3174,7 +5115,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "IP_50K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); _shared_maat_inst = maat_new(opts, g_table_info_path); @@ -3247,7 +5188,7 @@ class IP100KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_ip_sample("IP_100K", 100000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -3264,7 +5205,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "IP_100K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); _shared_maat_inst = maat_new(opts, g_table_info_path); @@ -3337,7 +5278,7 @@ class IP500KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_ip_sample("IP_500K", 500000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -3354,7 +5295,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "IP_500K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); _shared_maat_inst = maat_new(opts, g_table_info_path); @@ -3427,7 +5368,7 @@ class IP1MBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_ip_sample("IP_1M", 1000000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -3444,7 +5385,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "IP_1M", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); _shared_maat_inst = maat_new(opts, g_table_info_path); @@ -3517,7 +5458,7 @@ class IP5MBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_ip_sample("IP_5M", 5000000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -3534,7 +5475,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "IP_5M", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); _shared_maat_inst = maat_new(opts, g_table_info_path); @@ -3607,7 +5548,7 @@ class IP10MBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_ip_sample("IP_10M", 10000000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -3624,7 +5565,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "IP_10M", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); _shared_maat_inst = maat_new(opts, g_table_info_path); @@ -3697,7 +5638,7 @@ class Integer1KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_integer_sample("INTEGER_1K", 1000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -3714,7 +5655,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "INTEGER_1K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); _shared_maat_inst = maat_new(opts, g_table_info_path); @@ -3787,7 +5728,7 @@ class Integer5KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_integer_sample("INTEGER_5K", 5000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -3804,7 +5745,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "INTEGER_5K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); _shared_maat_inst = maat_new(opts, g_table_info_path); @@ -3877,7 +5818,7 @@ class Integer10KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_integer_sample("INTEGER_10K", 10000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -3894,7 +5835,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "INTEGER_10K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); _shared_maat_inst = maat_new(opts, g_table_info_path); @@ -3967,7 +5908,7 @@ class Flag1KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_flag_sample("FLAG_1K", 1000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -3984,7 +5925,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "FLAG_1K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); _shared_maat_inst = maat_new(opts, g_table_info_path); @@ -4057,7 +5998,7 @@ class Flag5KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_flag_sample("FLAG_5K", 5000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -4074,7 +6015,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "FLAG_5K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); _shared_maat_inst = maat_new(opts, g_table_info_path); @@ -4147,7 +6088,7 @@ class Flag10KBenchmarkGTest : public ::testing::Test { protected: static void SetUpTestCase() { - logger = log_handle_create("./benchmark_hs_gtest.log", 0); + logger = log_handle_create("./benchmark_gtest.log", 0); generate_flag_sample("FLAG_10K", 10000); FILE *fp = fopen("full_config_index.0000001", "w+"); @@ -4164,7 +6105,7 @@ protected: generate_group2compile_sample("GROUP2COMPILE_PERF", "FLAG_10K", 10); struct maat_options *opts = maat_options_new(); - maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_logger(opts, "./benchmark_gtest.log", LOG_LEVEL_INFO); maat_options_set_iris(opts, "./", "./"); maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); _shared_maat_inst = maat_new(opts, g_table_info_path); @@ -4237,7 +6178,7 @@ int main(int argc, char ** argv) { int ret=0; ::testing::InitGoogleTest(&argc, argv); - g_logger = log_handle_create("./benchmark_hs_gtest.log", 0); + g_logger = log_handle_create("./benchmark_gtest.log", 0); ret=RUN_ALL_TESTS(); diff --git a/test/benchmark/benchmark_rs_gtest.cpp b/test/benchmark/benchmark_rs_gtest.cpp deleted file mode 100644 index 48f2954..0000000 --- a/test/benchmark/benchmark_rs_gtest.cpp +++ /dev/null @@ -1,3638 +0,0 @@ -#include "maat.h" -#include "log/log.h" -#include "maat_utils.h" -#include "maat_rule.h" -#include "json2iris.h" -#include "ip_matcher.h" -#include "maat_table.h" -#include "maat_config_monitor.h" - -#include <gtest/gtest.h> - -#define MODULE_BENCHMARK_GTEST module_name_str("maat.benchmark_gtest") - -#define MAX_EXPR_RULE_NUM 2000000 -#define MID_EXPR_RULE_NUM 1000000 - -#define MAX_IP_RULE_NUM 8000000 -#define MID_IP_RULE_NUM 4000000 - -#define MAX_INTEGER_RULE_NUM 10000 -#define MID_INTEGER_RULE_NUM 5000 - -#define MAX_FLAG_RULE_NUM 10000 -#define MID_FLAG_RULE_NUM 5000 - -#define ARRAY_SIZE 10 -#define PERF_THREAD_NUM 5 -#define MAX_scan_times 1000000 - -const char *g_table_info_path = "./benchmark_table_info.conf"; -struct log_handle *g_logger = NULL; - -struct thread_param { - int thread_id; - int test_times; - int rule_count; - struct maat *maat_inst; - const char *table_name; - long long time_elapse_ms; - struct log_handle *logger; -}; - -static void random_keyword_generate(char *keyword_buf, size_t sz) -{ -#define MIN_KEYWORD_LEN 4 - size_t i = 0, len = 0; - len = random() % (sz - 1 - MIN_KEYWORD_LEN) + MIN_KEYWORD_LEN; - - for (i = 0; i < len; i++) { - keyword_buf[i] = 'a' + random() % ('z' - 'a'); - } - keyword_buf[i] = '\0'; -} - -void generate_expr_sample(const char *table_name, int sample_count) -{ - FILE *fp = fopen(table_name, "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", table_name); - return; - } - - fprintf(fp, "%d\n", sample_count); - fprintf(fp, "1\t1\t%s\t1\t0\t0\t1\n", "the souls of the departed"); - - for (int i = 2; i <= sample_count; i++) { - char keyword_buf[64] = {0}; - random_keyword_generate(keyword_buf, sizeof(keyword_buf)); - fprintf(fp, "%d\t%d\t%s\t1\t0\t0\t1\n", i, i, keyword_buf); - } - - fclose(fp); -} - -void generate_ip_sample(const char *table_name, int sample_count) -{ - FILE *fp = fopen(table_name, "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", table_name); - return; - } - - fprintf(fp, "%d\n", sample_count); - fprintf(fp, "1\t1\t4\t%s\t%s\t%s\t%s\t%d\t%d\t-1\t1\n", "range", - "100.64.1.1", "100.64.1.1", "range", 20000, 20000); - - for (int i = 2; i <= sample_count-1; i++) { - char ip_buf[64] = {0}; - sprintf(ip_buf, "%d.%d.%d.%d", (int)(random() % 256), (int)(random() % 256), - (int)(random() % 256), (int)(random() % 256)); - fprintf(fp, "%d\t%d\t4\t%s\t%s\t%s\t%s\t%d\t%d\t-1\t1\n", - i+1, i+1, "range", ip_buf, ip_buf, "range", 20000, 20000); - } - - fclose(fp); -} - -void generate_integer_sample(const char *table_name, int sample_count) -{ - FILE *fp = fopen(table_name, "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", table_name); - return; - } - - fprintf(fp, "%d\n", sample_count); - fprintf(fp, "1\t1\t%d\t%d\t1\n", 1000000, 1000000); - - for (int i = 2; i <= sample_count-1; i++) { - fprintf(fp, "%d\t%d\t%d\t%d\t1\n", i+1, i+1, i+1, i+1); - } - - fclose(fp); -} - -void generate_flag_sample(const char *table_name, int sample_count) -{ - FILE *fp = fopen(table_name, "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", table_name); - return; - } - - fprintf(fp, "%d\n", sample_count); - fprintf(fp, "1\t1\t%d\t%d\t1\n", 1000000, 1111111); - - for (int i = 2; i <= sample_count-1; i++) { - fprintf(fp, "%d\t%d\t%d\t%d\t1\n", i+1, i+1, i+1, i+1); - } - - fclose(fp); -} - -void generate_compile_sample(const char *table_name, int sample_count) -{ - FILE *fp = fopen(table_name, "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", table_name); - return; - } - - fprintf(fp, "%d\n", sample_count); - - for (int i = 0; i < sample_count; i++) { - fprintf(fp, "%d\t1\t1\t1\t1\t0\t%s\t1\t1\n", 100+i, "null"); - } - - fclose(fp); -} - -void generate_group2compile_sample(const char *table_name, const char *vtable_name, - int sample_count) -{ - FILE *fp = fopen(table_name, "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", table_name); - return; - } - - fprintf(fp, "%d\n", sample_count); - - for (int i = 0; i < sample_count; i++) { - fprintf(fp, "%d\t%d\t0\t%s\t1\t1\n", i+1, 100+i, vtable_name); - } - - fclose(fp); -} - -void *perf_literal_scan_thread(void *arg) -{ - struct thread_param *param = (struct thread_param *)arg; - struct maat *maat_inst = param->maat_inst; - const char *table_name = param->table_name; - struct timespec start, end; - const char *scan_data = "Maat was the goddness of harmony, justice, and truth in ancient Egyptian." - " Her feather was the measure that determined whether the souls of the departed " - "would reach the paradise of the afterlife successfully"; - long long results[ARRAY_SIZE] = {0}; - int hit_times = 0; - size_t n_hit_result = 0; - struct maat_state *state = maat_state_new(maat_inst, param->thread_id); - - int table_id = maat_get_table_id(maat_inst, table_name); - - clock_gettime(CLOCK_MONOTONIC, &start); - for (int i = 0; i < param->test_times; i++) { - int ret = maat_scan_string(maat_inst, table_id, scan_data, strlen(scan_data), - results, ARRAY_SIZE, &n_hit_result, state); - if (ret == MAAT_SCAN_HIT) { - hit_times++; - } - maat_state_reset(state); - } - clock_gettime(CLOCK_MONOTONIC, &end); - - param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 + - (end.tv_nsec - start.tv_nsec) / 1000000; - int *is_all_hit = ALLOC(int, 1); - *is_all_hit = (hit_times == param->test_times ? 1 : 0); - log_info(param->logger, MODULE_BENCHMARK_GTEST, - "thread_id:%d rule_count:%d literal_scan time_elapse:%lldms hit_times:%d", - param->thread_id, param->rule_count, param->time_elapse_ms, hit_times); - - return is_all_hit; -} - -void *perf_literal_update_thread(void *arg) -{ - struct thread_param *param = (struct thread_param *)arg; - const char *table_name = param->table_name; - const int CMD_EXPR_NUM = 10; - char keyword_buf[128]; - - for (int i = 0; i < CMD_EXPR_NUM; i++) { - random_keyword_generate(keyword_buf, sizeof(keyword_buf)); - FILE *fp = fopen(table_name, "a+"); - if (NULL == fp) { - continue; - } - - fprintf(fp, "%d\t%d\t%s\t1\t0\t0\t1\n", 2000001+i, 2000001+i, keyword_buf); - fclose(fp); - - sleep(1); - } - - int *is_all_hit = ALLOC(int, 1); - *is_all_hit = 1; - - return is_all_hit; -} - -void *perf_stream_scan_thread(void *arg) -{ - struct thread_param *param = (struct thread_param *)arg; - struct maat *maat_inst = param->maat_inst; - const char *table_name = param->table_name; - struct timespec start, end; - const char *scan_data = "Maat was the goddness of harmony, justice, and truth in ancient Egyptian." - " Her feather was the measure that determined whether the souls of the departed " - "would reach the paradise of the afterlife successfully"; - long long results[ARRAY_SIZE] = {0}; - int ret = 0, hit_times = 0; - size_t n_hit_result = 0; - - int table_id = maat_get_table_id(maat_inst, table_name); - struct maat_state *state = maat_state_new(maat_inst, param->thread_id); - struct maat_stream *sp = maat_stream_new(maat_inst, table_id, state); - - clock_gettime(CLOCK_MONOTONIC, &start); - for (int i = 0; i < param->test_times; i++) { - ret = maat_stream_scan(sp, scan_data, strlen(scan_data), results, ARRAY_SIZE, - &n_hit_result, state); - if (ret == MAAT_SCAN_HIT) { - hit_times++; - } - maat_state_reset(state); - } - clock_gettime(CLOCK_MONOTONIC, &end); - maat_stream_free(sp); - maat_state_free(state); - - param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 + - (end.tv_nsec - start.tv_nsec) / 1000000; - int *is_all_hit = ALLOC(int, 1); - *is_all_hit = ((hit_times == param->test_times) ? 1 : 0); - - log_info(param->logger, MODULE_BENCHMARK_GTEST, - "thread_id:%d rule_count:%d stream_scan time_elapse:%lldms hit_times:%d", - param->thread_id, param->rule_count, param->time_elapse_ms, hit_times); - return is_all_hit; -} - -void *perf_ip_scan_thread(void *arg) -{ - struct thread_param *param = (struct thread_param *)arg; - struct maat *maat_inst = param->maat_inst; - const char *table_name = param->table_name; - struct timespec start, end; - long long results[ARRAY_SIZE] = {0}; - int hit_times = 0; - size_t n_hit_result = 0; - struct maat_state *state = maat_state_new(maat_inst, param->thread_id); - - int table_id = maat_get_table_id(maat_inst, table_name); - EXPECT_GT(table_id, 0); - - uint32_t ip_addr; - inet_pton(AF_INET, "100.64.1.1", &ip_addr); - - clock_gettime(CLOCK_MONOTONIC, &start); - for (int i = 0; i < param->test_times; i++) { - int ret = maat_scan_ipv4(maat_inst, table_id, ip_addr, results, - ARRAY_SIZE, &n_hit_result, state); - if (ret == MAAT_SCAN_HIT) { - hit_times++; - } - maat_state_reset(state); - } - clock_gettime(CLOCK_MONOTONIC, &end); - - param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 + - (end.tv_nsec - start.tv_nsec) / 1000000; - int *is_all_hit = ALLOC(int, 1); - *is_all_hit = (hit_times == param->test_times ? 1 : 0); - log_info(param->logger, MODULE_BENCHMARK_GTEST, - "thread_id:%d rule_count:%d ip_scan time_elapse:%lldms hit_times:%d", - param->thread_id, param->rule_count, param->time_elapse_ms, hit_times); - - return is_all_hit; -} - -void *perf_ip_update_thread(void *arg) -{ - struct thread_param *param = (struct thread_param *)arg; - const char *table_name = param->table_name; - const int CMD_EXPR_NUM = 10; - - for (int i = 0; i < CMD_EXPR_NUM; i++) { - FILE *fp = fopen(table_name, "a+"); - if (NULL == fp) { - continue; - } - - char ip_buf[64] = {0}; - sprintf(ip_buf, "%d.%d.%d.%d", (int)(random() % 256), (int)(random() % 256), - (int)(random() % 256), (int)(random() % 256)); - fprintf(fp, "%d\t%d\t4\t%s\t%s\t%s\t%s\t%d\t%d\t-1\t1\n", - 8000001+i, 8000001+i, "range", ip_buf, ip_buf, "range", 20000, 20000); - fclose(fp); - - sleep(1); - } - - int *is_all_hit = ALLOC(int, 1); - *is_all_hit = 1; - - return is_all_hit; -} - -void *perf_integer_scan_thread(void *arg) -{ - struct thread_param *param = (struct thread_param *)arg; - struct maat *maat_inst = param->maat_inst; - const char *table_name = param->table_name; - struct timespec start, end; - long long results[ARRAY_SIZE] = {0}; - int hit_times = 0; - size_t n_hit_result = 0; - struct maat_state *state = maat_state_new(maat_inst, param->thread_id); - - int table_id = maat_get_table_id(maat_inst, table_name); - EXPECT_GT(table_id, 0); - - long long scan_data = 1000000; - - clock_gettime(CLOCK_MONOTONIC, &start); - for (int i = 0; i < param->test_times; i++) { - int ret = maat_scan_integer(maat_inst, table_id, scan_data, results, - ARRAY_SIZE, &n_hit_result, state); - if (ret == MAAT_SCAN_HIT) { - hit_times++; - } - maat_state_reset(state); - } - clock_gettime(CLOCK_MONOTONIC, &end); - - param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 + - (end.tv_nsec - start.tv_nsec) / 1000000; - int *is_all_hit = ALLOC(int, 1); - *is_all_hit = (hit_times == param->test_times ? 1 : 0); - log_info(param->logger, MODULE_BENCHMARK_GTEST, - "thread_id:%d rule_count:%d integer_scan time_elapse:%lldms hit_times:%d", - param->thread_id, param->rule_count, param->time_elapse_ms, hit_times); - - return is_all_hit; -} - -void *perf_integer_update_thread(void *arg) -{ - struct thread_param *param = (struct thread_param *)arg; - const char *table_name = param->table_name; - const int CMD_EXPR_NUM = 10; - - for (int i = 0; i < CMD_EXPR_NUM; i++) { - FILE *fp = fopen(table_name, "a+"); - if (NULL == fp) { - continue; - } - - fprintf(fp, "%d\t%d\t%d\t%d\t1\n", 10001+i, 10001+i, 10001+i, 10001+i); - fclose(fp); - - sleep(1); - } - - int *is_all_hit = ALLOC(int, 1); - *is_all_hit = 1; - - return is_all_hit; -} - -void *perf_flag_scan_thread(void *arg) -{ - struct thread_param *param = (struct thread_param *)arg; - struct maat *maat_inst = param->maat_inst; - const char *table_name = param->table_name; - struct timespec start, end; - long long results[ARRAY_SIZE] = {0}; - int hit_times = 0; - size_t n_hit_result = 0; - struct maat_state *state = maat_state_new(maat_inst, param->thread_id); - - int table_id = maat_get_table_id(maat_inst, table_name); - EXPECT_GT(table_id, 0); - - long long scan_data = 1000000; - - clock_gettime(CLOCK_MONOTONIC, &start); - for (int i = 0; i < param->test_times; i++) { - int ret = maat_scan_flag(maat_inst, table_id, scan_data, results, - ARRAY_SIZE, &n_hit_result, state); - if (ret == MAAT_SCAN_HIT) { - hit_times++; - } - maat_state_reset(state); - } - clock_gettime(CLOCK_MONOTONIC, &end); - - param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 + - (end.tv_nsec - start.tv_nsec) / 1000000; - int *is_all_hit = ALLOC(int, 1); - *is_all_hit = (hit_times == param->test_times ? 1 : 0); - log_info(param->logger, MODULE_BENCHMARK_GTEST, - "thread_id:%d rule_count:%d flag_scan time_elapse:%lldms hit_times:%d", - param->thread_id, param->rule_count, param->time_elapse_ms, hit_times); - - return is_all_hit; -} - -void *perf_flag_update_thread(void *arg) -{ - struct thread_param *param = (struct thread_param *)arg; - const char *table_name = param->table_name; - const int CMD_EXPR_NUM = 10; - - for (int i = 0; i < CMD_EXPR_NUM; i++) { - FILE *fp = fopen(table_name, "a+"); - if (NULL == fp) { - continue; - } - - fprintf(fp, "%d\t%d\t%d\t%d\t1\n", 10001+i, 10001+i, 10001+i, 10001+i); - fclose(fp); - - sleep(1); - } - - int *is_all_hit = ALLOC(int, 1); - *is_all_hit = 1; - - return is_all_hit; -} - -void *perf_regex_scan_thread(void *arg) -{ - struct thread_param *param = (struct thread_param *)arg; - struct maat *maat_inst = param->maat_inst; - const char *table_name = param->table_name; - struct timespec start, end; - const char *scan_data = "Maat was the goddness of harmony, justice, and truth in ancient Egyptian." - "Request from User-Agent: Chrome, will go to yyy.abc.net"; - long long results[ARRAY_SIZE] = {0}; - int hit_times = 0; - size_t n_hit_result = 0; - struct maat_state *state = maat_state_new(maat_inst, param->thread_id); - - int table_id = maat_get_table_id(maat_inst, table_name); - - clock_gettime(CLOCK_MONOTONIC, &start); - for (int i = 0; i < param->test_times; i++) { - int ret = maat_scan_string(maat_inst, table_id, scan_data, strlen(scan_data), - results, ARRAY_SIZE, &n_hit_result, state); - if (ret == MAAT_SCAN_HIT) { - hit_times++; - } - maat_state_reset(state); - } - clock_gettime(CLOCK_MONOTONIC, &end); - - param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 + - (end.tv_nsec - start.tv_nsec) / 1000000; - int *is_all_hit = ALLOC(int, 1); - *is_all_hit = (hit_times == param->test_times ? 1 : 0); - log_info(param->logger, MODULE_BENCHMARK_GTEST, - "thread_id:%d rule_count:%d regex_scan time_elapse:%lldms hit_times:%d", - param->thread_id, param->rule_count, param->time_elapse_ms, hit_times); - - return is_all_hit; -} - -void *perf_regex_update_thread(void *arg) -{ - struct thread_param *param = (struct thread_param *)arg; - const char *table_name = param->table_name; - const int CMD_EXPR_NUM = 10; - char keyword_buf[128]; - - for (int i = 0; i < CMD_EXPR_NUM; i++) { - random_keyword_generate(keyword_buf, sizeof(keyword_buf)); - FILE *fp = fopen(table_name, "a+"); - if (NULL == fp) { - continue; - } - - fprintf(fp, "%d\t%d\t%s\t1\t0\t0\t1\n", 2000001+i, 2000001+i, keyword_buf); - fclose(fp); - - sleep(1); - } - - int *is_all_hit = ALLOC(int, 1); - *is_all_hit = 1; - - return is_all_hit; -} - -class Regex100BenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "REGEX_100\t100\t./regex_rules/REGEX_100\n"); - fprintf(fp, "COMPILE_PERF\t10\t./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF\t10\t./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "REGEX_100", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *Regex100BenchmarkGTest::_shared_maat_inst; -struct log_handle *Regex100BenchmarkGTest::logger; - -TEST_F(Regex100BenchmarkGTest, LiteralScan) { - const char *table_name = "REGEX_100"; - struct maat *maat_inst = Regex100BenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM + 1]; - struct thread_param thread_params[PERF_THREAD_NUM + 1]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 100; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_regex_scan_thread, thread_params+i); - } else { - thread_params[i].test_times = 0; - pthread_create(&threads[i], NULL, perf_regex_update_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Regex100Scan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class Regex200BenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "REGEX_200\t200\t./regex_rules/REGEX_200\n"); - fprintf(fp, "COMPILE_PERF\t10\t./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF\t10\t./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "REGEX_200", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *Regex200BenchmarkGTest::_shared_maat_inst; -struct log_handle *Regex200BenchmarkGTest::logger; - -TEST_F(Regex200BenchmarkGTest, LiteralScan) { - const char *table_name = "REGEX_200"; - struct maat *maat_inst = Regex200BenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM + 1]; - struct thread_param thread_params[PERF_THREAD_NUM + 1]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 200; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_regex_scan_thread, thread_params+i); - } else { - thread_params[i].test_times = 0; - pthread_create(&threads[i], NULL, perf_regex_update_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Regex200Scan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class Regex300BenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "REGEX_300\t300\t./regex_rules/REGEX_300\n"); - fprintf(fp, "COMPILE_PERF\t10\t./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF\t10\t./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "REGEX_300", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *Regex300BenchmarkGTest::_shared_maat_inst; -struct log_handle *Regex300BenchmarkGTest::logger; - -TEST_F(Regex300BenchmarkGTest, LiteralScan) { - const char *table_name = "REGEX_300"; - struct maat *maat_inst = Regex300BenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM + 1]; - struct thread_param thread_params[PERF_THREAD_NUM + 1]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 300; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_regex_scan_thread, thread_params+i); - } else { - thread_params[i].test_times = 0; - pthread_create(&threads[i], NULL, perf_regex_update_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Regex300Scan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class Expr1KBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_expr_sample("EXPR_LITERAL_1K", 1000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "EXPR_LITERAL_1K 1000 ./EXPR_LITERAL_1K\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "EXPR_LITERAL_1K", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *Expr1KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Expr1KBenchmarkGTest::logger; - -TEST_F(Expr1KBenchmarkGTest, LiteralScan) { - const char *table_name = "EXPR_LITERAL_1K"; - struct maat *maat_inst = Expr1KBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM + 1]; - struct thread_param thread_params[PERF_THREAD_NUM + 1]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 1000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); - } else { - thread_params[i].test_times = 0; - pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Expr1KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class Expr5KBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_expr_sample("EXPR_LITERAL_5K", 5000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "EXPR_LITERAL_5K 5000 ./EXPR_LITERAL_5K\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "EXPR_LITERAL_5K", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *Expr5KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Expr5KBenchmarkGTest::logger; - -TEST_F(Expr5KBenchmarkGTest, LiteralScan) { - const char *table_name = "EXPR_LITERAL_5K"; - struct maat *maat_inst = Expr5KBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM + 1]; - struct thread_param thread_params[PERF_THREAD_NUM + 1]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 5000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); - } else { - thread_params[i].test_times = 0; - pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Expr5KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class Expr10KBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_expr_sample("EXPR_LITERAL_10K", 10000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "EXPR_LITERAL_10K 10000 ./EXPR_LITERAL_10K\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "EXPR_LITERAL_10K", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *Expr10KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Expr10KBenchmarkGTest::logger; - -TEST_F(Expr10KBenchmarkGTest, LiteralScan) { - const char *table_name = "EXPR_LITERAL_10K"; - struct maat *maat_inst = Expr10KBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM + 1]; - struct thread_param thread_params[PERF_THREAD_NUM + 1]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 10000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); - } else { - thread_params[i].test_times = 0; - pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Expr10KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class Expr50KBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_expr_sample("EXPR_LITERAL_50K", 50000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "EXPR_LITERAL_50K 50000 ./EXPR_LITERAL_50K\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "EXPR_LITERAL_50K", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *Expr50KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Expr50KBenchmarkGTest::logger; - -TEST_F(Expr50KBenchmarkGTest, LiteralScan) { - const char *table_name = "EXPR_LITERAL_50K"; - struct maat *maat_inst = Expr50KBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM + 1]; - struct thread_param thread_params[PERF_THREAD_NUM + 1]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 50000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); - } else { - thread_params[i].test_times = 0; - pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Expr50KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class Expr100KBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_expr_sample("EXPR_LITERAL_100K", 100000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "EXPR_LITERAL_100K 100000 ./EXPR_LITERAL_100K\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "EXPR_LITERAL_100K", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *Expr100KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Expr100KBenchmarkGTest::logger; - -TEST_F(Expr100KBenchmarkGTest, LiteralScan) { - const char *table_name = "EXPR_LITERAL_100K"; - struct maat *maat_inst = Expr100KBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM + 1]; - struct thread_param thread_params[PERF_THREAD_NUM + 1]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 100000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); - } else { - thread_params[i].test_times = 0; - pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Expr100KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class Expr500KBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_expr_sample("EXPR_LITERAL_500K", 500000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "EXPR_LITERAL_500K 500000 ./EXPR_LITERAL_500K\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "EXPR_LITERAL_500K", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *Expr500KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Expr500KBenchmarkGTest::logger; - -TEST_F(Expr500KBenchmarkGTest, LiteralScan) { - const char *table_name = "EXPR_LITERAL_500K"; - struct maat *maat_inst = Expr500KBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM + 1]; - struct thread_param thread_params[PERF_THREAD_NUM + 1]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 500000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); - } else { - thread_params[i].test_times = 0; - pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Expr500KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class Expr1MBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_expr_sample("EXPR_LITERAL_1M", 1000000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "EXPR_LITERAL_1M 1000000 ./EXPR_LITERAL_1M\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "EXPR_LITERAL_1M", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *Expr1MBenchmarkGTest::_shared_maat_inst; -struct log_handle *Expr1MBenchmarkGTest::logger; - -TEST_F(Expr1MBenchmarkGTest, LiteralScan) { - const char *table_name = "EXPR_LITERAL_1M"; - struct maat *maat_inst = Expr1MBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM + 1]; - struct thread_param thread_params[PERF_THREAD_NUM + 1]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 1000000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); - } else { - thread_params[i].test_times = 0; - pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Expr1MLiteralScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class Expr2MBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_expr_sample("EXPR_LITERAL_2M", 2000000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "EXPR_LITERAL_2M 2000000 ./EXPR_LITERAL_2M\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "EXPR_LITERAL_2M", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *Expr2MBenchmarkGTest::_shared_maat_inst; -struct log_handle *Expr2MBenchmarkGTest::logger; - -TEST_F(Expr2MBenchmarkGTest, LiteralScan) { - const char *table_name = "EXPR_LITERAL_2M"; - struct maat *maat_inst = Expr2MBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM + 1]; - struct thread_param thread_params[PERF_THREAD_NUM + 1]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 2000000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); - } else { - thread_params[i].test_times = 0; - pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Expr2MLiteralScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class Stream1KBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_expr_sample("STREAM_1K", 1000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "STREAM_1K 1000 ./STREAM_1K\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "STREAM_1K", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *Stream1KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Stream1KBenchmarkGTest::logger; - -TEST_F(Stream1KBenchmarkGTest, LiteralScan) { - const char *table_name = "STREAM_1K"; - struct maat *maat_inst = Stream1KBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM]; - struct thread_param thread_params[PERF_THREAD_NUM]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 1000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Stream1KScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class Stream5KBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_expr_sample("STREAM_5K", 5000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "STREAM_5K 5000 ./STREAM_5K\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "STREAM_5K", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *Stream5KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Stream5KBenchmarkGTest::logger; - -TEST_F(Stream5KBenchmarkGTest, LiteralScan) { - const char *table_name = "STREAM_5K"; - struct maat *maat_inst = Stream5KBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM]; - struct thread_param thread_params[PERF_THREAD_NUM]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 5000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Stream5KScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class Stream10KBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_expr_sample("STREAM_10K", 10000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "STREAM_10K 10000 ./STREAM_10K\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "STREAM_10K", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *Stream10KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Stream10KBenchmarkGTest::logger; - -TEST_F(Stream10KBenchmarkGTest, LiteralScan) { - const char *table_name = "STREAM_10K"; - struct maat *maat_inst = Stream10KBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM]; - struct thread_param thread_params[PERF_THREAD_NUM]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 10000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Stream10KScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class Stream50KBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_expr_sample("STREAM_50K", 50000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "STREAM_50K 50000 ./STREAM_50K\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "STREAM_50K", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *Stream50KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Stream50KBenchmarkGTest::logger; - -TEST_F(Stream50KBenchmarkGTest, LiteralScan) { - const char *table_name = "STREAM_50K"; - struct maat *maat_inst = Stream50KBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM]; - struct thread_param thread_params[PERF_THREAD_NUM]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 50000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Stream50KScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class Stream100KBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_expr_sample("STREAM_100K", 100000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "STREAM_100K 100000 ./STREAM_100K\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "STREAM_100K", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *Stream100KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Stream100KBenchmarkGTest::logger; - -TEST_F(Stream100KBenchmarkGTest, LiteralScan) { - const char *table_name = "STREAM_100K"; - struct maat *maat_inst = Stream100KBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM]; - struct thread_param thread_params[PERF_THREAD_NUM]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 100000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Stream100KScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class Stream500KBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_expr_sample("STREAM_500K", 500000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "STREAM_500K 500000 ./STREAM_500K\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "STREAM_500K", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *Stream500KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Stream500KBenchmarkGTest::logger; - -TEST_F(Stream500KBenchmarkGTest, LiteralScan) { - const char *table_name = "STREAM_500K"; - struct maat *maat_inst = Stream500KBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM]; - struct thread_param thread_params[PERF_THREAD_NUM]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 500000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Stream500KScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class Stream1MBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_expr_sample("STREAM_1M", 1000000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "STREAM_1M 1000000 ./STREAM_1M\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "STREAM_1M", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *Stream1MBenchmarkGTest::_shared_maat_inst; -struct log_handle *Stream1MBenchmarkGTest::logger; - -TEST_F(Stream1MBenchmarkGTest, LiteralScan) { - const char *table_name = "STREAM_1M"; - struct maat *maat_inst = Stream1MBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM]; - struct thread_param thread_params[PERF_THREAD_NUM]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 1000000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Stream1MScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class Stream2MBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_expr_sample("STREAM_2M", 2000000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "STREAM_2M 2000000 ./STREAM_2M\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "STREAM_2M", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *Stream2MBenchmarkGTest::_shared_maat_inst; -struct log_handle *Stream2MBenchmarkGTest::logger; - -TEST_F(Stream2MBenchmarkGTest, LiteralScan) { - const char *table_name = "STREAM_2M"; - struct maat *maat_inst = Stream2MBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM]; - struct thread_param thread_params[PERF_THREAD_NUM]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 2000000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Stream2MScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class IP1KBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_ip_sample("IP_1K", 1000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "IP_1K 1000 ./IP_1K\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "IP_1K", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *IP1KBenchmarkGTest::_shared_maat_inst; -struct log_handle *IP1KBenchmarkGTest::logger; - -TEST_F(IP1KBenchmarkGTest, IPScan) { - const char *table_name = "IP_1K"; - struct maat *maat_inst = IP1KBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM + 1]; - struct thread_param thread_params[PERF_THREAD_NUM + 1]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 1000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i); - } else { - thread_params[i].test_times = 0; - pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "IP1KScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class IP5KBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_ip_sample("IP_5K", 5000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "IP_5K 5000 ./IP_5K\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "IP_5K", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *IP5KBenchmarkGTest::_shared_maat_inst; -struct log_handle *IP5KBenchmarkGTest::logger; - -TEST_F(IP5KBenchmarkGTest, IPScan) { - const char *table_name = "IP_5K"; - struct maat *maat_inst = IP5KBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM + 1]; - struct thread_param thread_params[PERF_THREAD_NUM + 1]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 5000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i); - } else { - thread_params[i].test_times = 0; - pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "IP5KScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class IP10KBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_ip_sample("IP_10K", 10000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "IP_10K 10000 ./IP_10K\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "IP_10K", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *IP10KBenchmarkGTest::_shared_maat_inst; -struct log_handle *IP10KBenchmarkGTest::logger; - -TEST_F(IP10KBenchmarkGTest, IPScan) { - const char *table_name = "IP_10K"; - struct maat *maat_inst = IP10KBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM + 1]; - struct thread_param thread_params[PERF_THREAD_NUM + 1]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 10000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i); - } else { - thread_params[i].test_times = 0; - pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "IP10KScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class IP50KBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_ip_sample("IP_50K", 50000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "IP_50K 50000 ./IP_50K\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "IP_50K", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *IP50KBenchmarkGTest::_shared_maat_inst; -struct log_handle *IP50KBenchmarkGTest::logger; - -TEST_F(IP50KBenchmarkGTest, IPScan) { - const char *table_name = "IP_50K"; - struct maat *maat_inst = IP50KBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM + 1]; - struct thread_param thread_params[PERF_THREAD_NUM + 1]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 50000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i); - } else { - thread_params[i].test_times = 0; - pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "IP50KScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class IP100KBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_ip_sample("IP_100K", 100000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "IP_100K 100000 ./IP_100K\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "IP_100K", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *IP100KBenchmarkGTest::_shared_maat_inst; -struct log_handle *IP100KBenchmarkGTest::logger; - -TEST_F(IP100KBenchmarkGTest, IPScan) { - const char *table_name = "IP_100K"; - struct maat *maat_inst = IP100KBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM + 1]; - struct thread_param thread_params[PERF_THREAD_NUM + 1]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 100000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i); - } else { - thread_params[i].test_times = 0; - pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "IP100KScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class IP500KBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_ip_sample("IP_500K", 500000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "IP_500K 500000 ./IP_500K\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "IP_500K", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *IP500KBenchmarkGTest::_shared_maat_inst; -struct log_handle *IP500KBenchmarkGTest::logger; - -TEST_F(IP500KBenchmarkGTest, IPScan) { - const char *table_name = "IP_500K"; - struct maat *maat_inst = IP500KBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM + 1]; - struct thread_param thread_params[PERF_THREAD_NUM + 1]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 500000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i); - } else { - thread_params[i].test_times = 0; - pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "IP500KScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class IP1MBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_ip_sample("IP_1M", 1000000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "IP_1M 1000000 ./IP_1M\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "IP_1M", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *IP1MBenchmarkGTest::_shared_maat_inst; -struct log_handle *IP1MBenchmarkGTest::logger; - -TEST_F(IP1MBenchmarkGTest, IPScan) { - const char *table_name = "IP_1M"; - struct maat *maat_inst = IP1MBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM + 1]; - struct thread_param thread_params[PERF_THREAD_NUM + 1]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 1000000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i); - } else { - thread_params[i].test_times = 0; - pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "IP1MScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class IP5MBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_ip_sample("IP_5M", 5000000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "IP_5M 5000000 ./IP_5M\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "IP_5M", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *IP5MBenchmarkGTest::_shared_maat_inst; -struct log_handle *IP5MBenchmarkGTest::logger; - -TEST_F(IP5MBenchmarkGTest, IPScan) { - const char *table_name = "IP_5M"; - struct maat *maat_inst = IP5MBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM + 1]; - struct thread_param thread_params[PERF_THREAD_NUM + 1]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 5000000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i); - } else { - thread_params[i].test_times = 0; - pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "IP5MScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class IP10MBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_ip_sample("IP_10M", 10000000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "IP_10M 10000000 ./IP_10M\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "IP_10M", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *IP10MBenchmarkGTest::_shared_maat_inst; -struct log_handle *IP10MBenchmarkGTest::logger; - -TEST_F(IP10MBenchmarkGTest, IPScan) { - const char *table_name = "IP_10M"; - struct maat *maat_inst = IP10MBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM + 1]; - struct thread_param thread_params[PERF_THREAD_NUM + 1]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 10000000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i); - } else { - thread_params[i].test_times = 0; - pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "IP10MScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class Integer1KBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_integer_sample("INTEGER_1K", 1000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "INTEGER_1K 1000 ./INTEGER_1K\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "INTEGER_1K", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *Integer1KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Integer1KBenchmarkGTest::logger; - -TEST_F(Integer1KBenchmarkGTest, IntegerScan) { - const char *table_name = "INTEGER_1K"; - struct maat *maat_inst = Integer1KBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM + 1]; - struct thread_param thread_params[PERF_THREAD_NUM + 1]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 1000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_integer_scan_thread, thread_params+i); - } else { - thread_params[i].test_times = 0; - pthread_create(&threads[i], NULL, perf_integer_update_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Integer1KScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class Integer5KBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_integer_sample("INTEGER_5K", 5000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "INTEGER_5K 5000 ./INTEGER_5K\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "INTEGER_5K", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *Integer5KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Integer5KBenchmarkGTest::logger; - -TEST_F(Integer5KBenchmarkGTest, IntegerScan) { - const char *table_name = "INTEGER_5K"; - struct maat *maat_inst = Integer5KBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM + 1]; - struct thread_param thread_params[PERF_THREAD_NUM + 1]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 5000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_integer_scan_thread, thread_params+i); - } else { - thread_params[i].test_times = 0; - pthread_create(&threads[i], NULL, perf_integer_update_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Integer5KScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class Integer10KBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_integer_sample("INTEGER_10K", 10000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "INTEGER_10K 10000 ./INTEGER_10K\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "INTEGER_10K", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *Integer10KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Integer10KBenchmarkGTest::logger; - -TEST_F(Integer10KBenchmarkGTest, IntegerScan) { - const char *table_name = "INTEGER_10K"; - struct maat *maat_inst = Integer10KBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM + 1]; - struct thread_param thread_params[PERF_THREAD_NUM + 1]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 10000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_integer_scan_thread, thread_params+i); - } else { - thread_params[i].test_times = 0; - pthread_create(&threads[i], NULL, perf_integer_update_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Integer10KScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class Flag1KBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_flag_sample("FLAG_1K", 1000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "FLAG_1K 1000 ./FLAG_1K\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "FLAG_1K", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *Flag1KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Flag1KBenchmarkGTest::logger; - -TEST_F(Flag1KBenchmarkGTest, FlagScan) { - const char *table_name = "FLAG_1K"; - struct maat *maat_inst = Flag1KBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM + 1]; - struct thread_param thread_params[PERF_THREAD_NUM + 1]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 1000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_flag_scan_thread, thread_params+i); - } else { - thread_params[i].test_times = 0; - pthread_create(&threads[i], NULL, perf_flag_update_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Flag1KScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class Flag5KBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_flag_sample("FLAG_5K", 5000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "FLAG_5K 5000 ./FLAG_5K\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "FLAG_5K", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *Flag5KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Flag5KBenchmarkGTest::logger; - -TEST_F(Flag5KBenchmarkGTest, FlagScan) { - const char *table_name = "FLAG_5K"; - struct maat *maat_inst = Flag5KBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM + 1]; - struct thread_param thread_params[PERF_THREAD_NUM + 1]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 5000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_flag_scan_thread, thread_params+i); - } else { - thread_params[i].test_times = 0; - pthread_create(&threads[i], NULL, perf_flag_update_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Flag5KScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -class Flag10KBenchmarkGTest : public ::testing::Test -{ -protected: - static void SetUpTestCase() { - logger = log_handle_create("./benchmark_rs_gtest.log", 0); - generate_flag_sample("FLAG_10K", 10000); - - FILE *fp = fopen("full_config_index.0000001", "w+"); - if (NULL == fp) { - log_fatal(g_logger, "open file %s failed", "full_config_index.0000001"); - return; - } - fprintf(fp, "FLAG_10K 10000 ./FLAG_10K\n"); - fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); - fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); - fclose(fp); - - generate_compile_sample("COMPILE_PERF", 10); - generate_group2compile_sample("GROUP2COMPILE_PERF", "FLAG_10K", 10); - - 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_caller_thread_number(opts, PERF_THREAD_NUM); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); - - _shared_maat_inst = maat_new(opts, g_table_info_path); - maat_options_free(opts); - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - system_cmd_rmdir("COMPILE_PERF"); - system_cmd_rmdir("GROUP2COMPILE_PERF"); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *Flag10KBenchmarkGTest::_shared_maat_inst; -struct log_handle *Flag10KBenchmarkGTest::logger; - -TEST_F(Flag10KBenchmarkGTest, FlagScan) { - const char *table_name = "FLAG_10K"; - struct maat *maat_inst = Flag10KBenchmarkGTest::_shared_maat_inst; - - int table_id = maat_get_table_id(maat_inst, table_name); - ASSERT_GT(table_id, 0); - - pthread_t threads[PERF_THREAD_NUM + 1]; - struct thread_param thread_params[PERF_THREAD_NUM + 1]; - int i = 0; - int *is_all_hit = NULL; - - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - thread_params[i].maat_inst = maat_inst; - thread_params[i].thread_id = i; - thread_params[i].table_name = table_name; - thread_params[i].test_times = MAX_scan_times; - thread_params[i].rule_count = 10000; - thread_params[i].time_elapse_ms = 0; - thread_params[i].logger = logger; - - if (i < PERF_THREAD_NUM) { - pthread_create(&threads[i], NULL, perf_flag_scan_thread, thread_params+i); - } else { - thread_params[i].test_times = 0; - pthread_create(&threads[i], NULL, perf_flag_update_thread, thread_params+i); - } - } - - long long time_elapse_ms = 0; - long long scan_times = 0; - long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { - pthread_join(threads[i], (void **)&is_all_hit); - time_elapse_ms += thread_params[i].time_elapse_ms; - scan_times += thread_params[i].test_times; - - EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; - free(is_all_hit); - } - scan_per_second = scan_times * 1000 / time_elapse_ms; - - log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, - "Flag10KScan match rate on %d-threads speed %lld lookups/s/thread", - PERF_THREAD_NUM, scan_per_second); -} - -int main(int argc, char ** argv) -{ - int ret=0; - ::testing::InitGoogleTest(&argc, argv); - g_logger = log_handle_create("./benchmark_rs_gtest.log", 0); - - ret=RUN_ALL_TESTS(); - - log_handle_destroy(g_logger); - return ret; -} diff --git a/test/expr_matcher_gtest.cpp b/test/expr_matcher_gtest.cpp index 3f6e52c..43efcac 100644 --- a/test/expr_matcher_gtest.cpp +++ b/test/expr_matcher_gtest.cpp @@ -41,7 +41,7 @@ enum expr_case_sensitive case_sensitive_str_to_enum(const char *str) return case_sensitive; } -int is_hexbin_str_to_int(const char *str) +static int is_hexbin_str_to_int(const char *str) { int ret = 0; @@ -94,7 +94,8 @@ enum expr_pattern_type pattern_type_str_to_enum(const char *str) return pattern_type; } -int parse_config_file(const char *filename, struct expr_rule exprs[], size_t *n_expr) +static int +parse_config_file(const char *filename, struct expr_rule exprs[], size_t *n_expr) { unsigned char *json_buff = NULL; size_t json_buff_size = 0; @@ -147,17 +148,20 @@ int parse_config_file(const char *filename, struct expr_rule exprs[], size_t *n_ cJSON *item = cJSON_GetObjectItem(pat_item, "pattern_type"); if (item != NULL && item->type == cJSON_String) { - exprs[i].patterns[j].type = pattern_type_str_to_enum(item->valuestring); + exprs[i].patterns[j].type = + pattern_type_str_to_enum(item->valuestring); } item = cJSON_GetObjectItem(pat_item, "match_method"); if (item != NULL && item->type == cJSON_String) { - exprs[i].patterns[j].match_mode = match_method_to_match_mode(item->valuestring); + exprs[i].patterns[j].match_mode = + match_method_to_match_mode(item->valuestring); } item = cJSON_GetObjectItem(pat_item, "case_sensitive"); if (item != NULL && item->type == cJSON_String) { - exprs[i].patterns[j].case_sensitive = case_sensitive_str_to_enum(item->valuestring); + exprs[i].patterns[j].case_sensitive = + case_sensitive_str_to_enum(item->valuestring); } int is_hexbin = 0; @@ -191,9 +195,11 @@ int parse_config_file(const char *filename, struct expr_rule exprs[], size_t *n_ if (item != NULL && item->type == cJSON_String) { int key_left_offset = -1; int key_right_offset = -1; - sscanf(item->valuestring, "%d~%d", &key_left_offset, &key_right_offset); + sscanf(item->valuestring, "%d~%d", &key_left_offset, + &key_right_offset); if (key_left_offset < -1 || key_right_offset < -1) { - printf("Error: offset should not less than -1, left_offset:%d, right_offset:%d\n", + printf("Error: offset should not less than -1, " + "left_offset:%d, right_offset:%d\n", key_left_offset, key_right_offset); } exprs[i].patterns[j].start_offset = key_left_offset; @@ -219,7 +225,7 @@ next: return ret; } -void expr_array_free(struct expr_rule rules[], size_t n_rule) +static void expr_array_free(struct expr_rule rules[], size_t n_rule) { for (size_t i = 0; i < n_rule; i++) { for (size_t j = 0; j < rules[i].n_patterns; j++) { @@ -236,7 +242,8 @@ TEST(hs_expr_matcher_init, invalid_input_parameter) struct expr_rule rules[64]; size_t n_rule = 0; - struct expr_matcher *matcher = expr_matcher_new(NULL, 0, EXPR_ENGINE_TYPE_HS, 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(NULL, 0, EXPR_ENGINE_TYPE_HS, 1, g_logger); EXPECT_TRUE(matcher == NULL); matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, 1, g_logger); @@ -261,7 +268,8 @@ TEST(rs_expr_matcher_init, invalid_input_parameter) struct expr_rule rules[64]; size_t n_rule = 0; - struct expr_matcher *matcher = expr_matcher_new(NULL, 0, EXPR_ENGINE_TYPE_RS, 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(NULL, 0, EXPR_ENGINE_TYPE_RS, 1, g_logger); EXPECT_TRUE(matcher == NULL); matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, 1, g_logger); @@ -289,7 +297,8 @@ TEST(hs_expr_matcher_match, literal_sub_has_normal_offset) int ret = parse_config_file("./expr_matcher.conf", rules, &n_rule); EXPECT_EQ(ret, 0); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); @@ -345,7 +354,8 @@ TEST(rs_expr_matcher_match, literal_sub_has_normal_offset) int ret = parse_config_file("./expr_matcher.conf", rules, &n_rule); EXPECT_EQ(ret, 0); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); @@ -401,8 +411,8 @@ TEST(hs_expr_matcher_match, literal_sub_has_left_unlimit_offset) int ret = parse_config_file("./expr_matcher.conf", rules, &n_rule); EXPECT_EQ(ret, 0); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, - 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); @@ -459,8 +469,8 @@ TEST(rs_expr_matcher_match, literal_sub_has_left_unlimit_offset) int ret = parse_config_file("./expr_matcher.conf", rules, &n_rule); EXPECT_EQ(ret, 0); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, - 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); @@ -517,8 +527,8 @@ TEST(hs_expr_matcher_match, literal_sub_has_right_unlimit_offset) int ret = parse_config_file("./expr_matcher.conf", rules, &n_rule); EXPECT_EQ(ret, 0); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, - 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); @@ -584,8 +594,8 @@ TEST(rs_expr_matcher_match, literal_sub_has_right_unlimit_offset) int ret = parse_config_file("./expr_matcher.conf", rules, &n_rule); EXPECT_EQ(ret, 0); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, - 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); @@ -651,8 +661,8 @@ TEST(hs_expr_matcher_match, literal_sub_with_no_offset) int ret = parse_config_file("./expr_matcher.conf", rules, &n_rule); EXPECT_EQ(ret, 0); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, - 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); @@ -709,8 +719,8 @@ TEST(rs_expr_matcher_match, literal_sub_with_no_offset) int ret = parse_config_file("./expr_matcher.conf", rules, &n_rule); EXPECT_EQ(ret, 0); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, - 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); @@ -767,8 +777,8 @@ TEST(hs_expr_matcher_match, literal_exactly) int ret = parse_config_file("./expr_matcher.conf", rules, &n_rule); EXPECT_EQ(ret, 0); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, - 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); @@ -815,8 +825,8 @@ TEST(rs_expr_matcher_match, literal_exactly) int ret = parse_config_file("./expr_matcher.conf", rules, &n_rule); EXPECT_EQ(ret, 0); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, - 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); @@ -864,8 +874,8 @@ TEST(hs_expr_matcher_match, literal_prefix) int ret = parse_config_file("./expr_matcher.conf", rules, &n_rule); EXPECT_EQ(ret, 0); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, - 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); @@ -924,8 +934,8 @@ TEST(rs_expr_matcher_match, literal_prefix) int ret = parse_config_file("./expr_matcher.conf", rules, &n_rule); EXPECT_EQ(ret, 0); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, - 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); @@ -984,8 +994,8 @@ TEST(hs_expr_matcher_match, literal_suffix) int ret = parse_config_file("./expr_matcher.conf", rules, &n_rule); EXPECT_EQ(ret, 0); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, - 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); @@ -1044,8 +1054,8 @@ TEST(rs_expr_matcher_match, literal_suffix) int ret = parse_config_file("./expr_matcher.conf", rules, &n_rule); EXPECT_EQ(ret, 0); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, - 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); @@ -1104,8 +1114,8 @@ TEST(hs_expr_matcher_match, literal_sub_with_hex) int ret = parse_config_file("./expr_matcher.conf", rules, &n_rule); EXPECT_EQ(ret, 0); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, - 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); @@ -1143,8 +1153,8 @@ TEST(rs_expr_matcher_match, literal_sub_with_hex) int ret = parse_config_file("./expr_matcher.conf", rules, &n_rule); EXPECT_EQ(ret, 0); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, - 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); @@ -1182,8 +1192,8 @@ TEST(hs_expr_matcher_match, literal_with_chinese) int ret = parse_config_file("./expr_matcher.conf", rules, &n_rule); EXPECT_EQ(ret, 0); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, - 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); @@ -1211,8 +1221,8 @@ TEST(rs_expr_matcher_match, literal_with_chinese) int ret = parse_config_file("./expr_matcher.conf", rules, &n_rule); EXPECT_EQ(ret, 0); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, - 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); @@ -1240,8 +1250,8 @@ TEST(hs_expr_matcher_match, same_pattern_different_offset) int ret = parse_config_file("./expr_matcher.conf", rules, &n_rule); EXPECT_EQ(ret, 0); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, - 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); @@ -1269,8 +1279,8 @@ TEST(rs_expr_matcher_match, same_pattern_different_offset) int ret = parse_config_file("./expr_matcher.conf", rules, &n_rule); EXPECT_EQ(ret, 0); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, - 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); @@ -1298,8 +1308,8 @@ TEST(hs_expr_matcher_match, long_scan_data) int ret = parse_config_file("./expr_matcher.conf", rules, &n_rule); EXPECT_EQ(ret, 0); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, - 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); @@ -1329,8 +1339,8 @@ TEST(rs_expr_matcher_match, long_scan_data) int ret = parse_config_file("./expr_matcher.conf", rules, &n_rule); EXPECT_EQ(ret, 0); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, - 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); @@ -1377,20 +1387,22 @@ TEST(hs_expr_matcher_stream, basic) int ret = parse_config_file("./expr_matcher.conf", rules, &n_rule); EXPECT_EQ(ret, 0); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, - 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); const char* scan_data1 = "A directed path in a directed graph is a finite"; - const char *scan_data2 = " or infinite sequence of edges which joins a sequence of distinct vertices"; + const char *scan_data2 = " or infinite sequence of edges which joins a " + "sequence of distinct vertices"; struct expr_scan_result result[64] = {0}; size_t n_hit_result = 0; size_t n_hit_pattern = 0; int thread_id = 0; - struct expr_matcher_stream *stream = expr_matcher_stream_open(matcher, thread_id); + struct expr_matcher_stream *stream = + expr_matcher_stream_open(matcher, thread_id); EXPECT_TRUE(stream != NULL); ret = expr_matcher_stream_match(stream, scan_data1, strlen(scan_data1), result, @@ -1419,13 +1431,14 @@ TEST(rs_expr_matcher_stream, basic) int ret = parse_config_file("./expr_matcher.conf", rules, &n_rule); EXPECT_EQ(ret, 0); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, - 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); const char* scan_data1 = "A directed path in a directed graph is a finite"; - const char *scan_data2 = " or infinite sequence of edges which joins a sequence of distinct vertices"; + const char *scan_data2 = " or infinite sequence of edges which joins a " + "sequence of distinct vertices"; struct expr_scan_result result[64] = {0}; size_t n_hit_result = 0; @@ -1464,11 +1477,13 @@ TEST(hs_expr_matcher, regex_basic) ret = expr_matcher_verify_regex_expression("[0-9]rain", g_logger); EXPECT_EQ(ret, 1); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); - const char *scan_data1 = "http://www.cyberessays.com/search_results.php?action=search&query=username,abckkk,1234567"; + const char *scan_data1 = "http://www.cyberessays.com/search_results.php?" + "action=search&query=username,abckkk,1234567"; //const char *scan_data2 = "8rain"; struct expr_scan_result result[64] = {0}; size_t n_result = 0; @@ -1495,12 +1510,13 @@ TEST(rs_expr_matcher, regex_basic) ret = expr_matcher_verify_regex_expression("[0-9]rain", g_logger); EXPECT_EQ(ret, 1); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, - 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); - const char *scan_data1 = "http://www.cyberessays.com/search_results.php?action=search&query=username,abckkk,1234567"; + const char *scan_data1 = "http://www.cyberessays.com/search_results.php?" + "action=search&query=username,abckkk,1234567"; struct expr_scan_result result[64] = {0}; size_t n_result = 0; @@ -1525,7 +1541,8 @@ TEST(hs_expr_matcher, regex_unicode) int ret = parse_config_file("./expr_matcher.conf", rules, &n_rule); EXPECT_EQ(ret, 0); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); @@ -1552,7 +1569,8 @@ TEST(rs_expr_matcher, regex_unicode) int ret = parse_config_file("./expr_matcher.conf", rules, &n_rule); EXPECT_EQ(ret, 0); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_RS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); @@ -1579,8 +1597,8 @@ TEST(hs_expr_matcher, hit_pattern_num) int ret = parse_config_file("./expr_matcher.conf", rules, &n_rule); EXPECT_EQ(ret, 0); - struct expr_matcher *matcher = expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, - 1, g_logger); + struct expr_matcher *matcher = + expr_matcher_new(rules, n_rule, EXPR_ENGINE_TYPE_HS, 1, g_logger); EXPECT_TRUE(matcher != NULL); expr_array_free(rules, n_rule); diff --git a/test/group_nesting/group_nesting_gtest.cpp b/test/group_nesting/group_nesting_gtest.cpp index e32429d..4c53f05 100644 --- a/test/group_nesting/group_nesting_gtest.cpp +++ b/test/group_nesting/group_nesting_gtest.cpp @@ -33,7 +33,8 @@ struct group2group_rule { UT_icd ut_ex_group_id_icd = {sizeof(long long), NULL, NULL, NULL}; -static int parse_config_file(const char *filename, struct group2group_rule *rules) +static int +parse_config_file(const char *filename, struct group2group_rule *rules) { unsigned char *json_buff = NULL; size_t json_buff_size = 0; diff --git a/test/ipport_plugin/CMakeLists.txt b/test/ipport_plugin/CMakeLists.txt index e40e7cf..c03e9a4 100644 --- a/test/ipport_plugin/CMakeLists.txt +++ b/test/ipport_plugin/CMakeLists.txt @@ -1,4 +1,4 @@ include_directories(${PROJECT_SOURCE_DIR}/src/inc_internal) -add_executable(ipport_plugin_gtest ipport_plugin_gtest.cpp) +add_executable(ipport_plugin_gtest ipport_plugin_gtest.cpp ../test_utils.cpp) target_link_libraries(ipport_plugin_gtest maat_frame_static gtest_static)
\ No newline at end of file diff --git a/test/ipport_plugin/ipport_plugin_gtest.cpp b/test/ipport_plugin/ipport_plugin_gtest.cpp index 392de72..f367401 100644 --- a/test/ipport_plugin/ipport_plugin_gtest.cpp +++ b/test/ipport_plugin/ipport_plugin_gtest.cpp @@ -4,6 +4,7 @@ #include "maat_rule.h" #include "maat_utils.h" #include "log/log.h" +#include "../test_utils.h" #include "maat_config_monitor.h" #include "maat_redis_monitor.h" @@ -33,133 +34,6 @@ protected: struct log_handle *IPPortPluginTable::logger; -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) -{ - 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; - } - - reply = maat_wrap_redis_command(c, logger, "SET MAAT_VERSION 1"); - if (NULL == reply) { - return -1; - } else { - freeReplyObject(reply); - reply = NULL; - } - - reply = maat_wrap_redis_command(c, logger, "SET MAAT_PRE_VER 1"); - if (NULL == reply) { - return -1; - } else { - freeReplyObject(reply); - reply = NULL; - } - - reply = maat_wrap_redis_command(c, logger, "SET SEQUENCE_REGION 1"); - if (NULL == reply) { - return -1; - } else { - freeReplyObject(reply); - reply = NULL; - } - - reply = maat_wrap_redis_command(c, logger, "SET SEQUENCE_GROUP 1"); - if (NULL == reply) { - return -1; - } else { - freeReplyObject(reply); - reply = NULL; - } - - size_t total_line_cnt = 0; - char iris_idx_path[PATH_MAX] = {0}; - snprintf(iris_idx_path, sizeof(iris_idx_path), "test_data/index"); - config_monitor_traverse(0, iris_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, iris_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; -} - struct ipport_plugin_ud { long long rule_id; char *buffer; @@ -365,9 +239,13 @@ TEST_F(IPPortPluginTable, WITHOUT_SAME_IP) { char redis_ip[32] = "127.0.0.1"; int redis_port = 6379; int redis_db = 0; + char iris_idx_path[PATH_MAX] = {0}; struct log_handle *logger = IPPortPluginTable::logger; - int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger); + snprintf(iris_idx_path, sizeof(iris_idx_path), "test_data/index"); + + int ret = write_iris_to_redis(iris_idx_path, redis_ip, redis_port, + redis_db, logger); assert(ret == 0); struct maat_options *opts = maat_options_new(); @@ -434,9 +312,13 @@ TEST_F(IPPortPluginTable, WITH_256SAME_IP) { char redis_ip[32] = "127.0.0.1"; int redis_port = 6379; int redis_db = 0; + char iris_idx_path[PATH_MAX] = {0}; struct log_handle *logger = IPPortPluginTable::logger; - int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger); + snprintf(iris_idx_path, sizeof(iris_idx_path), "test_data/index"); + + int ret = write_iris_to_redis(iris_idx_path, redis_ip, redis_port, + redis_db, logger); assert(ret == 0); struct maat_options *opts = maat_options_new(); diff --git a/test/maat_ex_data_gtest.cpp b/test/maat_ex_data_gtest.cpp index 93898f0..a0b35df 100644 --- a/test/maat_ex_data_gtest.cpp +++ b/test/maat_ex_data_gtest.cpp @@ -20,8 +20,9 @@ struct user_info { int id; }; -void ex_data_new_cb(const char *table_name, int table_id, const char *key, const char *table_line, - void **ad, long argl, void *argp) +static void +ex_data_new_cb(const char *table_name, int table_id, const char *key, + const char *table_line, void **ad, long argl, void *argp) { int *counter = (int *)argp; struct user_info *u = ALLOC(struct user_info, 1); @@ -33,7 +34,7 @@ void ex_data_new_cb(const char *table_name, int table_id, const char *key, const (*counter)++; } -void ex_data_free_cb(int table_id, void **ad, long argl, void *argp) +static void ex_data_free_cb(int table_id, void **ad, long argl, void *argp) { struct user_info *u = (struct user_info *)(*ad); @@ -42,7 +43,8 @@ void ex_data_free_cb(int table_id, void **ad, long argl, void *argp) *ad = NULL; } -void ex_data_dup_cb(int table_id, void **to, void **from, long argl, void *argp) +static void +ex_data_dup_cb(int table_id, void **to, void **from, long argl, void *argp) { struct user_info *u = (struct user_info *)(*from); *to = u; @@ -70,7 +72,8 @@ TEST(EXDataRuntime, Update) { const char *row1 = "101\t192.168.0.1\tmahuateng"; const char *key1 = "192.168.0.1"; size_t key1_len = strlen(key1); - void *ex_data = ex_data_runtime_row2ex_data(ex_data_rt, table_name, row1, key1, key1_len); + void *ex_data = ex_data_runtime_row2ex_data(ex_data_rt, table_name, row1, + key1, key1_len); EXPECT_EQ(ex_data_counter, 1); struct ex_container *ex_container = ex_container_new(ex_data, NULL); @@ -130,27 +133,7 @@ int main(int argc, char ** argv) ::testing::InitGoogleTest(&argc, argv); g_logger = log_handle_create("./maat_ex_data_gtest.log", 0); - - 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", g_json_filename); - if ((access(json_iris_path, F_OK)) == 0) { - system_cmd_rmdir(json_iris_path); - } - - if (access(json_iris_path, F_OK) < 0) { - char *json_buff = NULL; - size_t json_buff_sz = 0; - - int ret = load_file_to_memory(g_json_filename, (unsigned char**)&json_buff, &json_buff_sz); - EXPECT_NE(ret, -1); - - 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); - } - + struct maat_options *opts = maat_options_new(); char json_path[PATH_MAX] = {0}; snprintf(json_path, sizeof(json_path), "./%s", g_json_filename); diff --git a/test/maat_framework_gtest.cpp b/test/maat_framework_gtest.cpp index 3c74a01..58b35ce 100644 --- a/test/maat_framework_gtest.cpp +++ b/test/maat_framework_gtest.cpp @@ -58,19 +58,6 @@ int del_command(struct maat *maat_inst, int compile_id) compile_id, "null", 1, 0); } -static void random_keyword_generate(char *keyword_buf, size_t sz) -{ -#define MIN_KEYWORD_LEN 4 - size_t i = 0; - size_t len = random() % (sz - 1 - MIN_KEYWORD_LEN) + MIN_KEYWORD_LEN; - - for (i = 0; i < len; i++) { - keyword_buf[i] = 'a' + random() % ('z' - 'a'); - } - - keyword_buf[i] = '\0'; -} - const char *watched_json = "./json_update/maat.json"; const char *old_json = "./json_update/old.json"; const char *new_json = "./json_update/new.json"; diff --git a/test/maat_framework_perf_gtest.cpp b/test/maat_framework_perf_gtest.cpp index d7f3181..bce99f8 100644 --- a/test/maat_framework_perf_gtest.cpp +++ b/test/maat_framework_perf_gtest.cpp @@ -30,19 +30,6 @@ struct thread_param { struct log_handle *logger; }; -void random_keyword_generate(char *keyword_buf, size_t sz) -{ -#define MIN_KEYWORD_LEN 4 - size_t i = 0; - size_t len = random() % (sz - 1 - MIN_KEYWORD_LEN) + MIN_KEYWORD_LEN; - for (i = 0; i < len; i++) { - keyword_buf[i] = 'a' + random() % ('z' - 'a'); - } - keyword_buf[i] = '\0'; -} - - - static void test_add_expr_command(struct maat *maat_inst, const char *table_name, const char *keywords) @@ -1644,78 +1631,6 @@ TEST_F(MaatPerfFileScan, IPPlugin) { } } -class MaatTSGFqdnScan : public testing::Test -{ -protected: - static void SetUpTestCase() { - char redis_ip[64] = "127.0.0.1"; - int redis_port = 6379; - int redis_db = 0; - const char *tsg_table_info = "./tsg_table_info.conf"; - - logger = log_handle_create("./maat_framework_perf_gtest.log", 0); - int ret = write_iris_to_redis("./tsgrule", redis_ip, redis_port, - redis_db, logger); - if (ret < 0) { - log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST, - "[%s:%d] write config to redis failed.", - __FUNCTION__, __LINE__); - } - - struct maat_options *opts = maat_options_new(); - maat_options_set_stat_file(opts, "./stat.log"); - maat_options_set_perf_on(opts); - maat_options_set_redis(opts, redis_ip, redis_port, redis_db); - maat_options_set_logger(opts, "./maat_framework_perf_gtest.log", - LOG_LEVEL_INFO); - - _shared_maat_inst = maat_new(opts, tsg_table_info); - maat_options_free(opts); - if (NULL == _shared_maat_inst) { - log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST, - "[%s:%d] create maat instance in MaatTSGFqdnScan failed.", - __FUNCTION__, __LINE__); - } - } - - static void TearDownTestCase() { - maat_free(_shared_maat_inst); - log_handle_destroy(logger); - } - - static struct log_handle *logger; - static struct maat *_shared_maat_inst; -}; - -struct maat *MaatTSGFqdnScan::_shared_maat_inst; -struct log_handle *MaatTSGFqdnScan::logger; - -#if 0 -TEST_F(MaatTSGFqdnScan, mem_used) { - char keyword_buf[128]; - const char *table_name1 = "TSG_OBJ_FQDN"; - const char *table_name2= "TSG_IP_ADDR"; - struct maat *maat_inst = MaatTSGFqdnScan::_shared_maat_inst; - struct log_handle *logger = MaatTSGFqdnScan::logger; - - for (size_t i = 0; i < 100; i++) { - random_keyword_generate(keyword_buf, sizeof(keyword_buf)); - int ret = expr_table_set_line(maat_inst, table_name1, MAAT_OP_ADD, - 600000000+i, 600000000+i, keyword_buf, - "null", 1, 0, 0, 0); - EXPECT_EQ(ret, 1); - - ret = ip_table_set_line(maat_inst, table_name2, MAAT_OP_ADD, - 600000000+i, 600000000+i, IPv4, "100.64.1.1", - "100.64.1.2", 0); - EXPECT_EQ(ret, 1); - - log_info(logger, MODULE_FRAMEWORK_PERF_GTEST, "MaatTSGFqdnScan update one line"); - sleep(150); - } -} -#endif - class MaatPerfIPPortPluginScan : public testing::Test { protected: diff --git a/test/maat_input_mode_gtest.cpp b/test/maat_input_mode_gtest.cpp index ade4371..b6977ba 100644 --- a/test/maat_input_mode_gtest.cpp +++ b/test/maat_input_mode_gtest.cpp @@ -2,6 +2,7 @@ #include "maat_utils.h" #include "maat_rule.h" #include "json2iris.h" +#include "test_utils.h" #include "maat_table.h" #include "maat_config_monitor.h" #include "maat_redis_monitor.h" @@ -15,29 +16,26 @@ 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 iris_idx_path[PATH_MAX] = {0}; char json_iris_path[PATH_MAX] = {0}; - snprintf(json_iris_path, sizeof(json_iris_path), - "./%s_iris_tmp", g_json_filename); - - if (access(json_iris_path, F_OK) < 0) { - char *json_buff = NULL; - size_t json_buff_sz = 0; + char json_path[PATH_MAX] = {0}; + long long results[5] = {0}; + size_t n_hit_result = 0; + int thread_id = 0; + char scan_data[128] = "string1, string2, string3, string4, " + "string5, string6, string7, string8"; + const char *table_name = "KEYWORDS_TABLE"; - int ret = load_file_to_memory(g_json_filename, - (unsigned char**)&json_buff, - &json_buff_sz); - EXPECT_NE(ret, -1); + snprintf(json_iris_path, sizeof(json_iris_path), "./%s_iris_tmp", + g_json_filename); + snprintf(iris_idx_path, sizeof(iris_idx_path), "%s/index", json_iris_path); + snprintf(json_path, sizeof(json_path), "./%s", g_json_filename); - 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); - } + int ret = write_json_to_iris(g_json_filename, iris_idx_path, + sizeof(iris_idx_path), g_logger); + assert(ret == 0); struct maat_options *opts = maat_options_new(); - char json_path[PATH_MAX] = {0}; - 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); @@ -45,188 +43,76 @@ TEST(json_mode, maat_scan_string) { struct maat *maat_inst = maat_new(opts, g_table_info_path); EXPECT_TRUE(maat_inst != NULL); - - const char *table_name = "KEYWORDS_TABLE"; + int table_id = maat_get_table_id(maat_inst, table_name); - char scan_data[128] = - "string1, string2, string3, string4, string5, string6, string7, string8"; - long long results[5] = {0}; - size_t n_hit_result = 0; - int thread_id = 0; struct maat_state *state = maat_state_new(maat_inst, thread_id); - int ret = maat_scan_string(maat_inst, table_id, scan_data, strlen(scan_data), - results, sizeof(results), &n_hit_result, state); + + ret = maat_scan_string(maat_inst, table_id, scan_data, strlen(scan_data), + results, sizeof(results), &n_hit_result, state); EXPECT_EQ(ret, MAAT_SCAN_HIT); EXPECT_EQ(n_hit_result, 1); EXPECT_EQ(results[0], 182); maat_options_free(opts); maat_state_free(state); - state = NULL; maat_free(maat_inst); } 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", 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(g_json_filename, - (unsigned char**)&json_buff, - &json_buff_sz); - EXPECT_NE(ret, -1); + char iris_idx_path[PATH_MAX] = {0}; + long long results[5] = {0}; + size_t n_hit_result = 0; + int thread_id = 0; + const char *table_name = "KEYWORDS_TABLE"; + char scan_data[128] = "string1, string2, string3, string4, " + "string5, string6, string7, string8"; - 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); - } + snprintf(json_iris_path, sizeof(json_iris_path), "./%s_iris_tmp", + g_json_filename); + snprintf(iris_idx_path, sizeof(iris_idx_path), "%s/index", json_iris_path); - char tmp_iris_full_idx_path[PATH_MAX] = {0}; - char tmp_iris_inc_idx_path[PATH_MAX] = {0}; - snprintf(tmp_iris_full_idx_path, sizeof(tmp_iris_full_idx_path), - "%s/index", json_iris_path); - snprintf(tmp_iris_inc_idx_path, sizeof(tmp_iris_inc_idx_path), - "%s/index", json_iris_path); + int ret = write_json_to_iris(g_json_filename, iris_idx_path, + sizeof(iris_idx_path), g_logger); + assert(ret == 0); struct maat_options *opts = maat_options_new(); maat_options_set_stat_on(opts); maat_options_set_perf_on(opts); - maat_options_set_iris(opts, tmp_iris_full_idx_path, tmp_iris_inc_idx_path); + maat_options_set_iris(opts, iris_idx_path, iris_idx_path); maat_options_set_logger(opts, "./maat_input_mode_gtest.log", LOG_LEVEL_INFO); struct maat *maat_inst = maat_new(opts, g_table_info_path); EXPECT_TRUE(maat_inst != NULL); - const char *table_name = "KEYWORDS_TABLE"; int table_id = maat_get_table_id(maat_inst, table_name); - char scan_data[128] = - "string1, string2, string3, string4, string5, string6, string7, string8"; - long long results[5] = {0}; - size_t n_hit_result = 0; - int thread_id = 0; struct maat_state *state = maat_state_new(maat_inst, thread_id); - int ret = maat_scan_string(maat_inst, table_id, scan_data, strlen(scan_data), - results, sizeof(results), &n_hit_result, state); + + ret = maat_scan_string(maat_inst, table_id, scan_data, strlen(scan_data), + results, sizeof(results), &n_hit_result, state); EXPECT_EQ(ret, MAAT_SCAN_HIT); EXPECT_EQ(n_hit_result, 1); EXPECT_EQ(results[0], 182); maat_options_free(opts); maat_state_free(state); - state = NULL; maat_free(maat_inst); } -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; -} - TEST(redis_mode, maat_scan_string) { - char json_iris_path[512] = {0}; - char redis_ip[64] = "127.0.0.1"; + char redis_ip[32] = "127.0.0.1"; int redis_port = 6379; int redis_db = 0; + const char *table_name = "KEYWORDS_TABLE"; + long long results[5] = {0}; + size_t n_hit_result = 0; + int thread_id = 0; + char scan_data[128] = "string1, string2, string3, string4, " + "string5, string6, string7, string8"; - snprintf(json_iris_path, sizeof(json_iris_path), - "./%s_iris_tmp", g_json_filename); - - redisContext *c = - maat_connect_redis(redis_ip, redis_port, redis_db, g_logger); - EXPECT_TRUE(c != NULL); - - redisReply *reply = maat_wrap_redis_command(c, NULL, "flushdb"); - EXPECT_TRUE(reply != NULL); - 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(g_json_filename, - (unsigned char **)&json_buff, - &json_buff_sz); - EXPECT_NE(ret, -1); - - 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); - } - - 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, g_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); - EXPECT_NE(server_time, -1); - - absolute_expire_time = server_time + 300; - config_monitor_traverse(0, tmp_iris_full_idx_path, NULL, make_serial_rule, - NULL, s_rule, NULL, g_logger); - s_rule->ref_ctx = NULL; - int success_cnt = 0; - do { - success_cnt = maat_cmd_write_rule(c, s_rule, total_line_cnt, - server_time, g_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); + int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, + redis_db, g_logger); + assert(ret == 0); struct maat_options *opts = maat_options_new(); maat_options_set_stat_on(opts); @@ -236,23 +122,19 @@ TEST(redis_mode, maat_scan_string) { LOG_LEVEL_INFO); 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] = - "string1, string2, string3, string4, string5, string6, string7, string8"; - long long results[5] = {0}; - size_t n_hit_result = 0; - int thread_id = 0; + assert(maat_inst != NULL); + struct maat_state *state = maat_state_new(maat_inst, thread_id); - int ret = maat_scan_string(maat_inst, table_id, scan_data, strlen(scan_data), - results, sizeof(results), &n_hit_result, state); + int table_id = maat_get_table_id(maat_inst, table_name); + + ret = maat_scan_string(maat_inst, table_id, scan_data, strlen(scan_data), + results, sizeof(results), &n_hit_result, state); EXPECT_EQ(ret, MAAT_SCAN_HIT); EXPECT_EQ(n_hit_result, 1); EXPECT_EQ(results[0], 182); maat_options_free(opts); maat_state_free(state); - state = NULL; maat_free(maat_inst); } diff --git a/test/test_utils.cpp b/test/test_utils.cpp index 0f5234a..e639b75 100644 --- a/test/test_utils.cpp +++ b/test/test_utils.cpp @@ -9,28 +9,34 @@ #include <assert.h> #include <unistd.h> -int count_line_num_cb(const char *table_name, const char *line, void *u_para) +int line_idx = 0; +long long absolute_expire_time = 0; + +static 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) +static 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') { + + 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); + 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; @@ -49,29 +55,32 @@ int make_serial_rule(const char *table_name, const char *line, void *u_para) return 0; } -int write_json_to_iris(const char* json_fn, char *iris_path, size_t path_sz, struct log_handle *logger) + +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); + &json_buff_sz); if (ret < 0) { return -1; } - ret = json2iris(json_buff, json_fn, NULL, iris_path, - path_sz, NULL, NULL, logger); + 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) + +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) { @@ -119,12 +128,21 @@ int write_iris_to_redis(const char* iris_path, char *redis_ip, int redis_port, i 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) + +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); + + int ret = write_json_to_iris(json_filename, iris_path, sizeof(iris_path), logger); + if (ret < 0) { + return -1; + } + + ret = write_iris_to_redis(iris_path, redis_ip, redis_port, redis_db, logger); + if (ret < 0) { + return -1; + } return 0; } @@ -147,7 +165,8 @@ int compile_table_set_line(struct maat *maat_inst, const char *table_name, 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) +#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, @@ -197,9 +216,10 @@ int expr_table_set_line(struct maat *maat_inst, const char *table_name, 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); + 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", @@ -231,9 +251,10 @@ int interval_table_set_line(struct maat *maat_inst, const char *table_name, 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); + 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", @@ -254,8 +275,8 @@ int interval_table_set_line(struct maat *maat_inst, const char *table_name, 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) + 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); @@ -300,4 +321,16 @@ int flag_table_set_line(struct maat *maat_inst, const char *table_name, line_rule.expire_after = expire_after; return maat_cmd_set_line(maat_inst, &line_rule); -}
\ No newline at end of file +} + +void random_keyword_generate(char *keyword_buf, size_t sz) +{ +#define MIN_KEYWORD_LEN 4 + size_t i = 0, len = 0; + len = random() % (sz - 1 - MIN_KEYWORD_LEN) + MIN_KEYWORD_LEN; + + for (i = 0; i < len; i++) { + keyword_buf[i] = 'a' + random() % ('z' - 'a'); + } + keyword_buf[i] = '\0'; +} diff --git a/test/test_utils.h b/test/test_utils.h index 6049c91..9c83c73 100644 --- a/test/test_utils.h +++ b/test/test_utils.h @@ -1,37 +1,53 @@ #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); +#include "ip_matcher/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 write_json_to_iris(const char* json_fn, char *iris_path, size_t path_sz, + 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); + 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 + enum maat_operation op, long long item_id, + long long group_id, long long flag, + long long flag_mask, int expire_after); + +void random_keyword_generate(char *keyword_buf, size_t sz);
\ No newline at end of file |
