Skip to content

stack_size_unification test: set expected stack sizes from config #12979

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

Conversation

LDong-Arm
Copy link
Contributor

@LDong-Arm LDong-Arm commented May 15, 2020

Summary of changes

Use macros defined by the build system to set expected stack sizes in stack_size_unification test so that

  • we do not need to maintain hardcoded values
  • ISR stack size is determined in the same way for bare metal and RTOS
  • there is no target-dependency.

Credits to @jeromecoutant for raising this.

Impact of changes

The test passes even if a target (i.e. one that has low memory) overrides the default stack sizes.

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)
[x] Tests / results supplied as part of this PR

Tested on

  • NRF52840_DK with target.boot-stack-size manually changed, with both the full profile and the bare metal profile.
  • LPC11U24 (low-memory target) with the bare metal profile. (This target is unsupported now but I copied its config + drivers from an older Mbed OS).

Reviewers

@evedon @ARMmbed/mbed-os-core @mprse @MarceloSalazar


@LDong-Arm LDong-Arm force-pushed the stack_size_expectation_from_config branch from 73ab9a8 to 0ac17ea Compare May 15, 2020 14:16
#ifdef MBED_CONF_RTOS_MAIN_THREAD_STACK_SIZE
#undef MBED_CONF_RTOS_MAIN_THREAD_STACK_SIZE
#endif
#define MBED_CONF_RTOS_MAIN_THREAD_STACK_SIZE 3072
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: This affects only TMPM46B - see a few lines above.
We remove this macro-redefinition and override it properly in rtos/source/TARGET_CORTEX/mbed_lib.json.

Copy link
Collaborator

@jeromecoutant jeromecoutant left a comment

Choose a reason for hiding this comment

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

| NUCLEO_F303K8-ARMC6 | NUCLEO_F303K8 | tests-mbed_hal-stack_size_unification | Stack size unification test | 1 | 0 | OK | 0.06 |


#if defined(TARGET_NUCLEO_F070RB) || defined(TARGET_STM32F072RB) || defined(TARGET_TMPM46B) || defined(TARGET_TMPM066)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All of NUCLEO_F070RB, STM32F072RB and TMPM46B have thread stack sizes overriden in rtos/source/TARGET_CORTEX/mbed_lib.json, so we don't need target-dependent code here. As for TARGET_TMPM066, it's not supported anymore).

@LDong-Arm
Copy link
Contributor Author

| NUCLEO_F303K8-ARMC6 | NUCLEO_F303K8 | tests-mbed_hal-stack_size_unification | Stack size unification test | 1 | 0 | OK | 0.06 |

Thanks for testing!

@ciarmcom ciarmcom requested review from evedon, MarceloSalazar, mprse and a team May 15, 2020 15:00
@ciarmcom
Copy link
Member

@LDong-Arm, thank you for your changes.
@evedon @MarceloSalazar @mprse @ARMmbed/mbed-os-core @ARMmbed/mbed-os-test @ARMmbed/mbed-os-hal @ARMmbed/mbed-os-maintainers please review.

@@ -76,6 +76,9 @@
"STM32F072RB": {
"main-thread-stack-size": 3072
},
"TMPM46B": {
"main-thread-stack-size": 3072
},
Copy link

@MarceloSalazar MarceloSalazar May 15, 2020

Choose a reason for hiding this comment

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

Do we really need to specify this per target?
Or can we set the stack-size depending on the total RAM? (which would be target independent)
EDIT: and of course let the user override it in mbed_app.json if they want

Copy link
Contributor Author

@LDong-Arm LDong-Arm May 15, 2020

Choose a reason for hiding this comment

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

Checking RAM size is ideal, and we do have target.mbed_ram_size for this purpose.

The trouble is, we only have it defined for a few targets. For most other targets, the RAM and ROM sizes are hardcoded in the linker scripts (e.g. scatter files) - only the linker knows the RAM, not the application/libraries/...

Copy link
Contributor Author

@LDong-Arm LDong-Arm May 15, 2020

Choose a reason for hiding this comment

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

