-
Notifications
You must be signed in to change notification settings - Fork 510
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
include unit tests and integration tests in the cmake build
Summary: This enable test targets to be built and ran Reviewed By: lnicco Differential Revision: D17408942 fbshipit-source-id: 144d223bc3830d07a0420e9569d3166a8646cd9a
- Loading branch information
1 parent
e05a440
commit ea14236
Showing
7 changed files
with
168 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
|
||
include(CTest) | ||
if(BUILD_TESTS) | ||
find_library(BOOST_SYSTEM libboost_system.a boost_system) | ||
find_package(FOLLY CONFIG REQUIRED) | ||
find_library(GTEST gtest) | ||
find_path(GTEST_INCLUDE_DIR gtest) | ||
find_library(PTHREAD pthread) | ||
include(GoogleTest) | ||
endif() | ||
|
||
function(katran_add_test) | ||
if(NOT BUILD_TESTS) | ||
return() | ||
endif() | ||
|
||
set(options) | ||
set(one_value_args TARGET WORKING_DIRECTORY PREFIX) | ||
set(multi_value_args SOURCES DEPENDS INCLUDES EXTRA_ARGS) | ||
cmake_parse_arguments(PARSE_ARGV 0 KATRAN_TEST "${options}" "${one_value_args}" "${multi_value_args}") | ||
|
||
if(NOT KATRAN_TEST_TARGET) | ||
message(FATAL_ERROR "The TARGET parameter is mandatory.") | ||
endif() | ||
|
||
if(NOT KATRAN_TEST_SOURCES) | ||
set(KATRAN_TEST_SOURCES "${KATRAN_TEST_TARGET}.cpp") | ||
endif() | ||
|
||
add_executable(${KATRAN_TEST_TARGET} | ||
"${KATRAN_TEST_SOURCES}" | ||
# implementation of 'main()' that also calls folly::init | ||
"${KATRAN_FBCODE_ROOT}/katran/lib/tests/common/TestMain.cpp" | ||
) | ||
|
||
target_link_libraries(${KATRAN_TEST_TARGET} PRIVATE | ||
"${KATRAN_TEST_DEPENDS}" | ||
${GTEST} | ||
) | ||
|
||
target_include_directories(${KATRAN_TEST_TARGET} PRIVATE | ||
${BPF_INCLUDE_DIRS} | ||
${GTEST_INCLUDE_DIR} | ||
${FOLLY_INCLUDE_DIR} | ||
${KATRAN_INCLUDE_DIR} | ||
${KATRAN_EXTRA_INCLUDE_DIRECTORIES} | ||
${KATRAN_TEST_INCLUDES} | ||
) | ||
|
||
gtest_discover_tests("${KATRAN_TEST_TARGET}" | ||
EXTRA_ARGS "${KATRAN_TEST_EXTRA_ARGS}" | ||
WORKING_DIRECTORY "${KATRAN_TEST_WORKING_DIRECTORY}" | ||
TEST_PREFIX ${KATRAN_TEST_PREFIX} | ||
TEST_LIST KATRAN_TEST_CASES) | ||
|
||
set_tests_properties(${KATRAN_TEST_CASES} PROPERTIES TIMEOUT 120) | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,43 @@ | ||
cmake_minimum_required (VERSION 3.9) | ||
project (libkatran_tests) | ||
set(KATRAN_INCLUDE_DIR "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../>") | ||
|
||
# find libs | ||
# find libraries | ||
find_library(CHHELPERS chhelpers) | ||
find_path(CHHELPERS_INCLUDE_DIR chhelpers) | ||
find_library(GTEST gtest) | ||
find_path(GTEST_INCLUDE_DIR gtest) | ||
find_package(FOLLY CONFIG REQUIRED) | ||
find_library(PTHREAD pthread) | ||
|
||
include(KatranTest) | ||
|
||
add_executable(iphelpers-tests IpHelpersTest.cpp) | ||
target_link_libraries(iphelpers-tests | ||
"${GTEST}" | ||
"${PTHREAD}" | ||
"Folly::folly" | ||
iphelpers | ||
) | ||
target_include_directories( | ||
iphelpers-tests PUBLIC | ||
"${GTEST_INCLUDE_DIR}" | ||
${FOLLY_INCLUDE_DIR} | ||
${KATRAN_INCLUDE_DIR} | ||
katran_add_test(TARGET iphelpers-tests | ||
SOURCES | ||
IpHelpersTest.cpp | ||
DEPENDS | ||
iphelpers | ||
${GTEST} | ||
${PTHREAD} | ||
"Folly::folly" | ||
) | ||
|
||
add_executable(chhelpers-tests CHHelpersTest.cpp) | ||
target_link_libraries(chhelpers-tests | ||
"${GTEST}" | ||
"${PTHREAD}" | ||
katranlb | ||
) | ||
target_include_directories( | ||
chhelpers-tests PUBLIC | ||
"${GTEST_INCLUDE_DIR}" | ||
${KATRAN_INCLUDE_DIR} | ||
katran_add_test(TARGET chhelpers-tests | ||
SOURCES | ||
CHHelpersTest.cpp | ||
DEPENDS | ||
katranlb | ||
${GTEST} | ||
${PTHREAD} | ||
) | ||
|
||
add_executable(libkatran-tests KatranLbTest.cpp) | ||
target_link_libraries(libkatran-tests | ||
"${GTEST}" | ||
"${PTHREAD}" | ||
"Folly::folly" | ||
) | ||
target_include_directories( | ||
libkatran-tests PUBLIC | ||
"${GTEST_INCLUDE_DIR}" | ||
"${FOLLY_INCLUDE_DIR}" | ||
katran_add_test(TARGET libkatran-tests | ||
SOURCES | ||
KatranLbTest.cpp | ||
DEPENDS | ||
katranlb | ||
${GTEST} | ||
${PTHREAD} | ||
"Folly::folly" | ||
) | ||
|
||
add_executable(vip-tests VipTest.cpp) | ||
target_link_libraries(vip-tests | ||
"${GTEST}" | ||
"${PTHREAD}" | ||
) | ||
target_include_directories( | ||
vip-tests PUBLIC | ||
"${GTEST_INCLUDE_DIR}" | ||
katran_add_test(TARGET vip-tests | ||
SOURCES | ||
VipTest.cpp | ||
DEPENDS | ||
katranlb | ||
${GTEST} | ||
${PTHREAD} | ||
"Folly::folly" | ||
) | ||
|
||
add_test(IpHelpersTests iphelpers-tests) | ||
add_test(CHHelpersTests chhelpers-tests) | ||
add_test(LibKatranTests libkatran-tests) | ||
add_test(VipTests vip-tests) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* Copyright (C) 2018-present, Facebook, Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; version 2 of the License. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
#include <folly/init/Init.h> | ||
|
||
#include <folly/Portability.h> | ||
#include <folly/portability/GFlags.h> | ||
#include <folly/portability/GTest.h> | ||
|
||
/* | ||
* This is the recommended main function for all tests. | ||
* The Makefile links it into all of the test programs so that tests do not need | ||
* to - and indeed should typically not - define their own main() functions | ||
*/ | ||
FOLLY_ATTR_WEAK int main(int argc, char** argv); | ||
|
||
int main(int argc, char** argv) { | ||
#if FOLLY_HAVE_LIBGFLAGS | ||
// Enable glog logging to stderr by default. | ||
gflags::SetCommandLineOptionWithMode( | ||
"logtostderr", "1", gflags::SET_FLAGS_DEFAULT); | ||
#endif | ||
|
||
::testing::InitGoogleTest(&argc, argv); | ||
folly::Init init(&argc, &argv); | ||
|
||
return RUN_ALL_TESTS(); | ||
} |