public inbox for ~johnnyrichard/olang-devel@lists.sr.ht
 help / color / mirror / code / Atom feed
From: Johnny Richard <johnny@johnnyrichard.com>
To: ~johnnyrichard/olang-devel@lists.sr.ht
Cc: Johnny Richard <johnny@johnnyrichard.com>
Subject: [PATCH olang v2 3/3] tests: build: add parallelization support for unit tests
Date: Sun, 22 Sep 2024 17:15:56 +0200	[thread overview]
Message-ID: <20240922152119.1214443-4-johnny@johnnyrichard.com> (raw)
In-Reply-To: <20240922152119.1214443-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            |  9 +++------
 tests/unit/Makefile | 40 ++++++++++++++++++----------------------
 2 files changed, 21 insertions(+), 28 deletions(-)

diff --git a/Makefile b/Makefile
index 7dbde3e..3a799ae 100644
--- a/Makefile
+++ b/Makefile
@@ -93,9 +93,8 @@ format-fix: $(SRCS) $(HEADERS)
 check-olc: $(TARGET)
 	$(MAKE) -C tests/olc/
 
-.PHONY: unit-test
-unit-test:
-	$(MAKE)
+.PHONY: check-unit
+check-unit: $(TARGET)
 	$(MAKE) -C tests/unit/
 
 .PHONY: clean
@@ -105,9 +104,7 @@ clean:
 	@rm -rf build/ $(TARGET)
 
 .PHONY: check
-check: check-olc
-	$(MAKE)
-	$(MAKE) -C tests/unit/
+check: check-unit check-olc
 
 .PHONY: docs
 docs:
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


  parent reply	other threads:[~2024-09-22 15:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-22 15:15 [PATCH olang v2 0/3] improve test's makes and compiler binary Johnny Richard
2024-09-22 15:15 ` [PATCH olang v2 1/3] olc: rename 'olang' binary to 'olc' Johnny Richard
2024-09-22 15:15 ` [PATCH olang v2 2/3] tests: build: enhance compiler tests Johnny Richard
2024-09-22 15:15 ` Johnny Richard [this message]
2024-09-23  9:09 ` [PATCH olang v2 0/3] improve test's makes and compiler binary Carlos Maniero
2024-09-23 10:57   ` 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=20240922152119.1214443-4-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