All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Jones <drjones@redhat.com>
To: "Radim Krčmář" <rkrcmar@redhat.com>
Cc: kvm@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [kvm-unit-tests PATCH v4 05/13] lib/util: add args_parse_keyval
Date: Wed, 11 May 2016 18:58:18 +0200	[thread overview]
Message-ID: <20160511165818.dzk6muttgr5fctw5@hawk.localdomain> (raw)
In-Reply-To: <1462983171-4208-6-git-send-email-rkrcmar@redhat.com>

On Wed, May 11, 2016 at 06:12:47PM +0200, Radim Krčmář wrote:
> The function parses command line arguments in "key=val" format, and
> treats "key" as "key=1".
> 
> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
> ---
>  v4: new
> 
>  lib/util.c | 17 +++++++++++++++++
>  lib/util.h | 10 ++++++++++
>  2 files changed, 27 insertions(+)
> 
> diff --git a/lib/util.c b/lib/util.c
> index 69b18100c972..8b33d474f4c0 100644
> --- a/lib/util.c
> +++ b/lib/util.c
> @@ -16,3 +16,20 @@ int parse_keyval(char *s, long *val)
>  	*val = atol(p+1);
>  	return p - s;
>  }
> +
> +long args_parse_keyval(int argc, char **argv, char *key)
> +{

I like this better than parse_keyval, except for...

> +	int i;
> +	size_t keylen = strlen(key);
> +
> +	for (i = 1; i < argc; i++) {
> +		if (keylen > 0 && strncmp(argv[i], key, keylen - 1))
> +			continue;
> +		if (argv[i][keylen] == '\0')
> +			return 1;
> +		if (argv[i][keylen] == '=')
> +			return atol(argv[i] + keylen + 1);
> +	}
> +
> +	return 0;

...this. Here we have ambiguous results. Either key was there
and had a value of 0, or wasn't there, and we still get zero.
How about merging the two, and then fixing-up the arm and powerpc
uses of the old one. I'd drop the "args_" from the name then
too.

Thanks,
drew

> +}
> diff --git a/lib/util.h b/lib/util.h
> index 4c4b44132277..d475b058526b 100644
> --- a/lib/util.h
> +++ b/lib/util.h
> @@ -20,4 +20,14 @@
>   */
>  extern int parse_keyval(char *s, long *val);
>  
> +/*
> + * argc and argv are standard C arguments to main().
> + * args_parse_keyval looks for an element of argv that matches the key.
> + * Returns val interpreted as a long if the element is in key=val format.
> + * Returns 1 if the element is key.
> + * Returns 0 otherwise.
> + *
> + */
> +long args_parse_keyval(int argc, char **argv, char *key);
> +
>  #endif
> -- 
> 2.8.2
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2016-05-11 16:58 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-11 16:12 [kvm-unit-tests PATCH v4 00/13] Improve the output of test runners Radim Krčmář
2016-05-11 16:12 ` [kvm-unit-tests PATCH v4 01/13] lib/report: allow test skipping Radim Krčmář
2016-05-11 16:12 ` [kvm-unit-tests PATCH v4 02/13] x86/*: report skipped tests Radim Krčmář
2016-05-17 12:19   ` Paolo Bonzini
2016-05-25 17:19     ` Radim Krčmář
2016-05-25 17:23       ` Radim Krčmář
2016-05-26  7:22         ` Paolo Bonzini
2016-05-11 16:12 ` [kvm-unit-tests PATCH v4 03/13] x86/unittests: remove svm-disabled Radim Krčmář
2016-05-11 16:12 ` [kvm-unit-tests PATCH v4 04/13] lib/string: add strncmp Radim Krčmář
2016-05-11 16:33   ` Andrew Jones
2016-05-11 16:12 ` [kvm-unit-tests PATCH v4 05/13] lib/util: add args_parse_keyval Radim Krčmář
2016-05-11 16:58   ` Andrew Jones [this message]
2016-05-11 17:19     ` Radim Krčmář
2016-05-11 17:23   ` Andrew Jones
2016-05-11 16:12 ` [kvm-unit-tests PATCH v4 06/13] x86/pmu: expect failure with nmi_watchdog Radim Krčmář
2016-05-11 17:00   ` Andrew Jones
2016-05-11 16:12 ` [kvm-unit-tests PATCH v4 07/13] lib/report: don't print 0 failed tests Radim Krčmář
2016-05-11 16:12 ` [kvm-unit-tests PATCH v4 08/13] scripts/runtime: consolidate summary tags Radim Krčmář
2016-05-17 12:22   ` Paolo Bonzini
2016-05-25 17:46     ` Radim Krčmář
2016-05-11 16:12 ` [kvm-unit-tests PATCH v4 09/13] run_tests: print SUMMARY line in summary Radim Krčmář
2016-05-11 17:10   ` Andrew Jones
2016-05-17 12:32   ` Paolo Bonzini
2016-05-25 17:41     ` Radim Krčmář
2016-05-11 16:30 ` [kvm-unit-tests PATCH v4 10/13] run_tests: log stderr Radim Krčmář
2016-05-11 16:30   ` [kvm-unit-tests PATCH v4 11/13] scripts/runtime: skip tests that cannot run Radim Krčmář
2016-05-11 17:20     ` Andrew Jones
2016-05-11 16:30   ` [kvm-unit-tests PATCH v4 12/13] scripts/arch-run: change QEMU failure detection Radim Krčmář
2016-05-11 17:24     ` Andrew Jones
2016-05-11 16:30   ` [kvm-unit-tests PATCH v4 13/13] scripts/run: generalize check Radim Krčmář
2016-05-11 17:31     ` Andrew Jones
2016-05-11 17:11   ` [kvm-unit-tests PATCH v4 10/13] run_tests: log stderr Andrew Jones
2016-05-17 12:29 ` [kvm-unit-tests PATCH v4 00/13] Improve the output of test runners Paolo Bonzini
2016-05-25 17:49   ` Radim Krčmář
2016-05-26  7:25     ` Paolo Bonzini

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=20160511165818.dzk6muttgr5fctw5@hawk.localdomain \
    --to=drjones@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.