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.52k stars 6.45k forks source link

tests/lib/ringbuffer: Assertion failure at test_ring_buffer_main() #14869

Closed cinlyooi-intel closed 5 years ago

cinlyooi-intel commented 5 years ago

Describe the bug (memcmp((char )getdata, rb_data, getsize sizeof(u32_t)) == 0

Seen on Altera Max10

To Reproduce Steps to reproduce the behavior:

  1. mkdir build; cd build
  2. cmake -DBOARD=altera_max10
  3. make
  4. make run

Expected behavior A clear and concise description of what you expected to happen.

Screenshots or console output

***** Booting Zephyr OS v1.14.0-rc1-1386-g5d35b6632765 (delayed boot 3000ms) *****
Running test suite test_ringbuffer_api
===================================================================
starting test - test_ringbuffer_init
PASS - test_ringbuffer_init
===================================================================
starting test - test_ringbuffer_declare_pow2
PASS - test_ringbuffer_declare_pow2
===================================================================
starting test - test_ringbuffer_declare_size
PASS - test_ringbuffer_declare_size
===================================================================
starting test - test_ringbuffer_put_get_thread
PASS - test_ringbuffer_put_get_thread
===================================================================
starting test - test_ringbuffer_put_get_isr
PASS - test_ringbuffer_put_get_isr
===================================================================
starting test - test_ringbuffer_put_get_thread_isr
PASS - test_ringbuffer_put_get_thread_isr
===================================================================
starting test - test_ringbuffer_pow2_put_get_thread_isr
PASS - test_ringbuffer_pow2_put_get_thread_isr
===================================================================
starting test - test_ringbuffer_size_put_get_thread_isr
PASS - test_ringbuffer_size_put_get_thread_isr
===================================================================
starting test - test_ring_buffer_main
    Assertion failed at /home/jenkins/workspace/zephyr-master-ci-master/zephyr.git/tests/lib/ringbuffer/src/main.c:95: test_ring_buffer_main: ((memcmp((char *)getdata, rb_data, getsize * sizeof(u32_t)) == 0) is false)**
data corrupted
FAIL - test_ring_buffer_main
===================================================================
starting test - test_ringbuffer_raw
PASS - test_ringbuffer_raw
===================================================================
starting test - test_ringbuffer_alloc_put
PASS - test_ringbuffer_alloc_put
===================================================================
starting test - test_byte_put_free
PASS - test_byte_put_free
===================================================================
Test suite test_ringbuffer_api failed.
===================================================================

Environment (please complete the following information):

Additional context Add any other context about the problem here.

andrewboie commented 5 years ago

does not fail on qemu_nios2

andrewboie commented 5 years ago

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

andrewboie commented 5 years ago

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:

RB PUT TO ADDR 0x00400e47
data[i] is 44434241

But on the Max10 board, the unaligned pointer is treated differently:

RB PUT TO ADDR 0x00400e33
data[i] is 41000000

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.

andrewboie commented 5 years ago

https://stackoverflow.com/questions/51126257/what-does-the-standard-say-about-unaligned-memory-access

I'm gonna go with this being undefined behavior.

arun1joshi commented 5 years ago

verified that the tests/lib/ringbuffer test cases are passed with the latest commit 9926f94