2022-08-28 17:25:08 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SCSI Target Emulator RaSCSI Reloaded
|
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
|
|
|
// Copyright (C) 2022 Uwe Seimet
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2022-10-04 15:23:42 +00:00
|
|
|
#include "mocks.h"
|
SASI code removal, error handling update, bug fixes, code cleanup (#806)
Summary ov most important changes triggered by the SASI code removal:
- Removed the SASI controller code
- New controller management. There is a new controller base class AbstractController and a class ControllerManager managing the controller lifecycle. The lifecycle management was removed from rasci.cpp and is covered by unit tests.
- New device management. The DeviceFactory manages the device lifecycle instead of rascsi.cpp. The new code is covered by unit tests.
- The lifecycle managment uses C++ collections with variable size instead of arrays with hard-coded sizes.
- The ScsiController method contains most of what was previously contained in scsidev_ctrl.cpp plus the code from sasidev_ctrl.cpp that was relevant for SCSI.
- scsi_command_util contains helper methods used for identical SCSI command implementations of more than one device
- Devices know their controllers, so that the controller instance does not need to be passed to each SCSI command. This change helps to decouple the devices from the controller. The phase_handler interface is also part of this decoupling.
- Use scsi_command_exception for propagating SCSI command execution errors, This resolves issues with the previous error handling, which was based on return values and often on magic numbers.
- Removed legacy SCSI error codes, all errors are now encoded by sense_key::, asc:: and status::.
- Fixed various warnings reported with -Wextra, -Weffc++ and -Wpedantic.
- Use constructor member initialization lists (recommended for ISO C++)
- Consistently use new/delete instead of malloc/free (recommended for ISO C++), resulting in better type safety and error handling
- Replaced variable sized arrays on the stack (violates ISO C++ and can cause a stack overflow)
- Replaced NULL by nullptr (recommended for C++), resulting in better type safety
- Use more const member functions in order to avoid side effects
- The format device page can now also be changed for hard disk drives (Fujitsu M2624S supports this, for instance), not just for MOs.
- Better encapsulation, updated access specifiers in many places
- Removed unused methods and method arguments
- Fixed a number of TODOs
- Added/updated unit tests for a lot of non-legacy classes
- Makefile support for creating HTML coverage reports with lcov/genhtml
2022-09-03 14:53:53 +00:00
|
|
|
#include "rascsi_exceptions.h"
|
2022-08-28 17:25:08 +00:00
|
|
|
#include "rascsi_version.h"
|
2022-10-04 15:23:42 +00:00
|
|
|
#include "controllers/controller_manager.h"
|
SASI code removal, error handling update, bug fixes, code cleanup (#806)
Summary ov most important changes triggered by the SASI code removal:
- Removed the SASI controller code
- New controller management. There is a new controller base class AbstractController and a class ControllerManager managing the controller lifecycle. The lifecycle management was removed from rasci.cpp and is covered by unit tests.
- New device management. The DeviceFactory manages the device lifecycle instead of rascsi.cpp. The new code is covered by unit tests.
- The lifecycle managment uses C++ collections with variable size instead of arrays with hard-coded sizes.
- The ScsiController method contains most of what was previously contained in scsidev_ctrl.cpp plus the code from sasidev_ctrl.cpp that was relevant for SCSI.
- scsi_command_util contains helper methods used for identical SCSI command implementations of more than one device
- Devices know their controllers, so that the controller instance does not need to be passed to each SCSI command. This change helps to decouple the devices from the controller. The phase_handler interface is also part of this decoupling.
- Use scsi_command_exception for propagating SCSI command execution errors, This resolves issues with the previous error handling, which was based on return values and often on magic numbers.
- Removed legacy SCSI error codes, all errors are now encoded by sense_key::, asc:: and status::.
- Fixed various warnings reported with -Wextra, -Weffc++ and -Wpedantic.
- Use constructor member initialization lists (recommended for ISO C++)
- Consistently use new/delete instead of malloc/free (recommended for ISO C++), resulting in better type safety and error handling
- Replaced variable sized arrays on the stack (violates ISO C++ and can cause a stack overflow)
- Replaced NULL by nullptr (recommended for C++), resulting in better type safety
- Use more const member functions in order to avoid side effects
- The format device page can now also be changed for hard disk drives (Fujitsu M2624S supports this, for instance), not just for MOs.
- Better encapsulation, updated access specifiers in many places
- Removed unused methods and method arguments
- Fixed a number of TODOs
- Added/updated unit tests for a lot of non-legacy classes
- Makefile support for creating HTML coverage reports with lcov/genhtml
2022-09-03 14:53:53 +00:00
|
|
|
#include "devices/device.h"
|
|
|
|
#include "devices/device_factory.h"
|
2022-10-01 15:56:06 +00:00
|
|
|
#include <unordered_map>
|
2022-08-28 17:25:08 +00:00
|
|
|
|
|
|
|
TEST(DeviceFactoryTest, GetTypeForFile)
|
|
|
|
{
|
2022-09-25 21:49:24 +00:00
|
|
|
DeviceFactory device_factory;
|
|
|
|
|
2022-09-08 02:45:00 +00:00
|
|
|
EXPECT_EQ(device_factory.GetTypeForFile("test.hd1"), SCHD);
|
2022-08-28 17:25:08 +00:00
|
|
|
EXPECT_EQ(device_factory.GetTypeForFile("test.hds"), SCHD);
|
|
|
|
EXPECT_EQ(device_factory.GetTypeForFile("test.HDS"), SCHD);
|
|
|
|
EXPECT_EQ(device_factory.GetTypeForFile("test.hda"), SCHD);
|
|
|
|
EXPECT_EQ(device_factory.GetTypeForFile("test.hdn"), SCHD);
|
|
|
|
EXPECT_EQ(device_factory.GetTypeForFile("test.hdi"), SCHD);
|
|
|
|
EXPECT_EQ(device_factory.GetTypeForFile("test.nhd"), SCHD);
|
|
|
|
EXPECT_EQ(device_factory.GetTypeForFile("test.hdr"), SCRM);
|
|
|
|
EXPECT_EQ(device_factory.GetTypeForFile("test.mos"), SCMO);
|
|
|
|
EXPECT_EQ(device_factory.GetTypeForFile("test.iso"), SCCD);
|
|
|
|
EXPECT_EQ(device_factory.GetTypeForFile("test.suffix.iso"), SCCD);
|
|
|
|
EXPECT_EQ(device_factory.GetTypeForFile("bridge"), SCBR);
|
|
|
|
EXPECT_EQ(device_factory.GetTypeForFile("daynaport"), SCDP);
|
|
|
|
EXPECT_EQ(device_factory.GetTypeForFile("printer"), SCLP);
|
|
|
|
EXPECT_EQ(device_factory.GetTypeForFile("services"), SCHS);
|
|
|
|
EXPECT_EQ(device_factory.GetTypeForFile("unknown"), UNDEFINED);
|
|
|
|
EXPECT_EQ(device_factory.GetTypeForFile("test.iso.suffix"), UNDEFINED);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DeviceFactoryTest, GetSectorSizes)
|
|
|
|
{
|
2022-09-25 21:49:24 +00:00
|
|
|
DeviceFactory device_factory;
|
2022-08-28 17:25:08 +00:00
|
|
|
unordered_set<uint32_t> sector_sizes;
|
|
|
|
|
|
|
|
sector_sizes = device_factory.GetSectorSizes(SCHD);
|
|
|
|
EXPECT_EQ(4, sector_sizes.size());
|
|
|
|
|
|
|
|
EXPECT_TRUE(sector_sizes.find(512) != sector_sizes.end());
|
|
|
|
EXPECT_TRUE(sector_sizes.find(1024) != sector_sizes.end());
|
|
|
|
EXPECT_TRUE(sector_sizes.find(2048) != sector_sizes.end());
|
|
|
|
EXPECT_TRUE(sector_sizes.find(4096) != sector_sizes.end());
|
|
|
|
|
|
|
|
sector_sizes = device_factory.GetSectorSizes(SCRM);
|
|
|
|
EXPECT_EQ(4, sector_sizes.size());
|
|
|
|
|
|
|
|
EXPECT_TRUE(sector_sizes.find(512) != sector_sizes.end());
|
|
|
|
EXPECT_TRUE(sector_sizes.find(1024) != sector_sizes.end());
|
|
|
|
EXPECT_TRUE(sector_sizes.find(2048) != sector_sizes.end());
|
|
|
|
EXPECT_TRUE(sector_sizes.find(4096) != sector_sizes.end());
|
|
|
|
|
|
|
|
sector_sizes = device_factory.GetSectorSizes(SCMO);
|
|
|
|
EXPECT_EQ(4, sector_sizes.size());
|
|
|
|
|
|
|
|
EXPECT_TRUE(sector_sizes.find(512) != sector_sizes.end());
|
|
|
|
EXPECT_TRUE(sector_sizes.find(1024) != sector_sizes.end());
|
|
|
|
EXPECT_TRUE(sector_sizes.find(2048) != sector_sizes.end());
|
|
|
|
EXPECT_TRUE(sector_sizes.find(4096) != sector_sizes.end());
|
|
|
|
|
|
|
|
sector_sizes = device_factory.GetSectorSizes(SCCD);
|
|
|
|
EXPECT_EQ(2, sector_sizes.size());
|
|
|
|
|
|
|
|
EXPECT_TRUE(sector_sizes.find(512) != sector_sizes.end());
|
|
|
|
EXPECT_TRUE(sector_sizes.find(2048) != sector_sizes.end());
|
|
|
|
}
|
|
|
|
|
2022-10-01 15:56:06 +00:00
|
|
|
TEST(DeviceFactoryTest, GetExtensionMapping)
|
|
|
|
{
|
|
|
|
DeviceFactory device_factory;
|
|
|
|
|
|
|
|
unordered_map<string, PbDeviceType> mapping = device_factory.GetExtensionMapping();
|
|
|
|
EXPECT_EQ(9, mapping.size());
|
|
|
|
EXPECT_EQ(SCHD, mapping["hd1"]);
|
|
|
|
EXPECT_EQ(SCHD, mapping["hds"]);
|
|
|
|
EXPECT_EQ(SCHD, mapping["hda"]);
|
|
|
|
EXPECT_EQ(SCHD, mapping["hdn"]);
|
|
|
|
EXPECT_EQ(SCHD, mapping["hdi"]);
|
|
|
|
EXPECT_EQ(SCHD, mapping["nhd"]);
|
|
|
|
EXPECT_EQ(SCRM, mapping["hdr"]);
|
|
|
|
EXPECT_EQ(SCMO, mapping["mos"]);
|
|
|
|
EXPECT_EQ(SCCD, mapping["iso"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DeviceFactoryTest, GetDefaultParams)
|
|
|
|
{
|
|
|
|
DeviceFactory device_factory;
|
|
|
|
|
|
|
|
unordered_map<string, string> params = device_factory.GetDefaultParams(SCHD);
|
|
|
|
EXPECT_TRUE(params.empty());
|
|
|
|
|
|
|
|
params = device_factory.GetDefaultParams(SCRM);
|
|
|
|
EXPECT_TRUE(params.empty());
|
|
|
|
|
|
|
|
params = device_factory.GetDefaultParams(SCMO);
|
|
|
|
EXPECT_TRUE(params.empty());
|
|
|
|
|
|
|
|
params = device_factory.GetDefaultParams(SCCD);
|
|
|
|
EXPECT_TRUE(params.empty());
|
|
|
|
|
|
|
|
params = device_factory.GetDefaultParams(SCHS);
|
|
|
|
EXPECT_TRUE(params.empty());
|
|
|
|
|
|
|
|
params = device_factory.GetDefaultParams(SCBR);
|
|
|
|
EXPECT_EQ(2, params.size());
|
|
|
|
|
|
|
|
params = device_factory.GetDefaultParams(SCDP);
|
|
|
|
EXPECT_EQ(2, params.size());
|
|
|
|
|
|
|
|
params = device_factory.GetDefaultParams(SCLP);
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_EQ(1, params.size());
|
2022-10-01 15:56:06 +00:00
|
|
|
}
|
|
|
|
|
2022-08-28 17:25:08 +00:00
|
|
|
TEST(DeviceFactoryTest, UnknownDeviceType)
|
|
|
|
{
|
2022-10-25 00:21:40 +00:00
|
|
|
auto bus_ptr = make_shared<MockBus>();
|
2022-09-25 21:49:24 +00:00
|
|
|
DeviceFactory device_factory;
|
2022-10-25 00:21:40 +00:00
|
|
|
ControllerManager controller_manager(bus_ptr);
|
2022-09-25 21:49:24 +00:00
|
|
|
|
2022-10-04 15:23:42 +00:00
|
|
|
auto device1 = device_factory.CreateDevice(controller_manager, UNDEFINED, 0, "test");
|
2022-10-01 15:56:06 +00:00
|
|
|
EXPECT_EQ(nullptr, device1);
|
|
|
|
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
2022-10-04 15:23:42 +00:00
|
|
|
auto device2 = device_factory.CreateDevice(controller_manager, SAHD, 0, "test");
|
2022-10-01 15:56:06 +00:00
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
EXPECT_EQ(nullptr, device2);
|
2022-08-28 17:25:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DeviceFactoryTest, SCHD_Device_Defaults)
|
|
|
|
{
|
2022-10-25 00:21:40 +00:00
|
|
|
auto bus_ptr = make_shared<MockBus>();
|
2022-09-25 21:49:24 +00:00
|
|
|
DeviceFactory device_factory;
|
2022-10-25 00:21:40 +00:00
|
|
|
ControllerManager controller_manager(bus_ptr);
|
2022-09-25 21:49:24 +00:00
|
|
|
|
2022-10-04 15:23:42 +00:00
|
|
|
auto device = device_factory.CreateDevice(controller_manager, UNDEFINED, 0, "test.hda");
|
2022-08-28 17:25:08 +00:00
|
|
|
EXPECT_NE(nullptr, device);
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_EQ(SCHD, device->GetType());
|
2022-08-28 17:25:08 +00:00
|
|
|
EXPECT_TRUE(device->SupportsFile());
|
|
|
|
EXPECT_FALSE(device->SupportsParams());
|
|
|
|
EXPECT_TRUE(device->IsProtectable());
|
|
|
|
EXPECT_FALSE(device->IsProtected());
|
|
|
|
EXPECT_FALSE(device->IsReadOnly());
|
|
|
|
EXPECT_FALSE(device->IsRemovable());
|
|
|
|
EXPECT_FALSE(device->IsRemoved());
|
|
|
|
EXPECT_FALSE(device->IsLockable());
|
|
|
|
EXPECT_FALSE(device->IsLocked());
|
|
|
|
EXPECT_TRUE(device->IsStoppable());
|
|
|
|
EXPECT_FALSE(device->IsStopped());
|
|
|
|
|
|
|
|
EXPECT_EQ("QUANTUM", device->GetVendor()) << "Invalid default vendor for Apple drive";
|
|
|
|
EXPECT_EQ("FIREBALL", device->GetProduct()) << "Invalid default vendor for Apple drive";
|
|
|
|
EXPECT_EQ(string(rascsi_get_version_string()).substr(0, 2) + string(rascsi_get_version_string()).substr(3, 2),
|
|
|
|
device->GetRevision());
|
|
|
|
|
2022-10-04 15:23:42 +00:00
|
|
|
device = device_factory.CreateDevice(controller_manager, UNDEFINED, 0, "test.hds");
|
SASI code removal, error handling update, bug fixes, code cleanup (#806)
Summary ov most important changes triggered by the SASI code removal:
- Removed the SASI controller code
- New controller management. There is a new controller base class AbstractController and a class ControllerManager managing the controller lifecycle. The lifecycle management was removed from rasci.cpp and is covered by unit tests.
- New device management. The DeviceFactory manages the device lifecycle instead of rascsi.cpp. The new code is covered by unit tests.
- The lifecycle managment uses C++ collections with variable size instead of arrays with hard-coded sizes.
- The ScsiController method contains most of what was previously contained in scsidev_ctrl.cpp plus the code from sasidev_ctrl.cpp that was relevant for SCSI.
- scsi_command_util contains helper methods used for identical SCSI command implementations of more than one device
- Devices know their controllers, so that the controller instance does not need to be passed to each SCSI command. This change helps to decouple the devices from the controller. The phase_handler interface is also part of this decoupling.
- Use scsi_command_exception for propagating SCSI command execution errors, This resolves issues with the previous error handling, which was based on return values and often on magic numbers.
- Removed legacy SCSI error codes, all errors are now encoded by sense_key::, asc:: and status::.
- Fixed various warnings reported with -Wextra, -Weffc++ and -Wpedantic.
- Use constructor member initialization lists (recommended for ISO C++)
- Consistently use new/delete instead of malloc/free (recommended for ISO C++), resulting in better type safety and error handling
- Replaced variable sized arrays on the stack (violates ISO C++ and can cause a stack overflow)
- Replaced NULL by nullptr (recommended for C++), resulting in better type safety
- Use more const member functions in order to avoid side effects
- The format device page can now also be changed for hard disk drives (Fujitsu M2624S supports this, for instance), not just for MOs.
- Better encapsulation, updated access specifiers in many places
- Removed unused methods and method arguments
- Fixed a number of TODOs
- Added/updated unit tests for a lot of non-legacy classes
- Makefile support for creating HTML coverage reports with lcov/genhtml
2022-09-03 14:53:53 +00:00
|
|
|
EXPECT_NE(nullptr, device);
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_EQ(SCHD, device->GetType());
|
SASI code removal, error handling update, bug fixes, code cleanup (#806)
Summary ov most important changes triggered by the SASI code removal:
- Removed the SASI controller code
- New controller management. There is a new controller base class AbstractController and a class ControllerManager managing the controller lifecycle. The lifecycle management was removed from rasci.cpp and is covered by unit tests.
- New device management. The DeviceFactory manages the device lifecycle instead of rascsi.cpp. The new code is covered by unit tests.
- The lifecycle managment uses C++ collections with variable size instead of arrays with hard-coded sizes.
- The ScsiController method contains most of what was previously contained in scsidev_ctrl.cpp plus the code from sasidev_ctrl.cpp that was relevant for SCSI.
- scsi_command_util contains helper methods used for identical SCSI command implementations of more than one device
- Devices know their controllers, so that the controller instance does not need to be passed to each SCSI command. This change helps to decouple the devices from the controller. The phase_handler interface is also part of this decoupling.
- Use scsi_command_exception for propagating SCSI command execution errors, This resolves issues with the previous error handling, which was based on return values and often on magic numbers.
- Removed legacy SCSI error codes, all errors are now encoded by sense_key::, asc:: and status::.
- Fixed various warnings reported with -Wextra, -Weffc++ and -Wpedantic.
- Use constructor member initialization lists (recommended for ISO C++)
- Consistently use new/delete instead of malloc/free (recommended for ISO C++), resulting in better type safety and error handling
- Replaced variable sized arrays on the stack (violates ISO C++ and can cause a stack overflow)
- Replaced NULL by nullptr (recommended for C++), resulting in better type safety
- Use more const member functions in order to avoid side effects
- The format device page can now also be changed for hard disk drives (Fujitsu M2624S supports this, for instance), not just for MOs.
- Better encapsulation, updated access specifiers in many places
- Removed unused methods and method arguments
- Fixed a number of TODOs
- Added/updated unit tests for a lot of non-legacy classes
- Makefile support for creating HTML coverage reports with lcov/genhtml
2022-09-03 14:53:53 +00:00
|
|
|
|
2022-10-04 15:23:42 +00:00
|
|
|
device = device_factory.CreateDevice(controller_manager, UNDEFINED, 0, "test.hdi");
|
SASI code removal, error handling update, bug fixes, code cleanup (#806)
Summary ov most important changes triggered by the SASI code removal:
- Removed the SASI controller code
- New controller management. There is a new controller base class AbstractController and a class ControllerManager managing the controller lifecycle. The lifecycle management was removed from rasci.cpp and is covered by unit tests.
- New device management. The DeviceFactory manages the device lifecycle instead of rascsi.cpp. The new code is covered by unit tests.
- The lifecycle managment uses C++ collections with variable size instead of arrays with hard-coded sizes.
- The ScsiController method contains most of what was previously contained in scsidev_ctrl.cpp plus the code from sasidev_ctrl.cpp that was relevant for SCSI.
- scsi_command_util contains helper methods used for identical SCSI command implementations of more than one device
- Devices know their controllers, so that the controller instance does not need to be passed to each SCSI command. This change helps to decouple the devices from the controller. The phase_handler interface is also part of this decoupling.
- Use scsi_command_exception for propagating SCSI command execution errors, This resolves issues with the previous error handling, which was based on return values and often on magic numbers.
- Removed legacy SCSI error codes, all errors are now encoded by sense_key::, asc:: and status::.
- Fixed various warnings reported with -Wextra, -Weffc++ and -Wpedantic.
- Use constructor member initialization lists (recommended for ISO C++)
- Consistently use new/delete instead of malloc/free (recommended for ISO C++), resulting in better type safety and error handling
- Replaced variable sized arrays on the stack (violates ISO C++ and can cause a stack overflow)
- Replaced NULL by nullptr (recommended for C++), resulting in better type safety
- Use more const member functions in order to avoid side effects
- The format device page can now also be changed for hard disk drives (Fujitsu M2624S supports this, for instance), not just for MOs.
- Better encapsulation, updated access specifiers in many places
- Removed unused methods and method arguments
- Fixed a number of TODOs
- Added/updated unit tests for a lot of non-legacy classes
- Makefile support for creating HTML coverage reports with lcov/genhtml
2022-09-03 14:53:53 +00:00
|
|
|
EXPECT_NE(nullptr, device);
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_EQ(SCHD, device->GetType());
|
SASI code removal, error handling update, bug fixes, code cleanup (#806)
Summary ov most important changes triggered by the SASI code removal:
- Removed the SASI controller code
- New controller management. There is a new controller base class AbstractController and a class ControllerManager managing the controller lifecycle. The lifecycle management was removed from rasci.cpp and is covered by unit tests.
- New device management. The DeviceFactory manages the device lifecycle instead of rascsi.cpp. The new code is covered by unit tests.
- The lifecycle managment uses C++ collections with variable size instead of arrays with hard-coded sizes.
- The ScsiController method contains most of what was previously contained in scsidev_ctrl.cpp plus the code from sasidev_ctrl.cpp that was relevant for SCSI.
- scsi_command_util contains helper methods used for identical SCSI command implementations of more than one device
- Devices know their controllers, so that the controller instance does not need to be passed to each SCSI command. This change helps to decouple the devices from the controller. The phase_handler interface is also part of this decoupling.
- Use scsi_command_exception for propagating SCSI command execution errors, This resolves issues with the previous error handling, which was based on return values and often on magic numbers.
- Removed legacy SCSI error codes, all errors are now encoded by sense_key::, asc:: and status::.
- Fixed various warnings reported with -Wextra, -Weffc++ and -Wpedantic.
- Use constructor member initialization lists (recommended for ISO C++)
- Consistently use new/delete instead of malloc/free (recommended for ISO C++), resulting in better type safety and error handling
- Replaced variable sized arrays on the stack (violates ISO C++ and can cause a stack overflow)
- Replaced NULL by nullptr (recommended for C++), resulting in better type safety
- Use more const member functions in order to avoid side effects
- The format device page can now also be changed for hard disk drives (Fujitsu M2624S supports this, for instance), not just for MOs.
- Better encapsulation, updated access specifiers in many places
- Removed unused methods and method arguments
- Fixed a number of TODOs
- Added/updated unit tests for a lot of non-legacy classes
- Makefile support for creating HTML coverage reports with lcov/genhtml
2022-09-03 14:53:53 +00:00
|
|
|
|
2022-10-04 15:23:42 +00:00
|
|
|
device = device_factory.CreateDevice(controller_manager, UNDEFINED, 0, "test.nhd");
|
SASI code removal, error handling update, bug fixes, code cleanup (#806)
Summary ov most important changes triggered by the SASI code removal:
- Removed the SASI controller code
- New controller management. There is a new controller base class AbstractController and a class ControllerManager managing the controller lifecycle. The lifecycle management was removed from rasci.cpp and is covered by unit tests.
- New device management. The DeviceFactory manages the device lifecycle instead of rascsi.cpp. The new code is covered by unit tests.
- The lifecycle managment uses C++ collections with variable size instead of arrays with hard-coded sizes.
- The ScsiController method contains most of what was previously contained in scsidev_ctrl.cpp plus the code from sasidev_ctrl.cpp that was relevant for SCSI.
- scsi_command_util contains helper methods used for identical SCSI command implementations of more than one device
- Devices know their controllers, so that the controller instance does not need to be passed to each SCSI command. This change helps to decouple the devices from the controller. The phase_handler interface is also part of this decoupling.
- Use scsi_command_exception for propagating SCSI command execution errors, This resolves issues with the previous error handling, which was based on return values and often on magic numbers.
- Removed legacy SCSI error codes, all errors are now encoded by sense_key::, asc:: and status::.
- Fixed various warnings reported with -Wextra, -Weffc++ and -Wpedantic.
- Use constructor member initialization lists (recommended for ISO C++)
- Consistently use new/delete instead of malloc/free (recommended for ISO C++), resulting in better type safety and error handling
- Replaced variable sized arrays on the stack (violates ISO C++ and can cause a stack overflow)
- Replaced NULL by nullptr (recommended for C++), resulting in better type safety
- Use more const member functions in order to avoid side effects
- The format device page can now also be changed for hard disk drives (Fujitsu M2624S supports this, for instance), not just for MOs.
- Better encapsulation, updated access specifiers in many places
- Removed unused methods and method arguments
- Fixed a number of TODOs
- Added/updated unit tests for a lot of non-legacy classes
- Makefile support for creating HTML coverage reports with lcov/genhtml
2022-09-03 14:53:53 +00:00
|
|
|
EXPECT_NE(nullptr, device);
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_EQ(SCHD, device->GetType());
|
2022-08-28 17:25:08 +00:00
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
void TestRemovableDrive(PbDeviceType type, const string& filename, const string& product)
|
2022-08-28 17:25:08 +00:00
|
|
|
{
|
2022-10-25 00:21:40 +00:00
|
|
|
auto bus_ptr = make_shared<MockBus>();
|
2022-09-25 21:49:24 +00:00
|
|
|
DeviceFactory device_factory;
|
2022-10-25 00:21:40 +00:00
|
|
|
ControllerManager controller_manager(bus_ptr);
|
2022-09-25 21:49:24 +00:00
|
|
|
|
2022-10-04 15:23:42 +00:00
|
|
|
auto device = device_factory.CreateDevice(controller_manager, UNDEFINED, 0, filename);
|
2022-08-28 17:25:08 +00:00
|
|
|
EXPECT_NE(nullptr, device);
|
2022-10-04 15:23:42 +00:00
|
|
|
EXPECT_EQ(type, device->GetType());
|
2022-08-28 17:25:08 +00:00
|
|
|
EXPECT_TRUE(device->SupportsFile());
|
|
|
|
EXPECT_FALSE(device->SupportsParams());
|
|
|
|
EXPECT_TRUE(device->IsProtectable());
|
|
|
|
EXPECT_FALSE(device->IsProtected());
|
|
|
|
EXPECT_FALSE(device->IsReadOnly());
|
|
|
|
EXPECT_TRUE(device->IsRemovable());
|
|
|
|
EXPECT_FALSE(device->IsRemoved());
|
|
|
|
EXPECT_TRUE(device->IsLockable());
|
|
|
|
EXPECT_FALSE(device->IsLocked());
|
|
|
|
EXPECT_TRUE(device->IsStoppable());
|
|
|
|
EXPECT_FALSE(device->IsStopped());
|
|
|
|
|
|
|
|
EXPECT_EQ("RaSCSI", device->GetVendor());
|
2022-10-04 15:23:42 +00:00
|
|
|
EXPECT_EQ(product, device->GetProduct());
|
2022-08-28 17:25:08 +00:00
|
|
|
EXPECT_EQ(string(rascsi_get_version_string()).substr(0, 2) + string(rascsi_get_version_string()).substr(3, 2),
|
|
|
|
device->GetRevision());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-10-04 15:23:42 +00:00
|
|
|
TEST(DeviceFactoryTest, SCRM_Device_Defaults)
|
2022-08-28 17:25:08 +00:00
|
|
|
{
|
2022-10-23 19:51:39 +00:00
|
|
|
TestRemovableDrive(SCRM, "test.hdr", "SCSI HD (REM.)");
|
2022-10-04 15:23:42 +00:00
|
|
|
}
|
2022-08-28 17:25:08 +00:00
|
|
|
|
2022-10-04 15:23:42 +00:00
|
|
|
TEST(DeviceFactoryTest, SCMO_Device_Defaults)
|
|
|
|
{
|
2022-10-23 19:51:39 +00:00
|
|
|
TestRemovableDrive(SCMO, "test.mos", "SCSI MO");
|
2022-08-28 17:25:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DeviceFactoryTest, SCCD_Device_Defaults)
|
|
|
|
{
|
2022-10-25 00:21:40 +00:00
|
|
|
auto bus_ptr = make_shared<MockBus>();
|
2022-09-25 21:49:24 +00:00
|
|
|
DeviceFactory device_factory;
|
2022-10-25 00:21:40 +00:00
|
|
|
ControllerManager controller_manager(bus_ptr);
|
2022-09-25 21:49:24 +00:00
|
|
|
|
2022-10-04 15:23:42 +00:00
|
|
|
auto device = device_factory.CreateDevice(controller_manager, UNDEFINED, 0, "test.iso");
|
2022-08-28 17:25:08 +00:00
|
|
|
EXPECT_NE(nullptr, device);
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_EQ(SCCD, device->GetType());
|
2022-08-28 17:25:08 +00:00
|
|
|
EXPECT_TRUE(device->SupportsFile());
|
|
|
|
EXPECT_FALSE(device->SupportsParams());
|
|
|
|
EXPECT_FALSE(device->IsProtectable());
|
|
|
|
EXPECT_FALSE(device->IsProtected());
|
|
|
|
EXPECT_TRUE(device->IsReadOnly());
|
|
|
|
EXPECT_TRUE(device->IsRemovable());
|
|
|
|
EXPECT_FALSE(device->IsRemoved());
|
|
|
|
EXPECT_TRUE(device->IsLockable());
|
|
|
|
EXPECT_FALSE(device->IsLocked());
|
|
|
|
EXPECT_TRUE(device->IsStoppable());
|
|
|
|
EXPECT_FALSE(device->IsStopped());
|
|
|
|
|
|
|
|
EXPECT_EQ("RaSCSI", device->GetVendor());
|
|
|
|
EXPECT_EQ("SCSI CD-ROM", device->GetProduct());
|
|
|
|
EXPECT_EQ(string(rascsi_get_version_string()).substr(0, 2) + string(rascsi_get_version_string()).substr(3, 2),
|
|
|
|
device->GetRevision());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DeviceFactoryTest, SCBR_Device_Defaults)
|
|
|
|
{
|
2022-10-25 00:21:40 +00:00
|
|
|
auto bus_ptr = make_shared<MockBus>();
|
2022-09-25 21:49:24 +00:00
|
|
|
DeviceFactory device_factory;
|
2022-10-25 00:21:40 +00:00
|
|
|
ControllerManager controller_manager(bus_ptr);
|
2022-09-25 21:49:24 +00:00
|
|
|
|
2022-10-04 15:23:42 +00:00
|
|
|
auto device = device_factory.CreateDevice(controller_manager, UNDEFINED, 0, "bridge");
|
2022-08-28 17:25:08 +00:00
|
|
|
EXPECT_NE(nullptr, device);
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_EQ(SCBR, device->GetType());
|
2022-08-28 17:25:08 +00:00
|
|
|
EXPECT_FALSE(device->SupportsFile());
|
|
|
|
EXPECT_TRUE(device->SupportsParams());
|
|
|
|
EXPECT_FALSE(device->IsProtectable());
|
|
|
|
EXPECT_FALSE(device->IsProtected());
|
|
|
|
EXPECT_FALSE(device->IsReadOnly());
|
|
|
|
EXPECT_FALSE(device->IsRemovable());
|
|
|
|
EXPECT_FALSE(device->IsRemoved());
|
|
|
|
EXPECT_FALSE(device->IsLockable());
|
|
|
|
EXPECT_FALSE(device->IsLocked());
|
|
|
|
EXPECT_FALSE(device->IsStoppable());
|
|
|
|
EXPECT_FALSE(device->IsStopped());
|
|
|
|
|
|
|
|
EXPECT_EQ("RaSCSI", device->GetVendor());
|
2022-09-22 16:03:36 +00:00
|
|
|
EXPECT_EQ("RASCSI BRIDGE", device->GetProduct());
|
2022-08-28 17:25:08 +00:00
|
|
|
EXPECT_EQ(string(rascsi_get_version_string()).substr(0, 2) + string(rascsi_get_version_string()).substr(3, 2),
|
|
|
|
device->GetRevision());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DeviceFactoryTest, SCDP_Device_Defaults)
|
|
|
|
{
|
2022-10-25 00:21:40 +00:00
|
|
|
auto bus_ptr = make_shared<MockBus>();
|
2022-09-25 21:49:24 +00:00
|
|
|
DeviceFactory device_factory;
|
2022-10-25 00:21:40 +00:00
|
|
|
ControllerManager controller_manager(bus_ptr);
|
2022-09-25 21:49:24 +00:00
|
|
|
|
2022-10-04 15:23:42 +00:00
|
|
|
auto device = device_factory.CreateDevice(controller_manager, UNDEFINED, 0, "daynaport");
|
2022-08-28 17:25:08 +00:00
|
|
|
EXPECT_NE(nullptr, device);
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_EQ(SCDP, device->GetType());
|
2022-08-28 17:25:08 +00:00
|
|
|
EXPECT_FALSE(device->SupportsFile());
|
|
|
|
EXPECT_TRUE(device->SupportsParams());
|
|
|
|
EXPECT_FALSE(device->IsProtectable());
|
|
|
|
EXPECT_FALSE(device->IsProtected());
|
|
|
|
EXPECT_FALSE(device->IsReadOnly());
|
|
|
|
EXPECT_FALSE(device->IsRemovable());
|
|
|
|
EXPECT_FALSE(device->IsRemoved());
|
|
|
|
EXPECT_FALSE(device->IsLockable());
|
|
|
|
EXPECT_FALSE(device->IsLocked());
|
|
|
|
EXPECT_FALSE(device->IsStoppable());
|
|
|
|
EXPECT_FALSE(device->IsStopped());
|
|
|
|
|
|
|
|
EXPECT_EQ("Dayna", device->GetVendor());
|
|
|
|
EXPECT_EQ("SCSI/Link", device->GetProduct());
|
|
|
|
EXPECT_EQ("1.4a", device->GetRevision());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DeviceFactoryTest, SCHS_Device_Defaults)
|
|
|
|
{
|
2022-10-25 00:21:40 +00:00
|
|
|
auto bus_ptr = make_shared<MockBus>();
|
2022-09-25 21:49:24 +00:00
|
|
|
DeviceFactory device_factory;
|
2022-10-25 00:21:40 +00:00
|
|
|
ControllerManager controller_manager(bus_ptr);
|
2022-09-25 21:49:24 +00:00
|
|
|
|
2022-10-04 15:23:42 +00:00
|
|
|
auto device = device_factory.CreateDevice(controller_manager, UNDEFINED, 0, "services");
|
2022-08-28 17:25:08 +00:00
|
|
|
EXPECT_NE(nullptr, device);
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_EQ(SCHS, device->GetType());
|
2022-08-28 17:25:08 +00:00
|
|
|
EXPECT_FALSE(device->SupportsFile());
|
|
|
|
EXPECT_FALSE(device->SupportsParams());
|
|
|
|
EXPECT_FALSE(device->IsProtectable());
|
|
|
|
EXPECT_FALSE(device->IsProtected());
|
|
|
|
EXPECT_FALSE(device->IsReadOnly());
|
|
|
|
EXPECT_FALSE(device->IsRemovable());
|
|
|
|
EXPECT_FALSE(device->IsRemoved());
|
|
|
|
EXPECT_FALSE(device->IsLockable());
|
|
|
|
EXPECT_FALSE(device->IsLocked());
|
|
|
|
EXPECT_FALSE(device->IsStoppable());
|
|
|
|
EXPECT_FALSE(device->IsStopped());
|
|
|
|
|
|
|
|
EXPECT_EQ("RaSCSI", device->GetVendor());
|
|
|
|
EXPECT_EQ("Host Services", device->GetProduct());
|
|
|
|
EXPECT_EQ(string(rascsi_get_version_string()).substr(0, 2) + string(rascsi_get_version_string()).substr(3, 2),
|
|
|
|
device->GetRevision());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DeviceFactoryTest, SCLP_Device_Defaults)
|
|
|
|
{
|
2022-10-25 00:21:40 +00:00
|
|
|
auto bus_ptr = make_shared<MockBus>();
|
2022-09-25 21:49:24 +00:00
|
|
|
DeviceFactory device_factory;
|
2022-10-25 00:21:40 +00:00
|
|
|
ControllerManager controller_manager(bus_ptr);
|
2022-09-25 21:49:24 +00:00
|
|
|
|
2022-10-04 15:23:42 +00:00
|
|
|
auto device = device_factory.CreateDevice(controller_manager, UNDEFINED, 0, "printer");
|
2022-08-28 17:25:08 +00:00
|
|
|
EXPECT_NE(nullptr, device);
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_EQ(SCLP, device->GetType());
|
2022-08-28 17:25:08 +00:00
|
|
|
EXPECT_FALSE(device->SupportsFile());
|
|
|
|
EXPECT_TRUE(device->SupportsParams());
|
|
|
|
EXPECT_FALSE(device->IsProtectable());
|
|
|
|
EXPECT_FALSE(device->IsProtected());
|
|
|
|
EXPECT_FALSE(device->IsReadOnly());
|
|
|
|
EXPECT_FALSE(device->IsRemovable());
|
|
|
|
EXPECT_FALSE(device->IsRemoved());
|
|
|
|
EXPECT_FALSE(device->IsLockable());
|
|
|
|
EXPECT_FALSE(device->IsLocked());
|
|
|
|
EXPECT_FALSE(device->IsStoppable());
|
|
|
|
EXPECT_FALSE(device->IsStopped());
|
|
|
|
|
|
|
|
EXPECT_EQ("RaSCSI", device->GetVendor());
|
|
|
|
EXPECT_EQ("SCSI PRINTER", device->GetProduct());
|
|
|
|
EXPECT_EQ(string(rascsi_get_version_string()).substr(0, 2) + string(rascsi_get_version_string()).substr(3, 2),
|
|
|
|
device->GetRevision());
|
|
|
|
}
|