Difference between revisions of "Tracing"

From STRIDE Wiki
Jump to: navigation, search
(Capturing Trace Content)
Line 60: Line 60:
 
Once you have captured your trace data into a file, you should look it over (using a text editor of your choice) and make sure that the test points and data captured are what you expect. You are free to manually edit this file as long as you maintain the existing field hierarchy for each test point entry.
 
Once you have captured your trace data into a file, you should look it over (using a text editor of your choice) and make sure that the test points and data captured are what you expect. You are free to manually edit this file as long as you maintain the existing field hierarchy for each test point entry.
  
You can reuse this data as a basis for a test module test - a simple example is available [[Perl_Script_Snippets#Reusing_a_trace_data_file|here for perl]]. The test will load the test points from the trace data file and use them as the basis for your expectation test. By default, both test point label and data are checked, although this behavior can be modified using options and custom predicates. More information on the options available when setting-up an expectation test is available [[Perl_Script_APIs#Methods|here]].
+
You can reuse this data as a basis for a test module test - a simple example is available [[Perl_Script_Snippets#Reusing_a_trace_data_file_as_expectation|here for perl]]. The test will load the test points from the trace data file and use them as the basis for your expectation test. By default, both test point label and data are checked, although this behavior can be modified using options and custom predicates. More information on the options available when setting-up an expectation test is available [[Perl_Script_APIs#Methods|here]].
  
  
 
[[Category:Source Instrumentation]]
 
[[Category:Source Instrumentation]]
 
[[Category:Running Tests & Publishing Results]]
 
[[Category:Running Tests & Publishing Results]]

Revision as of 18:26, 28 April 2010

Using the STRIDE Runner, it is relatively easy to observe test points and log messages on a running target or capture that content and reuse it as the basis for test module expectation tests.

Prerequisites

Similar to Running Tests you need to have a fully setup Host and Target environments.

Observation of the Execution Process

Once you have instrumented your source code, you might want to observe the execution process or more specifically verify that STRIDE Test Points are indeed being reported as you expect. One easy way to accomplish this is by using the console trace output feature in the STRIDE Runner.

The simplest usage model for tracing with the runner is to add the --trace flag to your command line runner parameters, for example:

stride --trace --trace_timeout=600 --log_level=all --database="/my/path/targetApp.sidb" --device=TCP:localhost:8000 

This will cause the runner to listen for 600 sec for test point and log messages from the target device. When the runner is passively tracing like this, you can terminate it by entering Ctrl-C in the console window. This mode of tracing works well if your device under test is continuously executing the instrumented code or if you can manually start the processing on the device (via external input, for example).

If, however, the source code under test must be initiated by a remote function call (using STRIDE remoting), then you will need to incorporate the function call into the execution of the runner. The simplest way to accomplish this is to write a simple script to make the remote function call, as shown here for perl.

Once you have written a simple script to invoke your function(s), you can execute it with the runner using:

stride --run=MyFunctionCall.pl --trace --trace_timeout=600 --log_level=all --database="/my/path/targetApp.sidb" --device=TCP:localhost:8000 

(assuming you named your script MyFunctionCall.pl)

Once you have managed to start the source under test on the device and have connected with the runner, you should see output that looks roughly like:

Loading database...
Connecting to device...
Executing...
  script "c:\s2\MyFunctionCall.pl"
2082576600 POINT "START" [../sample_src/s2_expectations_source.c:62]
2082586700 POINT "IDLE" - 02 00 00 00 [../sample_src/s2_expectations_source.c:77]
2082596700 LOG   "Info" - Idle state entered first time [../sample_src/s2_expectations_source.c:85]
2082596701 POINT "ACTIVE" - 03 00 00 00 [../sample_src/s2_expectations_source.c:100]
2082606800 POINT "ACTIVE Previous State" - IDLE [../sample_src/s2_expectations_source.c:102]
2082616800 POINT "IDLE" - 04 00 00 00 [../sample_src/s2_expectations_source.c:77]
2082626900 POINT "END" - 05 00 00 00 [../sample_src/s2_expectations_source.c:114]
    > 0 passed, 0 failed, 0 in progress, 0 not in use.
  ---------------------------------------------------------------------
  Summary: 0 passed, 0 failed, 0 in progress, 0 not in use.

Disconnecting from device...
Saving result file...

As you can see, any test points or logs that are executed in the source under test will be reported to the console output. This provides a mean to peruse the output of your instrumented source code and do a quick sanity check of your instrumentation.

Tracing within the runner also allows filters to be applied and timeout intervals to be specified - more details can be found in the STRIDE Runner page.

Capturing Trace Content

Besides console logging the trace content could be redirected to a file. Simply add the --trace_output flag to your command line runner parameters, for example:

stride --run=MyFunctionCall.pl --trace --trace_timeout=600 --trace_output=trace_data.yml --database="/my/path/targetApp.sidb" --device=TCP:localhost:8000 

The trace parameters specify that tracing should be activated (--trace) and the results should be written to an output file (--trace_output). We give the output file an extension of .yml because the trace file data is written in yaml (chosen for readability and parseability). It is also possible to specify a regular expression to the --trace parameter which would allow you filter the test point data that makes it into the trace output file - see the STRIDE Runner article for more details.

Once you have captured your trace data into a file, you should look it over (using a text editor of your choice) and make sure that the test points and data captured are what you expect. You are free to manually edit this file as long as you maintain the existing field hierarchy for each test point entry.

You can reuse this data as a basis for a test module test - a simple example is available here for perl. The test will load the test points from the trace data file and use them as the basis for your expectation test. By default, both test point label and data are checked, although this behavior can be modified using options and custom predicates. More information on the options available when setting-up an expectation test is available here.