crypto crypto-openssl: support hashing operations
[vpp.git] / test / debug.py
1 """ debug utilities """
2
3 import os
4 import pexpect
5 import sys
6
7 from sanity_run_vpp import SanityTestCase
8 from shutil import rmtree
9
10 gdb_path = '/usr/bin/gdb'
11
12
13 def spawn_gdb(binary_path, core_path):
14     if os.path.isfile(gdb_path) and os.access(gdb_path, os.X_OK):
15         # automatically attach gdb
16         gdb_cmdline = "%s %s %s" % (gdb_path, binary_path, core_path)
17         gdb = pexpect.spawn(gdb_cmdline)
18         gdb.interact()
19         try:
20             gdb.terminate(True)
21         except:
22             pass
23         if gdb.isalive():
24             raise Exception("GDB refused to die...")
25     else:
26         sys.stderr.write("Debugger '%s' does not exist or is not "
27                          "an executable..\n" % gdb_path)
28
29
30 def start_vpp_in_gdb():
31     # here we use SanityTestCase as a dummy to inherit functionality,
32     # but any test case class could be used ...
33     SanityTestCase.set_debug_flags("attach")
34     SanityTestCase.tempdir = SanityTestCase.get_tempdir()
35     if os.path.exists(SanityTestCase.tempdir):
36         if os.getenv("VPP_IN_GDB_NO_RMDIR", "0") in ["1", "y", "yes"]:
37             raise FileExistsError(
38                 "Temporary directory exists and removal denied.")
39         print("Removing existing temp dir '%s'." % SanityTestCase.tempdir)
40         rmtree(SanityTestCase.tempdir)
41     print("Creating temp dir '%s'." % SanityTestCase.tempdir)
42     os.mkdir(SanityTestCase.tempdir)
43     SanityTestCase.setUpConstants()
44     vpp_cmdline = SanityTestCase.vpp_cmdline
45     if os.getenv("VPP_IN_GDB_CMDLINE", "y").lower() in ["1", "y", "yes"]:
46         print("Hacking cmdline to make VPP interactive.")
47         vpp_cmdline.insert(vpp_cmdline.index("nodaemon"), "interactive")
48     print("VPP cmdline is %s" % " ".join(vpp_cmdline))
49     print("Running GDB.")
50
51     if os.path.isfile(gdb_path) and os.access(gdb_path, os.X_OK):
52         gdb_cmdline = "%s --args %s " % (gdb_path, " ".join(vpp_cmdline))
53         print("GDB cmdline is %s" % gdb_cmdline)
54         gdb = pexpect.spawn(gdb_cmdline)
55         gdb.interact()
56         try:
57             gdb.terminate(True)
58         except:
59             pass
60         if gdb.isalive():
61             raise Exception("GDB refused to die...")
62     else:
63         sys.stderr.write("Debugger '%s' does not exist or is not "
64                          "an executable..\n" % gdb_path)