Incorrect use of test fixtures
Test fixture accessed in suite-test setup/teardown, suite-test fixture accessed in suite setup/teardown
Since R2023b
Description
This defect occurs when you incorrectly access a test or suite-test fixture pointer using macros from the Polyspace® Test™ xUnit API outside the scope where it is defined. For instance:
You invoke the test fixture accessor macro
PST_TEST_FIXTURE_PTR
from a suite-test setup or teardown function (that is, a function registered usingPST_SUITE_TEST_SETUP
orPST_SUITE_TEST_TEARDOWN
).You invoke the suite-test fixture accessor macro
PST_SUITE_TEST_FIXTURE_PTR
from a suite-level setup or teardown function (that is, a function registered usingPST_SUITE_SETUP
orPST_SUITE_TEARDOWN
).
This checker is enabled if you specify the value pstunit
for the option Libraries used (-library)
or find defects in a test file from the Polyspace Platform (Polyspace Test) user interface. For more
information, see Check for Bugs and Run-Time Errors in C/C++ Tests and Functions Under Test (Polyspace Test).
Risk
Accessing a test fixture outside the scope where it is defined leads to undefined behavior.
Fix
Invoke the correct fixture accessor macro in your setup and teardown functions.
Fixture Accessor Macro | Setup and Teardown |
---|---|
PST_SUITE_TEST_FIXTURE_PTR |
|
PST_TEST_FIXTURE_PTR |
|
Examples
Result Information
Group: Libraries Misuse |
Language: C | C++ |
Default: Off |
Command-Line Syntax: PSTUNIT_MISUSE_FIXTURES |
Impact: Medium |
Version History
Introduced in R2023b