I use WSL2 from vscode to develop and build, but I am a novice linux user. I am currently developing in C and using unity for unit testing and dmalloc to check for correct memory usage.
Following the dmalloc documentation here, once the library has been installed, an alias must be created for dmalloc so that it can be configured from the command line. I use this option in the .bashrc file to create the alias:
function dmalloc { eval `command dmalloc -b $*`; }
Before running a program compiled with the dmalloc library, dmalloc must be told to place the results in a log file as follows:
dmalloc -l logfile -i 100 low
This all works well when typing the commands into the shell. However, my unit tests are run one by one from a make file. I would like dmalloc to output its results to a specific logfile for each unit test. However, since an alias is used to configure dmalloc and make does not expand aliases, dmalloc cannot be configured before each unit test is run.
Here is an example of how I would like to run the unit tests from my make file:
DIR_BUILD_TESTS := $(DIR_BUILD)tests/
TXT_TESTS := $(patsubst $(DIR_BUILD_TESTS)%.o,$(DIR_BUILD_TESTS)%.txt,$(OBJ_TESTS))
test: $(TXT_TESTS)
@echo "-----------------------\nPASSED:\n-----------------------"
@echo "$(PASSED)"
@echo "-----------------------\nIGNORES:\n-----------------------"
@echo "$(IGNORE)"
@echo "-----------------------\nFAILURES:\n-----------------------"
@echo "$(FAIL)"
@echo "DONE"
$(DIR_BUILD_TESTS)%.txt: $(DIR_BUILD_TESTS)%.exe
dmalloc -l $(subst .txt,.log,$@) -i 100 low
-./$< > $@ 2>&1
The default target is "test" which only outputs the results from the unit tests. However, the prerequisites for test are text files containing the test outputs, the rule after test runs each built .exe file and outputs its results to a text file. This was adapted from the makefile example from the unity documentation. As you can see, I would like to configure dmalloc before running each test so that each test has a dmalloc log file associated with it. This does not work though, here is an example of the current output:
dmalloc -l ../../build/debug/tests/testNumberOne.log -i 100 low
export DMALLOC_OPTIONS=debug=0x4e48503,inter=100,log=../../build/debug/tests/testNumberOne.log
./../../build/debug/tests/testNumberOne.exe > ../../build/debug/tests/testNumberOne.txt 2>&1
According to the dmalloc documentation, if "DMALLOC_OPTIONS" displays in the output then the alias did not take effect. This is what we were expecting since we know that make does not expand aliases.
So is there a way to get the functionality which I want?