-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Diego Herrera
committed
Oct 1, 2021
1 parent
19b4bc6
commit 6664dd5
Showing
11 changed files
with
242 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
.DEFAULT_GOAL := all | ||
|
||
|
||
# Include directories | ||
INCDIR := \ | ||
-I.. \ | ||
|
||
SRCDIR=src | ||
BINDIR=bin | ||
OBJDIR=obj | ||
LIBDIR=lib | ||
|
||
CC=gcc | ||
CXX=g++ | ||
CFLAGS =-I$(SRCDIR) $(INCDIR) | ||
CXXFLAGS =-I$(SRCDIR) $(INCDIR) | ||
LDFLAGS =-L$(LIBDIR) | ||
LDLIBS = -lrt | ||
|
||
OUTFILE=dining-philosopher | ||
|
||
EXCDIR := unittest | ||
CODEFILES := $(shell find $(SRCDIR) -type f -not -path "$(EXCDIR)/*") | ||
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)) | ||
|
||
|
||
|
||
|
||
|
||
$(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) | ||
mkdir -p $(BINDIR) | ||
$(CXX) -o $(BINDIR)/$@ $^ $(CFLAGS) $(LDFLAGS) $(LDLIBS) | ||
|
||
# $(OUTFILE): $(OBJFILES) | ||
# mkdir -p $(BINDIR) | ||
# ar rc $(BINDIR)/$@ $^ | ||
# ranlib $(BINDIR)/$@ | ||
|
||
debug: CXXFLAGS += -DDEBUG -O0 -ggdb3 | ||
debug: CFLAGS += -DDEBUG -O0 -ggdb3 | ||
debug: $(OUTFILE) | ||
|
||
rebuild: clean $(OUTFILE) | ||
|
||
.PHONY: all clean | ||
|
||
all: $(OUTFILE) | ||
|
||
clean: | ||
rm -rf $(OBJDIR)/* | ||
rm -rf $(BINDIR)/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include "waiting-state/philosopher.h" | ||
|
||
int main() | ||
{ | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "philosopher.h" | ||
|
||
using namespace WaitingPhilosopher; | ||
|
||
Philosopher::Philosopher() | ||
{ | ||
|
||
} | ||
|
||
bool Philosopher::checkNeighbor() | ||
{ | ||
bool neighborBusy = true; | ||
|
||
return neighborBusy; | ||
} | ||
|
||
void Philosopher::wait() | ||
{ | ||
|
||
} | ||
|
||
void Philosopher::eat() | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef PHILOSOPHER_H_ | ||
#define PHILOSOPHER_H_ | ||
|
||
// #ifdef __cplusplus | ||
// extern "C" { | ||
// #endif | ||
#include <string> | ||
|
||
namespace WaitingPhilosopher | ||
{ | ||
class Philosopher | ||
{ | ||
public: | ||
Philosopher(); | ||
bool checkNeighbor(); | ||
void wait(); | ||
void eat(); | ||
protected: | ||
bool waitingState = true; | ||
|
||
|
||
}; | ||
} | ||
|
||
#endif /* PHILOSOPHER_H_ */ | ||
|
||
// EOF |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
.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)/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <iostream> | ||
#include "gtest/gtest.h" | ||
|
||
using namespace std; | ||
|
||
GTEST_API_ int main(int argc, char **argv) | ||
{ | ||
testing::InitGoogleTest(&argc, argv); | ||
return RUN_ALL_TESTS(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "gtest/gtest.h" | ||
#include <string> | ||
#include "waiting-state/philosopher.h" | ||
|
||
using namespace WaitingPhilosopher; | ||
using namespace std; | ||
|
||
class WaitingPhilosopherTest : public testing::Test | ||
{ | ||
public: | ||
|
||
void SetUp() override { } | ||
void TearDown() override { } | ||
|
||
// Per-test-suite set-up. | ||
// Called before the first test in this test suite. | ||
// Can be omitted if not needed. | ||
static void SetUpTestSuite() | ||
{ | ||
|
||
} | ||
|
||
// Per-test-suite tear-down. | ||
// Called after the last test in this test suite. | ||
// Can be omitted if not needed. | ||
static void TearDownTestSuite() | ||
{ | ||
|
||
} | ||
}; | ||
|
||
|
||
TEST_F(WaitingPhilosopherTest, evenPhilosophers) | ||
{ | ||
Philosopher nietzche; | ||
ASSERT_TRUE(nietzche.checkNeighbor()); | ||
|
||
|
||
} | ||
|