Showing posts with label Toyota. Show all posts
Showing posts with label Toyota. Show all posts

Tuesday, June 13, 2017

Cost of an Error: Who Pays for Programming Blunders?

By Anastasia Zubkova 
Modern programmers live in a very special period of time, when the software is penetrating into literally all spheres of human life and is installed on a numerous amount of devices that are a part of our every day life. Nobody is surprised by software in the fridges, watches and coffee-machines. However, the dependence of people on the smart technology is also growing. The inevitable consequence: the reliability of the software becomes priority number 1. It's hard to scare someone with a freaked out coffee-maker, although it can bring a lot of harm (liters of boiling coffee flowing on your white marble countertop...). But the thought of growing requirements for the quality of software is really important, that's why let's talk about errors in the code that led to significant waste of time and money.
Picture 2
The aim of these stories is to fight against the idea that defects in programs can be treated as lightly as they were before. Errors in programs now aren't just incorrectly drawn units in a game, the code is now responsible for people's health and safety of property. In this article I would like to cover several new examples of the necessity to treat code really thoughtfully.


It's undeniable that complex programs are getting in our live more actively: household appliances controlled by a smartphone, gadgets, which obtained such features that were hard to imagine 10 years ago and of course, more complex software on the factories, cars and so on; any program created by a person, and the smarter it is, the more dangerous is its failure.
Let's talk about money lost because of errors in the software and the growth of our dependence of the program code. This topic has been repeatedly discussed (also by me colleague Andrey Karpov "The Big Calculator Gone Crazy") and every new example proves the same: the code quality is not something you can ignore.
Picture 1

Space

An Expensive Overline

Mariner 1 satellite was supposed to reach Venus. Launched from Cape Canaveral, the rocket almost immediately changed the trajectory, which created a threat to fall on the ground. To prevent a possible catastrophe, NASA made a decision to start the self-destruction system. Mariner 1 was destroyed 293 seconds after the launch.
Picture 3
The inspection committee conducted a research, during which they found that the cause of the accident was a programming error because of which a program received incorrect control signals.
The most detailed and consistent account was that the error was in hand-transcription of a mathematical symbol in the program specification for the guidance system, in particular a missing overbar. The error had occurred when a symbol was being transcribed by hand in the specification for the guidance program. The writer missed the superscript bar (or overline) in the formula (by which was meant "the n-th smoothed value of the time derivative of a radius R").
Since the smoothing function indicated by the bar was left out of the specification for the program, the implementation treated normal minor variations of velocity as if they were serious, causing spurious corrections that sent the rocket off course (source).
The cost of the "missing overbar" - 18 million dollars (for that time).

Russian GPS that Drowned

Another vivid example of how millions can get lost because of a programming error, is a relatively recent case. It should seem that in the 21st century there is everything necessary for writing secure programs, especially when we talk about the space industry. Experienced professionals with excellent education, financing, possibility to use best tools for testing the software. All of this didn't help. December 5, 2010, a carrier-rocket "Proton-M" with three satellites "Glonass-M" - a Russian equivalent of GPS, crashed in the Pacific Ocean.
Picture 5
The reason of the accident after the investigation was announced by an official representative of the Prosecutor-General's Office of the Russian Federation Alexander Kurennoy: "The investigation has established that the crash was due to the application of a wrong formula, which resulted in putting additional 1,582 kilograms of liquid oxygen into the acceleration unit's oxidizer tank. This error led to the carrier rocket's injection into an open orbit and its subsequent fall into the Pacific Ocean". (source
An interesting point is that the document on the need for adjustment of the formula was submitted to the organization's relevant department but was written off by the engineer as fulfilled. The authorities didn't verify the way their directives were carried out. All those involved in the accident, were convicted of a criminal offense and imposed large fines. Still, that doesn't compensate the loss of 138 million dollars.

Cars

Back in 2009, Manfred Broy, a professor of informatics at Technical University, Munich, and a leading expert on software in cars said: "it [every premium-class automobile] probably contains close to 100 million lines of software code" (source) It's been eight years since that moment and even if you aren't a fan of TopGear, you may have noticed that modern cars have become real intelligent machines.
According to the expert, the cost of the software and electronics in the car is about 40% of its price on the market. And this applies to gasoline engines, just think about hybrids and electric cars, where this value is approximately 70%!
When electronic filling becomes more complex than mechanical, it puts more responsibility on software developers. A bug in one of the key systems such as braking, is much more dangerous than a torn brake hose.
So here is a question - drive modern, comfortable and "smart" cars or oldschool, but simple cars? It's up to you to decide, I am suggesting you a selection of bugs in the software of cars.

