Reputation: 77
I would like a Makefile variable to hold a list of tests but run each test with a different flag and have the ability to run all tests or selectively one from the command line. Here's what I have so far and I am not sure how to add more tests but prevent creating individual variables for each test. In the example below I can say make all or make run_tests TESTS=block_test_A to either run all tests or a specific test. This works but if I were to add another 10 tests I would like to modify only TESTS string and add them there instead of adding TEST4, TEST5 and so on. Is there a clever way to make a loop that can parse the list of tests in TESTS and create the variables. I tried a couple of variations but couldnt get it to work. sim_design is target not shown that will execute the compile/sim using the values in the Makefile variables SIM_FLAGS and SIM_LOG. Thanks.
TESTS := block_test_A block_test_B block_test_C
TEST1 := $(word 1, $(TESTS))
$(TEST1) : SIM_FLAGS:= "$(SIM_FLAGS) -top $(TEST1)"
$(TEST1) : SIM_LOG:= "logs/$(TEST1).log"
TEST2 := $(word 2, $(TESTS))
$(TEST2) : SIM_FLAGS:= "$(SIM_FLAGS) -top $(TEST2)"
$(TEST2) : SIM_LOG:= "logs/$(TEST2).log"
TEST3 := $(word 3, $(TESTS))
$(TEST3) : SIM_FLAGS:= "$(SIM_FLAGS) -top $(TEST3)"
$(TEST3) : SIM_LOG:= "logs/$(TEST3).log"
$(TESTS):
$(shell mkdir -p logs)
@(echo Running TEST $@ with SIM_FLAGS=$(SIM_FLAGS) SIM_LOG=$(SIM_LOG))
$(MAKE) sim_design SIM_FLAGS=$(SIM_FLAGS) SIM_LOG=$(SIM_LOG)
run_tests: $(TESTS)
all:
@(echo Running Regression on $(DESIGN_TOP) with following list of tests $(TESTS))
@(echo To run a single test generating a dump use: make run_tests TESTS=\"valid_test_name\" REGRESS=0)
$(MAKE) run_tests REGRESS=1
Upvotes: 1
Views: 233
Reputation: 101041
This seems like exactly what automatic variables were created for...?
What's wrong with this:
TESTS := block_test_A block_test_B block_test_C
SIM_FLAGS += -top $@
SIM_LOG = logs/[email protected]
$(TESTS):
@mkdir -p logs
@echo Running TEST $@ with SIM_FLAGS=$(SIM_FLAGS) SIM_LOG=$(SIM_LOG)
$(MAKE) sim_design SIM_FLAGS="$(SIM_FLAGS)" SIM_LOG="$(SIM_LOG)"
Other things:
shell
function inside a recipe.echo
into a subshell with (...)
Upvotes: 1