zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.96k stars 6.67k forks source link

test: portability.posix.env.newlib/portability.posix.common.newlib Fatal error on nsim #79276

Open KamilxPaszkiet opened 1 month ago

KamilxPaszkiet commented 1 month ago

Describe the bug Tests: tests/posix/env/portability.posix.env.newlib and tests/posix/common/portability.posix.common.newlib end with error. I think these are similar problems.

To Reproduce twister -p nsim_em -s tests/posix/env/portability.posix.env.newlib twister -p nsim_em -s tests/posix/common/portability.posix.common.newlib

Logs and console output tests/posix/env/portability.posix.env.newlib:

*** Booting Zephyr OS build v3.7.0-3583-g0a20f24d7090 ***
Running TESTSUITE env
===================================================================
START - test_getenv
 PASS - test_getenv in 0.001 seconds
===================================================================
START - test_getenv_r
 PASS - test_getenv_r in 0.002 seconds
===================================================================
START - test_setenv
 PASS - test_setenv in 0.001 seconds
===================================================================
START - test_unsetenv
 PASS - test_unsetenv in 0.002 seconds
===================================================================
START - test_watertight
E: ***** Exception vector: 0x6, cause code: 0x1, parameter 0x2
E: Address 0x80000b40
E: EV_ProtV
E: Memory read protection violation (stack checking scheme)
E:  r0: 0x80000b44  r1: 0x0  r2: 0x8000009c  r3: 0x80000b47
E:  r4: 0x80808080  r5: 0x3d3d3d3d  r6: 0x3d6f7869  r7: 0x0
E:  r8: 0x1010101  r9: 0x0 r10: 0x80002cd0 r11: 0x80808080
E: r12: 0x3 r13: 0x0  pc: 0x7ae0
E:  blink: 0x14c status32: 0x80086a06
E: lp_end: 0x7bea lp_start: 0x7bdc lp_count: 0x0
E: >>> ZEPHYR FATAL ERROR 2: Stack overflow on CPU 0
E: Current thread: 0x8000009c (test_watertight)
E: Halting system
Console now belongs to simulator.

tests/posix/common/portability.posix.common.newlib:

*** Booting Zephyr OS build v3.7.0-3583-g0a20f24d7090 ***
Running TESTSUITE barrier
===================================================================
START - test_barrier
 PASS - test_barrier in 0.001 seconds
===================================================================
TESTSUITE barrier succeeded
Running TESTSUITE clock
===================================================================
START - test_clock_getcpuclockid
 PASS - test_clock_getcpuclockid in 0.001 seconds
===================================================================
START - test_clock_getres
 PASS - test_clock_getres in 0.001 seconds
===================================================================
START - test_clock_gettime
 PASS - test_clock_gettime in 0.001 seconds
===================================================================
START - test_clock_settime
 PASS - test_clock_settime in 0.001 seconds
===================================================================
START - test_gettimeofday
 PASS - test_gettimeofday in 0.001 seconds
===================================================================
START - test_realtime
I: n: 20, sleep: 100, margin: 10, lo: 110, avg: 110, hi: 110
 PASS - test_realtime in 2.199 seconds
===================================================================
TESTSUITE clock succeeded
Running TESTSUITE cond
===================================================================
START - test_cond_resource_exhausted
 PASS - test_cond_resource_exhausted in 0.001 seconds
===================================================================
START - test_cond_resource_leak
 PASS - test_cond_resource_leak in 0.002 seconds
===================================================================
START - test_pthread_condattr
 PASS - test_pthread_condattr in 0.001 seconds
===================================================================
TESTSUITE cond succeeded
Running TESTSUITE confstr
===================================================================
START - test_confstr
 PASS - test_confstr in 0.001 seconds
===================================================================
TESTSUITE confstr succeeded
Running TESTSUITE fnmatch
===================================================================
START - test_fnmatch
 PASS - test_fnmatch in 0.003 seconds
===================================================================
TESTSUITE fnmatch succeeded
Running TESTSUITE grp
===================================================================
START - test_grp_stubs
 PASS - test_grp_stubs in 0.001 seconds
===================================================================
TESTSUITE grp succeeded
Running TESTSUITE key
===================================================================
START - test_correct_key_is_deleted
 PASS - test_correct_key_is_deleted in 0.001 seconds
===================================================================
START - test_key_1toN_thread
 PASS - test_key_1toN_thread in 0.003 seconds
===================================================================
START - test_key_Nto1_thread
 PASS - test_key_Nto1_thread in 0.002 seconds
