Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "_test/framework"]
path = _test/framework
url = https://github.com/SunDevilRocketry/sdrtf.git
1 change: 1 addition & 0 deletions _test/framework
Submodule framework added at 29ac66
6 changes: 6 additions & 0 deletions _test/math_sdr/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build/
coverage/
results.txt
*.gcda
*.gcno
*.gcov
103 changes: 103 additions & 0 deletions _test/math_sdr/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
################################################################
#
# math_sdr unit tests (based on gcc)
#
################################################################

################################################################
# target
################################################################
TARGET = math_sdr

################################################################
# build variables
################################################################
DEBUG ?= 0
OPT = -Og

################################################################
# paths
################################################################
BUILD_DIR = build
ROOT_DIR = ../..

################################################################
# source
################################################################
TEST_SOURCES = \
test_math_sdr.c

COV_C_SOURCES = \
$(ROOT_DIR)/math_sdr/math_sdr.c

FRAMEWORK_SOURCES = \
$(ROOT_DIR)/_test/framework/src/test_assert.c \
$(ROOT_DIR)/_test/framework/src/test_runner.c

C_SOURCES = $(TEST_SOURCES) $(COV_C_SOURCES) $(FRAMEWORK_SOURCES)

################################################################
# compiler
################################################################
CC = gcc

################################################################
# C flags
################################################################
C_INCLUDES = \
-I. \
-I$(ROOT_DIR)/math_sdr \
-I$(ROOT_DIR)/_test/framework/src

C_DEFS = \
-DUNIT_TEST

CFLAGS = $(C_INCLUDES) $(C_DEFS) $(OPT) -Wall -g

CFLAGS += -Wno-unused-function
CFLAGS += -Wno-unused-variable
CFLAGS += -ftest-coverage
CFLAGS += -fprofile-arcs
ifeq ($(DEBUG), 1)
CFLAGS += -DDEBUG
else
CFLAGS += -DRELBLD
endif

################################################################
# build
################################################################
all: clean $(BUILD_DIR)/$(TARGET)

OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
vpath %.c $(sort $(dir $(C_SOURCES)))

$(BUILD_DIR)/%.o: %.c $(BUILD_DIR)
$(CC) -c $(CFLAGS) $< -o $@

$(BUILD_DIR)/$(TARGET): $(OBJECTS)
$(CC) $(OBJECTS) -o $@ -lgcov -lm

$(BUILD_DIR):
mkdir $@

################################################################
# test
################################################################
test:
@echo THIS TEST MUST BE EXECUTED IN A BASH TERMINAL. CMD/PS do not work.
-rm -fR $(BUILD_DIR)
$(MAKE) all
$(BUILD_DIR)/$(TARGET)
tail -n 7 "results.txt"
mkdir -p coverage
gcovr $(BUILD_DIR) \
--filter $(COV_C_SOURCES) \
--html-details coverage/coverage.html \
--json coverage/coverage.json

################################################################
# clean
################################################################
clean:
-rm -fR $(BUILD_DIR)
8 changes: 8 additions & 0 deletions _test/math_sdr/main.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef TEST_MATH_SDR_MAIN_H
#define TEST_MATH_SDR_MAIN_H

#include <math.h>
#include <stddef.h>
#include <stdint.h>

#endif /* TEST_MATH_SDR_MAIN_H */
Loading