summaryrefslogtreecommitdiff
path: root/test/tools/llvm-cov/Inputs/test.cpp
diff options
context:
space:
mode:
authorYuchen Wu <yuchenericwu@hotmail.com>2013-11-12 04:52:53 +0000
committerYuchen Wu <yuchenericwu@hotmail.com>2013-11-12 04:52:53 +0000
commitd99e04db6a9a8d58dcfdd958d1a4f00c7d518c9d (patch)
treecd16b8ee0f8f774241011a96cedb8d673466a7d7 /test/tools/llvm-cov/Inputs/test.cpp
parent86245071b52f1da99ac65157c38bfa5577a80714 (diff)
downloadllvm-d99e04db6a9a8d58dcfdd958d1a4f00c7d518c9d.tar.gz
llvm-d99e04db6a9a8d58dcfdd958d1a4f00c7d518c9d.tar.bz2
llvm-d99e04db6a9a8d58dcfdd958d1a4f00c7d518c9d.tar.xz
Added basic unit test for llvm-cov.
This test compares the output of llvm-cov against a coverage file generated by gcov. Since the source file must be in the current directory when reading GCNO files, the test will first cd into the Inputs directory. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194451 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/tools/llvm-cov/Inputs/test.cpp')
-rw-r--r--test/tools/llvm-cov/Inputs/test.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/test/tools/llvm-cov/Inputs/test.cpp b/test/tools/llvm-cov/Inputs/test.cpp
new file mode 100644
index 0000000000..07bc3f294c
--- /dev/null
+++ b/test/tools/llvm-cov/Inputs/test.cpp
@@ -0,0 +1,77 @@
+#include <cstdlib>
+
+bool on = false;
+int len = 42;
+double grid[10][10] = {0};
+const char * hello = "world";
+const char * world = "hello";
+
+struct A {
+ virtual void B();
+};
+
+void A::B() {}
+
+void useless() {}
+
+double more_useless() {
+ return 0;
+}
+
+int foo() {
+ on = true;
+ return 3;
+}
+
+int bar() {
+ len--;
+ return foo() + 45;
+}
+
+void assign(int ii, int jj) {
+ grid[ii][jj] = (ii+1) * (jj+1);
+}
+
+void initialize_grid() {
+ for (int ii = 0; ii < 2; ii++)
+ for (int jj = 0; jj < 2; jj++)
+ assign(ii, jj);
+}
+
+int main() {
+ initialize_grid();
+
+ int a = 2;
+ on = rand() % 2;
+ if (on) {
+ foo();
+ ++a;
+ } else {
+ bar();
+ a += rand();
+ }
+
+ for (int ii = 0; ii < 10; ++ii) {
+ switch (rand() % 5) {
+ case 0:
+ a += rand();
+ break;
+ case 1:
+ case 2:
+ a += rand() / rand();
+ break;
+ case 3:
+ a -= rand();
+ break;
+ default:
+ a = -1;
+ }
+ }
+
+ A thing;
+ for (uint64_t ii = 0; ii < 4294967296; ++ii)
+ thing.B();
+
+ return a + 8 + grid[2][3] + len;
+ return more_useless();
+}