Charta Aetatis Cyberpunk

Console For you Newsletter Pro Sign in Register
Aa · Display
Themes
Type size
Density
Hacker Culture · Lobsters · · 53:59 runtime

The Power of Ten: Rules for Safety Critical Coding

Withdrawn by the publisher. It may have been corrected or replaced.

Comments

In the wiki Jet Propulsion LaboratoryCuriosity Rover Also namedBell Labs, Perseverance rover
Transcript 7285 words · auto-generated captions

Machine-transcribed by YouTube. Expect errors in names, commands and version numbers.

[music]

[music]

[music]

>> Okay, um so I was um uh lured to join NASA JPL to work on software reliability. Um and basically I I I left computer

science research center at Bell Labs in 2003. And this was just the motivation at uh NASA to do something about the uh software reliability was um that they had lost a couple of missions uh due to software problems, software anomalies as as it was sort of kindly uh called. So, if you if you think about uh software reliability and software safety, there are a ton of standards out there, right? So, I started looking at like uh what what is what has been done uh that we can benefit from at JPL to improve our mission software, the flight software for deep space missions. And so, the nice thing about all these standards is like Andy Tanenbaum bomb used to say, there's so many, there's always one that you like and that you can use and you can ignore all the others. So, when I first came uh to JPL,

I learned that every mission, every project started by developing their own coding standard, not based on anything else, not based on international standards, just the personal preferences of whoever was leading that particular project or mission. So, I I started collecting all of those, put them in a database as you might expect, uh developed a query engine from that database, say, "How many rules are there in all these different standards to deal with uh dynamic memory allocation, for instance, or whatever topic uh you may think?" And um basically, uh there are all these standards, and they have all these rules based on personal preference, like like how to use white space, tabs or spaces, this is the the generic example, that has no correlation with risk, like with actually stuff that that breaks, that can go wrong.

Uh and and many of the rules, tabs and spaces, you can check, like you can can write a checker for, but it's totally meaningless, like why even bother? Um many of the rules in in all these standards were totally uncheckable, and the one thing that you learn very quickly is even if people strongly agree

on the the usefulness of a particular rule, like don't do this, do that instead, uh if you don't check, they don't follow the rule, even if they like the rule, if they they believe in the rule. So, um most of these rules are just to make people feel better, like, "Yeah, we have a coding standard." Yeah, nobody follows the standard, but all right. So, I wanted to do something about it. Now, the culture at NASA and at JPL was

perfect for this, right? There is a very strong uh um awareness of risk and the need to

reduce risk. Whatever the risk comes from, so hardware issues, like redundancy in hardware, but also software. So, there's this NASA uh uh guidebook that uh talks about

risk, and it says a couple of really uh good things like ba- basically all software must be considered potentially flawed. Uh, cuz that's just the reality of this. Like you may think you have found all the bugs. I I was amused by earlier statements about total eradication of all bugs. That is that's a nice start, but basically that that doesn't happen. So there are all these statements in there like most software cannot be exhaustively tested, especially if you have multi-threading, concurrency, distributed systems, and basically all software that we use today, including mission software for deep space mission missions is multi-threaded. That means you that there's no way that you can exhaustively test it. If you use MCDC coverage, exhaustive coverage, branch coverage, etc., you're just scratching the surface of the real issues that you can encounter.

I do not have enough time to show you those examples, but you you can easily if you're interested in that, I can send you some examples of very small programs where you you will miss the bug if you just do MCDC 100% branch coverage.

Uh, so that was very good to know, and then um another statement from a JPL guidebook was safe safety must be designed into the software from the beginning. You cannot test it into the software. You cannot just write your software any way you want and then hope that exhaustive testing in practice exhaustive testing means the tester is exhausted, not not the number of possibilities. >> [laughter] >> So you cannot do it. That's not the way to get to reliable software. So a couple of basics. Just basically

