Files
RASCSI/cpp/test/scsi_daynaport_test.cpp
T
Daniel Markstedt 485298ffe5 restore X68000 Host Bridge support
Restore the SCBR device as an X68000 Host Bridge, including the Human68k-compatible host file-system service and the bridge-specific SCSI message handlers. Back its Ethernet path with the TAP driver, derive a stable locally administered MAC address, preserve the driver minimum-frame/FCS expectations, and restrict received traffic to its own unicast frames and broadcasts.

Match the RASCTL/RASETHER/RASDRV bridge protocol that originated in the parent RaSCSI project: dispatch its non-standard message format on READ(10)/WRITE(10) (0x28/0x2a), with type, function, phase, and a three-byte byte count carried in the CDB. Advertise the legacy control channel required by RASCTL, translate its list and device-management commands to PiSCSI operations, and defer stop or system-shutdown requests until after the response is sent, while gating this insecure interface behind a new '-c disabled|media|full' runtime option. Preserve the type-1 Ethernet exchange used by RASETHER and the type-2, phased filesystem exchange used by RASDRV.

Register the device in the factory, protobuf API, controller transfer path, command-line tooling, device listings, and web UI. Share the explicit bridge and proxy-ARP topology workflow with DaynaPort so both adapters validate and use the same mode/interface pair.

Add build support for iconv where needed, extend unit coverage for device creation, RAS* protocol handling, CLI parsing, web attachment, and topology selection, and update the man pages and network-profile documentation for Host Bridge operation and its networking limits.
2026-09-01 00:52:00 +02:00

199 lines
7.0 KiB
C++

