[PATCH 5/7] spi: spidev_test: send predictable data
From: Jonas Rebmann
Date: Mon Sep 14 2026 - 12:34:46 EST
From: Marc Kleine-Budde <mkl@xxxxxxxxxxxxxx>
Introduce a flag to test on a predictable byte sequence instead of
random bytes. This is useful when comparing multiple runs e.g. with an
oscilloscope.
Signed-off-by: Marc Kleine-Budde <mkl@xxxxxxxxxxxxxx>
Signed-off-by: Jonas Rebmann <jre@xxxxxxxxxxxxxx>
---
tools/spi/spidev_test.c | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c
index 235b267c02f2..4d35ac0d9a48 100644
--- a/tools/spi/spidev_test.c
+++ b/tools/spi/spidev_test.c
@@ -49,6 +49,7 @@ 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 predictable;
static uint8_t default_tx[] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
@@ -176,7 +177,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 [-2348CDFHILMNORSZbdilctropsvwz]\n", prog);
+ printf("Usage: %s [-2348CDFHILMNORSZbdilctropsvwzP]\n", prog);
puts("general device settings:\n"
" -D --device device to use (default /dev/spidev1.1)\n"
" -s --speed max speed (Hz)\n"
@@ -201,6 +202,7 @@ static void print_usage(const char *prog)
" -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"
+ " -P --predictable Send a predictable sequence instead of random numbers\n"
" -S --size transfer size\n"
" -I --iter iterations\n"
"additional parameters:\n"
@@ -246,12 +248,13 @@ static void parse_opts(int argc, char *argv[])
{ "no-cs", 0, 0, 'N' },
{ "ready", 0, 0, 'R' },
{ "mosi-idle-low", 0, 0, 'M' },
+ { "predictable", 0, 0, 'P' },
{ "verbose", 0, 0, 'v' },
{ NULL, 0, 0, 0 },
};
int c;
- c = getopt_long(argc, argv, "D:s:d:w:b:i:o:lctrHOLC3ZFMNR248p:vS:zI:",
+ c = getopt_long(argc, argv, "D:s:d:w:b:i:o:lctrHOLC3ZFMNR248p:PvS:zI:",
lopts, NULL);
if (c == -1)
@@ -328,6 +331,9 @@ static void parse_opts(int argc, char *argv[])
case 'p':
input_tx = optarg;
break;
+ case 'P':
+ predictable = 1;
+ break;
case '2':
mode |= SPI_TX_DUAL;
break;
@@ -441,9 +447,13 @@ static void transfer_buf(int fd, int len)
if (!tx)
pabort("can't allocate tx buffer");
for (i = 0; i < len; i++) {
- do
- tx[i] = random();
- while (nonzero && (tx[i] == 0x0 || tx[i] == 0xff));
+ if (predictable) {
+ tx[i] = i - iterations;
+ } else {
+ do
+ tx[i] = random();
+ while (nonzero && (tx[i] == 0x0 || tx[i] == 0xff));
+ }
}
}
@@ -480,8 +490,8 @@ int main(int argc, char *argv[])
parse_opts(argc, argv);
- if (!!input_tx + !!input_file + !do_tx + !!nonzero > 1)
- pabort("only one of -p, -i (--input), -t (--no-tx), -z (--nonzero) may be selected");
+ if (!!input_tx + !!input_file + !do_tx + !!nonzero + !!predictable > 1)
+ pabort("only one of -p, -i (--input), -t (--no-tx), -z (--nonzero), -P (--predictable) may be selected");
if (compare && (!do_tx || !do_rx))
pabort("-l/-c conflict with -t or -r");
--
2.55.0.806.gb8242b093d