Skip to content

Conversation

@Fix-Point
Copy link
Contributor

Summary

This PR introduces several enhancements and fixes across multiple testing modules in the NuttX test suite:

  1. Spinlock Test Enhancement (testing/ostest/spinlock.c):

    • Added comprehensive spinlock testing framework with support for regular spinlocks, recursive spinlocks (rspinlock), and sequence counters (seqlock)
    • Refactored the test to improve accuracy and minimize scheduling jitters by:
      • Using atomic operations instead of pthread barriers for synchronization
      • Setting thread affinity and maximum priority for more consistent timing
      • Adding CPU core distribution for SMP configurations
    • Fixed Coverity issues by adding null check for total_ns and correcting loop boundary conditions
    • Added proper error checking for pthread operations
  2. Timer Test Improvements:

    • Fixed output formatting for timer tests to handle timer_t type changes
    • Relaxed timing constraints for simulated environments (QEMU/SIM) to account for vCPU preemption
    • Fixed timer assertion logic in periodic timer tests
    • Addressed time calculation overflow issues by changing uint32_t to uint64_t
  3. Other Test Fixes:

    • Fixed a synchronization bug in watchdog timer test where callback count update order could cause random failures
    • Re-enabled work queue test in flat build mode
    • Added clock measurement to taclebench benchmark
    • Fixed timer jitter test parameters to avoid errors with large USEC_PER_TICK settings

Impact

  • Testing Coverage: Significantly improves spinlock testing with support for multiple lock types and SMP configurations
  • Test Reliability: Fixes timing issues in simulated environments, making tests more robust on QEMU and simulation platforms
  • Code Quality: Addresses multiple Coverity issues and adds proper error handling
  • Performance: Improved test accuracy through better thread scheduling and affinity management
  • Compatibility: Maintains backward compatibility while fixing type-related formatting issues
  • Documentation: Enhanced test output formatting for better debugging and analysis
  • Build System: No impact on build process; all changes are confined to test modules

Test

Internal CI/CT passed. Tested on rv-virt:smp, ostest passed.

Fix-Point and others added 15 commits January 27, 2026 10:35
Since sim and qemu are not cycle accurate simulators, if the vCPU thread is preempted by other high priority tasks, it may cause timing issues. This is easy to happen when the test machine is busy. This commit modifies the condition of timing error and prints out the latency as a warning.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
On QEMU, if vcpus are preempted by other threads, the deviation of the
timer might be very large, causing assertion failure. This commit
addressed the problem.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
On SIM and QEMU, it is inevitable that the simulating vCPU got preempted
by other threads, causing large timing delay. This commit relax the timing
constraints to reduce the CT error.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
On QEMU, if vcpus are preempted by other threads, the deviation of the
timer might be very large, causing assertion failure. This commit
addressed the problem.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit fixed the wrong-test case where the time is acquired after
the timer being set, leading to the assertion failure.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit is to make Coverity happy.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit increased the default interval of the timerjitter to avoid errors with large USEC_PER_TICK setting.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit used the interval to calculate the timejitter iteration.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit added clock measurement for taclebench.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit re-enabled wqueue_test in flat mode.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
If we updated `callback_cnt` before the `triggered_tick` in the wdog timer callback, the `wdtest_rand` might failed randomly. This commit fixed the synchronizing bug by swapping the execution order of updating.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commmit fixed the time multiplication overflow issue.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit fixed totally wrong test-cases for the periodical timers.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit added spinlock/rspinlock test.

Signed-off-by: jiangtao16 <jiangtao16@xiaomi.com>
On QEMU, if vcpus are preempted by other threads, the deviation of the
timer might be very large, causing assertion failure. This commit
addressed the problem.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
Fix-Point and others added 5 commits January 27, 2026 15:44
This commit added checking for the return value.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
When expanding the macro VERIY, (0 == pthread_barrier_wait(&param->pub->barrier)) < 0 always false.
Regardless of the value of its operands.

Signed-off-by: anpeiyun <anpeiyun@xiaomi.com>
This commit added checking for the return value.

Signed-off-by: anpeiyun <anpeiyun@xiaomi.com>
This commit refactored the spinlock test for better accuracy and
minimized jitters introduced by scheduling.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit fixed coverity for spinlock test.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
jerpelea
jerpelea previously approved these changes Jan 27, 2026
Since the kernel spinlocks can only work in flat mode, this commit
allowed spinlock_test only in flat mode.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
@xiaoxiang781216 xiaoxiang781216 merged commit 71561d2 into apache:master Jan 27, 2026
40 checks passed
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.

4 participants