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

mbedtls|busybox: fix measuring test duration (trunner API change approach) #284

Merged
merged 4 commits into from
Nov 16, 2023

Conversation

nalajcie
Copy link
Member

Description

  • mbedtls: fix measuring test duration
    The subtest result was incorrectly "finished" (added to result) one line after
    the result (so actually computed the time of the next test).

    Use simplified API to add optional test message to the correct subtest

  • trunner: make subresult API more robust

    • remove add_subresult_obj() as it's misleading (doesn't add by reference,
      just by value
    • make add_subresult() return the subresult object which can be updated at a
      later time

Motivation and Context

phoenix-rtos/phoenix-rtos-project#877

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: (list targets here).

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

  • This PR needs additional PRs to work (list the PRs, preferably in merge-order).
  • I will merge this PR by myself when appropriate.

@nalajcie
Copy link
Member Author

switching to draft until busybox harness changes would be implemented

@github-actions
Copy link

github-actions bot commented Oct 26, 2023

Unit Test Results

5 989 tests  ±0   5 348 ✔️ ±0   31m 29s ⏱️ + 2m 2s
   333 suites ±0      641 💤 ±0 
       1 files   ±0          0 ±0 

Results for commit eaf18cf. ± Comparison against base commit 36b0b78.

♻️ This comment has been updated with latest results.

busybox/busybox.py Show resolved Hide resolved
@@ -26,21 +26,23 @@ def harness(dut: Dut, ctx: TestContext, result: TestResult):
parsed = dut.match.groupdict()

if idx == 2:
msg.append("\t\t" + parsed["line"])
continue
line_msg = parsed["line"] + " "
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't really know how the full output from the succesful/failed tescases looks like. Maybe we can put sample output as a mulitiline variable / comment after imports (to be used for pytest harness unit test in the near future hopefully).

From your code I suspect the output might be:

FAIL: test-name-1
why-failed-line-1
why-failed-line-2
msg-for-test-2
msg-for-test-2
PASS: test-name-2

If so - we can't assign message lines to the testcases in any sensible way (your code would append all 4 lines to test-name-1, but that's ok if the input is really like that) - but we should mention in comment that the messages might be invalid in that case.

Copy link
Member

Choose a reason for hiding this comment

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

After checking, the output can appear in several ways. It might be produced during the test. In the event of a failure, lines can be printed both during the test when something fails and after the test. However, when printing strictly informational messages, they are preceded by ====================== to distinguish them.

e.g.:
image
image

Copy link
Member Author

Choose a reason for hiding this comment

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

I've checked the busybox testsuite and it seems seems to be true only for newstyle tests (oldstyle tests don't print === nor messages before the test result - see mkdir for example). I don't see how to distinguish them in harness, maybe we should patch busybox testsuite framework instead?

Copy link
Contributor

@damianloew damianloew left a comment

Choose a reason for hiding this comment

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

Tested some of the most vulnerable cases and it seems to work really good (both mbedtls and busybox). Let's wait for phoenix-rtos/phoenix-rtos-ports#69 merge

busybox/busybox.py Outdated Show resolved Hide resolved
busybox/busybox.py Show resolved Hide resolved
@mateusz-bloch mateusz-bloch force-pushed the nalajcie/trunner branch 5 times, most recently from 004691d to 3dc6192 Compare November 10, 2023 12:33
mbedtls/mbedtls.py Outdated Show resolved Hide resolved
busybox/busybox.py Outdated Show resolved Hide resolved
from trunner.types import TestResult, TestSubResult, Status
from trunner.types import TestResult, Status

# Example of parsed outputs:
Copy link
Member Author

Choose a reason for hiding this comment

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

use multiline string , right now I don't know if the input has spaces in front or not, eg:

EXAMPLE_INPUT = """
test-msg-line-1
test-msg-line-2
FAIL: test-name-1
fail-msg-line-1
fail-msg-line-2
---Testcase test-name-2 starting---
test-msg-line-1
test-msg-line-2
PASS: test-name-2
---Testcase test-name-3 starting---
SKIPPED: test-name-3
"""

this would also make it easier to write unit tests (use variable as an input).

Also - test names should be in '?

busybox/busybox.py Show resolved Hide resolved
busybox/busybox.py Show resolved Hide resolved
Copy link
Contributor

@damianloew damianloew left a comment

Choose a reason for hiding this comment

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

Thanks for the latest improvements. Just 2 things more

Comment on lines 15 to 23
EXAMPLE_INPUT = """
---Testcase 'busybox as unknown name' starting---
echo -ne '' >input
echo -ne '' | ./unknown 2>&1
PASS: busybox as unknown name
---Testcase 'date-@-works' starting---
FAIL: date-@-works
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that it would be better to place it in a comment.

Copy link
Member

Choose a reason for hiding this comment

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

I based on the previous comment:
image

Copy link
Member Author

Choose a reason for hiding this comment

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

Please keep it as a multiline variable (reasoning provided previously).

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, right. Ok, I was worried about some potential issues (flake and so on) when we don't use those variables in fact.

busybox/busybox.py Show resolved Hide resolved
@mateusz-bloch mateusz-bloch force-pushed the nalajcie/trunner branch 2 times, most recently from f793544 to f2592cb Compare November 13, 2023 15:11
Copy link
Contributor

@damianloew damianloew left a comment

Choose a reason for hiding this comment

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

@mateusz-bloch please add JIRA ID to the first two commits and I'd like to merge it :)

- remove add_subresult_obj() as it's misleading (doesn't add by
reference, just by value
- make add_subresult() return the subresult object which can be updated
at a later time

Fixes: phoenix-rtos/phoenix-rtos-project#877

JIRA: CI-384
The subtest result was incorrectly "finished" (added to result) one line
after the result (so actually computed the time of the next test).

Use simplified API to add optional test message to the correct subtest

Fixes: phoenix-rtos/phoenix-rtos-project#877

JIRA: CI-384
@damianloew damianloew marked this pull request as ready for review November 14, 2023 15:17
damianloew
damianloew previously approved these changes Nov 14, 2023
Copy link
Contributor

@damianloew damianloew left a comment

Choose a reason for hiding this comment

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

LGTM

The subtest result was incorrectly finished (added to result) one line
after the result (so actually computed the time of the next test).

JIRA: CI-384
Copy link
Contributor

@damianloew damianloew left a comment

Choose a reason for hiding this comment

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

One case from busybox test suite was not handled, thanks for adding it @mateusz-bloch. Looks good to me

@damianloew damianloew merged commit bc832db into master Nov 16, 2023
33 checks passed
@damianloew damianloew deleted the nalajcie/trunner branch November 16, 2023 09:31
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