Toyota again

Japanese Toyota cars have positive reputation in general, but from time to time the media shows information about withdrawal of a number of machines. There is already an article in our blog about a software bug in Toyota - "Toyota: 81 514 issues in the code", but unfortunately, this is not the only case.
Picture 6
In the year 2005, 160 thousand Toyota Prius hybrids were withdrawn, manufactured in the end of 2004, beginning of 2005. The problem was that the machine could stop and conk out. It took about 90 minutes to fix the bug on one vehicle, in sum total about 240 man-hours.

Chrysler and Volkswagen

In May 2008, Chrysler withdrew 24535 Jeep Commanders cars manufactured in 2006. The reason was a programming error in the automatic transmission control module. The failure resulted in uncontrolled stop of an engine.
In June of the same year, Volkswagen recalls approximately 4000 Passat and 2500 Tiguan cars . In this case the software error caused the increase in the engine rotational rate. Tachometer registration was going up when the air conditioner is turned on.
Needless to say, that the process of car withdrawal is associated with enormous financial losses. What is much more dangerous for such huge manufacturers besides the financial expenses is the loss of consumer trust. Taking into account the toughness of the competition on the automotive market, such a mistake may have very negative consequences. Restoring a reputation as a reliable manufacturer may be very difficult.

Tesla

Previously we were speaking about usual vehicles, manufactured not really long ago. As you see, even they may have software errors, what can we say about actively marketed environmentally friendly electric cars.
Let's talk about Tesla Model S, of course. May 7, 2016, Joshua Brown, who became famous due to his You Tube videos where he praises this car, got into an accident. He was driving Tesla Model S. Being 100% sure in the intellect of the car, he entrusted the autopilot. The result of this trust is tragic - Joshua died at the scene due to injuries received in the crash.
The accident gained wide publicity. An investigation started. The research showed that apparently, Brown wasn't really keeping his eyes on the road, and the autopilot got into a situation that wasn't programmed in his code. There was a truck with a trailer moving in front of Joshua's Tesla car. The car planned to make a manoeuvre - to turn left, which required slower speed. But the Tesla car, going behind, didn't start slowing down, as the autopilot systems didn't recognize the object located ahead.
Most likely, it happened because of the bright sun. Immediately after the crash, the explanation for the failure (put forth by Tesla) was that the car likely failed to distinguish the white tractor trailer from the sky. The official report states the following: "braking for crossing path collisions, such as that present in the Florida fatal crash, are outside the expected performance capabilities of the system." (source). The complete accident report is freely available to the public.
In other words, the autopilot is meant to help the driver (more advanced cruise-control, so to say), but not to replace the functions. Of course, such an excuse from Tesla company wasn't a great help. The work on the software continued, but Tesla Model S weren't withdrawn.
Picture 7
The representatives of the company shared such road stats: "On average, one person dies on U.S. highways for every 90 million vehicle miles traveled. In contrast, people had driven Tesla's autopilot 130 million miles before the first confirmed death. That number is now up to 200 million." (source).
On the one hand, such statistics show that electric cars are safer, but are you ready to entrust your life, the life of the passengers and other road users to a program?
And this is not a rhetorical question. Judging by the exchange news, contrary to the sensational accident, the Tesla shares grew up to 50% in 2017. Two major factors of this: the popularity of environmental improvement and eco-friendly movements and high personal rating of the Tesla head - Elon Musk.

The world level - year 2038 problem

I couldn't help bringing this example at the end of the article here. You may read more about the Year 2038 Problem in the article "2038: only 21 years away", but I would like to point to an important point.
Equipment for factories: all kinds of machines, conveyors, home appliances and other complex facilities, equipment with specialized software have quite a long service life. The probability that a machine manufactured in 2017 will be still working in 2038 is quite high. Hence, it is logical to conclude: the problem when 32-bit values of time_t type will no longer be able to correctly display the dates is already relevant!
If the software developers don't take that into account now, what will happen in 2038? There is every chance that, the software for embedded systems will bring quite a number of surprises. I believe, we will be witnessing that.

