summaryrefslogtreecommitdiff
path: root/module_test/src/gtest_sapp_app_state.cpp
blob: 34eb400c082fed8216a0736a31e874251850274b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <assert.h>
#include <time.h>
#include <arpa/inet.h>
#include "stream.h"
#include <sys/types.h>			/* See NOTES */
#include <sys/socket.h>
#include <sys/un.h>
#include <errno.h>
#include "gtest_sapp_fun.h"
#include <gtest/gtest.h>

/*
	测试插件kill_other和kill_follow返回值功能:
	按挂载顺序分为三种:
		master挂载到第一位, 中间位置和最后一位;
	按流状态分为两种:
		master在pending状态返回kill_other或kill_follow;
		master在data状态返回kill_other或kill_follow;

	以上情况总计12种测试用例, 命名规范: kill---[插件返回值]---[master相对位置]---[在opstate哪个状态执行]
		kill_follow_head_pending,
		kill_follow_head_data,
		kill_follow_middle_pending,
		kill_follow_middle_data,
		kill_follow_tail_pending,
		kill_follow_tail_data.

		kill_other_head_pending,
		kill_other_head_data,
		kill_other_middle_pending,
		kill_other_middle_data,
		kill_other_tail_pending,
		kill_other_tail_data.		
*/


/* 公共的初始化函数 */
static void app_state_common_init(void)
{
	set_default_config();

	/* 创建插件目录 */
	system("mkdir -p ./plug/business/gtest_sapp_appstate_1");
	system("mkdir -p ./plug/business/gtest_sapp_appstate_2");

	append_project_list_conf("app_state_project", "struct");

	update_plugin_inf_with_options("./plug/business/gtest_sapp_appstate_1", "gtest1", "tcp_app_state_plug1_init", NULL, "TCP", "tcp_app_state_plug1");
	update_plugin_inf_with_options("./plug/business/gtest_sapp_appstate_2", "gtest2", "tcp_app_state_plug2_init", NULL, "TCP", "tcp_app_state_plug2");

	set_pcap_dumpfile("tcp/tcp_simple.pcap");

	ASSERT_EQ(file_md5_checksum("dumpfile", "df138740a6a22ca9c977052f21f7a470"),0);

	system("> /tmp/app_state_plug_init_file"); /* 清空插件初始化计数文件 */
	system("cp -f ./plug/business/gtest_sapp/libgtest_sapp.so ./plug/business/gtest_sapp_appstate_1/");
	system("cp -f ./plug/business/gtest_sapp/libgtest_sapp.so ./plug/business/gtest_sapp_appstate_2/");
}


/*
	插件挂载顺序:
		master
		plug1
		plug2
*/
void app_state_kill_follow_head_pending_run(void)
{
	app_state_common_init();
  
	/* 更新插件conflist, 第一次使用update, 后续使用append */
	update_conflist_inf("./plug/business/gtest_sapp/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp_appstate_1/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp_appstate_2/gtest_sapp.inf"); 

	/* 更新gtest.inf */
	update_plugin_inf_with_options("./plug/business/gtest_sapp", "gtest", "tcp_app_state_master_init", "tcp_app_state_master_destroy", "TCP", "as_kill_follow_head_pending");

	call_libsapp_devel_for_dumpfile_topspeed();
}

void app_state_kill_follow_head_pending_dropme_run(void)
{
	app_state_common_init();
  
	/* 更新插件conflist, 第一次使用update, 后续使用append */
	update_conflist_inf("./plug/business/gtest_sapp/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp_appstate_1/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp_appstate_2/gtest_sapp.inf"); 

	/* 更新gtest.inf */
	update_plugin_inf_with_options("./plug/business/gtest_sapp", "gtest", "tcp_app_state_master_init", "tcp_app_state_master_destroy", "TCP", "as_kill_follow_head_pending_dropme");

	call_libsapp_devel_for_dumpfile_topspeed();
}


/*
	插件挂载顺序:
		plug1
		master
		plug2
*/
void app_state_kill_follow_middle_pending_run(void)
{
	app_state_common_init();
  
  	system("echo ./plug/business/gtest_sapp_appstate_1/gtest_sapp.inf 1 > ./etc/necessary_plug_list.conf");

	/* 更新插件conflist, 第一次使用update, 后续使用append */
	update_conflist_inf("./plug/business/gtest_sapp_appstate_1/gtest_sapp.inf");
	append_conflist_inf("./plug/business/gtest_sapp/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp_appstate_2/gtest_sapp.inf"); 

	/* 更新gtest.inf */
	update_plugin_inf_with_options("./plug/business/gtest_sapp", "gtest", "tcp_app_state_master_init", NULL, "TCP", "as_kill_follow_middle_pending");

	call_libsapp_devel_for_dumpfile_topspeed();
}

