Exemple #1
0
    def test_remote_exec(self):
        """
        Tests execution on a remote target
        """
        self.log.info("Testing execution on a remote target")
        hit_breakpoint = False

        s = gdb.GDBServer()
        g = gdb.GDB()

        cmd = '-file-exec-and-symbols %s' % self.return99_binary_path
        r = g.cmd(cmd)
        self.assertEqual(r.result.class_, 'done')

        cmd = 'set remote exec-file %s' % self.return99_binary_path
        r = g.cmd(cmd)
        self.assertEqual(r.result.class_, 'done')

        cmd = "-break-insert %s" % 'main'
        r = g.cmd(cmd)
        self.assertEqual(r.result.class_, 'done')

        r = g.cmd('-exec-run')

        other_messages = g.read_until_break()
        for msg in other_messages:
            parsed_msg = gdb.parse_mi(msg)
            if (hasattr(parsed_msg, 'class_')
                    and parsed_msg.class_ == 'stopped'
                    and parsed_msg.result.reason == 'breakpoint-hit'):
                hit_breakpoint = True

        self.assertTrue(hit_breakpoint)
        g.exit()
        s.exit()
Exemple #2
0
    def test_disconnect_raw(self):
        """
        Connect/disconnect repeatedly from a remote debugger using raw commands
        """
        self.log.info("Testing connecting and disconnecting repeatedly using "
                      "raw commands")
        s = gdb.GDBServer()
        g = gdb.GDB()

        # Do 100 cycle of target (kind of connects) and disconnects
        for i in xrange(0, 100):
            cmd = '-target-select extended-remote :%s' % s.port
            r = g.cmd(cmd)
            self.assertEqual(r.result.class_, 'connected')
            r = g.cmd('-target-disconnect')
            self.assertEqual(r.result.class_, 'done')

        # manual server shutdown
        cmd = '-target-select extended-remote :%s' % s.port
        r = g.cmd(cmd)
        self.assertEqual(r.result.class_, 'connected')
        r = g.cli_cmd('monitor exit')
        self.assertEqual(r.result.class_, 'done')

        g.exit()
        s.exit()
Exemple #3
0
    def __init__(self, cmd, verbose=True, allow_output_check='all',
                 shell=False, env=None):
        """
        Creates the subprocess object, stdout/err, reader threads and locks.

        :param cmd: Command line to run.
        :type cmd: str
        :param verbose: Whether to log the command run and stdout/stderr.
                        Currently unused and provided for compatibility only.
        :type verbose: bool
        :param allow_output_check: Whether to log the command stream outputs
                                   (stdout and stderr) in the test stream
                                   files. Valid values: 'stdout', for
                                   allowing only standard output, 'stderr',
                                   to allow only standard error, 'all',
                                   to allow both standard output and error
                                   (default), and 'none', to allow
                                   none to be recorded. Currently unused and
                                   provided for compatibility only.
        :type allow_output_check: str
        """

        self.cmd = cmd

        self.args = shlex.split(cmd)
        self.binary = self.args[0]
        self.binary_path = os.path.abspath(self.cmd)
        self.result = CmdResult(cmd)

        self.gdb_server = gdb.GDBServer(runtime.GDBSERVER_PATH)
        self.gdb = gdb.GDB(runtime.GDB_PATH)
        self.gdb.connect(self.gdb_server.port)
        self.gdb.set_file(self.binary)
Exemple #4
0
 def test_server_exit(self):
     """
     Tests that the server is shutdown by using a monitor exit command
     """
     self.log.info("Testing that a single server exits cleanly")
     s = gdb.GDBServer()
     s.exit()
     self.assertFalse(self.is_process_alive(s.process))
Exemple #5
0
    def test_server_stderr(self):
        self.log.info('Testing server stderr collection')
        s = gdb.GDBServer()
        s.exit()
        self.assertTrue(os.path.exists(s.stderr_path))

        stderr_lines = open(s.stderr_path, 'r').readlines()
        listening_line = "Listening on port %s\n" % s.port
        self.assertIn(listening_line, stderr_lines)
Exemple #6
0
 def test_remote(self):
     """
     Tests GDBRemote interaction with a GDBServer
     """
     s = gdb.GDBServer()
     r = gdb.GDBRemote('127.0.0.1', s.port)
     r.connect()
     r.cmd("qSupported")
     r.cmd("qfThreadInfo")
     s.exit()
Exemple #7
0
 def test_connect_multiple_clients(self):
     """
     Tests two or more connections to the same server raise an exception
     """
     self.log.info("Testing that multiple clients cannot connect at once")
     s = gdb.GDBServer()
     c1 = gdb.GDB()
     c1.connect(s.port)
     c2 = gdb.GDB()
     self.assertRaises(ValueError, c2.connect, s.port)
     s.exit()
Exemple #8
0
    def test_server_stdout(self):
        self.log.info('Testing server stdout/stderr collection')
        s = gdb.GDBServer()
        c = gdb.GDB()
        c.connect(s.port)
        c.set_file(self.return99_binary_path)
        c.run()
        s.exit()

        self.assertTrue(os.path.exists(s.stdout_path))
        self.assertTrue(os.path.exists(s.stderr_path))

        stdout_lines = open(s.stdout_path, 'r').readlines()
        self.assertIn("return 99\n", stdout_lines)
Exemple #9
0
    def test_server_stderr_redirected(self):
        s = gdb.GDBServer()
        if not s.redirected_stderr:
            s.exit()
            return

        self.log.info('Testing server stderr redirection')
        c = gdb.GDB()
        c.connect(s.port)
        c.set_file(self.return99_binary_path)
        c.run()
        s.exit()

        # only thing in stderr should be the output generated by return99
        stderr = open(s.stderr_path, 'r').read()
        self.assertEqual("testing output to stderr\n", stderr)
Exemple #10
0
    def test_disconnect(self):
        """
        Connect/disconnect repeatedly from a remote debugger using utilities
        """
        self.log.info("Testing connecting and disconnecting repeatedly")
        s = gdb.GDBServer()
        g = gdb.GDB()

        for i in xrange(0, 100):
            r = g.connect(s.port)
            self.assertEqual(r.result.class_, 'connected')
            r = g.disconnect()
            self.assertEqual(r.result.class_, 'done')

        g.exit()
        s.exit()
Exemple #11
0
    def test_multiple_servers(self):
        """
        Tests multiple server instances without any blocking or race condition
        """
        self.log.info("Testing execution of multiple GDB server instances")
        process_count = 10
        server_instances = []
        for i in xrange(0, process_count):
            s = gdb.GDBServer()
            c = gdb.GDB()
            c.connect(s.port)
            c.cmd('show-version')
            c.disconnect()
            server_instances.append(s)

        for i in xrange(0, process_count):
            self.assertTrue(self.is_process_alive(server_instances[i].process))
            server_instances[i].exit()
            self.assertFalse(self.is_process_alive(
                server_instances[i].process))