|
FPT and WinFPT generate a simple measure of the quality of code based on the number
of errors and warnings generated per thousand lines of code. Some errors and warnings
are always generated when code is analysed. Some are generated only in response to
specific tests such as the argument check and name check. It is best to write a
script of standard tests which will be used at a site to test the code quality. For
example:
! millibug.fsp 13-Sep-02 John Christopherson
! *****************************************************************************
!
% check alignment
!
! Ignore distinction between e.g. REAL X and REAL*4 X
% argument check to ignore default sizes
% check arguments
!
% check data in COMMON blocks
% check data in structures
!
% check expressions
!
% equivalence check to ignore default sizes
% check equivalence
!
% check names
!
% check program flow
!
% check usage
!
! End of millibug.fsp ! *******************************************************
FPT and WinFPT report the index of quality in the list file at the end of processing.
For example, the report for GNX, an old VAX/VMS program, is:
Diagnostic Summary
Total diagnostics 590 Highest severity 2
Notes 168
Warnings 273
Errors 149
Code Quality Index
Error weighting 10
Total lines 10017
Index per 1000 lines 176.001
The index per 1000 lines, the "millibug rating" is computed here as
1000 * (10 * Number_of_Errors + Number_of_Warnings) / Number_of_lines
The weighting factor for errors may be changed by the user. It is probably
best written in the configuration file, config.fsp in the main installation
directory, for example:
Diagnostic Summary
Total diagnostics 590 Highest severity 2
Notes 168
Warnings 273
Errors 149
Code Quality Index
Error weighting 10
Total lines 10017
Index per 1000 lines 176.001
The listing also shows the contributions made by different types of disgnostic
to the overall quality index. The table for GNX, for example, shows:
Contributions to Code Quality Index
No. Description Count Contrib
1269 FORTRAN keyword used as local identifier name. 2 2
1273 FORTRAN auxiliary keyword used as identifier name. 4 0
1281 FORTRAN intrinsic used as an array name 1 0
1459 Fortran keyword EXIT used, presumably to call system service 1 1
1585 Arguments inconsistent with sub-program declaration. 85 850
1887 Arguments inconsistent with other calls. 3 30
1967 Unable to determine value of a PARAMETER. 5 0
2241 References are made to sub-programs which have not been read. 1 0
2315 The file has been referenced elsewhere by a different name 24 0
2517 ANSI FORTRAN 77 intrinsic used as a local identifier 2 2
2847 Multiple initialisation of COMMON block 1 1
2849 DATA for COMMON outside BLOCK DATA 1 1
3047 Fortran 90 intrinsic name used as an identifier 2 2
3073 Danger of overflow due to different integer sizes 229 229
3235 Symbol is read but never written to 61 610
3237 Symbol is written to but never read 2 2
3239 Symbol is declared but never used 128 0
3241 Name is used inconsistently in different contexts 1 1
3243 Object is mis-aligned in memory 14 14
3247 Mixed EQUIVALENCE - Objects of different type or size 18 18
3291 String shorter than parameter in parameter assignment 5 0
Our experience is that any program with a millibug rating greater than 10
is unlikely to run without problems. The rating of 176 for GNX is alarming. The
table of contributions shows that most of the problems come from mis-matched
arguments and unassigned variables. This was a VAX program, where arguments
with size mis-matches were still likely to be handled correctly and all unassigned
variables were set to zero. It would not port well to a PC!
|