beating the dead dead horse, right? So this is stuff that everybody knows or know. Um all non-trivial software has

bugs. No matter how how long you test it, the flight software at JPL and and elsewhere at NASA is extremely thoroughly tested with millions of simulations of the critical sequences in the software like for landing on Mars, the landing sequence is simulated ad nauseam for months at a time on cluster computers. Every imaginable situation is

is going to be tested in that way. And of course with with some of these landings, the actual landing when it finally does happen, typically goes way smoother than all the stuff that was simulated, which is a good thing. Um the average residual software defect ratio after testing, you should expect between 1 to 10. This is very thoroughly, well-designed software. You should expect to find between 1 and 10 residual software defects um after testing per 1,000 lines of code. Uh excluding comments. Like stripping away the comments, 1,000 lines of actual code that executes, should expect between 1 and 10. And you're very lucky if you can get that low.

Uh we we And then you can just calculate. Like if 3 million lines of software, the Curiosity lander

uh Mars Science Lab mission that landed on Mars, the the mission just before the last one, which was Perseverance. This one was Curiosity. 3 million lines of code. That's the number of defects that are in that code after testing. Uh and that can show up uh in in strange

cases like weird stuff does happen. The

very unlikely, no sane person can imagine that a particular sequence of of circumstances can happen. Something fails here, there's a bug in the error recovery code, and combined with yet another problem. Nobody can can Nobody say sane can think about those scenarios. They do happen. They will happen in practice. So, for mission safety critical code,

you want the defect rate the residual defect rate to be much lower. And the only way you can get that is by design, but not by testing. So, think space shuttle. Space shuttle

the most thorough process. If you want to fix a bug, there is like an an extraordinary

process or there was for changing the code. Almost impossible. You can't just go in and say, "Oh, I know what the bug is and I'm going to fix that." So, they got down to about 0.1 residual defects per 1,000 lines of code. Not zero. The worst thing you can do is to assume that you can get to zero. Because then then you start getting cocky and think, "Oh, I can get away with it now." So, cannot be achieved by testing alone.

Um so, all all non-trivial software

bugs The effect effect of even minor software defects can be disastrous. I think that you can lose the mission. And of course, nuclear power plants software I mean, you you know all the stories of what can happen. Like the Fukushima meltdown is a very nice example of what

combination of of factors can contribute

to a catastrophic loss that nobody could have predicted because there are too many things that have to combine in a particular way. Now, so one other thing I should mention is the The error-prone software in any system is default protection software, error recovery software because it's the the the least well-tested because no

again no sane person can think of all the bizarre things that can go wrong in a particular combination. So, um if there's one thing that I will say today, it's going to be on this slide. All the rest is just for your entertainment. Um collecting metrics on your software development process is the single most important thing you can do. So, here is sort of a generic pipeline. You start with a specification or a requirement specification. You do high-level design, low-level design, coding, and testing. Every one of these phases can introduce a defect. In the requirements phase because the requirements are ambiguous or contradictory or missing.

In the design phase, you just make a mistake or you work from faulty requirements. Obviously, in the coding phase. And you can introduce bugs in the testing phase. For instance, if you have to test a 24-hour timer that does some recovery. You're not going to wait 24 hours in the test bed for that timer to expire. So, you set it back to an hour. It expires. You forget to set it back to 24 hours. You've introduced a bug. That happens. Um so, here the numbers on this slide that you probably can barely read. On the top, these are measurements for AT&T switch development. The numbers at the top are the the number of defects that

were seen that were detected to be introduced in a particular phase of the development cycle, the process uh software development cycle. So, the numbers are per 1,000 lines of code that eventually come out at the the far end. The numbers at the bottom are the boxes that are detected, that are found in any

