2022-08-28 17:25:08 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2022-12-05 17:58:23 +00:00
|
|
|
// SCSI Target Emulator PiSCSI
|
2022-08-28 17:25:08 +00:00
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
2023-10-15 06:38:15 +00:00
|
|
|
// Copyright (C) 2022-2023 Uwe Seimet
|
2022-08-28 17:25:08 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
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 "devices/device.h"
|
2022-08-28 17:25:08 +00:00
|
|
|
|
2023-10-30 10:24:18 +00:00
|
|
|
TEST(DeviceTest, GetDefaultParams)
|
|
|
|
{
|
|
|
|
MockDevice device(0);
|
|
|
|
|
|
|
|
const auto params = device.GetDefaultParams();
|
|
|
|
EXPECT_TRUE(params.empty());
|
|
|
|
}
|
|
|
|
|
2022-09-25 21:49:24 +00:00
|
|
|
TEST(DeviceTest, Properties)
|
|
|
|
{
|
|
|
|
const int LUN = 5;
|
|
|
|
|
2022-10-04 15:23:42 +00:00
|
|
|
MockDevice device(LUN);
|
2022-09-25 21:49:24 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_FALSE(device.IsReady()) << "Wrong default value";
|
|
|
|
device.SetReady(true);
|
|
|
|
EXPECT_TRUE(device.IsReady());
|
|
|
|
device.SetReady(false);
|
|
|
|
EXPECT_FALSE(device.IsReady());
|
|
|
|
|
|
|
|
EXPECT_FALSE(device.IsReset()) << "Wrong default value";
|
|
|
|
device.SetReset(true);
|
|
|
|
EXPECT_TRUE(device.IsReset());
|
|
|
|
device.SetReset(false);
|
|
|
|
EXPECT_FALSE(device.IsReset());
|
|
|
|
|
|
|
|
EXPECT_FALSE(device.IsAttn()) << "Wrong default value";
|
|
|
|
device.SetAttn(true);
|
|
|
|
EXPECT_TRUE(device.IsAttn());
|
|
|
|
device.SetAttn(false);
|
|
|
|
EXPECT_FALSE(device.IsAttn());
|
|
|
|
|
|
|
|
EXPECT_FALSE(device.IsReadOnly()) << "Wrong default value";
|
|
|
|
device.SetReadOnly(true);
|
|
|
|
EXPECT_TRUE(device.IsReadOnly());
|
|
|
|
device.SetReadOnly(false);
|
|
|
|
EXPECT_FALSE(device.IsReadOnly());
|
|
|
|
|
|
|
|
EXPECT_FALSE(device.IsProtectable()) << "Wrong default value";
|
2022-09-25 21:49:24 +00:00
|
|
|
device.SetProtectable(true);
|
|
|
|
EXPECT_TRUE(device.IsProtectable());
|
2022-10-23 19:51:39 +00:00
|
|
|
device.SetProtectable(false);
|
|
|
|
EXPECT_FALSE(device.IsProtectable());
|
2022-09-25 21:49:24 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_FALSE(device.IsProtected()) << "Wrong default value";
|
|
|
|
device.SetProtected(true);
|
2022-09-25 21:49:24 +00:00
|
|
|
EXPECT_FALSE(device.IsProtected());
|
2022-10-23 19:51:39 +00:00
|
|
|
device.SetProtectable(true);
|
2022-09-25 21:49:24 +00:00
|
|
|
device.SetProtected(true);
|
|
|
|
EXPECT_TRUE(device.IsProtected());
|
2022-10-23 19:51:39 +00:00
|
|
|
device.SetProtected(false);
|
|
|
|
EXPECT_FALSE(device.IsProtected());
|
2022-09-25 21:49:24 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
device.SetProtectable(false);
|
2022-09-25 21:49:24 +00:00
|
|
|
device.SetReadOnly(true);
|
2022-10-23 19:51:39 +00:00
|
|
|
device.SetProtected(true);
|
|
|
|
EXPECT_FALSE(device.IsProtected()) << "Read-only or not protectable devices cannot be protected";
|
|
|
|
device.SetReadOnly(false);
|
|
|
|
device.SetProtected(true);
|
|
|
|
EXPECT_FALSE(device.IsProtected()) << "Read-only or not protectable devices cannot be protected";
|
2022-09-25 21:49:24 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_FALSE(device.IsStoppable()) << "Wrong default value";
|
2022-09-25 21:49:24 +00:00
|
|
|
device.SetStoppable(true);
|
|
|
|
EXPECT_TRUE(device.IsStoppable());
|
2022-10-23 19:51:39 +00:00
|
|
|
device.SetStoppable(false);
|
|
|
|
EXPECT_FALSE(device.IsStoppable());
|
2022-09-25 21:49:24 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_FALSE(device.IsStopped()) << "Wrong default value";
|
2022-09-25 21:49:24 +00:00
|
|
|
device.SetStopped(true);
|
|
|
|
EXPECT_TRUE(device.IsStopped());
|
2022-10-23 19:51:39 +00:00
|
|
|
device.SetStopped(false);
|
|
|
|
EXPECT_FALSE(device.IsStopped());
|
2022-09-25 21:49:24 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_FALSE(device.IsRemovable()) << "Wrong default value";
|
2022-09-25 21:49:24 +00:00
|
|
|
device.SetRemovable(true);
|
|
|
|
EXPECT_TRUE(device.IsRemovable());
|
2022-10-23 19:51:39 +00:00
|
|
|
device.SetRemovable(false);
|
|
|
|
EXPECT_FALSE(device.IsRemovable());
|
2022-09-25 21:49:24 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_FALSE(device.IsRemoved()) << "Wrong default value";
|
2022-09-25 21:49:24 +00:00
|
|
|
device.SetRemoved(true);
|
|
|
|
EXPECT_TRUE(device.IsRemoved());
|
2022-10-23 19:51:39 +00:00
|
|
|
device.SetRemoved(false);
|
|
|
|
EXPECT_FALSE(device.IsRemoved());
|
2022-09-25 21:49:24 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_FALSE(device.IsLockable()) << "Wrong default value";
|
2022-09-25 21:49:24 +00:00
|
|
|
device.SetLockable(true);
|
|
|
|
EXPECT_TRUE(device.IsLockable());
|
2022-10-23 19:51:39 +00:00
|
|
|
device.SetLockable(false);
|
|
|
|
EXPECT_FALSE(device.IsLockable());
|
2022-09-25 21:49:24 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_FALSE(device.IsLocked()) << "Wrong default value";
|
2022-09-25 21:49:24 +00:00
|
|
|
device.SetLocked(true);
|
|
|
|
EXPECT_TRUE(device.IsLocked());
|
2022-10-23 19:51:39 +00:00
|
|
|
device.SetLocked(false);
|
|
|
|
EXPECT_FALSE(device.IsLocked());
|
2022-09-25 21:49:24 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_FALSE(device.SupportsParams()) << "Wrong default value";
|
2022-10-04 15:23:42 +00:00
|
|
|
device.SupportsParams(true);
|
|
|
|
EXPECT_TRUE(device.SupportsParams());
|
2022-10-23 19:51:39 +00:00
|
|
|
device.SupportsParams(false);
|
|
|
|
EXPECT_FALSE(device.SupportsParams());
|
|
|
|
|
|
|
|
EXPECT_FALSE(device.SupportsFile()) << "Wrong default value";
|
|
|
|
device.SupportsFile(true);
|
|
|
|
EXPECT_TRUE(device.SupportsFile());
|
|
|
|
device.SupportsFile(false);
|
2022-10-04 15:23:42 +00:00
|
|
|
EXPECT_FALSE(device.SupportsFile());
|
2022-09-25 21:49:24 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(LUN, device.GetLun());
|
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
TEST(DeviceTest, GetTypeString)
|
|
|
|
{
|
|
|
|
MockDevice schd(SCHD);
|
2023-10-15 06:38:15 +00:00
|
|
|
EXPECT_EQ("SCHD", schd.GetTypeString());
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
MockDevice scrm(SCRM);
|
2023-10-15 06:38:15 +00:00
|
|
|
EXPECT_EQ("SCRM", scrm.GetTypeString());
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
MockDevice scmo(SCMO);
|
2023-10-15 06:38:15 +00:00
|
|
|
EXPECT_EQ("SCMO", scmo.GetTypeString());
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
MockDevice sccd(SCCD);
|
2023-10-15 06:38:15 +00:00
|
|
|
EXPECT_EQ("SCCD", sccd.GetTypeString());
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
MockDevice schs(SCHS);
|
2023-10-15 06:38:15 +00:00
|
|
|
EXPECT_EQ("SCHS", schs.GetTypeString());
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
MockDevice scbr(SCBR);
|
2023-10-15 06:38:15 +00:00
|
|
|
EXPECT_EQ("SCBR", scbr.GetTypeString());
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
MockDevice scdp(SCDP);
|
2023-10-15 06:38:15 +00:00
|
|
|
EXPECT_EQ("SCDP", scdp.GetTypeString());
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
MockDevice sclp(SCLP);
|
2023-10-15 06:38:15 +00:00
|
|
|
EXPECT_EQ("SCLP", sclp.GetTypeString());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DeviceTest, GetIdentifier)
|
|
|
|
{
|
|
|
|
MockDevice device(1);
|
|
|
|
|
|
|
|
EXPECT_CALL(device, GetId());
|
|
|
|
EXPECT_EQ("UNDEFINED 0:1", device.GetIdentifier());
|
2022-10-23 19:51:39 +00:00
|
|
|
}
|
|
|
|
|
2022-10-04 15:23:42 +00:00
|
|
|
TEST(DeviceTest, Vendor)
|
2022-08-28 17:25:08 +00:00
|
|
|
{
|
2022-10-04 15:23:42 +00:00
|
|
|
MockDevice device(0);
|
2022-08-28 17:25:08 +00:00
|
|
|
|
2022-10-04 15:23:42 +00:00
|
|
|
EXPECT_THROW(device.SetVendor(""), invalid_argument);
|
|
|
|
EXPECT_THROW(device.SetVendor("123456789"), invalid_argument);
|
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
|
|
|
device.SetVendor("12345678");
|
|
|
|
EXPECT_EQ("12345678", device.GetVendor());
|
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(DeviceTest, Product)
|
|
|
|
{
|
|
|
|
MockDevice device(0);
|
|
|
|
|
|
|
|
EXPECT_THROW(device.SetProduct(""), invalid_argument);
|
|
|
|
EXPECT_THROW(device.SetProduct("12345678901234567"), invalid_argument);
|
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
|
|
|
device.SetProduct("1234567890123456");
|
|
|
|
EXPECT_EQ("1234567890123456", device.GetProduct());
|
2022-10-04 15:23:42 +00:00
|
|
|
device.SetProduct("xyz", false);
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_EQ("1234567890123456", device.GetProduct()) << "Changing vital product data is not SCSI compliant";
|
2022-10-04 15:23:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DeviceTest, Revision)
|
|
|
|
{
|
|
|
|
MockDevice device(0);
|
2022-08-28 17:25:08 +00:00
|
|
|
|
2022-10-04 15:23:42 +00:00
|
|
|
EXPECT_THROW(device.SetRevision(""), invalid_argument);
|
|
|
|
EXPECT_THROW(device.SetRevision("12345"), invalid_argument);
|
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
|
|
|
device.SetRevision("1234");
|
|
|
|
EXPECT_EQ("1234", device.GetRevision());
|
2022-10-04 15:23:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DeviceTest, GetPaddedName)
|
|
|
|
{
|
|
|
|
MockDevice device(0);
|
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
|
|
|
|
|
|
|
device.SetVendor("V");
|
|
|
|
device.SetProduct("P");
|
|
|
|
device.SetRevision("R");
|
2022-08-28 17:25:08 +00:00
|
|
|
|
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_EQ("V P R ", device.GetPaddedName());
|
2022-08-28 17:25:08 +00:00
|
|
|
}
|
2022-09-25 21:49:24 +00:00
|
|
|
|
|
|
|
TEST(DeviceTest, StatusCode)
|
|
|
|
{
|
2022-10-04 15:23:42 +00:00
|
|
|
MockDevice device(0);
|
2022-09-25 21:49:24 +00:00
|
|
|
|
|
|
|
device.SetStatusCode(123);
|
|
|
|
EXPECT_EQ(123, device.GetStatusCode());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DeviceTest, Reset)
|
|
|
|
{
|
2022-10-04 15:23:42 +00:00
|
|
|
MockDevice device(0);
|
2022-09-25 21:49:24 +00:00
|
|
|
|
|
|
|
device.SetLocked(true);
|
|
|
|
device.SetAttn(true);
|
|
|
|
device.SetReset(true);
|
|
|
|
device.Reset();
|
|
|
|
EXPECT_FALSE(device.IsLocked());
|
|
|
|
EXPECT_FALSE(device.IsAttn());
|
|
|
|
EXPECT_FALSE(device.IsReset());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DeviceTest, Start)
|
|
|
|
{
|
2022-10-04 15:23:42 +00:00
|
|
|
MockDevice device(0);
|
2022-09-25 21:49:24 +00:00
|
|
|
|
|
|
|
device.SetStopped(true);
|
|
|
|
device.SetReady(false);
|
|
|
|
EXPECT_FALSE(device.Start());
|
|
|
|
EXPECT_TRUE(device.IsStopped());
|
|
|
|
device.SetReady(true);
|
|
|
|
EXPECT_TRUE(device.Start());
|
|
|
|
EXPECT_FALSE(device.IsStopped());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DeviceTest, Stop)
|
|
|
|
{
|
2022-10-04 15:23:42 +00:00
|
|
|
MockDevice device(0);
|
2022-09-25 21:49:24 +00:00
|
|
|
|
|
|
|
device.SetReady(true);
|
|
|
|
device.SetAttn(true);
|
|
|
|
device.SetStopped(false);
|
|
|
|
device.Stop();
|
|
|
|
EXPECT_FALSE(device.IsReady());
|
|
|
|
EXPECT_FALSE(device.IsAttn());
|
|
|
|
EXPECT_TRUE(device.IsStopped());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DeviceTest, Eject)
|
|
|
|
{
|
2022-10-04 15:23:42 +00:00
|
|
|
MockDevice device(0);
|
2022-09-25 21:49:24 +00:00
|
|
|
|
|
|
|
device.SetReady(false);
|
|
|
|
device.SetRemovable(false);
|
|
|
|
EXPECT_FALSE(device.Eject(false));
|
2022-10-23 19:51:39 +00:00
|
|
|
|
2022-09-25 21:49:24 +00:00
|
|
|
device.SetReady(true);
|
|
|
|
EXPECT_FALSE(device.Eject(false));
|
2022-10-23 19:51:39 +00:00
|
|
|
|
2022-09-25 21:49:24 +00:00
|
|
|
device.SetRemovable(true);
|
|
|
|
device.SetLocked(true);
|
|
|
|
EXPECT_FALSE(device.Eject(false));
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_TRUE(device.Eject(true));
|
|
|
|
|
|
|
|
device.SetReady(true);
|
2022-09-25 21:49:24 +00:00
|
|
|
device.SetLocked(false);
|
|
|
|
EXPECT_TRUE(device.Eject(false));
|
|
|
|
EXPECT_FALSE(device.IsReady());
|
|
|
|
EXPECT_FALSE(device.IsAttn());
|
|
|
|
EXPECT_TRUE(device.IsRemoved());
|
|
|
|
EXPECT_FALSE(device.IsLocked());
|
|
|
|
EXPECT_TRUE(device.IsStopped());
|
|
|
|
}
|