From e9d9929074084c121f09460e3024efea32ce7504 Mon Sep 17 00:00:00 2001 From: Costin Lupu Date: Mon, 16 Dec 2019 15:47:50 +0200 Subject: [PATCH] tests: Build tests The Ruby unit testing depends on both extensions and encodings. We currently add support for running only the time and file tests. Enabling the rest of the tests is subject of further work. Signed-off-by: Costin Lupu Reviewed-by: Stefan Teodorescu --- Config.uk | 7 +++++++ Makefile.uk | 42 +++++++++++++++++++++++++++++++++++++++++ generated/ext/extinit.c | 6 ++++++ 3 files changed, 55 insertions(+) diff --git a/Config.uk b/Config.uk index 56f2b6b..e47eee3 100644 --- a/Config.uk +++ b/Config.uk @@ -128,4 +128,11 @@ config LIBRUBY_ENC depends on !LIBRUBY_MINI default y +config LIBRUBY_TEST + bool "Enable unit testing" + depends on !LIBRUBY_MINI + depends on LIBRUBY_EXT + depends on LIBRUBY_ENC + default y + endif diff --git a/Makefile.uk b/Makefile.uk index 84c9aac..ef258be 100644 --- a/Makefile.uk +++ b/Makefile.uk @@ -41,6 +41,7 @@ $(eval $(call addlib_s,libruby,$(CONFIG_LIBRUBY))) $(eval $(call addlib_s,libruby_ext,$(CONFIG_LIBRUBY_EXT))) $(eval $(call addlib_s,libruby_enc,$(CONFIG_LIBRUBY_ENC))) +$(eval $(call addlib_s,libruby_test,$(CONFIG_LIBRUBY_TEST))) ################################################################################ # Sources @@ -542,6 +543,31 @@ LIBRUBY_ENC_SRCS-y += $(LIBRUBY_SRC)/enc/trans/single_byte.c LIBRUBY_ENC_SRCS-y += $(LIBRUBY_SRC)/enc/trans/utf8_mac.c LIBRUBY_ENC_SRCS-y += $(LIBRUBY_SRC)/enc/trans/utf_16_32.c +################################################################################ +# Unit testing +################################################################################ +LIBRUBY_TEST_CFLAGS-y += $(LIBRUBY_CINCLUDES-y) +LIBRUBY_TEST_CFLAGS-y += $(LIBRUBY_SUPPRESS_FLAGS) +LIBRUBY_TEST_CFLAGS-y += -DRUBY_EXTCONF_H=\"extconf.h\" + +$(LIBRUBY_SRC)/ext/-test-/file/init_file.c: $(LIBRUBY_SRC)/ext/-test-/file/init.c + ln -s $< $@ +LIBRUBY_TEST_SRCS-y += $(LIBRUBY_SRC)/ext/-test-/file/init_file.c +LIBRUBY_TEST_INIT_FILE_FLAGS-y += -I$(LIBRUBY_SRC)/ext/-test-/file +LIBRUBY_TEST_SRCS-y += $(LIBRUBY_SRC)/ext/-test-/file/fs.c +LIBRUBY_TEST_FS_FLAGS-y += -I$(LIBRUBY_SRC)/ext/-test-/file +LIBRUBY_TEST_SRCS-y += $(LIBRUBY_SRC)/ext/-test-/file/stat.c +LIBRUBY_TEST_STAT_FLAGS-y += -I$(LIBRUBY_SRC)/ext/-test-/file + +$(LIBRUBY_SRC)/ext/-test-/time/init_time.c: $(LIBRUBY_SRC)/ext/-test-/time/init.c + ln -s $< $@ +LIBRUBY_TEST_SRCS-y += $(LIBRUBY_SRC)/ext/-test-/time/init_time.c +LIBRUBY_TEST_INIT_TIME_FLAGS-y += -I$(LIBRUBY_SRC)/ext/-test-/time +LIBRUBY_TEST_SRCS-y += $(LIBRUBY_SRC)/ext/-test-/time/leap_second.c +LIBRUBY_TEST_LEAP_SECOND_FLAGS-y += -I$(LIBRUBY_SRC)/ext/-test-/time +LIBRUBY_TEST_SRCS-y += $(LIBRUBY_SRC)/ext/-test-/time/new.c +LIBRUBY_TEST_NEW_FLAGS-y += -I$(LIBRUBY_SRC)/ext/-test-/time + ################################################################################ # Prepare rules ################################################################################ @@ -562,3 +588,19 @@ $(LIBRUBY_BUILD)/.build: $(LIBRUBY_BUILD)/.configured UK_PREPARE += $(LIBRUBY_BUILD)/.build +ifeq ($(CONFIG_LIBRUBY_TEST),y) +# Customize config: configure stack size +$(APP_BASE)/.config.orig: $(APP_BASE)/.config + $(call verbose_cmd,CONFIG,libruby: $(notdir $@), \ + cp $(APP_BASE)/.config $@ && \ + sed -i 's/^CONFIG_STACK_SIZE_PAGE_ORDER=.*$$/CONFIG_STACK_SIZE_PAGE_ORDER=10/g' $(APP_BASE)/.config) + +# We need a bigger stack for tests +LIBRUBY_TEST_PREPARED_DEPS = \ + $(APP_BASE)/.config.orig \ + +$(LIBRUBY_TEST_BUILD)/.prepared: $(LIBRUBY_TEST_PREPARED_DEPS) + +UK_PREPARE += $(LIBRUBY_TEST_BUILD)/.prepared +endif + diff --git a/generated/ext/extinit.c b/generated/ext/extinit.c index 7bc4196..1a5ba7e 100644 --- a/generated/ext/extinit.c +++ b/generated/ext/extinit.c @@ -100,4 +100,10 @@ void Init_ext(void) #if CONFIG_LIBRUBY_EXT_SDBM init(Init_sdbm, "sdbm"); #endif + +#if CONFIG_LIBRUBY_TEST + /* TODO add more tests */ + init(Init_file, "-test-/file"); + init(Init_time, "-test-/time"); +#endif } -- 2.39.5