phase, right? And you want to make sure that the defect doesn't travel too much far down the the pipeline. So, you can find a defect in the requirements in the testing phase. You really don't want to do You don't want to wait that long. You want to detect it in the requirements phase itself. So, all these numbers, if you subtract the number at the bottom of a box from the number at the top of the box, you have the number of defects that are propagated to the next phase. You want that number to be zero. It is never zero. Especially the number at the very end, the number of residual defects, you want that to be zero. It's never zero. But to improve the process, you want to check where are most defects introduced, why am I not catching those in the phase where they are introduced, what can I do to improve the process to reduce those numbers, increase the number of defects detected, reduce the number of defects introduced.

Okay, that I I can talk about this for an hour. I'm not going to do that. Um so, metrics, collecting metrics is

hugely important if you want to improve software reliability, the thing that comes out at the far very end. So, uh design errors, coding errors, you all know about this, errors introduced in testing. So, uh fine-tuning that process is really important. You want to reduce propagation of errors, and you want to reduce how far the defect can travel down that that pipeline. So, a bug introduced in design, you want to catch in a design review. You don't want to catch it in testing or in the coding phase. Okay. So, software reliability is not just about finding and fixing defects. Every defect that you find, no matter where in that pipeline, reveals a flaw in the process itself.

Like you find a bug, that bug should have been found earlier. Or and that bug should not have been introduced because of a proper process. So, that that this just basics, right? And the importance of collecting metrics. So, now simplicity is one of the most important tools in getting software to be reliable. And so, the picture say which which system would you rather uh fix when it's broken? The one on the on the left or the one on the right? Of course, the one on the right, right? Because you'll going to spend a whole lot more time fixing the thing on the on the left.

So, uh you want to put a bound on software complexity. So, my luck doing this basically the pitch I'm giving you uh right now, my luck at JPL was that people were extremely aware of risk and what can happen. You don't want to be the guy who introduced defect that made

JPL and NASA lose a mission, right? You really don't want to be that guy. Uh so, all these people in the in the flight software development teams were very keenly aware like, not me, right? I'll do anything you say to to prevent these defects and to catch them. So, uh bounds on complexity, simplicity of control flow, etc. Uh language restrictions to make sure you don't use features that

are prone to introduce defects. We have a lot of statistics on things that have gone wrong and what went wrong and what language feature feature people used that caused the defect. Don't use those features. For instance, dynamic memory allocation is an example. Uh things that uh that contribute disproportionately you want strong guidelines for structuring your code. Like, if you introduce a defect in your module, it

should not be able to bring down another module that some other guy wrote based on uh assumptions that he made about yours. So, it's this assumed guarantee principle that one of the previous speakers talked about very well. So, you make assumptions about uh input to your module, and in return you provide a guarantee to um modules that take your output. Preconditions, postconditions, etc. You want to be able to be very strict about those things. You want to be able to uh check them. And then, automation is another one. If you don't check for a particular flaw, the flaw will go through the whole pipeline. You can talk about it, you can think about it. If you don't check, uh it it will get through. Automation, you use tools. You use tools to reduce the number of defects.

Um and you use tools to detect as many defects as possible. My favorite tool for for doing this is called Cobra.

Not surprisingly, my favorite tool. I've spent the last 10 years of my career working on making that thing uh go really fast. It's open source, and um it's the fastest static source code analyzer out there right now, and a very powerful. It's programmable, etc. So, uh you can use that to automate checks, for instance, for the power of 10 rules that I'm going to talk about.

Now, uh another thing that I did early on is to say, "Let's just make a catalog of

everything related to software that has gone wrong in a NASA mission." And maybe

not even just NASA, everywhere where I had information available to a mission failing or being affected by a software problem, I made this long list. And so, I made that list in 2006. And if I I It's very easy to to expand that list to 2026 because this is not the last MRO is not not the last mission that the software defect. So, all these things and then you say, "Okay, here here's what went wrong." What type of problem is that? Can I put it into different categories? So, here first you can say, "Well, did we actually lose the mission because of this?" Or what did it just cause problems that we had to do all kinds of things to recover from that problem. So, that that's sort of the red and the blue squares. And then categorize it. And my surprise was I only only needed about six different categories.

So, then you can say, "Well, okay, we have all these coding standards for safety-critical code. And they have hundreds and hundreds of rules. But really, there are only six issues that cause most problems." So, what are those six issues? It's basic coding issues. Well, by

stronger guidelines and stronger rules, you can prevent some of those. Design issues, memory use, dynamic memory use, uh thread use, multi-threading, deadlocks, race conditions, etc. Code reuse. Now, this this actually took a lot of convincing originally at JPL

to show that code reuse like code that has flown on a previous mission and was therefore trusted to be reused on a new mission is a really bad idea because the new mission is different. Like the whole context is different and things will break because you make assumptions about the previous mission, not about the current mission. And so, that can cause to And you can statistically also show that that code reuse tends to introduce a lot of defects that are avoidable. And then fault protection. Fault protection, I mentioned that error recovery code is the least thoroughly tested because you just can't imagine about everything that could possibly go wrong. So, given that, six categories, let's fix those six, and then we have like 90% of the problems.

Do something about those six things to make this over safe. Like, don't do certain things or do things in a different way. So, um heap memory use, accidental use

of freed memory happened in a lot of missions until we came up with the coding standard. Uh overrunning allocated blocks, running out of heap memory, uh and some memory allocators for dynamic memory allocation has have quadratic behavior, including the one in Unix and early versions of Linux. Uh and there's a reason for that that I won't uh go into, but uh could affect your performance. Uh could give a big hit to your performance if, you know, you you need to allocate a new block of memory, and the the system the allocator starts searching for a block of the right size, and basically destroys your performance.

Then, uh so, use of dynamic memory allocation is prohibited in almost every standard for safety-critical code, including for automobiles. So, the guiding standard for automobiles, or as you say, the guidelines, is the MISRA C standard, MISRA C and MISRA C++ standard

for uh uh use of engine control software in automobiles. Um It's also dynamic memory allocation is also uh prevented in the Power of 10 rule set. So, um clearly the point is we cannot prevent everything, but we should do our best to at least prevent the most commonly occurring problems. Um So, uh I actually started by uh doing a survey

of the MISRA C standard. It's the dominant standard in the safety critical software applications, and we wanted to sort of adjust it and look at how we can benefit from this standard for flight software for deep space mission robotic missions. And human-rated software is yet another level of seriousness here. So, the MISRA C standard has over 100 rules like most of these standards, and I started doing a survey

where I asked people which of these 128

some rules do you support? Do you agree with that they are wise? And which do you think are are stupid? And so, I asked a lot of people for that including Brian Kernighan and Dennis Ritchie because they were my friends and and colleagues from Bell Labs, but also JPL

flight software developers, NASA flight software. I tried to interview people that were known to be very skilled and good at writing software, not just random guy in his basement building something interesting. So, I then categorized the answers by saying, "Well, this rule is strongly supported, very popular, very unpopular,

etc." And then I came up with like the top 10 or this guy's it's like top 15 or so and the bottom 10 or 15. I say almost everybody hates this rule in the second set and almost everybody supports this rule in the first set. Say, "Okay, now you have a basis for talking about useful coding rules." But now I did the next thing. So, most of these people were flight software developers. And so, I looked at the list things that are very strongly supported. And then I looked at flight software, all the flight software I could get my hands on, which isn't simple because it this is considered export controlled and and need to see only uh so I but I collected flight software from all missions going back to Voyager.

And I looked like the rules that are strongly supported. I would expect those are followed, right? In in the flight software from all these missions. And the rules that are where everybody says that is just stupid over my dead body. And this is what I found that the rules that are strongly supported are not followed at all. The rules that are despised are followed. >> [laughter] >> So, psychology, right? So, what do you make of that? And it just means that a rule that is strongly supported but not checked. But none of these was checked. I was the first person to check to do I actually follow the rules that they like.

