Source Instrumentation Overview
Introduction
Source instrumentation is the process by which developers and domain experts selectively instrument the source under test for the purpose of writing test scenarios against the executing application. Implementing tests that leverage source instrumentation is called Expectation Testing. This validation technique is very useful for verifying proper code sequencing based on the software's internal design.
Unlike traditional unit testing that drives testing based on input parameters and isolating functionality, expectation testing is executed within a fully functional software build running on a real target platform. Expectation tests are not dependent on input parameters, but often leverage the same types of input/output controls used by functional and black-box testing.
Another unique feature of expectation testing is that domain expertise is not required to implement a test. Developers and domain experts use instrumentation to export design knowledge of the software to the entire team. Furthermore, there is no stubbing required, no special logic to generate input parameters, and no advanced knowledge required of how the application software is coded.
To enable effective test coverage, developers and domain experts are required to insert instrumentation at key locations to gain insight and testability. Here are some general suggested source code areas to consider instrumenting:
- critical function entry/exit points
- state transitions
- critical or interesting data transitions (using optional payload to convey data values)
- callback routines
- data persistence
- error conditions
Instrumentation
To make the software testable, the first step in the process is for the experts to selectively insert instrumentation macros -- called Test Points -- into the source code. Test Points themselves have nominal impact on the performance of the application – they are only active during test data collection[1]. Test Points contain names and optional payload data. When Test Points are activated, they are collected in the background, along with timing and any associated data. The set of Test Points hit, their order, timing, and data content can all be used to validate that the software is behaving as expected. Test Logs can also be added to the source code to provide additional information in the context of an executing test.
Here are the requirements for source instrumentation using the STRIDE Framework:
- define the STRIDE_ENABLED preprocessor macro in your build system
- include the srtest.h header file. This file is included in the Runtime source distribution
- selectively instrument strategic locations in your source code with Test Points and optionally Test Logs
Expectations
In addition to instrumenting the source code with Test Points, you must also define the Expectations of the Test Points. This involves defining the list of Test Points expected to be hit during a given test scenario. An expectation can also include any expected data associated with a Test Point that requires validation.
Testing
Once the source under test has been instrumented and the expectations defined, STRIDE offers a number of techniques that can be used for implementing expectation tests. For non-developers the STRIDE Scripting Solution is recommended. Scripting allows testers to leverage the power of dynamic languages that execute on the host. The framework provides script libraries that automate the behavior validation as well as hooks for customization. The script implementation also reduces software build dependencies since the test code is not part of the device image. Scripting can also leverage function remoting to fully automate test execution by invoking functions on the target.
For developers writing expectation tests, the STRIDE Test Units with test logic implemented in C or C++ is recommended as a starting point.
Notes
- ↑ Test data collection is typically implemented in a low priority background thread. The data is captured in the calling routine's thread context (no context switch) but processed in the background or on the host. Instrumentation macros return immediately to the caller (i.e. no-op) when testing is not active.