Skip to contentSkip to conversation

rtla/tests: Add unit tests for actions module

PATCH New Tomas Glozar 1 participant 1 message Apr 24

Subsystems (2)
lore
Share & tools
lore

Tomas Glozar

author maintainer
#0 lore raw

PATCH 1/1 rtla/tests: Add unit tests for actions module

Add unit tests covering all functions in the actions module, including both valid and invalid inputs and all action types, except for actions_perform(), where only shell and continue actions are tested.

To support testing multiple modules, the unit test build was modified so that it links the entire rtla-in.o file. For this to work, the main() function in rtla.c was declared weak, so that the unit test main is able to override it.

Other included minor changes to unit tests are:

- Make unit test output verbose to show which tests are being run, now that we have more than 3 tests.
- Add unit_tests file to .gitignore.
- Split unit test sources to one file per test suite, and keep only main() function in unit_tests.c.
- Fix Makefile dependencies so that "make unit-tests" will rebuild the binary with the changes in the commit.

Also with the linking the entire rtla-in.o file, it now has rtla's nr_cpus symbol, so the declaration in utils unit tests is made extern.

Assisted-by Composer:composer-2-fast
---
 tools/tracing/rtla/.gitignore               |   1 +
 tools/tracing/rtla/src/rtla.c               |   3 +
 tools/tracing/rtla/tests/unit/Build         |   3 +-
 tools/tracing/rtla/tests/unit/Makefile.unit |   6 +-
 tools/tracing/rtla/tests/unit/actions.c     | 380 ++++++++++++++++++++
 tools/tracing/rtla/tests/unit/unit_tests.c  | 107 +-----
 tools/tracing/rtla/tests/unit/utils.c       | 106 ++++++
 7 files changed, 502 insertions(+), 104 deletions(-)
 create mode 100644 tools/tracing/rtla/tests/unit/actions.c
 create mode 100644 tools/tracing/rtla/tests/unit/utils.c
tools/tracing/rtla/.gitignore +1 -0
index 4d39d64ac08c..231fb8d67f97 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 rtla
 rtla-static
+unit_tests
 fixdep
 feature
 FEATURE-DUMP
tools/tracing/rtla/src/rtla.c +3 -0
index 7635c70123ab..3398250076ea 100644
@@ -61,6 +61,9 @@ int run_command(int argc, char **argv, int start_position)
 	return 1;
 }
 
+/* Set main as weak to allow overriding it for building unit test binary */
+#pragma weak main
+
 int main(int argc, char *argv[])
 {
 	int retval;
tools/tracing/rtla/tests/unit/Build +2 -1
index 5f1e531ea8c9..2749f4cf202a 100644
@@ -1,2 +1,3 @@
+unit_tests-y += utils.o
+unit_tests-y += actions.o
 unit_tests-y += unit_tests.o
-unit_tests-y +=../../src/utils.o
tools/tracing/rtla/tests/unit/Makefile.unit +3 -3
index 2088c9cc3571..bacb00164e46 100644
@@ -3,10 +3,10 @@
 UNIT_TESTS := $(OUTPUT)unit_tests
 UNIT_TESTS_IN := $(UNIT_TESTS)-in.o
 
-$(UNIT_TESTS): $(UNIT_TESTS_IN)
-	$(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $^ -lcheck
+$(UNIT_TESTS): $(UNIT_TESTS_IN) $(RTLA_IN)
+	$(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $^ $(EXTLIBS) -lcheck
 
-$(UNIT_TESTS_IN):
+$(UNIT_TESTS_IN): fixdep
 	make $(build)=unit_tests
 
 unit-tests: FORCE
tools/tracing/rtla/tests/unit/actions.c new file +380 -0

380 lines not on this page · raw message

tools/tracing/rtla/tests/unit/unit_tests.c +7 -100

122 lines not on this page · raw message

tools/tracing/rtla/tests/unit/utils.c new file +106 -0

106 lines not on this page · raw message

Signature · 1 line
2.53.0