Skip to content

Commit 6601f89

Browse files
committed
tests: spi_loopback: Specify expected CS on helper func
The helper function should have the flexibility to have different expected CS counts. Namely, the test cases where the transfer is essentially empty should not need to assert CS and many platforms are failing on CS testing currently due to expecting CS assert and deassert despite it being a 0 clock/bit transfer being specified. Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
1 parent de59821 commit 6601f89

File tree

1 file changed

+22
-22
lines changed
  • tests/drivers/spi/spi_loopback/src

1 file changed

+22
-22
lines changed

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ static int spi_loopback_gpio_cs_loopback_init(void)
205205
/* just a wrapper of the driver transceive call with ztest error assert */
206206
static void spi_loopback_transceive(struct spi_dt_spec *const spec,
207207
const struct spi_buf_set *const tx,
208-
const struct spi_buf_set *const rx)
208+
const struct spi_buf_set *const rx,
209+
int expected_cs_count)
209210
{
210211
int ret;
211212

@@ -218,8 +219,7 @@ static void spi_loopback_transceive(struct spi_dt_spec *const spec,
218219
ztest_test_skip();
219220
}
220221
zassert_ok(ret, "SPI transceive failed, code %d", ret);
221-
/* There should be two CS triggers during the transaction, start and end */
222-
zassert_false(spi_loopback_gpio_cs_loopback_check(2));
222+
zassert_ok(spi_loopback_gpio_cs_loopback_check(expected_cs_count));
223223
zassert_ok(pm_device_runtime_put(spec->bus));
224224
}
225225

@@ -286,7 +286,7 @@ ZTEST(spi_loopback, test_spi_complete_multiple)
286286
buffer_rx, BUF_SIZE,
287287
buffer2_rx, BUF2_SIZE);
288288

289-
spi_loopback_transceive(spec, &tx, &rx);
289+
spi_loopback_transceive(spec, &tx, &rx, 2);
290290

291291
spi_loopback_compare_bufs(buffer_tx, buffer_rx, BUF_SIZE,
292292
buffer_print_tx, buffer_print_rx);
@@ -316,7 +316,7 @@ ZTEST(spi_loopback, test_spi_complete_multiple_timed)
316316

317317
/* since this is a test program, there shouldn't be much to interfere with measurement */
318318
start_time = k_cycle_get_32();
319-
spi_loopback_transceive(spec, &tx, &rx);
319+
spi_loopback_transceive(spec, &tx, &rx, 2);
320320
end_time = k_cycle_get_32();
321321

322322
zassert_ok(pm_device_runtime_put(spec->bus));
@@ -392,7 +392,7 @@ void spi_loopback_test_mode(struct spi_dt_spec *spec, bool cpol, bool cpha)
392392
spec->config.operation &= ~SPI_MODE_CPHA;
393393
}
394394

395-
spi_loopback_transceive(spec, &tx, &rx);
395+
spi_loopback_transceive(spec, &tx, &rx, 2);
396396

397397
spec->config.operation = original_op;
398398

@@ -447,7 +447,7 @@ ZTEST(spi_loopback, test_spi_null_tx_buf)
447447

448448
(void)memset(buffer_rx, 0x77, BUF_SIZE);
449449

450-
spi_loopback_transceive(spec, &tx, &rx);
450+
spi_loopback_transceive(spec, &tx, &rx, 2);
451451

452452
spi_loopback_compare_bufs(expected_nop_return_buf, buffer_rx, BUF_SIZE,
453453
buffer_print_rx, buffer_print_rx);
@@ -463,7 +463,7 @@ ZTEST(spi_loopback, test_spi_rx_half_start)
463463

464464
(void)memset(buffer_rx, 0, BUF_SIZE);
465465

466-
spi_loopback_transceive(spec, &tx, &rx);
466+
spi_loopback_transceive(spec, &tx, &rx, 2);
467467

468468
spi_loopback_compare_bufs(buffer_tx, buffer_rx, 8,
469469
buffer_print_tx, buffer_print_rx);
@@ -485,7 +485,7 @@ ZTEST(spi_loopback, test_spi_rx_half_end)
485485

486486
(void)memset(buffer_rx, 0, BUF_SIZE);
487487

488-
spi_loopback_transceive(spec, &tx, &rx);
488+
spi_loopback_transceive(spec, &tx, &rx, 2);
489489

490490
spi_loopback_compare_bufs(buffer_tx+8, buffer_rx, 8,
491491
buffer_print_tx, buffer_print_rx);
@@ -509,7 +509,7 @@ ZTEST(spi_loopback, test_spi_rx_every_4)
509509

510510
(void)memset(buffer_rx, 0, BUF_SIZE);
511511

512-
spi_loopback_transceive(spec, &tx, &rx);
512+
spi_loopback_transceive(spec, &tx, &rx, 2);
513513

514514
spi_loopback_compare_bufs(buffer_tx+4, buffer_rx, 4,
515515
buffer_print_tx, buffer_print_rx);
@@ -537,7 +537,7 @@ ZTEST(spi_loopback, test_spi_rx_bigger_than_tx)
537537

538538
(void)memset(buffer_rx, 0xff, BUF_SIZE);
539539

540-
spi_loopback_transceive(spec, &tx, &rx);
540+
spi_loopback_transceive(spec, &tx, &rx, 2);
541541

