<div dir="ltr"><div><div>Hi,<br><br></div>Here it is used to suppress the timeout, which just kills the client during debugging if you forget to turn it off.<br>Since it is just a way how to workaround forgetting of humans (read: me xD) I think that I don't care about this patch much.<br></div><div>If no-one else want this, I'm OK with rejecting this patch.<br></div><div><br></div><div>Thanks,<br>Marek<br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 28 November 2014 at 12:54, Pekka Paalanen <span dir="ltr"><<a href="mailto:ppaalanen@gmail.com" target="_blank">ppaalanen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Wed, 19 Nov 2014 12:20:31 +0100<br>
Marek Chalupa <<a href="mailto:mchqwerty@gmail.com">mchqwerty@gmail.com</a>> wrote:<br>
<br>
> Copy function from libinput/test/litest.c is_debugger_detached()<br>
> and use it in our test-runner. If debugger is attached, turn off<br>
> leak checks and timeouts automatically.<br>
><br>
> Revision of libinput: 028513a0a723e97941c39c4aeb17433198723913<br>
><br>
> Signed-off-by: Marek Chalupa <<a href="mailto:mchqwerty@gmail.com">mchqwerty@gmail.com</a>><br>
> ---<br>
> tests/test-runner.c | 43 +++++++++++++++++++++++++++++++++++++++++--<br>
> 1 file changed, 41 insertions(+), 2 deletions(-)<br>
><br>
> diff --git a/tests/test-runner.c b/tests/test-runner.c<br>
> index 1373225..63b25ed 100644<br>
> --- a/tests/test-runner.c<br>
> +++ b/tests/test-runner.c<br>
> @@ -33,6 +33,7 @@<br>
> #include <dlfcn.h><br>
> #include <errno.h><br>
> #include <limits.h><br>
> +#include <sys/ptrace.h><br>
><br>
> #include "test-runner.h"<br>
><br>
> @@ -224,6 +225,39 @@ rmdir_xdg_runtime_dir(void)<br>
> perror("Cleaning XDG_RUNTIME_DIR");<br>
> }<br>
><br>
> +<br>
> +/* this function is taken from libinput/test/litest.c<br>
> + * (rev 028513a0a723e97941c39)<br>
> + */<br>
> +static int<br>
> +is_debugger_attached(void)<br>
> +{<br>
> + int status;<br>
> + int rc;<br>
> + int pid = fork();<br>
> +<br>
> + if (pid == -1)<br>
> + return 0;<br>
> +<br>
> + if (pid == 0) {<br>
> + int ppid = getppid();<br>
> + if (ptrace(PTRACE_ATTACH, ppid, NULL, NULL) == 0) {<br>
> + waitpid(ppid, NULL, 0);<br>
> + ptrace(PTRACE_CONT, NULL, NULL);<br>
> + ptrace(PTRACE_DETACH, ppid, NULL, NULL);<br>
> + rc = 0;<br>
> + } else {<br>
> + rc = 1;<br>
> + }<br>
> + _exit(rc);<br>
> + } else {<br>
> + waitpid(pid, &status, 0);<br>
> + rc = WEXITSTATUS(status);<br>
> + }<br>
> +<br>
> + return rc;<br>
> +}<br>
> +<br>
> int main(int argc, char *argv[])<br>
> {<br>
> const struct test *t;<br>
> @@ -237,8 +271,13 @@ int main(int argc, char *argv[])<br>
> sys_malloc = dlsym(RTLD_NEXT, "malloc");<br>
> sys_free = dlsym(RTLD_NEXT, "free");<br>
><br>
> - leak_check_enabled = !getenv("WAYLAND_TESTS_NO_LEAK_CHECK");<br>
> - timeouts_enabled = !getenv("WAYLAND_TESTS_NO_TIMEOUTS");<br>
> + if (is_debugger_attached()) {<br>
> + leak_check_enabled = 0;<br>
> + timeouts_enabled = 0;<br>
> + } else {<br>
> + leak_check_enabled = !getenv("WAYLAND_TESTS_NO_LEAK_CHECK");<br>
> + timeouts_enabled = !getenv("WAYLAND_TESTS_NO_TIMEOUTS");<br>
> + }<br>
><br>
> if (argc == 2 && strcmp(argv[1], "--help") == 0)<br>
> usage(argv[0], EXIT_SUCCESS);<br>
<br>
</div></div>Hi,<br>
<br>
I'm a little wary of this kind of magic. You can't force-enable these<br>
settings under a debugger now, but I'm not sure anyone would want to.<br>
<br>
Would need a trivial rebase.<br>
<br>
Libinput seems use the debugger detection for preventing test forking,<br>
and we have our own way for that by running a single sub-test.<br>
<br>
Do we care enough to have this patch?<br>
<br>
<br>
Thanks,<br>
pq<br>
</blockquote></div><br></div>