27/09/2012 07:41 BST | Updated 27/11/2012 05:12 GMT

Coverity: Mars Rover Curiosity's 'Space Doctors' On Bug Hunting In Space

Of all the many, many improbable elements involved in the Curiosity Mars Rover - it's massive size (two tons), its cost ($2.5bn) and its hauntingly elegant descent via levitating sky crane - the software it runs doesn't get much attention. And the people who checked that code for errors? Even less so.

But consider this: all of the code involved in the entire Apollo 11 mission numbered roughly a few thousand lines. For Curiosity it's about two million.

That's a lot. And unlike back here on Earth, you can't just release buggy code and rely on patch updates to keep it working. If Curiosity crashes, there's a chance it could transform from the greatest mobile science lab ever constructed into a $2bn paperweight, overnight.

So it's no surprise that when Nasa decided to check its code for errors, they weren't messing about.

Enter Coverity, the international software analysis company who - for want of a better phrase - are Curiosity's doctor of choice.

Coverity were recruited by Nasa's Jet Propulsion Laboratory to help analyse the code behind Curiosity, from the relatively early stages of development right up until, well - now.

"As a kid I always imagined I'd be an astronaut," Andy Chou, CTO and co-founder of Coverity, told the Huffington Post.

"I think most people love the idea of space travel, and it's just really exciting that we did something like this."

Chou said that while the world's most iconic space agency obviously checks its own software, there are times when even Nasa needs to call in greater expertise.

"As software gets larger it becomes more difficult to test it thoroughly," he explained. "Two million lines of code is quite a lot. It's virtually impossible to test a software system with that much code with just ordinary testing, so they turned to other techniques. Our products use an an analysis technique called Static Analysis (SA), which automatically analyses the code and looks at all the different paths through it so we don't miss anything."

That work involved spending months modifying its SA products, and working constantly with Nasa to check and recheck its code.

Chou explains that Nasa is obsessive about looking for errors.

It took a few months to modify Coverity's products for the Nasa mission, and once they started the scans happened constantly. "New defects were being found as the code was freshly written," Chou said.

"They were very, very careful. Even just the hint of something complex and not easily understood was enough for them to rewrite parts of their code."

Even now the rover is on Mars and making progress to its first major scientific targets, Coverity are still involved. The rover will spend two years on the surface looking for evidence of life, investigating the landscape and sending back photos. Updates to the rover's software could potentially still be pushed to Mars, and Coverity would still be part of that process.

"The software was being updated even while the rover was in transit to Mars," he said. "In fact they have the capability of uploading new software even now. It's pretty remarkable if you think about it - that's a large amount of code and for something like this to get pulled off without a hitch is pretty amazing.

"Most software when it goes into production doesn't work flawlessly. Most software has some failure and patches get put out and people have to update that software - even pretty high-end mission critical software has issues, such as software used in financial exchanges, often have to be closely watched. The fact that this just worked the very first time - that's the remarkable part."

Photo galleryMars Curiosity Pictures See Gallery

So why did - does - the Curiosity rover capture people's imagination? Is it just the audacity of the project, the chance of finding evidence of life - or just the fact that the craft has its own Twitter feed?

Chris Adlard, senior manager for customer advocacy at Coverity, said that the robot has a tangible personality lacking from other massive science experiments, for instance the CERN Large Hadron Collider (on which Coverity also worked).

It's the fact that it's so personified," he said. :If you look at the commentary over Twitter for the rover, it's almost as if Curiosity itself is talking to you. It's much more immediate to the everyday person than other previous missions. "

Photo gallery See Gallery

Chou agrees. "There are very few things these days that can inspire where it comes to science and it's often esoteric, and this is just very concrete. An actual space craft has been sent out there," he said.

For all Coverity's insanely rigorous work on the rover, they recognise they were still only involved in one small element of its success. But the fact is that in modern science, where so much depends on hugely expensive experiments finding new, precious data for analysis, it is only in collaboration of this kind that the real advances may be made.

"There is so much data involved in modern science, processing that data and having software that can automate what would otherwise be impossible manually is critical," Chou said. "That's just a reality of how science is done today."

So to any young coders out there - you might not get to be the astronaut you dreamed of being as a kid. But fixing software bugs on Mars? Well, that's pretty cool too.