mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
spi: spidev_test: don't send 0x0 or 0xff
Particularly when using compare mode, if the controller fails to transfer any data, asserting on a read of 0x00 or 0xff may lead to a false negative test, indicating a byte was successfully transferred when the values simply originate from the pull-up or pull-down of RX. Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Jonas Rebmann <jre@pengutronix.de> Link: https://patch.msgid.link/20260924-spi-sun4i-spidev_test-v7-9-126e31a07fdc@pengutronix.de Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
d2b908c75a
commit
951a60af6c
|
|
@ -45,6 +45,7 @@ static int transfer_size = -1;
|
|||
static int iterations;
|
||||
static int interval = 5; /* interval in seconds for showing transfer rate */
|
||||
static int compare;
|
||||
static int nonzero;
|
||||
static int do_tx = 1, do_rx = 1;
|
||||
static int random_input;
|
||||
static int input_choices;
|
||||
|
|
@ -188,7 +189,7 @@ static void transfer(int fd, uint8_t const *tx, uint8_t const *rx, size_t len)
|
|||
|
||||
static void print_usage(const char *prog)
|
||||
{
|
||||
printf("Usage: %s [-2348CDFHILMNORSZbcdiloprstvw]\n", prog);
|
||||
printf("Usage: %s [-2348CDFHILMNORSZbcdiloprstvwz]\n", prog);
|
||||
puts("general device settings:\n"
|
||||
" -D --device device to use (default /dev/spidev1.1)\n"
|
||||
" -s --speed max speed (Hz)\n"
|
||||
|
|
@ -212,6 +213,7 @@ static void print_usage(const char *prog)
|
|||
" -i --input input data from a file (e.g. \"test.bin\")\n"
|
||||
" -o --output output data to a file (e.g. \"results.bin\")\n"
|
||||
" -p send data (e.g. \"1234\\xde\\xad\")\n"
|
||||
" -z --nonzero don't send 0x00 or 0xff bytes\n"
|
||||
" -S --size transfer the given number of random bytes\n"
|
||||
" -I --iter iterations\n"
|
||||
"additional parameters:\n"
|
||||
|
|
@ -249,6 +251,7 @@ static void parse_opts(int argc, char *argv[])
|
|||
{ "input", 1, 0, 'i' },
|
||||
{ "output", 1, 0, 'o' },
|
||||
{ "size", 1, 0, 'S' },
|
||||
{ "nonzero", 0, 0, 'z' },
|
||||
{ "iter", 1, 0, 'I' },
|
||||
{ "bpw", 1, 0, 'b' },
|
||||
{ "lsb", 0, 0, 'L' },
|
||||
|
|
@ -261,7 +264,7 @@ static void parse_opts(int argc, char *argv[])
|
|||
};
|
||||
int c;
|
||||
|
||||
c = getopt_long(argc, argv, "D:s:d:w:b:i:o:lctrHOLC3ZFMNR248p:vS:I:",
|
||||
c = getopt_long(argc, argv, "D:s:d:w:b:i:o:lctrHOLC3ZFMNR248p:vS:zI:",
|
||||
lopts, NULL);
|
||||
|
||||
if (c == -1)
|
||||
|
|
@ -353,6 +356,9 @@ static void parse_opts(int argc, char *argv[])
|
|||
random_input = 1;
|
||||
input_choices++;
|
||||
break;
|
||||
case 'z':
|
||||
nonzero = 1;
|
||||
break;
|
||||
case 'I':
|
||||
iterations = atoi(optarg);
|
||||
break;
|
||||
|
|
@ -455,8 +461,11 @@ static void transfer_buf(int fd, int len)
|
|||
tx = malloc(len);
|
||||
if (!tx)
|
||||
pabort("can't allocate tx buffer");
|
||||
for (i = 0; i < len; i++)
|
||||
tx[i] = random();
|
||||
for (i = 0; i < len; i++) {
|
||||
do
|
||||
tx[i] = random();
|
||||
while (nonzero && (tx[i] == 0x0 || tx[i] == 0xff));
|
||||
}
|
||||
}
|
||||
|
||||
if (do_rx) {
|
||||
|
|
@ -493,6 +502,9 @@ int main(int argc, char *argv[])
|
|||
if (iterations && transfer_size < 0)
|
||||
pabort("-I (--iter) is only implemented for -S (--size)");
|
||||
|
||||
if (nonzero && transfer_size < 0)
|
||||
pabort("-z (--nonzero) is only implemented for -S (--size)");
|
||||
|
||||
if (compare && (!do_tx || !do_rx))
|
||||
pabort("-c (--compare) conflicts with -t (--no-tx) or -r (--no-rx)");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user