aboutsummaryrefslogtreecommitdiffstats
path: root/test/debug.py
diff options
context:
space:
mode:
authorKlement Sekera <ksekera@cisco.com>2021-03-16 12:52:12 +0100
committerOle Tr�an <otroan@employees.org>2021-04-12 10:11:36 +0000
commite263685ac82454c39eee6e2a2146dd1e02d61de8 (patch)
tree54110ae98ed5618a057859019d518ed35e76423a /test/debug.py
parent3ff6ffce032544b4ffc3e42b5e069243681ae751 (diff)
tests: support attaching to existing vpp
Introduce a new option DEBUG=attach to run a test against existing already running vpp. A new target 'make test-start-gdb' will spawn VPP in gdb for this purpose. Customization options explained in test-help. Type: improvement Change-Id: Ia160a85b33da3b2df292d44bb95729af9dd9da96 Signed-off-by: Klement Sekera <ksekera@cisco.com>
Diffstat (limited to 'test/debug.py')
-rw-r--r--test/debug.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/debug.py b/test/debug.py
index d1c89c66f3c..e79f082615d 100644
--- a/test/debug.py
+++ b/test/debug.py
@@ -4,6 +4,9 @@ import os
import pexpect
import sys
+from sanity_run_vpp import SanityTestCase
+from shutil import rmtree
+
gdb_path = '/usr/bin/gdb'
@@ -22,3 +25,40 @@ def spawn_gdb(binary_path, core_path):
else:
sys.stderr.write("Debugger '%s' does not exist or is not "
"an executable..\n" % gdb_path)
+
+
+def start_vpp_in_gdb():
+ # here we use SanityTestCase as a dummy to inherit functionality,
+ # but any test case class could be used ...
+ SanityTestCase.set_debug_flags("attach")
+ SanityTestCase.tempdir = SanityTestCase.get_tempdir()
+ if os.path.exists(SanityTestCase.tempdir):
+ if os.getenv("VPP_IN_GDB_NO_RMDIR", "0") in ["1", "y", "yes"]:
+ raise FileExistsError(
+ "Temporary directory exists and removal denied.")
+ print("Removing existing temp dir '%s'." % SanityTestCase.tempdir)
+ rmtree(SanityTestCase.tempdir)
+ print("Creating temp dir '%s'." % SanityTestCase.tempdir)
+ os.mkdir(SanityTestCase.tempdir)
+ SanityTestCase.setUpConstants()
+ vpp_cmdline = SanityTestCase.vpp_cmdline
+ if os.getenv("VPP_IN_GDB_CMDLINE", "y").lower() in ["1", "y", "yes"]:
+ print("Hacking cmdline to make VPP interactive.")
+ vpp_cmdline.insert(vpp_cmdline.index("nodaemon"), "interactive")
+ print("VPP cmdline is %s" % " ".join(vpp_cmdline))
+ print("Running GDB.")
+
+ if os.path.isfile(gdb_path) and os.access(gdb_path, os.X_OK):
+ gdb_cmdline = "%s --args %s " % (gdb_path, " ".join(vpp_cmdline))
+ print("GDB cmdline is %s" % gdb_cmdline)
+ gdb = pexpect.spawn(gdb_cmdline)
+ gdb.interact()
+ try:
+ gdb.terminate(True)
+ except:
+ pass
+ if gdb.isalive():
+ raise Exception("GDB refused to die...")
+ else:
+ sys.stderr.write("Debugger '%s' does not exist or is not "
+ "an executable..\n" % gdb_path)