diff --git a/.gitignore b/.gitignore index 3306c9dd13..9182d5c826 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ Distribution/list_smargo-* webif/is_defined.txt # Testing program -tests +tests.bin +tests.bin.debug diff --git a/Makefile b/Makefile index db2dece86f..75a3c4cb60 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ SHELL = /bin/sh .SUFFIXES: .SUFFIXES: .o .c -.PHONY: all help README.build README.config simple default debug config menuconfig allyesconfig allnoconfig defconfig clean distclean +.PHONY: all tests help README.build README.config simple default debug config menuconfig allyesconfig allnoconfig defconfig clean distclean VER := $(shell ./config.sh --oscam-version) SVN_REV := $(shell ./config.sh --oscam-revision) @@ -190,6 +190,7 @@ OBJDIR := $(BUILD_DIR)/$(TARGET) -include $(OBJDIR)/config.mak OSCAM_BIN := $(BINDIR)/oscam-$(VER)$(SVN_REV)-$(subst cygwin,cygwin.exe,$(TARGET)) +TESTS_BIN := tests.bin LIST_SMARGO_BIN := $(BINDIR)/list_smargo-$(VER)$(SVN_REV)-$(subst cygwin,cygwin.exe,$(TARGET)) # Build list_smargo-.... only when WITH_LIBUSB build is requested. @@ -322,6 +323,10 @@ SRC-y += oscam-work.c SRC-y += oscam.c # config.c is automatically generated by config.sh in OBJDIR SRC-y += config.c +ifdef BUILD_TESTS +SRC-y += tests.c +override STD_DEFS += -DBUILD_TESTS=1 +endif SRC := $(SRC-y) OBJ := $(addprefix $(OBJDIR)/,$(subst .c,.o,$(SRC))) @@ -384,15 +389,13 @@ $(OBJDIR)/%.o: %.c Makefile -include $(subst .o,.d,$(OBJ)) -TESTS_SRC += oscam-array.c -TESTS_SRC += oscam-conf-mk.c -TESTS_SRC += oscam-conf-chk.c -TESTS_SRC += oscam-string.c -TESTS_SRC += oscam-llist.c - -tests: Makefile globals.h $(subst .c,.h,$(TESTS_SRC)) $(TESTS_SRC) tests.c - $(SAY) "BUILD $@" - $(Q)$(CC) $(STD_DEFS) $(CC_OPTS) $(CC_WARN) $(CFLAGS) $(LDFLAGS) $(TESTS_SRC) tests.c -o $@ +tests: + @-$(MAKE) --no-print-directory BUILD_TESTS=1 OSCAM_BIN=$(TESTS_BIN) + @-touch oscam.c +# The above is really hideous hack :-) If we don't force oscam.c recompilation +# after we've build the tests binary, the next "normal" compilation would fail +# because there would be no run_tests() function. So the touch is there to +# ensure oscam.c would be recompiled. config: $(SHELL) ./config.sh --gui @@ -412,7 +415,7 @@ defconfig: @-$(SHELL) ./config.sh --restore clean: - @-for FILE in $(BUILD_DIR)/* tests; do \ + @-for FILE in $(BUILD_DIR)/* $(TESTS_BIN) $(TESTS_BIN).debug; do \ echo "RM $$FILE"; \ rm -rf $$FILE; \ done @@ -688,7 +691,7 @@ OSCam build system documentation\n\ make static-ssl - Builds OSCam with SSL support linked statically\n\ \n\ Developer targets:\n\ - make tests - Builds 'tests' binary\n\ + make tests - Builds '$(TESTS_BIN)' binary\n\ \n\ Examples:\n\ Build OSCam for SH4 (the compilers are in the path):\n\ diff --git a/README.build b/README.build index aa87669756..60db0e5cfb 100644 --- a/README.build +++ b/README.build @@ -243,7 +243,7 @@ OSCam build system documentation make static-ssl - Builds OSCam with SSL support linked statically Developer targets: - make tests - Builds 'tests' binary + make tests - Builds 'tests.bin' binary Examples: Build OSCam for SH4 (the compilers are in the path): diff --git a/oscam.c b/oscam.c index bd2c80c01d..37bac7bcf9 100644 --- a/oscam.c +++ b/oscam.c @@ -1351,8 +1351,20 @@ static void detect_valgrind(void) #endif } +#ifdef BUILD_TESTS +extern void run_all_tests(void); +__attribute__ ((noreturn)) static void run_tests(void) +{ + run_all_tests(); + exit(0); +} +#else +static void run_tests(void) { } +#endif + int32_t main(int32_t argc, char *argv[]) { + run_tests(); int32_t i, j; prog_name = argv[0]; struct timespec start_ts; diff --git a/tests.c b/tests.c index 5f2e0c4be1..b1aff97231 100644 --- a/tests.c +++ b/tests.c @@ -72,7 +72,7 @@ static void run_parser_test(struct test_type *t) t->clear_fn(t->data_c); } -int main(void) +void run_all_tests(void) { ECM_WHITELIST ecm_whitelist, ecm_whitelist_c; struct test_type ecm_whitelist_test = @@ -234,6 +234,4 @@ int main(void) }, }; run_parser_test(&ftab_test); - - return 0; }