LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Understanding Cyclomatic Complexity in LabVIEW

I'm trying to understand Cyclomatic Complexity.  I've been reading online and it appears that complexity can be defined at various levels and methods - but it's meant to show all linearly independent paths through an application or module.  LabVIEW VI Analyzer will return metrics for a given VI, but I don't think there is any way to return metrics above the level of a VI.  Am I wrong that this does not show linearly independent paths?  

 

In other words, the image below shows a blank case structure with three options.  This has a cyclomatic complexity of 3 according to VI Analyzer (two other blank cases not shown):

ShaneC_0-1695671186335.png

 

If I add a subVI, and that subVI has a Boolean decision I would think there are now 5 independent paths through the program instead of 3, but VI Analyzer still returns a complexity of 3.  Does VI Analyzer really show the linearly independent paths described by Cyclomatic Complexity?

 

ShaneC_1-1695671272914.png

 

0 Kudos
Message 1 of 4
(716 Views)

VI analyzer only shows results for the VI it's checking, it doesn't check nested VIs recursively.  It mostly just counts case structure cases, select nodes, event structure cases, and loops as a general measure of complexity and calls it good.

 

You can actually see the code the test runs if you open this file:

National Instruments\LabVIEW 20xx\project\_VI Analyzer\_tests\Complexity Metrics\Cyclomatic Complexity.llb

 

Trying to map all of the nested VIs properly on a large VI with many sub-sub-sub-sub VIs would be nightmarishly complex to do.

 

Also wouldn't there only be 4 in your example?

1-True

1-False

2

3

 

 

0 Kudos
Message 2 of 4
(689 Views)

Yes, you're right, that is four.  I guess the reason I care about this is really in combination with another question.  How does one determine all the linearly independent paths through a program for MCDC code coverage?  

 

It's unclear to me if it's meant to be a collective analysis of all the independent paths through an application, or just the paths through a single section of code.  All the paths through the entire application would be orders of magnitude beyond testable for any application I've ever seen.  Similar story here with complexity.  You can have a VI with complexity 2 that calls a VI with complexity 32.  But from a coverage stand point, how many linearly independent paths are there that must be covered?  Do you count the two together giving 64 paths (assuming I'm thinking about that math correctly), or the individual component VIs, so 34 total paths to cover.

0 Kudos
Message 3 of 4
(673 Views)

I think your best option would probably be some form of unit testing.  There's a framework for it from NI.  It can be a bit tedious to set up and use but if you keep your subVIs with low enough complexity and create a good suite of test cases for each that's probably the best you can hope for.

 

 

0 Kudos
Message 4 of 4
(593 Views)