commit 6f55e56805069d7bff1b43a82e97662079254677
parent 04f343bf04ce512276a27788ef21f06e995b9496
Author: serge-sans-paille <sguelton@mozilla.com>
Date: Wed, 15 Oct 2025 07:04:19 +0000
Bug 1982008 - Move logalloc test to memory/replace/logalloc/replay/moz.build r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D260458
Diffstat:
4 files changed, 53 insertions(+), 48 deletions(-)
diff --git a/memory/replace/logalloc/replay/Makefile.in b/memory/replace/logalloc/replay/Makefile.in
@@ -1,48 +0,0 @@
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-ifdef MOZ_CODE_COVERAGE
-SKIP = 1
-endif
-
-ifdef CROSS_COMPILE
-SKIP = 1
-endif
-
-ifneq ($(SKIP),1)
-
-ifeq ($(OS_TARGET),WINNT)
-LOGALLOC_VAR = MOZ_REPLACE_MALLOC_LIB
-else
-ifeq ($(OS_TARGET),Darwin)
-LOGALLOC_VAR = DYLD_INSERT_LIBRARIES
-else
-LOGALLOC_VAR = LD_PRELOAD
-endif
-endif
-
-ifndef MOZ_REPLACE_MALLOC_STATIC
-LOGALLOC = $(LOGALLOC_VAR)=$(CURDIR)/../$(DLL_PREFIX)logalloc$(DLL_SUFFIX)
-endif
-
-expected_output.log: $(srcdir)/replay.log
-# The logalloc-replay program will only replay entries from the first pid,
-# so the expected output only contains entries beginning with "1 "
- grep "^1 " $< > $@
-
-check:: $(srcdir)/replay.log expected_output.log $(srcdir)/expected_output_minimal.log
-# Test with MALLOC_LOG as a file descriptor number
-# We filter out anything happening before the first jemalloc_stats (first
-# command in replay.log) because starting with libstdc++ 5, a static
-# initializer in the STL allocates memory, which we obviously don't have
-# in expected_output.log.
- MALLOC_LOG=1 $(LOGALLOC) ./$(PROGRAM) < $< | sed -n '/jemalloc_stats/,$$p' | $(PYTHON3) $(srcdir)/logalloc_munge.py | diff -w - expected_output.log
-# Test with MALLOC_LOG as a file name
- $(RM) test_output.log
- MALLOC_LOG=test_output.log $(LOGALLOC) ./$(PROGRAM) < $<
- sed -n '/jemalloc_stats/,$$p' test_output.log | $(PYTHON3) $(srcdir)/logalloc_munge.py | diff -w - expected_output.log
-
- MALLOC_LOG=1 MALLOC_LOG_MINIMAL=1 $(LOGALLOC) ./$(PROGRAM) < $< | sed -n '/jemalloc_stats/,$$p' | $(PYTHON3) $(srcdir)/logalloc_munge.py | diff -w - $(srcdir)/expected_output_minimal.log
-
-endif
diff --git a/memory/replace/logalloc/replay/moz.build b/memory/replace/logalloc/replay/moz.build
@@ -95,3 +95,30 @@ DisableStlWrapping()
include("/mozglue/build/replace_malloc.mozbuild")
include("/mozglue/misc/timestamp.mozbuild")
+
+
+if not CONFIG["MOZ_CODE_COVERAGE"] and not CONFIG["CROSS_COMPILE"]:
+ if not CONFIG["MOZ_REPLACE_MALLOC_STATIC"]:
+ if CONFIG["OS_TARGET"] == "WINNT":
+ logalloc_var = "MOZ_REPLACE_MALLOC_LIB"
+ elif CONFIG["OS_TARGET"] == "Darwin":
+ logalloc_var = "DYLD_INSERT_LIBRARIES"
+ else:
+ logalloc_var = "LD_PRELOAD"
+ logalloc = f"--logalloc={logalloc_var}={OBJDIR}/../{CONFIG['DLL_PREFIX']}logalloc{CONFIG['DLL_SUFFIX']}"
+ else:
+ logalloc = "--logalloc="
+
+ LegacyTest(
+ "test_logalloc.sh",
+ logalloc,
+ f"!/{FINAL_TARGET}/{PROGRAM}{CONFIG['BIN_SUFFIX']}",
+ ".",
+ f"%{CONFIG['PYTHON3']}",
+ depends=[
+ f"!/{FINAL_TARGET}/{PROGRAM}{CONFIG['BIN_SUFFIX']}",
+ "logalloc_munge.py",
+ "expected_output_minimal.log",
+ "replay.log",
+ ],
+ )
diff --git a/memory/replace/logalloc/replay/test_logalloc.sh b/memory/replace/logalloc/replay/test_logalloc.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+set -e
+
+LOGALLOC="${1#--logalloc=}"
+PROGRAM="$2"
+SRCDIR="$3"
+PYTHON3="$4"
+
+grep "^1 " ${SRCDIR}/replay.log > expected_output.log
+
+# Test with MALLOC_LOG as a file descriptor number
+# We filter out anything happening before the first jemalloc_stats (first
+# command in replay.log) because starting with libstdc++ 5, a static
+# initializer in the STL allocates memory, which we obviously don't have
+# in expected_output.log.
+MALLOC_LOG=1 ${LOGALLOC} ${PROGRAM} < ${SRCDIR}/replay.log | sed -n '/jemalloc_stats/,$p' | ${PYTHON3} ${SRCDIR}/logalloc_munge.py | diff -w - expected_output.log
+
+# Test with MALLOC_LOG as a file name
+rm -f test_output.log
+MALLOC_LOG=test_output.log ${LOGALLOC} ${PROGRAM} < ${SRCDIR}/replay.log
+sed -n '/jemalloc_stats/,$p' test_output.log | ${PYTHON3} ${SRCDIR}/logalloc_munge.py | diff -w - expected_output.log
+
+MALLOC_LOG=1 MALLOC_LOG_MINIMAL=1 ${LOGALLOC} ${PROGRAM} < ${SRCDIR}/replay.log | sed -n '/jemalloc_stats/,$p' | ${PYTHON3} ${SRCDIR}/logalloc_munge.py | diff -w - ${SRCDIR}/expected_output_minimal.log
+
diff --git a/python/mozbuild/mozbuild/test/test_legacy_test.py b/python/mozbuild/mozbuild/test/test_legacy_test.py
@@ -12,6 +12,7 @@ allowlist = {
"ipc/ipdl/test/ipdl/moz.build",
"js/src/moz.build",
"js/src/build/moz.build",
+ "memory/replace/logalloc/replay/moz.build",
"toolkit/xre/test/win/moz.build",
}