This commit is contained in:
Uwe Seimet 2023-11-15 17:48:45 +01:00
parent 89b45f29a4
commit b14ab0f084
9 changed files with 38 additions and 37 deletions

View File

@ -45,7 +45,7 @@ endif
PISCSI = piscsi
SCSICTL = scsictl
SCSIDUMP = scsidump
SCSISEND = scsisend
SCSIEXEC = scsiexec
SCSIMON = scsimon
PISCSI_TEST = piscsi_test
SCSILOOP = scsiloop
@ -73,7 +73,7 @@ BIN_ALL = \
# Some tools require initiator support
ifeq ($(CONNECT_TYPE), FULLSPEC)
BIN_ALL += $(BINDIR)/$(SCSIDUMP)
BIN_ALL += $(BINDIR)/$(SCSISEND)
BIN_ALL += $(BINDIR)/$(SCSIEXEC)
endif
SRC_PROTOC = piscsi_interface.proto
@ -107,9 +107,9 @@ SRC_SCSIDUMP = scsidump/scsidump.cpp
SRC_SCSIDUMP += $(shell find ./scsidump -name '*.cpp' | grep -v scsidump.cpp)
SRC_SCSIDUMP += $(shell find ./hal -name '*.cpp')
SRC_SCSISEND = scsisend/scsisend.cpp
SRC_SCSISEND += $(shell find ./scsisend -name '*.cpp' | grep -v scsisend.cpp)
SRC_SCSISEND += $(shell find ./hal -name '*.cpp')
SRC_SCSIEXEC = scsiexec/scsiexec.cpp
SRC_SCSIEXEC += $(shell find ./scsiexec -name '*.cpp' | grep -v scsiexec.cpp)
SRC_SCSIEXEC += $(shell find ./hal -name '*.cpp')
SRC_PISCSI_TEST = $(shell find ./test -name '*.cpp')
SRC_PISCSI_TEST += $(shell find ./scsidump -name '*.cpp' | grep -v scsidump.cpp)
@ -119,9 +119,9 @@ SRC_SCSILOOP += $(shell find ./scsiloop -name '*.cpp' | grep -v scsiloop.cpp)
SRC_SCSILOOP += $(shell find ./hal -name '*.cpp')
vpath %.h ./shared ./controllers ./devices ./scsimon ./hal \
./hal/pi_defs ./piscsi ./scsictl ./scsidump ./scsisend ./scsiloop
./hal/pi_defs ./piscsi ./scsictl ./scsidump ./scsiexec ./scsiloop
vpath %.cpp ./shared ./controllers ./devices ./scsimon ./hal \
./hal/pi_defs ./piscsi ./scsictl ./scsidump ./scsisend ./scsiloop ./test
./hal/pi_defs ./piscsi ./scsictl ./scsidump ./scsiexec ./scsiloop ./test
vpath %.o ./$(OBJDIR)
vpath ./$(BINDIR)
@ -131,7 +131,7 @@ OBJ_PISCSI := $(addprefix $(OBJDIR)/,$(notdir $(SRC_PISCSI:%.cpp=%.o)))
OBJ_SCSICTL_CORE := $(addprefix $(OBJDIR)/,$(notdir $(SRC_SCSICTL_CORE:%.cpp=%.o)))
OBJ_SCSICTL := $(addprefix $(OBJDIR)/,$(notdir $(SRC_SCSICTL:%.cpp=%.o)))
OBJ_SCSIDUMP := $(addprefix $(OBJDIR)/,$(notdir $(SRC_SCSIDUMP:%.cpp=%.o)))
OBJ_SCSISEND := $(addprefix $(OBJDIR)/,$(notdir $(SRC_SCSISEND:%.cpp=%.o)))
OBJ_SCSIEXEC := $(addprefix $(OBJDIR)/,$(notdir $(SRC_SCSIEXEC:%.cpp=%.o)))
OBJ_SCSIMON := $(addprefix $(OBJDIR)/,$(notdir $(SRC_SCSIMON:%.cpp=%.o)))
OBJ_PISCSI_TEST := $(addprefix $(OBJDIR)/,$(notdir $(SRC_PISCSI_TEST:%.cpp=%.o)))
OBJ_SCSILOOP := $(addprefix $(OBJDIR)/,$(notdir $(SRC_SCSILOOP:%.cpp=%.o)))
@ -145,7 +145,7 @@ BINARIES = $(USR_LOCAL_BIN)/$(SCSICTL) \
$(USR_LOCAL_BIN)/$(SCSILOOP)
ifeq ($(CONNECT_TYPE), FULLSPEC)
BINARIES += $(USR_LOCAL_BIN)/$(SCSIDUMP)
BINARIES += $(USR_LOCAL_BIN)/$(SCSISEND)
BINARIES += $(USR_LOCAL_BIN)/$(SCSIEXEC)
endif
MAN_PAGES = $(MAN_PAGE_DIR)/piscsi.1 \
@ -154,7 +154,7 @@ MAN_PAGES = $(MAN_PAGE_DIR)/piscsi.1 \
$(MAN_PAGE_DIR)/scsiloop.1
ifeq ($(CONNECT_TYPE), FULLSPEC)
MAN_PAGES += $(MAN_PAGE_DIR)/scsidump.1
MAN_PAGES += $(MAN_PAGE_DIR)/scsisend.1
MAN_PAGES += $(MAN_PAGE_DIR)/scsiexec.1
endif
GENERATED_DIR := generated
@ -166,7 +166,7 @@ TEST_WRAPS = -Wl,--wrap=fopen64
# The following will include all of the auto-generated dependency files (*.d)
# if they exist. This will trigger a rebuild of a source file if a header changes
ALL_DEPS := $(patsubst %.o,%.d,$(OBJ_PISCSI_CORE) $(OBJ_SCSICTL_CORE) $(OBJ_PISCSI) $(OBJ_SCSICTL) $(OBJ_SCSIDUMP) $(OBJ_SCSISEND) $(OBJ_SCSIMON) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_PISCSI_TEST) $(OBJ_SCSILOOP))
ALL_DEPS := $(patsubst %.o,%.d,$(OBJ_PISCSI_CORE) $(OBJ_SCSICTL_CORE) $(OBJ_PISCSI) $(OBJ_SCSICTL) $(OBJ_SCSIDUMP) $(OBJ_SCSIEXEC) $(OBJ_SCSIMON) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_PISCSI_TEST) $(OBJ_SCSILOOP))
-include $(ALL_DEPS)
$(OBJDIR) $(BINDIR):
@ -223,8 +223,8 @@ $(BINDIR)/$(SCSICTL): $(OBJ_GENERATED) $(OBJ_SCSICTL_CORE) $(OBJ_SCSICTL) $(OBJ_
$(BINDIR)/$(SCSIDUMP): $(OBJ_SCSIDUMP) $(OBJ_SHARED) | $(BINDIR)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJ_SCSIDUMP) $(OBJ_SHARED)
$(BINDIR)/$(SCSISEND): $(OBJ_SCSISEND) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) | $(BINDIR)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJ_SCSISEND) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) -lprotobuf
$(BINDIR)/$(SCSIEXEC): $(OBJ_SCSIEXEC) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) | $(BINDIR)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJ_SCSIEXEC) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) -lprotobuf
$(BINDIR)/$(SCSIMON): $(OBJ_SCSIMON) $(OBJ_SHARED) | $(BINDIR)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJ_SCSIMON) $(OBJ_SHARED)
@ -236,11 +236,11 @@ $(BINDIR)/$(PISCSI_TEST): $(OBJ_GENERATED) $(OBJ_PISCSI_CORE) $(OBJ_SCSICTL_CORE
$(CXX) $(CXXFLAGS) $(LDFLAGS) $(TEST_WRAPS) -o $@ $(OBJ_PISCSI_CORE) $(OBJ_SCSICTL_CORE) $(OBJ_PISCSI_TEST) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) -lpthread -lpcap -lprotobuf -lgmock -lgtest
# Phony rules for building individual utilities
.PHONY: $(PISCSI) $(SCSICTL) $(SCSIDUMP) $(SCSISEND) $(SCSIMON) $(PISCSI_TEST) $(SCSILOOP)
.PHONY: $(PISCSI) $(SCSICTL) $(SCSIDUMP) $(SCSIEXEC) $(SCSIMON) $(PISCSI_TEST) $(SCSILOOP)
$(PISCSI) : $(BINDIR)/$(PISCSI)
$(SCSICTL) : $(BINDIR)/$(SCSICTL)
$(SCSIDUMP) : $(BINDIR)/$(SCSIDUMP)
$(SCSISEND) : $(BINDIR)/$(SCSISEND)
$(SCSIEXEC) : $(BINDIR)/$(SCSIEXEC)
$(SCSIMON) : $(BINDIR)/$(SCSIMON)
$(PISCSI_TEST): $(BINDIR)/$(PISCSI_TEST)
$(SCSILOOP) : $(BINDIR)/$(SCSILOOP)

