Repository navigation
Examples
Now that you have FlipIt installed, let's walk though several examples to better understand FlipIt.
- Test Pass
- Sequential
- Matmul
- Countdown
- MPI
- Jacobi
This simplistic example shows the minimum code that needs to be added to enable corruptions via FlipIt.
#include <stdio.h>
#include "/home/aperson40/Documents/FlipIt//src/corrupt/corrupt.h"
int main(int argc, char** argv)
{
int a = 2, b=2;
int rank = 0;
int seed = 7;
FLIPIT_Init(rank, argc, argv, seed);
printf("Should be corrupted: %d + %d = %d\n", a, b, work(a, b));
FLIPIT_Finalize(NULL);
return 0;
}
Walking though the code we see the inclusion of a header file corrupt.h. This header file defines all API functions in FlipIt. Inside the function main we see calls to FLIPIT_Init and FLIPIT_Finalize. Calls to these functions should bound all execution of code instrumented by FlipIt's compiler pass. Should this not be the case segfaults can occur!
FLIPIT_Init's first argument is the rank of the current process (uses MPI terminology). For all sequential applications this argument can be set as 0. The last argument is a seed number that seed FlipIt's internal random number generator. This value should differ between runs to generate differing sequence of random numbers.
FLIPIT_Finalize's lone argument is the name of the file that it should write the histogram of fault site traversal to.
The function work is corrupted during the compilation process. It is corrupted using the following terminal commands to replace a normal compilation step cc -c work.c -o final.o
clang -g -emit-llvm work.c -c -o work.bc
llvm-link $FLIPIT_PATH/src/corrupt/corrupt.bc work.bc -o crpt_work.bc
opt -load $LLVM_BUILD_PATH/Release+Asserts/lib/FlipIt.so -FlipIt -singleInj 1 -prob 0.95 -byte -1 -arith 1 -ctrl 0 -ptr 0 -funcList "" < crpt_work.bc > final.bc
clang -g -c final.bc -o final.o
Command 1 compiles the C code to LLVM bitcode.
Command 2 links the resulting bitcode to a bitcode header file declaring FlipIt's corruption functions. Command 3 runs the fault injection compiler pass over the bitcode. In this case we want a single injection (-singleInj 1), a fault probability of (-prob 0.95), the injection can be in any byte of the data type (-byte -1), we want only injections into arithmetic and not control or pointer type instructions (-arith 1 -ctrl 0 -ptr 0), corrupt all functions defined in this file (-funcList ""), bitcode file to transform, and finally the output file name.
Command 4 compiled the instrumented bitcode into the object code we need for linking with other files.
In this case, the log file that is generated is displayed on the terminal prompt as command 3 is run. In practice this is written to a file on disk.