From mboxrd@z Thu Jan 1 00:00:00 1970 From: Radim =?utf-8?B?S3LEjW3DocWZ?= 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 Message-ID: <20160512131725.GD1859@potion> References: <1463000114-3572-1-git-send-email-rkrcmar@redhat.com> <1463000114-3572-3-git-send-email-rkrcmar@redhat.com> <20160512071908.537ltvwkiiekqvri@hawk.localdomain> <20160512080551.3sm5cj6bc26fkkty@hawk.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: kvm@vger.kernel.org, Paolo Bonzini , Thomas Huth , Laurent Vivier To: Andrew Jones Return-path: Received: from mx1.redhat.com ([209.132.183.28]:44458 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932080AbcELNR3 (ORCPT ); Thu, 12 May 2016 09:17:29 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 341B6C04B313 for ; Thu, 12 May 2016 13:17:29 +0000 (UTC) Content-Disposition: inline In-Reply-To: <20160512080551.3sm5cj6bc26fkkty@hawk.localdomain> Sender: kvm-owner@vger.kernel.org List-ID: 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=C4=8Dm=C3=A1=C5=99= wrote: >> > int main(int argc, char **argv) >> > @@ -115,33 +123,12 @@ int main(int argc, char **argv) >> > =20 >> > report_prefix_push("rtas"); >> > =20 >> > - if (argc < 2) >> > - report_abort("no test specified"); >> > - >> > - report_prefix_push(argv[1]); >> > - >> > - if (strcmp(argv[1], "get-time-of-day") =3D=3D 0) { >> > - >> > - len =3D parse_keyval(argv[2], &val); >> > - if (len =3D=3D -1) { >> > - printf("Missing parameter \"date\"\n"); >> > - abort(); >> > - } >> > - argv[2][len] =3D '\0'; >> > - >> > + if (parse_keyval(argc, argv, "get-time-of-day", &val)) >> > check_get_time_of_day(val); >> > =20 >> > - } else if (strcmp(argv[1], "set-time-of-day") =3D=3D 0) { >> > - >> > + if (find_key(argc, argv, "set-time-of-day")) >> > check_set_time_of_day(); >> > =20 >> > - } else { >> > - printf("Unknown subtest\n"); >> > - abort(); >> > - } >> > - >> > - report_prefix_pop(); >> > - >>=20 >> Also a nice cleanup. We could have kept the missing parameter abort >> with something like >>=20 >> 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) !=3D 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 =3Dval, but doesn't parse val. They are too similar to deserve a distinction. The previous find_key i= s somewhat useful, because the caller doesn't have to remember *key (=3D = can use a string literal) to distinguish the case when there is no argument= =2E