Uh if you don't check, they don't follow the rule. It's as simple as that. If you don't have a checker, there's no point in even having a rule in a coding standard because nobody will follow it because you you get away with it. Like it's like your children, if you have children. Uh if you don't check that they follow the rules that you set, they will not follow the rules that you set. They will pretend, but yeah. So, um now about how do you formulate coding rules? Uh there are different ways of doing that. Like so, traffic rules are a nice example. You can say, you know, when you get to an intersection, just be careful, right? Look look for other traffic. Just just do your best.

Like avoid bumping into other cars. Or you can say, stop at the red light, uh Uh, wear your seat belt, and uh don't go faster than 50 miles 55

miles an hour. What is the difference between these two? One is checkable, the other one is not.

Measurable uh rules. If your rule is not checkable, don't put it in the standard because that's just entertaining yourself. It doesn't have any effect. Um so the rule for rule also the rule must be

sparse. Like over 100 rules also people

may read through the rules once and think, "Oh yeah, maybe." Uh and and just forget about them. If you have a very small number of rules, say 10, there are historical precedents uh for this as well. 10 rules that are clear,

like not like needing a whole page to explain the rule, very clear, and uh that you can correlate with risk. And you can check them, then they can have effect. So, I was looking for the minimum number of rules where the the largest number of people would say, "Yes, I can understand that rule. I can remember 10 rules."

And we're going to check those 10 rules as strongly as we possibly can. That will make a standard. So, basically the trade-off here is the psychology is oh yes, you can come up with 500 rules that would be nice to have and that might correlate even with risk. But if you could only enforce 10 of them. So, if you had to pick 10, uh so only 10, but then in return you can check them and you can make sure everybody will follow this those 10 rules, which 10 would you pick? That that was basically what I was trying to uh do. So, uh Galileo uh had made this statement saying measure what is measurable and make measurable what is not so.

That's the scientific approach, right? If it's not measurable, you cannot do any type of experiment with it. You cannot reason about it. You have to make things measurable and as long as it's not measurable, you might as well leave it out of of your guideline and your design process because it will not have any effect. So, very simple principles that are used to pick those 10 rules. One is protect yourself from doom. And the second one is use your strength. Perfectly sensible, right? You Yes, you might want to write your code anyway that that pleases you. You want to be able to show that you really understand the language really well by doing something really bizarre. There's this famous comment from Ken Thompson in the Unix source code that says you do not have to understand this.

Uh, so some people who are very good like to show like I'm doing something really weird here, but trust me it works. Don't do that, right? Don't do that because the next guy who is not as smart as you are and wants to fix it will not know how to fix it.

Okay, so that's those are two principles. So, that let That's basically my my long-winded introduction to explaining this is why we picked these 10 rules. Because we we we wanted only 10 and we wanted make it sure that we could check them. So, use simple control flow. Don't use set jump, long jump. Don't use go to's. I mean, we've heard that story before. Go to's make code harder to read. May make it a little more efficient in some cases, but basically you can get confused about the control flow. Don't do it. Actually, this one was surprising to me that every single software developer at JPL said, "Yeah, of course."

And and then then you check in the code say count the number of go to's in the code and you get a different story, but basically they all agree, "Yeah, no, that's bad. We shouldn't do that." And you can check, right? Grab, you can check for go to's. Uh second rule is provide an explicit upper bound to all loops. You don't want to run away loops. You don't want like traversal linked list and the the linked list ends up being circular because of some other bug and you never get out of the loop. So for safety critical code, that that's a really bad thing, right? You get stuck in a loop uh and then some count on some timer expiring at some point. You want to give a fixed upper bound to some of the loops. So now I could tell you lots of anecdotes about what went on behind the scenes at JPL. So there was one software developer and I'll try not to do it except in this case. Um >> [laughter] >> So there was one software developer that I will not name who was really good at writing software, who said, "That's a stupid rule. That That That's That's totally unnecessary. Of course the loops the the the for loops and the while loops, they're going to be bounded. You don't don't make me put a counter on there and a and a maximum counter."

