gcov: add one more pytest
authorMartin Liska <mliska@suse.cz>
Thu, 14 Jan 2021 16:08:32 +0000 (17:08 +0100)
committerMartin Liska <mliska@suse.cz>
Thu, 14 Jan 2021 16:08:32 +0000 (17:08 +0100)
gcc/testsuite/ChangeLog:

* g++.dg/gcov/gcov-17.C: New test.
* g++.dg/gcov/test-gcov-17.py: New test.

gcc/testsuite/g++.dg/gcov/gcov-17.C [new file with mode: 0644]
gcc/testsuite/g++.dg/gcov/test-gcov-17.py [new file with mode: 0644]

diff --git a/gcc/testsuite/g++.dg/gcov/gcov-17.C b/gcc/testsuite/g++.dg/gcov/gcov-17.C
new file mode 100644 (file)
index 0000000..d11883c
--- /dev/null
@@ -0,0 +1,40 @@
+/* { dg-options "--coverage -std=c++11" } */
+/* { dg-do run { target native } } */
+
+template <class T> class Foo
+{
+public:
+  Foo () : b (1000) {}
+
+  void inc () { b++; }
+
+private:
+  int b;
+};
+
+template class Foo<int>;
+template class Foo<char>;
+
+int
+main (void)
+{
+  int i, total;
+  Foo<int> counter;
+
+  counter.inc ();
+  counter.inc ();
+  total = 0;
+
+  for (i = 0; i < 10; i++)
+    total += i;
+
+  int v = total > 100 ? 1 : 2;
+
+  if (total != 45)
+    __builtin_printf ("Failure\n");
+  else
+    __builtin_printf ("Success\n");
+  return 0;
+}
+
+/* { dg-final { run-gcov-pytest gcov-17.C "test-gcov-17.py" } } */
diff --git a/gcc/testsuite/g++.dg/gcov/test-gcov-17.py b/gcc/testsuite/g++.dg/gcov/test-gcov-17.py
new file mode 100644 (file)
index 0000000..ec5df3d
--- /dev/null
@@ -0,0 +1,37 @@
+from gcov import gcov_from_env
+
+import pytest
+
+
+@pytest.fixture(scope='function', autouse=True)
+def gcov():
+    return gcov_from_env()
+
+
+def test_basics(gcov):
+    files = gcov['files']
+    assert len(files) == 1
+    functions = files[0]['functions']
+    assert len(functions) == 5
+
+
+def test_lines(gcov):
+    lines = gcov['files'][0]['lines']
+    linesdict = {}
+    for line in lines:
+        lineno = int(line['line_number'])
+        linesdict.setdefault(lineno, [])
+        linesdict[lineno].append(line)
+
+    line9 = linesdict[9]
+    assert len(line9) == 2
+    assert line9[0]['function_name'] == '_ZN3FooIcE3incEv'
+    assert line9[1]['function_name'] == '_ZN3FooIiE3incEv'
+    assert line9[0]['count'] == 0
+    assert line9[1]['count'] == 2
+    assert line9[0]['unexecuted_block']
+    assert not line9[1]['unexecuted_block']
+    assert linesdict[31][0]['unexecuted_block']
+    assert linesdict[34][0]['unexecuted_block']
+    assert not linesdict[37][0]['unexecuted_block']
+    assert 32 not in linesdict