diff options
| author | yangwei <[email protected]> | 2024-09-06 13:41:40 +0800 |
|---|---|---|
| committer | yangwei <[email protected]> | 2024-09-06 19:48:29 +0800 |
| commit | 9cb50f81fb5338c73e4fa5cc8901109880bfe95e (patch) | |
| tree | bef5de5572241236062e6ba433d419569a636919 | |
| parent | cc542dc36538a8dd977a12c739f9c307c9e0b321 (diff) | |
✨ feat(plugin_manager_init): set max_msg_per_stage as parameter
| -rw-r--r-- | infra/plugin_manager/plugin_manager.c | 5 | ||||
| -rw-r--r-- | infra/plugin_manager/plugin_manager.h | 4 | ||||
| -rw-r--r-- | infra/plugin_manager/plugin_manager_interna.h | 4 | ||||
| -rw-r--r-- | infra/plugin_manager/test/plugin_manager_gtest_main.cpp | 48 |
4 files changed, 30 insertions, 31 deletions
diff --git a/infra/plugin_manager/plugin_manager.c b/infra/plugin_manager/plugin_manager.c index 77e0bcb..439869f 100644 --- a/infra/plugin_manager/plugin_manager.c +++ b/infra/plugin_manager/plugin_manager.c @@ -92,7 +92,7 @@ static void plugin_manager_per_thread_data_free(struct plugin_manager_per_thread return; } -struct plugin_manager_schema *plugin_manager_init(struct stellar *st, const char *plugin_spec_file_path) +struct plugin_manager_schema *plugin_manager_init(struct stellar *st, const char *plugin_spec_file_path, unsigned int max_msg_per_stage) { int spec_num; struct plugin_specific *specs = plugin_specs_load(plugin_spec_file_path, &spec_num); @@ -101,8 +101,7 @@ struct plugin_manager_schema *plugin_manager_init(struct stellar *st, const char return NULL; } struct plugin_manager_schema *plug_mgr = CALLOC(struct plugin_manager_schema, 1); - //TODO: set max_message_dispatch as parameter - plug_mgr->max_message_dispatch=MAX_MSG_PER_DISPATCH; + plug_mgr->max_message_dispatch=max_msg_per_stage; if(spec_num > 0) { utarray_new(plug_mgr->plugin_load_specs_array,&plugin_specs_icd); diff --git a/infra/plugin_manager/plugin_manager.h b/infra/plugin_manager/plugin_manager.h index 7b66e05..08cf287 100644 --- a/infra/plugin_manager/plugin_manager.h +++ b/infra/plugin_manager/plugin_manager.h @@ -7,10 +7,12 @@ extern "C" { #endif +#define MAX_MSG_PER_STAGE 256 + struct plugin_manager_schema; struct plugin_manager_runtime; -struct plugin_manager_schema *plugin_manager_init(struct stellar *st, const char *plugin_spec_file_path); +struct plugin_manager_schema *plugin_manager_init(struct stellar *st, const char *plugin_spec_file_path, unsigned int max_msg_per_stage); void plugin_manager_exit(struct plugin_manager_schema *plug_mgr); void plugin_manager_on_packet_input(struct plugin_manager_schema *plug_mgr, struct packet *pkt); diff --git a/infra/plugin_manager/plugin_manager_interna.h b/infra/plugin_manager/plugin_manager_interna.h index 9bbc763..ae82573 100644 --- a/infra/plugin_manager/plugin_manager_interna.h +++ b/infra/plugin_manager/plugin_manager_interna.h @@ -40,7 +40,7 @@ struct plugin_manager_schema UT_array *registered_polling_plugin_array; int stellar_mq_topic_num; int mq_topic_subscriber_num; - int max_message_dispatch; + unsigned int max_message_dispatch; struct plugin_manager_per_thread_data *per_thread_data; }__attribute__((aligned(sizeof(void*)))); @@ -131,8 +131,6 @@ struct stellar_mq_subscriber_info * PLUGIN MANAGER INIT & EXIT * *******************************/ -#define MAX_MSG_PER_DISPATCH 256 - #include <dlfcn.h> struct plugin_specific diff --git a/infra/plugin_manager/test/plugin_manager_gtest_main.cpp b/infra/plugin_manager/test/plugin_manager_gtest_main.cpp index d2e8f73..fe49514 100644 --- a/infra/plugin_manager/test/plugin_manager_gtest_main.cpp +++ b/infra/plugin_manager/test/plugin_manager_gtest_main.cpp @@ -49,7 +49,7 @@ void whitebox_test_plugin_manager_intrisic_metadata(struct stellar *st, struct p TEST(plugin_manager_init, init_with_null_toml) { struct stellar st={0}; - struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL); + struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL, MAX_MSG_PER_STAGE); whitebox_test_plugin_manager_intrisic_metadata(&st, plug_mgr); plugin_manager_exit(plug_mgr); } @@ -64,7 +64,7 @@ static void test_mock_overwrite_packet_exdata_free(int idx, void *ex_ptr, void * TEST(plugin_manager_init, packet_exdata_new_index_overwrite) { struct stellar st={0}; - struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL); + struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL, MAX_MSG_PER_STAGE); whitebox_test_plugin_manager_intrisic_metadata(&st, plug_mgr); const char *exdata_name="PACKET_EXDATA"; @@ -95,7 +95,7 @@ void test_mock_overwrite_packet_msg_free(void *msg, void *msg_free_arg){} TEST(plugin_manager_init, stellar_mq_topic_create_and_update) { struct stellar st={0}; - struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL); + struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL, MAX_MSG_PER_STAGE); whitebox_test_plugin_manager_intrisic_metadata(&st, plug_mgr); const char *topic_name="PACKET_TOPIC"; @@ -159,7 +159,7 @@ void test_mock_overwrite_on_packet_msg(int topic_id, const void *msg, void *plug TEST(plugin_manager_init, stellar_mq_subscribe) { struct stellar st={0}; - struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL); + struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL, MAX_MSG_PER_STAGE); whitebox_test_plugin_manager_intrisic_metadata(&st, plug_mgr); @@ -198,7 +198,7 @@ static void test_mock_overwrite_session_exdata_free(int idx, void *ex_ptr, void TEST(plugin_manager_init, session_exdata_new_index_overwrite) { struct stellar st={0}; - struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL); + struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL, MAX_MSG_PER_STAGE); whitebox_test_plugin_manager_intrisic_metadata(&st, plug_mgr); const char *exdata_name="SESSION_EXDATA"; @@ -232,7 +232,7 @@ void test_mock_overwrite_on_session_msg(int topic_id, const void *msg, void *plu TEST(plugin_manager_init, stellar_mq_subscribe_overwrite) { struct stellar st={0}; - struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL); + struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL, MAX_MSG_PER_STAGE); whitebox_test_plugin_manager_intrisic_metadata(&st, plug_mgr); const char *topic_name="SESSION_TOPIC"; @@ -276,7 +276,7 @@ int test_plugin_on_polling_func(void *plugin_env) TEST(plugin_manager_init, polling_plugin_register) { struct stellar st={0}; - struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL); + struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL, MAX_MSG_PER_STAGE); st.plug_mgr=plug_mgr; whitebox_test_plugin_manager_intrisic_metadata(&st, plug_mgr); @@ -334,7 +334,7 @@ static void test_basic_on_packet(struct packet *pkt, void *plugin_env) TEST(plugin_manager, packet_plugin_illegal_exdata) { struct stellar st={0}; - struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL); + struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL, MAX_MSG_PER_STAGE); whitebox_test_plugin_manager_intrisic_metadata(&st, plug_mgr); unsigned char ip_proto=6; @@ -374,7 +374,7 @@ static void test_proto_filter_on_packet(struct packet *pkt, void *plugin_env) TEST(plugin_manager, DISABLED_packet_plugins_with_proto_filter) { struct stellar st={0}; - struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL); + struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL, MAX_MSG_PER_STAGE); whitebox_test_plugin_manager_intrisic_metadata(&st, plug_mgr); struct packet_plugin_env env; @@ -481,7 +481,7 @@ static void test_packet_exdata_free(int idx, void *ex_ptr, void *arg) TEST(plugin_manager, packet_plugins_share_exdata) { struct stellar st={0}; - struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL); + struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL, MAX_MSG_PER_STAGE); whitebox_test_plugin_manager_intrisic_metadata(&st, plug_mgr); unsigned char ip_proto=6; @@ -576,7 +576,7 @@ static void test_mq_pub_on_packet(struct packet *pkt, void *plugin_env) TEST(plugin_manager, packet_plugins_mq_pub_sub) { struct stellar st={0}; - struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL); + struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL, MAX_MSG_PER_STAGE); whitebox_test_plugin_manager_intrisic_metadata(&st, plug_mgr); unsigned char ip_proto=6; @@ -665,16 +665,16 @@ static void overlimit_pub_on_packet(struct packet *pkt, void *plugin_env) EXPECT_TRUE(env!=NULL); //EXPECT_EQ(pkt->ip_proto, ip_protocol); int topic_id_num=(int)(sizeof(env->packet_topic_id) / sizeof(env->packet_topic_id[0])); - int cnt=0; + unsigned int cnt=0; int *msg; for(int i=0; i<topic_id_num; i++) { - for(int j=0; j < MAX_MSG_PER_DISPATCH; j++) + for(unsigned int j=0; j < env->plug_mgr->max_message_dispatch; j++) { msg=CALLOC(int, 1); *msg=cnt; int pub_ret=stellar_mq_publish_message(env->plug_mgr->st, env->packet_topic_id[i], msg); - if(cnt < MAX_MSG_PER_DISPATCH) + if(cnt < env->plug_mgr->max_message_dispatch) { ASSERT_EQ(pub_ret, 0); env->msg_pub_cnt+=1; @@ -693,7 +693,7 @@ static void overlimit_pub_on_packet(struct packet *pkt, void *plugin_env) TEST(plugin_manager, packet_plugins_pub_overlimit) { struct stellar st={0}; - struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL); + struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL, MAX_MSG_PER_STAGE); whitebox_test_plugin_manager_intrisic_metadata(&st, plug_mgr); unsigned char ip_proto=6; @@ -755,7 +755,7 @@ TEST(plugin_manager, packet_plugins_pub_overlimit) { } plugin_manager_exit(plug_mgr); - EXPECT_EQ(N_packet*MAX_MSG_PER_DISPATCH, env.msg_pub_cnt); + EXPECT_EQ(N_packet*MAX_MSG_PER_STAGE, env.msg_pub_cnt); EXPECT_EQ(env.msg_free_cnt, env.msg_pub_cnt); EXPECT_EQ(env.msg_sub_cnt, env.msg_pub_cnt*topic_sub_num); } @@ -801,7 +801,7 @@ static void test_exdata_free_pub_msg_on_packet_msg(int topic_id, const void *msg TEST(plugin_manager, packet_plugin_exdata_free_pub_msg) { struct stellar st={0}; - struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL); + struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL, MAX_MSG_PER_STAGE); whitebox_test_plugin_manager_intrisic_metadata(&st, plug_mgr); unsigned char ip_proto=6; @@ -937,7 +937,7 @@ TEST(plugin_manager, no_plugin_register_runtime) { struct stellar st={0}; // init stage - struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL); + struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL, MAX_MSG_PER_STAGE); whitebox_test_plugin_manager_intrisic_metadata(&st, plug_mgr); @@ -996,7 +996,7 @@ static void test_basic_session_exdata_free(int idx, void *ex_ptr, void *arg) TEST(plugin_manager, session_plugin_on_tcp) { struct stellar st={0}; - struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL); + struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL,MAX_MSG_PER_STAGE); whitebox_test_plugin_manager_intrisic_metadata(&st, plug_mgr); unsigned char ip_proto=6; @@ -1133,7 +1133,7 @@ static void test_overlimit_session_msg_free(void *msg, void *msg_free_arg) TEST(plugin_manager,DISABLED_session_plugin_pub_msg_overlimt) { struct stellar st={0}; - struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL); + struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL, MAX_MSG_PER_STAGE); whitebox_test_plugin_manager_intrisic_metadata(&st, plug_mgr); unsigned char ip_proto=6; @@ -1258,7 +1258,7 @@ TEST(plugin_manager, DISABLED_session_plugin_pub_msg_on_closing) { memset(&env, 0, sizeof(struct session_manager_plugin_env)); // pesudo init stage - struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL); + struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL, MAX_MSG_PER_STAGE); whitebox_test_plugin_manager_intrisic_metadata(&st, plug_mgr); // plugin manager register plugin @@ -1403,7 +1403,7 @@ TEST(plugin_manager, test_session_mq_priority) { memset(&env, 0, sizeof(struct session_plugin_env)); // pesudo init stage - struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL); + struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL, MAX_MSG_PER_STAGE); whitebox_test_plugin_manager_intrisic_metadata(&st, plug_mgr); // plugin manager register plugin @@ -1504,7 +1504,7 @@ TEST(plugin_manager, session_exdata_free_pub_msg) { struct session_manager_plugin_env env; // pesudo init stage - struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL); + struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL, MAX_MSG_PER_STAGE); whitebox_test_plugin_manager_intrisic_metadata(&st, plug_mgr); // plugin manager register plugin @@ -1596,7 +1596,7 @@ TEST(plugin_manager, basic_polling_plugins) { // pesudo init stage struct stellar st={0}; - struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL); + struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL, MAX_MSG_PER_STAGE); st.plug_mgr=plug_mgr; struct polling_plugin_env env; memset(&env, 0, sizeof(struct polling_plugin_env)); |