===================================================================
START - test_key_resource_leak
 PASS - test_key_resource_leak in 0.001 seconds
===================================================================
TESTSUITE key succeeded
Running TESTSUITE mqueue
===================================================================
START - test_mqueue
 PASS - test_mqueue in 0.023 seconds
===================================================================
START - test_mqueue_notify_basic
 PASS - test_mqueue_notify_basic in 0.002 seconds
===================================================================
START - test_mqueue_notify_errors
 PASS - test_mqueue_notify_errors in 0.002 seconds
===================================================================
START - test_mqueue_notify_non_empty_queue
 PASS - test_mqueue_notify_non_empty_queue in 0.002 seconds
===================================================================
START - test_mqueue_notify_thread
 PASS - test_mqueue_notify_thread in 0.104 seconds
===================================================================
TESTSUITE mqueue succeeded
Running TESTSUITE mutex
===================================================================
START - test_mutex_normal
mutex lock is taken
 PASS - test_mutex_normal in 0.105 seconds
===================================================================
START - test_mutex_prioceiling_stubs
 PASS - test_mutex_prioceiling_stubs in 0.001 seconds
===================================================================
START - test_mutex_recursive
recursive mutex lock is taken
 PASS - test_mutex_recursive in 0.105 seconds
===================================================================
START - test_mutex_resource_exhausted
 PASS - test_mutex_resource_exhausted in 0.001 seconds
===================================================================
START - test_mutex_resource_leak
 PASS - test_mutex_resource_leak in 0.002 seconds
===================================================================
START - test_mutex_timedlock
Expecting timedlock with timeout of 200 ms to fail
Expecting timedlock with timeout of 200 ms to succeed after 100ms
 PASS - test_mutex_timedlock in 0.320 seconds
===================================================================
TESTSUITE mutex succeeded
Running TESTSUITE mutex_attr
===================================================================
START - test_pthread_mutexattr_destroy
 PASS - test_pthread_mutexattr_destroy in 0.001 seconds
===================================================================
START - test_pthread_mutexattr_gettype
 PASS - test_pthread_mutexattr_gettype in 0.001 seconds
===================================================================
START - test_pthread_mutexattr_init
 PASS - test_pthread_mutexattr_init in 0.001 seconds
===================================================================
START - test_pthread_mutexattr_settype
 PASS - test_pthread_mutexattr_settype in 0.001 seconds
===================================================================
TESTSUITE mutex_attr succeeded
Running TESTSUITE nanosleep
===================================================================
START - test_clock_nanosleep_errors_errno
 PASS - test_clock_nanosleep_errors_errno in 0.001 seconds
===================================================================
START - test_clock_nanosleep_execution
 PASS - test_clock_nanosleep_execution in 3.015 seconds
===================================================================
START - test_nanosleep_errors_errno
 PASS - test_nanosleep_errors_errno in 2.028 seconds
===================================================================
START - test_nanosleep_execution
 PASS - test_nanosleep_execution in 3.538 seconds
===================================================================
TESTSUITE nanosleep succeeded
Running TESTSUITE posix_apis
===================================================================
START - test_fdtable_init
 PASS - test_fdtable_init in 0.001 seconds
===================================================================
START - test_posix_sysconf
 PASS - test_posix_sysconf in 0.001 seconds
===================================================================
TESTSUITE posix_apis succeeded
Running TESTSUITE pthread
===================================================================
START - test_pthread_cleanup
 PASS - test_pthread_cleanup in 0.001 seconds
===================================================================
START - test_pthread_descriptor_leak
 PASS - test_pthread_descriptor_leak in 0.006 seconds
===================================================================
START - test_pthread_equal
 PASS - test_pthread_equal in 0.001 seconds
===================================================================
START - test_pthread_execution
Thread 0 starting with scheduling policy 1 & priority 0
Thread 1 starting with scheduling policy 1 & priority 0
Thread 2 starting with scheduling policy 1 & priority 0
Bounce test OK
Barrier test OK
 PASS - test_pthread_execution in 4.987 seconds
===================================================================
START - test_pthread_priority_conversion
 PASS - test_pthread_priority_conversion in 0.001 seconds
===================================================================
START - test_pthread_set_get_concurrency
 PASS - test_pthread_set_get_concurrency in 0.001 seconds
===================================================================
START - test_pthread_setschedprio
 PASS - test_pthread_setschedprio in 0.001 seconds
