Skip to content

testing/ostest: Exercise custom work queues. - #3759

Open
13022591351 wants to merge 1 commit into
apache:masterfrom
13022591351:testing/custom-work-queues
Open

testing/ostest: Exercise custom work queues.#3759
13022591351 wants to merge 1 commit into
apache:masterfrom
13022591351:testing/custom-work-queues

Conversation

@13022591351

Copy link
Copy Markdown

Summary

  • Extend the existing ostest work queue coverage to dynamically created
    queues with one and two workers.
  • Run scheduler queues and custom queues in Flat builds, and libc custom user
    queues in non-Flat builds.
  • Add ostest wqueue as a focused entry without changing the original
    no-argument ostest flow.
  • Cover explicit caller priorities, invalid arguments, periodic requeue,
    pending replacement, synchronous and parallel cancellation, multiple
    simultaneous queues, self-destruction rejection, and teardown.
  • Check work queue and semaphore API results and release all local test
    resources.
  • Depends on wqueue: Support custom user work queues. nuttx#19982.

Impact

  • New feature: YES, test coverage for custom scheduler and libc user work
    queues.
  • User adaptation: NO. The no-argument ostest sequence remains unchanged
    in non-Flat builds; the focused test is selected with ostest wqueue.
  • Build process: NO. CONFIG_TESTING_OSTEST_WQUEUE defaults to enabled
    only when its pthread and work queue dependencies are available.
  • Hardware: NO production hardware behavior is changed.
  • Documentation: NO separate application documentation is required; the
    Kconfig help describes backend selection.
  • Security: NO impact.
  • Compatibility: Existing Flat ostest work queue coverage is retained and
    expanded.

Testing

Build host:

  • Linux 6.8.0-60-generic, x86_64
  • GNU Arm Embedded Toolchain 10.3.1 20210824

Target:

Before change:

The ostest work queue source is selected only with CONFIG_SCHED_WORKQUEUE.
It has no focused command entry and cannot exercise libc custom user queues
in a Protected user process.

Build output after change:

master_flat:
  FLASH     1470396 B / 1920 KB (74.79%)
  AXI_SRAM    63380 B / 512 KB  (12.09%)

master_protected user:
  uflash      751000 B / 1 MB   (71.62%)
  usram         8192 B / 384 KB (2.08%)

Runtime output summary:

nsh> time "ostest wqueue"

Flat runs:
  30.1490 / 30.1490 / 30.1480 s

Protected libc user runs:
  15.6540 / 15.6540 / 15.6540 s

Every run:
  API validation done
  periodic calls = 3, expect = 3
  replacement total = 2, expect = 2
  sync cancel finished = 1, expect = 1
  parallel callbacks = 2, expect = 2
  multiple queues loop 1/4 through 4/4 done
  self free result = -35, expect = -35
  pending callback = 0, expect = 0
  running callback = 1, expect = 1
  teardown requeue rejected
  teardown done

All three runs for each backend completed without assertion. Current heap
usage did not increase after the first run, and all custom workers exited.

Validation:

checkpatch commit messages: pass
checkpatch complete patch range: pass
full-file nxstyle for wqueue.c and ostest_main.c: pass
cmake-format: pass
git diff --check: pass

PR verification Self-Check

  • This PR introduces only one functional change.
  • I have updated all required description fields above.
  • My PR adheres to the contributing guidelines and coding standard.
  • My PR is still work in progress.
  • My PR is ready for review and can be safely merged.

@13022591351

Copy link
Copy Markdown
Author

Thanks for the earlier review. I force-pushed the branch to rebase and
organize the follow-up work into two focused commits:

  1. testing/ostest: exercise custom work queues

    • Exercises dynamically created queues with one and two workers.
    • Covers invalid arguments, periodic requeue, pending replacement,
      synchronous and parallel cancellation, multiple simultaneous queues,
      self-destruction rejection, and teardown.
    • Replaces unbounded semaphore waits with bounded waits and verifies
      exactly 100 callback executions.
  2. testing/ostest: test USRWORK without pthreads

    • Allows the focused WQ test to build with CONFIG_LIBC_USRWORK=y and
      CONFIG_DISABLE_PTHREAD=y.
    • Exercises real work on the predefined USRWORK queue, including
      immediate and delayed work, replacement, cancellation, synchronous
      cancellation, and callback-driven periodic requeue.

The Protected kernel harness is intentionally not included in this apps PR.
The existing non-Flat no-argument ostest flow remains unchanged.

The final two-commit version was validated on an STM32H7 PX4 FMUv6C:

  • Flat ostest wqueue: 30.1490 / 30.1480 / 30.1480 s
  • Protected libc user WQ: 15.6540 / 15.6540 / 15.6540 s
  • Protected USRWORK without pthreads: 0.2290 / 0.2290 / 0.2290 s

All runs completed successfully, and repeated runs showed no cumulative
Kmem or Umem growth. The force-push also normalizes the commit subjects to
the current NuttX style.

@github-actions github-actions Bot added Size: XL and removed Size: L labels Aug 30, 2026
Comment thread testing/ostest/wqueue.c Outdated

static int wait_sem(FAR sem_t *sem)
{
#ifdef __KERNEL__

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why need check __KERNEL__

Comment thread testing/ostest/wqueue.c Outdated

#include "ostest.h"

#ifdef CONFIG_DISABLE_PTHREAD

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

remove the check

Comment thread testing/ostest/Kconfig
default y
depends on !DISABLE_PTHREAD
depends on (BUILD_FLAT && SCHED_WORKQUEUE) || LIBC_USRWORK
depends on (BUILD_FLAT && !DISABLE_PTHREAD && SCHED_WORKQUEUE) || LIBC_USRWORK

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

sqaush into the first patch

Add a focused wqueue entry that exercises predefined and dynamically
created work queues without changing the no-argument ostest flow.

Share the semaphore wait and basic worker helpers across configurations.
Flat builds exercise scheduler queues, Protected builds exercise USRWORK,
and pthread-enabled builds additionally cover configurable custom worker
pools. When pthread support is disabled, only predefined USRWORK cases are
compiled.

Cover invalid arguments, priority lookup, immediate and delayed work,
pending replacement and cancellation, periodic requeue, synchronous and
parallel cancellation, concurrent queues, callback self-destruction, and
queue teardown.

Assisted-by: Codex:GPT-5
Signed-off-by: DuoYuWang <thirteenking.wang@gmail.com>
@13022591351
13022591351 force-pushed the testing/custom-work-queues branch from e6b1b16 to e5e05b4 Compare September 7, 2026 09:49
@13022591351

13022591351 commented Sep 7, 2026

Copy link
Copy Markdown
Author

Thanks for the review, and sorry for the delayed update.

I force-pushed the branch after addressing all three comments:

  • Removed the __KERNEL__ path from the apps test.
  • Removed the top-level CONFIG_DISABLE_PTHREAD implementation split. Semaphore waits and basic workers are now shared, while conditional compilation is limited to tests that actually require pthread-backed custom queues.
  • Squashed the no-pthread USRWORK coverage into the main test commit.

The branch is now a single commit rebased onto the current nuttx-apps master.
The dependent NuttX work queue API PR, apache/nuttx#19982, has also been merged.

I rebuilt and tested the updated code on PX4 FMUv6C in Flat, Protected, and Protected-with-pthreads-disabled configurations. All work queue tests passed, including repeated runs without cumulative heap growth.

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.

2 participants