Conclusion

Perhaps the examples given in the article seem too epic. Of course, only tragic cases get the public attention. But I am sure that in every company engaged in software development, there is a story about how just one mistake has caused a lot of problems, albeit local ones.
Is it possible to find whom to blame? Sometimes yes, sometimes no. There is no point in finding the guilty person and chastise him/her. The idea is that the programs get more complex, they are penetrating into our lives more and more, which means that the requirements for the code reliability are also growing. The price of the typical errors is increasing, and the responsibility for the code quality falls on the shoulders of the developers.
What is the solution? Modernize the development process. Provide assistants for programmers - special programs for detection and fixing of bugs. Complex use of modern techniques significantly decreases the probability that a bug in the code will not be detected at the development stage.

I wish you not to make errors in the code, so that your projects never get to the list of that projects you have just read about.

Thursday, October 13, 2016

Toyota: 81 514 issues in the code

A story about the fact that the software is penetrating more and more in our daily life. However, with the comfort and usefulness come new dangers. Now we deal with the bugs not only sitting at the computer, but driving on a road.
Picture 1
  • People: Hey, Toyota, we counted that 89 people died from 2000 to 2010 because of your screwed up your electronics and software.
  • Toyota: Yes, but these are people to blame, they confuse the pedals.
  • People: Houston, we have a problem.
  • NASA: Wait a little, we'll sort it out. We'll need 10 months and 3 million dollars.
  • People: Here, take it.
  • Toyota: 3 million isn't enough, here's some more cash.
(10 months later)
  • NASA: Hey, Toyota, we found a couple of bugs in your code, namely 7134 MISRA standards violations, recursion, 740-string long function and 9000 global variables.
  • Toyota: We have our own standards. Have you guys, been to the Moon?
  • NASA (publicly): Toyota is not to blame.
  • (Toyota Shares went up by 4.6%)
  • People: What was that?
(3 years later)
  • Two American testers (whose grandfathers died at Pearl Harbor): No bugs you say? What if we find them?
The National Highways Traffic Safety Administration (NHTSA), have evaluated that in the 10 year period from 2000 till 2010, in accidents caused by defective electronics, 89 people died and 57 people were seriously injured.
Toyota denies its fault, and states, based on their own research, that it's all because of "sticking" accelerator pedals, and a design flaw that enabled accelerator pedals to become trapped by floor mats, but recalls nearly 8 million vehicles around the world because of these two defects.
Still, there are more complaints coming.
We recommend that those with a nervous disposition not watch this video.
NHTSA started their own investigation, asking NASA to help.
During the 10-month investigation, NASA specialists claimed that the software does not comply with MISRAstandards (Motor Industry Software Reliability Association), and contains 7134 violations. Toyota responded, saying that they have their own standards.
December 20 2010, Toyota rejects all the accusations, but pays 16 billion dollars in pre-trial actions, releases software updates for some car models, and recalls 5.5 million vehicles.
After the announcement of the results of NASA's research, Toyota shares on the Tokyo Stock Exchange went up by 4.6%.
In the year 2013, an action is filed in Oklahoma Court in regards to an accident in 2007, involving two girls in a 2005 Toyota Camry. One of them died, the other spent five months in a hospital with injuries to the back and head. Toyota has not admitted its guilt. They said that the cause of the accident was the driver confusing the gas pedal and the brakes; when she realized her mistake and started braking — it was too late.
Picture 22
Two engineers started the investigation. Michael Barr and Philip Koopman. It took them 20 months to review 280 000 lines of code and write a 800-page long report. Each.
The address was kept in secret. The hotel room, where the engineers worked was guarded 24 hours a day - security ensured that nobody was bringing in or taking out any papers. All the phones and internet connections were disabled.
Toyota recalled more than 10 million vehicles worldwide. Still, they have never admitted their guilt.
According to Michael Barr, their report was classified as secret. The same thing was done with the contract which gave them access to Toyota's source code. Barr recommends Googling the transcript of the hearing material.
Here is where the analysts worked:
Picture 4
Here is the report they wrote:
Picture 6

What they looked for and what they found

The main program in the dock is the electronic throttle control system (ETCS).
Picture 8
Picture 10
NASA experts scanned the chips with x-rays.
Picture 12
Cosmic rays were also considered as a possible cause of errors.
They checked the C code:
Picture 14
And then they finally got at the code.

