All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 2/3] lib: Add TST_ASSERT_FILE_INT and TST_ASSERT_FILE_STR
Date: Wed, 29 Apr 2020 14:06:09 +0200	[thread overview]
Message-ID: <20200429120609.GA668@yuki.lan> (raw)
In-Reply-To: <1587450108-31100-2-git-send-email-xuyang2018.jy@cn.fujitsu.com>

Hi!
>  #endif /* TST_ASSERT_H__ */
> diff --git a/lib/tst_assert.c b/lib/tst_assert.c
> index 8ef3cd72e..65ee76473 100644
> --- a/lib/tst_assert.c
> +++ b/lib/tst_assert.c
> @@ -4,6 +4,7 @@
>   * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
>   * Copyright (c) 2020 Cyril Hrubis <chrubis@suse.cz>
>   */
> +#include <stdio.h>
>  #define TST_NO_DEFAULT_MAIN
>  #include "tst_assert.h"
>  #include "tst_test.h"
> @@ -22,6 +23,22 @@ void tst_assert_int(const char *file, const int lineno, const char *path, int va
>  	tst_res_(file, lineno, TFAIL, "%s != %d got %d", path, val, sys_val);
>  }
>  
> +void tst_assert_file_int(const char *file, const int lineno, const char *path, const char *buf, int val)
> +{
> +	int sys_val;
> +	char fmt[1024];
> +
> +	sprintf(fmt, "%s: %%d", buf);

If we want to keep the function as generic as possible we shouldn't add
the colon and space after the %s here.

There is no standard on proc files, for instance it wouldn't be possible
to parse /proc/vmstat if we hardcode the format string like that.

So I would just change this to "%s%%d" instead and pass "Foo: " instead
just "Foo" in the testcases.

Also I guess that we should call it prefix rather than buf, but that's
minor.

-- 
Cyril Hrubis
chrubis@suse.cz

  reply	other threads:[~2020-04-29 12:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-21  6:21 [LTP] [PATCH 1/3] lib/safe_file_ops: print file info when file_lines_scanf parsed fail Yang Xu
2020-04-21  6:21 ` [LTP] [PATCH 2/3] lib: Add TST_ASSERT_FILE_INT and TST_ASSERT_FILE_STR Yang Xu
2020-04-29 12:06   ` Cyril Hrubis [this message]
2020-04-30  8:22     ` Yang Xu
2020-04-30  9:58     ` [LTP] [PATCH v2 1/3] lib/tst_assert: print correct file and lineno when parsing failed Yang Xu
2020-04-30  9:58       ` [LTP] [PATCH v2 2/3] lib: Add TST_ASSERT_FILE_INT and TST_ASSERT_FILE_STR Yang Xu
2020-05-06 15:08         ` Cyril Hrubis
2020-04-30  9:58       ` [LTP] [PATCH v2 3/3] syscalls/prctl: Use TST_ASSERT_FILE_INT/STR Yang Xu
2020-05-06 15:09         ` Cyril Hrubis
2020-05-06 15:07       ` [LTP] [PATCH v2 1/3] lib/tst_assert: print correct file and lineno when parsing failed Cyril Hrubis
2020-04-21  6:21 ` [LTP] [PATCH 3/3] syscalls/prctl: Use TST_ASSERT_FILE_INT/STR Yang Xu
2020-04-28 14:56 ` [LTP] [PATCH 1/3] lib/safe_file_ops: print file info when file_lines_scanf parsed fail Cyril Hrubis

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=20200429120609.GA668@yuki.lan \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /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.