Bug 1368932 - Add a testcase for a replace-malloc library that doesn't implement all functions. r?njn draft
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 31 May 2017 15:04:32 +0900
changeset 587422 ef2d8ef4d37fc05a7c7163a9c54251c31b7d089a
parent 587421 e8ff2c54dcc2287970e22a1ccac9408a2e034eed
child 631258 8a483ee96cc76935fe9bb7c7b01e443b1e5ef008
push id61698
push userbmo:mh+mozilla@glandium.org
push dateThu, 01 Jun 2017 00:41:06 +0000
reviewersnjn
bugs1368932
milestone55.0a1
Bug 1368932 - Add a testcase for a replace-malloc library that doesn't implement all functions. r?njn
memory/replace/logalloc/LogAlloc.cpp
memory/replace/logalloc/logalloc.mozbuild
memory/replace/logalloc/minimal/moz.build
memory/replace/logalloc/moz.build
memory/replace/logalloc/replay/Makefile.in
memory/replace/logalloc/replay/expected_output_minimal.log
memory/replace/logalloc/replay/replay.log
--- a/memory/replace/logalloc/LogAlloc.cpp
+++ b/memory/replace/logalloc/LogAlloc.cpp
@@ -181,16 +181,17 @@ replace_malloc(size_t aSize)
   AutoLock lock(sLock);
   void* ptr = sFuncs->malloc(aSize);
   if (ptr) {
     FdPrintf(sFd, "%zu %zu malloc(%zu)=%p\n", GetPid(), GetTid(), aSize, ptr);
   }
   return ptr;
 }
 
