Fault Injection in Software Engineering

24 Jun, 2019
Fault Injection is a technique for enhancing the testing quality by involving the intentional faults in the software. Fault injection is often in stress testing and it is considered as an important part of developing robust software.
The broadcast of a fault through to an noticeable failure follows a well defined cycle. During execution a fault can cause an error which is not a valid state within a system boundary. Same error can cause further errors within the system boundary, hence each new error acts as a fault and it may propagate to the system boundary and be observable. When an error state is observed at the system boundary that is called as failure.
Classification of Fault Injection:Fault injection can be categorized into two types on the basis of software implementation: Compile-time fault injection and Run-time fault injection. These are explained as following below.
1. Compile-time fault injection:Compile-time fault injection is a fault injection technique in which source code is modified to inject imitated faults into a system.
Two methods are used to implement fault while compile time:
Code Modification:Mutation testing is used to change existing lines of code so that there may exist faults. Code mutation produces faults which are similar to the faults unintentionally done by programmers.Example:Original Code:
int main()
{
  int a = 10;
  while ( a > 0 )
  {
    cout << "GFG";
    a = a - 1;
  }
  return 0;
}

Modified Code:
int main()
{
  int a = 10;
  while ( a > 0 )
  {
    cout << "GFG";
    a = a + 1; // '-' is changed to '+'
  }
  return 0;
} Now it can be observed that value of a will increase and "while loop" will never terminate and program will go into an infinite loop.
Example:
Original Code:
int main()
{
  int a = 10;
  while ( a > 0 )
  {
    cout << "GFG";
    a = a - 1;
  }
  return 0;
}

Modified Code:
int main()
{
  int a = 10;
  while ( a > 0 )
  {
    cout << "GFG";
    a = a + 1; // '-' is changed to '+'
  }
  return 0;
} 
Now it can be observed that value of a will increase and "while loop" will never terminate and program will go into an infinite loop.
Code Insertion:A second method of code mutation is code insertion fault injection which adds code instead of modifying existing code. This is basically done by the use of anxiety functions which are simple functions which take an existing value and change it via some logic into another value.Example:Original Code:
int main()
{
  int a = 10;
  while ( a > 0 )
  {
    cout << "GFG";
    a = a - 1;
  }
  return 0;
}

Modified Code:
int main()
{
  int a = 10;
  while ( a > 0 )
  {
    cout << "GFG";
    a = a - 1;
    a++; // Additional code
  }
  return 0;
} Now it can be observed that value of a will be fixed and "while loop" will never terminate and program will go into an infinite loop.
Example:
Original Code:
int main()
{
  int a = 10;
  while ( a > 0 )
  {
    cout << "GFG";
    a = a - 1;
  }
  return 0;
}

Modified Code:
int main()
{
  int a = 10;
  while ( a > 0 )
  {
    cout << "GFG";
    a = a - 1;
    a++; // Additional code
  }
  return 0;
} 
Now it can be observed that value of a will be fixed and "while loop" will never terminate and program will go into an infinite loop.
2. Run-time fault injection:Run-time fault injection technique uses a software trigger to inject a fault into a running software system. Faults can be injected via a number of physical methods and triggers can be implemented in different ways.
Software Triggers used in Run-time fault injection:
1. Time Based Triggers
2. Interrupt Based Triggers 
3 methods are used to inject fault while run-time:
Corrupting memory space:This method involves corrupting main memory and processor registers.System call interposition:This method is related with the fault imitation from operating system kernel interfaces to executing system software. This is done by intercepting operating system calls made by user-level software and injecting faults into them.Network level:This method is related with the corrupting, loss or reordering of network packets at the network interface.
Corrupting memory space:This method involves corrupting main memory and processor registers.
System call interposition:This method is related with the fault imitation from operating system kernel interfaces to executing system software. This is done by intercepting operating system calls made by user-level software and injecting faults into them.
Network level:This method is related with the corrupting, loss or reordering of network packets at the network interface.
Fault Injection in different software testings:
(a) Robustness Testing – In robustness testing fault injection is used.
(b) Stress Testing – fault injection is also used in stress testing.
Software Testing
Software Engineering
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Functional vs Non Functional Requirements
Differences between Verification and Validation
Unit Testing | Software Testing
Software Engineering | Classical Waterfall Model
Software Requirement Specification (SRS) Format
Difference between Spring and Spring Boot
Software Engineering | Requirements Engineering Process
Software Testing Life Cycle (STLC)
Difference between IAAS, PAAS and SAAS
Software Engineering | Architectural Design