From 0052c3a98cfe24da7477583a7e43236007276521 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Mon, 5 Feb 2024 12:43:31 +0200 Subject: [PATCH 01/10] gperftools: add a test for plain malloc() support --- recipes/gperftools/all/test_package/CMakeLists.txt | 9 ++++----- recipes/gperftools/all/test_package/conanfile.py | 5 ++++- .../{test_package.c => test_package_direct.c} | 0 .../gperftools/all/test_package/test_package_indirect.c | 9 +++++++++ 4 files changed, 17 insertions(+), 6 deletions(-) rename recipes/gperftools/all/test_package/{test_package.c => test_package_direct.c} (100%) create mode 100644 recipes/gperftools/all/test_package/test_package_indirect.c 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..9288259b57518 100644 --- a/recipes/gperftools/all/test_package/conanfile.py +++ b/recipes/gperftools/all/test_package/conanfile.py @@ -21,5 +21,8 @@ def build(self): def test(self): if can_run(self): - bin_path = os.path.join(self.cpp.build.bindir, "test_package") + os.environ["MALLOCSTATS"] = "1" + bin_path = os.path.join(self.cpp.build.bindir, "test_package_indirect") + self.run(bin_path, env="conanrun") + bin_path = os.path.join(self.cpp.build.bindir, "test_package_direct") self.run(bin_path, env="conanrun") 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..f42f8bae49e7d --- /dev/null +++ b/recipes/gperftools/all/test_package/test_package_indirect.c @@ -0,0 +1,9 @@ +#include +#include +#include + +int main() { + void *p = malloc(100); + free(p); + return p == 0 ? EXIT_FAILURE : EXIT_SUCCESS; +} From 4376bc1db826e710dc8456343e0299f41877122b Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Mon, 5 Feb 2024 12:52:28 +0200 Subject: [PATCH 02/10] gperftools: add an assert to verify that MALLOCSTATS=1 worked --- .../gperftools/all/test_package/conanfile.py | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/recipes/gperftools/all/test_package/conanfile.py b/recipes/gperftools/all/test_package/conanfile.py index 9288259b57518..967af9dd8675d 100644 --- a/recipes/gperftools/all/test_package/conanfile.py +++ b/recipes/gperftools/all/test_package/conanfile.py @@ -1,4 +1,6 @@ -from conan import ConanFile +import io + +from conan import ConanFile, conan_version from conan.tools.build import can_run from conan.tools.cmake import cmake_layout, CMake import os @@ -19,10 +21,19 @@ def build(self): cmake.configure() cmake.build() + def _test(self, executable): + bin_path = os.path.join(self.cpp.build.bindir, executable) + if conan_version.major >= "2.0.15": + stderr = io.StringIO() + self.run(bin_path, env="conanrun", stderr=stderr) + stderr = stderr.getvalue() + self.output.info(stderr) + assert "MALLOC: " in stderr, "MALLOCSTATS was not successfully enabled" + else: + self.run(bin_path, env="conanrun") + def test(self): if can_run(self): os.environ["MALLOCSTATS"] = "1" - bin_path = os.path.join(self.cpp.build.bindir, "test_package_indirect") - self.run(bin_path, env="conanrun") - bin_path = os.path.join(self.cpp.build.bindir, "test_package_direct") - self.run(bin_path, env="conanrun") + self._test("test_package_indirect") + self._test("test_package_direct") From 1674928a75a938b0cabafcb64349de9f39a98da7 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Mon, 5 Feb 2024 12:56:44 +0200 Subject: [PATCH 03/10] gperftools: silence linter false-positive --- recipes/gperftools/all/test_package/conanfile.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/recipes/gperftools/all/test_package/conanfile.py b/recipes/gperftools/all/test_package/conanfile.py index 967af9dd8675d..6438113d53304 100644 --- a/recipes/gperftools/all/test_package/conanfile.py +++ b/recipes/gperftools/all/test_package/conanfile.py @@ -25,7 +25,8 @@ def _test(self, executable): bin_path = os.path.join(self.cpp.build.bindir, executable) if conan_version.major >= "2.0.15": stderr = io.StringIO() - self.run(bin_path, env="conanrun", stderr=stderr) + kwargs = dict(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" From 4738ae953b666add82ea3cfd44652c402e2afe94 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Tue, 6 Feb 2024 12:30:52 +0200 Subject: [PATCH 04/10] gperftools: silence linter false-positive v2 --- recipes/gperftools/all/test_package/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/gperftools/all/test_package/conanfile.py b/recipes/gperftools/all/test_package/conanfile.py index 6438113d53304..5b2f320be50e6 100644 --- a/recipes/gperftools/all/test_package/conanfile.py +++ b/recipes/gperftools/all/test_package/conanfile.py @@ -25,7 +25,7 @@ def _test(self, executable): bin_path = os.path.join(self.cpp.build.bindir, executable) if conan_version.major >= "2.0.15": stderr = io.StringIO() - kwargs = dict(stderr=stderr) + kwargs = dict([("stderr", stderr)]) self.run(bin_path, env="conanrun", **kwargs) stderr = stderr.getvalue() self.output.info(stderr) From f351ac7e8d510b2cfcfd351ca03d0ea0913de249 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Tue, 6 Feb 2024 13:10:35 +0200 Subject: [PATCH 05/10] gperftools: silence linter false-positive v3 --- recipes/gperftools/all/test_package/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/gperftools/all/test_package/conanfile.py b/recipes/gperftools/all/test_package/conanfile.py index 5b2f320be50e6..4c5004a39df80 100644 --- a/recipes/gperftools/all/test_package/conanfile.py +++ b/recipes/gperftools/all/test_package/conanfile.py @@ -25,7 +25,7 @@ def _test(self, executable): bin_path = os.path.join(self.cpp.build.bindir, executable) if conan_version.major >= "2.0.15": stderr = io.StringIO() - kwargs = dict([("stderr", stderr)]) + kwargs = {"stderr".strip(): stderr} self.run(bin_path, env="conanrun", **kwargs) stderr = stderr.getvalue() self.output.info(stderr) From 9c9377bb9b7964550837808330503a977021167d Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Tue, 6 Feb 2024 14:39:15 +0200 Subject: [PATCH 06/10] gperftools: fix version check Co-authored-by: ericLemanissier --- recipes/gperftools/all/test_package/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/gperftools/all/test_package/conanfile.py b/recipes/gperftools/all/test_package/conanfile.py index 4c5004a39df80..a08b5f4f344ae 100644 --- a/recipes/gperftools/all/test_package/conanfile.py +++ b/recipes/gperftools/all/test_package/conanfile.py @@ -23,7 +23,7 @@ def build(self): def _test(self, executable): bin_path = os.path.join(self.cpp.build.bindir, executable) - if conan_version.major >= "2.0.15": + if conan_version >= "2.0.15": stderr = io.StringIO() kwargs = {"stderr".strip(): stderr} self.run(bin_path, env="conanrun", **kwargs) From 9374d97c75e026dab00ae36665e1a6e86d7d8200 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Tue, 6 Feb 2024 16:21:58 +0200 Subject: [PATCH 07/10] gperftools: keep things simple Co-authored-by: ericLemanissier --- recipes/gperftools/all/test_package/conanfile.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/recipes/gperftools/all/test_package/conanfile.py b/recipes/gperftools/all/test_package/conanfile.py index a08b5f4f344ae..7b0030e1d39c8 100644 --- a/recipes/gperftools/all/test_package/conanfile.py +++ b/recipes/gperftools/all/test_package/conanfile.py @@ -25,8 +25,7 @@ def _test(self, executable): bin_path = os.path.join(self.cpp.build.bindir, executable) if conan_version >= "2.0.15": stderr = io.StringIO() - kwargs = {"stderr".strip(): stderr} - self.run(bin_path, env="conanrun", **kwargs) + self.run(bin_path, env="conanrun", stderr=stderr) stderr = stderr.getvalue() self.output.info(stderr) assert "MALLOC: " in stderr, "MALLOCSTATS was not successfully enabled" From c31e291ce81220ed740d02698d057c78405dcf7d Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Wed, 7 Feb 2024 09:35:55 +0200 Subject: [PATCH 08/10] gperftools: avoid test code being optimized out Co-authored-by: ericLemanissier --- recipes/gperftools/all/test_package/test_package_indirect.c | 1 + 1 file changed, 1 insertion(+) diff --git a/recipes/gperftools/all/test_package/test_package_indirect.c b/recipes/gperftools/all/test_package/test_package_indirect.c index f42f8bae49e7d..0c4eaf1da058c 100644 --- a/recipes/gperftools/all/test_package/test_package_indirect.c +++ b/recipes/gperftools/all/test_package/test_package_indirect.c @@ -4,6 +4,7 @@ int main() { void *p = malloc(100); + printf("%p\n", p); free(p); return p == 0 ? EXIT_FAILURE : EXIT_SUCCESS; } From 214f663223a96f27b06a61481e28da7b51c26368 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Sun, 3 Mar 2024 13:42:58 +0200 Subject: [PATCH 09/10] gperftools: disable indirect test on macOS static for v2 --- recipes/gperftools/all/test_package/conanfile.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/recipes/gperftools/all/test_package/conanfile.py b/recipes/gperftools/all/test_package/conanfile.py index 7b0030e1d39c8..68a90b0f2aecd 100644 --- a/recipes/gperftools/all/test_package/conanfile.py +++ b/recipes/gperftools/all/test_package/conanfile.py @@ -1,6 +1,7 @@ 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 @@ -28,12 +29,16 @@ def _test(self, executable): self.run(bin_path, env="conanrun", stderr=stderr) stderr = stderr.getvalue() self.output.info(stderr) - assert "MALLOC: " in stderr, "MALLOCSTATS was not successfully enabled" + assert "MALLOC: " in stderr, "MALLOCSTATS was not successfully enabled: " + stderr else: self.run(bin_path, env="conanrun") def test(self): if can_run(self): os.environ["MALLOCSTATS"] = "1" - self._test("test_package_indirect") 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") From 8a4acc46d1d2039397246bbc964e243c66a6a90b Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Sun, 24 Mar 2024 18:43:55 +0200 Subject: [PATCH 10/10] gperftools: linter workaround --- recipes/gperftools/all/test_package/conanfile.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/recipes/gperftools/all/test_package/conanfile.py b/recipes/gperftools/all/test_package/conanfile.py index 68a90b0f2aecd..15254490bd4f2 100644 --- a/recipes/gperftools/all/test_package/conanfile.py +++ b/recipes/gperftools/all/test_package/conanfile.py @@ -26,7 +26,9 @@ def _test(self, executable): bin_path = os.path.join(self.cpp.build.bindir, executable) if conan_version >= "2.0.15": stderr = io.StringIO() - self.run(bin_path, env="conanrun", stderr=stderr) + 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