blob: 98cbcd132ca53a0f1fb897a9ecc41919e80e84ed [file] [log] [blame]
Andrew Geissler95ac1b82021-03-31 14:34:31 -05001From 83c24e31df6932a6d4fced179050c6d8d8c6f3b5 Mon Sep 17 00:00:00 2001
2From: Philippe Waroquiers <philippe.waroquiers@skynet.be>
3Date: Sun, 7 Mar 2021 22:29:27 +0100
4Subject: [PATCH] Fix nlcontrolc.vgtest hanging on newer glibc and/or arm64
5
6This test verifies that GDB can interrupt a process with all threads
7blocked in a long select syscall.
8The test used to terminate by having GDB modifying the select argument.
9However, modifying the select argument works only for specific arch
10and/or specific versions of glibc.
11The test then blocks on other architectures/glibc versions.
12
13The previous version of the test was:
14 * first launching sleepers so as to have all threads blocked in long select
15 * interrupting these threads
16 * changing the select time arg so that the threads burn cpu
17 * and then change variables to have the program exit.
18
19The new version does:
20 * first launches sleepers so that all threads are burning cpu.
21 * interrupting these threads
22 * change the local variables of sleepers so that the threads will
23 block in a long select syscall
24 * interrupt these threads
25 * kill the program.
26
27With this new version, we still check the behaviour of gdb+vgdbserver
28for both burning and sleep threads, but without having the termination
29depending on modifying select syscall argument.
30
31Tested on debian amd64 and on ubuntu arm64 (to check the test does not hang
32on an arm64 platform).
33
34Upstream-Status: Backport
35
36From commit on master:
37c79180a3afcf65902e578646c3b716cc749db406
38
39Signed-off-by: Yi Fan Yu <yifan.yu@windriver.com>
40---
41 gdbserver_tests/nlcontrolc.stderr.exp | 4 +-
42 gdbserver_tests/nlcontrolc.stdinB.gdb | 57 +++++++++++++++-----------
43 gdbserver_tests/nlcontrolc.stdoutB.exp | 25 ++++++-----
44 gdbserver_tests/nlcontrolc.vgtest | 12 +++---
45 4 files changed, 56 insertions(+), 42 deletions(-)
46
47diff --git a/gdbserver_tests/nlcontrolc.stderr.exp b/gdbserver_tests/nlcontrolc.stderr.exp
48index ac75bb3da..b63a9a988 100644
49--- a/gdbserver_tests/nlcontrolc.stderr.exp
50+++ b/gdbserver_tests/nlcontrolc.stderr.exp
51@@ -3,9 +3,9 @@ Nulgrind, the minimal Valgrind tool
52 (action at startup) vgdb me ...
53
54
55-loops/sleep_ms/burn/threads_spec/affinity: 1000000000 1000000000 1000000000 BSBSBSBS 1
56+loops/sleep_ms/burn/threads_spec/affinity: 1000000000 0 100000 BSBSBSBS 1
57 Brussels ready to sleep and/or burn
58 London ready to sleep and/or burn
59 Petaouchnok ready to sleep and/or burn
60 main ready to sleep and/or burn
61-
62+Gdb request to kill this process
63diff --git a/gdbserver_tests/nlcontrolc.stdinB.gdb b/gdbserver_tests/nlcontrolc.stdinB.gdb
64index 667ece18d..ea4fcd530 100644
65--- a/gdbserver_tests/nlcontrolc.stdinB.gdb
66+++ b/gdbserver_tests/nlcontrolc.stdinB.gdb
67@@ -9,32 +9,43 @@ shell ./simulate_control_c --vgdb-prefix=./vgdb-prefix-nlcontrolc 1 grep main nl
68 #
69 continue
70 #
71-# Here, all tasks should be blocked in a loooonnnng select, all in WaitSys
72-info threads
73-# We will unblock them by changing their timeout argument
74-# To avoid going into the frame where the timeval arg is,
75-# it has been defined as global variables, as the nr
76-# of calls on the stack differs between 32bits and 64bits,
77-# and/or between OS.
78-# ensure select finishes in a few milliseconds max:
79-p t[0].tv_sec = 0
80-p t[1].tv_sec = 0
81-p t[2].tv_sec = 0
82-p t[3].tv_sec = 0
83-#
84-# We will change the burning parameters in a few seconds
85+# Threads are burning cpu now
86+# We would like to fully test info threads here, but which thread are Runnable
87+# or Yielding is unpredictable. With a recent enough gdb, check the nr of
88+# threads by state using pipe commands and grep/wc.
89+init-if-undefined $_gdb_major = 0
90+init-if-undefined $_gdb_minor = 0
91+if $_gdb_major >= 9
92+ | info threads | grep VgTs_Runnable | wc -l
93+ | info threads | grep VgTs_Yielding | wc -l
94+else
95+ echo 1\n
96+ echo 3\n
97+end
98+# We change the variables so that all the threads are blocked in a syscall
99+p burn = 0
100+p sleepms = 1000000
101+#
102+#
103 shell ./simulate_control_c --vgdb-prefix=./vgdb-prefix-nlcontrolc 1 grep changed nlcontrolc.stdoutB.out
104 #
105-echo changed burning parameters\n
106+echo changed burning parameters to sleeping parameters\n
107 continue
108+# Here, all tasks should be blocked in a loooonnnng select, all in WaitSys
109+info threads
110+# We reset the sleepms to 0. The threads should still be blocked in the syscall
111+p sleepms = 0
112+shell ./simulate_control_c --vgdb-prefix=./vgdb-prefix-nlcontrolc 1 grep reset nlcontrolc.stdoutB.out
113 #
114-# Threads are burning cpu now
115-# We would like to test info threads here, but which thread are Runnable or Yielding
116-# is unpredictable.
117-# info threads
118-p burn = 0
119-p loops = 0
120-p report_finished = 0
121+echo reset to sleeping parameters\n
122 continue
123-# and the process should stop very quickly now
124+# threads should still be blocked in a loooonnnng select, all in WaitSys
125+info threads
126+if $_gdb_major >= 9
127+ | info threads | grep VgTs_WaitSys | wc -l
128+else
129+ echo 4\n
130+end
131+# Make the process die.
132+kill
133 quit
134diff --git a/gdbserver_tests/nlcontrolc.stdoutB.exp b/gdbserver_tests/nlcontrolc.stdoutB.exp
135index e8a5ff8ba..2e8dc8498 100644
136--- a/gdbserver_tests/nlcontrolc.stdoutB.exp
137+++ b/gdbserver_tests/nlcontrolc.stdoutB.exp
138@@ -1,18 +1,21 @@
139 Continuing.
140 Program received signal SIGTRAP, Trace/breakpoint trap.
141+do_burn () at sleepers.c:41
142+41 for (i = 0; i < burn; i++) loopnr++;
143+ > > > > > >1
144+3
145+$1 = 0
146+$2 = 1000000
147+changed burning parameters to sleeping parameters
148+Continuing.
149+Program received signal SIGTRAP, Trace/breakpoint trap.
150 0x........ in syscall ...
151 * 1 Thread .... (tid 1 VgTs_WaitSys) 0x........ in syscall ...
152-$1 = 0
153-$2 = 0
154 $3 = 0
155-$4 = 0
156-changed burning parameters
157+reset to sleeping parameters
158 Continuing.
159 Program received signal SIGTRAP, Trace/breakpoint trap.
160-do_burn () at sleepers.c:41
161-41 for (i = 0; i < burn; i++) loopnr++;
162-$5 = 0
163-$6 = 0
164-$7 = 0
165-Continuing.
166-Program exited normally.
167+0x........ in syscall ...
168+* 1 Thread .... (tid 1 VgTs_WaitSys) 0x........ in syscall ...
169+ > > > >4
170+Kill the program being debugged? (y or n) [answered Y; input not from terminal]
171diff --git a/gdbserver_tests/nlcontrolc.vgtest b/gdbserver_tests/nlcontrolc.vgtest
172index bb5308403..09edfcaba 100644
173--- a/gdbserver_tests/nlcontrolc.vgtest
174+++ b/gdbserver_tests/nlcontrolc.vgtest
175@@ -4,16 +4,16 @@
176 # and modify some variables
177 # the user can control-c an process with all threads in Running/Yielding
178 # and modify some variables
179-# sleepers is started with argument so that it will compute during ages.
180-# The variable modifications means it will exit in a reasonable time.
181-# This test is disabled on Solaris because modifying select/poll/ppoll timeout
182-# has no effect if a thread is already blocked in that syscall.
183+# sleepers is started so that it burns CPU.
184+# We then interrupt the process.
185+# We modify variables so that instead of burning cpu, sleepers blocks
186+# all threads in a select syscall.
187 prog: sleepers
188-args: 1000000000 1000000000 1000000000 BSBSBSBS 1
189+args: 1000000000 0 100000 BSBSBSBS 1
190 vgopts: --tool=none --vgdb=yes --vgdb-error=0 --vgdb-prefix=./vgdb-prefix-nlcontrolc
191 stderr_filter: filter_stderr
192 # Bug 338633 nlcontrol hangs on arm64 currently.
193-prereq: test -e gdb -a -f vgdb.invoker && ! ../tests/arch_test arm64 && ! ../tests/os_test solaris
194+prereq: test -e gdb -a -f vgdb.invoker && ! ../tests/os_test solaris
195 progB: gdb
196 argsB: --quiet -l 60 --nx ./sleepers
197 stdinB: nlcontrolc.stdinB.gdb
198--
1992.29.2
200