summaryrefslogtreecommitdiff
path: root/test/src
diff options
context:
space:
mode:
authorliuxueli <[email protected]>2023-06-12 15:42:46 +0800
committerliuxueli <[email protected]>2023-06-12 15:42:46 +0800
commit03b39fc31431a60c411aa8455a636110ca1eeb4e (patch)
tree61a99e070057504062d4c1c7be85097619907d1f /test/src
parent3dea0f5399f2d749e188de9bfb94cd02f93f8a02 (diff)
优化存储application的空间
Diffstat (limited to 'test/src')
-rw-r--r--test/src/gtest_bridge.cpp38
-rw-r--r--test/src/gtest_common.cpp5
-rw-r--r--test/src/gtest_master.cpp45
3 files changed, 59 insertions, 29 deletions
diff --git a/test/src/gtest_bridge.cpp b/test/src/gtest_bridge.cpp
index 7f36454..2ec91a0 100644
--- a/test/src/gtest_bridge.cpp
+++ b/test/src/gtest_bridge.cpp
@@ -414,14 +414,38 @@ extern void session_gather_app_results_free(const struct streaminfo *a_stream, i
TEST(TSG_Bridge, GatherAppResultAsync)
{
const struct streaminfo a_stream = {0};
- struct gather_app_result *gather_result = (struct gather_app_result *)dictator_malloc(a_stream.threadnum, sizeof(struct gather_app_result));
- gather_result->app_num = 1003;
- session_gather_app_results_async(&a_stream, (void *)gather_result);
- struct gather_app_result *test = (struct gather_app_result *)session_gather_app_results_get(&a_stream);
- EXPECT_EQ(test, gather_result);
- EXPECT_EQ(test->app_num, 1003);
- session_gather_app_results_free(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_GATHER_APP_RESULT].id, (void *)test);
+ struct gather_app_result *gather_result_in = (struct gather_app_result *)dictator_malloc(a_stream.threadnum, sizeof(struct gather_app_result));
+ memset(gather_result_in, 0, sizeof(struct gather_app_result));
+
+ gather_result_in->unknown_flag = 1;
+ gather_result_in->unknown.app_id=4;
+ gather_result_in->unknown.surrogate_id=0;
+ gather_result_in->unknown.packet_sequence=40;
+
+ session_gather_app_results_async(&a_stream, (void *)gather_result_in);
+ struct gather_app_result *gather_result_out = (struct gather_app_result *)session_gather_app_results_get(&a_stream);
+ EXPECT_NE(nullptr, gather_result_out);
+ EXPECT_EQ(gather_result_out->unknown_flag, 1);
+ EXPECT_EQ(gather_result_out->unknown.app_id, 4);
+ EXPECT_EQ(gather_result_out->unknown.surrogate_id, 0);
+ EXPECT_EQ(gather_result_out->unknown.packet_sequence, 40);
+
+ EXPECT_EQ(gather_result_out->matched_app_flag, 0);
+ EXPECT_EQ(gather_result_out->l7_protocol_num, 0);
+ EXPECT_EQ(gather_result_out->l7_qm_engine_num, 0);
+ EXPECT_EQ(gather_result_out->qm_engine_num, 0);
+ EXPECT_EQ(gather_result_out->user_define_num, 0);
+ EXPECT_EQ(gather_result_out->built_in_num, 0);
+
+ EXPECT_EQ(nullptr, gather_result_out->built_in);
+ EXPECT_EQ(nullptr, gather_result_out->l7_protocol);
+ EXPECT_EQ(nullptr, gather_result_out->qm_engine);
+ EXPECT_EQ(nullptr, gather_result_out->user_define);
+
+ session_gather_app_results_free(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_GATHER_APP_RESULT].id, (void *)gather_result_out);
session_gather_app_results_async(&a_stream, NULL);
+
+ EXPECT_EQ(nullptr, session_gather_app_results_get(&a_stream));
}
static void tsg_bridge_test_init_attribute(const struct streaminfo *a_stream, struct session_runtime_attribute *attribute)
diff --git a/test/src/gtest_common.cpp b/test/src/gtest_common.cpp
index f3e3718..086ee7e 100644
--- a/test/src/gtest_common.cpp
+++ b/test/src/gtest_common.cpp
@@ -20,6 +20,11 @@ void *dictator_malloc(int thread_seq,size_t size)
return calloc(1, size);
}
+void *dictator_realloc(int thread_seq, void * pbuf, size_t size)
+{
+ return realloc(pbuf, size);
+}
+
const char *printaddr (const struct layer_addr *paddrinfo, int threadindex)
{
return gtest_addrlist;
diff --git a/test/src/gtest_master.cpp b/test/src/gtest_master.cpp
index 0a2b20c..047aa9f 100644
--- a/test/src/gtest_master.cpp
+++ b/test/src/gtest_master.cpp
@@ -20,31 +20,32 @@ extern void session_segment_id_free(const struct streaminfo * a_stream, int brid
TEST(TSGMaster, SetAPPIDHttp)
{
const struct streaminfo a_stream={0};
- struct gather_app_result async_gather_result[ORIGIN_MAX]={0};
-
- async_gather_result[ORIGIN_BASIC_PROTOCOL].app_num=1;
- async_gather_result[ORIGIN_BASIC_PROTOCOL].origin=ORIGIN_BASIC_PROTOCOL;
- async_gather_result[ORIGIN_BASIC_PROTOCOL].attributes[0].app_id=67; //HTTP
-
- session_gather_app_results_async(&a_stream, (void *)async_gather_result);
- struct gather_app_result *gather_result=(struct gather_app_result *)session_gather_app_results_get(&a_stream);
- EXPECT_NE(nullptr, gather_result);
- EXPECT_EQ(1, gather_result[ORIGIN_BASIC_PROTOCOL].app_num);
- EXPECT_EQ(67, gather_result[ORIGIN_BASIC_PROTOCOL].attributes[0].app_id);
- EXPECT_EQ(0, gather_result[ORIGIN_BASIC_PROTOCOL].attributes[0].packet_sequence);
- EXPECT_EQ(0, gather_result[ORIGIN_BASIC_PROTOCOL].attributes[0].surrogate_id);
- EXPECT_EQ(ORIGIN_BASIC_PROTOCOL, gather_result[ORIGIN_BASIC_PROTOCOL].origin);
+ struct gather_app_result *gather_result_in=(struct gather_app_result *)dictator_malloc(0, sizeof(struct gather_app_result));
+ memset(gather_result_in, 0, sizeof(struct gather_app_result));
+
+ gather_result_in->l7_protocol_num=1;
+ gather_result_in->l7_protocol=(struct app_attributes *)dictator_malloc(0, sizeof(struct app_attributes));
+ gather_result_in->l7_protocol[0].app_id=67; //HTTP
+ gather_result_in->l7_protocol[0].surrogate_id=0; //HTTP
+ gather_result_in->l7_protocol[0].packet_sequence=1; //HTTP
+
+ session_gather_app_results_async(&a_stream, (void *)gather_result_in);
+ struct gather_app_result *gather_result_out=(struct gather_app_result *)session_gather_app_results_get(&a_stream);
+ EXPECT_NE(nullptr, gather_result_out);
+ EXPECT_EQ(1, gather_result_out->l7_protocol_num);
+ EXPECT_EQ(67, gather_result_out->l7_protocol[0].app_id);
+ EXPECT_EQ(0, gather_result_out->l7_protocol[0].surrogate_id);
+ EXPECT_EQ(1, gather_result_out->l7_protocol[0].packet_sequence);
struct TLD_handle_t *handle=TLD_create(0);
set_app_id(g_tsg_log_instance, handle, (struct streaminfo *)&a_stream);
char app_ids[256]={0};
TLD_convert_json(handle, app_ids, sizeof(app_ids));
- EXPECT_STREQ("{\"common_app_full_path\":\"http\",\"common_app_label\":\"http\",\"common_app_id\":{\"LPI_L7\":[{\"app_name\":\"http\",\"app_id\":67,\"surrogate_id\":0,\"packet_sequence\":0}]}}", app_ids);
+ EXPECT_STREQ("{\"common_app_full_path\":\"http\",\"common_app_label\":\"http\",\"common_app_id\":{\"LPI_L7\":[{\"app_name\":\"http\",\"app_id\":67,\"surrogate_id\":0,\"packet_sequence\":1}]}}", app_ids);
-
+ dictator_free(0, gather_result_out);
session_gather_app_results_async(&a_stream, NULL);
- gather_result=(struct gather_app_result *)session_gather_app_results_get(&a_stream);
- EXPECT_EQ(nullptr, gather_result);
+ EXPECT_EQ(nullptr, session_gather_app_results_get(&a_stream));
}
TEST(TSGMaster, SetAPPIDUnknown)
@@ -989,11 +990,11 @@ TEST(TSGMaster, SessionDealStatePending)
struct gather_app_result *gather_result=(struct gather_app_result *)session_gather_app_results_get(&a_stream);
EXPECT_NE(nullptr, gather_result);
- EXPECT_EQ(1, gather_result[ORIGIN_BASIC_PROTOCOL].app_num);
- EXPECT_EQ(45, gather_result[ORIGIN_BASIC_PROTOCOL].attributes[0].app_id);
- EXPECT_EQ(0, gather_result[ORIGIN_BASIC_PROTOCOL].attributes[0].surrogate_id);
+ EXPECT_EQ(1, gather_result->l7_protocol_num);
+ EXPECT_EQ(45, gather_result->l7_protocol[0].app_id);
+ EXPECT_EQ(0, gather_result->l7_protocol[0].surrogate_id);
- free(gather_result);
+ dictator_free(0, gather_result);
session_gather_app_results_async(&a_stream, NULL);
EXPECT_EQ(nullptr, session_gather_app_results_get(&a_stream));