Repository navigation
Advanced testing
SCSI2Pi has an extensive set of unit tests. However, these tests do not fully verify whether the SCSI2Pi emulation and its accompanying tools correctly handle the SCSI bus protocol. Furthermore, they do not test the SCSI2Pi emulation and initiator mode tools against each other. Running such tests in theory require two SCSI devices: an initiator (typically a computer), and a target (such as a hard drive). The initiator and the target are connected via physical SCSI bus hardware (the PiSCSI boards) and exchange data and status information with bus signals.
A very useful hardware setup for testing SCSI2Pi is two interconnected PiSCSI boards. On one board, you emulate a SCSI device using s2p, on the other, you run an initiator tool like s2pdump or s2pexec. This allows you to test SCSI2Pi against itself. With this setup, any unexpected behavior is guaranteed to be an issue with SCSI2Pi, as no other SCSI devices are involved.
However, there is a drawback with this approach: It requires two Pis and two PiSCSI boards. Wouldn't it be great to run these interoperability tests without any special hardware, even on a PC or Mac?
You can actually do that! SCSI2Pi features a special virtual bus ("in-process bus") that records and manages all bus signals directly in memory. An initiator and a target running within in the same process communicate via this bus as if they were running on separate physical computers/devices. The virtual bus completely replaces the physical hardware, making it an invaluable asset for development and testing.
The SCSI2Pi initiator tools (s2pdump, s2pexec and s2pproto) are all prepared to use the virtual bus instead of physical hardware.
With s2ptool you can run tests that make use of the virtual bus. The tool spawns an s2p instance and an initiator tool instance, e.g. s2pexec, within the same process, connecting them via a virtual bus. They execute against each other exactly as if they were connected by physical SCSI hardware. Because it does not rely on GPIO hardware, this setup works on any platform where SCSI2Pi can be compiled, including Linux PCs, BSD systems, and even macOS.
When launching s2ptool, you can pass separate command-line options to s2p and the initiator tool. When running s2pctl against s2p via a virtual bus, a standard network connection is established between s2p and s2pctl. You enable bus signal logging using the --log-signals/-l option at trace log level. Note that signal logging is very verbose.
You can run s2pdump against s2p like this:
>s2ptool -s "-i 0 services" -c "s2pdump -I -i 0"The output from the command above looks like this:
SCSI Device Emulator and SCSI Tools SCSI2Pi (SCSI/SASI Command Execution Tool)
Version 6.5-devel
Copyright (C) 2016-2020 GIMONS
Copyright (C) 2020-2023 Contributors to the PiSCSI project
Copyright (C) 2021-2026 Uwe Seimet
[info] Set log level to 'info'
[info] Validating: operation=ATTACH, device=0:0, type=UNDEFINED, device parameters='file=services', vendor='', product='', revision='', block size=0
[info] Executing: operation=ATTACH, device=0:0, type=UNDEFINED, device parameters='file=services', vendor='', product='', revision='', block size=0
[info] Attached SCHS 0:0
[info] +--------+------+-------------------------------------
[info] | ID:LUN | Type | Image File/Device File/Description
[info] +--------+------+-------------------------------------
[info] | 0:0 | SCHS | Host Services
[info] +--------+------+-------------------------------------
----------------------------------------
Board (initiator) ID is 7
----------------------------------------
Checking target ID:LUN 0:0
INQUIRY product data:
Vendor: 'SCSI2Pi '
Product: 'Host Services '
Revision: '0650'
Device Type: Processor
SCSI Level: SPC-3
Response Data Format: SCSI-2
Removable: No
Device properties for s2p configuration file, usually '/etc/s2p.conf':
device.0.type=SCHS
device.0.product_name=SCSI2Pi:Host Services:0640
device.0.mode_page.32=20:08:01:00:7d:02:01:0a:1e:34You can also run s2pexec against s2p interactively:
>s2ptool -s "-i 0 test.hds"
SCSI Device Emulator and SCSI Tools SCSI2Pi (SCSI/SASI Command Execution Tool)
Version 6.4
Copyright (C) 2016-2020 GIMONS
Copyright (C) 2020-2023 Contributors to the PiSCSI project
Copyright (C) 2021-2025 Uwe Seimet
[info] Set log level to 'info'
[info] Validating: operation=ATTACH, device=0:0, device parameters='file=test.hds'
[info] Executing: operation=ATTACH, device=0:0, device parameters='file=test.hds'
[info] Attached SCHD 0:0
[info] +--------+------+-------------------------------------
[info] | ID:LUN | Type | Image File/Device File/Description
[info] +--------+------+-------------------------------------
[info] | 0:0 | SCHD | /home/us/images/test.hds
[info] +--------+------+-------------------------------------
SCSI Device Emulator and SCSI Tools SCSI2Pi (SCSI/SASI Command Execution Tool)
Version 6.4
Copyright (C) 2023-2026 Uwe Seimet
Entering interactive mode, Ctrl-D, "exit" or "quit" to quit
s2pexec>s2pexec>-i 0 -c 12:00:00:00:30:00
00000000 00:00:02:02:1f:00:00:00:53:43:53:49:32:50:69:20 '........SCSI2Pi '
00000010 53:43:53:49:20:48:44:20:31:36:20:4d:69:42:20:20 'SCSI HD 16 MiB '
00000020 30:36:34:30 '0640'
s2pexec>-c 08:00:00:03:01:00
00000000 f8:0f:ff:0f:03:00:04:00:05:00:06:00:07:00:08:00 '................'
00000010 09:00:0a:00:0b:00:0c:00:0d:00:0e:00:0f:00:10:00 '................'
00000020 11:00:12:00:13:00:14:00:15:00:16:00:17:00:18:00 '................'
...While s2ptool is active, you can open another terminal and use s2pctl to send commands to the running in-process s2p instance:
>s2pctl -c d -i 0You can also run s2pctl against s2p.
>s2ptool -c s2pctl -s "-i 5 printer" -a "--detach-all"
SCSI Device Emulator and SCSI Tools SCSI2Pi (SCSI/SASI Command Execution Tool)
Version 6.4
Copyright (C) 2016-2020 GIMONS
Copyright (C) 2020-2023 Contributors to the PiSCSI project
Copyright (C) 2021-2025 Uwe Seimet
[info] Set log level to 'info'
[info] Validating: operation=ATTACH, device=5:0, type=UNDEFINED, device parameters='file=printer', vendor='', product='', revision='', block size=0
[info] Executing: operation=ATTACH, device=5:0, type=UNDEFINED, device parameters='file=printer', vendor='', product='', revision='', block size=0
[info] Attached SCLP 5:0
[info] +--------+------+-------------------------------------
[info] | ID:LUN | Type | Image File/Device File/Description
[info] +--------+------+-------------------------------------
[info] | 5:0 | SCLP | SCSI Printer
[info] +--------+------+-------------------------------------
This platform is not a Raspberry Pi, functionality is limited
[info] Detached all devicesThe interactive modes of s2pexec and s2ptool support automated test scripts. This makes it easy to compare the console output with reference data.
>cat script.txt
# The target ID
-i 0
# Run INQUIRY
-c 12:00:00:00:ff:00
# Read capacity
-c 25:00:00:00:00:00:00:00:00:00
# Set sector size to 512 bytes
-c 15:10:00:00:0c:00 -d 00:00:00:08:00:00:00:00:00:00:02:00
# Verify result
-c 25:00:00:00:00:00:00:00:00:00
# Set sector size back to 2048 bytes
-c 15:10:00:00:0c:00 -d 00:00:00:08:00:00:00:00:00:00:08:00
# Verify result
-c 25:00:00:00:00:00:00:00:00:00>s2pexec < script.txt
00000000 05:80:02:02:33:00:00:18:50:4c:45:58:54:4f:52:20 '....3...PLEXTOR '
00000010 43:44:2d:52:4f:4d:20:50:58:2d:34:30:54:53:20:20 'CD-ROM PX-40TS '
00000020 31:2e:31:31:30:32:2f:32:31:2f:30:30:20:30:31:3a '1.1102/21/00 01:'
00000030 31:31:20:20:20:20:20:20 '11 '
00000000 00:00:47:c7:00:00:08:00 '..G.....'
00000000 00:01:1f:1f:00:00:02:00 '........'
00000000 00:00:47:c7:00:00:08:00 '..G.....'>s2ptool -s "-i 0 test.hds" < script.txt