Skip to content

Commit 0e22334

Browse files
rlyerlymeta-codesync[bot]
authored andcommitted
Fix getdeps test failures - add folly::init to interface and navy tests
Summary: The OSS CMake build uses GTest::gtest_main which does not call folly::init(). Tests that exercise code paths using folly singletons (Timekeeper) or XLOG crash with SIGABRT or SEGFAULT. This adds a custom TestMain.cpp that calls InitGoogleTest() followed by folly::Init, and links it directly to each test executable via target_sources to avoid link-order issues with transitively-linked GTest::gtest_main. Fixes 3 of 4 failing interface tests. FlashCacheComponentTest.ExpirationCallback still fails due to a deeper XLOG initialization issue that needs manual investigation. --- > Generated by [Metamate](https://fb.workplace.com/groups/metamate.feedback/) [Metamate Session](https://internalfb.com/intern/bunny?q=eggmate%207c5c00c7-1341-40c1-81a6-e1c31c25b415), [Trace](https://www.internalfb.com/confucius?session_id=7c5c00c7-1341-40c1-81a6-e1c31c25b415&tab=Trace) --- Other changes: * Remove `WORKING_DIRECTORY "${TOP_DIR}"` from the main CMakeLists. `TOP_DIR` is never set, so this was create log spam from warnings and was getting unset anyway. * Use new `CO_ASSERT_OK` in CO_TEST* tests. This uses `CO_ASSERT_TRUE` (a coro-compatible macro) rather than XCHECK (which just crashes). * Move FlashCacheComponentTest to gcc-disabled tests (internal compiler error). ___ overriding_review_checks_triggers_an_audit_and_retroactive_review Oncall Short Name: cachelib Differential Revision: D100265646 fbshipit-source-id: bea090e7ab7f5d6bc76501c07b99dfe156798cb4
1 parent d4a8956 commit 0e22334

8 files changed

Lines changed: 120 additions & 82 deletions

File tree

cachelib/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ function (generic_add_source_test TEST_PREFIX SOURCE_FILE)
163163

164164
# make tests visible to ctest
165165
gtest_add_tests(TARGET "${TEST_PREFIX}-${TEST_NAME}"
166-
WORKING_DIRECTORY "${TOP_DIR}"
167166
TEST_PREFIX "${TEST_PREFIX}-${TEST_NAME}."
168167
TEST_LIST "test_cases")
169168
# use same timeout as folly

cachelib/common/tests/TestMain.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <folly/init/Init.h>
18+
#include <gtest/gtest.h>
19+
20+
int main(int argc, char** argv) {
21+
// InitGoogleTest must be called BEFORE folly::Init so that gtest
22+
// consumes --gtest_filter and other gtest flags before gflags
23+
// (called by folly::Init) rejects them as unknown flags.
24+
::testing::InitGoogleTest(&argc, argv);
25+
folly::Init init(&argc, &argv);
26+
return RUN_ALL_TESTS();
27+
}

cachelib/interface/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,24 @@ if (BUILD_TESTS)
5050
glog::glog
5151
gflags
5252
GTest::gtest
53-
GTest::gtest_main
5453
GTest::gmock
5554
)
5655

5756
function (add_source_test SOURCE_FILE)
5857
generic_add_source_test("interface-test" "${SOURCE_FILE}"
5958
interface_test_support "${ARGN}")
59+
get_filename_component(TEST_NAME "${SOURCE_FILE}" NAME_WE)
60+
target_sources("interface-test-${TEST_NAME}" PRIVATE
61+
"${CACHELIB_HOME}/common/tests/TestMain.cpp")
6062
endfunction()
6163

6264
# GCC ICE in gimplify_var_or_parm_decl with coroutine test macros
6365
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
6466
add_source_test (tests/InterfaceTest.cpp)
6567
add_source_test (components/tests/CacheComponentTest.cpp)
68+
add_source_test (components/tests/FlashCacheComponentTest.cpp)
6669
endif()
6770
add_source_test (tests/ResultTest.cpp)
68-
add_source_test (components/tests/FlashCacheComponentTest.cpp)
6971
add_source_test (utils/tests/CoroFiberAdapterTest.cpp)
7072
add_source_test (utils/tests/ShardedSerializerTest.cpp)
7173
endif()

0 commit comments

Comments
 (0)