Fix SonarQube issues (#1276)

* Fix SonarQube issues

* Fix error handling when target ID for INQUIRY is missing
This commit is contained in:
Uwe Seimet 2023-11-01 12:53:05 +01:00 committed by GitHub
parent 029cf06c72
commit 8cb4105409
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 13 deletions

View File

@ -15,7 +15,10 @@ using namespace std;
shared_ptr<ScsiController> ControllerManager::CreateScsiController(BUS& bus, int id) const
{
return make_shared<ScsiController>(bus, id);
auto controller = make_shared<ScsiController>(bus, id);
controller->Init();
return controller;
}
bool ControllerManager::AttachToController(BUS& bus, int id, shared_ptr<PrimaryDevice> device)

View File

@ -0,0 +1,22 @@
//---------------------------------------------------------------------------
//
// SCSI Target Emulator PiSCSI
// for Raspberry Pi
//
// Copyright (C) 2023 Uwe Seimet
//
//---------------------------------------------------------------------------
#include "phase_handler.h"
void PhaseHandler::Init()
{
phase_executors[phase_t::busfree] = [this] () { BusFree(); };
phase_executors[phase_t::selection] = [this] () { Selection(); };
phase_executors[phase_t::dataout] = [this] () { DataOut(); };
phase_executors[phase_t::datain] = [this] () { DataIn(); };
phase_executors[phase_t::command] = [this] () { Command(); };
phase_executors[phase_t::status] = [this] () { Status(); };
phase_executors[phase_t::msgout] = [this] () { MsgOut(); };
phase_executors[phase_t::msgin] = [this] () { MsgIn(); };
}

View File

@ -25,6 +25,8 @@ public:
PhaseHandler() = default;
virtual ~PhaseHandler() = default;
void Init();
virtual void BusFree() = 0;
virtual void Selection() = 0;
virtual void Command() = 0;
@ -61,14 +63,5 @@ protected:
private:
const unordered_map<phase_t, function<void()>> phase_executors = {
{ phase_t::busfree, [this] () { BusFree(); } },
{ phase_t::selection, [this] () { Selection(); } },
{ phase_t::dataout, [this] () { DataOut(); } },
{ phase_t::datain, [this] () { DataIn(); } },
{ phase_t::command, [this] () { Command(); } },
{ phase_t::status, [this] () { Status(); } },
{ phase_t::msgout, [this] () { MsgOut(); } },
{ phase_t::msgin, [this] () { MsgIn(); } },
};
unordered_map<phase_t, function<void()>> phase_executors;
};

View File

@ -153,7 +153,7 @@ void ScsiDump::ParseArguments(span<char *> args)
throw parser_exception("Missing filename");
}
if (!scan_bus && !inquiry && target_id == -1) {
if (!scan_bus && target_id == -1) {
throw parser_exception("Missing target ID");
}
@ -638,7 +638,7 @@ int ScsiDump::DumpRestore()
cout << "Transfered : " << inq_info.capacity * inq_info.sector_size << " bytes ["
<< inq_info.capacity * inq_info.sector_size / 1024 / 1024 << "MiB]\n";
cout << "Total time: " << duration << " seconds (" << duration / 60 << " minutes\n";
cout << "Averate transfer rate: " << (inq_info.capacity * inq_info.sector_size / 8) / duration
cout << "Average transfer rate: " << (inq_info.capacity * inq_info.sector_size / 8) / duration
<< " bytes per second (" << (inq_info.capacity * inq_info.sector_size / 8) / duration / 1024
<< " KiB per second)\n";
cout << DIVIDER << "\n";

View File

@ -98,6 +98,7 @@ TEST(PhaseHandlerTest, Phases)
TEST(PhaseHandlerTest, ProcessPhase)
{
MockPhaseHandler handler;
handler.Init();
handler.SetPhase(phase_t::selection);
EXPECT_CALL(handler, Selection);

View File

@ -31,6 +31,7 @@ TEST(ScsiControllerTest, Process)
{
auto bus = make_shared<NiceMock<MockBus>>();
MockScsiController controller(bus, 0);
controller.Init();
controller.SetPhase(phase_t::reserved);
ON_CALL(*bus, GetRST).WillByDefault(Return(true));