Main Content

Troubleshoot Code Profiling for Polyspace Test xUnit API-Based Tests

Issue

To successfully calculate code profiling and generate a Polyspace® Test code profiling report at the command line, you must:

  1. Instrument the source code.

  2. Compile and link the instrumented code to produce the test executable.

  3. Collect coverage data by running the test executable.

  4. Produce the coverage report from the collected data

If any of these steps fail, the generated report might be empty or display incomplete results.

Possible Solutions

To resolve this issue, check the output of each step in the workflow. Use the -verbose flag when running the commands and then check the log for errors and warnings.

Check If Your Code or Build Command Contains Unsupported Construct

Polyspace cannot complete the instrumentation step if:

  • Your source code contains unsupported constructs

  • Your build command contains unsupported flags

When calculating the execution and stack profile of your program, Polyspace Test does not support these code constructs:

  • Code that uses multitasking libraries.

  • Code that uses recursion.

  • Functions that raise exceptions.

  • Functions that handle exceptions that are raised elsewhere.

If your source code or build command contains an unsupported construct, the code might not be instrumented or partially instrumented code. Coverage reports generated from such code might be empty or contain incomplete results.

If your build command contains unsupported constructs, Polyspace Test might be unable to parse the command, leading to incorrectly instrumented or uninstrumented code. Check the log to see if your code or build command contains any unsupported construct.

If your code contains unsupported constructs, you exclude those parts of your code from the instrumentation by using the pragma tmw code_instrumentation. When Polyspace Test™ encounters the pragma tmw code_instrumentation off, it stops instrumenting the source code until it encounters the pragma tmw code_instrumentation on. For instance, in this code, the multitasking code is excluded from instrumentation by using this pragma:

void bar(){
	//...
	#pragma tmw code_instrumentation off 
	// multitasking code
	#pragma tmw code_instrumentation on
	//....
}

Check If Correct Files Are Instrumented

Check which source files you are including and excluding from instrumentation and if your build command includes the correct source files. You might be accidentally instrumenting Polyspace Test library files or excluding a desired source file.

If your project contains only header files, Polyspace does not calculate code profile metrics for the header.

If necessary, limit the scope of the instrumentation step by using the option -instrument-dir. Exclude unnecessary files by using the flag -ignore-file.

Check If Instrumented Test Executable Runs Correctly

If the test executable runs correctly, you see the test results in the command line console or in the log. If you do not see the expected test results:

  • Check if your build command is correct. Try building your project and tests without instrumenting to verify the build command.

  • Check if the compiled objects are linked with the Polyspace Test run-time library when generating the test executable. If the provided run-time library is incompatible with your environment, recompile the library for your environment. See Create Library for Code Profiling Using Self-Managed Builds.

  • Check if the instrumented test executable terminates abruptly, perhaps because of a run-time error or an exception. If the text executable does terminate abruptly, Polyspace Test might not generate the coverage data required to calculate the report.

Check If Coverage Data Generates

Check if a *.bin file is generated after executing the -run command. Coverage data might fail to generate if you do not invoke the instrumented source code. For instance, in this code, if you inadvertently exclude the foo() function from instrumentation, then Polyspace Test does not calculate the coverage data for bar().

void bar(){/*Instrumented code*/}
void foo(){//Not instrumented
//...
bar();
}

Check Definition of PSPROFILE_RESULTS_FILE

You might be collecting coverage data by running the instrumented test executable without using the polyspace-code-profiler -run command. In this workflow, the generated code coverage data is collected in a *.bin file specified by the environment variable, PSPROFILE_RESULTS_FILE. When defining this environment variable:

  • The value must be the complete path to a *.bin file.

  • The specified path must preexist.

If you define PSPROFILE_RESULTS_FILE incorrectly, Polyspace Test does not collect the coverage data. you cannot generate the coverage report without the data. If you define the environment variable correctly, generated coverage data is appended in the *.bin file.

Check for Precompiled Headers in Visual Studio Project

If your Visual Studio® project uses precompiled headers, the project is incompatible with the polyspace-code-profiler command. To calculate code coverage of your Visual Studio project, compile your project without using precompiled headers.

Check Static Library Used When Generating Test Executable

When generating the test executable, link the correct version of the Polyspace Test static runtime library with your instrumented code. For instance, if you want to run the test executable in a Linux® environment, then link the static runtime library located in the folder polyspaceroot/polyspace/psprofile/lib/glnxa64. Using in incorrect library results in an executable that might not run correctly or fail to generate coverage data.

See Also

Topics