fix rule_monitor_loop bug
This commit is contained in:
@@ -331,6 +331,7 @@ struct maat *maat_new(struct maat_options *opts, const char *table_info_path)
|
||||
maat_instance->last_full_version = 0;
|
||||
maat_instance->nr_worker_thread = opts->nr_worker_threads;
|
||||
maat_instance->rule_effect_interval_ms = opts->rule_effect_interval_ms;
|
||||
maat_instance->rule_update_checking_interval_ms = opts->rule_update_checking_interval_ms;
|
||||
maat_instance->gc_timeout_ms = opts->gc_timeout_ms;
|
||||
maat_instance->deferred_load = opts->deferred_load_on;
|
||||
garbage_gc_timeout_s = (maat_instance->rule_effect_interval_ms / 1000) +
|
||||
@@ -856,6 +857,14 @@ int maat_scan_integer(struct maat *maat_instance, int table_id, int thread_id,
|
||||
}
|
||||
|
||||
maat_runtime_ref_inc(maat_instance->maat_rt, thread_id);
|
||||
|
||||
table_type = table_manager_get_table_type(maat_instance->tbl_mgr, physical_table_id);
|
||||
if ((table_type == TABLE_TYPE_INTERVAL_PLUS) &&
|
||||
(NULL == mid || DISTRICT_FLAG_UNSET == mid->is_set_district)) {
|
||||
maat_instance->scan_err_cnt++;
|
||||
return MAAT_SCAN_ERR;
|
||||
}
|
||||
|
||||
alignment_int64_array_add(maat_instance->thread_call_cnt, thread_id, 1);
|
||||
|
||||
int group_ids[MAX_SCANNER_HIT_GROUP_NUM] = {-1};
|
||||
|
||||
@@ -91,6 +91,7 @@ struct compile_runtime {
|
||||
uint32_t rule_num;
|
||||
uint32_t updating_rule_num;
|
||||
|
||||
pthread_rwlock_t rwlock; /* TODO: replaced with mutex? */
|
||||
struct bool_expr_match *expr_match_buff;
|
||||
struct maat_garbage_bin *ref_garbage_bin;
|
||||
struct log_handle *logger;
|
||||
@@ -195,7 +196,7 @@ void *compile_runtime_get_user_data(struct compile_runtime *compile_rt, int comp
|
||||
struct maat_compile *compile = NULL;
|
||||
void *ret = NULL;
|
||||
|
||||
//TODO: add mutex
|
||||
pthread_rwlock_rdlock(&compile_rt->rwlock);
|
||||
HASH_FIND_INT(compile_rt->compile_hash, &compile_id, compile);
|
||||
if (compile != NULL) {
|
||||
ret = compile->user_data;
|
||||
@@ -203,6 +204,7 @@ void *compile_runtime_get_user_data(struct compile_runtime *compile_rt, int comp
|
||||
compile->user_data = NULL;
|
||||
}
|
||||
}
|
||||
pthread_rwlock_unlock(&compile_rt->rwlock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -578,6 +580,7 @@ void *compile_runtime_new(void *compile_schema, int max_thread_num,
|
||||
compile_rt->expr_match_buff = ALLOC(struct bool_expr_match, max_thread_num * MAX_SCANNER_HIT_COMPILE_NUM);
|
||||
compile_rt->logger = logger;
|
||||
compile_rt->ref_garbage_bin = garbage_bin;
|
||||
pthread_rwlock_init(&compile_rt->rwlock, NULL);
|
||||
|
||||
return compile_rt;
|
||||
}
|
||||
@@ -617,6 +620,9 @@ void compile_runtime_free(void *compile_runtime)
|
||||
}
|
||||
|
||||
struct compile_runtime *compile_rt = (struct compile_runtime *)compile_runtime;
|
||||
|
||||
pthread_rwlock_wrlock(&compile_rt->rwlock);
|
||||
|
||||
if (compile_rt->bm != NULL) {
|
||||
bool_matcher_free(compile_rt->bm);
|
||||
}
|
||||
@@ -624,6 +630,7 @@ void compile_runtime_free(void *compile_runtime)
|
||||
if (compile_rt->compile_hash != NULL) {
|
||||
maat_compile_hash_free(&(compile_rt->compile_hash));
|
||||
}
|
||||
pthread_rwlock_unlock(&compile_rt->rwlock);
|
||||
|
||||
if (compile_rt->expr_match_buff != NULL) {
|
||||
FREE(compile_rt->expr_match_buff);
|
||||
@@ -797,22 +804,9 @@ int maat_compile_hash_add(struct maat_compile **compile_hash, int compile_id,
|
||||
struct maat_compile *compile)
|
||||
{
|
||||
int ret = 0;
|
||||
struct maat_compile *tmp_compile = NULL;
|
||||
|
||||
HASH_FIND_INT(*compile_hash, &compile_id, tmp_compile);
|
||||
if (!tmp_compile) {
|
||||
// not found
|
||||
assert(compile->declared_clause_num >= 0);
|
||||
HASH_ADD_INT(*compile_hash, compile_id, compile);
|
||||
} else {
|
||||
// already exist
|
||||
if (tmp_compile->user_data != NULL) {
|
||||
ret = -1;
|
||||
} else {
|
||||
maat_compile_set(tmp_compile, compile->declared_clause_num,
|
||||
compile->user_data, compile->user_data_free);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO:mytest need to delete
|
||||
#if 0
|
||||
@@ -825,16 +819,23 @@ int maat_compile_hash_add(struct maat_compile **compile_hash, int compile_id,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int maat_compile_hash_remove(struct maat_compile **compile_hash, int compile_id,
|
||||
struct maat_garbage_bin *garbage_bin)
|
||||
void maat_compile_hash_set(struct maat_compile **compile_hash, int compile_id,
|
||||
struct maat_compile *compile)
|
||||
{
|
||||
struct maat_compile *compile = NULL;
|
||||
struct maat_compile *tmp_compile = NULL;
|
||||
|
||||
HASH_FIND_INT(*compile_hash, &compile_id, compile);
|
||||
if (!compile) {
|
||||
return -1;
|
||||
}
|
||||
HASH_FIND_INT(*compile_hash, &compile_id, tmp_compile);
|
||||
assert(tmp_compile != NULL);
|
||||
|
||||
assert(tmp_compile->user_data == NULL);
|
||||
maat_compile_set(tmp_compile, compile->declared_clause_num,
|
||||
compile->user_data, compile->user_data_free);
|
||||
|
||||
}
|
||||
|
||||
int maat_compile_hash_remove(struct maat_compile **compile_hash, int compile_id,
|
||||
struct maat_compile *compile, struct maat_garbage_bin *garbage_bin)
|
||||
{
|
||||
if (0 == compile->actual_clause_num) {
|
||||
HASH_DEL(*compile_hash, compile);
|
||||
maat_garbage_bagging(garbage_bin, compile, (void (*)(void *))maat_compile_free);
|
||||
@@ -1045,6 +1046,7 @@ maat_compile_bool_matcher_new(struct maat_compile *compile_hash,
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
//some compile may have zero groups, e.g. default policy.
|
||||
if (j == (size_t)compile->declared_clause_num && j > 0) {
|
||||
bool_expr_array[expr_cnt].expr_id = compile->compile_id;
|
||||
@@ -1420,15 +1422,15 @@ void maat_compile_state_update_hit_clause(struct maat_compile_state *compile_sta
|
||||
return;
|
||||
}
|
||||
|
||||
struct compile_runtime *compile_rt = (struct compile_runtime *)compile_runtime;
|
||||
assert(compile_rt->compile_hash != NULL);
|
||||
|
||||
struct maat_compile *compile = NULL, *tmp_compile = NULL;
|
||||
struct maat_clause_state *clause_state = NULL;
|
||||
struct maat_literal_id literal_id = {group_id, vtable_id};
|
||||
struct maat_literal_id *tmp = NULL;
|
||||
|
||||
unsigned long long *clause_id = 0;
|
||||
struct compile_runtime *compile_rt = (struct compile_runtime *)compile_runtime;
|
||||
|
||||
pthread_rwlock_wrlock(&compile_rt->rwlock);
|
||||
assert(compile_rt->compile_hash != NULL);
|
||||
|
||||
HASH_ITER(hh, compile_rt->compile_hash, compile, tmp_compile) {
|
||||
for (size_t i = 0; i < MAX_ITEMS_PER_BOOL_EXPR; i++) {
|
||||
@@ -1463,6 +1465,7 @@ void maat_compile_state_update_hit_clause(struct maat_compile_state *compile_sta
|
||||
}
|
||||
}
|
||||
}
|
||||
pthread_rwlock_unlock(&compile_rt->rwlock);
|
||||
}
|
||||
|
||||
int maat_compile_state_has_NOT_clause(struct maat_compile_state *compile_state)
|
||||
@@ -1562,10 +1565,20 @@ int compile_runtime_update(void *compile_runtime, void *compile_schema,
|
||||
int compile_id = get_column_value(line, schema->compile_id_column);
|
||||
if (is_valid < 0) {
|
||||
return -1;
|
||||
} else if (0 == is_valid) {
|
||||
}
|
||||
|
||||
if (0 == is_valid) {
|
||||
//delete
|
||||
pthread_rwlock_wrlock(&compile_rt->rwlock);
|
||||
compile = maat_compile_hash_find(&(compile_rt->compile_hash), compile_id);
|
||||
if (NULL == compile) {
|
||||
pthread_rwlock_unlock(&compile_rt->rwlock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = maat_compile_hash_remove(&(compile_rt->compile_hash), compile_id,
|
||||
compile_rt->ref_garbage_bin);
|
||||
compile, compile_rt->ref_garbage_bin);
|
||||
pthread_rwlock_unlock(&compile_rt->rwlock);
|
||||
if (ret < 0) {
|
||||
log_error(compile_rt->logger, MODULE_COMPILE,
|
||||
"remove compile table(table_id:%d) compile(compile_id:%d) from compile_hash failed",
|
||||
@@ -1574,8 +1587,11 @@ int compile_runtime_update(void *compile_runtime, void *compile_schema,
|
||||
}
|
||||
} else {
|
||||
//add
|
||||
pthread_rwlock_wrlock(&compile_rt->rwlock);
|
||||
|
||||
compile_item = compile_item_new(line, schema, compile_rt->logger);
|
||||
if (NULL == compile_item) {
|
||||
pthread_rwlock_unlock(&compile_rt->rwlock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1587,6 +1603,7 @@ int compile_runtime_update(void *compile_runtime, void *compile_schema,
|
||||
compile = maat_compile_new(compile_rule->compile_id);
|
||||
if (NULL == compile) {
|
||||
destroy_compile_rule(compile_rule);
|
||||
pthread_rwlock_unlock(&compile_rt->rwlock);
|
||||
log_error(compile_rt->logger, MODULE_COMPILE,
|
||||
"maat_compile_new failed, compile_table(table_id:%d) compile_id:%d",
|
||||
schema->table_id, compile_item->compile_id);
|
||||
@@ -1595,14 +1612,15 @@ int compile_runtime_update(void *compile_runtime, void *compile_schema,
|
||||
|
||||
maat_compile_set(compile, compile_rule->declared_clause_num, compile_rule,
|
||||
(void (*)(void *))destroy_compile_rule);
|
||||
ret = maat_compile_hash_add(&(compile_rt->compile_hash), compile_id, compile);
|
||||
if (ret < 0) {
|
||||
maat_compile_free(compile);
|
||||
log_error(compile_rt->logger, MODULE_COMPILE,
|
||||
"add compile table(table_id:%d) compile(compile_id:%d) to compile_hash failed",
|
||||
schema->table_id, compile_id);
|
||||
return -1;
|
||||
|
||||
struct maat_compile *tmp_compile = maat_compile_hash_find(&(compile_rt->compile_hash), compile_id);
|
||||
if (tmp_compile != NULL) {
|
||||
maat_compile_hash_set(&(compile_rt->compile_hash), compile_id, compile);
|
||||
} else {
|
||||
maat_compile_hash_add(&(compile_rt->compile_hash), compile_id, compile);
|
||||
}
|
||||
|
||||
pthread_rwlock_unlock(&compile_rt->rwlock);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -1630,6 +1648,7 @@ int group2compile_runtime_update(void *g2c_runtime, void *g2c_schema,
|
||||
return -1;
|
||||
}
|
||||
|
||||
pthread_rwlock_wrlock(&compile_rt->rwlock);
|
||||
if (0 == is_valid) {
|
||||
//delete
|
||||
ret = maat_remove_group_from_compile(&(compile_rt->compile_hash), g2g_rt, g2c_item,
|
||||
@@ -1649,6 +1668,7 @@ int group2compile_runtime_update(void *g2c_runtime, void *g2c_schema,
|
||||
}
|
||||
}
|
||||
}
|
||||
pthread_rwlock_unlock(&compile_rt->rwlock);
|
||||
|
||||
group2compile_item_free(g2c_item);
|
||||
return ret;
|
||||
@@ -1661,6 +1681,7 @@ int compile_runtime_commit(void *compile_runtime, const char *table_name)
|
||||
}
|
||||
|
||||
struct compile_runtime *compile_rt = (struct compile_runtime *)compile_runtime;
|
||||
//TODO: no need add rdlock?
|
||||
size_t compile_cnt = maat_compile_in_use_count(compile_rt->compile_hash);
|
||||
if (0 == compile_cnt) {
|
||||
return 0;
|
||||
@@ -1684,8 +1705,11 @@ int compile_runtime_commit(void *compile_runtime, const char *table_name)
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
pthread_rwlock_wrlock(&compile_rt->rwlock);
|
||||
old_bool_matcher = compile_rt->bm;
|
||||
compile_rt->bm = new_bool_matcher;
|
||||
pthread_rwlock_unlock(&compile_rt->rwlock);
|
||||
|
||||
maat_garbage_bagging(compile_rt->ref_garbage_bin, old_bool_matcher,
|
||||
(void (*)(void*))maat_compile_bool_matcher_free);
|
||||
|
||||
@@ -1748,10 +1772,12 @@ int compile_runtime_match(struct compile_runtime *compile_rt,
|
||||
struct compile_rule *compile_rules[compile_ids_size];
|
||||
|
||||
// all hit clause_id -> compile_id
|
||||
pthread_rwlock_rdlock(&compile_rt->rwlock);
|
||||
size_t bool_match_ret = maat_compile_bool_matcher_match(compile_rt->bm,
|
||||
is_last_scan, compile_state,
|
||||
(void **)compile_rules,
|
||||
compile_ids_size);
|
||||
pthread_rwlock_unlock(&compile_rt->rwlock);
|
||||
if (bool_match_ret > 0) {
|
||||
qsort(compile_rules, bool_match_ret, sizeof(struct compile_rule *),
|
||||
compare_compile_rule);
|
||||
|
||||
@@ -866,11 +866,13 @@ int expr_runtime_scan(struct expr_runtime *expr_rt, int thread_id,
|
||||
n_hit_item = MAX_SCANNER_HIT_ITEM_NUM;
|
||||
}
|
||||
|
||||
int hit_item_ids[MAX_SCANNER_HIT_ITEM_NUM] = {-1};
|
||||
int hit_item_ids[MAX_SCANNER_HIT_ITEM_NUM];
|
||||
struct maat_item_inner *item = NULL;
|
||||
int real_hit_item_cnt = 0;
|
||||
int district_id = state->district_id;
|
||||
|
||||
memset(hit_item_ids, -1, sizeof(hit_item_ids));
|
||||
|
||||
for (size_t i = 0; i < n_hit_item; i++) {
|
||||
item = (struct maat_item_inner *)(hit_results[i].user_tag);
|
||||
if (item->district_id == district_id || district_id == DISTRICT_ANY) {
|
||||
|
||||
@@ -429,7 +429,9 @@ int flag_runtime_scan(struct flag_runtime *flag_rt, int thread_id,
|
||||
n_hit_item = MAX_SCANNER_HIT_ITEM_NUM;
|
||||
}
|
||||
|
||||
int hit_item_ids[MAX_SCANNER_HIT_ITEM_NUM] = {-1};
|
||||
int hit_item_ids[MAX_SCANNER_HIT_ITEM_NUM];
|
||||
memset(hit_item_ids, -1, sizeof(hit_item_ids));
|
||||
|
||||
for (int i = 0; i < n_hit_item; i++) {
|
||||
hit_item_ids[i] = hit_results[i].rule_id;
|
||||
}
|
||||
|
||||
@@ -10,9 +10,31 @@
|
||||
|
||||
#include "maat_fqdn.h"
|
||||
#include "log/log.h"
|
||||
#include "fqdn_engine.h"
|
||||
|
||||
struct fqdn_schema {
|
||||
int item_id_column;
|
||||
int group_id_column;
|
||||
int fqdn_column;
|
||||
int match_method_column;
|
||||
int table_id;
|
||||
struct table_manager *ref_tbl_mgr;
|
||||
};
|
||||
|
||||
struct fqdn_runtime {
|
||||
struct FQDN_engine *engine;
|
||||
struct rcu_hash_table *htable;
|
||||
|
||||
uint32_t rule_num;
|
||||
uint32_t updating_rule_num;
|
||||
struct maat_item *item_hash;
|
||||
void (*item_user_data_free)(void *);
|
||||
|
||||
struct maat_garbage_bin *ref_garbage_bin;
|
||||
struct log_handle *logger;
|
||||
|
||||
long long *scan_cnt;
|
||||
long long *hit_cnt;
|
||||
};
|
||||
|
||||
void *fqdn_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
|
||||
@@ -354,7 +354,7 @@ int interval_runtime_update(void *interval_runtime, void *interval_schema,
|
||||
return -1;
|
||||
}
|
||||
|
||||
u_para = maat_item_inner_new(interval_item->group_id, item_id, 0);
|
||||
u_para = maat_item_inner_new(interval_item->group_id, item_id, interval_item->district_id);
|
||||
item = maat_item_new(item_id, interval_item->group_id, u_para);
|
||||
HASH_ADD_INT(interval_rt->item_hash, item_id, item);
|
||||
|
||||
@@ -459,9 +459,18 @@ int interval_runtime_scan(struct interval_runtime *interval_rt, int thread_id,
|
||||
n_hit_item = MAX_SCANNER_HIT_ITEM_NUM;
|
||||
}
|
||||
|
||||
int hit_item_ids[MAX_SCANNER_HIT_ITEM_NUM] = {-1};
|
||||
int hit_item_ids[MAX_SCANNER_HIT_ITEM_NUM];
|
||||
struct maat_item_inner *item = NULL;
|
||||
int real_hit_item_cnt = 0;
|
||||
int district_id = state->district_id;
|
||||
|
||||
memset(hit_item_ids, -1, sizeof(hit_item_ids));
|
||||
|
||||
for (int i = 0; i < n_hit_item; i++) {
|
||||
hit_item_ids[i] = hit_results[i].rule_id;
|
||||
item = (struct maat_item_inner *)(hit_results[i].user_tag);
|
||||
if (item->district_id == district_id || district_id == DISTRICT_ANY) {
|
||||
hit_item_ids[real_hit_item_cnt++] = hit_results[i].rule_id;
|
||||
}
|
||||
}
|
||||
|
||||
size_t group_hit_cnt = 0;
|
||||
|
||||
@@ -509,7 +509,9 @@ int ip_runtime_scan(struct ip_runtime *ip_rt, int thread_id, int ip_type,
|
||||
n_hit_item = MAX_SCANNER_HIT_ITEM_NUM;
|
||||
}
|
||||
|
||||
int hit_item_ids[MAX_SCANNER_HIT_ITEM_NUM] = {-1};
|
||||
int hit_item_ids[MAX_SCANNER_HIT_ITEM_NUM];
|
||||
memset(hit_item_ids, -1, sizeof(hit_item_ids));
|
||||
|
||||
for (int i = 0; i < n_hit_item; i++) {
|
||||
hit_item_ids[i] = scan_results[i].rule_id;
|
||||
}
|
||||
|
||||
@@ -417,7 +417,9 @@ void *rule_monitor_loop(void *arg)
|
||||
struct stat attrib;
|
||||
while (maat_instance->is_running) {
|
||||
usleep(maat_instance->rule_update_checking_interval_ms * 1000);
|
||||
if( 0 == pthread_mutex_trylock(&(maat_instance->background_update_mutex))) {
|
||||
if (0 == pthread_mutex_trylock(&(maat_instance->background_update_mutex))) {
|
||||
log_info(maat_instance->logger, MODULE_MAAT_RULE,
|
||||
"rule_monitor_loop.................%d", maat_instance->rule_update_checking_interval_ms * 1000);
|
||||
switch (maat_instance->input_mode) {
|
||||
case DATA_SOURCE_REDIS:
|
||||
redis_monitor_traverse(maat_instance->maat_version,
|
||||
|
||||
@@ -210,17 +210,17 @@ TEST(block_mode_initialize, invalid_input_parameter)
|
||||
/* case1: invalid scan_mode parameter */
|
||||
hs_instance = adapter_hs_initialize(HS_SCAN_MODE_MAX, HS_PATTERN_TYPE_REG,
|
||||
1, exprs, 1, g_logger);
|
||||
EXPECT_EQ(hs_instance, NULL);
|
||||
EXPECT_TRUE(hs_instance == NULL);
|
||||
|
||||
/* case2: invalid expr parameter */
|
||||
hs_instance = adapter_hs_initialize(HS_SCAN_MODE_BLOCK, HS_PATTERN_TYPE_REG,
|
||||
1, NULL, 1, g_logger);
|
||||
EXPECT_EQ(hs_instance, NULL);
|
||||
EXPECT_TRUE(hs_instance == NULL);
|
||||
|
||||
/* case3: invalid expr num */
|
||||
hs_instance = adapter_hs_initialize(HS_SCAN_MODE_BLOCK, HS_PATTERN_TYPE_REG,
|
||||
1, exprs, 0, g_logger);
|
||||
EXPECT_EQ(hs_instance, NULL);
|
||||
EXPECT_TRUE(hs_instance == NULL);
|
||||
}
|
||||
|
||||
TEST(block_mode_scan, invalid_input_parameter)
|
||||
@@ -230,18 +230,18 @@ TEST(block_mode_scan, invalid_input_parameter)
|
||||
|
||||
struct adapter_hs *hs_instance = adapter_hs_initialize(HS_SCAN_MODE_BLOCK, HS_PATTERN_TYPE_REG,
|
||||
1, NULL, 0, g_logger);
|
||||
EXPECT_EQ(hs_instance, NULL);
|
||||
EXPECT_TRUE(hs_instance == NULL);
|
||||
|
||||
hs_instance = adapter_hs_initialize(HS_SCAN_MODE_MAX, HS_PATTERN_TYPE_REG, 1, expr_array,
|
||||
n_expr_array, g_logger);
|
||||
EXPECT_EQ(hs_instance, NULL);
|
||||
EXPECT_TRUE(hs_instance == NULL);
|
||||
|
||||
n_expr_array = 1;
|
||||
expr_array[0].expr_id = 101;
|
||||
expr_array[0].n_patterns = 10;
|
||||
hs_instance = adapter_hs_initialize(HS_SCAN_MODE_BLOCK, HS_PATTERN_TYPE_REG, 1, expr_array,
|
||||
n_expr_array, g_logger);
|
||||
EXPECT_EQ(hs_instance, NULL);
|
||||
EXPECT_TRUE(hs_instance == NULL);
|
||||
|
||||
memset(expr_array, 0, sizeof(expr_array));
|
||||
n_expr_array = 1;
|
||||
@@ -249,7 +249,7 @@ TEST(block_mode_scan, invalid_input_parameter)
|
||||
expr_array[0].n_patterns = 1;
|
||||
hs_instance = adapter_hs_initialize(HS_SCAN_MODE_BLOCK, HS_PATTERN_TYPE_REG, 1, expr_array,
|
||||
n_expr_array, g_logger);
|
||||
EXPECT_EQ(hs_instance, NULL);
|
||||
EXPECT_TRUE(hs_instance == NULL);
|
||||
}
|
||||
|
||||
TEST(block_mode_scan, literal_sub_has_normal_offset)
|
||||
@@ -263,7 +263,7 @@ TEST(block_mode_scan, literal_sub_has_normal_offset)
|
||||
|
||||
struct adapter_hs *hs_instance = adapter_hs_initialize(HS_SCAN_MODE_BLOCK, HS_PATTERN_TYPE_STR, 1,
|
||||
expr_array, n_expr_array, g_logger);
|
||||
EXPECT_NE(hs_instance, NULL);
|
||||
EXPECT_TRUE(hs_instance != NULL);
|
||||
expr_array_free(expr_array, n_expr_array);
|
||||
|
||||
char scan_data1[64] = "hello aaa";
|
||||
@@ -303,7 +303,7 @@ TEST(block_mode_scan, literal_sub_has_left_unlimit_offset)
|
||||
|
||||
struct adapter_hs *hs_instance = adapter_hs_initialize(HS_SCAN_MODE_BLOCK, HS_PATTERN_TYPE_STR, 1,
|
||||
expr_array, n_expr_array, g_logger);
|
||||
EXPECT_NE(hs_instance, NULL);
|
||||
EXPECT_TRUE(hs_instance != NULL);
|
||||
expr_array_free(expr_array, n_expr_array);
|
||||
|
||||
char scan_data1[64] = "hello bbb";
|
||||
@@ -344,7 +344,7 @@ TEST(block_mode_scan, literal_sub_has_right_unlimit_offset)
|
||||
|
||||
struct adapter_hs *hs_instance = adapter_hs_initialize(HS_SCAN_MODE_BLOCK, HS_PATTERN_TYPE_STR, 1,
|
||||
expr_array, n_expr_array, g_logger);
|
||||
EXPECT_NE(hs_instance, NULL);
|
||||
EXPECT_TRUE(hs_instance != NULL);
|
||||
expr_array_free(expr_array, n_expr_array);
|
||||
|
||||
char scan_data1[64] = "hello ccc";
|
||||
@@ -400,7 +400,7 @@ TEST(block_mode_scan, literal_sub_with_no_offset)
|
||||
|
||||
struct adapter_hs *hs_instance = adapter_hs_initialize(HS_SCAN_MODE_BLOCK, HS_PATTERN_TYPE_STR, 1,
|
||||
expr_array, n_expr_array, g_logger);
|
||||
EXPECT_NE(hs_instance, NULL);
|
||||
EXPECT_TRUE(hs_instance != NULL);
|
||||
expr_array_free(expr_array, n_expr_array);
|
||||
|
||||
char scan_data1[64] = "hello ddd";
|
||||
@@ -448,7 +448,7 @@ TEST(block_mode_scan, literal_exactly)
|
||||
|
||||
struct adapter_hs *hs_instance = adapter_hs_initialize(HS_SCAN_MODE_BLOCK, HS_PATTERN_TYPE_STR, 1,
|
||||
expr_array, n_expr_array, g_logger);
|
||||
EXPECT_NE(hs_instance, NULL);
|
||||
EXPECT_TRUE(hs_instance != NULL);
|
||||
expr_array_free(expr_array, n_expr_array);
|
||||
|
||||
char scan_data1[64] = "hello eee";
|
||||
@@ -490,7 +490,7 @@ TEST(block_mode_scan, literal_prefix)
|
||||
|
||||
struct adapter_hs *hs_instance = adapter_hs_initialize(HS_SCAN_MODE_BLOCK, HS_PATTERN_TYPE_STR, 1,
|
||||
expr_array, n_expr_array, g_logger);
|
||||
EXPECT_NE(hs_instance, NULL);
|
||||
EXPECT_TRUE(hs_instance != NULL);
|
||||
expr_array_free(expr_array, n_expr_array);
|
||||
|
||||
char scan_data1[64] = "hello fff";
|
||||
@@ -541,7 +541,7 @@ TEST(block_mode_scan, literal_suffix)
|
||||
|
||||
struct adapter_hs *hs_instance = adapter_hs_initialize(HS_SCAN_MODE_BLOCK, HS_PATTERN_TYPE_STR, 1,
|
||||
expr_array, n_expr_array, g_logger);
|
||||
EXPECT_NE(hs_instance, NULL);
|
||||
EXPECT_TRUE(hs_instance != NULL);
|
||||
expr_array_free(expr_array, n_expr_array);
|
||||
|
||||
char scan_data1[64] = "hello ggg";
|
||||
@@ -592,7 +592,7 @@ TEST(block_mode_scan, literal_sub_with_hexbin)
|
||||
|
||||
struct adapter_hs *hs_instance = adapter_hs_initialize(HS_SCAN_MODE_BLOCK, HS_PATTERN_TYPE_STR, 1,
|
||||
expr_array, n_expr_array, g_logger);
|
||||
EXPECT_NE(hs_instance, NULL);
|
||||
EXPECT_TRUE(hs_instance != NULL);
|
||||
expr_array_free(expr_array, n_expr_array);
|
||||
|
||||
char scan_data1[64] = "Content-Type: /html";
|
||||
@@ -625,7 +625,7 @@ TEST(block_mode_scan, literal_with_chinese)
|
||||
|
||||
struct adapter_hs *hs_instance = adapter_hs_initialize(HS_SCAN_MODE_BLOCK, HS_PATTERN_TYPE_STR, 1,
|
||||
expr_array, n_expr_array, g_logger);
|
||||
EXPECT_NE(hs_instance, NULL);
|
||||
EXPECT_TRUE(hs_instance != NULL);
|
||||
expr_array_free(expr_array, n_expr_array);
|
||||
|
||||
char data0[64] = "#中国 你好";
|
||||
|
||||
@@ -141,10 +141,7 @@ protected:
|
||||
static void TearDownTestCase() {
|
||||
|
||||
}
|
||||
|
||||
static int table_id;
|
||||
};
|
||||
int MaatStringScan::table_id;
|
||||
|
||||
TEST_F(MaatStringScan, Expr8) {
|
||||
int table_id = maat_table_get_id(g_maat_instance, "KEYWORDS_TABLE");
|
||||
@@ -353,7 +350,6 @@ TEST_F(MaatStringScan, ExprPlusWithOffset)
|
||||
maat_state_free(&state);
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_F(MaatStringScan, dynamic_config) {
|
||||
int table_id = maat_table_get_id(g_maat_instance, "HTTP_URL_LITERAL");
|
||||
|
||||
@@ -590,7 +586,6 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
#if 0
|
||||
TEST_F(MaatIntervalScan, Pure) {
|
||||
int results[ARRAY_SIZE] = {0};
|
||||
size_t n_hit_result = 0;
|
||||
@@ -607,11 +602,10 @@ TEST_F(MaatIntervalScan, Pure) {
|
||||
maat_state_free(&state);
|
||||
|
||||
unsigned int scan_data2 = 300;
|
||||
int ret = maat_scan_integer(g_maat_instance, table_id, 0, scan_data2, results, ARRAY_SIZE,
|
||||
ret = maat_scan_integer(g_maat_instance, table_id, 0, scan_data2, results, ARRAY_SIZE,
|
||||
&n_hit_result, &state);
|
||||
EXPECT_EQ(ret, MAAT_SCAN_HIT);
|
||||
EXPECT_EQ(n_hit_result, 1);
|
||||
EXPECT_EQ(results[0], 124);
|
||||
EXPECT_EQ(ret, MAAT_SCAN_HALF_HIT);
|
||||
EXPECT_EQ(n_hit_result, 0);
|
||||
maat_state_free(&state);
|
||||
}
|
||||
|
||||
@@ -626,7 +620,7 @@ TEST_F(MaatIntervalScan, IntervalPlus) {
|
||||
|
||||
const char *district_str = "interval.plus";
|
||||
int ret = maat_state_set_scan_district(g_maat_instance, &state, district_str, strlen(district_str));
|
||||
ASSERT_GT(ret, 0);
|
||||
EXPECT_EQ(ret, 0);
|
||||
|
||||
unsigned int scan_data1 = 2020;
|
||||
ret = maat_scan_integer(g_maat_instance, table_id, 0, scan_data1, results, ARRAY_SIZE,
|
||||
@@ -636,7 +630,6 @@ TEST_F(MaatIntervalScan, IntervalPlus) {
|
||||
EXPECT_EQ(results[0], 179);
|
||||
maat_state_free(&state);
|
||||
}
|
||||
#endif
|
||||
|
||||
int count_line_num_cb(const char *table_name, const char *line, void *u_para)
|
||||
{
|
||||
|
||||
@@ -34,7 +34,7 @@ TEST(json_mode, maat_scan_string) {
|
||||
maat_options_set_json_file(opts, json_path);
|
||||
|
||||
struct maat *maat_instance = maat_new(opts, table_info_path);
|
||||
EXPECT_NE(maat_instance, NULL);
|
||||
EXPECT_TRUE(maat_instance != NULL);
|
||||
|
||||
int table_id = maat_table_get_id(maat_instance, "KEYWORDS_TABLE");
|
||||
|
||||
@@ -79,7 +79,7 @@ TEST(iris_mode, maat_scan_string) {
|
||||
maat_options_set_iris(opts, tmp_iris_full_idx_path, tmp_iris_inc_idx_path);
|
||||
|
||||
struct maat *maat_instance = maat_new(opts, table_info_path);
|
||||
EXPECT_NE(maat_instance, NULL);
|
||||
EXPECT_TRUE(maat_instance != NULL);
|
||||
|
||||
int table_id = maat_table_get_id(maat_instance, "KEYWORDS_TABLE");
|
||||
|
||||
@@ -153,10 +153,10 @@ TEST(redis_mode, maat_scan_string) {
|
||||
snprintf(json_iris_path, sizeof(json_iris_path), "./%s_iris_tmp", json_filename);
|
||||
|
||||
redisContext *c = maat_cmd_connect_redis(redis_ip, redis_port, redis_db, g_logger);
|
||||
EXPECT_NE(c, NULL);
|
||||
EXPECT_TRUE(c != NULL);
|
||||
|
||||
redisReply *reply = maat_cmd_wrap_redis_command(c, "flushdb");
|
||||
EXPECT_NE(reply, NULL);
|
||||
EXPECT_TRUE(reply != NULL);
|
||||
|
||||
if (access(json_iris_path, F_OK) < 0) {
|
||||
char tmp_iris_path[128] = {0};
|
||||
|
||||
@@ -15,13 +15,13 @@ void data_free(void *user_ctx, void *data)
|
||||
|
||||
TEST(rcu_hash_new, invalid_input_parameter) {
|
||||
struct rcu_hash_table *htable = rcu_hash_new(NULL);
|
||||
EXPECT_EQ(htable, NULL);
|
||||
EXPECT_TRUE(htable == NULL);
|
||||
}
|
||||
|
||||
TEST(rcu_hash_add_one_node, single_thread) {
|
||||
/* add one node to hash */
|
||||
struct rcu_hash_table *htable = rcu_hash_new(data_free);
|
||||
EXPECT_NE(htable, NULL);
|
||||
EXPECT_TRUE(htable != NULL);
|
||||
|
||||
struct user_data *data = ALLOC(struct user_data, 1);
|
||||
data->id = 101;
|
||||
@@ -35,7 +35,7 @@ TEST(rcu_hash_add_one_node, single_thread) {
|
||||
|
||||
/* find in hash before commit */
|
||||
void *res = rcu_hash_find(htable, key, key_len);
|
||||
EXPECT_EQ(res, NULL);
|
||||
EXPECT_TRUE(res == NULL);
|
||||
|
||||
int ret = rcu_hash_count(htable);
|
||||
EXPECT_EQ(ret, 0);
|
||||
@@ -51,7 +51,7 @@ TEST(rcu_hash_add_one_node, single_thread) {
|
||||
|
||||
/* find in hash after commit */
|
||||
res = rcu_hash_find(htable, key, key_len);
|
||||
EXPECT_NE(res, NULL);
|
||||
EXPECT_TRUE(res != NULL);
|
||||
|
||||
struct user_data *res_data = (struct user_data *)res;
|
||||
EXPECT_EQ(res_data->id, 101);
|
||||
@@ -72,7 +72,7 @@ TEST(rcu_hash_add_one_node, single_thread) {
|
||||
TEST(rcu_hash_add_multi_node, single_thread) {
|
||||
/* add multi node to hash */
|
||||
struct rcu_hash_table *htable = rcu_hash_new(data_free);
|
||||
EXPECT_NE(htable, NULL);
|
||||
EXPECT_TRUE(htable != NULL);
|
||||
|
||||
struct user_data *data0 = ALLOC(struct user_data, 1);
|
||||
data0->id = 101;
|
||||
@@ -92,9 +92,9 @@ TEST(rcu_hash_add_multi_node, single_thread) {
|
||||
|
||||
/* find in hash before commit */
|
||||
void *res = rcu_hash_find(htable, key0, key0_len);
|
||||
EXPECT_EQ(res, NULL);
|
||||
EXPECT_TRUE(res == NULL);
|
||||
res = rcu_hash_find(htable, key1, key1_len);
|
||||
EXPECT_EQ(res, NULL);
|
||||
EXPECT_TRUE(res == NULL);
|
||||
|
||||
int ret = rcu_hash_count(htable);
|
||||
EXPECT_EQ(ret, 0);
|
||||
@@ -110,14 +110,14 @@ TEST(rcu_hash_add_multi_node, single_thread) {
|
||||
|
||||
/* find in hash after commit */
|
||||
res = rcu_hash_find(htable, key0, key0_len);
|
||||
EXPECT_NE(res, NULL);
|
||||
EXPECT_TRUE(res != NULL);
|
||||
|
||||
struct user_data *res_data0 = (struct user_data *)res;
|
||||
EXPECT_EQ(res_data0->id, 101);
|
||||
EXPECT_STREQ(res_data0->name, "www.baidu.com");
|
||||
|
||||
res = rcu_hash_find(htable, key1, key1_len);
|
||||
EXPECT_NE(res, NULL);
|
||||
EXPECT_TRUE(res != NULL);
|
||||
|
||||
struct user_data *res_data1 = (struct user_data *)res;
|
||||
EXPECT_EQ(res_data1->id, 102);
|
||||
@@ -138,7 +138,7 @@ TEST(rcu_hash_add_multi_node, single_thread) {
|
||||
TEST(rcu_hash_del_one_node, single_thread) {
|
||||
/* case1: add and del before commit */
|
||||
struct rcu_hash_table *htable = rcu_hash_new(data_free);
|
||||
EXPECT_NE(htable, NULL);
|
||||
EXPECT_TRUE(htable != NULL);
|
||||
|
||||
struct user_data *data = ALLOC(struct user_data, 1);
|
||||
data->id = 101;
|
||||
@@ -156,7 +156,7 @@ TEST(rcu_hash_del_one_node, single_thread) {
|
||||
|
||||
/* find in hash before commit */
|
||||
void *res = rcu_hash_find(htable, key, key_len);
|
||||
EXPECT_EQ(res, NULL);
|
||||
EXPECT_TRUE(res == NULL);
|
||||
|
||||
ret = rcu_hash_count(htable);
|
||||
EXPECT_EQ(ret, 0);
|
||||
@@ -173,7 +173,7 @@ TEST(rcu_hash_del_one_node, single_thread) {
|
||||
|
||||
/* find in hash after commit */
|
||||
res = rcu_hash_find(htable, key, key_len);
|
||||
EXPECT_EQ(res, NULL);
|
||||
EXPECT_TRUE(res == NULL);
|
||||
|
||||
/* case2: add && commit, and del */
|
||||
struct user_data *data1 = ALLOC(struct user_data, 1);
|
||||
@@ -190,7 +190,7 @@ TEST(rcu_hash_del_one_node, single_thread) {
|
||||
rcu_hash_del(htable, key1, key1_len);
|
||||
|
||||
res = rcu_hash_find(htable, key1, key1_len);
|
||||
EXPECT_NE(res, NULL);
|
||||
EXPECT_TRUE(res != NULL);
|
||||
|
||||
struct user_data *res_data = (struct user_data *)res;
|
||||
EXPECT_EQ(res_data->id, 102);
|
||||
@@ -205,7 +205,7 @@ TEST(rcu_hash_del_one_node, single_thread) {
|
||||
/* delete commit */
|
||||
rcu_hash_commit(htable);
|
||||
res = rcu_hash_find(htable, key1, key1_len);
|
||||
EXPECT_EQ(res, NULL);
|
||||
EXPECT_TRUE(res == NULL);
|
||||
|
||||
ret = rcu_hash_count(htable);
|
||||
EXPECT_EQ(ret, 0);
|
||||
@@ -219,7 +219,7 @@ TEST(rcu_hash_del_one_node, single_thread) {
|
||||
TEST(rcu_hash_del_multi_node, single_thread) {
|
||||
/* case1: add and del before commit */
|
||||
struct rcu_hash_table *htable = rcu_hash_new(data_free);
|
||||
EXPECT_NE(htable, NULL);
|
||||
EXPECT_TRUE(htable != NULL);
|
||||
|
||||
struct user_data *data1 = ALLOC(struct user_data, 1);
|
||||
data1->id = 101;
|
||||
@@ -239,7 +239,7 @@ TEST(rcu_hash_del_multi_node, single_thread) {
|
||||
|
||||
/* find in hash before commit */
|
||||
void *res = rcu_hash_find(htable, key1, key1_len);
|
||||
EXPECT_EQ(res, NULL);
|
||||
EXPECT_TRUE(res == NULL);
|
||||
|
||||
int ret = rcu_hash_count(htable);
|
||||
EXPECT_EQ(ret, 0);
|
||||
@@ -257,10 +257,10 @@ TEST(rcu_hash_del_multi_node, single_thread) {
|
||||
|
||||
/* find in hash after commit */
|
||||
res = rcu_hash_find(htable, key1, key1_len);
|
||||
EXPECT_EQ(res, NULL);
|
||||
EXPECT_TRUE(res == NULL);
|
||||
|
||||
res = rcu_hash_find(htable, key2, key2_len);
|
||||
EXPECT_NE(res, NULL);
|
||||
EXPECT_TRUE(res != NULL);
|
||||
|
||||
ret = rcu_hash_count(htable);
|
||||
EXPECT_EQ(ret, 1);
|
||||
|
||||
Reference in New Issue
Block a user