Table of Contents
Fetching ...

The ACPATH Metric: Precise Estimation of the Number of Acyclic Paths in C-like Languages

Roberto Bagnara, Abramo Bagnara, Alessandro Benedetti, Patricia M. Hill

TL;DR

A new metric for C-like languages, called ACPATH, is defined that allows to quickly compute an very good estimation of the number of acyclic execution paths through the given function, and it is shown that, if the function bodydoes not contain backward gotos and does not contain jumps into a loop from outside the loop, then such estimation is actually exact.

Abstract

NPATH is a metric introduced by Brian A. Nejmeh in [13] that is aimed at overcoming some important limitations of McCabe's cyclomatic complexity. Despite the fact that the declared NPATH objective is to count the number of acyclic execution paths through a function, the definition given for the C language in [13] fails to do so even for very simple programs. We show that counting the number of acyclic paths in CFG is unfeasible in general. Then we define a new metric for C-like languages, called ACPATH, that allows to quickly compute a very good estimation of the number of acyclic execution paths through the given function. We show that, if the function body does not contain backward gotos and does not contain jumps into a loop from outside the loop, then such estimation is actually exact.

The ACPATH Metric: Precise Estimation of the Number of Acyclic Paths in C-like Languages

TL;DR

A new metric for C-like languages, called ACPATH, is defined that allows to quickly compute an very good estimation of the number of acyclic execution paths through the given function, and it is shown that, if the function bodydoes not contain backward gotos and does not contain jumps into a loop from outside the loop, then such estimation is actually exact.

Abstract

NPATH is a metric introduced by Brian A. Nejmeh in [13] that is aimed at overcoming some important limitations of McCabe's cyclomatic complexity. Despite the fact that the declared NPATH objective is to count the number of acyclic execution paths through a function, the definition given for the C language in [13] fails to do so even for very simple programs. We show that counting the number of acyclic paths in CFG is unfeasible in general. Then we define a new metric for C-like languages, called ACPATH, that allows to quickly compute a very good estimation of the number of acyclic execution paths through the given function. We show that, if the function body does not contain backward gotos and does not contain jumps into a loop from outside the loop, then such estimation is actually exact.

Paper Structure

This paper contains 46 sections, 10 theorems, 119 equations, 10 figures, 6 tables.

Key Result

Theorem 1

Consider a directed graph $G = (N, A)$ with entry node $s$ and exit nodes in set $T$. Counting $s-T$ acyclic paths in $G$ is $\mathsf{\sharp P}$-complete.

Figures (10)

  • Figure 1: Scatter plot: $\log\bigl(1 + \log(\mathrm{ACPATH})\bigr)$, $x$ axis, vs $\log\bigl(1 + \log(\mathrm{NPATH})\bigr)$, $y$ axis
  • Figure 2: ACPATH value, $x$ axis, vs NPATH predicted value distribution, $y$ axis
  • Figure 3: ACPATH value, $x$ axis, vs NPATH, $y$ axis: each bar contains the central $68\%$ of the samples
  • Figure 4: CFG for $\bigl\{\, \mathtt{if} \; (\cdot \mathbin{\mathtt{\&\&}} \cdot \mathbin{\mathtt{\&\&}} \cdot) \; \mathtt{return} \; (\cdot \mathrel{\mathtt{?}} 0 \mathrel{\mathtt{:}} 1); \; \mathtt{else} \; \mathtt{return} \; (\cdot \mathrel{\mathtt{?}} 0 \mathrel{\mathtt{:}} 1); \,\bigr\}$: $8$ acyclic paths
  • Figure 5: CFG for $\bigl\{\, \mathtt{while} \; (\cdot) \; \mathtt{if} \; (\cdot) \; \mathtt{break}; \; \mathtt{else} \; \mathtt{continue}; \,\bigr\}$: $3$ acyclic paths
  • ...and 5 more figures

Theorems & Definitions (30)

  • definition 1
  • definition 2
  • definition 3
  • Theorem 1
  • proof
  • definition 4
  • definition 5
  • definition 6
  • definition 7
  • proposition 1
  • ...and 20 more