Target Language Compiler | ![]() ![]() |
TLC Coverage
The example in the last section used the debugger to detect a problem in one section of the TLC file. Since it is conceivable that a test model does not cover all possible cases, there is a technique that traces the untested cases, the TLC coverage option.
Using the TLC Coverage Option
The TLC coverage option provides an easier way to ascertain that the different code parts (not paths) in your code are exercised. To initiate TLC coverage generation, select Start TLC coverage when generating code from the TLC debugging
category of the Real-Time Workshop pane of the Simulation Parameters dialog box. You can also initiate TLC coverage from the command line switch -dn
in the System target file field, but this is not recommended.
When you initiate TLC coverage, the Target Language Compiler produces a .log
file for every target file (*.tlc
) used. These .log
files are placed in the Real-Time Workshop created project directory for the model. The .log
file contains usage (count) information regarding how many times it encounters each line during execution. Each line includes the number of times it is encountered followed by a colon and followed by the code.
Example .log File
The .log
file for gain.tlc
is gain.log
. It is shown here when used with the simple_log
test model in matlabroot
/toolbox/rtw/rtwdemos/tlctutorial/tlcdebug/
. This file is located in work_directory
/simple_log_grt_rtw/gain.log
:
1: %% $RCSfile: cp_debu5.html,v $ 1: %% $Revision: 1.9 $ 1: %% $Date: 2002/06/19 21:30:21 $ 1: %% 1: %% Copyright 1994-2000 The MathWorks, Inc. 1: %% 1: %% Abstract: Gain block target file 1: %% NOTE: This is different from the file used by Real-Time Workshop to 1: %% implement the Simulink built-in Gain block, and is used here 1: %% only for illustrative purpose 1: 1: %implements Gain "C" 1: 1: %% Function:FcnEliminateUnnecessaryParams==================== 1: %% Abstract: 1: %% Eliminate unnecessary multiplications for following gain cases when 1: %% in-lining parameters: 1: %% Zero: memset in registration routine zeroes output 1: %% Positive One: assign output equal to input 1: %% Negative One: assign output equal to unary minus of input 1: %% 1: %function FcnEliminateUnnecessaryParams(y,u,k) Output 2: %if LibIsEqual(k, "(0.0)") 1: %if ShowEliminatedStatements == 1 1: /* %<y> = %<u> * %<k>; */ 1: %endif 2: %elseif LibIsEqual(k, "(1.0)") 1: %<y> = %<k>; 1: %elseif LibIsEqual(k, "(-1.0)") 0: %<y> = -%<k>; 0: %else 0: %<y> = %<u> * %<k>; 2: %endif 1: %endfunction 1: 1: %% Function: Outputs========================================= 1: %% Abstract: 1: %% Y = U * K 1: %% 1: %function Outputs(block,system) Output 2: /* %<Type> Block: %<Name> */ 2: %warning LOCAL VERSION OF TLC FILE 2: %assign rollVars = ["U","Y", "P"] 2: 2: %roll sigIdx = RollRegions, lcv = RollThreshold, block, "Roller", rollVars 2: %assign y = LibBlockOutputSignal(0, "", lcv, sigIdx) 2: %assign u = LibBlockInputSignal(0, "", lcv, sigIdx) 2: %assign k = LibBlockParameter(Gain, "", lcv, sigIdx) 2: %if InlineParameters == 1 2: %<FcnEliminateUnnecessaryParams(y, u, k)>\ 2: %else 0: %<y> = %<u> * %<k>; 2: %endif 2: %endroll 2: 1: %endfunction 1: 1: %% [EOF] gain.tlc
Analyzing the Results
This structure makes it easy to identify branches not taken and to develop new tests that can exercise unused portions of the target files.
Looking at the gain.log
file, you can see that the code has not been tested with InlineParameters
off and some cases with InlineParameters
have not been exercised. Using this log as a reference and creating models to exercise unexecuted lines, you can make sure that your code is more robust.
![]() | TLC Debugger Command Summary | TLC Profiler | ![]() |