+#ifndef LOGALLOC_MINIMAL
 int
 replace_posix_memalign(void** aPtr, size_t aAlignment, size_t aSize)
 {
   AutoLock lock(sLock);
   int ret = sFuncs->posix_memalign(aPtr, aAlignment, aSize);
   if (ret == 0) {
     FdPrintf(sFd, "%zu %zu posix_memalign(%zu,%zu)=%p\n", GetPid(), GetTid(),
              aAlignment, aSize, *aPtr);
@@ -216,16 +217,17 @@ replace_calloc(size_t aNum, size_t aSize
   AutoLock lock(sLock);
   void* ptr = sFuncs->calloc(aNum, aSize);
   if (ptr) {
     FdPrintf(sFd, "%zu %zu calloc(%zu,%zu)=%p\n", GetPid(), GetTid(), aNum,
              aSize, ptr);
   }
   return ptr;
 }
+#endif
 
 void*
 replace_realloc(void* aPtr, size_t aSize)
 {
   AutoLock lock(sLock);
   void* new_ptr = sFuncs->realloc(aPtr, aSize);
   if (new_ptr || !aSize) {
     FdPrintf(sFd, "%zu %zu realloc(%p,%zu)=%p\n", GetPid(), GetTid(), aPtr,
@@ -251,26 +253,28 @@ replace_memalign(size_t aAlignment, size
   void* ptr = sFuncs->memalign(aAlignment, aSize);
   if (ptr) {
     FdPrintf(sFd, "%zu %zu memalign(%zu,%zu)=%p\n", GetPid(), GetTid(),
              aAlignment, aSize, ptr);
   }
   return ptr;
 }
 
+#ifndef LOGALLOC_MINIMAL
 void*
 replace_valloc(size_t aSize)
 {
   AutoLock lock(sLock);
   void* ptr = sFuncs->valloc(aSize);
   if (ptr) {
     FdPrintf(sFd, "%zu %zu valloc(%zu)=%p\n", GetPid(), GetTid(), aSize, ptr);
   }
   return ptr;
 }
+#endif
 
 void
 replace_jemalloc_stats(jemalloc_stats_t* aStats)
 {
   AutoLock lock(sLock);
   sFuncs->jemalloc_stats(aStats);
   FdPrintf(sFd, "%zu %zu jemalloc_stats()\n", GetPid(), GetTid());
 }
copy from memory/replace/logalloc/moz.build
copy to memory/replace/logalloc/logalloc.mozbuild
--- a/memory/replace/logalloc/moz.build
+++ b/memory/replace/logalloc/logalloc.mozbuild
@@ -1,16 +1,14 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # 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/.
 
-SharedLibrary('logalloc')
-
 SOURCES += [
     'FdPrintf.cpp',
     'LogAlloc.cpp',
 ]
 
 DISABLE_STL_WRAPPING = True
 USE_STATIC_LIBS = True
 DEFINES['MOZ_NO_MOZALLOC'] = True
@@ -30,12 +28,8 @@ else:
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 # Android doesn't have pthread_atfork, but we have our own in mozglue.
 if CONFIG['OS_TARGET'] == 'Android':
     USE_LIBS += [
         'mozglue',
     ]
-
-DIRS += [
-    'replay',
-]
new file mode 100644
--- /dev/null
+++ b/memory/replace/logalloc/minimal/moz.build
@@ -0,0 +1,11 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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/.
+
+SharedLibrary('logalloc_minimal')
+
+include('../logalloc.mozbuild')
+
+DEFINES['LOGALLOC_MINIMAL'] = True
--- a/memory/replace/logalloc/moz.build
+++ b/memory/replace/logalloc/moz.build
@@ -1,41 +1,14 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # 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/.
 
 SharedLibrary('logalloc')
 
-SOURCES += [
-    'FdPrintf.cpp',
-    'LogAlloc.cpp',
-]
-
-DISABLE_STL_WRAPPING = True
-USE_STATIC_LIBS = True
-DEFINES['MOZ_NO_MOZALLOC'] = True
-# Avoid Lock_impl code depending on mozilla::Logger.
-DEFINES['NDEBUG'] = True
-DEFINES['DEBUG'] = False
-
-# Use locking code from the chromium stack.
-if CONFIG['OS_TARGET'] == 'WINNT':
-    SOURCES += [
-        '../../../ipc/chromium/src/base/lock_impl_win.cc',
-    ]
-else:
-    SOURCES += [
-        '../../../ipc/chromium/src/base/lock_impl_posix.cc',
-    ]
-
-include('/ipc/chromium/chromium-config.mozbuild')
-
-# Android doesn't have pthread_atfork, but we have our own in mozglue.
-if CONFIG['OS_TARGET'] == 'Android':
-    USE_LIBS += [
-        'mozglue',
-    ]
+include('logalloc.mozbuild')
 
 DIRS += [
+    'minimal',
     'replay',
 ]
--- a/memory/replace/logalloc/replay/Makefile.in
+++ b/memory/replace/logalloc/replay/Makefile.in
@@ -2,35 +2,40 @@
 # 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/.
 
 include $(topsrcdir)/mozglue/build/replace_malloc.mk
 
 ifndef CROSS_COMPILE
 
 ifeq ($(OS_TARGET),WINNT)
-LOGALLOC = MOZ_REPLACE_MALLOC_LIB=$(CURDIR)/../logalloc.dll
+LOGALLOC_VAR = MOZ_REPLACE_MALLOC_LIB
 else
 ifeq ($(OS_TARGET),Darwin)
-LOGALLOC = DYLD_INSERT_LIBRARIES=$(CURDIR)/../liblogalloc.dylib
+LOGALLOC_VAR = DYLD_INSERT_LIBRARIES
 else
-LOGALLOC = LD_PRELOAD=$(CURDIR)/../$(DLL_PREFIX)logalloc$(DLL_SUFFIX)
+LOGALLOC_VAR = LD_PRELOAD
 endif
 endif
 
+LOGALLOC = $(LOGALLOC_VAR)=$(CURDIR)/../$(DLL_PREFIX)logalloc$(DLL_SUFFIX)
+LOGALLOC_MINIMAL = $(LOGALLOC_VAR)=$(CURDIR)/../minimal/$(DLL_PREFIX)logalloc_minimal$(DLL_SUFFIX)
+
 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
+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' | $(PYTHON) $(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 | $(PYTHON) $(srcdir)/logalloc_munge.py | diff -w - expected_output.log
 
+	MALLOC_LOG=1 $(LOGALLOC_MINIMAL) ./$(PROGRAM) < $< | sed -n '/jemalloc_stats/,$$p' | $(PYTHON) $(srcdir)/logalloc_munge.py | diff -w - $(srcdir)/expected_output_minimal.log
+
 endif
copy from memory/replace/logalloc/replay/replay.log
copy to memory/replace/logalloc/replay/expected_output_minimal.log
--- a/memory/replace/logalloc/replay/replay.log
+++ b/memory/replace/logalloc/replay/expected_output_minimal.log
@@ -1,18 +1,17 @@
 1 1 jemalloc_stats()
 1 1 malloc(42)=#1
 1 1 malloc(24)=#2
-2 2 malloc(42)=#1
 1 1 free(#1)
-1 1 posix_memalign(4096,1024)=#1
-1 1 calloc(4,42)=#3
+1 1 memalign(4096,1024)=#1
+1 1 malloc(168)=#3
 1 1 free(#2)
 1 1 realloc(#3,84)=#2
-1 1 aligned_alloc(512,1024)=#3
+1 1 memalign(256,1024)=#3
 1 1 memalign(512,1024)=#4
-1 1 valloc(1024)=#5
+1 1 memalign(4096,1024)=#5
 1 1 jemalloc_stats()
 1 1 free(#5)
 1 1 free(#4)
 1 1 free(#3)
 1 1 free(#2)
 1 1 free(#1)
--- a/memory/replace/logalloc/replay/replay.log
+++ b/memory/replace/logalloc/replay/replay.log
@@ -2,17 +2,17 @@ 1 1 jemalloc_stats()
 1 1 malloc(42)=#1
 1 1 malloc(24)=#2
 2 2 malloc(42)=#1
 1 1 free(#1)
 1 1 posix_memalign(4096,1024)=#1
 1 1 calloc(4,42)=#3
 1 1 free(#2)
 1 1 realloc(#3,84)=#2
-1 1 aligned_alloc(512,1024)=#3
+1 1 aligned_alloc(256,1024)=#3
 1 1 memalign(512,1024)=#4
 1 1 valloc(1024)=#5
 1 1 jemalloc_stats()
 1 1 free(#5)
 1 1 free(#4)
 1 1 free(#3)
 1 1 free(#2)
 1 1 free(#1)