gtest_inject_tcp_rst creates a working directory under the current path
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
struct dumpfile_io
|
||||
{
|
||||
uint16_t nr_threads;
|
||||
char work_dir[256];
|
||||
char directory[256];
|
||||
|
||||
pcap_t *pcap;
|
||||
@@ -68,7 +69,7 @@ struct pcap_file_hdr DEFAULT_PCAP_FILE_HDR =
|
||||
* Private API
|
||||
******************************************************************************/
|
||||
|
||||
static void save_packet(struct packet *pkt, uint64_t idx)
|
||||
static void save_packet(const char *work_dir, struct packet *pkt, uint64_t idx)
|
||||
{
|
||||
int len = 0;
|
||||
FILE *fp = NULL;
|
||||
@@ -94,7 +95,7 @@ static void save_packet(struct packet *pkt, uint64_t idx)
|
||||
inet_ntop(AF_INET6, &tuple.src_addr.v6, src_addr, INET6_ADDRSTRLEN);
|
||||
inet_ntop(AF_INET6, &tuple.dst_addr.v6, dst_addr, INET6_ADDRSTRLEN);
|
||||
}
|
||||
snprintf(file, sizeof(file), "/tmp/inject-%s:%u-%s:%u-%lu.pcap", src_addr, ntohs(tuple.src_port), dst_addr, ntohs(tuple.dst_port), idx);
|
||||
snprintf(file, sizeof(file), "%s/inject-%s:%u-%s:%u-%lu.pcap", work_dir, src_addr, ntohs(tuple.src_port), dst_addr, ntohs(tuple.dst_port), idx);
|
||||
|
||||
fp = fopen(file, "w+");
|
||||
if (fp)
|
||||
@@ -297,6 +298,11 @@ struct dumpfile_io *dumpfile_io_new(const char *directory, uint16_t nr_threads)
|
||||
PACKET_IO_LOG_ERROR("unable to allocate memory for dumpfile_io");
|
||||
return NULL;
|
||||
}
|
||||
if (getcwd(handle->work_dir, sizeof(handle->work_dir)) == NULL)
|
||||
{
|
||||
PACKET_IO_LOG_ERROR("unable to get current work directory");
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
handle->nr_threads = nr_threads;
|
||||
strncpy(handle->directory, directory, MIN(strlen(directory), sizeof(handle->directory)));
|
||||
@@ -468,7 +474,7 @@ int dumpfile_io_inject(struct dumpfile_io *handle, uint16_t thr_idx, struct pack
|
||||
stat->dev_tx_pkts++;
|
||||
stat->dev_tx_bytes += len;
|
||||
|
||||
save_packet(pkt, stat->inject_pkts);
|
||||
save_packet(handle->work_dir, pkt, stat->inject_pkts);
|
||||
|
||||
packet_free(pkt);
|
||||
}
|
||||
|
||||
@@ -2,18 +2,24 @@
|
||||
|
||||
#include "packet_injector_test_frame.h"
|
||||
|
||||
static char current_dir[1024] = {0};
|
||||
|
||||
#if 1
|
||||
TEST(INJECT_IPV4_BASED_TCP_RST, AFTER_RECV_SYN_ACK)
|
||||
{
|
||||
char work_dir[2048] = {0};
|
||||
char input_dir[2048] = {0};
|
||||
snprintf(work_dir, sizeof(work_dir), "%s/%s", current_dir, "inject_ipv4_based_tcp_rst_after_recv_syn_ack");
|
||||
snprintf(input_dir, sizeof(input_dir), "%s/%s", current_dir, "pcap/inject_ipv4_based_tcp_rst_after_recv_syn_ack/test/");
|
||||
|
||||
struct packet_injector_case test = {
|
||||
// descriptor
|
||||
.finish_clean_work_dir = 1,
|
||||
.finish_clean_work_dir = 0,
|
||||
.descriptor = "Inject IPv4 based TCP RST after receiving SYN-ACK packet.",
|
||||
.work_dir = "/tmp/inject_ipv4_based_tcp_rst_after_recv_syn_ack/", // user defined work directory
|
||||
.work_dir = work_dir,
|
||||
|
||||
// prefix
|
||||
.input_prefix = "pcap/inject_ipv4_based_tcp_rst_after_recv_syn_ack/test/",
|
||||
.output_prefix = "/tmp/",
|
||||
.input_prefix = input_dir,
|
||||
|
||||
// input pcap
|
||||
.input_pcap = "input.pcap",
|
||||
@@ -37,15 +43,19 @@ TEST(INJECT_IPV4_BASED_TCP_RST, AFTER_RECV_SYN_ACK)
|
||||
#if 1
|
||||
TEST(INJECT_IPV4_BASED_TCP_RST, AFTER_RECV_SUB_ACK)
|
||||
{
|
||||
char work_dir[2048] = {0};
|
||||
char input_dir[2048] = {0};
|
||||
snprintf(work_dir, sizeof(work_dir), "%s/%s", current_dir, "inject_ipv4_based_tcp_rst_after_recv_sub_ack");
|
||||
snprintf(input_dir, sizeof(input_dir), "%s/%s", current_dir, "pcap/inject_ipv4_based_tcp_rst_after_recv_sub_ack/test/");
|
||||
|
||||
struct packet_injector_case test = {
|
||||
// descriptor
|
||||
.finish_clean_work_dir = 1,
|
||||
.finish_clean_work_dir = 0,
|
||||
.descriptor = "Inject IPv4 based TCP RST after receiving SUB-ACK packet.",
|
||||
.work_dir = "/tmp/inject_ipv4_based_tcp_rst_after_recv_sub_ack/", // user defined work directory
|
||||
.work_dir = work_dir,
|
||||
|
||||
// prefix
|
||||
.input_prefix = "pcap/inject_ipv4_based_tcp_rst_after_recv_sub_ack/test/",
|
||||
.output_prefix = "/tmp/",
|
||||
.input_prefix = input_dir,
|
||||
|
||||
// input pcap
|
||||
.input_pcap = "input.pcap",
|
||||
@@ -69,15 +79,19 @@ TEST(INJECT_IPV4_BASED_TCP_RST, AFTER_RECV_SUB_ACK)
|
||||
#if 1
|
||||
TEST(INJECT_IPV4_BASED_TCP_RST, AFTER_RECV_C2S_FIRST_PAYLOAD)
|
||||
{
|
||||
char work_dir[2048] = {0};
|
||||
char input_dir[2048] = {0};
|
||||
snprintf(work_dir, sizeof(work_dir), "%s/%s", current_dir, "inject_ipv4_based_tcp_rst_after_recv_c2s_first_payload");
|
||||
snprintf(input_dir, sizeof(input_dir), "%s/%s", current_dir, "pcap/inject_ipv4_based_tcp_rst_after_recv_c2s_first_payload/test/");
|
||||
|
||||
struct packet_injector_case test = {
|
||||
// descriptor
|
||||
.finish_clean_work_dir = 1,
|
||||
.finish_clean_work_dir = 0,
|
||||
.descriptor = "Inject IPv4 based TCP RST after receiving C2S first payload packet.",
|
||||
.work_dir = "/tmp/inject_ipv4_based_tcp_rst_after_recv_c2s_first_payload/", // user defined work directory
|
||||
.work_dir = work_dir,
|
||||
|
||||
// prefix
|
||||
.input_prefix = "pcap/inject_ipv4_based_tcp_rst_after_recv_c2s_first_payload/test/",
|
||||
.output_prefix = "/tmp/",
|
||||
.input_prefix = input_dir,
|
||||
|
||||
// input pcap
|
||||
.input_pcap = "input.pcap",
|
||||
@@ -101,15 +115,19 @@ TEST(INJECT_IPV4_BASED_TCP_RST, AFTER_RECV_C2S_FIRST_PAYLOAD)
|
||||
#if 1
|
||||
TEST(INJECT_IPV4_BASED_TCP_RST, AFTER_RECV_S2C_FIRST_PAYLOAD)
|
||||
{
|
||||
char work_dir[2048] = {0};
|
||||
char input_dir[2048] = {0};
|
||||
snprintf(work_dir, sizeof(work_dir), "%s/%s", current_dir, "inject_ipv4_based_tcp_rst_after_recv_s2c_first_payload");
|
||||
snprintf(input_dir, sizeof(input_dir), "%s/%s", current_dir, "pcap/inject_ipv4_based_tcp_rst_after_recv_s2c_first_payload/test/");
|
||||
|
||||
struct packet_injector_case test = {
|
||||
// descriptor
|
||||
.finish_clean_work_dir = 1,
|
||||
.finish_clean_work_dir = 0,
|
||||
.descriptor = "Inject IPv4 based TCP RST after receiving S2C first payload packet.",
|
||||
.work_dir = "/tmp/inject_ipv4_based_tcp_rst_after_recv_s2c_first_payload/", // user defined work directory
|
||||
.work_dir = work_dir,
|
||||
|
||||
// prefix
|
||||
.input_prefix = "pcap/inject_ipv4_based_tcp_rst_after_recv_s2c_first_payload/test/",
|
||||
.output_prefix = "/tmp/",
|
||||
.input_prefix = input_dir,
|
||||
|
||||
// input pcap
|
||||
.input_pcap = "input.pcap",
|
||||
@@ -132,6 +150,7 @@ TEST(INJECT_IPV4_BASED_TCP_RST, AFTER_RECV_S2C_FIRST_PAYLOAD)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
getcwd(current_dir, sizeof(current_dir));
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ void packet_injector_test_frame_run(struct packet_injector_case *test)
|
||||
// compare pcap
|
||||
if (test->c2s_output_pcap && test->c2s_expect_pcap)
|
||||
{
|
||||
system_cmd("mv %s/%s %s", test->output_prefix, test->c2s_output_pcap, output_dir_abs_path);
|
||||
system_cmd("mv %s/%s %s", test->work_dir, test->c2s_output_pcap, output_dir_abs_path);
|
||||
expect_cmp_inject(test->work_dir,
|
||||
expect_dir_abs_path, test->c2s_expect_pcap,
|
||||
output_dir_abs_path, test->c2s_output_pcap,
|
||||
@@ -189,7 +189,7 @@ void packet_injector_test_frame_run(struct packet_injector_case *test)
|
||||
}
|
||||
if (test->s2c_output_pcap && test->s2c_expect_pcap)
|
||||
{
|
||||
system_cmd("mv %s/%s %s", test->output_prefix, test->s2c_output_pcap, output_dir_abs_path);
|
||||
system_cmd("mv %s/%s %s", test->work_dir, test->s2c_output_pcap, output_dir_abs_path);
|
||||
expect_cmp_inject(test->work_dir,
|
||||
expect_dir_abs_path, test->s2c_expect_pcap,
|
||||
output_dir_abs_path, test->s2c_output_pcap,
|
||||
|
||||
@@ -15,7 +15,6 @@ struct packet_injector_case
|
||||
|
||||
// prefix
|
||||
const char *input_prefix;
|
||||
const char *output_prefix;
|
||||
|
||||
// input pcap
|
||||
const char *input_pcap;
|
||||
|
||||
Reference in New Issue
Block a user