添加依赖库googletest.
This commit is contained in:
@@ -7,6 +7,22 @@ variables:
|
||||
|
||||
stages:
|
||||
- build
|
||||
- test
|
||||
|
||||
|
||||
google_test:
|
||||
stage: test
|
||||
script:
|
||||
- yum makecache
|
||||
- pwd
|
||||
- ls -l /opt/MESA/lib
|
||||
- echo "/opt/MESA/lib" >> /etc/ld.so.conf
|
||||
- ldconfig
|
||||
- cd /home/mesasoft/sapp_run
|
||||
- ulimit -c 0
|
||||
- ./gtest_jump_layer
|
||||
tags:
|
||||
- share
|
||||
|
||||
.build_by_travis:
|
||||
before_script:
|
||||
|
||||
@@ -34,23 +34,11 @@ elseif(ASAN_OPTION MATCHES "THREAD")
|
||||
endif()
|
||||
# end of for ASAN
|
||||
|
||||
include_directories(${PROJECT_SOURCE_DIR}/include/)
|
||||
add_subdirectory(./vendor)
|
||||
add_subdirectory(./src)
|
||||
add_subdirectory(./test)
|
||||
|
||||
file(GLOB SRC
|
||||
"src/*.c"
|
||||
"src/*.cpp"
|
||||
)
|
||||
|
||||
# Shared Library Output
|
||||
add_library(${lib_name}_shared SHARED ${SRC})
|
||||
target_link_libraries(${lib_name}_shared m)
|
||||
if(DEFINED MESA_SHARED_INSTALL_DIR)
|
||||
set_target_properties(${lib_name}_shared PROPERTIES OUTPUT_NAME ${lib_name} LIBRARY_OUTPUT_DIRECTORY ${MESA_SHARED_INSTALL_DIR})
|
||||
else()
|
||||
set_target_properties(${lib_name}_shared PROPERTIES OUTPUT_NAME ${lib_name})
|
||||
endif()
|
||||
|
||||
install(TARGETS ${lib_name}_shared LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib COMPONENT LIBRARY)
|
||||
install(TARGETS ${lib_name} LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib COMPONENT LIBRARY)
|
||||
install(FILES inc/MESA_jump_layer.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/MESA COMPONENT HEADER)
|
||||
|
||||
include(Package)
|
||||
|
||||
23
src/CMakeLists.txt
Normal file
23
src/CMakeLists.txt
Normal file
@@ -0,0 +1,23 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
set(MESA_SDK_PREFIX "/opt/MESA" CACHE STRING "MESA Framework Prefix")
|
||||
|
||||
include_directories(${MESA_SDK_PREFIX}/include)
|
||||
include_directories(${MESA_SDK_PREFIX}/include/MESA)
|
||||
include_directories(${MESA_SDK_PREFIX}/include/MESA/include)
|
||||
include_directories(${MESA_SDK_PREFIX}/include/MESA/stream_inc)
|
||||
|
||||
include_directories(${PROJECT_SOURCE_DIR}/include/)
|
||||
|
||||
LINK_DIRECTORIES(/opt/MESA/lib)
|
||||
|
||||
add_definitions(-D_BSD_SOURCE -D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H)
|
||||
add_definitions(-DSAPP_V4=1)
|
||||
|
||||
add_definitions(-fPIC)
|
||||
add_definitions(-std=c++11)
|
||||
|
||||
add_library(${lib_name} SHARED MESA_jump_layer.cpp)
|
||||
target_link_libraries(${lib_name} m)
|
||||
|
||||
|
||||
16
test/CMakeLists.txt
Normal file
16
test/CMakeLists.txt
Normal 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)
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
21
vendor/CMakeLists.txt
vendored
Normal file
21
vendor/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
# CMakeFiles for 3rd vendor library
|
||||
|
||||
include(ExternalProject)
|
||||
# libgtest
|
||||
ExternalProject_Add(libgtest PREFIX libgtest
|
||||
URL ${CMAKE_SOURCE_DIR}/vendor/googletest-release-1.10.0.tar.gz
|
||||
URL_MD5 ecd1fa65e7de707cd5c00bdac56022cd
|
||||
#CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
|
||||
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> -DCMAKE_BUILD_TYPE=RELWITHDEBINFO)
|
||||
ExternalProject_Get_Property(libgtest INSTALL_DIR)
|
||||
file(MAKE_DIRECTORY ${INSTALL_DIR}/include)
|
||||
add_library(gtest-static STATIC IMPORTED GLOBAL)
|
||||
add_dependencies(gtest-static libgtest)
|
||||
set_property(TARGET gtest-static PROPERTY IMPORTED_LOCATION ${INSTALL_DIR}/lib64/libgtest.a)
|
||||
set_property(TARGET gtest-static PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${INSTALL_DIR}/include)
|
||||
set_property(TARGET gtest-static PROPERTY INTERFACE_LINK_LIBRARIES pthread)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BIN
vendor/googletest-release-1.10.0.tar.gz
vendored
Normal file
BIN
vendor/googletest-release-1.10.0.tar.gz
vendored
Normal file
Binary file not shown.
Reference in New Issue
Block a user