2022-10-08 17:26:04 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SCSI Target Emulator RaSCSI Reloaded
|
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
|
|
|
// Copyright (C) 2022 Uwe Seimet
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "mocks.h"
|
2022-11-10 06:44:06 +00:00
|
|
|
#include "shared/rascsi_exceptions.h"
|
2022-10-08 17:26:04 +00:00
|
|
|
#include "devices/scsi_daynaport.h"
|
|
|
|
|
|
|
|
TEST(ScsiDaynaportTest, Inquiry)
|
|
|
|
{
|
2022-10-23 19:51:39 +00:00
|
|
|
TestInquiry(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)
|
|
|
|
{
|
2022-11-04 07:22:32 +00:00
|
|
|
auto bus = make_shared<MockBus>();
|
|
|
|
auto controller_manager = make_shared<ControllerManager>(*bus);
|
|
|
|
auto controller = make_shared<MockAbstractController>(controller_manager, 0);
|
|
|
|
auto daynaport = CreateDevice(SCDP, *controller);
|
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);
|
2022-11-04 07:22:32 +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)
|
|
|
|
{
|
2022-11-02 06:36:25 +00:00
|
|
|
vector<uint8_t> buf(0);
|
2022-11-04 07:22:32 +00:00
|
|
|
auto bus = make_shared<MockBus>();
|
|
|
|
auto controller_manager = make_shared<ControllerManager>(*bus);
|
|
|
|
auto controller = make_shared<MockAbstractController>(controller_manager, 0);
|
|
|
|
auto daynaport = dynamic_pointer_cast<SCSIDaynaPort>(CreateDevice(SCDP, *controller));
|
2022-10-23 19:51:39 +00:00
|
|
|
|
2022-11-04 07:22:32 +00:00
|
|
|
auto& cmd = controller->GetCmd();
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
// ALLOCATION LENGTH
|
|
|
|
cmd[4] = 1;
|
|
|
|
EXPECT_EQ(0, daynaport->Read(cmd, buf, 0)) << "Trying to read the root sector must fail";
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ScsiDaynaportTest, WriteBytes)
|
|
|
|
{
|
2022-11-02 06:36:25 +00:00
|
|
|
vector<uint8_t> buf(0);
|
2022-11-04 07:22:32 +00:00
|
|
|
auto bus = make_shared<MockBus>();
|
|
|
|
auto controller_manager = make_shared<ControllerManager>(*bus);
|
|
|
|
auto controller = make_shared<MockAbstractController>(controller_manager, 0);
|
|
|
|
auto daynaport = dynamic_pointer_cast<SCSIDaynaPort>(CreateDevice(SCDP, *controller));
|
2022-10-23 19:51:39 +00:00
|
|
|
|
2022-11-04 07:22:32 +00:00
|
|
|
auto& cmd = controller->GetCmd();
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
// Unknown data format
|
|
|
|
cmd[5] = 0xff;
|
|
|
|
EXPECT_TRUE(daynaport->WriteBytes(cmd, buf, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ScsiDaynaportTest, Read6)
|
|
|
|
{
|
2022-11-04 07:22:32 +00:00
|
|
|
auto bus = make_shared<MockBus>();
|
|
|
|
auto controller_manager = make_shared<ControllerManager>(*bus);
|
|
|
|
auto controller = make_shared<MockAbstractController>(controller_manager, 0);
|
|
|
|
auto daynaport = CreateDevice(SCDP, *controller);
|
2022-10-23 19:51:39 +00:00
|
|
|
|
2022-11-04 07:22:32 +00:00
|
|
|
auto& cmd = controller->GetCmd();
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
cmd[5] = 0xff;
|
2022-11-02 06:36:25 +00:00
|
|
|
EXPECT_THAT([&] { daynaport->Dispatch(scsi_command::eCmdRead6); }, Throws<scsi_exception>(AllOf(
|
2022-10-29 16:16:03 +00:00
|
|
|
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
|
|
|
|
Property(&scsi_exception::get_asc, asc::INVALID_FIELD_IN_CDB))))
|
|
|
|
<< "Invalid data format";
|
2022-10-23 19:51:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ScsiDaynaportTest, Write6)
|
|
|
|
{
|
2022-11-04 07:22:32 +00:00
|
|
|
auto bus = make_shared<MockBus>();
|
|
|
|
auto controller_manager = make_shared<ControllerManager>(*bus);
|
|
|
|
auto controller = make_shared<MockAbstractController>(controller_manager, 0);
|
|
|
|
auto daynaport = CreateDevice(SCDP, *controller);
|
2022-10-23 19:51:39 +00:00
|
|
|
|
2022-11-04 07:22:32 +00:00
|
|
|
auto& cmd = controller->GetCmd();
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
cmd[5] = 0x00;
|
2022-11-02 06:36:25 +00:00
|
|
|
EXPECT_THAT([&] { daynaport->Dispatch(scsi_command::eCmdWrite6); }, Throws<scsi_exception>(AllOf(
|
2022-10-29 16:16:03 +00:00
|
|
|
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
|
|
|
|
Property(&scsi_exception::get_asc, asc::INVALID_FIELD_IN_CDB))))
|
|
|
|
<< "Invalid transfer length";
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
cmd[3] = -1;
|
|
|
|
cmd[4] = -8;
|
|
|
|
cmd[5] = 0x80;
|
2022-11-02 06:36:25 +00:00
|
|
|
EXPECT_THAT([&] { daynaport->Dispatch(scsi_command::eCmdWrite6); }, Throws<scsi_exception>(AllOf(
|
2022-10-29 16:16:03 +00:00
|
|
|
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
|
|
|
|
Property(&scsi_exception::get_asc, asc::INVALID_FIELD_IN_CDB))))
|
|
|
|
<< "Invalid transfer length";
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
cmd[3] = 0;
|
|
|
|
cmd[4] = 0;
|
|
|
|
cmd[5] = 0xff;
|
2022-11-02 06:36:25 +00:00
|
|
|
EXPECT_THAT([&] { daynaport->Dispatch(scsi_command::eCmdWrite6); }, Throws<scsi_exception>(AllOf(
|
2022-10-29 16:16:03 +00:00
|
|
|
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
|
|
|
|
Property(&scsi_exception::get_asc, asc::INVALID_FIELD_IN_CDB))))
|
|
|
|
<< "Invalid transfer length";
|
2022-10-23 19:51:39 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
TEST(ScsiDaynaportTest, TestRetrieveStats)
|
|
|
|
{
|
2022-11-04 07:22:32 +00:00
|
|
|
auto bus = make_shared<MockBus>();
|
|
|
|
auto controller_manager = make_shared<ControllerManager>(*bus);
|
|
|
|
auto controller = make_shared<MockAbstractController>(controller_manager, 0);
|
|
|
|
auto daynaport = CreateDevice(SCDP, *controller);
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2022-11-04 07:22:32 +00:00
|
|
|
auto& cmd = controller->GetCmd();
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
// ALLOCATION LENGTH
|
|
|
|
cmd[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)
|
|
|
|
{
|
2022-11-04 07:22:32 +00:00
|
|
|
auto bus = make_shared<MockBus>();
|
|
|
|
auto controller_manager = make_shared<ControllerManager>(*bus);
|
|
|
|
auto controller = make_shared<MockAbstractController>(controller_manager, 0);
|
|
|
|
auto daynaport = CreateDevice(SCDP, *controller);
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2022-11-04 07:22:32 +00:00
|
|
|
auto& cmd = controller->GetCmd();
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
// Unknown interface command
|
2022-11-02 06:36:25 +00:00
|
|
|
EXPECT_THAT([&] { daynaport->Dispatch(scsi_command::eCmdSetIfaceMode); }, Throws<scsi_exception>(AllOf(
|
2022-10-29 16:16:03 +00:00
|
|
|
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
|
|
|
|
cmd[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);
|
2022-11-04 07:22:32 +00:00
|
|
|
EXPECT_EQ(status::GOOD, controller->GetStatus());
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
cmd[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
|
|
|
|
cmd[5] = SCSIDaynaPort::CMD_SCSILINK_STATS;
|
2022-11-02 06:36:25 +00:00
|
|
|
EXPECT_THAT([&] { daynaport->Dispatch(scsi_command::eCmdSetIfaceMode); }, Throws<scsi_exception>(AllOf(
|
2022-10-29 16:16:03 +00:00
|
|
|
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
|
|
|
|
cmd[5] = SCSIDaynaPort::CMD_SCSILINK_ENABLE;
|
2022-11-02 06:36:25 +00:00
|
|
|
EXPECT_THAT([&] { daynaport->Dispatch(scsi_command::eCmdSetIfaceMode); }, Throws<scsi_exception>(AllOf(
|
2022-10-29 16:16:03 +00:00
|
|
|
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
|
|
|
|
cmd[5] = SCSIDaynaPort::CMD_SCSILINK_SET;
|
2022-11-02 06:36:25 +00:00
|
|
|
EXPECT_THAT([&] { daynaport->Dispatch(scsi_command::eCmdSetIfaceMode); }, Throws<scsi_exception>(AllOf(
|
2022-10-29 16:16:03 +00:00
|
|
|
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)
|
|
|
|
{
|
2022-11-04 07:22:32 +00:00
|
|
|
auto bus = make_shared<MockBus>();
|
|
|
|
auto controller_manager = make_shared<ControllerManager>(*bus);
|
|
|
|
auto controller = make_shared<MockAbstractController>(controller_manager, 0);
|
|
|
|
auto daynaport = CreateDevice(SCDP, *controller);
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2022-11-04 07:22:32 +00:00
|
|
|
auto& cmd = controller->GetCmd();
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2022-11-02 06:36:25 +00:00
|
|
|
EXPECT_THAT([&] { daynaport->Dispatch(scsi_command::eCmdSetMcastAddr); }, Throws<scsi_exception>(AllOf(
|
2022-10-29 16:16:03 +00:00
|
|
|
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";
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
cmd[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)
|
|
|
|
{
|
2022-11-04 07:22:32 +00:00
|
|
|
auto bus = make_shared<MockBus>();
|
|
|
|
auto controller_manager = make_shared<ControllerManager>(*bus);
|
|
|
|
auto controller = make_shared<MockAbstractController>(controller_manager, 0);
|
|
|
|
auto daynaport = CreateDevice(SCDP, *controller);
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2022-11-04 07:22:32 +00:00
|
|
|
auto& cmd = controller->GetCmd();
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
// Enable
|
2022-11-02 06:36:25 +00:00
|
|
|
EXPECT_THAT([&] { daynaport->Dispatch(scsi_command::eCmdEnableInterface); }, Throws<scsi_exception>(AllOf(
|
2022-10-29 16:16:03 +00:00
|
|
|
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
|
|
|
|
cmd[5] = 0x80;
|
2022-11-02 06:36:25 +00:00
|
|
|
EXPECT_THAT([&] { daynaport->Dispatch(scsi_command::eCmdEnableInterface); }, Throws<scsi_exception>(AllOf(
|
2022-10-29 16:16:03 +00:00
|
|
|
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);
|
2022-11-02 14:36:19 +00:00
|
|
|
const unordered_map<string, string> params;
|
|
|
|
daynaport.Init(params);
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(6, daynaport.GetSendDelay());
|
|
|
|
}
|