From 7624c58c6b7b2b313c92b25ebbd267cf0ed7f7c4 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Thu, 14 Jan 2021 17:08:32 +0100 Subject: [PATCH] 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. --- gcc/testsuite/g++.dg/gcov/gcov-17.C | 40 +++++++++++++++++++++++ gcc/testsuite/g++.dg/gcov/test-gcov-17.py | 37 +++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 gcc/testsuite/g++.dg/gcov/gcov-17.C create mode 100644 gcc/testsuite/g++.dg/gcov/test-gcov-17.py diff --git a/gcc/testsuite/g++.dg/gcov/gcov-17.C b/gcc/testsuite/g++.dg/gcov/gcov-17.C new file mode 100644 index 00000000000..d11883cfd39 --- /dev/null +++ b/gcc/testsuite/g++.dg/gcov/gcov-17.C @@ -0,0 +1,40 @@ +/* { dg-options "--coverage -std=c++11" } */ +/* { dg-do run { target native } } */ + +template class Foo +{ +public: + Foo () : b (1000) {} + + void inc () { b++; } + +private: + int b; +}; + +template class Foo; +template class Foo; + +int +main (void) +{ + int i, total; + Foo 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 index 00000000000..ec5df3dec03 --- /dev/null +++ b/gcc/testsuite/g++.dg/gcov/test-gcov-17.py @@ -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 -- 2.30.2