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

Unit tests: Move target_h/ stubs into libraries' test doubles #14929

Merged
merged 17 commits into from
Aug 3, 2021

Conversation

LDong-Arm
Copy link
Contributor

@LDong-Arm LDong-Arm commented Jul 16, 2021

Summary of changes

Fixes: #14799

This PR moves stubs headers from UNITTESTS/target_h/ into individual libraries' own UNITTESTS/doubles/, similar to what we did with UNITTESTS/stubs/. The CMake targets that contain those headers are changed from mbed-headers-base to mbed-headers-<library>.

Note: Even though headers previously in target_h are technically stubs/fakes too, they are used by not only unit tests but also regular libraries when compiled for unit tests, because no target-specific HAL implementation exists in this case. In order for regular library sources to pick up target_h headers, those headers must

  • have the same names as regular headers
  • appear first in include paths

This is why those headers are part of mbed-headers-<library> and not mbed-stubs-<library>. Before this refactoring, mbed-headers-base which contained target_h was the first in all unit tests' include paths.

To avoid duplicating the above explanation in every commit, it is only in the commit message of the last commit "Unit tests: Remove redundant CMake target mbed-headers-base".

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

@ARMmbed/mbed-os-core


@ciarmcom ciarmcom added the release-type: patch Indentifies a PR as containing just a patch label Jul 16, 2021
@ciarmcom ciarmcom requested a review from a team July 16, 2021 15:00
@ciarmcom
Copy link
Member

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

@LDong-Arm
Copy link
Contributor Author

Fixed astyle.

rajkan01
rajkan01 previously approved these changes Jul 19, 2021
Copy link
Contributor

@rajkan01 rajkan01 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 changes @LDong-Arm , it looks good to me and needs to fix CI

rwalton-arm
rwalton-arm previously approved these changes Jul 20, 2021
@rwalton-arm
Copy link
Contributor

The "pinvalidate" test is failing with the following output:

$ git diff --name-only --diff-filter=d FETCH_HEAD..HEAD \

  | ( grep '.*[\\|\/]PinNames.h$' || true ) \

  | while read file; do python ./hal/tests/pinvalidate/pinvalidate.py -vfp "${file}"; done

WARNING: MBED TARGET LIST marker invalid or not found in file hal/tests/UNITTESTS/doubles/PinNames.h

Target could not be determined. Only the generic test suite will run. You can manually specify additional suites.

+----------------------------------------+--------------+----------+---------------+

| Platform name                          | Test suite   | Result   |   Error count |

+========================================+==============+==========+===============+

| hal/tests/UNITTESTS/doubles/PinNames.h | generic      | FAILED   |             1 |

+----------------------------------------+--------------+----------+---------------+

One or more test cases failed

@mergify mergify bot dismissed stale reviews from rajkan01 and rwalton-arm July 20, 2021 11:57

Pull request has been modified.

Copy link
Contributor Author

@LDong-Arm LDong-Arm left a comment

Choose a reason for hiding this comment

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

@rajkan01 @rwalton-arm: Thanks for the reviews. The unit test stub PinNames.h didn't satisfy the latest requirements on pin names. I've added a commit to fix that, hopefully Travis will pass!

@LDong-Arm
Copy link
Contributor Author

Rebased PR and fixed an actual issue in the PinName.h stub that failed Travis.

@LDong-Arm
Copy link
Contributor Author

@rajkan01 @rwalton-arm Travis now passes after I rebased the PR and fixed the PinNames.h stub. Are you happy to have a look and re-approve? Thanks.

@mergify
Copy link

mergify bot commented Jul 21, 2021

This PR cannot be merged due to conflicts. Please rebase to resolve them.

@LDong-Arm
Copy link
Contributor Author

Rebased again

Stubs previously in UNITTESTS/target_h/ have the same names as
regular Mbed OS headers, intending to override the latter directly.
We move platform target_h stubs into
platform/tests/UNITTESTS/doubles/platform/.

Note: nvic_wrapper.h is normally implemented and used by Mbed targets
as needed. But as unit tests do not have a real target, we treat it
as a stub for the platform.
The header `mbed.h` is a convenient wrapper that pre-includes some
platform headers, for use by user applications. Libraries and tests
internal to Mbed OS should not use it, and they should explicitly
include headers they need. So a stub is not needed.
The stub header randLIB.h overrides the header of the same name in
platform/randlib/ which is an external repository vendored into
the mbed-os codebase. As the repository is synchronized regularly,
it is better not to put overrides there, so we put the randLIB.h
stub into the regular platform doubles directory.
Stubs previously in UNITTESTS/target_h/ have the same names as
regular Mbed OS headers, intending to override the latter directly.
We move hal target_h stubs into hal/tests/UNITTESTS/doubles/.

Note: In Mbed OS, the standard include format requires each header to
be prefixed with its module name, for example "hal/gpio_api.h". This
requires headers to be organized in a module directory. But unit tests
stubs for hal correspond to what a real Mbed target would have
implemented (in a non-test scenario), and targets do not currently put
headers in hal/, so we similary put stub headers directly in
hal/tests/UNITTESTS/doubles/ instead of add a hal/ subdirectory there.
Individual libraries' `target_h` stub headers have now all been moved
from `mbed-headers-base` to `mbed-headers-<library>`.

Note: Even though headers previously in `target_h` are technically
stubs/fakes too, they are used by not only unit tests but also regular
libraries when compiled for unit tests, because no target-specific HAL
implementation exists in this case. In order for regular library
sources to pick up `target_h` headers, those headers must

* have the same names as regular headers
* appear first in include paths

This is why those headers are part of `mbed-headers-<library>` and not
`mbed-stubs-<library>`. Before this refactoring, `mbed-headers-base`
was the first in unit tests' include paths.
The test script pinvalidate.py requires the following which are
missing in the unit test stub PinName.h:
* A comment "MBED TARGET LIST"
* `CONSOLE_TX` and `CONSOLE_RX` in the `PinName` enum

This commit adds them.
Run pinvalidate.py with -vvv to print the cause of failure, making
it easier for authors of pull requests to fix pin names.
@LDong-Arm
Copy link
Contributor Author

LDong-Arm commented Aug 2, 2021

The CI failure was due to missing .mbedignore in Unit tests: Move cmsis target_h stubs. Now fixed.

@mergify mergify bot dismissed Patater’s stale review August 2, 2021 16:43

Pull request has been modified.

@mbed-ci
Copy link

mbed-ci commented Aug 2, 2021

Jenkins CI Test : ❌ FAILED

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_build-cloud-example-GCC_ARM
jenkins-ci/mbed-os-ci_build-cloud-example-ARM
jenkins-ci/mbed-os-ci_cmake-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM
jenkins-ci/mbed-os-ci_build-example-GCC_ARM
jenkins-ci/mbed-os-ci_build-example-ARM

@Patater
Copy link
Contributor

Patater commented Aug 3, 2021

CI started

@mbed-ci
Copy link

mbed-ci commented Aug 3, 2021

Jenkins CI Test : ✔️ SUCCESS

Build Number: 2 | 🔒 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 7acd5b4 into ARMmbed:master Aug 3, 2021
@mergify mergify bot removed the ready for merge label Aug 3, 2021
@mbedmain mbedmain added release-version: 6.14.0 Release-pending and removed release-type: patch Indentifies a PR as containing just a patch Release-pending labels Aug 18, 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.

Findout a place to keep mbed-os/UNITTESTS/target_h
8 participants