Skip to content

testsuite: added mocked serial monitor for integration tests #2379

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

Merged
merged 7 commits into from
Oct 23, 2023

Conversation

cmaglie
Copy link
Member

@cmaglie cmaglie commented Oct 20, 2023

Please check if the PR fulfills these requirements

See how to contribute

  • The PR has no duplicates (please search among the Pull Requests
    before creating one)
  • The PR follows
    our contributing guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • UPGRADING.md has been updated with a migration guide (for breaking changes)
  • configuration.schema.json updated if new parameters are added.

What kind of change does this PR introduce?

Adds a mocked serial monitor to perform integration tests that require a working serial monitor.
The mocked monitor can be "implanted" with the command:

	cli.InstallMockedSerialMonitor(t)

This command will replace the original serial monitor with the mocked one. There is no way to restore the original monitor, so tests that do not require the mocking should be written separately.

The mocked serial monitor sends over the "emulated" serial port the name of the opened port and the initial port configuration.
If the monitor receives the string "QUIT" from the emulated serial port it quits and closes the port.
To actually allow the arduino-cli to send the QUIT command over the emulated port, I had to remove the IsTerminal check from the arduino-cli monitor command that prevented running arduino-cli monitor in a scripted environment (as the CI).

This change has the good side-effect of allowing the arduino-cli monitor command in a script to send data to the board.

An integration test that exercises the monitor command flags has been added as well.

What is the current behavior?

What is the new behavior?

Does this PR introduce a breaking change, and is titled accordingly?

Other information

@cmaglie cmaglie self-assigned this Oct 20, 2023
@cmaglie cmaglie added type: enhancement Proposed improvement topic: infrastructure Related to project infrastructure labels Oct 20, 2023
@codecov
Copy link

codecov bot commented Oct 20, 2023

Codecov Report

Attention: 16 lines in your changes are missing coverage. Please review.

Comparison is base (710ecba) 62.77% compared to head (78e5d03) 63.59%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2379      +/-   ##
==========================================
+ Coverage   62.77%   63.59%   +0.82%     
==========================================
  Files         205      205              
  Lines       19283    19289       +6     
==========================================
+ Hits        12104    12266     +162     
+ Misses       6119     5931     -188     
- Partials     1060     1092      +32     
Flag Coverage Δ
unit 63.59% <5.88%> (+0.82%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
internal/cli/monitor/monitor.go 62.77% <0.00%> (+39.87%) ⬆️
internal/cli/feedback/terminal.go 16.32% <8.33%> (+7.23%) ⬆️

... and 4 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@alessio-perugini alessio-perugini left a comment

Choose a reason for hiding this comment

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

❤️

@cmaglie cmaglie merged commit eb8f2f2 into arduino:master Oct 23, 2023
@cmaglie cmaglie deleted the monitor-mocking branch October 23, 2023 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: infrastructure Related to project infrastructure type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants