Target Language Compiler    

Code Coverage for Debugging TLC Files

Objective: Learn about Real-Time Workshop's capabilities for checking TLC code coverage. This is useful as a debugging tool when writing TLC code. TLC code coverage is easy to use and indicates whether you've exercised all possible cases for generated code that your TLC file can produce.

Example directory: tlctutorial/codecover

Performing the Tasks

  1. Open the model simple_log.
  2. Select the TLC debugging from the Category pulldown on the Real-Time Workshop page and check the Retain .rtw file and Start TLC coverage when generating code check boxes. This tells Real-Time Workshop to create log files for TLC code coverage. One log file is created for each TLC file used in generating code for the model. This is the block diagram for the simple_log model.
  3. Select Generate code only. Be sure Inline parameters is not selected on the Advanced page. Generate code for the model.

    Now, look in your build directory and observe the filenames with the .log extension (i.e., type: dir *.log). These .log files correspond to the TLC files with .tlc extensions that were used to generate C code for your model.

  1. Open the log file gain.log. Observe the integers 0, 1, 2, ..., n, which indicate how many times the lines of TLC code were exercised. This tool is very useful for debugging custom written TLC files. Aside from TLC files for individual blocks such as gain.tlc, TLC relies on additional files such as blocklib.tlc, genmap.tlc, mdlhdr.tlc, mdlbody.tlc, mdlparam.tlc, mdlvars.tlc, etc.
  2. Select the Inline parameters check box and generate code once again. View gain.log and simple_log.c and pay attention to the model output code for the three outports. Is it clear how the code has changed and why? The generated code is optimized for speed, however, it is not suited for parameter tuning.
  3. You may also try playing with the various parameters, such as changing the source block for subsystem 2 from a discrete to a continuous sine wave, changing Gain3rd from 0 to 1, and seeing how the .log file and the generated C code change with and without inlined parameters.

 Explore Variable Names and Loop Rolling Using a Wrapper S-Function Inlined with TLC