From 80fc384e217ca43d29bd7e8323a391ffccb526d2 Mon Sep 17 00:00:00 2001 From: Andrei Pavel Date: Tue, 22 Apr 2025 23:08:26 +0300 Subject: [PATCH] [#3732] Meson: Add gtest.cc compiler check to detect crashes --- compiler-checks/gtest.cc | 12 ++++++++++++ meson.build | 21 ++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 compiler-checks/gtest.cc diff --git a/compiler-checks/gtest.cc b/compiler-checks/gtest.cc new file mode 100644 index 0000000000..eb1bcea6ec --- /dev/null +++ b/compiler-checks/gtest.cc @@ -0,0 +1,12 @@ +#include + +// musl's mallocng memory allocator stupidly crash for test names that are +// lengthier than 16 characters. Hence the long test name. +TEST(Fixture, testWithLongLongLongName) { + EXPECT_LT(1, 2); +} + +int main() { + testing::InitGoogleTest(); + return RUN_ALL_TESTS(); +} diff --git a/meson.build b/meson.build index 3f5d541a67..f66a543e53 100644 --- a/meson.build +++ b/meson.build @@ -244,11 +244,22 @@ if netconf_opt.enabled() and NETCONF_DEP.get_variable( error('Dependency not found: NETCONF.') endif -GTEST_DEP = dependency( - 'gtest', - fallback: ['gtest', 'gtest_dep'], - required: TESTS_OPT.enabled() or FUZZ_OPT.enabled(), -) +# Google Test +GTEST_DEP = dependency('gtest', required: TESTS_OPT.enabled() or FUZZ_OPT.enabled()) +if GTEST_DEP.found() + result = cpp.run( + fs.read('compiler-checks/gtest.cc'), + name: 'Check if a simple GTest test runs.', + dependencies: [GTEST_DEP], + ) + if result.returncode() != 0 + GTEST_DEP = disabler() + gtest_subproject = subproject('gtest', required: false) + if gtest_subproject.found() + GTEST_DEP = gtest_subproject.get_variable('gtest_dep') + endif + endif +endif # Crypto if crypto_opt == 'botan'