===================================================================
START - test_pthread_termination
Thread 0 starting with a priority of 4
Cancelling thread 0
Thread 0 could not be cancelled
Thread 1 starting with a priority of 3
Cancelling thread 1
Thread 1 could not be cancelled
Thread 2 starting with a priority of 2
Cancelling thread 2
Thread 2 could not be cancelled
Thread 3 starting with a priority of 1
Cancelling thread 3
Thread 3 could not be cancelled
 PASS - test_pthread_termination in 1.012 seconds
===================================================================
START - test_pthread_testcancel
 PASS - test_pthread_testcancel in 0.001 seconds
===================================================================
START - test_sched_getparam
 PASS - test_sched_getparam in 0.001 seconds
===================================================================
START - test_sched_getscheduler
 PASS - test_sched_getscheduler in 0.001 seconds
===================================================================
START - test_sched_rr_get_interval
 PASS - test_sched_rr_get_interval in 0.001 seconds
===================================================================
START - test_sched_setparam
 PASS - test_sched_setparam in 0.001 seconds
===================================================================
START - test_sched_setscheduler
 PASS - test_sched_setscheduler in 0.001 seconds
===================================================================
TESTSUITE pthread succeeded
Running TESTSUITE pthread_attr
===================================================================
START - test_null_attr
 PASS - test_null_attr in 0.001 seconds
===================================================================
START - test_pthread_attr_getdetachstate
 PASS - test_pthread_attr_getdetachstate in 0.001 seconds
===================================================================
START - test_pthread_attr_getguardsize
 PASS - test_pthread_attr_getguardsize in 0.001 seconds
===================================================================
START - test_pthread_attr_getinheritsched
 PASS - test_pthread_attr_getinheritsched in 0.001 seconds
===================================================================
START - test_pthread_attr_getschedparam
 PASS - test_pthread_attr_getschedparam in 0.001 seconds
===================================================================
START - test_pthread_attr_getschedpolicy
 PASS - test_pthread_attr_getschedpolicy in 0.001 seconds
===================================================================
START - test_pthread_attr_getscope
 PASS - test_pthread_attr_getscope in 0.001 seconds
===================================================================
START - test_pthread_attr_getstack
 PASS - test_pthread_attr_getstack in 0.001 seconds
===================================================================
START - test_pthread_attr_getstacksize
 PASS - test_pthread_attr_getstacksize in 0.001 seconds
===================================================================
START - test_pthread_attr_init_destroy
 PASS - test_pthread_attr_init_destroy in 0.002 seconds
===================================================================
START - test_pthread_attr_large_stacksize
Unable to allocate large stack of size 8388608 (skipping)
 SKIP - test_pthread_attr_large_stacksize in 0.002 seconds
===================================================================
START - test_pthread_attr_policy_and_priority_limits
 PASS - test_pthread_attr_policy_and_priority_limits in 0.004 seconds
===================================================================
START - test_pthread_attr_setdetachstate
 PASS - test_pthread_attr_setdetachstate in 0.202 seconds
===================================================================
START - test_pthread_attr_setguardsize
 PASS - test_pthread_attr_setguardsize in 0.001 seconds
===================================================================
START - test_pthread_attr_setinheritsched
 PASS - test_pthread_attr_setinheritsched in 0.002 seconds
===================================================================
START - test_pthread_attr_setschedparam
 PASS - test_pthread_attr_setschedparam in 0.001 seconds
===================================================================
START - test_pthread_attr_setschedpolicy
 PASS - test_pthread_attr_setschedpolicy in 0.001 seconds
===================================================================
START - test_pthread_attr_setscope
 PASS - test_pthread_attr_setscope in 0.001 seconds
===================================================================
START - test_pthread_attr_setstack
 PASS - test_pthread_attr_setstack in 0.002 seconds
===================================================================
START - test_pthread_attr_setstacksize
 PASS - test_pthread_attr_setstacksize in 0.002 seconds
===================================================================
START - test_pthread_attr_static_corner_cases
 SKIP - test_pthread_attr_static_corner_cases in 0.001 seconds
===================================================================
TESTSUITE pthread_attr succeeded
Running TESTSUITE pwd
===================================================================
START - test_pwd_stubs
 PASS - test_pwd_stubs in 0.001 seconds
===================================================================
TESTSUITE pwd succeeded
Running TESTSUITE rwlock
===================================================================
START - test_pthread_rwlockattr_getpshared
 PASS - test_pthread_rwlockattr_getpshared in 0.001 seconds
===================================================================
START - test_pthread_rwlockattr_setpshared
 PASS - test_pthread_rwlockattr_setpshared in 0.001 seconds
