Skip to content

Commit

Permalink
Merge tag 'v23.04.01'
Browse files Browse the repository at this point in the history
PiSCSI version 23.04.01
  • Loading branch information
Tony Kuker committed Apr 23, 2023
2 parents 92d9fe5 + ba1d867 commit 57fa874
Show file tree
Hide file tree
Showing 38 changed files with 2,197 additions and 2,601 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,28 +93,16 @@ jobs:
working-directory: cpp
run: gcov --preserve-paths $(find -name '*.gcno')

- uses: actions/cache@v3
name: Cache SonarCloud scan cache
id: sonar-scan-cache
with:
path: ~/.sonar_cache/
key: sonar-scan-cache-${{ env.SONAR_SCANNER_VERSION }}-${{ github.ref_name }}-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}
restore-keys: |
sonar-scan-cache-${{ env.SONAR_SCANNER_VERSION }}-${{ github.ref_name }}
- name: Run sonar-scanner
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: >-
(mkdir -p $HOME/.sonar_cache || true) &&
$HOME/.sonar/sonar-scanner-${{ env.SONAR_SCANNER_VERSION }}-linux/bin/sonar-scanner
--define sonar.host.url="${{ env.SONAR_SERVER_URL }}"
--define sonar.projectKey=${{ env.SONAR_PROJECT_KEY }}
--define sonar.organization=${{ env.SONAR_ORGANIZATION }}
--define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}"
--define sonar.cfamily.gcov.reportsPath=.
--define sonar.cfamily.cache.enabled=true
--define sonar.cfamily.cache.path="$HOME/.sonar_cache/"
--define sonar.coverage.exclusions="cpp/**/test/**"
--define sonar.cpd.exclusions="cpp/**/test/**"
--define sonar.inclusions="cpp/**,python/**"
Expand Down
16 changes: 8 additions & 8 deletions cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -199,22 +199,22 @@ docs: $(DOC_DIR)/piscsi_man_page.txt $(DOC_DIR)/scsictl_man_page.txt $(DOC_DIR)/
$(SRC_PISCSI_CORE) $(SRC_SCSICTL_CORE) : $(OBJ_GENERATED)

$(BINDIR)/$(PISCSI): $(SRC_GENERATED) $(OBJ_PISCSI_CORE) $(OBJ_PISCSI) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) | $(BINDIR)
$(CXX) $(CXXFLAGS) -o $@ $(OBJ_PISCSI_CORE) $(OBJ_PISCSI) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) -lpthread -lpcap -lprotobuf -lstdc++fs
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJ_PISCSI_CORE) $(OBJ_PISCSI) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) -lpthread -lpcap -lprotobuf -lstdc++fs

$(BINDIR)/$(SCSICTL): $(SRC_GENERATED) $(OBJ_SCSICTL_CORE) $(OBJ_SCSICTL) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) | $(BINDIR)
$(CXX) $(CXXFLAGS) -o $@ $(OBJ_SCSICTL_CORE) $(OBJ_SCSICTL) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) -lpthread -lprotobuf
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJ_SCSICTL_CORE) $(OBJ_SCSICTL) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) -lpthread -lprotobuf

$(BINDIR)/$(SCSIDUMP): $(OBJ_SCSIDUMP) $(OBJ_SHARED) | $(BINDIR)
$(CXX) $(CXXFLAGS) -o $@ $(OBJ_SCSIDUMP) $(OBJ_SHARED)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJ_SCSIDUMP) $(OBJ_SHARED)

$(BINDIR)/$(SCSIMON): $(OBJ_SCSIMON) $(OBJ_SHARED) | $(BINDIR)
$(CXX) $(CXXFLAGS) -o $@ $(OBJ_SCSIMON) $(OBJ_SHARED)

