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

Unity: Add macros for test skipping. #7448

Merged
merged 1 commit into from
Jul 16, 2018

Conversation

davidsaada
Copy link
Contributor

Description

The TEST_SKIP and TEST_SKIP_UNLESS macros (w/ and w/o messages) allow the test to skip the test case execution from the point the macro was called (without failing the test).
This is useful in case the conditions (such as missing H/W, memory limitations etc.) don't allow the test to run properly.

Pull request type

[x] Fix
[ ] Refactor
[ ] New target
[ ] Feature
[ ] Breaking change

@0xc0170 0xc0170 requested review from a team and removed request for a team July 10, 2018 08:47
@davidsaada
Copy link
Contributor Author

@adbridge
Copy link
Contributor

adbridge commented Jul 10, 2018

OK this fix slightly subverts the way Utest/Unity are supposed to work. You may want to read the Utest readme, in particular:

Test Case Attributes

You can modify test case behavior by returning control_t modifiers:

    CaseNext: never repeats and immediately moves to next test case
    CaseNoRepeat: never repeats.
    CaseRepeatAll: repeats test case with setup and teardown handlers.
    CaseRepeatHandler: repeats test case without set and teardown handlers.
    CaseNoTimeout: immediately moves to next test case.
    CaseAwait: waits indefinitely for callback validation (use with caution).
    CaseTimeout(uint32_t ms): waits for callback validation for ms milliseconds, times out after that (fails with REASON_TIMEOUT).
    CaseRepeatAllOnTimeout(uint32_t ms): waits for callback validation for ms milliseconds, repeats test case with setup and teardown handlers on time out.
    CaseRepeatHandlerOnTimeout(uint32_t ms): waits for callback validation for ms milliseconds, repeats test case without setup and teardown handlers on time out.

From what I can make out your new Unity macro just does an immediate 'return' to skip executing the rest of a test case, however if the test case has been designed to return with one of the above custom control_t types then have you investigated what the knock on effect would be ? ie would it just break Utest?

*-------------------------------------------------------*/

#define UNITY_TEST_SKIP(line, message) { UnitySkipPrint( (message), (UNITY_LINE_TYPE)(line)); return; }
#define UNITY_TEST_SKIP_UNLESS(condition, line, message) if ((condition)) {} else UNITY_TEST_SKIP(line, message)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why isn't this just -
if (!(condition) {UNITY_TEST_SKIP((line), (message))} ?
Note also other brackets around parameters

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right on both. Will change. Regarding the condition, it was just a copy/paste from the UNITY_TEST_ASSERT macro, but that's not an excuse.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed a fix now.

@davidsaada
Copy link
Contributor Author

davidsaada commented Jul 11, 2018

From what I can make out your new Unity macro just does an immediate 'return' to skip executing the rest of a test case, however if the test case has been designed to return with one of the above custom control_t types then have you investigated what the knock on effect would be ? ie would it just break Utest?

The vast majority of the tests return nothing. Only tests that return the control_t type are in storage_abstraction, which is deprecated, and in the Utest tests themselves of course. Using the macro in these tests would produce an error/warning for not returning a return value. In all other tests (practically all tests), using this macro would simply end the function.
I can add macros with a return value, but again as I see it, it's not used anywhere in the code.
This macro is really intended as a convenient one liner for gracefully ending a test case, which is something which I believe is needed. So instead of having:

if (!normal_state) {
  printf(__LINE__)
  printf(message);
  return;
}

Just call TEST_SKIP_UNLESS(normal_state, message)
But anyway, will add a comment for clarity sake.

Copy link
Contributor

@OPpuolitaival OPpuolitaival left a comment

Choose a reason for hiding this comment

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

Looks good

The TEST_SKIP and TEST_SKIP_UNLESS macros (w/ and w/o messages) allow the test
to skip the test case execution from the point the macro was called (without
failing the test).
@0xc0170
Copy link
Contributor

0xc0170 commented Jul 13, 2018

/morph build

@0xc0170 0xc0170 requested review from a team and removed request for a team July 13, 2018 13:08
@mbed-ci
Copy link

mbed-ci commented Jul 13, 2018

Build : SUCCESS

Build number : 2601
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/7448/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build
/morph mbed2-build

@mbed-ci
Copy link

mbed-ci commented Jul 13, 2018

@mbed-ci
Copy link

mbed-ci commented Jul 14, 2018

Copy link
Member

@fkjagodzinski fkjagodzinski left a comment

Choose a reason for hiding this comment

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

This might come in handy. 👍

@cmonr cmonr merged commit be215a3 into ARMmbed:master Jul 16, 2018
@davidsaada davidsaada deleted the david_unity_test_skip branch August 1, 2018 13:25
pan- pushed a commit to pan-/mbed that referenced this pull request Aug 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants