Skip to content
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

tests: Calling sem_destroy() on semaphores that are still being used #1160

Open
Tracked by #1161
stanislaw opened this issue Sep 22, 2021 · 0 comments
Open
Tracked by #1161
Labels
bug unit-test Tickets related to the OSAL unit testing (functional and/or coverage)

Comments

@stanislaw
Copy link
Contributor

Is your feature request related to a problem? Please describe.

(I would like to open this as a general discussion so using the Feature ticket as the closest one)

Running some of the OSAL's tests on macOS results in BUG IN CLIENT OF LIBDISPATCH: Semaphore object deallocated while in use". Instead of <semaphore.h> macOS's provides <dispatch/semaphore.h> and with some minor differences, the API is very similar. The above error message is a protection built in the implementation of semaphores to prevent a user from calling dispatch_release() on a semaphore that is still being used.

Describe the solution you'd like

3 of the current OSAL's test are hitting this error (see Appendix below) and I am wondering if it would be practical to improve the design of these tests.

I would also like to check with someone my understanding that destroying the resources while they are still being used results in undefined behaviour and that the undefined behaviour should be avoided even if the scope is test code, not the OSAL code itself.

Describe alternatives you've considered

For now, I am using an alternative implementation of semaphores found here but I think it would be better to use the dispatch_semaphore.h as a more native implementation on macOS.

Additional context

Requester Info

Stanislav Pankevich, individual contribution.


Appendix: Calling sem_destroy() when a semaphore is still being used

70 - osal_core_UT (ILLEGAL)

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
  * frame #0: 0x00007fff2026d229 libdispatch.dylib`_dispatch_semaphore_dispose.cold.1 + 27
    frame #1: 0x00007fff202400bc libdispatch.dylib`_dispatch_semaphore_dispose + 46
    frame #2: 0x00007fff2023ec1a libdispatch.dylib`_dispatch_dispose + 87
    frame #3: 0x000000010804c130 osal_core_UT`mac_sem_destroy(psem=0x00000001082b1f90) at posix-macos-semaphore2.c:44:5
    frame #4: 0x0000000108049964 osal_core_UT`OS_CountSemDelete_Impl(token=0x00007ffee7bcf8d8) at os-impl-countsem.c:114:9
    frame #5: 0x000000010803f386 osal_core_UT`OS_CountSemDelete(sem_id=196634) at osapi-countsem.c:135:23
    frame #6: 0x0000000108038416 osal_core_UT`UT_os_count_sem_take_test at ut_oscore_countsem_test.c:235:9
    frame #7: 0x000000010803e4f9 osal_core_UT`UtTest_Run at uttest.c:174:17
    frame #8: 0x000000010803dae9 osal_core_UT`OS_Application_Run at utbsp.c:232:5
    frame #9: 0x000000010805154a osal_core_UT`main(argc=1, argv=0x00007ffee7bcf9d8) at bsp_start.c:247:5
    frame #10: 0x00007fff20404f3d libdyld.dylib`start + 1
    frame #11: 0x00007fff20404f3d libdyld.dylib`start + 1
_dispatch_semaphore_dispose.cold.1:
	movq   %rsi, %rax
	subq   (%rdi), %rax
	leaq   0x62a5(%rip), %rcx         ; "BUG IN CLIENT OF LIBDISPATCH: Semaphore object deallocated while in use"
	movq   %rcx, 0x604a3566(%rip)     ; gCRAnnotations + 8
	movq   %rax, 0x604a358f(%rip)     ; gCRAnnotations + 56
	ud2

54 - count-sem-test (ILLEGAL)

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
  * frame #0: 0x00007fff2026d229 libdispatch.dylib`_dispatch_semaphore_dispose.cold.1 + 27
    frame #1: 0x00007fff202400bc libdispatch.dylib`_dispatch_semaphore_dispose + 46
    frame #2: 0x00007fff2023ec1a libdispatch.dylib`_dispatch_dispose + 87
    frame #3: 0x0000000102c1f980 count-sem-test`mac_sem_destroy(psem=0x0000000102c3cbc8) at posix-macos-semaphore2.c:44:5
    frame #4: 0x0000000102c1d1c4 count-sem-test`OS_CountSemDelete_Impl(token=0x00007ffeecff47c8) at os-impl-countsem.c:114:9
    frame #5: 0x0000000102c13156 count-sem-test`OS_CountSemDelete(sem_id=196609) at osapi-countsem.c:135:23
    frame #6: 0x0000000102c12e7d count-sem-test`OS_CleanUpObject(object_id=196609, arg=0x00007ffeecff493c) at osapi-common.c:332:13
    frame #7: 0x0000000102c160fc count-sem-test`OS_ForEachDoCallback(obj_id=196609, ref=0x00007ffeecff4880) at osapi-idmap.c:247:5
    frame #8: 0x0000000102c1731d count-sem-test`OS_ObjectIdIteratorProcessEntry(iter=0x00007ffeecff4898, func=(count-sem-test`OS_ForEachDoCallback at osapi-idmap.c:243)) at osapi-idmap.c:1370:14
    frame #9: 0x0000000102c1743a count-sem-test`OS_ForEachObjectOfType(idtype=3, creator_id=0, callback_ptr=(count-sem-test`OS_CleanUpObject at osapi-common.c:315), callback_arg=0x00007ffeecff493c) at osapi-idmap.c:1436:13
    frame #10: 0x0000000102c173a7 count-sem-test`OS_ForEachObject(creator_id=0, callback_ptr=(count-sem-test`OS_CleanUpObject at osapi-common.c:315), callback_arg=0x00007ffeecff493c) at osapi-idmap.c:1410:9
    frame #11: 0x0000000102c12cf9 count-sem-test`OS_DeleteAllObjects at osapi-common.c:386:9
    frame #12: 0x0000000102c12c49 count-sem-test`OS_API_Teardown at osapi-common.c:262:5
    frame #13: 0x0000000102c123b9 count-sem-test`UtTest_Run at uttest.c:180:17
    frame #14: 0x0000000102c11979 count-sem-test`OS_Application_Run at utbsp.c:232:5
    frame #15: 0x0000000102c24c1a count-sem-test`main(argc=1, argv=0x00007ffeecff4a08) at bsp_start.c:247:5
    frame #16: 0x00007fff20404f3d libdyld.dylib`start + 1
    frame #17: 0x00007fff20404f3d libdyld.dylib`start + 1