===================================================================
START - test_rw_lock
 PASS - test_rw_lock in 0.133 seconds
===================================================================
TESTSUITE rwlock succeeded
Running TESTSUITE semaphore
===================================================================
START - test_named_semaphore
 PASS - test_named_semaphore in 5.695 seconds
===================================================================
START - test_semaphore
 PASS - test_semaphore in 5.008 seconds
===================================================================
TESTSUITE semaphore succeeded
Running TESTSUITE signal
===================================================================
START - test_pthread_sigmask
 PASS - test_pthread_sigmask in 0.002 seconds
===================================================================
START - test_sigaddset
 PASS - test_sigaddset in 0.001 seconds
===================================================================
START - test_sigaddset_oor
 PASS - test_sigaddset_oor in 0.001 seconds
===================================================================
START - test_sigdelset
 PASS - test_sigdelset in 0.001 seconds
===================================================================
START - test_sigdelset_oor
 PASS - test_sigdelset_oor in 0.001 seconds
===================================================================
START - test_sigemptyset
 PASS - test_sigemptyset in 0.001 seconds
===================================================================
START - test_sigfillset
 PASS - test_sigfillset in 0.001 seconds
===================================================================
START - test_sigismember
 PASS - test_sigismember in 0.001 seconds
===================================================================
START - test_sigismember_oor
 PASS - test_sigismember_oor in 0.001 seconds
===================================================================
START - test_signal_strsignal
E: ***** Exception vector: 0x6, cause code: 0x1, parameter 0x2
E: Address 0x800041b0
E: EV_ProtV
E: Memory read protection violation (stack checking scheme)
E:  r0: 0x800041b4  r1: 0x800040f0  r2: 0x800016e0  r3: 0x800041b7
E:  r4: 0x1010101  r5: 0xb  r6: 0x1  r7: 0x1010101
E:  r8: 0x8000412c  r9: 0x0 r10: 0x0 r11: 0x0
E: r12: 0xa r13: 0x27394 pc: 0x186fc
E:  blink: 0x776e status32: 0x80086a06
E: lp_end: 0x1c3cc lp_start: 0x1c3c4 lp_count: 0x0
E: >>> ZEPHYR FATAL ERROR 2: Stack overflow on CPU 0
E: Current thread: 0x800012c4 (test_signal_strsignal)
E: Halting system
Console now belongs to simulator.

Expected behavior Tests passed

Environment:

cfriedt commented 1 month ago

It looks like a stack overflow, so perhaps a configuration issue?

gbarkadiusz commented 9 hours ago

Observed also on nsim/nsim_hs/mpuv6. nsim/nsim_hs/mpuv6 tests/posix/common/portability.posix.common.newlib FAILED Timeout (nsim 2.060s) _twister-out/nsim_nsim_hsmpuv6/tests/posix/common/portability.posix.common.newlib/handler.log

...
===================================================================
START - test_sigismember_oor
 PASS - test_sigismember_oor in 0.001 seconds
===================================================================
START - test_signal_strsignal
E: ***** Exception vector: 0x6, cause code: 0x1, parameter 0x2
E: Address 0x80003da0
E: EV_ProtV
E: Memory read protection violation (stack checking scheme)
E:  r0: 0x80003da4  r1: 0x80003ce0  r2: 0x800016cc  r3: 0x80003da7
E:  r4: 0xb  r5: 0x1  r6: 0x2e  r7: 0x0
E:  r8: 0x0  r9: 0x0 r10: 0x0 r11: 0x2a1bd
E: r12: 0xa r13: 0x2758c  pc: 0x16fb4
E:  blink: 0x76ba status32: 0x80086a02
E: lp_end: 0x1a9ac lp_start: 0x1a9a4 lp_count: 0x0
E: >>> ZEPHYR FATAL ERROR 2: Stack overflow on CPU 0
E: Current thread: 0x800012b4 (test_s)
E: Halting system
ruuddw commented 4 hours ago

Looks like a problem with the 'optimized' newlib strlen implementation that compares words instead of bytes. These instructions trigger the problem:

strlen       or           %r3,%r0,7
strlen+0x04  ld           %r2,[%r3,-7] 

ARC hardware stack bounds checking not only ensures the stack stays within bounds but also raises an exception on non-sp based memory references to the unallocated stack (between stack_top and sp). The word alignment (or 7) and correction (-7 offset) points to a valid address (4 bytebuf), but r3 points to the unallocated stack.

Not sure yet who's to blame and where to fix: compiler, newlib (or even hardware to not check the base but base+offset...)?