public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: "Radim Krčmář" <rkrcmar@redhat.com>
To: Andrew Jones <drjones@redhat.com>
Cc: kvm@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>,
	Thomas Huth <thuth@redhat.com>,
	Laurent Vivier <lvivier@redhat.com>
Subject: Re: [kvm-unit-tests PATCH 2/2] lib/util,arm,powerpc: replace parse_keyval with better helpers
Date: Thu, 12 May 2016 15:17:26 +0200	[thread overview]
Message-ID: <20160512131725.GD1859@potion> (raw)
In-Reply-To: <20160512080551.3sm5cj6bc26fkkty@hawk.localdomain>

2016-05-12 10:05+0200, Andrew Jones:
> On Thu, May 12, 2016 at 09:19:08AM +0200, Andrew Jones wrote:
>> On Wed, May 11, 2016 at 10:55:14PM +0200, Radim Krčmář wrote:
>> >  int main(int argc, char **argv)
>> > @@ -115,33 +123,12 @@ int main(int argc, char **argv)
>> >  
>> >  	report_prefix_push("rtas");
>> >  
>> > -	if (argc < 2)
>> > -		report_abort("no test specified");
>> > -
>> > -	report_prefix_push(argv[1]);
>> > -
>> > -	if (strcmp(argv[1], "get-time-of-day") == 0) {
>> > -
>> > -		len = parse_keyval(argv[2], &val);
>> > -		if (len == -1) {
>> > -			printf("Missing parameter \"date\"\n");
>> > -			abort();
>> > -		}
>> > -		argv[2][len] = '\0';
>> > -
>> > +	if (parse_keyval(argc, argv, "get-time-of-day", &val))
>> >  		check_get_time_of_day(val);
>> >  
>> > -	} else if (strcmp(argv[1], "set-time-of-day") == 0) {
>> > -
>> > +	if (find_key(argc, argv, "set-time-of-day"))
>> >  		check_set_time_of_day();
>> >  
>> > -	} else {
>> > -		printf("Unknown subtest\n");
>> > -		abort();
>> > -	}
>> > -
>> > -	report_prefix_pop();
>> > -
>> 
>> Also a nice cleanup. We could have kept the missing parameter abort
>> with something like
>> 
>>  if (find_key(argc, argv, "get-time-of-day")) {
>>      if (!parse_keyval(argc, argv, "get-time-of-day", &val)) {
>>          printf("Missing parameter \"date\"\n");
>>          abort();
>>      }
>>      check_get_time_of_day(val);
>>  }

If checked for the parameter, I'd rather keep it closer to the original:

  if (argc < 3) // there was a bug in the original
      report_abort("")
  if (find_key(2, argv, "get-time-of-day")) {
      if (!parse_keyval(2, argv+2, "date", &val))
          report_abort("");
      check_get_time_of_day(val);
  }

> Hmm, actually the above wouldn't work with the current
> find_key implementation. Maybe we should change it to
> just check for null?

No, that was the point.

>  bool find_key(int argc, char **argv, char *key)
>  {
>     return find_keyval(argc, argv, key) != NULL;
>  }

This is the same as return find_keyval(argc, argv, key), so you could
just use that.

> And change the documentation to explain it looks for @key
> by itself, or with a paired =val, but doesn't parse val.

They are too similar to deserve a distinction.  The previous find_key is
somewhat useful, because the caller doesn't have to remember *key (= can
use a string literal) to distinguish the case when there is no argument.

  parent reply	other threads:[~2016-05-12 13:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-11 20:55 [kvm-unit-tests PATCH 0/2] lib,arm,powerpc: change command line parsing Radim Krčmář
2016-05-11 20:55 ` [kvm-unit-tests PATCH 1/2] lib/string: add strncmp Radim Krčmář
2016-05-12  7:02   ` Laurent Vivier
2016-05-11 20:55 ` [kvm-unit-tests PATCH 2/2] lib/util,arm,powerpc: replace parse_keyval with better helpers Radim Krčmář
2016-05-12  7:19   ` Andrew Jones
2016-05-12  8:05     ` Andrew Jones
2016-05-12  8:09       ` Laurent Vivier
2016-05-12 13:22         ` Radim Krčmář
2016-05-12 13:27           ` Thomas Huth
2016-05-12 13:17       ` Radim Krčmář [this message]
2016-05-12 13:00     ` Radim Krčmář

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=20160512131725.GD1859@potion \
    --to=rkrcmar@redhat.com \
    --cc=drjones@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=thuth@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