添加依赖库googletest.

This commit is contained in:
lijia
2021-10-26 22:05:15 +08:00
parent daef36bc33
commit 5bcadbe078
7 changed files with 85 additions and 21 deletions

16
test/CMakeLists.txt Normal file
View File

@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 2.8)
include_directories(${CMAKE_SOURCE_DIR}/inc)
include_directories(${MESA_SDK_PREFIX}/include)
include_directories(${MESA_SDK_PREFIX}/include/MESA)
add_definitions(-D_BSD_SOURCE -D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H)
add_definitions(-fPIC -std=c++11)
LINK_DIRECTORIES(/opt/MESA/lib)
LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/src)
add_executable(gtest_jump_layer gtest_jump_layer.cpp)
target_link_libraries(gtest_jump_layer pcap gtest-static MESA_jump_layer)

View File

@@ -56,11 +56,11 @@ static int jump_check_ipv4_pkt(const struct ip *ip4hdr, int expect_tot_len, unsi
return -1;
}
if(ip4hdr->ip_hl*4 < 20){
printf("\033[1;31;40mMESA_net_jump_to_layer(): ipv4 header check header length error!\033[0m\n");
printf("\033[1;31;40mMESA_net_jump_to_layer(): ipv4 header check header length error, iphdr less than 20Byte!\033[0m\n");
return -1;
}
if(ntohs(ip4hdr->ip_len) != expect_tot_len){
printf("\033[1;31;40mMESA_net_jump_to_layer(): ipv4 header check length error!\033[0m\n");
printf("\033[1;31;40mMESA_net_jump_to_layer(): ipv4 header check length error, ip len is:%d, but expect:%d!\033[0m\n", ntohs(ip4hdr->ip_len), expect_tot_len);
return -1;
}
@@ -205,7 +205,6 @@ static int jmp_file_md5_checksum(const char *filename, const char *expect_md5sum
static void jump_layer_eth_ipv4_tcp(u_char *result_val, const struct pcap_pkthdr *hdr, const u_char *data)
{
int ret;
int tot_pkt_len;
const void *eth_header, *ipv4_header, *tcp_header;
const void *next_header;
@@ -219,7 +218,7 @@ static void jump_layer_eth_ipv4_tcp(u_char *result_val, const struct pcap_pkthdr
}
const struct ip* ip4hdr = (struct ip*)ipv4_header;
jump_check_ipv4_pkt(ip4hdr, tot_pkt_len-sizeof(struct ethhdr), IPPROTO_TCP, "192.168.10.250", "192.168.10.234");
jump_check_ipv4_pkt(ip4hdr, 60, IPPROTO_TCP, "192.168.10.250", "192.168.10.234");
tcp_header = MESA_net_jump_to_layer((void *)ipv4_header, ADDR_TYPE_IPV4, ADDR_TYPE_TCP);
if(NULL == tcp_header){
@@ -254,7 +253,8 @@ static void jump_layer_eth_ipv4_tcp(u_char *result_val, const struct pcap_pkthdr
TEST(jump_layer, eth_ipv4_tcp)
{
int fun_ret, chk_res = -1;
int fun_ret;
u_char chk_res = -1;
fun_ret = jmp_file_md5_checksum("./sample_pcap/tcp_simple.pcap", "eb4b176720c698e86c1acbacf2f30ede");
ASSERT_EQ(fun_ret, 0);