Re: [kvm-unit-tests PATCH 2/2] lib/util,arm,powerpc: replace parse_keyval with better helpers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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);
>  }

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

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

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

drew
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux