Adventures in Software Engineering

Spectrum-based Fault Localisation, a Primer

S

We’re all familiar with debugging – it’s just part of life as a programmer. In all honesty though it is one of my favourite things, taking me away from the mental gymnastics of straight development and to a peaceful place of execution monitoring and pattern spotting. It’s like refactoring foreplay. Fun times. Most people don’t think like that of course because they’re normal, and would love for some automation to bring terror to the error. Enter stage left, spectrum-based fault localisation.

Spectrum-based Fault Localisation

In essence this is nothing more than recording the execution of program flow, to indicate which lines were executed and which branches were followed. Let’s imagine that we have the following code block causing all kinds of grief, as it always prints that ISIC is a hero:

public void print(final boolean hero) {
print("The real hero has been decided as ");
if(true) {
println("ISIC");
} else {
println("Oscar Mike");
}
}

It’s pretty obvious what is wrong here, but we decide to instrument this code to produce a spectrum that helps us analyse things anyway. It might look a little something like this:

public void print(final boolean hero) {
log(0)
print("The real hero has been decided as ");
if(true) {
log(1);
println("ISIC");
} else {
log(2);
println("Oscar Mike");
}
}

The addition is that prior to each code line run, a different value is executed. When the code is exercised by providing both true and false, we end up with the following results:

InputLogged Values
true0,1
false0,1

It is immediately obvious that the line which was supposed to output the number two has not been run. Thinking on we can see that the numbers zero and one have been output, so perhaps we can conclude the problem lies between these two outputs – and we’d be right! The input parameter isn’t being considered at all. It’s an easy fix:

public void print(final boolean hero) {
print("The real hero has been decided as ");
if(hero) {
println("ISIC");
} else {
println("Oscar Mike");
}
}

The Road from Here

We’ve briefly covered the very basics of spectrum-based fault localisation.┬áNext time we’ll look in more depth at the spectra that are available for us to use, before going on to see how they evolved into more complex predicates. See you then!

About the author

Johnathan Meehan
Johnathan Meehan

I'm a software engineer with more years and stomach under my belt than I would like. I have an odd sense of humour and a predilection for junk food, whiskey and beer. My first job was in 68K on God's computer, the Commodore Amiga. Since then I've worked here, there and everywhere being paid to play with all kinds of fun things and once even nibbled around the edges of being an Apache committer. Most time now is spent with Java, and I put a heavy emphasis on quality. When I grow up, I want to be just like Oscar Mike.

Add comment

Adventures in Software Engineering

Johnathan Meehan

Johnathan Meehan

I'm a software engineer with more years and stomach under my belt than I would like. I have an odd sense of humour and a predilection for junk food, whiskey and beer. My first job was in 68K on God's computer, the Commodore Amiga. Since then I've worked here, there and everywhere being paid to play with all kinds of fun things and once even nibbled around the edges of being an Apache committer. Most time now is spent with Java, and I put a heavy emphasis on quality. When I grow up, I want to be just like Oscar Mike.

Recommended Host