Guess who the first software developer was that hit that problem because he wasn't following the rule? That same guy. So after that point, he just followed all the rules. So he didn't argue anymore. And it basically can happen to all of us, right? It wasn't like he was particularly vulnerable to that. It's just sometimes bizarre things happen. No dynamic memory allocation after initialization. >> [applause] >> Avoid a host of problems. So we I can point to

missions deep space missions that have failed completely because they weren't following that rule. That was before we had the the rule set. Uh use short functions, basically no longer than what you can see on a single screen. Um This is actually something that a lot of people have argued against for a long time, but at some point you said we can check it. We have agreed this is the standard. The the power of 2 10 rule set

became part of the institutional standard that applies to all software developed at JPL. Not just mission software, all software. So, no question. It's just we're going to check a little more thorough if it's mission software. And so that was institutionalized etc. And uh uh part of the rule and okay. Use assertions. Now, I I put a few things in red. This is the first thing I'm putting in red is number five because originally I put it as as the fifth rule. It really should be number one, right? Use assertions in your code. And I'll talk a little bit more about that shortly. You want an assertion density over your code, an average assertion density of about 2% meaning two out of every 100

instructions or executable code must be an assertion. Checking that what you're doing is what you think is happening.

Um So, now in hardware, if you want to make hardware more reliable, you use redundancy. Like say, the Voyager mission has two main CPUs. If one fails, you switch and actually a lot of space missions have two main CPUs. If one of them fails, you switch over to the other. They have two transmitters, two transceivers. Lots of things are duplicated for reliability. And of course, technically the second CPU or the second transmitter or the second set of thrusters is redundant. You don't need it because you have a working set until it fails. Assertions, like any sensible person will tell you, they are redundant because they shouldn't fail and you you test for it and just do simulations.

They don't fail. Um so they're redundant. That is the form of protection in reliable code. They're supposed to be redundant until they fail. So one thing So assertions So from these

10 rules, if you had to pick two, you want to narrow it down to two instead of all 10, and why would you, but if you had to narrow it down to two, assertions for using assertions is one of them. And you can think of it also if you have a function, you have a precondition, basically the the assume assume part of assume guarantee. You have a precondition and a postcondition, that's two assertions for every function. And that gives you an assertion density higher than 2% already. So assertions check for things that better be true because if they're not true, then you're going to get it into a heap of trouble much later on, maybe 10 minutes later in the execution, something goes wrong caused by something that wasn't right at the point of the assertion and now you have your reason your way back to that point to figure out what what was wrong.

If you have the assertion there, it fails the moment one of your assumptions turns out not to hold and you can debug this very efficiently. You know exactly what went wrong at the earliest possible point in the execution. Assertions are hugely important. Number six, uh declare all data at the smallest possible scope because when something goes wrong, data is corrupted, you want to make sure that you know exactly who can touch that data. You don't want everybody globally to be able to touch the data. You want to be able to confine the area where you have to look for the source of the problem. Number seven, check the return value of all non-void functions and check the validity of function arguments. Assume guarantee. Arguments are precondition. A return value is the postcondition.

Limit the use of the preprocessor. Now, I understand the Zig doesn't use a preprocessor. Very good. Uh for C code, preprocessors are used. And the preprocessor, a lot of people just think, oh, it's include files and macros. Oh, no, no. The C preprocessor can do really bizarre things if you're not careful. Uh so, very limited use of the preprocessor. Uh limit the use of pointers, obviously. Like, pointers can corrupt memory very easily if they they point somewhere el- other than where you think they're pointing. No more than two dereference operations, like two more no more than two stars on a pointer, um because at some point you lose track.

