diff --git a/recipes/gperftools/all/test_package/CMakeLists.txt b/recipes/gperftools/all/test_package/CMakeLists.txt index 5baf67b50cd5e..47710be6311b8 100644 --- a/recipes/gperftools/all/test_package/CMakeLists.txt +++ b/recipes/gperftools/all/test_package/CMakeLists.txt @@ -3,9 +3,8 @@ project(test_package LANGUAGES C) find_package(gperftools REQUIRED CONFIG) -add_executable(${PROJECT_NAME} test_package.c) -target_link_libraries(${PROJECT_NAME} PRIVATE gperftools::gperftools) - -add_executable(${PROJECT_NAME}_minimal test_package.c) -target_link_libraries(${PROJECT_NAME}_minimal PRIVATE gperftools::tcmalloc_minimal) +add_executable(${PROJECT_NAME}_indirect test_package_indirect.c) +target_link_libraries(${PROJECT_NAME}_indirect PRIVATE gperftools::tcmalloc_minimal) +add_executable(${PROJECT_NAME}_direct test_package_direct.c) +target_link_libraries(${PROJECT_NAME}_direct PRIVATE gperftools::tcmalloc_minimal) diff --git a/recipes/gperftools/all/test_package/conanfile.py b/recipes/gperftools/all/test_package/conanfile.py index f5cf204295e19..15254490bd4f2 100644 --- a/recipes/gperftools/all/test_package/conanfile.py +++ b/recipes/gperftools/all/test_package/conanfile.py @@ -1,4 +1,7 @@ -from conan import ConanFile +import io + +from conan import ConanFile, conan_version +from conan.tools.apple import is_apple_os from conan.tools.build import can_run from conan.tools.cmake import cmake_layout, CMake import os @@ -19,7 +22,25 @@ def build(self): cmake.configure() cmake.build() + def _test(self, executable): + bin_path = os.path.join(self.cpp.build.bindir, executable) + if conan_version >= "2.0.15": + stderr = io.StringIO() + kwargs = {} # workaround for a linter false positive + kwargs.update([("stderr", stderr)]) + self.run(bin_path, env="conanrun", **kwargs) + stderr = stderr.getvalue() + self.output.info(stderr) + assert "MALLOC: " in stderr, "MALLOCSTATS was not successfully enabled: " + stderr + else: + self.run(bin_path, env="conanrun") + def test(self): if can_run(self): - bin_path = os.path.join(self.cpp.build.bindir, "test_package") - self.run(bin_path, env="conanrun") + os.environ["MALLOCSTATS"] = "1" + self._test("test_package_direct") + if conan_version.major == 2 and is_apple_os(self) and not self.dependencies["gperftools"].options.shared: + # FIXME + self.output.warning(f"Indirect use of malloc() on {self.settings.os} for a static build is broken and is currently skipped") + else: + self._test("test_package_indirect") diff --git a/recipes/gperftools/all/test_package/test_package.c b/recipes/gperftools/all/test_package/test_package_direct.c similarity index 100% rename from recipes/gperftools/all/test_package/test_package.c rename to recipes/gperftools/all/test_package/test_package_direct.c diff --git a/recipes/gperftools/all/test_package/test_package_indirect.c b/recipes/gperftools/all/test_package/test_package_indirect.c new file mode 100644 index 0000000000000..0c4eaf1da058c --- /dev/null +++ b/recipes/gperftools/all/test_package/test_package_indirect.c @@ -0,0 +1,10 @@ +#include +#include +#include + +int main() { + void *p = malloc(100); + printf("%p\n", p); + free(p); + return p == 0 ? EXIT_FAILURE : EXIT_SUCCESS; +}