How can I determine if a script is being run by the codegen -test input parameter?

14 views (last 30 days)
I would like to avoid running certain lines of code when runing a script that calls a generated mex file (codegen -test or coder.runTest).
I have a script that builds an entry point function "functionA"
codegen -config cfg functionA -args ARGS -test testScript
And I would like to avoid running certain lines of code within testScript only when running the test with codegen (i.e. in the codegen command or with coder.runTest). Is this possible, and if so how.
My first instinct was'MATLAB'), isdeployed, ismcc, however none of these return a true flag when running in test mode.

Accepted Answer

Mukund Sankaran
Mukund Sankaran on 31 Mar 2020
As far as I'm aware, coder.runTest and codegen -test do not support this behavior. Can you please let us know more about your use case, so we can consider supporting this in the future ?
As a workaround, you could perhaps set a global variable outside the test bench, and check the value of the global while running the test bench. Say something like this:
% Entry point function foo
function out = foo(a, b)
out = a + b;
% Test bench foo_tb
function foo_tb()
global tbFlag;
if tbFlag
foo(3, 5);
disp('Do Nothing');
% set global tbFlag
function setGlobalTbFlag(value)
global tbFlag;
tbFlag = value;
% build script
codegen -config cfg foo -args {2,3} -test foo_tb

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!