Skip to content

Commit

Permalink
Upgrade test/Makefile to the 21st century
Browse files Browse the repository at this point in the history
  • Loading branch information
babelouest committed Jun 2, 2021
1 parent eb7c578 commit 2c2cd0b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
31 changes: 20 additions & 11 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,32 @@ CC=gcc
CFLAGS+=-Wall -D_REENTRANT -DDEBUG -g -O0 -I$(INCLUDE_LOCATION) $(CPPFLAGS)
YDER_LOCATION=../src
INCLUDE_LOCATION=../include
LIBS=-lc -lorcania -lyder $(shell pkg-config --libs check) -L$(YDER_LOCATION)
LDFLAGS=-lc -lorcania -lyder $(shell pkg-config --libs check) -L$(YDER_LOCATION)
TARGET=yder_test
VALGRIND_COMMAND=valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all
VERBOSE=0
MEMCHECK=0

all: test

clean:
rm -f *.o yder_test valgrind.txt
rm -f *.o $(TARGET) *.log valgrind-*.txt

libyder.so:
cd $(YDER_LOCATION) && $(MAKE) debug
$(YDER_LIBRARY): $(YDER_LOCATION)/yder.c
cd $(YDER_LOCATION) && $(MAKE) debug $*

yder_test: yder_test.c
$(CC) $(CFLAGS) yder_test.c -o yder_test $(LIBS)
%: $(YDER_LIBRARY) %.c
$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS)

test_yder_test: libyder.so yder_test
LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./yder_test
test: $(YDER_LIBRARY) $(TARGET) test_yder_test

test: test_yder_test
check: test

memcheck: yder_test
LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all ./yder_test 2>valgrind.txt
test_%: % $(YDER_LIBRARY)
@if [ "$(VERBOSE)" = "0" ] && [ "$(MEMCHECK)" = "0" ]; then \
LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./run_test.sh ./$^; \
elif [ "$(MEMCHECK)" = "0" ]; then \
LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./$^ ; \
else \
LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} $(VALGRIND_COMMAND) ./$^ 2>valgrind-$@.txt; \
fi
27 changes: 27 additions & 0 deletions test/run_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

printf_new() {
str=$1
num=$2
v=$(printf "%-${num}s" "$str")
printf "${v// / }"
}

RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
COMMAND=$1
CHRLEN=${#COMMAND}
NBSP=$((32-$CHRLEN))

printf "Run $1"
printf_new " " $NBSP

$1 $2 $3 $4 $5 $6 $7 $8 $9 1>$1.log 2>&1

if [ $? -ne 0 ]
then
printf "${RED}FAIL${NC}\n"
else
printf "${GREEN}SUCCESS${NC}\n"
fi

0 comments on commit 2c2cd0b

Please sign in to comment.