drgn/tests
Omar Sandoval a5845e63d4 tests: fix race condition in stack trace tests
Stephen Brennan reported a flaky test while working on #121:

======================================================================
ERROR: test_by_task_struct (tests.helpers.linux.test_stack_trace.TestStackTrace)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/work/drgn/drgn/tests/helpers/linux/test_stack_trace.py", line 22, in test_by_task_struct
    self.assertIn("pause", str(self.prog.stack_trace(find_task(self.prog, pid))))
ValueError: cannot unwind stack of running task

The problem is that the stack trace tests wait for the thread state to
change to "S". However, the state is updated while the thread is still
technically running. For example, the pause() system call is implemented
as:

SYSCALL_DEFINE0(pause)
{
	while (!signal_pending(current)) {
		__set_current_state(TASK_INTERRUPTIBLE);
		schedule();
	}
	return -ERESTARTNOHAND;
}

If Program.stack_trace() accesses the thread after the state is changed
but before the thread has actually been scheduled out (namely, before
task_struct::on_cpu is set to 0), it will fail.

Instead, let's check /proc/$pid/syscall, which contains "running" until
the thread is completely scheduled out.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-11-04 14:13:55 -07:00
..
helpers tests: fix race condition in stack trace tests 2021-11-04 14:13:55 -07:00
__init__.py Fix some flake8 errors 2021-08-11 14:52:44 -07:00
assembler.py libdrgn: binary_buffer: handle non-canonical LEB128 numbers 2021-06-30 21:39:31 -07:00
dwarf.py Track byte order in scalar types instead of objects 2021-02-19 21:41:29 -08:00
dwarfwriter.py libdrgn: dwarf_index: handle DW_FORM_block 2021-06-30 01:34:52 -07:00
elf.py Use GPL-3.0-or-later license identifier instead of GPL-3.0+ 2021-04-03 01:10:35 -07:00
elfwriter.py Use GPL-3.0-or-later license identifier instead of GPL-3.0+ 2021-04-03 01:10:35 -07:00
libdrgn.py Fix some flake8 errors 2021-08-11 14:52:44 -07:00
test_docs.py Use GPL-3.0-or-later license identifier instead of GPL-3.0+ 2021-04-03 01:10:35 -07:00
test_dwarf.py Fix some flake8 errors 2021-08-11 14:52:44 -07:00
test_language_c.py Use GPL-3.0-or-later license identifier instead of GPL-3.0+ 2021-04-03 01:10:35 -07:00
test_lexer.py Use GPL-3.0-or-later license identifier instead of GPL-3.0+ 2021-04-03 01:10:35 -07:00
test_object.py Fix some flake8 errors 2021-08-11 14:52:44 -07:00
test_path.py Use GPL-3.0-or-later license identifier instead of GPL-3.0+ 2021-04-03 01:10:35 -07:00
test_platform.py Use GPL-3.0-or-later license identifier instead of GPL-3.0+ 2021-04-03 01:10:35 -07:00
test_program.py tests: skip PID memory read test if /proc/$pid/mem doesn't work 2021-10-28 14:41:44 -07:00
test_python.py Use GPL-3.0-or-later license identifier instead of GPL-3.0+ 2021-04-03 01:10:35 -07:00
test_serialize.py Use GPL-3.0-or-later license identifier instead of GPL-3.0+ 2021-04-03 01:10:35 -07:00
test_type.py Fix some flake8 errors 2021-08-11 14:52:44 -07:00
test_util.py Use GPL-3.0-or-later license identifier instead of GPL-3.0+ 2021-04-03 01:10:35 -07:00