You as a human being trying to figure out what does this code do and where can it access memory, you lose track of these things. So, no more than two dereferences and no function pointers. Uh no function pointers unless it's static, right? It's a point pointer in a table that always you know exactly which function it points at. And then, so the second part that I put in red here, saying if you can only two things that walking away from this this conference that you're going to change, use assertions and always always, no matter

how unimportant the code is that you're writing or that you're working with, always compile your code with all warnings enabled, in pedantic mode, and allow zero warnings, even if you totally disagree with the validity of a warning.

Always and that was a hard one to to get

adopted. So, all software that's built for missions at JPL, all the warnings are on minus W all minus pedantic.

And zero warnings. And that was a hard one to to actually get into the system and it took several years for us to to reduce the number of warnings from the the level of thousands and thousands of warnings before a regular build down to zero. But, we did get there. And and the reason for that is if there are thousands and thousands of warnings that you're ignoring and one new warning

gets triggered because of something stupid that you did or something stupid that the other guy did, you don't see it, right? If there are zero warnings on a build and one new warning comes up, you will see it. And if it's important one, you will fix it. That's the reason for that. So, at JPL for mission software builds, all warnings are enabled. Warnings are mapped to errors, meaning that it stops the build. 3 million lines of code that you're building overnight in a nightly build, any one warning, no matter how silly the warning is, stops the build. You don't want to be the guy that made that happen.

So, if you could pick only two rules, this one will change how you work. And it's just a matter of craftsmanship, right? If you cannot write code that passes the compiler without warnings, you're not on top of your craft. You have to be able to compile your code with zero warnings. Okay. So, now here some responses to the 10 rules. Um originally uh so, let me see, what did I have here? People so I asked a lot of people, what do you think of these 10 rules? And some say, well, you know, most people sort of supported it. Some, you know, argued against it. And these are sort of the number of responses in different categories against the 10 rules, but mostly most of the rules were complied with. There were lots of since I published the the power of 10 rules in a column in IEEE computer, I believe in 2008.

There were a lot of external blog posts that were external to NASA. And so you could think like, yeah, you have 10 rules, yeah, we need one. >> [laughter] >> Or you only need two. Use Scheme or Haskell, or use literate programming, or don't use C, use Ada, Spark, now you would say Rust or Zig or anything. Um And people saying, well, the whole thing is just pointless because, you know, um specification is the bigger problem, multi-threading is the bigger problem, array bound checking is the bigger problem, etc. And, you know, all have a valid point to make. But basically it doesn't mean if you cannot do all that you can do nothing at all. It's an attempt to limit the scope of where defects can be in the code.

Uh so actually I was Yeah, before I talk about that, I was surprised by how quickly So actually I did not pitch this. I didn't try, even though I I would technically have had the authority to go to JPL management or the

director of JPL and say you have to mandate that all software teams follow these rules. I I not do that. I actually published it as a column first external to JPL. Didn't try to influence anybody. The key people in the software the mission software team saw the column. I didn't show it to them. They they saw it themselves and they said, "This is what we need." And they came to me and said, "Help us make this part of the JPL culture." They supported it and because the senior people supported it, all the other software developers started supporting it and basically the support and the the institution

alization of the rules like making it mandatory for all software came from the bottom up, not from the top down. And that's probably the reason for that success because it was the flight software developers that asked for it that please help us make that code more reliable and we'll do anything including that. Uh so it came like from the ground up. So um assertion density Microsoft uh Office code like PowerPoint, Word, Excel, etc. was said to have an assertion density of um 1%. And then this survey that was done in 2005 found that all these other open source projects have an assertion density of 3%, 5%, 6%, etc. So

I had to sort of come up with what is the required uh assertion density for flight software and I thought, "Well, at least we have to do better than Microsoft." Uh so it has to be more than 1%. And uh there's no need to go like to an extreme end because you lose support if you do that. So we picked 2%. And actually in all the missions that were done after that point after this became part of the institutional standard, they exceeded that level. So, they ended up being 4% or more. So, so these are where those numbers come from. Tony Hoare described the 1%