/*
	插件挂载顺序:
		plug1
		plug2
		master
*/
void app_state_kill_follow_tail_pending_run(void)
{
	app_state_common_init();
  
  	system("echo ./plug/business/gtest_sapp_appstate_1/gtest_sapp.inf 1 > ./etc/necessary_plug_list.conf");
  	system("echo ./plug/business/gtest_sapp_appstate_2/gtest_sapp.inf 1 >> ./etc/necessary_plug_list.conf");
	/* 更新插件conflist, 第一次使用update, 后续使用append */
	update_conflist_inf("./plug/business/gtest_sapp_appstate_1/gtest_sapp.inf");
	append_conflist_inf("./plug/business/gtest_sapp_appstate_2/gtest_sapp.inf");
	append_conflist_inf("./plug/business/gtest_sapp/gtest_sapp.inf"); 

	/* 更新gtest.inf */
	update_plugin_inf_with_options("./plug/business/gtest_sapp", "gtest", "tcp_app_state_master_init", NULL, "TCP", "as_kill_follow_tail_pending");

	call_libsapp_devel_for_dumpfile_topspeed();
}

void app_state_kill_follow_head_data_run(void)
{
	app_state_common_init();
  
	/* 更新插件conflist, 第一次使用update, 后续使用append */
	update_conflist_inf("./plug/business/gtest_sapp/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp_appstate_1/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp_appstate_2/gtest_sapp.inf"); 

	/* 更新gtest.inf */
	update_plugin_inf_with_options("./plug/business/gtest_sapp", "gtest", "tcp_app_state_master_init", NULL, "TCP", "as_kill_follow_head_data");

	call_libsapp_devel_for_dumpfile_topspeed();
}

void app_state_kill_follow_head_data_dropme_run(void)
{
	app_state_common_init();
  
	/* 更新插件conflist, 第一次使用update, 后续使用append */
	update_conflist_inf("./plug/business/gtest_sapp/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp_appstate_1/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp_appstate_2/gtest_sapp.inf"); 

	/* 更新gtest.inf */
	update_plugin_inf_with_options("./plug/business/gtest_sapp", "gtest", "tcp_app_state_master_init", "tcp_app_state_master_destroy", "TCP", "as_kill_follow_head_data_dropme");

	call_libsapp_devel_for_dumpfile_topspeed();
}


void app_state_kill_follow_middle_data_run(void)
{
	app_state_common_init();
  
  	system("echo ./plug/business/gtest_sapp_appstate_1/gtest_sapp.inf 1 > ./etc/necessary_plug_list.conf");

	/* 更新插件conflist, 第一次使用update, 后续使用append */
	update_conflist_inf("./plug/business/gtest_sapp_appstate_1/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp_appstate_2/gtest_sapp.inf"); 

	/* 更新gtest.inf */
	update_plugin_inf_with_options("./plug/business/gtest_sapp", "gtest", "tcp_app_state_master_init", NULL, "TCP", "as_kill_follow_middle_data");

	call_libsapp_devel_for_dumpfile_topspeed();
}


void app_state_kill_follow_tail_data_run(void)
{
	app_state_common_init();
  
  	system("echo ./plug/business/gtest_sapp_appstate_1/gtest_sapp.inf 1 > ./etc/necessary_plug_list.conf");
  	system("echo ./plug/business/gtest_sapp_appstate_2/gtest_sapp.inf 1 >> ./etc/necessary_plug_list.conf");
	/* 更新插件conflist, 第一次使用update, 后续使用append */
	update_conflist_inf("./plug/business/gtest_sapp_appstate_1/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp_appstate_2/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp/gtest_sapp.inf"); 

	/* 更新gtest.inf */
	update_plugin_inf_with_options("./plug/business/gtest_sapp", "gtest", "tcp_app_state_master_init", NULL, "TCP", "as_kill_follow_tail_data");

	call_libsapp_devel_for_dumpfile_topspeed();
}

void app_state_kill_other_head_pending_run(void)
{
	app_state_common_init();
  
	/* 更新插件conflist, 第一次使用update, 后续使用append */
	update_conflist_inf("./plug/business/gtest_sapp/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp_appstate_1/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp_appstate_2/gtest_sapp.inf"); 

	/* 更新gtest.inf */
	update_plugin_inf_with_options("./plug/business/gtest_sapp", "gtest", "tcp_app_state_master_init", NULL, "TCP", "as_kill_other_head_pending");

	call_libsapp_devel_for_dumpfile_topspeed();
}

