✨ feat(packet_io): add gtest_packet_io
This commit is contained in:
@@ -5,6 +5,8 @@ include_directories(${CMAKE_SOURCE_DIR}/src/packet_io/)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/src/session_manager/)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/src/plugin_manager/)
|
||||
|
||||
|
||||
enable_testing()
|
||||
add_subdirectory(packet_io)
|
||||
add_subdirectory(session_manager)
|
||||
add_subdirectory(plugin_manager)
|
||||
|
||||
14
src/main.cpp
14
src/main.cpp
@@ -5,7 +5,7 @@
|
||||
|
||||
struct packet_io_loop_arg
|
||||
{
|
||||
struct device *dev;
|
||||
struct packet_io_device *dev;
|
||||
int thread_id;
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@ void packet_io_loop(struct packet_io_loop_arg *arg)
|
||||
struct session_event *event;
|
||||
while(1)
|
||||
{
|
||||
int fetch_num = packetio_rx(arg->dev, arg->thread_id, &rx_pkt, 1);
|
||||
int fetch_num = packet_io_rx(arg->dev, arg->thread_id, &rx_pkt, 1);
|
||||
if(fetch_num > 0)
|
||||
{
|
||||
event = session_manager_commit(rx_pkt);
|
||||
@@ -26,7 +26,7 @@ void packet_io_loop(struct packet_io_loop_arg *arg)
|
||||
}
|
||||
|
||||
//clean session_manager event queue
|
||||
packetio_tx(arg->dev, arg->thread_id, &rx_pkt, 1);
|
||||
packet_io_tx(arg->dev, arg->thread_id, &rx_pkt, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -39,10 +39,10 @@ void packet_io_loop(struct packet_io_loop_arg *arg)
|
||||
}
|
||||
|
||||
|
||||
struct device *packetio_init(int worker_thread_num, const char *instance_name, const char *device_name)
|
||||
struct packet_io_device *packet_io_init(int worker_thread_num, const char *instance_name, const char *device_name)
|
||||
{
|
||||
struct packetio_instance * instance = packetio_create(instance_name);
|
||||
struct device *dev = packetio_open_device(instance, device_name, worker_thread_num, worker_thread_num);
|
||||
struct packet_io_instance * instance = packet_io_create(PACKET_IO_PCAP, instance_name);
|
||||
struct packet_io_device *dev = packet_io_open_device(instance, device_name, worker_thread_num, worker_thread_num);
|
||||
return dev;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ int main(int argc, char ** argv)
|
||||
//config_manager_init
|
||||
|
||||
session_manager_session_event_register(http_decoder, SESSION_TYPE_HTTP);
|
||||
//packetio_init
|
||||
//packet_io_init
|
||||
|
||||
//create_worker_thread
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
|
||||
add_library(packet_io
|
||||
packet_io.cpp
|
||||
)
|
||||
)
|
||||
|
||||
add_subdirectory(test)
|
||||
@@ -1,37 +1,37 @@
|
||||
#include "packet_io.h"
|
||||
|
||||
struct packetio_instance *packetio_create(const char *instance_name)
|
||||
struct packet_io_instance *packet_io_create(packe_io_mode mode, const char *instance_name)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
struct packetio_instance *packetio_current()
|
||||
struct packet_io_instance *packet_io_current()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void packetio_destory(struct packetio_instance *instance)
|
||||
void packet_io_destory(struct packet_io_instance *instance)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
struct device *packetio_open_device(struct packetio_instance *instance, const char *dev_sym, uint32_t nr_rxqueue, uint32_t nr_txqueue)
|
||||
struct packet_io_device *packet_io_open_device(struct packet_io_instance *instance, const char *dev_sym, uint32_t nr_rxqueue, uint32_t nr_txqueue)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void packetio_close_device(struct device *dev)
|
||||
void packet_io_close_device(struct packet_io_device *dev)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int packetio_rx(struct device *dev, uint32_t rx_queue_id, struct packet *p[], int nr_p)
|
||||
int packet_io_rx(struct packet_io_device *dev, uint32_t rx_queue_id, struct packet *p[], int nr_p)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int packetio_tx(struct device *dev, uint32_t rx_queue_id, struct packet *p[], int nr_p)
|
||||
int packet_io_tx(struct packet_io_device *dev, uint32_t rx_queue_id, struct packet *p[], int nr_p)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -3,16 +3,21 @@
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
struct packetio_instance;
|
||||
struct device;
|
||||
struct packet_io_instance;
|
||||
struct packet_io_device;
|
||||
|
||||
struct packetio_instance *packetio_create(const char *instance_name);
|
||||
struct packetio_instance *packetio_current();
|
||||
void packetio_destory(struct packetio_instance *instance);
|
||||
enum packe_io_mode
|
||||
{
|
||||
PACKET_IO_PCAP,
|
||||
PACKET_IO_MARSIO,
|
||||
};
|
||||
|
||||
struct packet_io_instance *packet_io_create(packe_io_mode mode, const char *instance_name);
|
||||
struct packet_io_instance *packet_io_current();
|
||||
void packet_io_destory(struct packet_io_instance *instance);
|
||||
|
||||
struct device *packetio_open_device(struct packetio_instance *instance, const char *dev_sym, uint32_t nr_rxqueue, uint32_t nr_txqueue);
|
||||
void packetio_close_device(struct device *dev);
|
||||
struct packet_io_device *packet_io_open_device(struct packet_io_instance *instance, const char *dev_sym, uint32_t nr_rxqueue, uint32_t nr_txqueue);
|
||||
void packet_io_close_device(struct packet_io_device *dev);
|
||||
|
||||
int packetio_rx(struct device *dev, uint32_t rx_queue_id, struct packet *p[], int nr_p);
|
||||
int packetio_tx(struct device *dev, uint32_t rx_queue_id, struct packet *p[], int nr_p);
|
||||
int packet_io_rx(struct packet_io_device *dev, uint32_t rx_queue_id, struct packet *p[], int nr_p);
|
||||
int packet_io_tx(struct packet_io_device *dev, uint32_t rx_queue_id, struct packet *p[], int nr_p);
|
||||
12
src/packet_io/test/CMakeLists.txt
Normal file
12
src/packet_io/test/CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
add_executable(gtest_packet_io
|
||||
gtest_packet_io.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
gtest_packet_io
|
||||
gtest_main
|
||||
packet_io
|
||||
)
|
||||
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(gtest_packet_io)
|
||||
15
src/packet_io/test/gtest_packet_io.cpp
Normal file
15
src/packet_io/test/gtest_packet_io.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "packet_io.h"
|
||||
|
||||
TEST(PACKET_IO_Test, packet_io_create) {
|
||||
EXPECT_EQ(packet_io_create(PACKET_IO_PCAP, "TEST"), nullptr);
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
int ret=0;
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
ret=RUN_ALL_TESTS();
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user