Skip to content

Remove the UNITTEST macro from production code #14884

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 4 commits into from
Jul 7, 2021

Conversation

LDong-Arm
Copy link
Contributor

Summary of changes

Fixes #14883

Following discussion in #14870 (comment), we agree that production code should not contain any test-specific checks - stubs/fakes/mocks/... should be sufficient.

This PR removes the UNITTEST macro from the entire Mbed OS code base. For details, see individual commit messages.

Impact of changes

Migration actions required

Documentation

None


Pull request type

[x] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[x] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

Reviewers

@rajkan01 @rwalton-arm @ARMmbed/mbed-os-core


LDong-Arm added 4 commits July 6, 2021 16:50
Production code should not contain any test-specific checks. Rather
than checking `UNITTEST`, unit tests can directly set
`MBED_CONF_RTOS_PRESENT=1` to make RTOS available for testing.

Note: The cellular ATHandler test also has `MBED_CONF_RTOS_PRESENT=1`
added because `ATHandler.cpp` contains a check of this variable.
The stub version of mbed_assert.h is never used outside unit tests,
so the check on `UNITTEST` is redundant.
The stub version of <mstd_type_traits> is mostly identical to the
production file of the same name, except the former lags behind
and doesn't contain the recent "is_constant_evaluated" feature.
It's safe to update the stub file, because "is_constant_evaluated"
only checks generic GCC and Clang versions that also apply to
compilers on PCs.

This enables MbedCRC.h to include <mstd_type_traits> without
distinguishing between Mbed applications and unit tests.
Production code should not contain any test-specific checks. Rather
than checking `UNITTEST`, MbedCRC.h can simply include in all cases
<mstd_type_traits> whose unit test stub exists.

Also remove the `UNITTEST` macro from CMake definitions of kvstore
unit tests which depend on MbedCRC.h.
@LDong-Arm LDong-Arm requested review from rwalton-arm and rajkan01 July 6, 2021 16:40
@ciarmcom ciarmcom added the release-type: patch Indentifies a PR as containing just a patch label Jul 6, 2021
@ciarmcom
Copy link
Member

ciarmcom commented Jul 6, 2021

@LDong-Arm, thank you for your changes.
@ARMmbed/mbed-os-maintainers please review.

@mergify mergify bot added needs: CI and removed needs: review labels Jul 7, 2021
@0xc0170
Copy link
Contributor

0xc0170 commented Jul 7, 2021

CI started

@mbed-ci
Copy link

mbed-ci commented Jul 7, 2021

Jenkins CI Test : ✔️ SUCCESS

Build Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_cmake-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_greentea-test ✔️

@Patater Patater merged commit dc6dd17 into ARMmbed:master Jul 7, 2021
@mergify mergify bot removed the ready for merge label Jul 7, 2021
@mbedmain mbedmain added release-version: 6.13.0 Release-pending and removed release-type: patch Indentifies a PR as containing just a patch Release-pending labels Jul 14, 2021
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.

Unit tests: Libraries should not contain test-specific logic
7 participants