From f26ed588daa1c296a23fcef931930778f68df50a Mon Sep 17 00:00:00 2001 From: yangwei Date: Thu, 19 Sep 2024 15:58:39 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=88=20style(module=20manager):=20renam?= =?UTF-8?q?e=20plugin=20to=20module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- infra/module_manager/module_manager.c | 25 +--------- infra/mq/test/gtest_mq_main.cpp | 71 +++++++++++++-------------- 2 files changed, 35 insertions(+), 61 deletions(-) diff --git a/infra/module_manager/module_manager.c b/infra/module_manager/module_manager.c index 2a89f07..819384e 100644 --- a/infra/module_manager/module_manager.c +++ b/infra/module_manager/module_manager.c @@ -50,7 +50,7 @@ struct module_specific *module_specs_load(toml_table_t* conf, int *mod_num) } void* handle = dlopen(path, RTLD_NOW|RTLD_LAZY|RTLD_GLOBAL); if (!handle) { - fprintf(stderr, "Error loading plugin %s: %s\n", path, dlerror()); + fprintf(stderr, "Error loading module %s: %s\n", path, dlerror()); goto MODULE_SPEC_LOAD_ERROR; } @@ -126,29 +126,6 @@ void stellar_module_manager_free(struct stellar_module_manager *mod_mgr) } utarray_free(mod_mgr->schema.module_specs_array); } -#if 0 - if(plug_mgr->stellar_mq_schema_array) - { - for(unsigned int i = 0; i < utarray_len(plug_mgr->stellar_mq_schema_array); i++) - { - stellar_mq_destroy_topic( plug_mgr->st, i); - } - utarray_free(plug_mgr->stellar_mq_schema_array); - } - - //if(plug_mgr->stellar_exdata_schema_array)utarray_free(plug_mgr->stellar_exdata_schema_array); - if(plug_mgr->registered_polling_plugin_array)utarray_free(plug_mgr->registered_polling_plugin_array); - if(plug_mgr->registered_packet_plugin_array) - { - struct registered_plugin_schema *s = NULL; - while ((s = (struct registered_plugin_schema *)utarray_next(plug_mgr->registered_packet_plugin_array, s))) - { - if(s->registed_mq_subscriber_info)utarray_free(s->registed_mq_subscriber_info); - } - utarray_free(plug_mgr->registered_packet_plugin_array); - } -#endif - FREE(mod_mgr); return; } diff --git a/infra/mq/test/gtest_mq_main.cpp b/infra/mq/test/gtest_mq_main.cpp index 3f33737..c09dd96 100644 --- a/infra/mq/test/gtest_mq_main.cpp +++ b/infra/mq/test/gtest_mq_main.cpp @@ -81,8 +81,8 @@ TEST(mq_schema, mq_topic_create_and_update) { mq_schema_free(s); } -void test_mock_on_packet_msg(int topic_id, void *msg, void *plugin_env){} -void test_mock_overwrite_on_packet_msg(int topic_id, void *msg, void *plugin_env){} +void test_mock_on_packet_msg(int topic_id, void *msg, void *sub_arg){} +void test_mock_overwrite_on_packet_msg(int topic_id, void *msg, void *sub_arg){} TEST(mq_schema, subscribe) { @@ -134,29 +134,26 @@ TEST(mq_runtime, new_and_free) { } -#define PACKET_PROTO_PLUGIN_NUM 128 #define PACKET_EXDATA_NUM 2 #define PACKET_TOPIC_NUM 2 #define PACKET_MQ_SUB_NUM 2 -struct packet_plugin_env +struct mock_packet_mq_env { struct mq_schema *s; struct mq_runtime *rt; int basic_on_packet_called; - int proto_filter_plugin_id[PACKET_PROTO_PLUGIN_NUM]; - int proto_filter_plugin_called[PACKET_PROTO_PLUGIN_NUM]; int exdata_set_on_packet_called; int exdata_get_on_packet_called; unsigned int packet_exdata_idx[PACKET_EXDATA_NUM]; int exdata_free_called[PACKET_EXDATA_NUM]; unsigned int packet_topic_id[PACKET_TOPIC_NUM]; - unsigned int packet_mq_sub_plugin_id[PACKET_MQ_SUB_NUM]; + unsigned int packet_mq_sub_module_id[PACKET_MQ_SUB_NUM]; int msg_pub_cnt; int msg_sub_cnt; int msg_free_cnt; }; -struct packet_message +struct mock_packet_message { unsigned char ip_proto; int topic_in; @@ -165,22 +162,22 @@ struct packet_message static void test_packet_msg_free_cb_func(void *msg, void *msg_free_arg) { - struct packet_plugin_env *env = (struct packet_plugin_env *)msg_free_arg; + struct mock_packet_mq_env *env = (struct mock_packet_mq_env *)msg_free_arg; env->msg_free_cnt+=1; return; } -static void test_mq_on_packet_topic_msg(int topic_id, void *msg, void *plugin_env) +static void test_mq_on_packet_topic_msg(int topic_id, void *msg, void *sub_arg) { - struct packet_plugin_env *env = (struct packet_plugin_env *)plugin_env; + struct mock_packet_mq_env *env = (struct mock_packet_mq_env *)sub_arg; EXPECT_TRUE(env!=NULL); env->msg_sub_cnt+=1; return; } -static void test_mq_on_packet_in_out(int topic_id, void *msg, void *plugin_env) +static void test_mq_on_packet_in_out(int topic_id, void *msg, void *sub_arg) { - struct packet_plugin_env *env = (struct packet_plugin_env *)plugin_env; + struct mock_packet_mq_env *env = (struct mock_packet_mq_env *)sub_arg; EXPECT_TRUE(env!=NULL); int topic_id_num=(int)(sizeof(env->packet_topic_id) / sizeof(env->packet_topic_id[0])); for(int i=0; itopic_array), topic_id_num); } - int topic_sub_num=(int)(sizeof(env.packet_mq_sub_plugin_id) / sizeof(env.packet_mq_sub_plugin_id[0])); + int topic_sub_num=(int)(sizeof(env.packet_mq_sub_module_id) / sizeof(env.packet_mq_sub_module_id[0])); for (int i = 0; i < topic_sub_num; i++) { @@ -242,7 +239,7 @@ TEST(mq_runtime, basic_pub_sub) { mq_schema_subscribe(s, packet_in_topic_id, test_mq_on_packet_in_out, &env); mq_schema_subscribe(s, packet_out_topic_id, test_mq_on_packet_in_out, &env); - struct packet_message pkt={6, packet_in_topic_id, packet_out_topic_id}; + struct mock_packet_message pkt={6, packet_in_topic_id, packet_out_topic_id}; struct mq_runtime *rt = mq_runtime_new(s); EXPECT_TRUE(rt!=NULL); @@ -270,18 +267,18 @@ TEST(mq_runtime, basic_pub_sub) { * MQ RUNTIME WITH DISPATCH * **********************************************/ -struct session_message +struct mock_session_message { int id; int cnt; }; -struct session_mq_test_env +struct mock_session_mq_env { struct mq_schema *s; struct mq_runtime *rt; int N_session; - struct session_message sess[1024]; + struct mock_session_message sess[1024]; int intrinsc_tcp_input_topic_id; int basic_on_tcp_called; int sess_dispatch_called; @@ -290,41 +287,41 @@ struct session_mq_test_env }; #define TOPIC_TCP "TCP" -typedef void on_session_msg_cb_func(int topic_id, struct session_message *sess, void *module_ctx); +typedef void mock_on_session_msg_cb_func(int topic_id, struct mock_session_message *sess, void *module_ctx); -static void pesudo_on_msg_dispatch(int topic_id, +static void mock_on_msg_dispatch(int topic_id, void *msg, on_msg_cb_func* on_msg_cb, void *on_msg_cb_arg, void *dispatch_arg) { - on_session_msg_cb_func *session_cb = (on_session_msg_cb_func *)on_msg_cb; - struct session_message *sess=(struct session_message *)msg; + mock_on_session_msg_cb_func *session_cb = (mock_on_session_msg_cb_func *)on_msg_cb; + struct mock_session_message *sess=(struct mock_session_message *)msg; EXPECT_TRUE(dispatch_arg==NULL); session_cb(topic_id, sess, on_msg_cb_arg); - struct session_mq_test_env *env=(struct session_mq_test_env *)on_msg_cb_arg; + struct mock_session_mq_env *env=(struct mock_session_mq_env *)on_msg_cb_arg; env->sess_dispatch_called+=1; } -static void pesudo_tcp_session_msg_free(void *msg, void *msg_free_arg) +static void mock_tcp_session_msg_free(void *msg, void *msg_free_arg) { - struct session_mq_test_env *env=(struct session_mq_test_env *)msg_free_arg; + struct mock_session_mq_env *env=(struct mock_session_mq_env *)msg_free_arg; env->sess_msg_free_called+=1; } -static int pesudo_tcp_session_subscribe(struct session_mq_test_env *env, on_session_msg_cb_func *on_session_cb) +static int mock_tcp_session_subscribe(struct mock_session_mq_env *env, mock_on_session_msg_cb_func *on_session_cb) { int topic_id=mq_schema_get_topic_id(env->s, TOPIC_TCP); if(topic_id<0) { - topic_id=mq_schema_create_topic(env->s, TOPIC_TCP, pesudo_on_msg_dispatch, NULL, pesudo_tcp_session_msg_free, env); + topic_id=mq_schema_create_topic(env->s, TOPIC_TCP, mock_on_msg_dispatch, NULL, mock_tcp_session_msg_free, env); } return mq_schema_subscribe(env->s, topic_id, (on_msg_cb_func *)on_session_cb, env); } -static void test_basic_on_tcp_session(int topic_id, struct session_message *sess, void *plugin_env) +static void test_basic_on_tcp_session(int topic_id, struct mock_session_message *sess, void *sub_arg) { - struct session_mq_test_env *env = (struct session_mq_test_env *)plugin_env; + struct mock_session_mq_env *env = (struct mock_session_mq_env *)sub_arg; EXPECT_TRUE(env!=NULL); if(sess) { @@ -335,13 +332,13 @@ static void test_basic_on_tcp_session(int topic_id, struct session_message *sess TEST(mq_runtime, sub_with_dispatch_cb) { - struct session_mq_test_env env; + struct mock_session_mq_env env; memset(&env, 0, sizeof(env)); env.N_session=10; env.s=mq_schema_new(); - EXPECT_EQ(pesudo_tcp_session_subscribe(&env, test_basic_on_tcp_session), 0); + EXPECT_EQ(mock_tcp_session_subscribe(&env, test_basic_on_tcp_session), 0); env.intrinsc_tcp_input_topic_id=mq_schema_get_topic_id(env.s, TOPIC_TCP); env.rt=mq_runtime_new(env.s); @@ -558,7 +555,7 @@ TEST(mq_runtime, test_session_mq_priority) { struct session_plugin_env env; memset(&env, 0, sizeof(struct session_plugin_env)); -// pesudo init stage +// mock init stage struct plugin_manager_schema *plug_mgr = plugin_manager_init(&st, NULL, MAX_MSG_PER_STAGE); whitebox_test_plugin_manager_intrisic_metadata(&st, plug_mgr); @@ -586,7 +583,7 @@ TEST(mq_runtime, test_session_mq_priority) { EXPECT_EQ(stellar_mq_subscribe(&st, env.test_mq_topic_id, test_session_mq_priority_plugin_1_on_msg, plugin_id_1), 0); EXPECT_EQ(stellar_mq_subscribe(&st, env.test_mq_topic_id, test_session_mq_priority_plugin_2_on_msg, plugin_id_2), 0); -// pesudo packet and session +// mock packet and session env.plug_mgr=plug_mgr; env.N_per_session_pkt_cnt=10; @@ -597,7 +594,7 @@ TEST(mq_runtime, test_session_mq_priority) { struct session sess[env.N_session]; memset(&sess, 0, sizeof(sess)); -// pesudo running stage +// mock running stage for(int i=0; i < env.N_session; i++) { sess[i].state=SESSION_STATE_OPENING; @@ -625,7 +622,7 @@ TEST(mq_runtime, test_session_mq_priority) { session_exdata_runtime_free(sess[i].session_exdat_rt); } -// pesudo exit stage +// mock exit stage plugin_manager_exit(plug_mgr); // each session publish TCP TOPIC per_session_pkt_cnt+1, and SESSION_PRIORITY_TOPIC 2*(msg per_session_pkt_cnt+1)