From: Johnny Richard <johnny@johnnyrichard.com>
To: ~johnnyrichard/olang-devel@lists.sr.ht
Cc: Johnny Richard <johnny@johnnyrichard.com>
Subject: [PATCH olang v1 2/2] tests: build: add parallelization support for unit tests
Date: Sat, 21 Sep 2024 23:02:49 +0200 [thread overview]
Message-ID: <20240921210512.1100242-3-johnny@johnnyrichard.com> (raw)
In-Reply-To: <20240921210512.1100242-1-johnny@johnnyrichard.com>
Removes inline shell script and enable test execution by target on make.
Now we should be able to execute tests with more jobs (make -j<n-of-jobs>)
Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
---
Makefile | 4 ++--
tests/unit/Makefile | 40 ++++++++++++++++++----------------------
2 files changed, 20 insertions(+), 24 deletions(-)
diff --git a/Makefile b/Makefile
index 2b65f96..83c88a2 100644
--- a/Makefile
+++ b/Makefile
@@ -94,8 +94,8 @@ check-execute:
$(MAKE)
$(MAKE) -C tests/execute/
-.PHONY: unit-test
-unit-test:
+.PHONY: check-unit
+check-unit:
$(MAKE)
$(MAKE) -C tests/unit/
diff --git a/tests/unit/Makefile b/tests/unit/Makefile
index 783225c..686938f 100644
--- a/tests/unit/Makefile
+++ b/tests/unit/Makefile
@@ -1,33 +1,29 @@
-SRCS := $(wildcard *_test.c)
-OBJS := $(patsubst %_test.c, %_test.o, $(SRCS))
-SUBJECT_OBJS := $(filter-out ../../build/main.o, $(wildcard ../../build/*.o))
-CFLAGS := -I../../src -I../shared
-TESTS := $(patsubst %_test.c, %_test, $(SRCS))
-EXEC_TESTS := $(patsubst %_test, ./%_test, $(TESTS))
-MUNIT_SRC := ../shared/munit.c
-MUNIT := ./munit.o
+SRCS := $(wildcard *.c)
+DEP_OBJS := $(filter-out ../../build/main.o, $(wildcard ../../build/*.o))
+CFLAGS := -I../../src -I../shared
+TESTS := $(patsubst %.c, %.bin, $(SRCS))
+RUN_TESTS := $(patsubst %.bin, %.run, $(TESTS))
+MUNIT_SRC := ../shared/munit.c
+MUNIT := ./munit.o
-.PHONY: all
-all: $(MUNIT) $(TESTS)
- @for file in $(EXEC_TESTS); do \
- ./"$$file"; \
- done
+.PHONY: all clean format format-fix
+all: $(RUN_TESTS)
+
+%.bin: %.c $(MUNIT)
+ @$(CC) $(CFLAGS) $(MUNIT) $(DEP_OBJS) $< -o $@
+
+%.run: %.bin
+ @./$<
-.PHONY: clean
clean:
- $(RM) *.o *_test
- $(RM) -rfv lib
+ @$(RM) *.o *.bin
+ @$(RM) -rfv lib
-.PHONY: format
format: $(SRCS)
clang-format --dry-run --Werror $?
-.PHONY: format-fix
format-fix: $(SRCS)
clang-format -i $?
-%_test: $(MUNIT) $(SUBJECT_OBJS) %_test.c
- $(CC) $? $(CFLAGS) -o $@
-
$(MUNIT):
- $(CC) -c $(MUNIT_SRC) $(CFLAGS) -o $(MUNIT)
+ @$(CC) -c $(MUNIT_SRC) $(CFLAGS) -o $(MUNIT)
--
2.46.0
next prev parent reply other threads:[~2024-09-21 21:05 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-21 21:02 [PATCH olang v1 0/2] tests: build: improve makefile for tests Johnny Richard
2024-09-21 21:02 ` [PATCH olang v1 1/2] tests: build: enhance compiler functional tests Johnny Richard
2024-09-21 22:11 ` [PATCH olang v1 1/2] tests: build: enhance compiler functional test Carlos Maniero
2024-09-21 21:02 ` Johnny Richard [this message]
2024-09-21 21:05 ` [olang/patches/.build.yml] build success builds.sr.ht
2024-09-21 22:30 ` [PATCH olang v1 2/2] tests: build: add parallelization support for unit tests Carlos Maniero
2024-09-22 15:23 ` [PATCH olang v1 0/2] tests: build: improve makefile for tests Johnny Richard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240921210512.1100242-3-johnny@johnnyrichard.com \
--to=johnny@johnnyrichard.com \
--cc=~johnnyrichard/olang-devel@lists.sr.ht \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.johnnyrichard.com/olang.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox