Add support for testing memory allocation failures
The new control interface command TEST_ALLOC_FAIL and GET_ALLOC_FAIL can now be used to trigger memory allocation failures for testing purposes. TEST_ALLOC_FAIL sets a failure conditions with <count>:func[;func][;func]... string and GET_ALLOC_FAIL returns the current state using the same format. Whenever an allocation is made with a matching backtrace of calling functions, the count is decremented by one and once zero is reached, the allocation is forced to fail. Function names can be prefixed with either '=' or '?' to get different matching behavior. '=' requires this specific function to be the next one in the backtrace (i.e., do not skip any other functions in the list which is the default behavior). '?' allows the function to be optionally present in the backtrace. Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
52b3943c94
commit
a156ffda61
5 changed files with 231 additions and 0 deletions
|
@ -243,6 +243,52 @@ void wpa_trace_dump_funcname(const char *title, void *pc)
|
|||
wpa_trace_bfd_addr(pc);
|
||||
}
|
||||
|
||||
|
||||
size_t wpa_trace_calling_func(const char *buf[], size_t len)
|
||||
{
|
||||
bfd *abfd;
|
||||
void *btrace_res[WPA_TRACE_LEN];
|
||||
int i, btrace_num;
|
||||
size_t pos = 0;
|
||||
|
||||
if (len == 0)
|
||||
return 0;
|
||||
if (len > WPA_TRACE_LEN)
|
||||
len = WPA_TRACE_LEN;
|
||||
|
||||
wpa_trace_bfd_init();
|
||||
abfd = cached_abfd;
|
||||
if (!abfd)
|
||||
return 0;
|
||||
|
||||
btrace_num = backtrace(btrace_res, len);
|
||||
if (btrace_num < 1)
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < btrace_num; i++) {
|
||||
struct bfd_data data;
|
||||
|
||||
data.pc = (bfd_hostptr_t) btrace_res[i];
|
||||
data.found = FALSE;
|
||||
bfd_map_over_sections(abfd, find_addr_sect, &data);
|
||||
|
||||
while (data.found || !data.function) {
|
||||
if (pos > 0 ||
|
||||
os_strcmp(data.function, __func__) != 0) {
|
||||
buf[pos++] = data.function;
|
||||
if (pos == len)
|
||||
return pos;
|
||||
}
|
||||
|
||||
data.found = bfd_find_inliner_info(abfd, &data.filename,
|
||||
&data.function,
|
||||
&data.line);
|
||||
}
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
#else /* WPA_TRACE_BFD */
|
||||
|
||||
#define wpa_trace_bfd_init() do { } while (0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue