Skip to content

Commit f955ca0

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 3cac4ee commit f955ca0

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
@@ -204,7 +204,8 @@ static int spi_loopback_gpio_cs_loopback_init(void)
204204
/* just a wrapper of the driver transceive call with ztest error assert */
205205
static void spi_loopback_transceive(struct spi_dt_spec *const spec,
206206
const struct spi_buf_set *const tx,
207-
const struct spi_buf_set *const rx)
207+
const struct spi_buf_set *const rx,
208+
int expected_cs_count)
208209
{
209210
int ret;
210211

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

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

288-
spi_loopback_transceive(spec, &tx, &rx);
288+
spi_loopback_transceive(spec, &tx, &rx, 2);
289289

290290
spi_loopback_compare_bufs(buffer_tx, buffer_rx, BUF_SIZE,
291291
buffer_print_tx, buffer_print_rx);
@@ -315,7 +315,7 @@ ZTEST(spi_loopback, test_spi_complete_multiple_timed)
315315

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

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

394-
spi_loopback_transceive(spec, &tx, &rx);
394+
spi_loopback_transceive(spec, &tx, &rx, 2);
395395

396396
spec->config.operation = original_op;
397397

@@ -446,7 +446,7 @@ ZTEST(spi_loopback, test_spi_null_tx_buf)
446446

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

449-
spi_loopback_transceive(spec, &tx, &rx);
449+
spi_loopback_transceive(spec, &tx, &rx, 2);
450450

451451
spi_loopback_compare_bufs(expected_nop_return_buf, buffer_rx, BUF_SIZE,
452452
buffer_print_rx, buffer_print_rx);
@@ -462,7 +462,7 @@ ZTEST(spi_loopback, test_spi_rx_half_start)
462462

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

465-
spi_loopback_transceive(spec, &tx, &rx);
465+
spi_loopback_transceive(spec, &tx, &rx, 2);
466466

467467
spi_loopback_compare_bufs(buffer_tx, buffer_rx, 8,
468468
buffer_print_tx, buffer_print_rx);
@@ -484,7 +484,7 @@ ZTEST(spi_loopback, test_spi_rx_half_end)
484484

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

487-
spi_loopback_transceive(spec, &tx, &rx);
487+
spi_loopback_transceive(spec, &tx, &rx, 2);
488488

489489
spi_loopback_compare_bufs(buffer_tx+8, buffer_rx, 8,
490490
buffer_print_tx, buffer_print_rx);
@@ -508,7 +508,7 @@ ZTEST(spi_loopback, test_spi_rx_every_4)
508508

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

511-
spi_loopback_transceive(spec, &tx, &rx);
511+
spi_loopback_transceive(spec, &tx, &rx, 2);
512512

513513
spi_loopback_compare_bufs(buffer_tx+4, buffer_rx, 4,
514514
buffer_print_tx, buffer_print_rx);
@@ -536,7 +536,7 @@ ZTEST(spi_loopback, test_spi_rx_bigger_than_tx)
536536

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

539-
spi_loopback_transceive(spec, &tx, &rx);
539+
spi_loopback_transceive(spec, &tx, &rx, 2);
540540

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

559-
spi_loopback_transceive(spec, &tx, &rx);
559+
spi_loopback_transceive(spec, &tx, &rx, 2);
560560

561561
zassert_false(memcmp(large_buffer_tx, large_buffer_rx, BUF3_SIZE),
562562
"Large Buffer contents are different");
@@ -571,7 +571,7 @@ ZTEST(spi_loopback, test_spi_null_tx_buf_set)
571571

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

574-
spi_loopback_transceive(spec, NULL, &rx);
574+
spi_loopback_transceive(spec, NULL, &rx, 2);
575575

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

586-
spi_loopback_transceive(spec, &tx, NULL);
586+
spi_loopback_transceive(spec, &tx, NULL, 2);
587587
}
588588

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

593-
spi_loopback_transceive(spec, NULL, NULL);
593+
spi_loopback_transceive(spec, NULL, NULL, 0);
594594
}
595595

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

602-
spi_loopback_transceive(spec, &tx, &rx);
602+
spi_loopback_transceive(spec, &tx, &rx, 0);
603603

604604
/* nothing really to check here, check is done in spi_loopback_transceive */
605605
}
@@ -614,7 +614,7 @@ ZTEST(spi_loopback, test_spi_write_back)
614614

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

617-
spi_loopback_transceive(spec, &set, &set);
617+
spi_loopback_transceive(spec, &set, &set, 2);
618618

619619
spi_loopback_compare_bufs(tx_data, buffer_rx, BUF_SIZE,
620620
buffer_print_tx, buffer_print_rx);
@@ -635,7 +635,7 @@ ZTEST(spi_loopback, test_spi_same_buf_cmd)
635635

636636
memcpy(buffer_rx, tx_data, BUF_SIZE);
637637

638-
spi_loopback_transceive(spec, &tx, &rx);
638+
spi_loopback_transceive(spec, &tx, &rx, 2);
639639

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

669-
spi_loopback_transceive(spec_copy, &tx, &rx);
669+
spi_loopback_transceive(spec_copy, &tx, &rx, 2);
670670

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

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

967-
spi_loopback_transceive(try_spec, &tx, &rx);
967+
spi_loopback_transceive(try_spec, &tx, &rx, 2);
968968

969969
lock_spec->config.operation &= ~SPI_LOCK_ON;
970970
}
@@ -1020,7 +1020,7 @@ ZTEST(spi_extra_api_features, test_spi_hold_on_cs)
10201020
}
10211021

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

10251025
return;
10261026

0 commit comments

Comments
 (0)