Skip to content

Commit 7fc84c4

Browse files
authored
Initial unit tests based on GoogleTest and GoogleMock (#802)
* Initial dummy test * Makefile update * Make protected method visible * Test update * Test update * Updated mode page device * Only build tests with explicit test target * make test builds and executes tests * Replaced constant * Added TODO * Merged develop * Added unit test * Comment update * Unit test update * Added tests * Added tests * Test cleanup * Updated error handling * Reverted MODE SENSE change * Reverted last change * Use GoogleMock * Comment update * Signature update * Cleanup * Cleanup * Further cleanup * Removed obsolete comment * Updated error handling * Cleanup * Added TODO * Added test * Added test * Renaming * Added test * Cleanup * Header update * Added two tests * Renaming * Fixed test argument order * Namespaces are needed in order to avoid name clashes * Added test * Added tests * Added tests * Added tests * Added tests * Updated host services test * Merge with develop * Moved code * Renaming * Added tests * Added tests * Initial device tests * Test cleanup * Added test * Removed cast * RASCSI_TEST target has to depend on SRC_PROTOBUF
1 parent 41ddc5f commit 7fc84c4

File tree

6 files changed

+571
-13
lines changed

6 files changed

+571
-13
lines changed

src/raspberrypi/Makefile

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ RASCTL = rasctl
6464
RASDUMP = rasdump
6565
SASIDUMP = sasidump
6666
SCSIMON = scsimon
67+
RASCSI_TEST = rascsi_test
6768

6869
SYSTEMD_CONF = /etc/systemd/system/rascsi.service
6970
RSYSLOG_CONF = /etc/rsyslog.d/rascsi.conf
@@ -90,21 +91,22 @@ SRC_PROTOC = \
9091
SRC_PROTOBUF = \
9192
rascsi_interface.pb.cpp
9293

93-
SRC_RASCSI = \
94-
rascsi.cpp \
95-
scsi.cpp \
94+
SRC_RASCSI_CORE = scsi.cpp \
9695
gpiobus.cpp \
9796
filepath.cpp \
98-
fileio.cpp\
97+
fileio.cpp \
9998
rascsi_version.cpp \
10099
rascsi_image.cpp \
101100
rascsi_response.cpp \
102101
rasutil.cpp \
103102
protobuf_util.cpp \
104103
localizer.cpp
105-
SRC_RASCSI += $(shell find ./controllers -name '*.cpp')
106-
SRC_RASCSI += $(shell find ./devices -name '*.cpp')
107-
SRC_RASCSI += $(SRC_PROTOBUF)
104+
SRC_RASCSI_CORE += $(shell find ./controllers -name '*.cpp')
105+
SRC_RASCSI_CORE += $(shell find ./devices -name '*.cpp')
106+
SRC_RASCSI_CORE += $(SRC_PROTOBUF)
107+
108+
SRC_RASCSI = rascsi.cpp
109+
SRC_RASCSI += $(SRC_RASCSI_CORE)
108110

109111
SRC_SCSIMON = \
110112
scsimon.cpp \
@@ -128,19 +130,24 @@ SRC_RASDUMP = \
128130
scsi.cpp \
129131
gpiobus.cpp \
130132
filepath.cpp \
131-
fileio.cpp\
133+
fileio.cpp \
132134
rascsi_version.cpp
133135

134136
SRC_SASIDUMP = \
135137
sasidump.cpp \
136138
scsi.cpp \
137139
gpiobus.cpp \
138140
filepath.cpp \
139-
fileio.cpp\
141+
fileio.cpp \
140142
rascsi_version.cpp
141143

144+
145+
SRC_RASCSI_TEST = $(shell find ./test -name '*.cpp')
146+
SRC_RASCSI_TEST += $(SRC_RASCSI_CORE)
147+
148+
142149
vpath %.h ./ ./controllers ./devices ./monitor
143-
vpath %.cpp ./ ./controllers ./devices ./monitor
150+
vpath %.cpp ./ ./controllers ./devices ./monitor ./test
144151
vpath %.o ./$(OBJDIR)
145152
vpath ./$(BINDIR)
146153

@@ -150,13 +157,14 @@ OBJ_RASCTL := $(addprefix $(OBJDIR)/,$(notdir $(SRC_RASCTL:%.cpp=%.o)))
150157
OBJ_RASDUMP := $(addprefix $(OBJDIR)/,$(notdir $(SRC_RASDUMP:%.cpp=%.o)))
151158
OBJ_SASIDUMP := $(addprefix $(OBJDIR)/,$(notdir $(SRC_SASIDUMP:%.cpp=%.o)))
152159
OBJ_SCSIMON := $(addprefix $(OBJDIR)/,$(notdir $(SRC_SCSIMON:%.cpp=%.o)))
160+
OBJ_RASCSI_TEST := $(addprefix $(OBJDIR)/,$(notdir $(SRC_RASCSI_TEST:%.cpp=%.o)))
153161

154162
GEN_PROTOBUF := $(SRC_PROTOBUF) rascsi_interface.pb.h
155163

156164

157165
# The following will include all of the auto-generated dependency files (*.d)
158166
# if they exist. This will trigger a rebuild of a source file if a header changes
159-
ALL_DEPS := $(patsubst %.o,%.d,$(OBJ_RASCSI) $(OBJ_RASCTL) $(OBJ_SCSIMON))
167+
ALL_DEPS := $(patsubst %.o,%.d,$(OBJ_RASCSI) $(OBJ_RASCTL) $(OBJ_SCSIMON) $(OBJ_RASCSI_TEST))
160168
-include $(ALL_DEPS)
161169

162170
$(OBJDIR) $(BINDIR):
@@ -180,6 +188,9 @@ $(SRC_PROTOBUF): $(SRC_PROTOC)
180188
all: $(BIN_ALL) docs
181189
ALL: all
182190

191+
test: $(BINDIR)/$(RASCSI_TEST)
192+
$(BINDIR)/$(RASCSI_TEST)
193+
183194
docs: $(DOC_DIR)/rascsi_man_page.txt $(DOC_DIR)/rasctl_man_page.txt $(DOC_DIR)/scsimon_man_page.txt
184195

185196
$(BINDIR)/$(RASCSI): $(SRC_PROTOBUF) $(OBJ_RASCSI) | $(BINDIR)
@@ -197,6 +208,9 @@ $(BINDIR)/$(SASIDUMP): $(OBJ_SASIDUMP) | $(BINDIR)
197208
$(BINDIR)/$(SCSIMON): $(OBJ_SCSIMON) | $(BINDIR)
198209
$(CXX) $(CXXFLAGS) -o $@ $(OBJ_SCSIMON) -lpthread
199210

211+
$(BINDIR)/$(RASCSI_TEST): $(SRC_PROTOBUF) $(OBJ_RASCSI_TEST) | $(BINDIR)
212+
$(CXX) $(CXXFLAGS) -o $@ $(OBJ_RASCSI_TEST) -lpcap -lprotobuf -lgmock -lgtest -lgtest_main
213+
200214

201215
# Phony rules for building individual utilities
202216
.PHONY: $(RASCSI) $(RASCTL) $(RASDUMP) $(SASIDUMP) $(SCSIMON)

src/raspberrypi/devices/device_factory.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class Device;
2626

2727
class DeviceFactory
2828
{
29-
private:
3029
DeviceFactory();
3130
~DeviceFactory() {}
3231

src/raspberrypi/devices/host_services.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ class HostServices: public ModePageDevice
3434

3535
bool SupportsFile() const override { return false; }
3636

37+
protected:
38+
39+
void AddModePages(map<int, vector<BYTE>>&, int, bool) const override;
40+
3741
private:
3842

3943
typedef ModePageDevice super;
4044

4145
Dispatcher<HostServices, SCSIDEV> dispatcher;
4246

43-
void AddModePages(map<int, vector<BYTE>>&, int, bool) const override;
4447
void AddRealtimeClockPage(map<int, vector<BYTE>>&, bool) const;
4548
};

0 commit comments

Comments
 (0)