View File

@ -8,7 +8,7 @@
//---------------------------------------------------------------------------
#include "shared/scsi.h"
#include "scsisend/scsi_executor.h"
#include "scsiexec/scsi_executor.h"
#include "generated/piscsi_interface.pb.h"
#include <google/protobuf/util/json_util.h>
#include <spdlog/spdlog.h>
@ -56,7 +56,7 @@ void ScsiExecutor::Execute(const string& filename, bool binary)
if (!binary) {
const string json((const char *)buffer.data(), length);
cerr << "json received:\n" << json << endl;
spdlog::info("json received:\n" + json);
}
else {
PbResult result;
@ -65,6 +65,6 @@ void ScsiExecutor::Execute(const string& filename, bool binary)
}
string json;
google::protobuf::util::MessageToJsonString(result, &json);
cerr << "json (converted from binary) received:\n" << json << endl;
spdlog::info("json (converted from binary) received:\n" + json);
}
}

View File

@ -9,7 +9,7 @@
#pragma once
#include "scsisend/phase_executor.h"
#include "scsiexec/phase_executor.h"
#include <cstdint>
#include <vector>
#include <span>

View File

@ -7,7 +7,7 @@
//
//---------------------------------------------------------------------------
#include "scsisend/scsisend_core.h"
#include "scsisexec_core.h"
using namespace std;
@ -15,5 +15,5 @@ int main(int argc, char *argv[])
{
vector<char *> args(argv, argv + argc);
return ScsiSend().run(args);
return ScsiExec().run(args);
}