//---------------------------------------------------------------------------
//
// SCSI Target Emulator PiSCSI
// for Raspberry Pi
//
// Copyright (C) 2022-2023 Uwe Seimet
//
//---------------------------------------------------------------------------
#include "mocks.h"
#include "shared/piscsi_exceptions.h"
#include "devices/scsi_daynaport.h"
TEST(ScsiDaynaportTest, GetDefaultParams)
{
const auto [controller, daynaport] = CreateDevice(SCDP);
const auto params = daynaport->GetDefaultParams();
EXPECT_EQ(2, params.size());
EXPECT_EQ("bridge", params.at("mode"));
EXPECT_FALSE(params.contains("inet"));
}
TEST(ScsiDaynaportTest, DeriveMac)
{
const array<uint8_t, 6> uplink_mac = { 0xb8, 0x27, 0xeb, 0xb5, 0xa3, 0x15 };
EXPECT_EQ((array<uint8_t, 6> { 0x00, 0x80, 0x19, 0xb5, 0xa3, 0x15 }), SCSIDaynaPort::DeriveMac(uplink_mac));
const array<uint8_t, 5> invalid_mac = { 0, 1, 2, 3, 4 };
EXPECT_EQ((array<uint8_t, 6> {}), SCSIDaynaPort::DeriveMac(invalid_mac));
}
TEST(ScsiDaynaportTest, Inquiry)
{
TestInquiry::Inquiry(SCDP, device_type::processor, scsi_level::scsi_2, "Dayna SCSI/Link 1.4a", 0x20, false);
}
TEST(ScsiDaynaportTest, TestUnitReady)
{
auto [controller, daynaport] = CreateDevice(SCDP);
EXPECT_CALL(*controller, Status());
daynaport->Dispatch(scsi_command::eCmdTestUnitReady);
EXPECT_EQ(status::good, controller->GetStatus());
}
TEST(ScsiDaynaportTest, Read)
{
auto [controller, daynaport] = CreateDevice(SCDP);
// ALLOCATION LENGTH
controller->SetCmdByte(4, 1);
vector<uint8_t> buf(0);
EXPECT_EQ(0, dynamic_pointer_cast<SCSIDaynaPort>(daynaport)->Read(controller->GetCmd(), buf, 0)) << "Trying to read the root sector must fail";
}
TEST(ScsiDaynaportTest, Write)
{
auto [controller, daynaport] = CreateDevice(SCDP);
// Unknown data format
controller->SetCmdByte(5, 0xff);
vector<uint8_t> buf(0);
EXPECT_TRUE(dynamic_pointer_cast<SCSIDaynaPort>(daynaport)->Write(controller->GetCmd(), buf));
}
TEST(ScsiDaynaportTest, Read6)
{
auto [controller, daynaport] = CreateDevice(SCDP);
// Required by the bullseye clang++ compiler
auto d = daynaport;
controller->SetCmdByte(5, 0xff);
EXPECT_THAT([&] { d->Dispatch(scsi_command::eCmdRead6); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::illegal_request),
Property(&scsi_exception::get_asc, asc::invalid_field_in_cdb))))
<< "Invalid data format";
}
TEST(ScsiDaynaportTest, Write6)
{
auto [controller, daynaport] = CreateDevice(SCDP);
// Required by the bullseye clang++ compiler
auto d = daynaport;
controller->SetCmdByte(5, 0x00);
EXPECT_THAT([&] { d->Dispatch(scsi_command::eCmdWrite6); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::illegal_request),
Property(&scsi_exception::get_asc, asc::invalid_field_in_cdb))))
<< "Invalid transfer length";
controller->SetCmdByte(3, -1);
controller->SetCmdByte(4, -8);
controller->SetCmdByte(5, 0x08);
EXPECT_THAT([&] { d->Dispatch(scsi_command::eCmdWrite6); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::illegal_request),
Property(&scsi_exception::get_asc, asc::invalid_field_in_cdb))))
<< "Invalid transfer length";
controller->SetCmdByte(3, 0);
controller->SetCmdByte(4, 0);
controller->SetCmdByte(5, 0xff);
EXPECT_THAT([&] { d->Dispatch(scsi_command::eCmdWrite6); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::illegal_request),
Property(&scsi_exception::get_asc, asc::invalid_field_in_cdb))))
<< "Invalid transfer length";
}
TEST(ScsiDaynaportTest, TestRetrieveStats)
{
auto [controller, daynaport] = CreateDevice(SCDP);
// ALLOCATION LENGTH
controller->SetCmdByte(4, 255);
EXPECT_CALL(*controller, DataIn());
daynaport->Dispatch(scsi_command::eCmdRetrieveStats);
}
TEST(ScsiDaynaportTest, SetInterfaceMode)
{
auto [controller, daynaport] = CreateDevice(SCDP);
// Required by the bullseye clang++ compiler
auto d = daynaport;
// Unknown interface command
EXPECT_THAT([&] { d->Dispatch(scsi_command::eCmdSetIfaceMode); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::illegal_request),
Property(&scsi_exception::get_asc, asc::invalid_command_operation_code))));
// Not implemented, do nothing
controller->SetCmdByte(5, SCSIDaynaPort::CMD_SCSILINK_SETMODE);
EXPECT_CALL(*controller, Status());
daynaport->Dispatch(scsi_command::eCmdSetIfaceMode);
EXPECT_EQ(status::good, controller->GetStatus());
controller->SetCmdByte(5, SCSIDaynaPort::CMD_SCSILINK_SETMAC);
EXPECT_CALL(*controller, DataOut());
daynaport->Dispatch(scsi_command::eCmdSetIfaceMode);
// Not implemented
controller->SetCmdByte(5, SCSIDaynaPort::CMD_SCSILINK_STATS);
EXPECT_THAT([&] { d->Dispatch(scsi_command::eCmdSetIfaceMode); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::illegal_request),
Property(&scsi_exception::get_asc, asc::invalid_command_operation_code))));
// Not implemented
controller->SetCmdByte(5, SCSIDaynaPort::CMD_SCSILINK_ENABLE);
EXPECT_THAT([&] { d->Dispatch(scsi_command::eCmdSetIfaceMode); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::illegal_request),
Property(&scsi_exception::get_asc, asc::invalid_command_operation_code))));
// Not implemented
controller->SetCmdByte(5, SCSIDaynaPort::CMD_SCSILINK_SET);
EXPECT_THAT([&] { d->Dispatch(scsi_command::eCmdSetIfaceMode); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::illegal_request),
Property(&scsi_exception::get_asc, asc::invalid_command_operation_code))));
}
TEST(ScsiDaynaportTest, SetMcastAddr)
{
auto [controller, daynaport] = CreateDevice(SCDP);
// Required by the bullseye clang++ compiler
auto d = daynaport;
EXPECT_THAT([&] { d->Dispatch(scsi_command::eCmdSetMcastAddr); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::illegal_request),
Property(&scsi_exception::get_asc, asc::invalid_field_in_cdb))))
<< "Length of 0 is not supported";
controller->SetCmdByte(4, 1);
EXPECT_CALL(*controller, DataOut());
daynaport->Dispatch(scsi_command::eCmdSetMcastAddr);
}
TEST(ScsiDaynaportTest, EnableInterface)
{
auto [controller, daynaport] = CreateDevice(SCDP);
// Required by the bullseye clang++ compiler
auto d = daynaport;
// Enable
EXPECT_THAT([&] { d->Dispatch(scsi_command::eCmdEnableInterface); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::aborted_command),
Property(&scsi_exception::get_asc, asc::no_additional_sense_information))));
// Disable
controller->SetCmdByte(5, 0x00);
EXPECT_THAT([&] { d->Dispatch(scsi_command::eCmdEnableInterface); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::aborted_command),
Property(&scsi_exception::get_asc, asc::no_additional_sense_information))));
}
TEST(ScsiDaynaportTest, GetSendDelay)
{
SCSIDaynaPort daynaport(0);
daynaport.Init({});
EXPECT_EQ(6, daynaport.GetSendDelay());
}