Well, 17 targets have it defined: https://github.com/ARMmbed/mbed-os/blob/master/targets/targets.json
Okay it's more than a few, but still far from a good coverage.

Choose a reason for hiding this comment

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

Agree, thanks for clarifying it
This PR is great anyway as it helps us with some clean-up. More could be done in the future.

Copy link
Contributor Author

@LDong-Arm LDong-Arm May 15, 2020

Choose a reason for hiding this comment

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

Personally I'd like to see the sizes defined - it can help us to disable certain Greentea test cases for ultra-constrained targets for which we even struggle to compile some very basic tests... @evedon

Copy link
Contributor

Choose a reason for hiding this comment

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

The best would be to generate the linker script (having set per toolchain and that is it) so having the size defined is one way forward there :)

Copy link
Contributor

@evedon evedon left a comment

Choose a reason for hiding this comment

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

That's great @LDong-Arm. Thanks for the PR.

@mergify mergify bot added needs: CI and removed needs: review labels May 18, 2020
@0xc0170
Copy link
Contributor

0xc0170 commented May 19, 2020

CI started

@LDong-Arm
Copy link
Contributor Author

LDong-Arm commented May 19, 2020

CI failed with

tools.utils.NotSupportedException: Target NU_PFM_M2351_NPSA_S is not supported by toolchain GCC_ARM

Looks unrelated to this PR?

@0xc0170
Copy link
Contributor

0xc0170 commented May 25, 2020

CI restarted

It was a bug on master.

@LDong-Arm
Copy link
Contributor Author

@0xc0170 Thanks but could you please keep this on hold? There's a slight issue I'll fix tomorrow

@mbed-ci
Copy link

mbed-ci commented May 25, 2020

Test run: SUCCESS

Summary: 6 of 6 test jobs passed
Build number : 2
Build artifacts


#define EXPECTED_USER_THREAD_DEFAULT_STACK_SIZE (4096)
#define EXPECTED_USER_THREAD_DEFAULT_STACK_SIZE (MBED_CONF_RTOS_THREAD_STACK_SIZE)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the test case below, we use this macro to verify OS_STACK_SIZE:

TEST_ASSERT_EQUAL(EXPECTED_USER_THREAD_DEFAULT_STACK_SIZE, OS_STACK_SIZE);

where OS_STACK_SIZE is conditional

#if defined(MBED_CONF_APP_THREAD_STACK_SIZE)
#define OS_STACK_SIZE MBED_CONF_APP_THREAD_STACK_SIZE
#else
#define OS_STACK_SIZE MBED_CONF_RTOS_THREAD_STACK_SIZE
#endif

The trouble is, to get the assertion to pass in all scenarios, our expectation needs to be conditional in the same way. But isn't it a duplication? I'm not sure there's any value in comparing two macros in a Greentea test to begin with...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my opinion, we should remove this assertion from the test case - which is out of this PR's initial scope (i.e. fixing line 34). But still this line of diff doesn't make things worse than before (i.e. hardcoded 4096).

@0xc0170 If this PR blocks any release, maybe we can get it in as it is?

@LDong-Arm
Copy link
Contributor Author

@adbridge This Greentea test fix is required for all targets with a non-default stack size, particularly bare-metal-only targets with small memories. Is it critical for the release?

@adbridge
Copy link
Contributor

Patch updates can wait until the next release

@0xc0170 0xc0170 added the release-type: patch Indentifies a PR as containing just a patch label Jun 4, 2020
@0xc0170 0xc0170 merged commit ab43962 into ARMmbed:master Jun 4, 2020
@mergify mergify bot removed the ready for merge label Jun 4, 2020
@mergify
Copy link

mergify bot commented Jun 4, 2020

This PR does not contain release version label after merging.

@mergify mergify bot added the release version missing When PR does not contain release version, bot should label it and we fix it afterwards label Jun 4, 2020
@adbridge adbridge added release-version: 6.1.0 Release-pending and removed release-type: patch Indentifies a PR as containing just a patch Release-pending labels Jun 24, 2020
@0xc0170 0xc0170 removed the release version missing When PR does not contain release version, bot should label it and we fix it afterwards label Aug 23, 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.

8 participants