diff options
| author | yangwei <[email protected]> | 2024-11-26 18:59:55 +0800 |
|---|---|---|
| committer | yangwei <[email protected]> | 2024-11-27 10:29:23 +0800 |
| commit | f80da6760d8ef7a2ac00e22e7c4655dc79285e2d (patch) | |
| tree | b51776a48864af74fa9a7e7505db19afb754c849 /test | |
| parent | 1b55f09ba7b13be81808688919d1766e05707676 (diff) | |
🧪 test(enable lpi plus test): lpi test
Diffstat (limited to 'test')
| -rw-r--r-- | test/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | test/lpi_plus/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | test/lpi_plus/gtest_lpip.h | 10 | ||||
| -rw-r--r-- | test/lpi_plus/gtest_lpip_main.cpp | 16 | ||||
| -rw-r--r-- | test/lpi_plus/gtest_lpip_module.c | 67 | ||||
| -rw-r--r-- | test/lpi_plus/test_config/spec.toml | 11 |
6 files changed, 50 insertions, 59 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8b080ac..cc3398a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,7 +1,7 @@ #add_subdirectory(packet_inject) add_subdirectory(packet_tool) #add_subdirectory(session_debugger) -#add_subdirectory(lpi_plus) +add_subdirectory(lpi_plus) #add_subdirectory(decoders/http) #add_subdirectory(decoders/socks) #add_subdirectory(decoders/stratum) diff --git a/test/lpi_plus/CMakeLists.txt b/test/lpi_plus/CMakeLists.txt index 9f63273..5eb5094 100644 --- a/test/lpi_plus/CMakeLists.txt +++ b/test/lpi_plus/CMakeLists.txt @@ -4,7 +4,7 @@ target_include_directories(gtest_lpip PRIVATE ${CMAKE_SOURCE_DIR}/deps/) target_include_directories(gtest_lpip PRIVATE ${CMAKE_SOURCE_DIR}/decoders/) target_link_libraries( - gtest_lpip PRIVATE stellar_lib cjson-static lpi_plus + gtest_lpip PRIVATE stellar_lib cjson-static dl "-rdynamic" gtest gmock ) @@ -20,7 +20,6 @@ add_test(NAME ${TEST_NAME}.SETUP COMMAND sh -c " mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/log && mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/tsgconf && cp ${CMAKE_SOURCE_DIR}/conf/stellar.toml ${CMAKE_CURRENT_BINARY_DIR}/conf/ && - cat ${CMAKE_CURRENT_SOURCE_DIR}/test_config/spec.toml >> ${CMAKE_CURRENT_BINARY_DIR}/conf/stellar.toml && cp ${CMAKE_CURRENT_SOURCE_DIR}/test_config/tsg_l7_protocol.conf ${CMAKE_CURRENT_BINARY_DIR}/tsgconf/ && tomlq -t -i '.packet_io.pcap_path=\"-\"' ${CMAKE_CURRENT_BINARY_DIR}/conf/stellar.toml && tomlq -t -i '.packet_io.mode=\"pcaplist\"' ${CMAKE_CURRENT_BINARY_DIR}/conf/stellar.toml diff --git a/test/lpi_plus/gtest_lpip.h b/test/lpi_plus/gtest_lpip.h index 9b13571..1080048 100644 --- a/test/lpi_plus/gtest_lpip.h +++ b/test/lpi_plus/gtest_lpip.h @@ -5,12 +5,16 @@ extern "C" { #endif -int stellar_test_result_setup(); - +void stellar_test_result_setup(); char *stellar_test_result_json_export(); - void stellar_test_result_cleanup(); +#define GTEST_LPIP_MODULE_NAME "TEST_LPIP" +void gtest_lpip_on_packet(struct packet *pkt, struct module *mod); + +struct module *gtest_lpip_module_init(struct module_manager *mod_mgr); +void gtest_lpip_module_exit(struct module_manager *mod_mgr, struct module *mod); + #ifdef __cplusplus } #endif
\ No newline at end of file diff --git a/test/lpi_plus/gtest_lpip_main.cpp b/test/lpi_plus/gtest_lpip_main.cpp index 6745832..63306b8 100644 --- a/test/lpi_plus/gtest_lpip_main.cpp +++ b/test/lpi_plus/gtest_lpip_main.cpp @@ -113,6 +113,10 @@ static void gtest_result_free(struct gtest_json_result *para) * GTEST MAIN * **********************************************/ +#include "stellar/packet.h" + +extern "C" void gtest_lpip_on_packet(struct packet *pkt, struct module *mod); + int main(int argc, char ** argv) { ::testing::InitGoogleTest(&argc, argv); @@ -126,6 +130,16 @@ int main(int argc, char ** argv) struct stellar *st=stellar_new("./conf/stellar.toml"); + struct module_manager *mod_mgr=stellar_get_module_manager(st); + + struct module *pkt_mgr_mod=module_manager_get_module(mod_mgr, PACKET_MANAGER_MODULE_NAME); + + struct packet_manager *pkt_mgr=module_to_packet_manager(pkt_mgr_mod); + + struct module *gtest_lpip_mod=gtest_lpip_module_init(mod_mgr); + + packet_manager_register_node(pkt_mgr, "LPI_PLUS", PACKET_STAGE_FORWARD, PKT_TAG_KEY_IPPROTO, PKT_TAG_VAL_IPPROTO_TCP | PKT_TAG_VAL_IPPROTO_UDP, gtest_lpip_on_packet, gtest_lpip_mod); + stellar_test_result_setup(); EXPECT_TRUE(st!=NULL); @@ -133,6 +147,8 @@ int main(int argc, char ** argv) stellar_free(st); + gtest_lpip_module_exit(mod_mgr, gtest_lpip_mod); + char *test_result_json=stellar_test_result_json_export(); g_test_para->test_json_root=cJSON_Parse(test_result_json); free(test_result_json); diff --git a/test/lpi_plus/gtest_lpip_module.c b/test/lpi_plus/gtest_lpip_module.c index c6998dc..00e0a28 100644 --- a/test/lpi_plus/gtest_lpip_module.c +++ b/test/lpi_plus/gtest_lpip_module.c @@ -12,16 +12,22 @@ #include "cjson/cJSON.h" -#include "lpi_plus/lpi_plus_internal.h" +#include "stellar/lpi_plus.h" +#include "gtest_lpip.h" struct test_lpip_env { struct module_manager *mod_mgr; + struct session_manager *sess_mgr; struct lpi_plus *lpip; int l7_exdata_idx; int session_num; }; +#ifndef MAX_APPID_NUM +#define MAX_APPID_NUM 8 +#endif + struct test_lpip_exdata { int appid[MAX_APPID_NUM]; @@ -35,6 +41,7 @@ void stellar_test_result_setup() { if(g_result_json!=NULL)return; g_result_json=cJSON_CreateArray(); + return; } char *stellar_test_result_json_export() @@ -111,41 +118,25 @@ static void gtest_lpip_exdata_free(int idx __attribute__((unused)), void *ex_ptr } -static void gtest_lpip_on_appid_msg(struct session *sess, int appid[], int packet_sequence[],size_t appid_num, void *args) +void gtest_lpip_on_packet(struct packet *pkt, struct module *mod) { - if(sess==NULL || appid==NULL || args==NULL)return; - struct test_lpip_env *env = (struct test_lpip_env *)args; - struct test_lpip_exdata *test_appid_exdata=session_get_exdata(sess, env->l7_exdata_idx); - if(test_appid_exdata==NULL) + + struct test_lpip_env *env = (struct test_lpip_env *)module_get_ctx(mod); + struct session *sess=packet_exdata_to_session(env->sess_mgr, pkt); + struct test_lpip_exdata *test_appid_exdata=session_get_exdata(sess, env->l7_exdata_idx); + if (test_appid_exdata==NULL) { test_appid_exdata = CALLOC(struct test_lpip_exdata, 1); test_appid_exdata->sess=sess; - + session_set_exdata(sess, env->l7_exdata_idx, test_appid_exdata); } - memcpy(test_appid_exdata->appid, appid, appid_num*sizeof(appid[0])); - test_appid_exdata->appid_num=appid_num; - session_set_exdata(sess, env->l7_exdata_idx, test_appid_exdata); - return; -} -static void on_session(struct session *sess, enum session_state state, struct packet *pkt, void *args) -{ - if (state == SESSION_STATE_CLOSED) + size_t appid_num=0; + int32_t *appid = packet_exdata_to_lpip_appid(env->lpip, pkt, &appid_num); + if(appid_num>0 && appid!=NULL) { - assert(pkt == NULL); - return; - } - - struct test_lpip_env *env = (struct test_lpip_env *)args; - if (session_get_current_state(sess) == SESSION_STATE_OPENING) - { - struct test_lpip_exdata *test_appid_exdata = session_get_exdata(sess, env->l7_exdata_idx); - if (test_appid_exdata == NULL) - { - test_appid_exdata = CALLOC(struct test_lpip_exdata, 1); - test_appid_exdata->sess=sess; - session_set_exdata(sess, env->l7_exdata_idx, test_appid_exdata); - } + test_appid_exdata->appid_num=appid_num; + memcpy(test_appid_exdata->appid, appid, sizeof(*appid)*appid_num); } return; } @@ -156,27 +147,19 @@ struct module *gtest_lpip_module_init(struct module_manager *mod_mgr) struct module *lpip_mod = module_manager_get_module(mod_mgr, LPI_PLUS_MODULE_NAME); env->lpip=module_to_lpi_plus(lpip_mod); struct module *sess_mgr_mod=module_manager_get_module(mod_mgr, SESSION_MANAGER_MODULE_NAME); - struct session_manager *sess_mgr = module_to_session_manager(sess_mgr_mod); - if(sess_mgr == NULL) + env->sess_mgr = module_to_session_manager(sess_mgr_mod); + if(env->sess_mgr == NULL) { perror("gtest_lpi_plugin_load:stellar_module_get_session_manager failed !!!\n"); exit(-1); } - - session_manager_subscribe_udp(sess_mgr, on_session, env); - session_manager_subscribe_tcp(sess_mgr, on_session, env); - - env->l7_exdata_idx = session_manager_new_session_exdata_index(sess_mgr, "EXDATA_L7", gtest_lpip_exdata_free, env); - - lpi_plus_appid_subscribe(env->lpip, gtest_lpip_on_appid_msg, env); + env->l7_exdata_idx = session_manager_new_session_exdata_index(env->sess_mgr, "EXDATA_L7", gtest_lpip_exdata_free, env); printf("gtest_lpip_module_init OK!\n"); - - return module_new("TEST_LPIP", env); + return module_new(GTEST_LPIP_MODULE_NAME, env); } -void gtest_lpip_module_exit(struct module_manager *mod_mgr, struct module *mod) +void gtest_lpip_module_exit(struct module_manager *mod_mgr __unused, struct module *mod) { - assert(mod_mgr!=NULL); struct test_lpip_env *env = (struct test_lpip_env *)module_get_ctx(mod); free(env); printf("gtest_lpip_module_exit OK!\n"); diff --git a/test/lpi_plus/test_config/spec.toml b/test/lpi_plus/test_config/spec.toml deleted file mode 100644 index 329f401..0000000 --- a/test/lpi_plus/test_config/spec.toml +++ /dev/null @@ -1,11 +0,0 @@ -# stellar_plugin.toml -# -[[module]] -path = "" -init = "lpi_plus_init" -exit = "lpi_plus_exit" - -[[module]] -path = "" -init = "gtest_lpip_module_init" -exit = "gtest_lpip_module_exit" |
