diff mbox series

[ptest-runner] Makefile: Improvements on rules mainly check (unittest)

Message ID 20250707144350.2013683-1-anibal@limonsoftware.com
State New
Headers show
Series [ptest-runner] Makefile: Improvements on rules mainly check (unittest) | expand

Commit Message

Anibal Limon July 7, 2025, 2:43 p.m. UTC
Commnly we built ptest-runner without unittest, so by default
only build ptest-runner executable (all target).
Move the -pthread flag into common CFLAGS upon.

Add pkg-config and check tests to let know the user this components
are expected to be in the system when build and/or run tests using
check.

Drop redundant tests rule and only keep check rule, if only wanna
build the ptest-runner-test executable can be made explicitly.

```
devel@ls:~/ptest-runner2$ make ptest-runner-test
devel@ls:~/ptest-runner2$ ./ptest-runner-test
Usage: ./ptest-runner-test <-d directory>

```

The check rule stay the same when execute it it builts ptest-runner-test
and execute unittests suite.

```
devel@ls:~/ptest-runner2$ make check
PATH=".:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" ptest-runner-test -d /workspace/ptest-runner2/tests/data
Running suite(s): ptest_list
100%: Checks: 9, Failures: 0, Errors: 0
tests/ptest_list.c:47:P:Core:test_alloc_free:0: Passed
tests/ptest_list.c:55:P:Core:test_add:0: Passed
tests/ptest_list.c:66:P:Core:test_free_all:0: Passed
tests/ptest_list.c:89:P:Core:test_length:0: Passed
tests/ptest_list.c:110:P:Core:test_search:0: Passed
tests/ptest_list.c:143:P:Core:test_remove:0: Passed
tests/ptest_list.c:165:P:Core:test_remove_first:0: Passed
tests/ptest_list.c:188:P:Core:test_remove_last:0: Passed
tests/ptest_list.c:203:P:Core:test_remove_all:0: Passed
Running suite(s): utils
dmesg: read kernel buffer failed: Operation not permitted
XML File './' could not be created. Is a directory.
100%: Checks: 9, Failures: 0, Errors: 0
tests/utils.c:88:P:Core:test_get_available_ptests:0: Passed
tests/utils.c:134:P:Core:test_print_ptests:0: Passed
tests/utils.c:161:P:Core:test_filter_ptests:0: Passed
tests/utils.c:193:P:Core:test_run_ptests:0: Passed
tests/utils.c:224:P:Core:test_run_timeout_duration_ptest:0: Passed
tests/utils.c:254:P:Core:test_run_signal_ptest:0: Passed
tests/utils.c:284:P:Core:test_run_fail_ptest:0: Passed
tests/utils.c:328:P:Core:test_xml_pass:0: Passed
tests/utils.c:338:P:Core:test_xml_fail:0: Passed
```

Signed-off-by: Anibal Limon <anibal@limonsoftware.com>
---
 Makefile | 43 +++++++++++++++++++++++++++----------------
 1 file changed, 27 insertions(+), 16 deletions(-)
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 662ced7..7ad4161 100644
--- a/Makefile
+++ b/Makefile
@@ -17,35 +17,46 @@  endif
 ifeq ($(MEMCHECK), 1)
 CFLAGS+= -DMEMCHECK
 endif
+CFLAGS+= -pthread
 LDFLAGS=
 
 BASE_SOURCES=utils.c ptest_list.c
-SOURCES=main.c $(BASE_SOURCES)
+BASE_OBJECTS=$(BASE_SOURCES:.c=.o)
+SOURCES=main.c
 OBJECTS=$(SOURCES:.c=.o)
 EXECUTABLE=ptest-runner
 
-TEST_SOURCES=tests/main.c tests/ptest_list.c tests/utils.c $(BASE_SOURCES)
+PKGCONFIG_BIN:=pkg-config
+CHECK_LIB:=check
+TEST_SOURCES=tests/main.c tests/ptest_list.c tests/utils.c
 TEST_OBJECTS=$(TEST_SOURCES:.c=.o)
 TEST_EXECUTABLE=ptest-runner-test
-TEST_CFLAGS=$(shell pkg-config --cflags check)
-TEST_LDFLAGS=$(shell pkg-config --libs check)
+TEST_CFLAGS=$(shell $(PKGCONFIG_BIN) --cflags $(CHECK_LIB) 2>/dev/null)
+TEST_LDFLAGS=$(shell $(PKGCONFIG_BIN) --libs $(CHECK_LIB) 2>/dev/null)
 
 TEST_DATA=$(shell echo `pwd`/tests/data)
 
-all: $(SOURCES) $(EXECUTABLE)
-
-$(EXECUTABLE): $(OBJECTS)
-	$(CC) $(LDFLAGS) $(OBJECTS) -pthread -lutil -o $@
-
-tests: $(TEST_SOURCES) $(TEST_EXECUTABLE)
-
-$(TEST_EXECUTABLE): $(TEST_OBJECTS)
-	$(CC) $(LDFLAGS) $(TEST_OBJECTS) -o $@ $(TEST_CFLAGS) $(TEST_LDFLAGS)
+all: $(EXECUTABLE)
 
 check: $(TEST_EXECUTABLE)
-	PATH=.:$(PATH) ./$(TEST_EXECUTABLE) -d $(TEST_DATA)
+	PATH=".:$(PATH)" $(TEST_EXECUTABLE) -d $(TEST_DATA)
 
 clean:
-	rm -rf $(EXECUTABLE) $(OBJECTS) $(TEST_EXECUTABLE) $(TEST_OBJECTS)
+	rm -rf $(BASE_OBJECTS) $(EXECUTABLE) $(OBJECTS) $(TEST_EXECUTABLE) $(TEST_OBJECTS)
+
+$(EXECUTABLE): $(BASE_OBJECTS) $(OBJECTS)
+	$(CC) $(LDFLAGS) $^ -o $@
+
+$(TEST_EXECUTABLE): $(BASE_OBJECTS) $(TEST_OBJECTS)
+ifeq ($(shell command -v $(PKGCONFIG_BIN)),)
+	$(error Please install `$(PKGCONFIG_BIN)`, use to get compilation flags.)
+endif
+ifeq ($(TEST_LDFLAGS),)
+	$(error Please install `$(CHECK_LIB)`, can't get LDFLAGS via pkg-config.)
+endif
+ifeq ($(TEST_CFLAGS),)
+	$(error Please install `$(CHECK_LIB)`, can't get CFLAGS via pkg-config.)
+endif
+	$(CC) $(TEST_CFLAGS) $^ -o $@ $(LDFLAGS) $(TEST_LDFLAGS)
 
-.PHONY: clean tests
+.PHONY: all check clean