tests/qtest: Introduce tests for Xilinx VERSAL CANFD controller
PATCH v6 4/4 tests/qtest: Introduce tests for Xilinx VERSAL CANFD controller
The QTests perform three tests on the Xilinx VERSAL CANFD controller:
Tests the CANFD controllers in loopback.
Tests the CANFD controllers in normal mode with CAN frame. Tests the CANFD controllers in normal mode with CANFD frame.
--- tests/qtest/meson.build | 1 + tests/qtest/xlnx-canfd-test.c | 423 ++++++++++++++++++++++++++++++++++ 2 files changed, 424 insertions(+) create mode 100644 tests/qtest/xlnx-canfd-test.c
tests/qtest/meson.build +1 -0
@@ -215,6 +215,7 @@ qtests_aarch64 = \ (config_all.has_key('CONFIG_TCG') and config_all_devices.has_key('CONFIG_TPM_TIS_SYSBUS') ? \ ['tpm-tis-device-test', 'tpm-tis-device-swtpm-test'] : []) + \ (config_all_devices.has_key('CONFIG_XLNX_ZYNQMP_ARM') ? ['xlnx-can-test', 'fuzz-xlnx-dp-test'] : []) + \ + (config_all_devices.has_key('CONFIG_XLNX_VERSAL') ? ['xlnx-canfd-test'] : []) + \ (config_all_devices.has_key('CONFIG_RASPI') ? ['bcm2835-dma-test'] : []) + \ (config_all.has_key('CONFIG_TCG') and \ config_all_devices.has_key('CONFIG_TPM_TIS_I2C') ? ['tpm-tis-i2c-test'] : []) + \
tests/qtest/xlnx-canfd-test.c new file +423 -0
423 lines not on this page · raw message
Signature · 1 line
2.17.1
Quoted 10 lines · Vikram Garhwal
The QTests perform three tests on the Xilinx VERSAL CANFD controller:
Tests the CANFD controllers in loopback.
Tests the CANFD controllers in normal mode with CAN frame. Tests the CANFD controllers in normal mode with CANFD frame.Signed-off-by Vikram Garhwal <[email protected]>Acked-by Thomas Huth <[email protected]>Reviewed-by Francisco Iglesias <[email protected]>Reviewed-by Peter Maydell <[email protected]>
Hi; Coverity has spotted some issues with this test code; could you investigate and send followup patches, please ?
tests/qtest/xlnx-canfd-test.c line 268
Quoted 9 lines
tests/qtest/xlnx-canfd-test.c new file +9
-0+static void match_rx_tx_data (const uint32_t *buf_tx,const uint32_t *buf_rx, +bool is_canfd_frame) +{ +uint16_t size =0 ; +uint8_t len =CAN_FRAME_SIZE ; + +if (is_canfd_frame) { + len =CANFD_FRAME_SIZE ; + }
Here len is either 4 (if !is_canfd_frame) or 18 (if is_canfd_frame)...
Review
Quoted 2 lines
(quoted diff) +2
-0+ + while (size < len) {
...and we loop with size always less than len...
tests/qtest/xlnx-canfd-test.c line 275
Quoted 5 lines
tests/qtest/xlnx-canfd-test.c new file +5
-0+if (R_RX0_ID_OFFSET +4 * size ==R_RX0_DLC_OFFSET ) { + g_assert_cmpint((buf_rx[size] & DLC_FD_BIT_MASK), ==, + (buf_tx[size] &DLC_FD_BIT_MASK )); + }else { +if (!is_canfd_frame && size ==4 ) {
...so here this condition can never be true: if !is_canfd_frame then we know size is less than 4.
What was the intention here ?
(CID 1512900)
Quoted 11 lines
tests/qtest/xlnx-canfd-test.c new file +11
-0+break ; + } + + g_assert_cmpint(buf_rx[size], ==, buf_tx[size]); + } + + size++; + } +} +/* +* Xilinx CANFD supports both CAN and CANFD frames. This test will be
tests/qtest/xlnx-canfd-test.c line 296
Quoted 10 lines
tests/qtest/xlnx-canfd-test.c new file +10
-0+* transferring CAN frame i.e. 8 bytes of data from CANFD0 and CANFD1 through +* canbus. CANFD0 initiate the data transfer to can-bus, CANFD1 receives the +* data. Test compares the can frame data sent from CANFD0 and received on +* CANFD1. +*/ +static void test_can_data_transfer (void ) +{ +uint32_t buf_tx[CAN_FRAME_SIZE ] = {0x5a5bb9a4 ,0x80000000 , +0x12345678 ,0x87654321 }; +uint32_t buf_rx[CAN_FRAME_SIZE ] = {0x00 ,0x00 ,0x00 ,0x00 };
The buf_rx[] array here is only 4 bytes long...
Quoted 15 lines
tests/qtest/xlnx-canfd-test.c new file +15
-0+uint32_t status =0 ; + +generate_random_data (buf_tx, false); + +QTestState *qts =qtest_init ("-machine xlnx-versal-virt" +" -object can-bus,id=canbus" +" -machine canbus0=canbus" +" -machine canbus1=canbus" + ); + +configure_canfd (qts,MSR_NORMAL_MODE ); + +/* Check if CANFD0 and CANFD1 are in Normal mode. */ + status =qtest_readl (qts,CANFD0_BASE_ADDR +R_SR_OFFSET ); + status = status &STATUS_REG_MASK ;
tests/qtest/xlnx-canfd-test.c line 321
Quoted 10 lines
tests/qtest/xlnx-canfd-test.c new file +10
-0+ g_assert_cmpint(status, ==, STATUS_NORMAL_MODE); + + status =qtest_readl (qts,CANFD1_BASE_ADDR +R_SR_OFFSET ); + status = status &STATUS_REG_MASK ; + g_assert_cmpint(status, ==, STATUS_NORMAL_MODE); + +write_data (qts,CANFD0_BASE_ADDR , buf_tx, false); + +send_data (qts,CANFD0_BASE_ADDR ); +read_data (qts,CANFD1_BASE_ADDR , buf_rx);
...but read_data() will write up to 17 bytes of data to the buffer, if the incoming data from the device claims it to be a canfd frame. The device shouldn't really do that, but the point of a test is that the device might not be functioning correctly, so we should size buf_rx[] large enough to fit whatever read_data() writes to it.
(CID 1512899)
tests/qtest/xlnx-canfd-test.c line 325
Quoted 4 lines
tests/qtest/xlnx-canfd-test.c new file +4
-0+match_rx_tx_data (buf_tx, buf_rx, false); + +qtest_quit (qts); +}
thanks
-- PMM
Hi Peter,
Thanks for sharing the details. I will fix these and send a follow up patch soon.
Quoted 103 lines · Peter Maydell
Quoted 9 lines · Vikram Garhwal
The QTests perform three tests on the Xilinx VERSAL CANFD controller:
Tests the CANFD controllers in loopback.
Tests the CANFD controllers in normal mode with CAN frame. Tests the CANFD controllers in normal mode with CANFD frame.Signed-off-by Vikram Garhwal <[email protected]>Acked-by Thomas Huth <[email protected]>Reviewed-by Francisco Iglesias <[email protected]>Reviewed-by Peter Maydell <[email protected]>Hi; Coverity has spotted some issues with this test code; could you investigate and send followup patches, please ?
tests/qtest/xlnx-canfd-test.c line 268
Quoted 9 lines
tests/qtest/xlnx-canfd-test.c new file +9
-0+static void match_rx_tx_data (const uint32_t *buf_tx,const uint32_t *buf_rx, +bool is_canfd_frame) +{ +uint16_t size =0 ; +uint8_t len =CAN_FRAME_SIZE ; + +if (is_canfd_frame) { + len =CANFD_FRAME_SIZE ; + }Here len is either 4 (if !is_canfd_frame) or 18 (if
is_canfd_frame)...Review
Quoted 2 lines
(quoted diff) +2
-0+ + while (size < len) {...and we loop with size always less than len...
tests/qtest/xlnx-canfd-test.c line 275
Quoted 5 lines
tests/qtest/xlnx-canfd-test.c new file +5
-0+if (R_RX0_ID_OFFSET +4 * size ==R_RX0_DLC_OFFSET ) { + g_assert_cmpint((buf_rx[size] & DLC_FD_BIT_MASK), ==, + (buf_tx[size] &DLC_FD_BIT_MASK )); + }else { +if (!is_canfd_frame && size ==4 ) {...so here this condition can never be true: if !is_canfd_frame then we know size is less than 4.
What was the intention here ?
(CID 1512900)
Quoted 11 lines
tests/qtest/xlnx-canfd-test.c new file +11
-0+break ; + } + + g_assert_cmpint(buf_rx[size], ==, buf_tx[size]); + } + + size++; + } +} +/* +* Xilinx CANFD supports both CAN and CANFD frames. This test will be tests/qtest/xlnx-canfd-test.c line 296
Quoted 10 lines
tests/qtest/xlnx-canfd-test.c new file +10
-0+* transferring CAN frame i.e. 8 bytes of data from CANFD0 and CANFD1 through +* canbus. CANFD0 initiate the data transfer to can-bus, CANFD1 receives the +* data. Test compares the can frame data sent from CANFD0 and received on +* CANFD1. +*/ +static void test_can_data_transfer (void ) +{ +uint32_t buf_tx[CAN_FRAME_SIZE ] = {0x5a5bb9a4 ,0x80000000 , +0x12345678 ,0x87654321 }; +uint32_t buf_rx[CAN_FRAME_SIZE ] = {0x00 ,0x00 ,0x00 ,0x00 };The buf_rx[] array here is only 4 bytes long...
Quoted 15 lines
tests/qtest/xlnx-canfd-test.c new file +15
-0+uint32_t status =0 ; + +generate_random_data (buf_tx, false); + +QTestState *qts =qtest_init ("-machine xlnx-versal-virt" +" -object can-bus,id=canbus" +" -machine canbus0=canbus" +" -machine canbus1=canbus" + ); + +configure_canfd (qts,MSR_NORMAL_MODE ); + +/* Check if CANFD0 and CANFD1 are in Normal mode. */ + status =qtest_readl (qts,CANFD0_BASE_ADDR +R_SR_OFFSET ); + status = status &STATUS_REG_MASK ;tests/qtest/xlnx-canfd-test.c line 321
Quoted 10 lines
tests/qtest/xlnx-canfd-test.c new file +10
-0+ g_assert_cmpint(status, ==, STATUS_NORMAL_MODE); + + status =qtest_readl (qts,CANFD1_BASE_ADDR +R_SR_OFFSET ); + status = status &STATUS_REG_MASK ; + g_assert_cmpint(status, ==, STATUS_NORMAL_MODE); + +write_data (qts,CANFD0_BASE_ADDR , buf_tx, false); + +send_data (qts,CANFD0_BASE_ADDR ); +read_data (qts,CANFD1_BASE_ADDR , buf_rx);...but
read_data()will write up to 17 bytes of data to the buffer, if the incoming data from the device claims it to be a canfd frame. The device shouldn't really do that, but the point of a test is that the device might not be functioning correctly, so we should size buf_rx[] large enough to fit whateverread_data()writes to it.(CID 1512899)
tests/qtest/xlnx-canfd-test.c line 325
Quoted 4 lines
tests/qtest/xlnx-canfd-test.c new file +4
-0+match_rx_tx_data (buf_tx, buf_rx, false); + +qtest_quit (qts); +}thanks
-- PMM