kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: Bill Wendling <morbo@google.com>
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
	"David Hildenbrand" <david@redhat.com>,
	"kvm list" <kvm@vger.kernel.org>,
	"Lukáš Doktor" <ldoktor@redhat.com>,
	"David Gibson" <dgibson@redhat.com>,
	"Laurent Vivier" <lvivier@redhat.com>,
	"Andrew Jones" <drjones@redhat.com>
Subject: Re: [kvm-unit-tests PATCH] lib: use an argument which doesn't require default argument promotion
Date: Mon, 14 Oct 2019 11:32:58 +0200	[thread overview]
Message-ID: <b35a5604-b54a-d95d-ed09-ecf89d43d282@redhat.com> (raw)
In-Reply-To: <CAGG=3QUurbcE-gESo8D3bj-tcdWwsc=umG3QTtZrTcVZp6PpWw@mail.gmail.com>

On 14/10/2019 10.14, Bill Wendling wrote:
> On Mon, Oct 14, 2019 at 12:57 AM Thomas Huth <thuth@redhat.com> wrote:
>>
>> On 11/10/2019 20.36, Bill Wendling wrote:
>>> I apologize for the breakage. I'm not sure how this escaped me. Here's
>>> a proposed fix. Thoughts?
>>>
>>> commit 5fa1940140fd75a97f3ac5ae2e4de9e1bef645d0
>>> Author: Bill Wendling <morbo@google.com>
>>> Date:   Fri Oct 11 11:26:03 2019 -0700
>>>
>>>     Use a status enum for reporting pass/fail
>>>
>>>     Some values passed into "report" as "pass/fail" are larger than the
>>>     size of the parameter. Use instead a status enum so that the size of the
>>>     argument no longer matters.
>>>
>>> diff --git a/lib/libcflat.h b/lib/libcflat.h
>>> index b6635d9..8f80a1c 100644
>>> --- a/lib/libcflat.h
>>> +++ b/lib/libcflat.h
>>> @@ -95,13 +95,22 @@ extern int vsnprintf(char *buf, int size, const
>>> char *fmt, va_list va)
>>>  extern int vprintf(const char *fmt, va_list va)
>>>   __attribute__((format(printf, 1, 0)));
>>>
>>> +enum status { PASSED, FAILED };
>>> +
>>> +#define STATUS(x) ((x) != 0 ? PASSED : FAILED)
>>> +
>>> +#define report(msg_fmt, status, ...) \
>>> + report_status(msg_fmt, STATUS(status) __VA_OPT__(,) __VA_ARGS__)
>>> +#define report_xfail(msg_fmt, xfail, status, ...) \
>>> + report_xfail_status(msg_fmt, xfail, STATUS(status) __VA_OPT__(,) __VA_ARGS__)
>>> +
>>>  void report_prefix_pushf(const char *prefix_fmt, ...)
>>>   __attribute__((format(printf, 1, 2)));
>>>  extern void report_prefix_push(const char *prefix);
>>>  extern void report_prefix_pop(void);
>>> -extern void report(const char *msg_fmt, unsigned pass, ...)
>>> +extern void report_status(const char *msg_fmt, unsigned pass, ...)
>>>   __attribute__((format(printf, 1, 3)));
>>> -extern void report_xfail(const char *msg_fmt, bool xfail, unsigned pass, ...)
>>> +extern void report_xfail_status(const char *msg_fmt, bool xfail, enum
>>> status status, ...)
>>>   __attribute__((format(printf, 1, 4)));
>>>  extern void report_abort(const char *msg_fmt, ...)
>>>   __attribute__((format(printf, 1, 2)))
>>> diff --git a/lib/report.c b/lib/report.c
>>> index 2a5f549..4ba2ac0 100644
>>> --- a/lib/report.c
>>> +++ b/lib/report.c
>>> @@ -80,12 +80,12 @@ void report_prefix_pop(void)
>>>   spin_unlock(&lock);
>>>  }
>>>
>>> -static void va_report(const char *msg_fmt,
>>> - bool pass, bool xfail, bool skip, va_list va)
>>> +static void va_report(const char *msg_fmt, enum status status, bool xfail,
>>> +               bool skip, va_list va)
>>>  {
>>>   const char *prefix = skip ? "SKIP"
>>> -   : xfail ? (pass ? "XPASS" : "XFAIL")
>>> -   : (pass ? "PASS"  : "FAIL");
>>> +   : xfail ? (status == PASSED ? "XPASS" : "XFAIL")
>>> +   : (status == PASSED ? "PASS"  : "FAIL");
>>>
>>>   spin_lock(&lock);
>>>
>>> @@ -96,27 +96,27 @@ static void va_report(const char *msg_fmt,
>>>   puts("\n");
>>>   if (skip)
>>>   skipped++;
>>> - else if (xfail && !pass)
>>> + else if (xfail && status == FAILED)
>>>   xfailures++;
>>> - else if (xfail || !pass)
>>> + else if (xfail || status == FAILED)
>>>   failures++;
>>>
>>>   spin_unlock(&lock);
>>>  }
>>>
>>> -void report(const char *msg_fmt, unsigned pass, ...)
>>> +void report_status(const char *msg_fmt, enum status status, ...)
>>>  {
>>>   va_list va;
>>> - va_start(va, pass);
>>> - va_report(msg_fmt, pass, false, false, va);
>>> + va_start(va, status);
>>> + va_report(msg_fmt, status, false, false, va);
>>>   va_end(va);
>>>  }
>>>
>>> -void report_xfail(const char *msg_fmt, bool xfail, unsigned pass, ...)
>>> +void report_xfail_status(const char *msg_fmt, bool xfail, enum status
>>> status, ...)
>>>  {
>>>   va_list va;
>>> - va_start(va, pass);
>>> - va_report(msg_fmt, pass, xfail, false, va);
>>> + va_start(va, status);
>>> + va_report(msg_fmt, status, xfail, false, va);
>>>   va_end(va);
>>>  }
>>
>> That's certainly a solution... but I wonder whether it might be easier
>> to simply fix the failing tests instead, to make sure that they do not
>> pass a value > sizeof(int) to report() and report_xfail_status() ?
>>
> It may be easier, but it won't stop future changes from encountering
> the same issue.

True.

>> Another idea would be to swap the parameters of report() and
>> report_xfail_status() :
>>
> It's a bit non-standard, but I don't have much of a preference. It
> would take changing tons of places in the code base though.

Yes, it's a bigger change now ... but with your approach, I'm a little
bit afraid that we'll forget the reason over the years, so one day in
the future somebody might wonder what's this "enum status" magic all
about and more or less revert your patch again... so if we take your
patch, I think there should either be some comments in the code as
explanation, or we might want to add builds with clang to the
.travis.yml and gitlab-ci.yml files to make sure that we keep building
the kvm-unit-tests with clang, too.

 Thomas

  reply	other threads:[~2019-10-14  9:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-09 23:11 [kvm-unit-tests PATCH] lib: use an argument which doesn't require default argument promotion Bill Wendling
2019-09-10 16:43 ` Jim Mattson
2019-09-30 21:59   ` Bill Wendling
2019-10-09 10:13 ` Paolo Bonzini
2019-10-11 14:19 ` David Hildenbrand
2019-10-11 16:24   ` Thomas Huth
2019-10-11 16:36     ` Thomas Huth
2019-10-11 18:36       ` Bill Wendling
2019-10-14  7:57         ` Thomas Huth
2019-10-14  8:12           ` David Hildenbrand
2019-10-14  8:14           ` Bill Wendling
2019-10-14  9:32             ` Thomas Huth [this message]
2019-10-14 11:04           ` Paolo Bonzini
2019-10-17 12:32             ` Thomas Huth

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=b35a5604-b54a-d95d-ed09-ecf89d43d282@redhat.com \
    --to=thuth@redhat.com \
    --cc=david@redhat.com \
    --cc=dgibson@redhat.com \
    --cc=drjones@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=ldoktor@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=morbo@google.com \
    --cc=pbonzini@redhat.com \
    /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 NNTP newsgroup(s).