Skip to content

Fix reporter wraparound and add bounds checks#4

Merged
jserv merged 1 commit intomainfrom
improve
Mar 23, 2026
Merged

Fix reporter wraparound and add bounds checks#4
jserv merged 1 commit intomainfrom
improve

Conversation

@jserv
Copy link
Copy Markdown
Contributor

@jserv jserv commented Mar 23, 2026

Reporter tolerance check: (average - 1) wraps to ULONG_MAX when average is 0 (first cycle or short TM_TEST_DURATION runs), producing spurious ERROR messages. Guard with average > 0 before the check.

Reporter snapshot: volatile counters were read multiple times per report cycle: once for the total sum, again for each per-counter tolerance comparison. Workers keep incrementing between reads, making the check self-inconsistent. Snapshot all counters into locals in a single pass, then compute total/average/tolerance from the snapshot.

Porting layer bounds checks: all 13 API entry points in both ThreadX and FreeRTOS ports now validate thread_id, queue_id, semaphore_id, pool_id, and priority range, returning TM_ERROR for out-of-bounds values instead of silently indexing past array ends.


Summary by cubic

Fixes false ERRORs in test reporters by snapshotting counters and avoiding unsigned wraparound, and adds bounds checks to all port APIs to prevent out-of-range access. Improves correctness on short test runs and hardens the FreeRTOS/ThreadX ports.

  • Bug Fixes
    • Reporters: snapshot counters once per cycle and compute total/average/tolerance from the snapshot; skip tolerance checks when average is 0 to avoid (average - 1) underflow. Applies to cooperative, preemptive, interrupt, and interrupt-preemption reports.
    • Ports: validate thread/queue/semaphore/pool IDs and priority range in all 13 FreeRTOS and ThreadX API entry points; return TM_ERROR on invalid input instead of indexing past array bounds.

Written for commit b7e37b6. Summary will update on new commits.

Reporter tolerance check: (average - 1) wraps to ULONG_MAX when average
is 0 (first cycle or short TM_TEST_DURATION runs), producing spurious
ERROR messages. Guard with average > 0 before the check.

Reporter snapshot: volatile counters were read multiple times per report
cycle: once for the total sum, again for each per-counter tolerance
comparison. Workers keep incrementing between reads, making the check
self-inconsistent. Snapshot all counters into locals in a single pass,
then compute total/average/tolerance from the snapshot.

Porting layer bounds checks: all 13 API entry points in both ThreadX and
FreeRTOS ports now validate thread_id, queue_id, semaphore_id, pool_id,
and priority range, returning TM_ERROR for out-of-bounds values instead
of silently indexing past array ends.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 6 files

@github-actions
Copy link
Copy Markdown

Thread-Metric Benchmark Results

✅ All tests passed47703cf — 2026-03-23T11:08:25Z

Summary

RTOS Target OS Status Passed Failed Total
freertos cortex-m ubuntu-24.04 ✅ passed 8 0 8
freertos posix macos-latest ✅ passed 8 0 8
freertos posix ubuntu-24.04 ✅ passed 8 0 8
threadx cortex-m ubuntu-24.04 ✅ passed 8 0 8
threadx posix macos-latest ✅ passed 8 0 8
threadx posix ubuntu-24.04 ✅ passed 8 0 8

Per-Test Results

Test freertos/cortex-m freertos/posix freertos/posix threadx/cortex-m threadx/posix threadx/posix
basic_processing
cooperative_scheduling
preemptive_scheduling
message_processing
synchronization_processing
memory_allocation
interrupt_processing
interrupt_preemption_processing

@jserv jserv merged commit 9f5fb8c into main Mar 23, 2026
13 checks passed
@jserv jserv deleted the improve branch March 23, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant