2022-10-08 17:26:04 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2022-12-05 17:58:23 +00:00
|
|
|
// SCSI Target Emulator PiSCSI
|
2022-10-08 17:26:04 +00:00
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
2023-10-15 06:38:15 +00:00
|
|
|
// Copyright (C) 2022-2023 Uwe Seimet
|
2022-10-08 17:26:04 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "mocks.h"
|
2022-12-05 17:58:23 +00:00
|
|
|
#include "shared/piscsi_exceptions.h"
|
2022-10-08 17:26:04 +00:00
|
|
|
#include "devices/scsi_daynaport.h"
|
|
|
|
|
2023-10-30 10:24:18 +00:00
|
|
|
TEST(ScsiDaynaportTest, GetDefaultParams)
|
|
|
|
{
|
|
|
|
const auto [controller, daynaport] = CreateDevice(SCDP);
|
|
|
|
const auto params = daynaport->GetDefaultParams();
|
|
|
|
EXPECT_EQ(2, params.size());
|
|
|
|
}
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
TEST(ScsiDaynaportTest, Inquiry)
|
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
TestInquiry::Inquiry(SCDP, device_type::processor, scsi_level::scsi_2, "Dayna SCSI/Link 1.4a", 0x20, false);
|
2022-10-08 17:26:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ScsiDaynaportTest, TestUnitReady)
|
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
auto [controller, daynaport] = CreateDevice(SCDP);
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2022-11-04 07:22:32 +00:00
|
|
|
EXPECT_CALL(*controller, Status());
|
2022-11-02 14:36:19 +00:00
|
|
|
daynaport->Dispatch(scsi_command::eCmdTestUnitReady);
|
2023-10-15 06:38:15 +00:00
|
|
|
EXPECT_EQ(status::good, controller->GetStatus());
|
2022-10-08 17:26:04 +00:00
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
TEST(ScsiDaynaportTest, Read)
|
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
auto [controller, daynaport] = CreateDevice(SCDP);
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
// ALLOCATION LENGTH
|
2023-10-15 06:38:15 +00:00
|
|
|
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";
|
2022-10-23 19:51:39 +00:00
|
|
|
}
|
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
TEST(ScsiDaynaportTest, Write)
|
2022-10-23 19:51:39 +00:00
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
auto [controller, daynaport] = CreateDevice(SCDP);
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
// Unknown data format
|
2023-10-15 06:38:15 +00:00
|
|
|
controller->SetCmdByte(5, 0xff);
|
|
|
|
vector<uint8_t> buf(0);
|
|
|
|
EXPECT_TRUE(dynamic_pointer_cast<SCSIDaynaPort>(daynaport)->Write(controller->GetCmd(), buf));
|
2022-10-23 19:51:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ScsiDaynaportTest, Read6)
|
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
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))))
|
2022-10-29 16:16:03 +00:00
|
|
|
<< "Invalid data format";
|
2022-10-23 19:51:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ScsiDaynaportTest, Write6)
|
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
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))))
|
2022-10-29 16:16:03 +00:00
|
|
|
<< "Invalid transfer length";
|
2022-10-23 19:51:39 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
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))))
|
2022-10-29 16:16:03 +00:00
|
|
|
<< "Invalid transfer length";
|
2022-10-23 19:51:39 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
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))))
|
2022-10-29 16:16:03 +00:00
|
|
|
<< "Invalid transfer length";
|
2022-10-23 19:51:39 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
TEST(ScsiDaynaportTest, TestRetrieveStats)
|
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
auto [controller, daynaport] = CreateDevice(SCDP);
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
// ALLOCATION LENGTH
|
2023-10-15 06:38:15 +00:00
|
|
|
controller->SetCmdByte(4, 255);
|
2022-11-04 07:22:32 +00:00
|
|
|
EXPECT_CALL(*controller, DataIn());
|
2022-11-02 14:36:19 +00:00
|
|
|
daynaport->Dispatch(scsi_command::eCmdRetrieveStats);
|
2022-10-08 17:26:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ScsiDaynaportTest, SetInterfaceMode)
|
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
auto [controller, daynaport] = CreateDevice(SCDP);
|
|
|
|
// Required by the bullseye clang++ compiler
|
|
|
|
auto d = daynaport;
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
// Unknown interface command
|
2023-10-15 06:38:15 +00:00
|
|
|
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))));
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
// Not implemented, do nothing
|
2023-10-15 06:38:15 +00:00
|
|
|
controller->SetCmdByte(5, SCSIDaynaPort::CMD_SCSILINK_SETMODE);
|
2022-11-04 07:22:32 +00:00
|
|
|
EXPECT_CALL(*controller, Status());
|
2022-11-02 14:36:19 +00:00
|
|
|
daynaport->Dispatch(scsi_command::eCmdSetIfaceMode);
|
2023-10-15 06:38:15 +00:00
|
|
|
EXPECT_EQ(status::good, controller->GetStatus());
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
controller->SetCmdByte(5, SCSIDaynaPort::CMD_SCSILINK_SETMAC);
|
2022-11-04 07:22:32 +00:00
|
|
|
EXPECT_CALL(*controller, DataOut());
|
2022-11-02 14:36:19 +00:00
|
|
|
daynaport->Dispatch(scsi_command::eCmdSetIfaceMode);
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
// Not implemented
|
2023-10-15 06:38:15 +00:00
|
|
|
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))));
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
// Not implemented
|
2023-10-15 06:38:15 +00:00
|
|
|
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))));
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
// Not implemented
|
2023-10-15 06:38:15 +00:00
|
|
|
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))));
|
2022-10-08 17:26:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ScsiDaynaportTest, SetMcastAddr)
|
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
auto [controller, daynaport] = CreateDevice(SCDP);
|
|
|
|
// Required by the bullseye clang++ compiler
|
|
|
|
auto d = daynaport;
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
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))))
|
2022-10-29 16:16:03 +00:00
|
|
|
<< "Length of 0 is not supported";
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
controller->SetCmdByte(4, 1);
|
2022-11-04 07:22:32 +00:00
|
|
|
EXPECT_CALL(*controller, DataOut());
|
2022-11-02 14:36:19 +00:00
|
|
|
daynaport->Dispatch(scsi_command::eCmdSetMcastAddr);
|
2022-10-08 17:26:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ScsiDaynaportTest, EnableInterface)
|
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
auto [controller, daynaport] = CreateDevice(SCDP);
|
|
|
|
// Required by the bullseye clang++ compiler
|
|
|
|
auto d = daynaport;
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
// Enable
|
2023-10-15 06:38:15 +00:00
|
|
|
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))));
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
// Disable
|
2023-10-15 06:38:15 +00:00
|
|
|
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))));
|
2022-10-08 17:26:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ScsiDaynaportTest, GetSendDelay)
|
|
|
|
{
|
|
|
|
SCSIDaynaPort daynaport(0);
|
2023-10-15 06:38:15 +00:00
|
|
|
daynaport.Init({});
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(6, daynaport.GetSendDelay());
|
|
|
|
}
|