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

Use usleep instead of sleep/nanosleep on Mbed OS. #8393

Conversation

pan-
Copy link
Contributor

@pan- pan- commented Jul 14, 2021

Problem

nanosleep is not available on Mbed OS and sleep as a different semantic compared to POSIX (not tie to newlib).
Some unit tests actively use this feature which cause a compilation error.

Change overview

In unit tests, use usleep instead of nanosleep or sleep when compiled for Mbed OS.

Testing

How was this tested? (at least one bullet point required)

Existing unit tests.

@pan- pan- mentioned this pull request Jul 15, 2021
7 tasks
src/messaging/tests/TestReliableMessageProtocol.cpp Outdated Show resolved Hide resolved
src/platform/tests/TestPlatformMgr.cpp Outdated Show resolved Hide resolved
src/platform/tests/TestPlatformTime.cpp Outdated Show resolved Hide resolved
src/platform/tests/TestPlatformTime.cpp Outdated Show resolved Hide resolved
@pan- pan- force-pushed the use-usleep-instead-of-nanosleep-on-mbed branch from 1bc1116 to 4256ae3 Compare July 15, 2021 22:27
@github-actions
Copy link

Size increase report for "esp32-example-build" from 15669b6

File Section File VM
chip-temperature-measurement-app.elf .flash.text 60 60
chip-all-clusters-app.elf .flash.text 16 16
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv

Comparing ./master_artifact/chip-temperature-measurement-app.elf and ./pull_artifact/chip-temperature-measurement-app.elf:

sections,vmsize,filesize
.flash.text,60,60
[Unmapped],0,-60

Comparing ./master_artifact/chip-persistent-storage.elf and ./pull_artifact/chip-persistent-storage.elf:

sections,vmsize,filesize

Comparing ./master_artifact/chip-pigweed-app.elf and ./pull_artifact/chip-pigweed-app.elf:

sections,vmsize,filesize

Comparing ./master_artifact/chip-lock-app.elf and ./pull_artifact/chip-lock-app.elf:

sections,vmsize,filesize

Comparing ./master_artifact/chip-all-clusters-app.elf and ./pull_artifact/chip-all-clusters-app.elf:

sections,vmsize,filesize
.xt.lit._ZN4chip6System5Mutex6UnlockEv,0,128
.xt.lit._ZN4chip11DeviceLayer8Internal35GenericPlatformManagerImpl_FreeRTOSINS0_19PlatformManagerImplEE10_PostEventEPKNS0_15ChipDeviceEventE,0,80
.xt.prop._ZN4chip11DeviceLayer8Internal26GenericPlatformManagerImplINS0_19PlatformManagerImplEE14_InitChipStackEv,0,40
.flash.text,16,16
.xt.prop._ZN4chip11DeviceLayer8Internal35GenericPlatformManagerImpl_FreeRTOSINS0_19PlatformManagerImplEE14_LockChipStackEv,0,-12
.xt.prop._ZN4chip11DeviceLayer8Internal35GenericPlatformManagerImpl_FreeRTOSINS0_19PlatformManagerImplEE15_StartChipTimerEj,0,-12
.xt.prop._ZN4chip11DeviceLayer8Internal35GenericPlatformManagerImpl_FreeRTOSINS0_19PlatformManagerImplEE16_UnlockChipStackEv,0,-12
[Unmapped],0,-16
.xt.lit._ZN4chip11DeviceLayer8Internal35GenericPlatformManagerImpl_FreeRTOSINS0_19PlatformManagerImplEE14_LockChipStackEv,0,-48
.xt.lit._ZN4chip11DeviceLayer8Internal35GenericPlatformManagerImpl_FreeRTOSINS0_19PlatformManagerImplEE15_StartChipTimerEj,0,-48
.xt.lit._ZN4chip11DeviceLayer8Internal35GenericPlatformManagerImpl_FreeRTOSINS0_19PlatformManagerImplEE16_UnlockChipStackEv,0,-48
.xt.prop._ZN4chip6System5Mutex6UnlockEv,0,-108

Comparing ./master_artifact/chip-shell.elf and ./pull_artifact/chip-shell.elf:

sections,vmsize,filesize


@pan-
Copy link
Contributor Author

pan- commented Jul 20, 2021

I use usleep everywhere, everything seems fine.

@pan- pan- requested a review from bzbarsky-apple July 20, 2021 08:07
src/messaging/tests/TestReliableMessageProtocol.cpp Outdated Show resolved Hide resolved
src/platform/tests/TestPlatformTime.cpp Outdated Show resolved Hide resolved
@bzbarsky-apple
Copy link
Contributor

@pan- See review comments?

@ATmobica
Copy link
Contributor

ATmobica commented Aug 2, 2021

@bzbarsky-apple Hi, @pan- is on holiday so I take over this PR. I changed the casting according to your comments

pan- and others added 2 commits August 2, 2021 10:39
nanosleep isn't available with newlib which is used by many embedded targets.
@ATmobica ATmobica force-pushed the use-usleep-instead-of-nanosleep-on-mbed branch from c63e4a5 to 5a6ecb3 Compare August 2, 2021 10:45
@bzbarsky-apple bzbarsky-apple merged commit 379953f into project-chip:master Aug 2, 2021
nikita-s-wrk pushed a commit to nikita-s-wrk/connectedhomeip that referenced this pull request Sep 23, 2021
* Use usleep instead of nanoseep in tests to increase portability.

nanosleep isn't available with newlib which is used by many embedded targets.

* Use C++-style cast - static_cast replacement

Co-authored-by: ATmobica <[email protected]>
@ATmobica ATmobica deleted the use-usleep-instead-of-nanosleep-on-mbed branch October 28, 2021 09:37
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.

7 participants