gcov: add one more pytest

gcc/testsuite/ChangeLog:

	* g++.dg/gcov/gcov-17.C: New test.
	* g++.dg/gcov/test-gcov-17.py: New test.
This commit is contained in:
Martin Liska 2021-01-14 17:08:32 +01:00
parent 236d6a33ca
commit 7624c58c6b
2 changed files with 77 additions and 0 deletions

View File

@ -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" } } */

View File

@ -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