Skip to content

Commit

Permalink
updated unittest folder structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Herrera committed Oct 1, 2021
1 parent 6664dd5 commit 298bcd3
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 71 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@
*.exe
*.out
*.app

# Build Folders
bin/
obj/
14 changes: 14 additions & 0 deletions code/README.md
Original file line number Diff line number Diff line change
@@ -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`
Binary file removed code/bin/dining-philosopher
Binary file not shown.
41 changes: 32 additions & 9 deletions code/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,64 @@

# 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++
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)
Expand All @@ -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)

Expand Down
Binary file removed code/unittest/bin/unittest
Binary file not shown.
62 changes: 0 additions & 62 deletions code/unittest/makefile

This file was deleted.

File renamed without changes.
File renamed without changes.

0 comments on commit 298bcd3

Please sign in to comment.