$(BINDIR)/$(PISCSI_TEST): $(SRC_GENERATED) $(OBJ_PISCSI_CORE) $(OBJ_SCSICTL_CORE) $(OBJ_PISCSI_TEST) $(OBJ_SCSICTL_TEST) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) | $(BINDIR)
$(CXX) $(CXXFLAGS) $(TEST_WRAPS) -o $@ $(OBJ_PISCSI_CORE) $(OBJ_SCSICTL_CORE) $(OBJ_PISCSI_TEST) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) -lpthread -lpcap -lprotobuf -lstdc++fs -lgmock -lgtest
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJ_SCSIMON) $(OBJ_SHARED)

$(BINDIR)/$(SCSILOOP): $(OBJ_SHARED) $(OBJ_SCSILOOP) | $(BINDIR)
$(CXX) $(CXXFLAGS) -o $@ $(OBJ_SHARED) $(OBJ_SCSILOOP)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJ_SHARED) $(OBJ_SCSILOOP)

$(BINDIR)/$(PISCSI_TEST): $(SRC_GENERATED) $(OBJ_PISCSI_CORE) $(OBJ_SCSICTL_CORE) $(OBJ_PISCSI_TEST) $(OBJ_SCSICTL_TEST) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) | $(BINDIR)
$(CXX) $(CXXFLAGS) $(LDFLAGS) $(TEST_WRAPS) -o $@ $(OBJ_PISCSI_CORE) $(OBJ_SCSICTL_CORE) $(OBJ_PISCSI_TEST) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) -lpthread -lpcap -lprotobuf -lstdc++fs -lgmock -lgtest

# Phony rules for building individual utilities
.PHONY: $(PISCSI) $(SCSICTL) $(SCSIDUMP) $(SCSIMON) $(PISCSI_TEST) $(SCSILOOP)
Expand Down
4 changes: 3 additions & 1 deletion cpp/devices/device_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ DeviceFactory::DeviceFactory()
extension_mapping["hdr"] = SCRM;
extension_mapping["mos"] = SCMO;
extension_mapping["iso"] = SCCD;
extension_mapping["is1"] = SCCD;

