Skip to content

Commit

Permalink
Remove all valgrind stuff
Browse files Browse the repository at this point in the history
It used to be quite good if rather noisy.  The sanitizers are
a lot better and I can compile everything (except libc) using
them.
  • Loading branch information
rogerbinns committed Nov 25, 2024
1 parent e20bb9b commit 68679c1
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 163 deletions.
27 changes: 1 addition & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ GENDOCS = \
doc/fts.rst

.PHONY : help all tagpush clean doc docs build_ext build_ext_debug coverage pycoverage test test_debug fulltest linkcheck unwrapped \
publish stubtest showsymbols compile-win setup-wheel source_nocheck source release pydebug pyvalgrind valgrind valgrind1 \
publish stubtest showsymbols compile-win setup-wheel source_nocheck source release pydebug \
fossil doc-depends dev-depends docs-no-fetch compile-win-one langserver

help: ## Show this help
Expand Down Expand Up @@ -256,8 +256,6 @@ PYDEBUG_VER=3.12.7
PYDEBUG_DIR=/space/pydebug
PYTHREAD_VER=$(PYDEBUG_VER)
PYTHREAD_DIR=/space/pythread
PYVALGRIND_VER=$(PYDEBUG_VER)
PYVALGRIND_DIR=/space/pyvalgrind
# This must end in slash
PYDEBUG_WORKDIR=/space/apsw-test/

Expand All @@ -278,29 +276,6 @@ pythread: ## Build a debug python including thread sanitizer. Extensions it bui
$(MAKE) -j install
$(MAKE) dev-depends PYTHON=$(PYTHREAD_DIR)/bin/python3

pyvalgrind: ## Build a debug python with valgrind integration
set -x && cd "$(PYVALGRIND_DIR)" && find . -delete && \
curl https://www.python.org/ftp/python/`echo $(PYVALGRIND_VER) | sed 's/[abr].*//'`/Python-$(PYVALGRIND_VER).tar.xz | tar xfJ - && \
cd Python-$(PYVALGRIND_VER) && \
./configure --with-valgrind --without-pymalloc --with-pydebug --prefix="$(PYVALGRIND_DIR)" \
--without-freelists --with-assertions && \
$(MAKE) -j install
$(MAKE) dev-depends PYTHON=$(PYVALGRIND_DIR)/bin/python3


valgrind: $(PYVALGRIND_DIR)/bin/python3 src/faultinject.h ## Runs multiple iterations with valgrind to catch leaks
$(PYVALGRIND_DIR)/bin/python3 setup.py fetch --version=$(SQLITEVERSION) --all && \
env APSWTESTPREFIX=$(PYDEBUG_WORKDIR) PATH=$(PYVALGRIND_DIR)/bin:$$PATH APSW_TEST_ITERATIONS=6 tools/valgrind.sh 2>&1 | tee l6 && \
env APSWTESTPREFIX=$(PYDEBUG_WORKDIR) PATH=$(PYVALGRIND_DIR)/bin:$$PATH APSW_TEST_ITERATIONS=7 tools/valgrind.sh 2>&1 | tee l7 && \
env APSWTESTPREFIX=$(PYDEBUG_WORKDIR) PATH=$(PYVALGRIND_DIR)/bin:$$PATH APSW_TEST_ITERATIONS=8 tools/valgrind.sh 2>&1 | tee l8

valgrind1: $(PYVALGRIND_DIR)/bin/python3 src/faultinject.h ## valgrind check (one iteration)
$(PYVALGRIND_DIR)/bin/python3 setup.py fetch --version=$(SQLITEVERSION) --all && \
env APSWTESTPREFIX=$(PYDEBUG_WORKDIR) PATH=$(PYVALGRIND_DIR)/bin:$$PATH APSW_TEST_ITERATIONS=1 tools/valgrind.sh

