[issue10195] Memory allocation fault-injection?

Dave Malcolm report at bugs.python.org
Tue Oct 26 02:23:49 CEST 2010


New submission from Dave Malcolm <dmalcolm at redhat.com>:

We were chatting on #python-dev on possible ways of testing the correct handling of "MemoryError".

Attached is one idea: adding a sys._inject_malloc_failure() hook, letting you inject a memory-allocation (or reallocation) failure some number of allocations in the future:

>>> import sys
[52733 refs]
>>> 2 + 2
4
[52733 refs]
>>> sys._inject_malloc_failure(50)
[52733 refs]
>>> 2 + 2
MemoryError
[52747 refs]
>>> 2 + 2
4
[52747 refs]

I'm not sure how to make this useful; perhaps it could instead compare with the "serialno" in Objects/obmalloc.c so that you could set up a specific numbered allocation and have it fail (or perhaps a range of serial numbers, and expose "serialno" within the "sys" module?)

Another idea might be to randomly have some proportion of allocations fail.  Perhaps the test suite could have an option where it runs each set of tests in a separate subprocess, and sets a command-line switch to inject "random" malloc failures? (storing the seed, so that they're reproducible, on one machine at least).

----------
components: Tests
files: py3k-inject-malloc-failure.txt
messages: 119586
nosy: dmalcolm, pitrou
priority: normal
severity: normal
status: open
title: Memory allocation fault-injection?
type: feature request
versions: Python 3.2
Added file: http://bugs.python.org/file19365/py3k-inject-malloc-failure.txt

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10195>
_______________________________________


More information about the Python-bugs-list mailing list