diff options
author | Martin Nowack <m.nowack@imperial.ac.uk> | 2018-07-29 16:17:32 +0100 |
---|---|---|
committer | Cristian Cadar <c.cadar@imperial.ac.uk> | 2018-10-24 14:15:25 +0300 |
commit | a1afcbf98c455ed52fc341df104e19a5d000095f (patch) | |
tree | 6a1b61f9286d4b77da54976825f254541860d16c /test | |
parent | 5bca619d7c11273e9492fa01fc7492e2cbb4eff5 (diff) | |
download | klee-a1afcbf98c455ed52fc341df104e19a5d000095f.tar.gz |
Add test case for div checker
Check that only important div instructions are annotated. Check the optimized case as well: the call to the validating function might not be part of the code anymore but already inlined - make sure the instruction still has the metadata attached.
Diffstat (limited to 'test')
-rw-r--r-- | test/Feature/DivCheck.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/test/Feature/DivCheck.c b/test/Feature/DivCheck.c new file mode 100644 index 00000000..219648a9 --- /dev/null +++ b/test/Feature/DivCheck.c @@ -0,0 +1,48 @@ +// Check if div-instructions are correctly instrumented: +// * unoptimized code will contain a call to klee_div_zero_check +// * optimized code will have this check inlined +// In both cases, the `div` instruction should have been marked with meta-data: klee.check.div +// +// RUN: %llvmgcc %s -emit-llvm -g -c -o %t.bc +// RUN: rm -rf %t.klee-out +// RUN: %klee --output-dir=%t.klee-out --check-div-zero=true %t.bc >%t.div_enabled.log +// RUN: FileCheck %s -input-file=%t.klee-out/assembly.ll -check-prefix=DIV-ENABLED +// RUN: rm -rf %t.klee-out +// RUN: %klee --output-dir=%t.klee-out --check-div-zero=true --optimize %t.bc >%t.div_enabled.log +// RUN: FileCheck %s -input-file=%t.klee-out/assembly.ll -check-prefix=DIV-ENABLED-OPT +// Without debug information +// RUN: %llvmgcc %s -emit-llvm -c -o %t.bc +// RUN: rm -rf %t.klee-out +// RUN: %klee --output-dir=%t.klee-out --check-div-zero=true %t.bc >%t.div_enabled.log +// RUN: FileCheck %s -input-file=%t.klee-out/assembly.ll -check-prefix=DIV-ENABLED +// RUN: rm -rf %t.klee-out +// RUN: %klee --output-dir=%t.klee-out --check-div-zero=true --optimize %t.bc >%t.div_enabled.log +// RUN: FileCheck %s -input-file=%t.klee-out/assembly.ll -check-prefix=DIV-ENABLED-OPT +#include "klee/klee.h" +#include <stdio.h> + +int main(int argc, char **argv) { + char c; + + klee_make_symbolic(&c, sizeof(c), "index"); + + // Validate + if (argc / c == 5) + return 1; + // Check that div has been instrumented once + // DIV-ENABLED: call {{.*}}void @klee_div_zero_check({{.+}} %{{.+}}) + // DIV-ENABLED-NOT: call {{.*}}void @klee_div_zero_check + // Check that div has the proper metadata + // DIV-ENABLED: sdiv {{.*}} !klee.check.div + // DIV-ENABLED-OPT: sdiv {{.*}} !klee.check.div + + // Validate + if (argc / 5 == 5) + return 1; + // Check that div has not been instrumented + // DIV-ENABLED-NOT: call {{.*}}void @klee_div_zero_check(i64 5) + // DIV-ENABLED-NOT: sdiv {{.*}} !klee.check.div + // DIV-ENABLED-OPT-NOT: sdiv {{.*}} !klee.check.div + + return 0; +} |