1import os
2import infra.basetest
3
4
5class BaseGdb(infra.basetest.BRTest):
6    def verify_host_gdb(self, prefix="arm-linux"):
7        cmd = ["host/bin/%s-gdb" % prefix, "--version"]
8        # We don't check the return value, as it automatically raises
9        # an exception if the command returns with a non-zero value
10        infra.run_cmd_on_host(self.builddir, cmd)
11
12    def boot(self):
13        img = os.path.join(self.builddir, "images", "rootfs.cpio")
14        self.emulator.boot(arch="armv5",
15                           kernel="builtin",
16                           options=["-initrd", img,
17                                    "-net", "nic",
18                                    "-net", "user"])
19        self.emulator.login()
20
21    def verify_gdbserver(self):
22        cmd = "gdbserver --version"
23        self.assertRunOk(cmd)
24
25    def verify_gdb(self):
26        cmd = "gdb --version"
27        self.assertRunOk(cmd)
28
29
30class TestGdbHostOnlyDefault(BaseGdb):
31    config = \
32        infra.basetest.MINIMAL_CONFIG + \
33        """
34        BR2_arm=y
35        BR2_TOOLCHAIN_EXTERNAL=y
36        BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y
37        BR2_PACKAGE_HOST_GDB=y
38        """
39
40    def test_run(self):
41        self.verify_host_gdb()
42
43
44class TestGdbHostOnlyAllFeatures(BaseGdb):
45    config = \
46        infra.basetest.MINIMAL_CONFIG + \
47        """
48        BR2_arm=y
49        BR2_TOOLCHAIN_EXTERNAL=y
50        BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y
51        BR2_PACKAGE_HOST_GDB=y
52        BR2_PACKAGE_HOST_GDB_TUI=y
53        BR2_PACKAGE_HOST_GDB_PYTHON3=y
54        BR2_PACKAGE_HOST_GDB_SIM=y
55        """
56
57    def test_run(self):
58        self.verify_host_gdb()
59
60
61class TestGdbserverOnly(BaseGdb):
62    config = \
63        """
64        BR2_arm=y
65        BR2_TOOLCHAIN_EXTERNAL=y
66        BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y
67        BR2_PACKAGE_GDB=y
68        BR2_TARGET_ROOTFS_CPIO=y
69        # BR2_TARGET_ROOTFS_TAR is not set
70        """
71
72    def test_run(self):
73        self.boot()
74        self.verify_gdbserver()
75
76
77class TestGdbFullTarget(BaseGdb):
78    config = \
79        """
80        BR2_arm=y
81        BR2_TOOLCHAIN_EXTERNAL=y
82        BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y
83        BR2_PACKAGE_GDB=y
84        BR2_PACKAGE_GDB_DEBUGGER=y
85        BR2_TARGET_ROOTFS_CPIO=y
86        # BR2_TARGET_ROOTFS_TAR is not set
87        """
88
89    def test_run(self):
90        self.boot()
91        self.verify_gdb()
92
93
94class TestGdbArc(BaseGdb):
95    config = \
96        """
97        BR2_arcle=y
98        BR2_archs4x_rel31=y
99        BR2_TOOLCHAIN_EXTERNAL=y
100        BR2_PACKAGE_HOST_GDB=y
101        BR2_PACKAGE_GDB=y
102        BR2_PACKAGE_GDB_SERVER=y
103        BR2_PACKAGE_GDB_DEBUGGER=y
104        """
105
106    def test_run(self):
107        self.verify_host_gdb("arc-linux")
108