Skip to content

Commit a5c0fac

Browse files
committed
flag for dropin gdb for oss integ tests incase of crash
Signed-off-by: Manish Addanki <[email protected]>
1 parent c55bdf2 commit a5c0fac

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

build.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Usage: build.sh [options...]
2828
--configure Run cmake stage (aka configure stage).
2929
--verbose | -v Run verbose build.
3030
--debug Build for debug version.
31+
--debug-on-crash Enable interactive gdb debugging on a valkey-server crash for oss integration tests (single test mode only).
3132
--clean Clean the current build configuration (debug or release).
3233
--format Applies clang-format. (Run in dev container environment to ensure correct clang-format version)
3334
--run-tests Run all tests. Optionally, pass a test name to run: "--run-tests=<test-name>".
@@ -139,6 +140,13 @@ while [ $# -gt 0 ]; do
139140
print_usage
140141
exit 0
141142
;;
143+
--debug-on-crash)
144+
export DEBUG_ON_CRASH="yes"
145+
BUILD_CONFIG="debug" # Force debug build for better debugging
146+
shift || true
147+
echo "Debug-on-crash enabled - will drop into gdb on valkey-server crash"
148+
echo "Automatically enabling debug build for better debugging symbols"
149+
;;
142150
*)
143151
print_usage
144152
exit 1
@@ -393,6 +401,9 @@ elif [[ "${INTEGRATION_TEST}" == "yes" ]]; then
393401
if [[ "${SAN_BUILD}" == "thread" ]]; then
394402
params="${params} --tsan"
395403
fi
404+
if [[ "${DEBUG_ON_CRASH}" == "yes" ]]; then
405+
params="${params} --debug-on-crash"
406+
fi
396407
# Run will run ASan or normal tests based on the environment variable SAN_BUILD
397408
./run.sh ${params}
398409
popd >/dev/null

integration/run.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ while [ $# -gt 0 ]; do
5151
print_usage
5252
exit 0
5353
;;
54+
--debug-on-crash)
55+
shift || true
56+
export DEBUG_ON_CRASH="yes"
57+
LOG_INFO "Debug-on-crash enabled"
58+
;;
5459
*)
5560
print_usage
5661
exit 1

integration/valkey_search_test_case.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,44 @@
1414
import string
1515
import logging
1616
import shutil
17+
import subprocess
1718

1819
LOGS_DIR = "/tmp/valkey-test-framework-files"
1920

2021
if "LOGS_DIR" in os.environ:
2122
LOGS_DIR = os.environ["LOGS_DIR"]
2223

2324

25+
class DebugValkeyServerHandle(ValkeyServerHandle):
26+
"""ValkeyServerHandle that wraps valkey-server with gdb for crash debugging"""
27+
28+
def start(self, wait_for_ping=True, connect_client=True):
29+
if self.server:
30+
raise RuntimeError("Server already started")
31+
32+
# Build server command
33+
server_args = [self.valkey_path]
34+
if self.conf_file:
35+
server_args.append(self.conf_file)
36+
for k, v in self.args.items():
37+
server_args.extend([f"--{k.replace('_', '-')}", str(v)])
38+
39+
# Wrap with gdb if debug-on-crash enabled
40+
if os.environ.get("DEBUG_ON_CRASH") == "yes":
41+
cmd = ["gdb", "--ex", "run", "--args"] + server_args
42+
else:
43+
cmd = server_args
44+
45+
self.server = subprocess.Popen(cmd, cwd=self.cwd)
46+
# Standard connection handling
47+
if connect_client:
48+
self.wait_for_ready_to_accept_connections()
49+
if wait_for_ping:
50+
self.connect()
51+
52+
return self.client
53+
54+
2455
class Node:
2556
"""This class represents a valkey server instance, regardless of its role"""
2657

@@ -148,6 +179,12 @@ def get_config_file_lines(self, testdir, port) -> List[str]:
148179
for example usage."""
149180
raise NotImplementedError
150181

182+
def get_valkey_handle(self):
183+
"""Return debug-enabled valkey handle when debug-on-crash is enabled"""
184+
if os.environ.get("DEBUG_ON_CRASH") == "yes":
185+
return DebugValkeyServerHandle
186+
return ValkeyServerHandle
187+
151188
def start_server(
152189
self,
153190
port: int,

0 commit comments

Comments
 (0)