diff options
author | Havoc Pennington <hp@redhat.com> | 2003-02-14 04:54:55 +0000 |
---|---|---|
committer | Havoc Pennington <hp@redhat.com> | 2003-02-14 04:54:55 +0000 |
commit | 07a795f1db3b09beeec647643a4f263f617bc371 (patch) | |
tree | 4f557fce8ee2012dc7fcd40587d8d40b20d112e3 /dbus/dbus-internals.c | |
parent | b544e59358251f0811c9fe35c149a67d5deafdba (diff) |
2003-02-14 Havoc Pennington <hp@pobox.com>
* dbus/dbus-mempool.c: fail if the debug functions so indicate
* dbus/dbus-memory.c: fail if the debug functions indicate we
should
* dbus/dbus-internals.c (_dbus_set_fail_alloc_counter)
(_dbus_decrement_fail_alloc_counter): debug functions to
simulate memory allocation failures
Diffstat (limited to 'dbus/dbus-internals.c')
-rw-r--r-- | dbus/dbus-internals.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/dbus/dbus-internals.c b/dbus/dbus-internals.c index 78a1b687..d51f5a97 100644 --- a/dbus/dbus-internals.c +++ b/dbus/dbus-internals.c @@ -391,4 +391,56 @@ _dbus_type_to_string (int type) } } +#ifdef DBUS_BUILD_TESTS +static int fail_alloc_counter = _DBUS_INT_MAX; +/** + * Sets the number of allocations until we simulate a failed + * allocation. If set to 0, the next allocation to run + * fails; if set to 1, one succeeds then the next fails; etc. + * Set to _DBUS_INT_MAX to not fail anything. + * + * @param until_next_fail number of successful allocs before one fails + */ +void +_dbus_set_fail_alloc_counter (int until_next_fail) +{ + fail_alloc_counter = until_next_fail; +} + +/** + * Gets the number of successful allocs until we'll simulate + * a failed alloc. + * + * @returns current counter value + */ +int +_dbus_get_fail_alloc_counter (void) +{ + return fail_alloc_counter; +} + +/** + * Called when about to alloc some memory; if + * it returns #TRUE, then the allocation should + * fail. If it returns #FALSE, then the allocation + * should not fail. + * + * @returns #TRUE if this alloc should fail + */ +dbus_bool_t +_dbus_decrement_fail_alloc_counter (void) +{ + if (fail_alloc_counter <= 0) + { + fail_alloc_counter = _DBUS_INT_MAX; + return TRUE; + } + else + { + fail_alloc_counter -= 1; + return FALSE; + } +} +#endif /* DBUS_BUILD_TESTS */ + /** @} */ |