public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <law@redhat.com>
To: "Martin Liška" <mliska@suse.cz>, "GCC Development" <gcc@gcc.gnu.org>
Subject: Re: Pytest usage in DejaGNU?
Date: Mon, 14 Dec 2020 13:30:40 -0700	[thread overview]
Message-ID: <a2ab10c6-0154-b527-0dfc-55fbd4add7c5@redhat.com> (raw)
In-Reply-To: <b0da2320-30b1-9aae-6025-8c94994d37d4@suse.cz>



On 12/14/20 9:02 AM, Martin Liška wrote:
> Hello.
>
> GCOV tests suffer from tests that would cover the intermediate format.
> It's a JSON format and and I'm attaching an example of its output.
>
> I would really like to use Python to make more complex tests:
>
> $ cat test_json.py
> import pytest
> import json
>
> def test_gcov_output():
>     data = json.load(open('gcov.json'))
>     assert len(data['files']) == 1
>     f0 = data['files'][0]
>     assert f0['file'] == 'gcov-lambda.C'
>     assert len(f0['functions']) == 3
>
>     fns = {}
>     for fn in f0['functions']:
>         fns[fn['name']] = fn
>     lines = f0['lines']
>
>     for line in lines:
>         lineno = line['line_number']
>         linefn = line['function_name']
>         assert linefn in fns
>         fn = fns[linefn]
>         assert fn['start_line'] <= lineno and lineno <= fn['end_line']
>
> I see it pretty complicated to do the same in DejaGNU. Mainly due the
> missing
> JSON parser.
>
> Would it be possible to make optional Python tests in our testsuite?
> I can imagine a simple pytest wrapper that will do something like:
>
> +proc pytest-execute { dgargs } {
> +    verbose "dg-pytest-execute: ${dgargs}" 2
> +    set script [lindex $dgargs 0]
> +    verbose "  script: ${script}" 2
> +
> +    spawn -noecho pytest -rA -s --tb=no $script
> +
> +    expect {
> +      -re "FAILED .*" {
> +       fail "pytest $expect_out(0,string)"
> +      }
> +      -re "PASSED .*" {
> +       pass "pytest $expect_out(0,string)"
> +      }
> +    }
> +}
>
> as Pytest can provide a reasonable close output:
>
> ===========================================================================================================================
> short test summary info
> ============================================================================================================================
> PASSED test_json.py::test_gcov_output
> PASSED test_json.py::test_gcov_output
> PASSED test_json.py::test_gcov_output
I thought we already approved using python elsewhere (JIT?  Analyzer?)

jeff


  reply	other threads:[~2020-12-14 20:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-14 16:02 Martin Liška
2020-12-14 20:30 ` Jeff Law [this message]
2020-12-14 21:21 ` Joseph Myers
2020-12-14 21:53   ` Matthias Klose

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a2ab10c6-0154-b527-0dfc-55fbd4add7c5@redhat.com \
    --to=law@redhat.com \
    --cc=gcc@gcc.gnu.org \
    --cc=mliska@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).