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

Add start_and_break_on decorator to simplify gdb tests #2146

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

gsingh93
Copy link
Member

@gsingh93 gsingh93 commented May 3, 2024

@start_and_break_on takes a binary to run, a list of breakpoints, and optionally arguments to pass to the binary. It performs the same setup start_binary does, but also adds the breakpoints and then continues the program. This lets us remove some boilerplate from tests, as shown in the plist tests.

@gsingh93 gsingh93 requested a review from disconnect3d May 3, 2024 07:01
from . import binaries


def start_and_break_on(binary, bps, *args):
Copy link
Member

Choose a reason for hiding this comment

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

Why don't we make it a pytest fixture instead of a decorator?

Copy link
Member Author

Choose a reason for hiding this comment

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

Two reasons:

  1. A function that the user could just import themselves is not a good pytest fixture. The way we use start_binary right now is not great. If we instead automatically started it for them and passed in the process object, that would be a better fixture, but then the user can't customize the binary, breakpoints, etc.
  2. Even if we pass this function in as a fixture, the user still has to call it as one of the first things they do. Tests are usually better when the initialization has happened before the function is even called, which can be done with a decorator.

Copy link
Member Author

Choose a reason for hiding this comment

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

@disconnect3d lmk what you think. I prefer this approach and was going to migrate some other tests to it, but will wait until you let me know you're ok with it.

Copy link
Member

Choose a reason for hiding this comment

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

@gsingh93 I think making it a decorator makes things more complex unnecessarily? Why not just a standard function call that would be called within the test function instead? Some tests could want to call it multiple times too.

Regarding fixtures, the fixtures are kinda broken bcoz we never run tests all together but instead we run them each one by one. Fixtures allows for 'session fixtures' where the fixture would be called once for all tests in a test session etc. Another good thing of fixtures is that u can yield in them and whatever code is after the yield will be executed after the test finishes, as a kind of 'destructor'. But yeah, maybe its not so needed here.

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

Successfully merging this pull request may close these issues.

None yet

2 participants