Skip to content

Commit

Permalink
tests: Build tests binary by using standard build system machinery.
Browse files Browse the repository at this point in the history
This fixes the build under OS X and also allows the tests to cover
all oscam functionality (once the tests are written of course).

Note that the binary that build by `make tests` now would be called
`tests.bin` (previously it was called `tests`). You can override
that name using an undocumented TESTS_BIN `make` parameter, so
`make tests TESTS_BIN=blah` would build the tests binary called
`blah`.

git-svn-id: http://streamboard.de.vu/svn/oscam/trunk@10511 4b0bc96b-bc66-0410-9d44-ebda105a78c1
  • Loading branch information
gfto committed Feb 13, 2015
1 parent 7ab0d9a commit a5c55a4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -13,4 +13,5 @@ Distribution/list_smargo-*
webif/is_defined.txt

# Testing program
tests
tests.bin
tests.bin.debug
27 changes: 15 additions & 12 deletions Makefile
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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\
Expand Down
2 changes: 1 addition & 1 deletion README.build
Expand Up @@ -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):
Expand Down
12 changes: 12 additions & 0 deletions oscam.c
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions tests.c
Expand Up @@ -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 =
Expand Down Expand Up @@ -234,6 +234,4 @@ int main(void)
},
};
run_parser_test(&ftab_test);

return 0;
}

0 comments on commit a5c55a4

Please sign in to comment.