Violations of MISRA (and NASA) standards

According to estimates, every 30 MISRA standard violations lead to one "serious bug".
  • In MISRA-C:1998 - the list contains 127 rules (93 mandatory and 34 advisory)
  • In MISRA-C:2004 141 rules (121 mandatory and 20 advisory). The rules are divided into 21 categories.
  • In MISRA-C:2012 there are 143 rules (each of them can be checked by a static code analyzer) and 16 directives (whose compliance is more open to interpretation, or relates to process or procedural matters). The rules are divided into mandatory, required, and advisory; can be applied to individual units or the entire system. The rules are divided into Decidable and Undecidable.
Toyota took only 11 rules from MISRA.
Picture 15
Picture 17
NASA analysis tools were able to check 35 MISRA rules, and 14 of them were violated.
Picture 19
The source - NASA report, appendix A: Software, page 28]
Total: 7134 (NASA estimation), or 81 514 (according to Michael Barra's estimations).
10 rules of NASA
The Power of Ten - 10 Rules for Writing Safety Critical Code
  • Restrict to simple control flow constructs.
  • Give all loops a fixed upper-bound.
  • Do not use dynamic memory allocation after initialization.
  • Limit functions to no more than 60 lines of text.
  • Use minimally two assertions per function on average.
  • Declare data objects at the smallest possible level of scope.
  • Check the return value of non-void functions, and check the validity of function parameters.
  • Limit the use of the preprocessor to file inclusion and simple macros.
  • Limit the use of pointers. Use no more than two levels of dereferencing per expression.
  • Compile with all warnings enabled, and use one or more source code analyzers.
[The source - spinroot.com/p10]
Picture 21
The function length is limited to 60-75 code strings, after removing empty strings and comments. More than 200 functions in Camry05 code exceeded the specified length. One of the functions was 740 strings long.

Variables

31 names were declared several times in different scopes. The most frequent name is sts_flags1, which appeared in 57 different scopes.
Picture 42
Picture 26
This is worth a closer look.
Picture 28
Picture 30

Misleading code

Picture 31
A graph of the flow control of a simple program.
Cyclomatic complexity of the program above 50 - an indicator that the program cannot be tested.
Picture 33
In the ETCS-code Toyota has:
  • 67 functions with complexity above 50
  • The complexity of Throttle angle function = 146; 1300 code strings without the plan for unit testing.

Recursion

Picture 35
Programmers used the recursion in the Toyota code, every issue related to its usage led to the restart of the processor (CPU reset).

And so?

The amount of shitty code, on which the lives of people depends on, gets bigger. The example of the Toyota company, shows that the system developers can screw the code on an elementary level, not to mention, on the level of accepting the ethical decisions of the artificial intelligence. Although the main trouble is not that there are errors, but the fact that the owners hinder their process of finding and fixing the issues. These people are powerful enough to push on NASA.
Picture 37
"Applications programming is a race between software engineers, who strive to produce idiot-proof programs, and the universe which strives to produce bigger idiots. So far the Universe is winning."
- Rick Cook, writer

Media

Investigation report

An exhaustive presentation of Philippe Kupmana's:
NASA Report on Toyota Unintended Acceleration Investigation
NHTSA Report on Toyota Unintended Acceleration Investigation
Picture 39
Four years before that
Picture 40
Wherever I'm going, I'll be there to apply the formula. I'll keep the secret intact.
It's simple arithmetic.
It's a story problem.
If a new car built by my company leaves Chicago traveling west at 60 miles per hour, and the rear differential locks up, and the car crashes and burns with everyone trapped inside, does my company initiate a recall?
You take the population of vehicles in the field (A) and multiply it by the probable rate of failure (B), then multiply the result by the average cost of an out-of-court settlement (C). A times B times C equals X. This is what it will cost if we don't initiate a recall.
If X is greater than the cost of a recall, we recall the cars and no one gets hurt.
If X is less than the cost of a recall, then we don't recall.
- Chuck Palahniuk "Fight club", 1996
- How often do such accidents happen?
- You won't believe it.
- Which company do you work for?
- Oh, it's a very large one.
- "Fight club", film, 1999.
This article was originally published (in Russian) on habrahabr.ru. The original and translated versions were posted on our blog with the permission of the author.