_dispatch_semaphore_dispose.cold.1:
	movq   %rsi, %rax
	subq   (%rdi), %rax
	leaq   0x62a5(%rip), %rcx         ; "BUG IN CLIENT OF LIBDISPATCH: Semaphore object deallocated while in use"
	movq   %rcx, 0x604a3566(%rip)     ; gCRAnnotations + 8
	movq   %rax, 0x604a358f(%rip)     ; gCRAnnotations + 56
	ud2

55 - count-sem-timeout-test (ILLEGAL)

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
  * frame #0: 0x00007fff2026d229 libdispatch.dylib`_dispatch_semaphore_dispose.cold.1 + 27
    frame #1: 0x00007fff202400bc libdispatch.dylib`_dispatch_semaphore_dispose + 46
    frame #2: 0x00007fff2023ec1a libdispatch.dylib`_dispatch_dispose + 87
    frame #3: 0x0000000106f7a840 count-sem-timeout-test`mac_sem_destroy(psem=0x0000000106f97bc8) at posix-macos-semaphore2.c:44:5
    frame #4: 0x0000000106f78084 count-sem-timeout-test`OS_CountSemDelete_Impl(token=0x00007ffee8c997b8) at os-impl-countsem.c:114:9
    frame #5: 0x0000000106f6e016 count-sem-timeout-test`OS_CountSemDelete(sem_id=196609) at osapi-countsem.c:135:23
    frame #6: 0x0000000106f6dd3d count-sem-timeout-test`OS_CleanUpObject(object_id=196609, arg=0x00007ffee8c9992c) at osapi-common.c:332:13
    frame #7: 0x0000000106f70fbc count-sem-timeout-test`OS_ForEachDoCallback(obj_id=196609, ref=0x00007ffee8c99870) at osapi-idmap.c:247:5
    frame #8: 0x0000000106f721dd count-sem-timeout-test`OS_ObjectIdIteratorProcessEntry(iter=0x00007ffee8c99888, func=(count-sem-timeout-test`OS_ForEachDoCallback at osapi-idmap.c:243)) at osapi-idmap.c:1370:14
    frame #9: 0x0000000106f722fa count-sem-timeout-test`OS_ForEachObjectOfType(idtype=3, creator_id=0, callback_ptr=(count-sem-timeout-test`OS_CleanUpObject at osapi-common.c:315), callback_arg=0x00007ffee8c9992c) at osapi-idmap.c:1436:13
    frame #10: 0x0000000106f72267 count-sem-timeout-test`OS_ForEachObject(creator_id=0, callback_ptr=(count-sem-timeout-test`OS_CleanUpObject at osapi-common.c:315), callback_arg=0x00007ffee8c9992c) at osapi-idmap.c:1410:9
    frame #11: 0x0000000106f6dbb9 count-sem-timeout-test`OS_DeleteAllObjects at osapi-common.c:386:9
    frame #12: 0x0000000106f6db09 count-sem-timeout-test`OS_API_Teardown at osapi-common.c:262:5
    frame #13: 0x0000000106f6d279 count-sem-timeout-test`UtTest_Run at uttest.c:180:17
    frame #14: 0x0000000106f6c839 count-sem-timeout-test`OS_Application_Run at utbsp.c:232:5
    frame #15: 0x0000000106f7fada count-sem-timeout-test`main(argc=1, argv=0x00007ffee8c999f8) at bsp_start.c:247:5
    frame #16: 0x00007fff20404f3d libdyld.dylib`start + 1
    frame #17: 0x00007fff20404f3d libdyld.dylib`start + 1
_dispatch_semaphore_dispose.cold.1:
	movq   %rsi, %rax
	subq   (%rdi), %rax
	leaq   0x62a5(%rip), %rcx         ; "BUG IN CLIENT OF LIBDISPATCH: Semaphore object deallocated while in use"
	movq   %rcx, 0x604a3566(%rip)     ; gCRAnnotations + 8
	movq   %rax, 0x604a358f(%rip)     ; gCRAnnotations + 56
	ud2
@skliper skliper added bug unit-test Tickets related to the OSAL unit testing (functional and/or coverage) labels Sep 22, 2021
@stanislaw stanislaw changed the title Tests: Calling sem_destroy() on semaphores that are still being used tests: Calling sem_destroy() on semaphores that are still being used Sep 22, 2021
jphickey pushed a commit to jphickey/osal that referenced this issue Aug 10, 2022
jphickey pushed a commit to jphickey/osal that referenced this issue Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug unit-test Tickets related to the OSAL unit testing (functional and/or coverage)
Projects
None yet
Development

No branches or pull requests

2 participants