summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Peplin <chris.peplin@rhubarbtech.com>2014-01-03 12:37:53 -0500
committerChristopher Peplin <chris.peplin@rhubarbtech.com>2014-01-03 12:37:53 -0500
commitca2035c4a4d935dd41f0feb7782d62335ca0b003 (patch)
tree8299e001b4b7ca20b9e46c78a289f02120f1652b
parent64af0554cb8c60f56bf2c1fa5cd59b9c2c5758ff (diff)
Compile with coverage calculation, put objects in a subdir.
-rw-r--r--.gitignore2
-rw-r--r--Makefile34
2 files changed, 28 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore
index b4225c09..96a3694f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,5 @@
.DS_Store
*~
*.bin
+*.gcno
+build
diff --git a/Makefile b/Makefile
index 5d757846..f44f8cd9 100644
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,11 @@
CC = gcc
INCLUDES = -Isrc -Ideps/bitfield-c/src
-CFLAGS = $(INCLUDES) -c -w -Wall -Werror -g -ggdb -std=c99
-LDFLAGS =
+CFLAGS = $(INCLUDES) -c -w -Wall -Werror -g -ggdb -std=gnu++0x -coverage
+LDFLAGS = -coverage -lm
LDLIBS = -lcheck
TEST_DIR = tests
+TEST_OBJDIR = build
# Guard against \r\n line endings only in Cygwin
OSTYPE := $(shell uname)
@@ -15,24 +16,41 @@ ifneq ($(OSTYPE),Darwin)
endif
endif
+LIBS_PATH = deps
SRC = $(wildcard src/**/*.c)
SRC += $(wildcard deps/bitfield-c/src/**/*.c)
-OBJS = $(SRC:.c=.o)
+OBJS = $(patsubst %,$(TEST_OBJDIR)/%,$(SRC:.c=.o))
TEST_SRC = $(wildcard $(TEST_DIR)/test_*.c)
-TESTS=$(patsubst %.c,%.bin,$(TEST_SRC))
+TESTS=$(patsubst %.c,$(TEST_OBJDIR)/%.bin,$(TEST_SRC))
TEST_SUPPORT_SRC = $(TEST_DIR)/common.c
-TEST_SUPPORT_OBJS = $(TEST_SUPPORT_SRC:.c=.o)
+TEST_SUPPORT_OBJS = $(patsubst %,$(TEST_OBJDIR)/%,$(TEST_SUPPORT_SRC:.c=.o))
all: $(OBJS)
test: $(TESTS)
@set -o $(TEST_SET_OPTS) >/dev/null 2>&1
@export SHELLOPTS
- @sh runtests.sh $(TEST_DIR)
+ @sh runtests.sh $(TEST_OBJDIR)/$(TEST_DIR)
-$(TEST_DIR)/%.bin: $(TEST_DIR)/%.o $(OBJS) $(TEST_SUPPORT_OBJS)
+COVERAGE_INFO_FILENAME = coverage.info
+COVERAGE_INFO_PATH = $(TEST_OBJDIR)/$(COVERAGE_INFO_FILENAME)
+coverage:
+ @lcov --base-directory . --directory src --zerocounters -q
+ @make clean
+ @make test
+ @lcov --base-directory . --directory $(TEST_OBJDIR) -c -o $(TEST_OBJDIR)/coverage.info
+ @lcov --remove $(COVERAGE_INFO_PATH) "$(LIBS_PATH)/bitfield-c/*" -o $(COVERAGE_INFO_PATH)
+ @genhtml -o $(TEST_OBJDIR)/coverage -t "isotp-c test coverage" --num-spaces 4 $(COVERAGE_INFO_PATH)
+ @$(BROWSER) $(TEST_OBJDIR)/coverage/index.html
+ @echo "$(GREEN)Coverage information generated in $(TEST_OBJDIR)/coverage/index.html.$(COLOR_RESET)"
+
+$(TEST_OBJDIR)/%.o: %.c
+ @mkdir -p $(dir $@)
+ $(CC) $(CFLAGS) $(CC_SYMBOLS) $(INCLUDES) -o $@ $<
+
+$(TEST_OBJDIR)/%.bin: $(TEST_OBJDIR)/%.o $(OBJS) $(TEST_SUPPORT_OBJS)
@mkdir -p $(dir $@)
$(CC) $(LDFLAGS) $(CC_SYMBOLS) $(INCLUDES) -o $@ $^ $(LDLIBS)
clean:
- rm -rf **/*.o $(TEST_DIR)/*.bin
+ rm -rf $(TEST_OBJDIR)