Skip to content

Commit f7853df

Browse files
decsnydanieldegrasse
authored andcommitted
tests: spi_loopback: Fix same_buf_cmd test
The tests was written wrong. It was meant to test using same spi bufs for both rx and tx, as in tree many sensor and other spi device drivers use this paradigm. But the 2nd buf setup call was overwriting the first. Fix by not using the helper function for this case. And for the write back test, test using same spi_buf_set. Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
1 parent 1804eb7 commit f7853df

File tree

1 file changed

+19
-14
lines changed
  • tests/drivers/spi/spi_loopback/src

1 file changed

+19
-14
lines changed

tests/drivers/spi/spi_loopback/src/spi.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -599,18 +599,17 @@ ZTEST(spi_loopback, test_nop_nil_bufs)
599599
/* nothing really to check here, check is done in spi_loopback_transceive */
600600
}
601601

602-
/* test using the same buffer for RX and TX will write same data back */
602+
/* test using the same buffer set for RX and TX will write same data back */
603603
ZTEST(spi_loopback, test_spi_write_back)
604604
{
605605
struct spi_dt_spec *spec = loopback_specs[spec_idx];
606-
const struct spi_buf_set tx = spi_loopback_setup_xfer(rx_bufs_pool, 1,
607-
buffer_rx, BUF_SIZE);
608-
const struct spi_buf_set rx = spi_loopback_setup_xfer(rx_bufs_pool, 1,
609-
buffer_rx, BUF_SIZE);
606+
607+
struct spi_buf buf = {.buf = buffer_rx, .len = BUF_SIZE};
608+
struct spi_buf_set set = {.buffers = &buf, .count = 1};
610609

611610
memcpy(buffer_rx, tx_data, sizeof(tx_data));
612611

613-
spi_loopback_transceive(spec, &tx, &rx);
612+
spi_loopback_transceive(spec, &set, &set);
614613

615614
spi_loopback_compare_bufs(tx_data, buffer_rx, BUF_SIZE,
616615
buffer_print_tx, buffer_print_rx);
@@ -620,19 +619,25 @@ ZTEST(spi_loopback, test_spi_write_back)
620619
ZTEST(spi_loopback, test_spi_same_buf_cmd)
621620
{
622621
struct spi_dt_spec *spec = loopback_specs[spec_idx];
623-
const struct spi_buf_set tx = spi_loopback_setup_xfer(rx_bufs_pool, 2,
624-
buffer_rx, 1,
625-
NULL, BUF_SIZE - 1);
626-
const struct spi_buf_set rx = spi_loopback_setup_xfer(rx_bufs_pool, 1,
627-
NULL, BUF_SIZE - 1,
628-
buffer_rx+(BUF_SIZE - 1), 1);
629622

630-
memcpy(buffer_rx, tx_data, sizeof(tx_data));
623+
struct spi_buf buf[2] = {
624+
{.buf = buffer_rx, .len = 1},
625+
{.buf = buffer_rx+1, .len = BUF_SIZE - 1}
626+
};
627+
628+
const struct spi_buf_set tx = {.buffers = buf, .count = 1};
629+
const struct spi_buf_set rx = {.buffers = buf, .count = 2};
630+
631+
memcpy(buffer_rx, tx_data, BUF_SIZE);
631632

632633
spi_loopback_transceive(spec, &tx, &rx);
633634

634-
spi_loopback_compare_bufs(tx_data, buffer_rx, BUF_SIZE,
635+
spi_loopback_compare_bufs(tx_data, buffer_rx, 1,
635636
buffer_print_tx, buffer_print_rx);
637+
638+
char zeros[BUF_SIZE - 1] = {0};
639+
640+
zassert_ok(memcmp(buffer_rx+1, zeros, BUF_SIZE - 1));
636641
}
637642

638643

0 commit comments

Comments
 (0)