-
Notifications
You must be signed in to change notification settings - Fork 7.5k
tests/lib/ringbuffer: Assertion failure at test_ring_buffer_main() #14869
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
Comments
does not fail on qemu_nios2 |
I've reproduced on Max10 HW, but this is still mysterious. I think this has something to do with unaligned memory access to the ring buffer storage area, still digging |
Seems that on the real Max10 board, trying to array reference an unaligned pointer implictly changes stuff. The rb_data[] array passed to ring_buf_item_put() is not 4-byte aligned. In emulation, and presumably on other hardware, we see:
But on the Max10 board, the unaligned pointer is treated differently:
We expect data[i] to be 0x44434241, which is what "ABCD" would look like if cast to a u32_t. It seems that the CPU is instead doing something which causes the array beginning to be treated as 0x00400e30 instead. I don't know if this is an undefined behavior problem with the test, or some bug on Max10. |
Casting the rb_data character array to a u32_t can result in an unaligned u32_t * pointer being passed to ring_buf_item_put(), since rb_data is only byte-aligned. Our Altera Max10 CPU build is not configured to detect unaligned memory access and throw an exception, it is instead rounding down the memory address of the data pointer to the nearest 4-byte value, causing the wrong data to be copied into the ring buffer. It appears that in the C standard this is considered Undefined Behavior so the approach this patch takes is to fix the test, by ensuring that rb_data is aligned to u32_t. Fixes: zephyrproject-rtos#14869 Signed-off-by: Andrew Boie <[email protected]>
I'm gonna go with this being undefined behavior. |
Casting the rb_data character array to a u32_t can result in an unaligned u32_t * pointer being passed to ring_buf_item_put(), since rb_data is only byte-aligned. Our Altera Max10 CPU build is not configured to detect unaligned memory access and throw an exception, it is instead rounding down the memory address of the data pointer to the nearest 4-byte value, causing the wrong data to be copied into the ring buffer. It appears that in the C standard this is considered Undefined Behavior so the approach this patch takes is to fix the test, by ensuring that rb_data is aligned to u32_t. Fixes: #14869 Signed-off-by: Andrew Boie <[email protected]>
verified that the tests/lib/ringbuffer test cases are passed with the latest commit 9926f94 |
Describe the bug
(memcmp((char *)getdata, rb_data, getsize * sizeof(u32_t)) == 0
Seen on Altera Max10
To Reproduce
Steps to reproduce the behavior:
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots or console output
Environment (please complete the following information):
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: