diff --git a/.gitignore b/.gitignore index 259148f..6f09d05 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,7 @@ *.exe *.out *.app + +# Build Folders +bin/ +obj/ diff --git a/code/README.md b/code/README.md index e69de29..787935f 100644 --- a/code/README.md +++ b/code/README.md @@ -0,0 +1,14 @@ +# Dining Philosopher Implementation + +## Build +`make all` +## Execution +Run the executable: + +`./bin/dining-philosopher` +## Build Test +`make test` +## Run Tests +Run the executable: + +`./bin/unittest` diff --git a/code/bin/dining-philosopher b/code/bin/dining-philosopher deleted file mode 100755 index 5316863..0000000 Binary files a/code/bin/dining-philosopher and /dev/null differ diff --git a/code/makefile b/code/makefile index c8f981c..a64da3d 100644 --- a/code/makefile +++ b/code/makefile @@ -3,12 +3,15 @@ # Include directories INCDIR := \ - -I.. \ + -I$(FUSED_GTEST_DIR) \ + -I$(FUSED_GTEST_DIR)/src \ + SRCDIR=src BINDIR=bin OBJDIR=obj LIBDIR=lib +TSTDIR=unittest CC=gcc CXX=g++ @@ -16,32 +19,48 @@ CFLAGS =-I$(SRCDIR) $(INCDIR) CXXFLAGS =-I$(SRCDIR) $(INCDIR) LDFLAGS =-L$(LIBDIR) LDLIBS = -lrt +TSTLIBS = -lrt -lgtest -lgtest_main -pthread -lcrypto -lssl -lgcrypt -lgpg-error OUTFILE=dining-philosopher +TESTFILE=unittest -EXCDIR := unittest -CODEFILES := $(shell find $(SRCDIR) -type f -not -path "$(EXCDIR)/*") +CODEFILES := $(shell find $(SRCDIR) -type f -not -path "$(TSTDIR)/*") CFILES := $(filter %.c,$(CODEFILES)) CPPFILES := $(filter %.cpp,$(CODEFILES)) SRCFILES := $(CFILES) $(CPPFILES) HDRFILES := $(filter %.h,$(CODEFILES)) OBJFILES := $(subst $(SRCDIR), $(OBJDIR),$(CPPFILES:%.cpp=%.o) $(CFILES:%.c=%.o)) - - - +EXCFILE := main.* +TESTCODEFILES := $(shell find $(SRCDIR) -type f -not -name "$(EXCFILE)") +TESTCODEFILES += $(shell find $(TSTDIR) -type f ) +TESTCFILES := $(filter %.c,$(TESTCODEFILES)) +TESTCPPFILES := $(filter %.cpp,$(TESTCODEFILES)) +TESTOBJFILES := $(subst $(TSTDIR)/, $(OBJDIR)/, $(subst $(SRCDIR)/, $(OBJDIR)/,$(TESTCPPFILES:%.cpp=%.o) $(TESTCFILES:%.c=%.o))) $(OBJDIR)/%.o: $(SRCDIR)/%.c $(HDRFILES) mkdir -p $(dir $@) $(CC) -c -o $@ $< $(CFLAGS) +$(OBJDIR)/%.o: $(TSTDIR)/%.c $(HDRFILES) + mkdir -p $(dir $@) + $(CC) -c -o $@ $< $(CFLAGS) -$(OBJDIR)/%.o: $(SRCDIR)/%.cpp $(HDRFILES) +$(OBJDIR)/%.o: $(SRCDIR)/%.cpp $(HDRFILES) + mkdir -p $(dir $@) + $(CXX) -c -o $@ $< $(CXXFLAGS) + +$(OBJDIR)/%.o: $(TSTDIR)/%.cpp $(HDRFILES) mkdir -p $(dir $@) $(CXX) -c -o $@ $< $(CXXFLAGS) $(OUTFILE): $(OBJFILES) mkdir -p $(BINDIR) - $(CXX) -o $(BINDIR)/$@ $^ $(CFLAGS) $(LDFLAGS) $(LDLIBS) + $(CXX) -o $(BINDIR)/$@ $^ $(CXXFLAGS) $(LDFLAGS) $(LDLIBS) + +$(TESTFILE): $(TESTOBJFILES) + echo $(TESTOBJFILES) + mkdir -p $(BINDIR) + $(CXX) -o $(BINDIR)/$@ $^ $(CXXFLAGS) $(LDFLAGS) $(TSTLIBS) # $(OUTFILE): $(OBJFILES) # mkdir -p $(BINDIR) @@ -52,9 +71,13 @@ debug: CXXFLAGS += -DDEBUG -O0 -ggdb3 debug: CFLAGS += -DDEBUG -O0 -ggdb3 debug: $(OUTFILE) +test: CXXFLAGS += -DDEBUG -O0 -ggdb3 +test: CFLAGS += -DDEBUG -O0 -ggdb3 +test: $(TESTFILE) + rebuild: clean $(OUTFILE) -.PHONY: all clean +.PHONY: all clean test all: $(OUTFILE) diff --git a/code/unittest/bin/unittest b/code/unittest/bin/unittest deleted file mode 100755 index b5542eb..0000000 Binary files a/code/unittest/bin/unittest and /dev/null differ diff --git a/code/unittest/makefile b/code/unittest/makefile deleted file mode 100644 index fb2ff54..0000000 --- a/code/unittest/makefile +++ /dev/null @@ -1,62 +0,0 @@ -.DEFAULT_GOAL := all - -SRCDIR=src -BINDIR=bin -OBJDIR=obj -LIBDIR= - -FUSED_GTEST_DIR = /usr/src/googletest/googletest - - - -# Include directories -INCDIR := \ - -Iinclude/ \ - -I$(FUSED_GTEST_DIR) \ - -I$(FUSED_GTEST_DIR)/src \ - -I../src \ - -CC=gcc -CXX=g++ -CFLAGS =-I$(SRCDIR) $(INCDIR) -CXXFLAGS =-I$(SRCDIR) $(INCDIR) -LDFLAGS =-L$(LIBDIR) -LDLIBS = -lrt -lgtest -lgtest_main -pthread -lcrypto -lssl -lgcrypt -lgpg-error - -OUTFILE=unittest - -EXCFILE := main.* -CODEFILES := $(shell find $(SRCDIR) -type f -not -name "$(EXCFILE)") -CFILES := $(filter %.c,$(CODEFILES)) -CPPFILES := $(filter %.cpp,$(CODEFILES)) -SRCFILES := $(CFILES) $(CPPFILES) -HDRFILES := $(filter %.h,$(CODEFILES)) -OBJFILES := $(subst $(SRCDIR), $(OBJDIR),$(CPPFILES:%.cpp=%.o) $(CFILES:%.c=%.o)) -SRCOBJFILES := $(shell find ../obj -type f -not -name "$(EXCFILE)") - -$(OBJDIR)/%.o: $(SRCDIR)/%.c $(HDRFILES) - mkdir -p $(dir $@) - $(CC) -c -o $@ $< $(CFLAGS) - -$(OBJDIR)/%.o: $(SRCDIR)/%.cpp $(HDRFILES) - mkdir -p $(dir $@) - $(CXX) -c -o $@ $< $(CXXFLAGS) - -$(OUTFILE): $(OBJFILES) $(SRCOBJFILES) - mkdir -p $(BINDIR) - $(CXX) -o $(BINDIR)/$@ $^ $(CFLAGS) $(LDFLAGS) $(LDLIBS) - - -debug: CXXFLAGS += -DDEBUG -O0 -ggdb3 -debug: CFLAGS += -DDEBUG -O0 -ggdb3 -debug: clean $(OUTFILE) - -rebuild: clean $(OUTFILE) - -.PHONY: all clean - -all: debug - -clean: - rm -rf $(OBJDIR)/* - rm -rf $(BINDIR)/* \ No newline at end of file diff --git a/code/unittest/src/waiting-philosopher.cpp b/code/unittest/test-waiting-state.cpp similarity index 100% rename from code/unittest/src/waiting-philosopher.cpp rename to code/unittest/test-waiting-state.cpp diff --git a/code/unittest/src/unittest.cpp b/code/unittest/testmain.cpp similarity index 100% rename from code/unittest/src/unittest.cpp rename to code/unittest/testmain.cpp