void app_state_kill_other_middle_pending_run(void)
{
	app_state_common_init();
  
	/* 更新插件conflist, 第一次使用update, 后续使用append */
	update_conflist_inf("./plug/business/gtest_sapp_appstate_1/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp_appstate_2/gtest_sapp.inf"); 

	/* 更新gtest.inf */
	update_plugin_inf_with_options("./plug/business/gtest_sapp", "gtest", "tcp_app_state_master_init", NULL, "TCP", "as_kill_other_middle_pending");

	call_libsapp_devel_for_dumpfile_topspeed();
}

void app_state_kill_other_tail_pending_run(void)
{
	app_state_common_init();
  
	/* 更新插件conflist, 第一次使用update, 后续使用append */
	update_conflist_inf("./plug/business/gtest_sapp_appstate_1/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp_appstate_2/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp/gtest_sapp.inf"); 

	/* 更新gtest.inf */
	update_plugin_inf_with_options("./plug/business/gtest_sapp", "gtest", "tcp_app_state_master_init", NULL, "TCP", "as_kill_other_tail_pending");

	call_libsapp_devel_for_dumpfile_topspeed();
}

void app_state_kill_other_tail_pending_dropme_run(void)
{
	app_state_common_init();
  
	/* 更新插件conflist, 第一次使用update, 后续使用append */
	update_conflist_inf("./plug/business/gtest_sapp_appstate_1/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp_appstate_2/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp/gtest_sapp.inf"); 

	/* 更新gtest.inf */
	update_plugin_inf_with_options("./plug/business/gtest_sapp", "gtest", "tcp_app_state_master_init", "tcp_app_state_master_destroy", "TCP", "as_kill_other_tail_pending_dropme");

	call_libsapp_devel_for_dumpfile_topspeed();
}


void app_state_kill_other_head_data_run(void)
{
	app_state_common_init();
  
	/* 更新插件conflist, 第一次使用update, 后续使用append */
	update_conflist_inf("./plug/business/gtest_sapp/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp_appstate_1/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp_appstate_2/gtest_sapp.inf"); 

	/* 更新gtest.inf */
	update_plugin_inf_with_options("./plug/business/gtest_sapp", "gtest", "tcp_app_state_master_init", NULL, "TCP", "as_kill_other_head_data");

	call_libsapp_devel_for_dumpfile_topspeed();
}

void app_state_kill_other_middle_data_run(void)
{
	app_state_common_init();
  
	/* 更新插件conflist, 第一次使用update, 后续使用append */
	update_conflist_inf("./plug/business/gtest_sapp_appstate_1/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp_appstate_2/gtest_sapp.inf"); 

	/* 更新gtest.inf */
	update_plugin_inf_with_options("./plug/business/gtest_sapp", "gtest", "tcp_app_state_master_init", NULL, "TCP", "as_kill_other_middle_data");

	call_libsapp_devel_for_dumpfile_topspeed();
}

void app_state_kill_other_tail_data_run(void)
{
	app_state_common_init();
  
	/* 更新插件conflist, 第一次使用update, 后续使用append */
	update_conflist_inf("./plug/business/gtest_sapp_appstate_1/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp_appstate_2/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp/gtest_sapp.inf"); 

	/* 更新gtest.inf */
	update_plugin_inf_with_options("./plug/business/gtest_sapp", "gtest", "tcp_app_state_master_init", NULL, "TCP", "as_kill_other_tail_data");

	call_libsapp_devel_for_dumpfile_topspeed();
}


void app_state_kill_follow_ip_entry_run(void)
{
	app_state_common_init();
  
	/* 更新插件conflist, 第一次使用update, 后续使用append */
	update_conflist_inf("./plug/business/gtest_sapp/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp_appstate_1/gtest_sapp.inf"); 
	append_conflist_inf("./plug/business/gtest_sapp_appstate_2/gtest_sapp.inf"); 
	
	/* 更新gtest.inf */
	update_plugin_inf_with_options("./plug/business/gtest_sapp", "gtest", "tcp_app_state_master_init", NULL, "IP", "as_ip_plug_master");
	update_plugin_inf_with_options("./plug/business/gtest_sapp_appstate_1", "gtest1", "tcp_app_state_plug1_init", NULL, "IP", "as_ip_plug_1");
	update_plugin_inf_with_options("./plug/business/gtest_sapp_appstate_2", "gtest2", "tcp_app_state_plug2_init", NULL, "IP", "as_ip_plug_2");

	call_libsapp_devel_for_dumpfile_topspeed();
}