542542
spi_loopback_compare_bufs(buffer_tx, buffer_rx, tx_buf_size,
543543
buffer_print_tx, buffer_print_rx);
@@ -557,7 +557,7 @@ ZTEST(spi_loopback, test_spi_complete_large_transfers)
557557
const struct spi_buf_set rx = spi_loopback_setup_xfer(rx_bufs_pool, 1,
558558
large_buffer_rx, BUF3_SIZE);
559559

560-
spi_loopback_transceive(spec, &tx, &rx);
560+
spi_loopback_transceive(spec, &tx, &rx, 2);
561561

562562
zassert_false(memcmp(large_buffer_tx, large_buffer_rx, BUF3_SIZE),
563563
"Large Buffer contents are different");
@@ -572,7 +572,7 @@ ZTEST(spi_loopback, test_spi_null_tx_buf_set)
572572

573573
(void)memset(buffer_rx, 0x77, BUF_SIZE);
574574

575-
spi_loopback_transceive(spec, NULL, &rx);
575+
spi_loopback_transceive(spec, NULL, &rx, 2);
576576

577577
spi_loopback_compare_bufs(expected_nop_return_buf, buffer_rx, BUF_SIZE,
578578
buffer_print_rx, buffer_print_rx);
@@ -584,14 +584,14 @@ ZTEST(spi_loopback, test_spi_null_rx_buf_set)
584584
const struct spi_buf_set tx = spi_loopback_setup_xfer(tx_bufs_pool, 1,
585585
buffer_tx, BUF_SIZE);
586586

587-
spi_loopback_transceive(spec, &tx, NULL);
587+
spi_loopback_transceive(spec, &tx, NULL, 2);
588588
}
589589

590590
ZTEST(spi_loopback, test_spi_null_tx_rx_buf_set)
591591
{
592592
struct spi_dt_spec *spec = loopback_specs[spec_idx];
593593

594-
spi_loopback_transceive(spec, NULL, NULL);
594+
spi_loopback_transceive(spec, NULL, NULL, 0);
595595
}
596596

597597
ZTEST(spi_loopback, test_nop_nil_bufs)
@@ -600,7 +600,7 @@ ZTEST(spi_loopback, test_nop_nil_bufs)
600600
const struct spi_buf_set tx = spi_loopback_setup_xfer(tx_bufs_pool, 1, NULL, 0);
601601
const struct spi_buf_set rx = spi_loopback_setup_xfer(rx_bufs_pool, 1, NULL, 0);
602602

603-
spi_loopback_transceive(spec, &tx, &rx);
603+
spi_loopback_transceive(spec, &tx, &rx, 0);
604604

605605
/* nothing really to check here, check is done in spi_loopback_transceive */
606606
}
@@ -615,7 +615,7 @@ ZTEST(spi_loopback, test_spi_write_back)
615615

616616
memcpy(buffer_rx, tx_data, sizeof(tx_data));
617617

618-
spi_loopback_transceive(spec, &set, &set);
618+
spi_loopback_transceive(spec, &set, &set, 2);
619619

620620
spi_loopback_compare_bufs(tx_data, buffer_rx, BUF_SIZE,
621621
buffer_print_tx, buffer_print_rx);
@@ -636,7 +636,7 @@ ZTEST(spi_loopback, test_spi_same_buf_cmd)
636636

637637
memcpy(buffer_rx, tx_data, BUF_SIZE);
638638

639-
spi_loopback_transceive(spec, &tx, &rx);
639+
spi_loopback_transceive(spec, &tx, &rx, 2);
640640

641641
spi_loopback_compare_bufs(tx_data, buffer_rx, 1,
642642
buffer_print_tx, buffer_print_rx);
@@ -667,7 +667,7 @@ static void spi_loopback_test_word_size(struct spi_dt_spec *spec,
667667
const struct spi_buf_set rx = spi_loopback_setup_xfer(rx_bufs_pool, 1,
668668
rx_buffer, buffer_size);
669669

670-
spi_loopback_transceive(spec_copy, &tx, &rx);
670+
spi_loopback_transceive(spec_copy, &tx, &rx, 2);
671671

672672
zassert_false(memcmp(compare_data, rx_buffer, buffer_size),
673673
"%d-bit word buffer contents are different", word_size);
@@ -961,11 +961,11 @@ ZTEST(spi_extra_api_features, test_spi_lock_release)
961961
lock_spec->config.operation |= SPI_LOCK_ON;
962962

963963
zassert_ok(pm_device_runtime_get(lock_spec->bus));
964-
spi_loopback_transceive(lock_spec, &tx, &rx);
964+
spi_loopback_transceive(lock_spec, &tx, &rx, 2);
965965
zassert_false(spi_release_dt(lock_spec), "SPI release failed");
966966
zassert_ok(pm_device_runtime_put(lock_spec->bus));
967967

968-
spi_loopback_transceive(try_spec, &tx, &rx);
968+
spi_loopback_transceive(try_spec, &tx, &rx, 2);
969969

970970
lock_spec->config.operation &= ~SPI_LOCK_ON;
971971
}
@@ -1021,7 +1021,7 @@ ZTEST(spi_extra_api_features, test_spi_hold_on_cs)
10211021
}
10221022

10231023
/* now just do a normal transfer to make sure there was no leftover effects */
1024-
spi_loopback_transceive(hold_spec, &tx, &rx);
1024+
spi_loopback_transceive(hold_spec, &tx, &rx, 2);
10251025

10261026
return;
10271027

0 commit comments

Comments
 (0)