valgrind_no_fetch: $(PYVALGRIND_DIR)/bin/python3 src/faultinject.h ## valgrind check (one iteration) - does not fetch SQLite, using existing directory
env APSWTESTPREFIX=$(PYDEBUG_WORKDIR) PATH=$(PYVALGRIND_DIR)/bin:$$PATH APSW_TEST_ITERATIONS=1 tools/valgrind.sh

langserver: ## Language server integration json
$(PYTHON) tools/gencompilecommands.py > compile_commands.json

Expand Down
50 changes: 23 additions & 27 deletions apsw/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ class big:
del big

def testMemoryLeaks(self):
"MemoryLeaks: Run with a memory profiler such as valgrind and debug Python"
"MemoryLeaks: Run with a memory sanitizer and debug Python"
# make and toss away a bunch of db objects, cursors, functions etc - if you use memory profiling then
# simple memory leaks will show up
c = self.db.cursor()
Expand Down Expand Up @@ -8016,36 +8016,32 @@ def testBackup(self):
self.assertRaises(ValueError, self.db.backup, "main", self.db, "it doesn't care what is here")

# try and get inuse error
if not os.getenv("APSW_VALGRIND"):
# valgrind only runs one thread at a time (kinda like the GIL)
# which makes this race condition almost impossible to cause
# so we skip
dbt = apsw.Connection(":memory:")
vals = {"stop": False, "raised": False}

def wt():
# worker thread spins grabbing and releasing inuse flag
while not vals["stop"]:
try:
dbt.set_busy_timeout(100)
except apsw.ThreadingViolationError:
# this means main thread grabbed inuse first
pass
dbt = apsw.Connection(":memory:")
vals = {"stop": False, "raised": False}

runtime = float(os.getenv("APSW_HEAVY_DURATION")) if os.getenv("APSW_HEAVY_DURATION") else 30
t = ThreadRunner(wt)
t.start()
b4 = time.time()
# try to get inuse error
try:
def wt():
# worker thread spins grabbing and releasing inuse flag
while not vals["stop"]:
try:
while not vals["stop"] and time.time() - b4 < runtime:
self.db.backup("main", dbt, "main").close()
dbt.set_busy_timeout(100)
except apsw.ThreadingViolationError:
vals["stop"] = True
vals["raised"] = True
finally:
# this means main thread grabbed inuse first
pass

runtime = float(os.getenv("APSW_HEAVY_DURATION")) if os.getenv("APSW_HEAVY_DURATION") else 30
t = ThreadRunner(wt)
t.start()
b4 = time.time()
# try to get inuse error
try:
try:
while not vals["stop"] and time.time() - b4 < runtime:
self.db.backup("main", dbt, "main").close()
except apsw.ThreadingViolationError:
vals["stop"] = True
vals["raised"] = True
finally:
vals["stop"] = True

# standard usage
db2 = apsw.Connection(":memory:")
Expand Down
6 changes: 3 additions & 3 deletions doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,9 @@ extra code that deliberately induces extra conditions such as memory
allocation failures, SQLite returning error codes, Python APIs
erroring etc. That brings coverage up to 99.6% of the code.

A memory checker `Valgrind <https://valgrind.org>`_ and `compiler
sanitizer options <https://en.wikipedia.org/wiki/AddressSanitizer>`__
are also used for further validation.
`Compiler sanitizers options
<https://en.wikipedia.org/wiki/AddressSanitizer>`__ are also used for
further validation.

To ensure compatibility with the various Python versions, a script
downloads and compiles all supported Python versions in both debug and
Expand Down
2 changes: 1 addition & 1 deletion src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ For example, to use for Connection and xCreate:
The implementation uses a sentinel on the stack with a magic number on
it. That way if the call exits without CALL_LEAVE a later check will
assert fail or cause a valgrind error.
assert fail or cause a sanitizer error.
*/

Expand Down
55 changes: 0 additions & 55 deletions tools/find_in_valgrind.py

This file was deleted.

51 changes: 0 additions & 51 deletions tools/valgrind.sh

This file was deleted.

0 comments on commit 68679c1

Please sign in to comment.