Skip to content

Commit

Permalink
Cleanup build with tsapibackend (#10725)
Browse files Browse the repository at this point in the history
* Introduce tsapibackend

* unit tests only link with the library they are testing

* cleanup some links for traffic_ programs

* remove dup stubs

* run cmake-format

* add overridable_txn_vars

---------

Co-authored-by: Chris McFarlen <[email protected]>
  • Loading branch information
cmcfarlen and Chris McFarlen authored Nov 8, 2023
1 parent 1c486ca commit aa0b339
Show file tree
Hide file tree
Showing 19 changed files with 287 additions and 354 deletions.
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -607,9 +607,6 @@ endif()
if(ENABLE_CRIPTS)
add_subdirectory(src/cripts)
endif()
if(BUILD_TESTING)
add_subdirectory(src/tests)
endif()
if(ENABLE_AUTEST)
add_subdirectory(tests)
endif()
Expand Down
2 changes: 1 addition & 1 deletion plugins/experimental/uri_signing/unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ add_executable(
${PROJECT_SOURCE_DIR}/parse.cc
${PROJECT_SOURCE_DIR}/timing.cc
${PROJECT_SOURCE_DIR}/uri_signing.cc
${CMAKE_SOURCE_DIR}/src/shared/overridable_txn_vars.cc
)
target_compile_definitions(uri_signing_test PRIVATE UNITTEST)
target_include_directories(uri_signing_test PRIVATE ${PROJECT_SOURCE_DIR})
Expand All @@ -44,6 +43,7 @@ target_link_libraries(
ts::configmanager
ts::logging
ts::inknet
ts::overridable_txn_vars
OpenSSL::SSL
OpenSSL::Crypto
)
Expand Down
34 changes: 22 additions & 12 deletions src/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#
#######################

add_library(tsapi SHARED InkAPI.cc InkIOCoreAPI.cc)
# plugin api *only*
add_library(tsapi SHARED InkAPI.cc InkIOCoreAPI.cc FetchSM.cc # OSCP stapling
)
add_library(ts::tsapi ALIAS tsapi)

set(TSAPI_PUBLIC_HEADERS
Expand All @@ -32,23 +34,31 @@ set(TSAPI_PUBLIC_HEADERS
target_link_libraries(tsapi PRIVATE libswoc yaml-cpp::yaml-cpp PCRE::PCRE OpenSSL::SSL)
set_target_properties(tsapi PROPERTIES PUBLIC_HEADER "${TSAPI_PUBLIC_HEADERS}")

# Items common between api and other ts libraries
add_library(
tsapicore STATIC
APIHook.cc
APIHooks.cc
Metrics.cc
ConfigUpdateCbTable.cc
InkContInternal.cc
InkVConnInternal.cc
FetchSM.cc
LifecycleAPIHooks.cc
DbgCtl.cc
tsapibackend
ConfigUpdateCbTable.cc # configmanager
InkContInternal.cc # proxy, http
InkVConnInternal.cc # proxy, http
APIHook.cc # iocore
APIHooks.cc # proxy
LifecycleAPIHooks.cc # proxy, http
HttpHookState.cc # proxy, http
)
add_library(ts::tsapibackend ALIAS tsapibackend)
target_link_libraries(
tsapibackend
PUBLIC ts::inknet ts::http
PRIVATE ts::proxy ts::hdrs ts::tscore
)

# Items that even tscore can depend on
add_library(tsapicore Metrics.cc DbgCtl.cc)
add_library(ts::tsapicore ALIAS tsapicore)
target_link_libraries(tsapicore PRIVATE ts::tscore)
set_target_properties(tsapicore PROPERTIES POSITION_INDEPENDENT_CODE TRUE)

install(TARGETS tsapi PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ts)
install(TARGETS tsapi tsapicore tsapibackend PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ts)

if(APPLE)
target_link_options(tsapi PRIVATE -undefined dynamic_lookup)
Expand Down
103 changes: 103 additions & 0 deletions src/api/HttpHookState.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/** @file
Internal SDK stuff
@section license License
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include "api/InkAPIInternal.h"

void
HttpHookState::init(TSHttpHookID id, HttpAPIHooks const *global, HttpAPIHooks const *ssn, HttpAPIHooks const *txn)
{
_id = id;

if (global) {
_global.init(global, id);
} else {
_global.clear();
}

if (ssn) {
_ssn.init(ssn, id);
} else {
_ssn.clear();
}

if (txn) {
_txn.init(txn, id);
} else {
_txn.clear();
}
}

APIHook const *
HttpHookState::getNext()
{
APIHook const *zret = nullptr;

#ifdef DEBUG
Debug("plugin", "computing next callback for hook %d", _id);
#endif

if (zret = _global.candidate(); zret) {
++_global;
} else if (zret = _ssn.candidate(); zret) {
++_ssn;
} else if (zret = _txn.candidate(); zret) {
++_txn;
}

return zret;
}

void
HttpHookState::Scope::init(HttpAPIHooks const *feature_hooks, TSHttpHookID id)
{
_hooks = (*feature_hooks)[id];

_p = nullptr;
_c = _hooks->head();
}

APIHook const *
HttpHookState::Scope::candidate()
{
/// Simply returns _c hook for now. Later will do priority checking here

// Check to see if a hook has been added since this was initialized empty
if (nullptr == _c && nullptr == _p && _hooks != nullptr) {
_c = _hooks->head();
}
return _c;
}

void
HttpHookState::Scope::operator++()
{
_p = _c;
_c = _c->next();
}

void
HttpHookState::Scope::clear()
{
_hooks = nullptr;
_p = _c = nullptr;
}
85 changes: 0 additions & 85 deletions src/api/InkAPI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1041,91 +1041,6 @@ FileImpl::fgets(char *buf, size_t length)
return buf;
}

////////////////////////////////////////////////////////////////////
//
// APIHook, APIHooks, HttpAPIHooks, HttpHookState
//
////////////////////////////////////////////////////////////////////

void
HttpHookState::init(TSHttpHookID id, HttpAPIHooks const *global, HttpAPIHooks const *ssn, HttpAPIHooks const *txn)
{
_id = id;

if (global) {
_global.init(global, id);
} else {
_global.clear();
}

if (ssn) {
_ssn.init(ssn, id);
} else {
_ssn.clear();
}

if (txn) {
_txn.init(txn, id);
} else {
_txn.clear();
}
}

APIHook const *
HttpHookState::getNext()
{
APIHook const *zret = nullptr;

#ifdef DEBUG
Debug("plugin", "computing next callback for hook %d", _id);
#endif

if (zret = _global.candidate(); zret) {
++_global;
} else if (zret = _ssn.candidate(); zret) {
++_ssn;
} else if (zret = _txn.candidate(); zret) {
++_txn;
}

return zret;
}

void
HttpHookState::Scope::init(HttpAPIHooks const *feature_hooks, TSHttpHookID id)
{
_hooks = (*feature_hooks)[id];

_p = nullptr;
_c = _hooks->head();
}

APIHook const *
HttpHookState::Scope::candidate()
{
/// Simply returns _c hook for now. Later will do priority checking here

// Check to see if a hook has been added since this was initialized empty
if (nullptr == _c && nullptr == _p && _hooks != nullptr) {
_c = _hooks->head();
}
return _c;
}

void
HttpHookState::Scope::operator++()
{
_p = _c;
_c = _c->next();
}

void
HttpHookState::Scope::clear()
{
_hooks = nullptr;
_p = _c = nullptr;
}

////////////////////////////////////////////////////////////////////
//
// api_init
Expand Down
10 changes: 10 additions & 0 deletions src/iocore/aio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,13 @@ target_link_libraries(aio PUBLIC ts::inkevent ts::tscore)
if(TS_USE_LINUX_IO_URING)
target_link_libraries(aio PUBLIC ts::inkuring)
endif()

if(BUILD_TESTING)
add_executable(test_AIO test_AIO.cc)
target_link_libraries(test_AIO ts::aio)
add_test(
NAME test_AIO
COMMAND $<TARGET_FILE:test_AIO>
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src/iocore/aio
)
endif()
35 changes: 35 additions & 0 deletions src/iocore/cache/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,38 @@ target_link_libraries(
if(HAVE_LZMA_H)
target_link_libraries(inkcache PRIVATE LibLZMA::LibLZMA)
endif()

if(BUILD_TESTING)
macro(add_cache_test name)
add_executable(${name} unit_tests/main.cc unit_tests/stub.cc unit_tests/CacheTestHandler.cc ${ARGN})
target_link_libraries(${name} PRIVATE ts::inkcache catch2::catch2)
add_test(NAME test_cache_${name} COMMAND $<TARGET_FILE:${name}>)
endmacro()

add_cache_test(Cache unit_tests/test_Cache.cc)
add_cache_test(Populated_Cache unit_tests/test_Populated_Cache.cc)
if(ENABLE_DISK_FAILURE_TESTS)
foreach(i RANGE 1)
add_cache_test(Disk_Init_Failure_${i} unit_tests/test_Disk_Init_Failure.cc)
target_compile_definitions(Disk_Init_Failure_${i} PUBLIC FAILURE_INDICES={${i}})
endforeach()
foreach(i RANGE 5 20)
add_cache_test(Disk_Failure_${i} unit_tests/test_Disk_Failure.cc)
target_compile_definitions(Disk_Failure_${i} PUBLIC FAILURE_INDICES={${i}})
endforeach()
add_cache_test(Populated_Cache_Disk_Failure unit_tests/test_Populated_Cache_Disk_Failure.cc)
endif()
add_cache_test(CacheDir unit_tests/test_CacheDir.cc)
add_cache_test(CacheVol unit_tests/test_CacheVol.cc)
add_cache_test(RWW unit_tests/test_RWW.cc)
add_cache_test(Alternate_L_to_S unit_tests/test_Alternate_L_to_S.cc)
add_cache_test(Alternate_S_to_L unit_tests/test_Alternate_S_to_L.cc)
add_cache_test(Alternate_L_to_S_remove_L unit_tests/test_Alternate_L_to_S_remove_L.cc)
add_cache_test(Alternate_L_to_S_remove_S unit_tests/test_Alternate_L_to_S_remove_S.cc)
add_cache_test(Alternate_S_to_L_remove_L unit_tests/test_Alternate_S_to_L_remove_L.cc)
add_cache_test(Alternate_S_to_L_remove_S unit_tests/test_Alternate_S_to_L_remove_S.cc)
add_cache_test(Update_L_to_S unit_tests/test_Update_L_to_S.cc)
add_cache_test(Update_S_to_L unit_tests/test_Update_S_to_L.cc)
add_cache_test(Update_Header unit_tests/test_Update_header.cc)

endif()
40 changes: 0 additions & 40 deletions src/iocore/cache/unit_tests/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -366,43 +366,3 @@ CacheReadTest::start_test(int event, void *e)
}

constexpr size_t WRITE_LIMIT = 1024 * 3;

/************ STUB ******************/

#include "api/FetchSM.h"
ClassAllocator<FetchSM> FetchSMAllocator("unusedFetchSMAllocator");
void
FetchSM::ext_launch()
{
}
void
FetchSM::ext_destroy()
{
}
ssize_t
FetchSM::ext_read_data(char *, unsigned long)
{
return 0;
}
void
FetchSM::ext_add_header(char const *, int, char const *, int)
{
}
void
FetchSM::ext_write_data(void const *, unsigned long)
{
}
void *
FetchSM::ext_get_user_data()
{
return nullptr;
}
void
FetchSM::ext_set_user_data(void *)
{
}
void
FetchSM::ext_init(Continuation *, char const *, char const *, char const *, sockaddr const *, int)
{
}
ChunkedHandler::ChunkedHandler() {}
Loading

0 comments on commit aa0b339

Please sign in to comment.