View File

@ -7,7 +7,7 @@
//
//---------------------------------------------------------------------------
#include "scsisend/scsisend_core.h"
#include "scsisexec_core.h"
#include "hal/sbc_version.h"
#include "hal/gpiobus_factory.h"
#include "controllers/controller_manager.h"
@ -25,14 +25,14 @@ using namespace spdlog;
using namespace scsi_defs;
using namespace piscsi_util;
void ScsiSend::CleanUp() const
void ScsiExec::CleanUp() const
{
if (bus != nullptr) {
bus->Cleanup();
}
}
void ScsiSend::TerminationHandler(int)
void ScsiExec::TerminationHandler(int)
{
instance->bus->SetRST(true);
@ -41,9 +41,9 @@ void ScsiSend::TerminationHandler(int)
// Process will terminate automatically
}
bool ScsiSend::Banner(span<char*> args) const
bool ScsiExec::Banner(span<char*> args) const
{
cout << piscsi_util::Banner("(SCSI Action Trigger Utility)");
cout << piscsi_util::Banner("(SCSI Action Execution Utility)");
if (args.size() < 2 || string(args[1]) == "-h" || string(args[1]) == "--help") {
cout << "Usage: " << args[0] << " -t ID[:LUN] [-i BID] -f FILENAME [-L log_level] [-b] \n"
@ -60,7 +60,7 @@ bool ScsiSend::Banner(span<char*> args) const
return true;
}
bool ScsiSend::Init(bool)
bool ScsiExec::Init(bool)
{
instance = this;
// Signal handler for cleaning up
@ -81,7 +81,7 @@ bool ScsiSend::Init(bool)
return bus != nullptr;
}
void ScsiSend::ParseArguments(span<char*> args)
void ScsiExec::ParseArguments(span<char*> args)
{
optind = 1;
opterr = 0;
@ -122,7 +122,7 @@ void ScsiSend::ParseArguments(span<char*> args)
}
}
int ScsiSend::run(span<char*> args, bool in_process)
int ScsiExec::run(span<char*> args, bool in_process)
{
if (!Banner(args)) {
return EXIT_SUCCESS;
@ -163,7 +163,7 @@ int ScsiSend::run(span<char*> args, bool in_process)
return EXIT_SUCCESS;
}
bool ScsiSend::SetLogLevel() const
bool ScsiExec::SetLogLevel() const
{
const level::level_enum l = level::from_str(log_level);
// Compensate for spdlog using 'off' for unknown levels

View File

@ -10,7 +10,7 @@
#pragma once
#include "hal/bus.h"
#include "scsisend/scsi_executor.h"
#include "scsiexec/scsi_executor.h"
#include <string>
#include <span>
#include <vector>
@ -18,13 +18,13 @@
using namespace std;
class ScsiSend
class ScsiExec
{
public:
ScsiSend() = default;
~ScsiSend() = default;
ScsiExec() = default;
~ScsiExec() = default;
int run(span<char*>, bool = false);
@ -59,5 +59,5 @@ private:
string log_level = "info";
// Required for the termination handler
static inline ScsiSend *instance;
static inline ScsiExec *instance;
};

View File

@ -12,7 +12,7 @@
TEST(BusTest, GetCommandByteCount)
{
EXPECT_EQ(41, scsi_defs::command_mapping.size());
EXPECT_EQ(42, scsi_defs::command_mapping.size());
EXPECT_EQ(6, BUS::GetCommandByteCount(0x00));
EXPECT_EQ(6, BUS::GetCommandByteCount(0x01));
EXPECT_EQ(6, BUS::GetCommandByteCount(0x03));
@ -47,13 +47,14 @@ TEST(BusTest, GetCommandByteCount)
EXPECT_EQ(10, BUS::GetCommandByteCount(0x4a));
EXPECT_EQ(10, BUS::GetCommandByteCount(0x55));
EXPECT_EQ(10, BUS::GetCommandByteCount(0x5a));
EXPECT_EQ(12, BUS::GetCommandByteCount(0xa0));
EXPECT_EQ(16, BUS::GetCommandByteCount(0x88));
EXPECT_EQ(16, BUS::GetCommandByteCount(0x8a));
EXPECT_EQ(16, BUS::GetCommandByteCount(0x8f));
EXPECT_EQ(16, BUS::GetCommandByteCount(0x91));
EXPECT_EQ(16, BUS::GetCommandByteCount(0x9e));
EXPECT_EQ(16, BUS::GetCommandByteCount(0x9f));
EXPECT_EQ(12, BUS::GetCommandByteCount(0xa0));
EXPECT_EQ(10, BUS::GetCommandByteCount(0xc0));
EXPECT_EQ(0, BUS::GetCommandByteCount(0x1f));
}