builder

package builder
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/builder

commit efc83749dd27823f977be15675ba54420a767226
parent 574653e874ac1fb9976090a308eacf9034406851
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Tue, 24 Jan 2017 19:40:19 +0100

Add(Coverage tests)

Diffstat:
MMakefile | 13+++++++++++--
Minc/builder.h | 12++++++++++++
Mtests/Makefile | 2+-
Mtests/main.c | 32+++++++++++++++++++++++++++++---
Atests/test.h | 16++++++++++++++++
5 files changed, 69 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile @@ -29,18 +29,27 @@ MAINTAINER = Jules HEZARD <hezardj@gmail.com> all: $(NAME) -$(NAME): $(OBJS) lib +$(NAME): $(OBJS) make -C lib/ $(CC) $(CFLAGS) $(OBJS) -o $(NAME) $(LIB) $(LFLAGS) -check: +check: all make -C tests check +coverage: + $(MAKE) fclean all CFLAGS="-Wall -Wextra -Werror -Wno-unused-result -Iinc -Ilib/inc -std=c99 -g -O0 -coverage -lgcov" + make -C tests re check + gcov -o src/ $(SRCS) + doc: doxygen docs/doxyfile clean: rm -f $(OBJS) + rm -f *.gcov + rm -f src/*.gcno + rm -f src/*.gcda + fclean: clean rm -f $(NAME) diff --git a/inc/builder.h b/inc/builder.h @@ -13,6 +13,18 @@ #ifndef BUILDER_H # define BUILDER_H +#ifndef NAME +# define NAME "builder_coverage" +#endif + +#ifndef VERSION +# define VERSION "coverage" +#endif + +#ifndef MAINTAINER +# define MAINTAINER "morphux@morphux.org" +#endif + # define PID_FILE "/var/run/"NAME".pid" # define LOG_FILE "/var/log/"NAME".log" diff --git a/tests/Makefile b/tests/Makefile @@ -1,6 +1,6 @@ NAME = test CC = gcc -CFLAGS = -Wall -Wextra -g -O3 -I../lib/inc -lmorphux +CFLAGS = -Wall -Wextra -Wno-unused-result -g -O3 -I../lib/inc -lmorphux SRCS = $(wildcard *.c) OBJS = $(SRCS:%.c=%.o) diff --git a/tests/main.c b/tests/main.c @@ -1,16 +1,42 @@ -#include <morphux.h> +#include "test.h" TEST(main) { - int i = 1; + int st, fd[2]; + pid_t pid; - TEST_ASSERT(i == 1, "Nope"); + pipe(fd); + if ((pid = fork()) == 0) { + DUP_ALL_OUTPUTS(fd); + execl(BIN, BIN, "--help", NULL); + exit(1); + } else { + WAIT_AND_CLOSE(pid, st, fd); + } return TEST_SUCCESS; } +TEST(main2) { + int st, fd[2]; + pid_t pid; + + pipe(fd); + if ((pid = fork()) == 0) { + DUP_ALL_OUTPUTS(fd); + execl(BIN, BIN, NULL); + exit(1); + } else { + WAIT_AND_CLOSE(pid, st, fd); + } + return TEST_SUCCESS; + +} + + int main(void) { u32_t ret; reg_test("main", main); + reg_test("main", main2); m_info("Beginning tests...\n"); ret = test_all(); diff --git a/tests/test.h b/tests/test.h @@ -0,0 +1,16 @@ +#ifndef TEST_H +# define TEST_H + +# include <morphux.h> +# include <unistd.h> +# include <stdlib.h> +# include <sys/types.h> +# include <sys/wait.h> +# include <errno.h> + +# define DUP_ALL_OUTPUTS(name) dup2(name[1], 1); dup2(name[1], 2); close(name[1]); +# define WAIT_AND_CLOSE(pid, status, fd) pid = waitpid(pid, &status, 0); close(fd[1]); + +# define BIN "../builder" + +#endif /* TEST_H */