Skip to content

Commit 167975c

Browse files
author
Walter Karas
committed
Add traffic_server command line option for debugging in Au test.
1 parent ee11108 commit 167975c

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

src/traffic_server/traffic_server.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,16 @@ static int poll_timeout = -1; // No value set.
174174
static int cmd_disable_freelist = 0;
175175
static bool signal_received[NSIG];
176176

177+
/*
178+
To be able to attach with a debugger to traffic_server running in an Au test case, temporarily add the
179+
parameter block_for_debug=True to the call to Test.MakeATSProcess(). This means Au test will wait
180+
effectively indefinitely (10 hours) for traffic_server to initialize itself. Run the modified Au test,
181+
attach the debugger to the traffic_server process, set one or more breakpoints, set the variable
182+
cmd_block to 0, then continue. On linux, the command 'ps -ef | fgrep -e --block' will help identify the
183+
PID of the traffic_server process (second column of output).
184+
*/
185+
static int cmd_block = 0;
186+
177187
// 1: the main thread delayed accepting, start accepting.
178188
// 0: delay accept, wait for cache initialization.
179189
// -1: cache is already initialized, don't delay.
@@ -217,6 +227,7 @@ static ArgumentDescription argument_descriptions[] = {
217227
{"bind_stderr", '-', "Regular file to bind stderr to", "S512", &bind_stderr, "PROXY_BIND_STDERR", nullptr},
218228
{"accept_mss", '-', "MSS for client connections", "I", &accept_mss, nullptr, nullptr},
219229
{"poll_timeout", 't', "poll timeout in milliseconds", "I", &poll_timeout, nullptr, nullptr},
230+
{"block", '-', "block for debug attach", "T", &cmd_block, nullptr, nullptr},
220231
HELP_ARGUMENT_DESCRIPTION(),
221232
VERSION_ARGUMENT_DESCRIPTION(),
222233
RUNROOT_ARGUMENT_DESCRIPTION(),
@@ -1753,6 +1764,12 @@ main(int /* argc ATS_UNUSED */, const char **argv)
17531764
command_index = find_cmd_index(command_string);
17541765
command_valid = command_flag && command_index >= 0;
17551766

1767+
// Attach point when TS is blocked for debugging is in this loop.
1768+
//
1769+
while (cmd_block) {
1770+
sleep(1);
1771+
}
1772+
17561773
ink_freelist_init_ops(cmd_disable_freelist, cmd_disable_pfreelist);
17571774

17581775
#if TS_HAS_TESTS

tests/gold_tests/autest-site/trafficserver.test.ext

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ def make_id(s):
2727

2828
# this forms is for the global process define
2929

30-
30+
# 'block_for_debug', if True, causes traffic_server to run with the --block option enabled, and effectively
31+
# disables timeouts that could be triggered by running traffic_server under a debugger.
3132
def MakeATSProcess(obj, name, command='traffic_server', select_ports=True,
32-
enable_tls=False, enable_cache=True, enable_quic=False):
33+
enable_tls=False, enable_cache=True, enable_quic=False,
34+
block_for_debug=False):
3335
#####################################
3436
# common locations
3537

@@ -60,6 +62,14 @@ def MakeATSProcess(obj, name, command='traffic_server', select_ports=True,
6062
storage_dir = os.path.join(ts_dir, 'storage')
6163
cache_dir = os.path.join(ts_dir, 'cache')
6264

65+
if block_for_debug:
66+
if command.startswith('traffic_server'):
67+
command += ' --block'
68+
elif command.startswith('traffic_manager'):
69+
if '--tsArgs' not in command:
70+
command += ' --tsArgs'
71+
command += ' --block'
72+
6373
# create process
6474
p = obj.Processes.Process(name, command)
6575
#p_debug = obj.Processes.Process("port-debug", "ss --listen --tcp --process")
@@ -341,6 +351,15 @@ def MakeATSProcess(obj, name, command='traffic_server', select_ports=True,
341351
else:
342352
p.ReturnCode = 0
343353

354+
if block_for_debug:
355+
p.Env['PROXY_BLOCK'] = '1'
356+
# Cause traffic_server to wait effectviely indefinitely (10 hours) for the debugger to attach.
357+
p.StartupTimeout = 10 * 60 * 60
358+
# Hitting breakpoints may cause long delays in traffic_server transaction processing, so make
359+
# the timeout for test processes (that may interact with traffic_server) effectively forever
360+
# (10 hours).
361+
obj.Variables.Autest.Process.TimeOut = 10 * 60 * 60
362+
344363
return p
345364

346365

0 commit comments

Comments
 (0)