Skip to content

dist/testrunner: Capture number of unittests that passed#13665

Merged
miri64 merged 2 commits intoRIOT-OS:masterfrom
leandrolanzieri:pr/dist/testrunner_check_unittests_fix_regex
Apr 3, 2020
Merged

dist/testrunner: Capture number of unittests that passed#13665
miri64 merged 2 commits intoRIOT-OS:masterfrom
leandrolanzieri:pr/dist/testrunner_check_unittests_fix_regex

Conversation

@leandrolanzieri
Copy link
Contributor

Contribution description

#13642 introduced the check_unittests helper function, to verify the result of unit tests on applications. Some tests (e.g. gnrc_sixlowpan_iphc_w_vrb, gnrc_ipv6_ext_frag) expect the number of passed tests to be captured. This modifies the regex to do that.

Testing procedure

Run tests which make use of this function, they should pass.

Issues/PRs references

#13642

@leandrolanzieri leandrolanzieri added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: tests Area: tests and testing framework Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer labels Mar 20, 2020
@leandrolanzieri leandrolanzieri added this to the Release 2020.04 milestone Mar 20, 2020
def check_unittests(child, timeout=TIMEOUT, nb_tests=None):
_tests = r'\d+' if nb_tests is None else int(nb_tests)
child.expect(r'OK \({} tests\)'.format(_tests), timeout=timeout)
child.expect(r'OK \(({}) tests\)'.format(_tests), timeout=timeout)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rather use this on the line above: '(\d+)'

Copy link
Member

Choose a reason for hiding this comment

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

This then makes the match object in child.match very inconsistent, depending if nb_tests is provided or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

if nb_tests is provided, this is not a regexp anymore.

Copy link
Member

Choose a reason for hiding this comment

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

Of course it is. It just matches to the number provided.

Copy link
Contributor

@aabadie aabadie Mar 20, 2020

Choose a reason for hiding this comment

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

if you set nb_tests to a value, but the actual number of successful tests is different, the expect will fail anyway. And if it is successful, you already know that number (since it was given as parameter), so there's no need to guess it with a match.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ping @aabadie ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Still on my position, sorry.

Why do you think your approach is a better approach than having the expect object / side-effects behave consistently on this function call regardless of input?

The problem is not about treating the same way all kind of inputs but check the input to properly handle it (None => regexp, nb_tests => plain string check). If nb_tests is set, you can use the expect_exact match (which I should have done in the first place and which is faster), if not, use expect with a regexp.

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with you having a position on that. I just don't understand why you want the behavior like that. IMHO it just makes this function harder to understand and use.

Copy link
Contributor

@aabadie aabadie Mar 25, 2020

Choose a reason for hiding this comment

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

it just makes this function harder to understand and use.

Why ? If it's hard to understand, add comments.
If you want to return the number of successful tests, if nb_tests is None, just return your proposition below (int(child.match(1)), in all other cases, return nb_tests.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, but why add a comment if we can have the same intuitively like this? IMHO we are just bike-shedding. expect_exact should only have minor speed advantages here and the other "advantage" that one can just carelessly copy-paste is not given here, as this function abstracts that away.

@leandrolanzieri
Copy link
Contributor Author

I modified the function to always return the amount of passed tests. Also changed the tests that use that function, to check for the returned value instead of getting the captured group.

Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

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

ACK. Fixes some assertions and abstracts away pexpect sufficiently.

@miri64
Copy link
Member

miri64 commented Apr 3, 2020

Please squash

@miri64 miri64 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: run tests If set, CI server will run tests on hardware for the labeled PR labels Apr 3, 2020
@leandrolanzieri leandrolanzieri force-pushed the pr/dist/testrunner_check_unittests_fix_regex branch from af8d7ac to 50659c7 Compare April 3, 2020 11:32
Copy link
Contributor

@aabadie aabadie 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 addressing the changes. However, there's still room for improvement.

Copy link
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

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

ACK, please squash!

@leandrolanzieri leandrolanzieri force-pushed the pr/dist/testrunner_check_unittests_fix_regex branch from 1e27790 to dee76f6 Compare April 3, 2020 12:17
@leandrolanzieri
Copy link
Contributor Author

I forgot to remove the slashes now that the expect_exact is a string 😅

@leandrolanzieri leandrolanzieri force-pushed the pr/dist/testrunner_check_unittests_fix_regex branch from dee76f6 to 8ce1bcd Compare April 3, 2020 12:53
@leandrolanzieri
Copy link
Contributor Author

I fixed that and squashed directly.

@leandrolanzieri
Copy link
Contributor Author

Ok now Murdock is happy

@miri64 miri64 merged commit 942c63e into RIOT-OS:master Apr 3, 2020
@leandrolanzieri leandrolanzieri deleted the pr/dist/testrunner_check_unittests_fix_regex branch April 3, 2020 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: run tests If set, CI server will run tests on hardware for the labeled PR Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants