Skip to content

tests: posix: semaphores: ensure test is not skipped #88769

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

cfriedt
Copy link
Member

@cfriedt cfriedt commented Apr 17, 2025

Commit f7633a5 moved the tests for the POSIX_SEMAPHORES Option Group from the tests/posix/common testsuite to tests/posix/semaphores.

However, there was a copy-paste error. Previously, tests would have been run only once when dynamic threads were enabled, and then skipped when dynamic threads were disabled, since that follows the posix programming model better. However, dynamic threads were never actually enabled after moving to the new testsuite. So all tests were effectively skipped.

Add the necessary options to prj.conf in order to ensure that there are sufficient dynamic threads available to run the testsuite.

Fixes #88768

@github-actions github-actions bot added the area: POSIX POSIX API Library label Apr 17, 2025
@github-actions github-actions bot requested a review from ycsin April 17, 2025 13:33
@cfriedt cfriedt requested a review from nashif April 17, 2025 13:33
@cfriedt cfriedt added the area: Tests Issues related to a particular existing or missing test label Apr 17, 2025
ycsin
ycsin previously approved these changes Apr 17, 2025
@@ -3,3 +3,7 @@ CONFIG_ZTEST=y

CONFIG_POSIX_AEP_CHOICE_BASE=y
CONFIG_POSIX_SEMAPHORES=y

CONFIG_DYNAMIC_THREAD=y
CONFIG_DYNAMIC_THREAD_POOL_SIZE=2
Copy link
Member

Choose a reason for hiding this comment

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

Same as #88767, we can make it bulletproof by BUILD_ASSERTing CONFIG_DYNAMIC_THREAD_POOL_SIZE>=2

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed!

ycsin
ycsin previously approved these changes Apr 18, 2025
jukkar
jukkar previously approved these changes Apr 19, 2025
JordanYates
JordanYates previously approved these changes Apr 19, 2025
@cfriedt
Copy link
Member Author

cfriedt commented Apr 19, 2025

This needs another change unfortunately - it should be visible after a rebase, but due to #88538, the default heap-add with CONFIG_POSIX_API has been reduced from 1 kiB down to 256 bytes. Since posix semaphores allocate from the heap historically, and still have not been converted to use pooled allocators, tests/posix/semaphores fails after #88538 was merged.

I'll add another commit ahead of this one to create a heap-add for posix semaphores.

https://github.com/zephyrproject-rtos/zephyr/actions/runs/14535678361/job/40783625837?pr=88762

The above failure can be traced to k_calloc() here

nsem = k_calloc(1, sizeof(struct nsem_obj));

@cfriedt cfriedt dismissed stale reviews from JordanYates, jukkar, and ycsin via 4b5ae9e April 19, 2025 14:07
@cfriedt cfriedt force-pushed the tests-posix-semaphors-skipped branch 2 times, most recently from 4b5ae9e to 61f1411 Compare April 19, 2025 14:08
@cfriedt
Copy link
Member Author

cfriedt commented Apr 19, 2025

  • rebased
  • posix: semaphores: use a default minimal heap-add for semaphores
  • tests: posix: semaphores: reduce execution time by 5s
  • tests: posix: semaphores: coalesce string constants
  • tests: posix: semaphores: ensure test is not skipped

@cfriedt cfriedt requested review from jukkar, ycsin and JordanYates April 19, 2025 16:11
@cfriedt
Copy link
Member Author

cfriedt commented Apr 19, 2025

@nashif - this should reduce test execution time for semaphores by a good amount (for cortex-a53, and likely x86-64 as well)

@cfriedt cfriedt force-pushed the tests-posix-semaphors-skipped branch from 61f1411 to 4e6a92d Compare April 19, 2025 18:15
The implementation of POSIX_SEMAPHORES historically used heap allocation
and has not yet been transitioned to a pool allocator.

However, since 590258b, the default heap-add with CONFIG_POSIX_API
has been reduced from 1 kiB which causes tests/posix/semaphores to fail
due to NULL being returned from a call to k_calloc().

Create a minimal heap-add for the POSIX_SEMAPHORES Option Group.

This can be removed at a future date if semaphores are changed to use
a pooled allocator and fixed-size name, rather than heap allocation.

Signed-off-by: Chris Friedt <[email protected]>
@cfriedt cfriedt force-pushed the tests-posix-semaphors-skipped branch 2 times, most recently from bec2865 to e462778 Compare April 19, 2025 20:57
@cfriedt
Copy link
Member Author

cfriedt commented Apr 19, 2025

  • ensure adding WAIT_TIME_MS to abstime results in a valid timespec

@@ -51,11 +54,10 @@ static void semaphore_test(sem_t *sem)

zassert_equal(clock_gettime(CLOCK_REALTIME, &abstime), 0, "clock_gettime failed");

abstime.tv_sec += 5;
abstime.tv_sec += WAIT_TIME_MS / MSEC_PER_SEC;
Copy link
Member

Choose a reason for hiding this comment

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

Is this supposed to be in the second commit?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, probably not.

I've actually been working on a timespec_util.h header as well that includes a few useful functions. That's been long overdue.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed!

cfriedt added 3 commits April 20, 2025 17:29
There is no reason to use a 5s wait time in tests. This can add up quite
significantly across multiple platforms that execute in real-time under
qemu (or even just on real hardware).

Speedup observed with qemu_cortex_a53/qemu_cortex_a53/smp

Before:
```
START - test_named_semaphore
 PASS - test_named_semaphore in 5.688 seconds
```

After:
```
START - test_named_semaphore
 PASS - test_named_semaphore in 0.783 seconds
```

Signed-off-by: Chris Friedt <[email protected]>
Just a formatting change, in a separate commit.

Signed-off-by: Chris Friedt <[email protected]>
Commit f7633a5 moved the tests for the
POSIX_SEMAPHORES Option Group from the tests/posix/common testsuite to
its own dedicated testsuite.

However, there was a copy-paste error. Previously, tests would have been
run only once when dynamic threads were enabled, and then skipped when
dynamic threads were disabled, since that follows the posix programming
model better. However, dynamic threads were never actually enabled after
moving to the new testsuite. So all tests were effectively skipped.

Add the necessary options to prj.conf in order to ensure that there are
sufficient dynamic threads available to run the testsuite.

Signed-off-by: Chris Friedt <[email protected]>
@cfriedt cfriedt force-pushed the tests-posix-semaphors-skipped branch from e462778 to a6a106c Compare April 20, 2025 21:32
@cfriedt cfriedt requested a review from ycsin April 20, 2025 22:25
@kartben kartben merged commit 9535a69 into zephyrproject-rtos:main Apr 22, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: POSIX POSIX API Library area: Tests Issues related to a particular existing or missing test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tests: posix: semaphores: ensure test is not skipped
5 participants