Test Log: Difference between revisions

From STRIDE Wiki
Jump to navigation Jump to search
(Created page with 'Test Log macros provide a simple means to add information from the source under test to the currently executing test case. This information is added to the test report as annotat…')
 
mNo edit summary
 
(11 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Test Log macros provide a simple means to add information from the source under test to the currently executing test case. This information is added to the test report as annotations with a level of either ''Error'', ''Warning'', or ''Info'' according to the macro that is used. The log messages are also captured when tracing is enabled in the STRIDE runner.
__NOTOC__
Test Log macros provide a simple means to add information from the source under test to the currently executing test case. This information is added to the test report as annotations with a level of either ''Error'', ''Warning'', or ''Info'' according to the macro that is used. The log messages are also captured when tracing is enabled in the [[Stride Runner]].


===Behaviour Testing===
The <tt>srTEST_LOG_xx()</tt> macro is intended to be a general instrumentation macro for capturing information in the source under test. Logs differ from Test Points in that they cannot be used for the basis of expectation tests - they are strictly informational. The Stride log messages are intended to supplement, not supplant a [[Test Point | Test Points]].
The <tt>srTEST_LOG_xx()</tt> macro is intended to be a general instrumentation macro for capturing information in the source under test. Logs differ from test points in that they cannot be used for the basis of expectation tests - they are strictly informational. The STRIDE log messages are intended to supplement, not supplant [[Using_Test_Points | STRIDE Test Points]].


===Compilation===
= Reference =
To use these macros you should include the '''srtest.h''' header file from the STRIDE Runtime in your compilation unit. The Test Log macros are active only when <tt>STRIDE_ENABLED</tt> is <tt>#define</tt>d, therefore it is practical to place these macros in-line in production source. When <tt>STRIDE_ENABLED</tt> is not <tt>#define</tt>d, these macros evaluate to nothing.  
To use these macros you should include the '''srtest.h''' header file from the Stride Runtime in your compilation unit. The Test Log macros are active only when <tt>STRIDE_ENABLED</tt> is <tt>#define</tt>d, therefore it is practical to place these macros in-line in production source. When <tt>STRIDE_ENABLED</tt> is not <tt>#define</tt>d, these macros evaluate to nothing.  
 
== Reference ==


{| class="prettytable"
{| class="prettytable"
| colspan="2" | '''Error Logging'''
| colspan="2" | '''Error Logging'''
|-
|-
| srTEST_LOG_ERROR(''message'')
| srTEST_LOG_ERROR(''message'', ...)
| ''message'' is a pointer to a null-terminated string
|-
| srTEST_LOG[1..4]_ERROR(''message'', ...)
| ''message'' is a pointer to a null-terminated format string<br/>
| ''message'' is a pointer to a null-terminated format string<br/>
''...'' variable list (up to 4) matching the format string
''...'' variable list matching the format string
|}
|}


Line 23: Line 18:
| colspan="2" | '''Warning Logging'''
| colspan="2" | '''Warning Logging'''
|-
|-
| srTEST_LOG_WARN(''message'')
| srTEST_LOG_WARN(''message'', ...)
| ''message'' is a pointer  to a null-terminated string
|-
| srTEST_LOG[1..4]_WARN(''message'', ...)
| ''message'' is a pointer to a null-terminated format string<br/>
| ''message'' is a pointer to a null-terminated format string<br/>
''...'' variable list (up to 4) matching the format string
''...'' variable list matching the format string
|}
|}


Line 34: Line 26:
| colspan="2" | '''Info Logging'''
| colspan="2" | '''Info Logging'''
|-
|-
| srTEST_LOG_INFO(''message'')
| srTEST_LOG_INFO(''message'', ...)
| ''message'' is a pointer  to a null-terminated string
|-
| srTEST_LOG[1..4]_INFO(''message'', ...)
| ''message'' is a pointer to a null-terminated format string<br/>
| ''message'' is a pointer to a null-terminated format string<br/>
''...'' variable list (up to 4) matching the format string
''...'' variable list matching the format string
|}
|}


* The maximum length of the message string approximately 1000 characters. If the maximum length is exceeded, the message string is truncated.
* The maximum length of the message string approximately 1000 characters. If the maximum length is exceeded, the message string is truncated.


=== Example ===
=== C++ Only Features ===
In C++ source the macros above support adding to other content to the message by using the << operator.
 
=== Log Level ===
 
By default only logs with level of either ''Error'' or ''Warning'' are propagated to the host. The [[STRIDE Runner#Options | Stride Runner]] via <tt>--log_level</tt> ''option'' provides finer control over that behavior.
 
== Code Snippets ==
<source lang='c'>
<source lang='c'>
#include <srtest.h>
...
srTEST_LOG_ERROR("This is an error message.");
srTEST_LOG_ERROR("This is an error message.");
srTEST_LOG1_WARN("This is a warning message with format string %d.", 123);
 
srTEST_LOG2_INFO("This is an info message with format string %s and %s.", "this", "that");
srTEST_LOG_WARN("This is a warning message with format string %d.", 123);
 
srTEST_LOG_INFO("This is an info message with format string %s and %s.", "this", "that");
 
#ifdef __cplusplus
srTEST_LOG_ERROR("some error: ") << "stream input supported under c++";
#endif
</source>
</source>
[[Category:Source Instrumentation]]

Latest revision as of 18:54, 21 July 2015

Test Log macros provide a simple means to add information from the source under test to the currently executing test case. This information is added to the test report as annotations with a level of either Error, Warning, or Info according to the macro that is used. The log messages are also captured when tracing is enabled in the Stride Runner.

The srTEST_LOG_xx() macro is intended to be a general instrumentation macro for capturing information in the source under test. Logs differ from Test Points in that they cannot be used for the basis of expectation tests - they are strictly informational. The Stride log messages are intended to supplement, not supplant a Test Points.

Reference

To use these macros you should include the srtest.h header file from the Stride Runtime in your compilation unit. The Test Log macros are active only when STRIDE_ENABLED is #defined, therefore it is practical to place these macros in-line in production source. When STRIDE_ENABLED is not #defined, these macros evaluate to nothing.

Error Logging
srTEST_LOG_ERROR(message, ...) message is a pointer to a null-terminated format string

... variable list matching the format string

Warning Logging
srTEST_LOG_WARN(message, ...) message is a pointer to a null-terminated format string

... variable list matching the format string

Info Logging
srTEST_LOG_INFO(message, ...) message is a pointer to a null-terminated format string

... variable list matching the format string

  • The maximum length of the message string approximately 1000 characters. If the maximum length is exceeded, the message string is truncated.

C++ Only Features

In C++ source the macros above support adding to other content to the message by using the << operator.

Log Level

By default only logs with level of either Error or Warning are propagated to the host. The Stride Runner via --log_level option provides finer control over that behavior.

Code Snippets

#include <srtest.h>
...
srTEST_LOG_ERROR("This is an error message.");

srTEST_LOG_WARN("This is a warning message with format string %d.", 123);

srTEST_LOG_INFO("This is an info message with format string %s and %s.", "this", "that");

#ifdef __cplusplus
srTEST_LOG_ERROR("some error: ") << "stream input supported under c++";
#endif