Skip to content

Commit

Permalink
Fix data compression mode page size, update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Oct 27, 2024
1 parent 4be1045 commit 13d6667
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 14 deletions.
4 changes: 2 additions & 2 deletions cpp/base/primary_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ void PrimaryDevice::TestUnitReady()

void PrimaryDevice::Inquiry()
{
// EVPD and page code check
if ((GetCdbByte(1) & 0x01) || GetCdbByte(2)) {
// EVPD, CMDDT and page code check
if ((GetCdbByte(1) & 0x03) || GetCdbByte(2)) {
throw scsi_exception(sense_key::illegal_request, asc::invalid_field_in_cdb);
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/base/property_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void PropertyHandler::Init(const string &filenames, const property_map &cmd_prop

property_map properties;

// Always parse the optional global property file
// Parse the optional global property file unless disabled
if (!ignore_conf && exists(path(CONFIGURATION))) {
ParsePropertyFile(properties, CONFIGURATION, true);
}
Expand Down
1 change: 0 additions & 1 deletion cpp/devices/host_services.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ void HostServices::AddRealtimeClockPage(map<int, vector<byte>> &pages, bool chan

int HostServices::WriteData(span<const uint8_t> buf, scsi_command command)
{
assert(command == scsi_command::execute_operation);
if (command != scsi_command::execute_operation) {
throw scsi_exception(sense_key::aborted_command);
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/devices/scsi_hd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void ScsiHd::AddFormatPage(map<int, vector<byte>> &pages, bool changeable) const
vector<byte> buf(24);

if (changeable) {
// The sector size is simulated to be changeable in multiples of 4 with a maximum of 4096 bytes per sector.
// The sector size is simulated to be changeable in multiples of 4.
// See the MODE SELECT implementation for details.
SetInt16(buf, 12, 0x1ffc);

Expand Down
2 changes: 1 addition & 1 deletion cpp/devices/tape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ void Tape::AddModeBlockDescriptor(map<int, vector<byte>> &pages) const

void Tape::AddDataCompressionPage(map<int, vector<byte>> &pages) const
{
vector<byte> buf(14);
vector<byte> buf(16);

pages[15] = buf;
}
Expand Down
6 changes: 3 additions & 3 deletions cpp/s2p/s2p_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ void S2pParser::Banner(bool usage) const
<< " default is device-specific and usually SCSI-2.\n"
<< " --name/-n PRODUCT_NAME Optional product name for SCSI INQUIRY command,\n"
<< " format is VENDOR:PRODUCT:REVISION.\n"
<< " --block-size/-b BLOCK_SIZE Optional block (sector) size.\n"
<< " --block-size/-b BLOCK_SIZE Optional block size, 4-4096 bytes\n"
<< " in multiples of 4.\n"
<< " --caching-mode/-m MODE Caching mode (piscsi|write-through|linux\n"
<< " |linux-optimized), default currently is PiSCSI\n"
<< " compatible caching.\n"
Expand All @@ -45,8 +46,7 @@ void S2pParser::Banner(bool usage) const
<< " --property/-c KEY=VALUE Sets a configuration property.\n"
<< " --property-files/-C List of configuration property files.\n"
<< " --log-level/-L LEVEL Log level (trace|debug|info|warning|error|\n"
<< " critical|off),\n"
<< " default is 'info'.\n"
<< " critical|off), default is 'info'.\n"
<< " --log-pattern/-l PATTERN The spdlog pattern to use for logging.\n"
<< " --token-file/-P FILE Access token file.\n"
<< " --port/-p PORT s2p server port, default is 6868.\n"
Expand Down
7 changes: 4 additions & 3 deletions cpp/s2pctl/sp2ctl_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ void S2pCtl::Banner(bool usage) const
<< " |unprotect).\n"
<< " --type/-t TYPE Optional device type\n"
<< " (schd|scrm|sccd|scmo|scdp|sclp|schs|sahd).\n"
<< " --block-size/-b BLOCK_SIZE Optional block size\n"
<< " (256|512|1024|2048|4096).\n"
<< " --block-size/-b BLOCK_SIZE Optional block size, 4-4096 bytes\n"
<< " in multiples of 4.\n"
<< " --caching-mode/-m MODE Caching mode (piscsi|write-through|linux\n"
<< " |linux-optimized), default is PiSCSI\n"
<< " compatible caching.\n"
Expand Down Expand Up @@ -77,7 +77,8 @@ void S2pCtl::Banner(bool usage) const
<< " s2p requires authentication.\n"
<< " --list-settings/-s List s2p settings.\n"
<< " --list-statistics/-S List s2p statistics.\n"
<< " --persist Save the current configuration to /etc/s2p.conf.\n"
<< " --persist Save the current configuration to\n"
<< " /etc/s2p.conf.\n"
<< " --version/-v Display the program version.\n"
<< " --server-version/-V Display the s2p server version.\n"
<< " --shut-down/-X Shut down s2p.\n";
Expand Down
13 changes: 12 additions & 1 deletion cpp/test/controller_factory_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,18 @@ TEST(ControllerFactoryTest, AttachToController)

TEST(ControllerFactoryTest, ProcessOnController)
{
const int VALID_ID = 0;
const int INVALID_ID = 1;

MockBus bus;
ControllerFactory controller_factory;

EXPECT_EQ(shutdown_mode::none, controller_factory.ProcessOnController(0));
EXPECT_EQ(shutdown_mode::none, controller_factory.ProcessOnController(VALID_ID));

const auto device = make_shared<MockPrimaryDevice>(0);
EXPECT_TRUE(controller_factory.AttachToController(bus, VALID_ID, device));

EXPECT_EQ(shutdown_mode::none, controller_factory.ProcessOnController(VALID_ID));

EXPECT_EQ(shutdown_mode::none, controller_factory.ProcessOnController(INVALID_ID));
}
2 changes: 2 additions & 0 deletions cpp/test/host_services_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ TEST(HostServicesTest, WriteData)
auto [controller, services] = CreateDevice(SCHS);
array<uint8_t, 1> buf = { };

EXPECT_THROW(services->WriteData(buf, scsi_command::test_unit_ready), scsi_exception)<< "Illegal command";

EXPECT_EQ(0, services->WriteData(buf, scsi_command::execute_operation));

controller->SetCdbByte(8, 1);
Expand Down
2 changes: 1 addition & 1 deletion cpp/test/tape_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static void ValidateModePages(map<int, vector<byte>> &pages)
EXPECT_EQ(12U, pages[1].size());
EXPECT_EQ(16U, pages[2].size());
EXPECT_EQ(8U, pages[10].size());
EXPECT_EQ(14U, pages[15].size());
EXPECT_EQ(16U, pages[15].size());
EXPECT_EQ(16U, pages[16].size());
EXPECT_EQ(8U, pages[17].size());
}
Expand Down

0 comments on commit 13d6667

Please sign in to comment.