2022-10-08 17:26:04 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2022-12-05 17:58:23 +00:00
|
|
|
// SCSI Target Emulator PiSCSI
|
2022-10-08 17:26:04 +00:00
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
2023-10-15 06:38:15 +00:00
|
|
|
// Copyright (C) 2022-2023 Uwe Seimet
|
2022-10-08 17:26:04 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "mocks.h"
|
|
|
|
|
2022-10-25 08:29:57 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
TEST(ScsiMoTest, Inquiry)
|
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
TestInquiry::Inquiry(SCMO, device_type::optical_memory, scsi_level::scsi_2, "PiSCSI SCSI MO ", 0x1f, true);
|
2022-10-23 19:51:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ScsiMoTest, SupportsSaveParameters)
|
|
|
|
{
|
|
|
|
map<int, vector<byte>> pages;
|
2023-11-14 14:32:46 +00:00
|
|
|
MockSCSIMO mo(0);
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
EXPECT_TRUE(mo.SupportsSaveParameters());
|
2022-10-08 17:26:04 +00:00
|
|
|
}
|
|
|
|
|
2023-11-14 14:32:46 +00:00
|
|
|
TEST(ScsiMoTest, GetSectorSizes)
|
|
|
|
{
|
|
|
|
MockSCSIMO mo(0);
|
|
|
|
|
|
|
|
const auto& sector_sizes = mo.GetSupportedSectorSizes();
|
|
|
|
EXPECT_EQ(4, sector_sizes.size());
|
|
|
|
|
|
|
|
EXPECT_TRUE(sector_sizes.contains(512));
|
|
|
|
EXPECT_TRUE(sector_sizes.contains(1024));
|
|
|
|
EXPECT_TRUE(sector_sizes.contains(2048));
|
|
|
|
EXPECT_TRUE(sector_sizes.contains(4096));
|
|
|
|
}
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
TEST(ScsiMoTest, SetUpModePages)
|
|
|
|
{
|
2022-10-23 19:51:39 +00:00
|
|
|
map<int, vector<byte>> pages;
|
2023-11-14 14:32:46 +00:00
|
|
|
MockSCSIMO mo(0);
|
2022-10-23 19:51:39 +00:00
|
|
|
|
2022-10-25 08:29:57 +00:00
|
|
|
// Non changeable
|
2022-10-23 19:51:39 +00:00
|
|
|
mo.SetUpModePages(pages, 0x3f, false);
|
2022-10-25 08:29:57 +00:00
|
|
|
ScsiMo_SetUpModePages(pages);
|
|
|
|
|
|
|
|
// Changeable
|
|
|
|
pages.clear();
|
|
|
|
mo.SetUpModePages(pages, 0x3f, true);
|
|
|
|
ScsiMo_SetUpModePages(pages);
|
2022-10-23 19:51:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ScsiMoTest, TestAddVendorPage)
|
|
|
|
{
|
|
|
|
map<int, vector<byte>> pages;
|
2023-11-14 14:32:46 +00:00
|
|
|
MockSCSIMO mo(0);
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
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());
|
2022-11-02 06:36:25 +00:00
|
|
|
EXPECT_EQ(0, to_integer<int>(page_32[2])) << "Wrong format mode";
|
|
|
|
EXPECT_EQ(0, to_integer<int>(page_32[3])) << "Wrong format type";
|
2022-10-23 19:51:39 +00:00
|
|
|
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);
|
2022-11-02 06:36:25 +00:00
|
|
|
EXPECT_EQ(0, to_integer<int>(page_32[2]));
|
|
|
|
EXPECT_EQ(0, to_integer<int>(page_32[3]));
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_EQ(0, GetInt32(page_32, 4));
|
|
|
|
EXPECT_EQ(0, GetInt16(page_32, 8));
|
|
|
|
EXPECT_EQ(0, GetInt16(page_32, 10));
|
2022-10-08 17:26:04 +00:00
|
|
|
}
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
TEST(ScsiMoTest, ModeSelect)
|
|
|
|
{
|
2023-11-14 14:32:46 +00:00
|
|
|
MockSCSIMO mo(0);
|
2022-10-23 19:51:39 +00:00
|
|
|
vector<int> cmd(10);
|
2022-11-02 06:36:25 +00:00
|
|
|
vector<uint8_t> buf(255);
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
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";
|
|
|
|
}
|