mirror of
https://github.com/akuker/RASCSI.git
synced 2024-12-21 23:29:39 +00:00
41bdcd4aed
* Update logging * Remove duplicate code * Update unit tests * Clean up includes * Merge ProtobufSerializer into protobuf_util namespace * Precompile regex * Add const * Add Split() convenience method, update log level/ID parsing * Move log.h to legacy folder * Elimininate gotos * Fixes for gcc 13 * Update compiler flags * Update default folder handling * Use references instead of pointers * Move code for better encapsulation * Move code * Remove unused method argument * Move device logger * Remove redundant to_string * Rename for consistency * Update handling of protobuf pointers * Simplify protobuf usage * Memory handling update * Add hasher
147 lines
4.2 KiB
C++
147 lines
4.2 KiB
C++
//---------------------------------------------------------------------------
|
|
//
|
|
// SCSI Target Emulator PiSCSI
|
|
// for Raspberry Pi
|
|
//
|
|
// Copyright (C) 2022-2023 Uwe Seimet
|
|
//
|
|
//---------------------------------------------------------------------------
|
|
|
|
#include "mocks.h"
|
|
|
|
void ScsiMo_SetUpModePages(map<int, vector<byte>>& pages)
|
|
{
|
|
EXPECT_EQ(6, pages.size()) << "Unexpected number of mode pages";
|
|
EXPECT_EQ(12, pages[1].size());
|
|
EXPECT_EQ(24, pages[3].size());
|
|
EXPECT_EQ(24, pages[4].size());
|
|
EXPECT_EQ(4, pages[6].size());
|
|
EXPECT_EQ(12, pages[8].size());
|
|
EXPECT_EQ(12, pages[32].size());
|
|
}
|
|
|
|
TEST(ScsiMoTest, Inquiry)
|
|
{
|
|
TestInquiry::Inquiry(SCMO, device_type::optical_memory, scsi_level::scsi_2, "PiSCSI SCSI MO ", 0x1f, true);
|
|
}
|
|
|
|
TEST(ScsiMoTest, SupportsSaveParameters)
|
|
{
|
|
map<int, vector<byte>> pages;
|
|
MockSCSIMO mo(0, {});
|
|
|
|
EXPECT_TRUE(mo.SupportsSaveParameters());
|
|
}
|
|
|
|
TEST(ScsiMoTest, SetUpModePages)
|
|
{
|
|
map<int, vector<byte>> pages;
|
|
MockSCSIMO mo(0, {});
|
|
|
|
// Non changeable
|
|
mo.SetUpModePages(pages, 0x3f, false);
|
|
ScsiMo_SetUpModePages(pages);
|
|
|
|
// Changeable
|
|
pages.clear();
|
|
mo.SetUpModePages(pages, 0x3f, true);
|
|
ScsiMo_SetUpModePages(pages);
|
|
}
|
|
|
|
TEST(ScsiMoTest, TestAddVendorPage)
|
|
{
|
|
map<int, vector<byte>> pages;
|
|
MockSCSIMO mo(0, {});
|
|
|
|
mo.SetReady(true);
|
|
mo.SetUpModePages(pages, 0x21, false);
|
|
EXPECT_TRUE(pages.empty()) << "Unsupported vendor-specific page was returned";
|
|
|
|
mo.SetBlockCount(0x12345678);
|
|
mo.SetUpModePages(pages, 0x20, false);
|
|
EXPECT_EQ(1, pages.size()) << "Unexpected number of mode pages";
|
|
vector<byte>& page_32 = pages[32];
|
|
EXPECT_EQ(12, page_32.size());
|
|
EXPECT_EQ(0, to_integer<int>(page_32[2])) << "Wrong format mode";
|
|
EXPECT_EQ(0, to_integer<int>(page_32[3])) << "Wrong format type";
|
|
EXPECT_EQ(0x12345678, GetInt32(page_32, 4)) << "Wrong number of blocks";
|
|
EXPECT_EQ(0, GetInt16(page_32, 8)) << "Wrong number of spare blocks";
|
|
EXPECT_EQ(0, GetInt16(page_32, 10));
|
|
|
|
mo.SetSectorSizeInBytes(512);
|
|
mo.SetUpModePages(pages, 0x20, false);
|
|
page_32 = pages[32];
|
|
EXPECT_EQ(0, GetInt16(page_32, 8)) << "Wrong number of spare blocks";
|
|
EXPECT_EQ(0, GetInt16(page_32, 10));
|
|
|
|
mo.SetBlockCount(248826);
|
|
mo.SetUpModePages(pages, 0x20, false);
|
|
page_32 = pages[32];
|
|
EXPECT_EQ(1024, GetInt16(page_32, 8)) << "Wrong number of spare blocks";
|
|
EXPECT_EQ(1, GetInt16(page_32, 10));
|
|
|
|
mo.SetBlockCount(446325);
|
|
mo.SetUpModePages(pages, 0x20, false);
|
|
page_32 = pages[32];
|
|
EXPECT_EQ(1025, GetInt16(page_32, 8)) << "Wrong number of spare blocks";
|
|
EXPECT_EQ(10, GetInt16(page_32, 10));
|
|
|
|
mo.SetBlockCount(1041500);
|
|
mo.SetUpModePages(pages, 0x20, false);
|
|
page_32 = pages[32];
|
|
EXPECT_EQ(2250, GetInt16(page_32, 8)) << "Wrong number of spare blocks";
|
|
EXPECT_EQ(18, GetInt16(page_32, 10));
|
|
|
|
mo.SetSectorSizeInBytes(2048);
|
|
mo.SetBlockCount(0x12345678);
|
|
mo.SetUpModePages(pages, 0x20, false);
|
|
page_32 = pages[32];
|
|
EXPECT_EQ(0, GetInt16(page_32, 8)) << "Wrong number of spare blocks";
|
|
EXPECT_EQ(0, GetInt16(page_32, 10));
|
|
|
|
mo.SetBlockCount(310352);
|
|
mo.SetUpModePages(pages, 0x20, false);
|
|
page_32 = pages[32];
|
|
EXPECT_EQ(2244, GetInt16(page_32, 8)) << "Wrong number of spare blocks";
|
|
EXPECT_EQ(11, GetInt16(page_32, 10));
|
|
|
|
mo.SetBlockCount(605846);
|
|
mo.SetUpModePages(pages, 0x20, false);
|
|
page_32 = pages[32];
|
|
EXPECT_EQ(4437, GetInt16(page_32, 8)) << "Wrong number of spare blocks";
|
|
EXPECT_EQ(18, GetInt16(page_32, 10));
|
|
|
|
// Changeable page
|
|
mo.SetUpModePages(pages, 0x20, true);
|
|
EXPECT_EQ(0, to_integer<int>(page_32[2]));
|
|
EXPECT_EQ(0, to_integer<int>(page_32[3]));
|
|
EXPECT_EQ(0, GetInt32(page_32, 4));
|
|
EXPECT_EQ(0, GetInt16(page_32, 8));
|
|
EXPECT_EQ(0, GetInt16(page_32, 10));
|
|
}
|
|
|
|
TEST(ScsiMoTest, ModeSelect)
|
|
{
|
|
MockSCSIMO mo(0, { 1024, 2048 });
|
|
vector<int> cmd(10);
|
|
vector<uint8_t> buf(255);
|
|
|
|
mo.SetSectorSizeInBytes(2048);
|
|
|
|
// PF
|
|
cmd[1] = 0x10;
|
|
// Page 3 (Device Format Page)
|
|
buf[4] = 0x03;
|
|
// 2048 bytes per sector
|
|
buf[16] = 0x08;
|
|
EXPECT_NO_THROW(mo.ModeSelect(scsi_command::eCmdModeSelect6, cmd, buf, 255)) << "MODE SELECT(6) is supported";
|
|
buf[4] = 0;
|
|
buf[16] = 0;
|
|
|
|
// Page 3 (Device Format Page)
|
|
buf[8] = 0x03;
|
|
// 2048 bytes per sector
|
|
buf[20] = 0x08;
|
|
EXPECT_NO_THROW(mo.ModeSelect(scsi_command::eCmdModeSelect10, cmd, buf, 255)) << "MODE SELECT(10) is supported";
|
|
}
|