主要内容

Import Justifications Between Code Coverage Results

You can exclude or justify parts of your code with missing or low coverage during result review and save the justifications in a reusable file. If you update your source code, you cannot use the existing justifications directly. This example shows how to import existing justification file after you update your source code.

When you upload your results to Polyspace® Access™, the existing justifications are automatically imported and applies to the new version of the results.

Prerequisites

To follow this topic:

  1. Copy this code in src1.c file:

    //src.c
    int LUT(int ch){
    
        int table[5];
    
        for(int i=0;i<=4;i++){
            table[i]=i^2+i+1;
        }
    
        if(table[ch]>100){ /* Condition always false */
             return 0;  
        }
        return table[ch];
    }
    
    

  2. Copy this code in src2.c:

    int LUT(int ch){
    
        int table[5];
        for(int i=0;i<=4;i++){
            table[i]=i^2+i+1;
        }
        if(table[ch]<0){return -1;}
        if(table[ch]>100){ 
             return 0;  
        }
        return table[ch];
    }
    
    

  3. Calculate code coverage of the sources by using the test case LUT(0)==3. Store the code coverage results of the first and second version of the source code in the folders run1 and run2. For details about how to calculate code coverage, see Calculate C/C++ Code Coverage Using Self-Managed Builds

  4. For src1.c, justify the 'false' outcome of the decision table[ch]>100 and save the justification in a *.psprof.filter file. See Save Justification for C/C++ Code Coverage Results.

    Save the justification in the filemyFilter.psprof.filter. Verify that the content of the file matches this XML content :

    <?xml version="1.0" encoding="utf-8"?>
    <filter>
        <rule type="DECISION" fileName="src.c" functionName="LUT" expr="table[ch]&gt;100" index="2" mode="JUSTIFIED" rationale=""/>
    </filter>
    

Import Justification

In the src1.c, the decision table[ch]>100 is always false. The file myFilter.psprof.filter justifies this decision. The file identifies the decision by using components such as filename, functionname, expr, and index. When you update the source code in src2.c, Polyspace can no longer identify the decision table[ch]>100 by using the existing values of these parameters. When you import the justifications to your new result, Polyspace compares the original source code with the updated source code and modifies these parameters to attach the justification to the correct outcome.

You can import justifications between code coverage results either by using the Polyspace Platform user interface or the command line.

Importing Review Information in User Interface

To import preexisting justifications to your new results:

  1. Open the new results for run2 in the Polyspace Platform user interface. See Open Polyspace Results in Polyspace Platform User Interface.

  2. Click Show Outcomes to see all the outcomes,

  3. To Import the justifications, in the Review tab, click Import and navigate to the file myFilter.psprof.filter.

The 'true' outcome of the decision table[ch]>100 is automatically justified. The justification propagates to higher levels and highlights the results in the color cyan.

Importing Justifications at Command Line

To import the preexisting justifications to your new results at the command line, first create an updated justification (psprof.filter) file from your existing psprof.filter file. Then, apply the updated justification file to your new *.psprof file from the run2 folder.

To compute the updated justification (psprof.filter) file for the updated source code, use the command polyspace-code-profiler -import-filters:

polyspace-code-profiler -import-filters -filter-file myFilter.psprof.filter run1 run2
This command generates a new justification file output_run.psprof.filter in the folder run2. This file is modified to account for the changes in the source code:
<?xml version="1.0" encoding="utf-8"?>
<filter>
    <rule type="DECISION" fileName="src.c" functionName="LUT" expr="table[ch]&gt;100" index="3" source="IMPORT" mode="JUSTIFIED" rationale=""/>
</filter>
The value of the component index changes from 2 to 3. This file behaves correctly when you use it with the updated source code.

Create a report for the updated source code using the imported justification:

polyspace-code-profiler -report -html -report-dir filteredreport  run2 
The folder filteredReport contains the generated report. The report shows that the decision table[ch]>100 is justified in the updated source code.

See Also

Topics