device_mapping["bridge"] = SCBR;
device_mapping["daynaport"] = SCDP;
Expand Down Expand Up @@ -118,7 +119,8 @@ shared_ptr<PrimaryDevice> DeviceFactory::CreateDevice(PbDeviceType type, int lun
break;

case SCCD:
device = make_shared<SCSICD>(lun, sector_sizes.find(SCCD)->second);
device = make_shared<SCSICD>(lun, sector_sizes.find(SCCD)->second,
GetExtensionLowerCase(filename) == "is1" ? scsi_level::SCSI_1_CCS : scsi_level::SCSI_2);
device->SetProduct("SCSI CD-ROM");
break;

Expand Down
7 changes: 6 additions & 1 deletion cpp/devices/disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,12 @@ void Disk::SetUpModePages(map<int, vector<byte>>& pages, int page, bool changeab
void Disk::AddErrorPage(map<int, vector<byte>>& pages, bool) const
{
// Retry count is 0, limit time uses internal default value
pages[1] = vector<byte>(12);
vector<byte> buf(12);

// TB, PER, DTE (required for OpenVMS/VAX compatibility, see issue #1117)
buf[2] = (byte)0x26;

pages[1] = buf;
}

void Disk::AddFormatPage(map<int, vector<byte>>& pages, bool changeable) const
Expand Down
5 changes: 3 additions & 2 deletions cpp/devices/scsicd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
using namespace scsi_defs;
using namespace scsi_command_util;

SCSICD::SCSICD(int lun, const unordered_set<uint32_t>& sector_sizes) : Disk(SCCD, lun)
SCSICD::SCSICD(int lun, const unordered_set<uint32_t>& sector_sizes, scsi_defs::scsi_level level)
: Disk(SCCD, lun), scsi_level(level)
{
SetSectorSizes(sector_sizes);

Expand Down Expand Up @@ -164,7 +165,7 @@ void SCSICD::ReadToc()

vector<uint8_t> SCSICD::InquiryInternal() const
{
return HandleInquiry(device_type::CD_ROM, scsi_level::SCSI_2, true);
return HandleInquiry(device_type::CD_ROM, scsi_level, true);
}

void SCSICD::SetUpModePages(map<int, vector<byte>>& pages, int page, bool changeable) const
Expand Down
3 changes: 2 additions & 1 deletion cpp/devices/scsicd.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SCSICD : public Disk, private ScsiMmcCommands
{
public:

SCSICD(int, const unordered_set<uint32_t>&);
SCSICD(int, const unordered_set<uint32_t>&, scsi_defs::scsi_level = scsi_level::SCSI_2);
~SCSICD() override = default;

bool Init(const unordered_map<string, string>&) override;
Expand All @@ -43,6 +43,7 @@ class SCSICD : public Disk, private ScsiMmcCommands

void AddCDROMPage(map<int, vector<byte>>&, bool) const;
void AddCDDAPage(map<int, vector<byte>>&, bool) const;
scsi_defs::scsi_level scsi_level;

void OpenIso();
void OpenPhysical();
Expand Down
6 changes: 3 additions & 3 deletions cpp/devices/scsihd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ string SCSIHD::GetProductData() const
uint64_t capacity = GetBlockCount() * GetSectorSizeInBytes();
string unit;

// 10 GiB and more
if (capacity >= 1'099'511'627'776) {
capacity /= 1'099'511'627'776;
// 10,000 MiB and more
if (capacity >= 10'485'760'000) {
capacity /= 1'073'741'824;
unit = "GiB";
}
// 1 MiB and more
Expand Down
4 changes: 2 additions & 2 deletions cpp/hal/gpiobus_raspberry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ bool GPIOBUS_Raspberry::Init(mode_e mode)
// Map peripheral region memory
void *map = mmap(NULL, 0x1000100, PROT_READ | PROT_WRITE, MAP_SHARED, fd, baseaddr);
if (map == MAP_FAILED) {
LOGERROR("Error: Unable to map memory")
LOGERROR("Error: Unable to map memory: %s", strerror(errno))
close(fd);
return false;
}
Expand Down Expand Up @@ -985,4 +985,4 @@ uint32_t GPIOBUS_Raspberry::Acquire()
#endif // SIGNAL_CONTROL_MODE

return signals;
}
}
3 changes: 2 additions & 1 deletion cpp/piscsi/piscsi_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ void Piscsi::Banner(const vector<char *>& args) const
cout << " hdi : SCSI HD image (Anex86 HD image)\n";
cout << " nhd : SCSI HD image (T98Next HD image)\n";
cout << " mos : SCSI MO image (MO image)\n";
cout << " iso : SCSI CD image (ISO 9660 image)\n" << flush;
cout << " iso : SCSI CD image (ISO 9660 image)\n";
cout << " is1 : SCSI CD image (ISO 9660 image, SCSI-1)\n" << flush;

exit(EXIT_SUCCESS);
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/shared/piscsi_version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

// The following should be updated for each release
const int piscsi_major_version = 23; // Last two digits of year
const int piscsi_minor_version = 2; // Month
const int piscsi_minor_version = 4; // Month
const int piscsi_patch_version = 1; // Patch number - increment for each update

using namespace std;
Expand Down
4 changes: 3 additions & 1 deletion cpp/test/device_factory_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ TEST(DeviceFactoryTest, GetTypeForFile)
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.is1"), SCCD);
EXPECT_EQ(device_factory.GetTypeForFile("test.suffix.iso"), SCCD);
EXPECT_EQ(device_factory.GetTypeForFile("bridge"), SCBR);
EXPECT_EQ(device_factory.GetTypeForFile("daynaport"), SCDP);
Expand Down Expand Up @@ -79,7 +80,7 @@ TEST(DeviceFactoryTest, GetExtensionMapping)
DeviceFactory device_factory;

unordered_map<string, PbDeviceType> mapping = device_factory.GetExtensionMapping();
EXPECT_EQ(9, mapping.size());
EXPECT_EQ(10, mapping.size());
EXPECT_EQ(SCHD, mapping["hd1"]);
EXPECT_EQ(SCHD, mapping["hds"]);
EXPECT_EQ(SCHD, mapping["hda"]);
Expand All @@ -89,6 +90,7 @@ TEST(DeviceFactoryTest, GetExtensionMapping)
EXPECT_EQ(SCRM, mapping["hdr"]);
EXPECT_EQ(SCMO, mapping["mos"]);
EXPECT_EQ(SCCD, mapping["iso"]);
EXPECT_EQ(SCCD, mapping["is1"]);
}

TEST(DeviceFactoryTest, GetDefaultParams)
Expand Down
3 changes: 2 additions & 1 deletion cpp/test/mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SCSI Target Emulator PiSCSI
// for Raspberry Pi
//
// Copyright (C) 2022 Uwe Seimet
// Copyright (C) 2022-2023 Uwe Seimet
//
//---------------------------------------------------------------------------

Expand Down Expand Up @@ -358,6 +358,7 @@ class MockSCSIHD : public SCSIHD //NOSONAR Ignore inheritance hierarchy depth in
class MockSCSIHD_NEC : public SCSIHD_NEC //NOSONAR Ignore inheritance hierarchy depth in unit tests
{
FRIEND_TEST(ScsiHdNecTest, SetUpModePages);
FRIEND_TEST(ScsiHdNecTest, TestAddErrorPage);
FRIEND_TEST(ScsiHdNecTest, TestAddFormatPage);
FRIEND_TEST(ScsiHdNecTest, TestAddDrivePage);
FRIEND_TEST(PiscsiExecutorTest, ProcessDeviceCmd);
Expand Down
10 changes: 10 additions & 0 deletions cpp/test/piscsi_image_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ TEST(PiscsiImageTest, CreateImage)
PbCommand command;
PiscsiImage image;

StorageDevice::UnreserveAll();

EXPECT_FALSE(image.CreateImage(context, command)) << "Filename must be reported as missing";

SetParam(command, "file", "/a/b/c/filename");
Expand All @@ -63,6 +65,8 @@ TEST(PiscsiImageTest, DeleteImage)
PbCommand command;
PiscsiImage image;

StorageDevice::UnreserveAll();

EXPECT_FALSE(image.DeleteImage(context, command)) << "Filename must be reported as missing";

SetParam(command, "file", "/a/b/c/filename");
Expand All @@ -82,6 +86,8 @@ TEST(PiscsiImageTest, RenameImage)
PbCommand command;
PiscsiImage image;

StorageDevice::UnreserveAll();

EXPECT_FALSE(image.RenameImage(context, command)) << "Source filename must be reported as missing";

SetParam(command, "from", "/a/b/c/filename_from");
Expand All @@ -99,6 +105,8 @@ TEST(PiscsiImageTest, CopyImage)
PbCommand command;
PiscsiImage image;

StorageDevice::UnreserveAll();

EXPECT_FALSE(image.CopyImage(context, command)) << "Source filename must be reported as missing";

SetParam(command, "from", "/a/b/c/filename_from");
Expand All @@ -116,6 +124,8 @@ TEST(PiscsiImageTest, SetImagePermissions)
PbCommand command;
PiscsiImage image;

StorageDevice::UnreserveAll();

EXPECT_FALSE(image.SetImagePermissions(context, command)) << "Filename must be reported as missing";

SetParam(command, "file", "/a/b/c/filename");
Expand Down
2 changes: 1 addition & 1 deletion cpp/test/piscsi_response_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,5 @@ TEST(PiscsiResponseTest, GetMappingInfo)

const auto& info = response.GetMappingInfo(result);
EXPECT_TRUE(result.status());
EXPECT_EQ(9, info->mapping().size());
EXPECT_EQ(10, info->mapping().size());
}
2 changes: 2 additions & 0 deletions cpp/test/scsicd_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ void ScsiCdTest_SetUpModePages(map<int, vector<byte>>& pages)
TEST(ScsiCdTest, Inquiry)
{
TestInquiry(SCCD, device_type::CD_ROM, scsi_level::SCSI_2, "PiSCSI SCSI CD-ROM ", 0x1f, true);

TestInquiry(SCCD, device_type::CD_ROM, scsi_level::SCSI_1_CCS, "PiSCSI SCSI CD-ROM ", 0x1f, true, ".is1");
}

TEST(ScsiCdTest, SetUpModePages)
Expand Down
16 changes: 15 additions & 1 deletion cpp/test/scsihd_nec_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SCSI Target Emulator PiSCSI
// for Raspberry Pi
//
// Copyright (C) 2022 Uwe Seimet
// Copyright (C) 2022-2023 Uwe Seimet
//
//---------------------------------------------------------------------------

Expand Down Expand Up @@ -47,6 +47,20 @@ TEST(ScsiHdNecTest, SetUpModePages)
ScsiHdNecTest_SetUpModePages(pages);
}

TEST(ScsiHdNecTest, TestAddErrorPage)
{
map<int, vector<byte>> pages;
MockSCSIHD_NEC hd(0);

hd.SetBlockCount(0x1234);
hd.SetReady(true);
// Non changeable
hd.SetUpModePages(pages, 0x01, false);
EXPECT_EQ(1, pages.size()) << "Unexpected number of mode pages";
const vector<byte>& page_1 = pages[1];
EXPECT_EQ(0x26, to_integer<int>(page_1[2]));
}

TEST(ScsiHdNecTest, TestAddFormatPage)
{
map<int, vector<byte>> pages;
Expand Down
4 changes: 2 additions & 2 deletions cpp/test/scsihd_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ TEST(ScsiHdTest, GetProductData)

hd_gb.SetFilename(string(filename));
hd_gb.SetSectorSizeInBytes(1024);
hd_gb.SetBlockCount(1'099'511'627'776 / 1024);
hd_gb.SetBlockCount(10'737'418'240 / 1024);
hd_gb.FinalizeSetup(0);
s = hd_gb.GetProduct();
EXPECT_NE(string::npos, s.find("1 GiB"));
EXPECT_NE(string::npos, s.find("10 GiB"));
remove(filename);
}

Expand Down
1 change: 1 addition & 0 deletions doc/piscsi.1
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ PiSCSI will determine the type of device based upon the file extension of the FI
hda: SCSI Hard Disk image (Apple compatible - typically used with Macintosh computers)
mos: SCSI Magneto-Optical image (generic - typically used with NeXT, X68000, etc.)
iso: SCSI CD-ROM or DVD-ROM image (ISO 9660 image)
is1: SCSI CD-ROM or DVD-ROM image (ISO 9660 image, SCSI-1)

For example, if you want to specify an Apple-compatible HD image on ID 0, you can use the following command:
sudo piscsi -ID0 /path/to/drive/hdimage.hda
Expand Down
1 change: 1 addition & 0 deletions doc/piscsi_man_page.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ DESCRIPTION
hda: SCSI Hard Disk image (Apple compatible - typically used with Macintosh computers)
mos: SCSI Magneto-Optical image (generic - typically used with NeXT, X68000, etc.)
iso: SCSI CD-ROM or DVD-ROM image (ISO 9660 image)
is1: SCSI CD-ROM or DVD-ROM image (ISO 9660 image, SCSI-1)

For example, if you want to specify an Apple-compatible HD image on ID 0, you can use the following command:
sudo piscsi -ID0 /path/to/drive/hdimage.hda
Expand Down
Loading

0 comments on commit 57fa874

Please sign in to comment.