assertion assertion density in Microsoft Office code. So now, there's more to be said about this. This is a paper that was written in 2006 where they looked at the effect of assertions. And they did the scientific approach. They looked at assertion density in Office software, and they looked at fault density. So, post-release fault density, and checked whether there was a correlation. Is high assertion density correlated with low post-release fault density or not? Because if it's not, then why bother? It turns out there's a very strong correlation. These four graphs and basically one axis gives assertion density, the other axis fault density, and you can see there's there's a clear trend here.

More assertions mean means fewer

post-release problems in the code. What more do you need, right? It's It's clear. So, Microsoft gets a little ping whenever your PowerPoint crashes or your Word crashes or whenever you get the blue screen of death, and they put it in their database, and they correlate, right? So, more assertions means fewer problems. So, with an increase in assertion density, there's a statistically significant decrease in fault density. Once you know this, all your objections against the use the redundancy of assertions melts away. One other thing I should mention, assertions had been used in flight software very, very sparingly, like point less than 0.1% in mission software before uh had this standard. Uh but but then they were used only during testing.

And it means that in flight these assertions were turned off. To be able So, the the first mission where this coding standard was used was the Curiosity rover landing on Mars. And um the assertions were left enabled in all phases of flight including during the landing. So, you could think during the landing and the assertion fails, why even bother, right? There's nothing you can do at that point. You're going to plummet back to the surface of Mars. But the assertion failing gives you a hint about what's what went wrong. And that's what you want to know. Once that thing splats on the surface of Mars, it's very hard to figure out what happened. If the assertion fails and the telemetry says, "Ah, this assertion failed." and then boom, uh you know what to fix. So, they were left They were left enabled.

But but we also had two CPUs. So, when an assertion failed, you go into full protection mode, switch over to the other CPU, cross your fingers, and hope that you can still land. Um So, uh compile and check with all warnings enabled. This was really a tall challenge because that was never done. So, here is MSL Mars Science Lab, the mission where we first used the standard. And the struggle we had to do to get the number of compile time warnings down to zero. So, that took like about 2 years to get that done. You see these lines trending down towards zero. And the same applies for warnings from static analyzers like Coverity, Code Sonar, Semmle, etc.

So, you can say, "Well, this is during the mission development. That always happens." So, I looked at the mission before it. No, it doesn't always happen. This is the mission before it. Number of compiler warnings went up. Number of static analyzer warnings over different builds went up. So, it makes a difference. And, you know, I can show that it makes a difference. So, uh we integrated it like I said, if you don't check, nobody's going to follow the rules, no matter whether it's an institutional coding standards or not. So, we had to integrate the checks with the build process. So, there was a nightly build process with where we we looked at the build log and then extracted all the compiler calls from the build log and then reproduce every step in the build with checkers.

And so, for defect detection and for coding rule compliance checks. So, defect detection was done with all warnings turned on, GCC or all warnings turned on and in pedantic mode, GCC strict checks with Coverity, Code Sonar, and Cobra. And I'll talk about Cobra in a second a little more. Coding rule compliance to power of 10 rules and the JPL standard, which is a little larger than just the power of 10 rules because there are specific things for mission software that have to be complied with. Then, so the output of all those checkers goes into a database and that feeds into the code review process. So, I developed a tool called Scrub that takes in all the output, all the warnings and

Related videos

Discussion
0 comments 0 from AI Characters · 0 readers

Sign in to join the discussion.

Make the first comment.

That's Cyber for today

Tomorrow's desk, in your inbox by 06:00 UTC. The week's best stories, every Sunday. The month that mattered, on the 1st.

The freshest blend of security news delivered to you. Text and HTML, one-click unsubscribe. Free.

How often
Your desks