Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug: use TCL-RPC to fetch results of OpenOCD commands instead of parsing log file #522

Merged

Conversation

aap-sc
Copy link
Collaborator

@aap-sc aap-sc commented Nov 8, 2023

Quick and dirty fix for #520

@aap-sc
Copy link
Collaborator Author

aap-sc commented Nov 8, 2023

@timsifive could you please take a look?

@aap-sc
Copy link
Collaborator Author

aap-sc commented Nov 8, 2023

Note to reviewers:

  1. The patch requires nc (netcat) utility to be present on a host system. I hope this is not a big deal since nc is pretty lightweight utility.
  2. It looks like I forgot to cleanup resources. If there is no objections against the suggested approach - I'll update the patch (I think I need to extend __del__ method of OpenOCD class to close the spawned process).

Copy link
Collaborator

@timsifive timsifive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Using nc is a hack, but less of a hack than reading the logfile so it's an improvement.

I assume this fixes the failures you've been seeing.

debug/testlib.py Outdated
Comment on lines 432 to 433
"""Write the command to OpenOCD's stdin. Return the output of the
command, minus the prompt."""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment needs to be updated

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

raise TestLibError("unexpected re-definition of TCL-RPC port")
self.tclrpc_port = int(m.group(3))

if self.tclrpc_port and (len(self.gdb_ports) > 0):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is not introduced by this patch, but I think it worth pointing out. This condition relies on all GDB ports being reported by OpenOCD prior to TCL-RPC port.
In turn this depends on whether the call to init is implicit or explicit:

> openocd ... -c "gdb_port 0" -c "tcl_port 0"  -c "telnet_port disabled" |& grep 'Listening'
Info : Listening on port 41587 for tcl connections
Info : Listening on port 40911 for gdb connections
Info : Listening on port 33639 for gdb connections
> openocd ... -c "gdb_port 0" -c "tcl_port 0"  -c "telnet_port disabled" -c init |& grep 'Listening'
Info : Listening on port 40575 for gdb connections
Info : Listening on port 38511 for gdb connections
Info : Listening on port 35989 for tcl connections

Currently, this works, since all the configs in debug/targets/RISC-V call init explicitly.
Wouldn't it be better to add some comment regarding this behavior?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not add anything unnecessary to this patch. It's fairly urgent since without this fix, OpenOCD development is hamstrung. It's better to merge this soon than it is to disable the tests while we add more improvements to this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've already addressed this. Just added a comment

debug/testlib.py Outdated
Comment on lines 388 to 397
m = self.expect(
rb"(Listening on port (\d+) for gdb connections|"
rb"tcl server disabled)",
rb"Listening on port (\d+) for tcl connections)",
message="Waiting for OpenOCD to start up...")
if b"gdb" in m.group(1):
if b"gdb connections" in m.group(1):
self.gdb_ports.append(int(m.group(2)))
else:
elif b"tcl connections" in m.group(1):
if self.tclrpc_port:
raise TestLibError("unexpected re-definition of TCL-RPC port")
self.tclrpc_port = int(m.group(3))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest using named match groups and avoid searching a sub-string in a match:

                m = self.expect(
                        rb"Listening on port (?P<port>\d+) for (?P<server>(?:gdb)|(?:tcl)) connections",
                        message="Waiting for OpenOCD to start up...")
                if m["server"] == b"gdb":
                    self.gdb_ports.append(int(m["port"]))
                ...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moreover, since the regular expression has matched, elif can be replaced with else and an assertion, if you like.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed. I haven't replaced elif with else, though

@timsifive
Copy link
Collaborator

Can you address the pylint complaints for this PR?

@aap-sc
Copy link
Collaborator Author

aap-sc commented Nov 9, 2023

Can you address the pylint complaints for this PR

Sure! I'm in the middle of it...

@aap-sc
Copy link
Collaborator Author

aap-sc commented Nov 9, 2023

Can you address the pylint complaints for this PR?

Done.

Note: also addressed comments by @en-sc

@timsifive
Copy link
Collaborator

pylint is still failing. (I'm commenting here because I'm not sure if you get notified about that automatically.)

@aap-sc
Copy link
Collaborator Author

aap-sc commented Nov 9, 2023

pylint is still failing. (I'm commenting here because I'm not sure if you get notified about that automatically.)

My bad. I was in a hurry and submitted an update as soon as I've tested these changes with OpenOCD. Never bothered to check if a new issue is introduced.

Addressed.

@timsifive timsifive merged commit bd0a19c into riscv-software-src:master Nov 10, 2023
2 checks passed
timsifive added a commit to riscv-software-src/riscv-isa-sim that referenced this pull request Nov 10, 2023
To get riscv-software-src/riscv-tests#522, which
fixes an intermittent failure.
@timsifive
Copy link
Collaborator

They're all running now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants