public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Wei Gao <wegao@suse.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v3 1/2] tst_memutils.c: Add tst_print_meminfo function
Date: Fri, 15 Dec 2023 19:57:49 +0100	[thread overview]
Message-ID: <20231215185749.GA58273@pevik> (raw)
In-Reply-To: <20231214071321.9863-2-wegao@suse.com>

Hi Wei,

...
> +++ b/include/tst_memutils.h
> @@ -58,4 +58,10 @@ void tst_enable_oom_protection(pid_t pid);
>   */
>  void tst_disable_oom_protection(pid_t pid);

> +void tst_print_meminfo(void);
> +
> +void tst_print_meminfo_(const char *file, const int lineno);
> +
> +#define tst_print_meminfo() tst_print_meminfo_(__FILE__, __LINE__)
Most of the macros we have upper case, can it be please TST_PRINT_MEMINFO() ?
I guess it does not have to be SAFE_PRINT_MEMINFO().

And because it's just one liner, could it be:

#define TST_PRINT_MEMINFO() safe_print_file(__FILE__, __LINE__, "/proc/meminfo")

...

> +++ b/lib/safe_macros.c

We don't want to add anything to the legacy API (otherwise it would go to
lib/safe_file_ops.c), please add this to lib/tst_safe_macros.c.

BTW I'm slightly confused, what would be the best place for this,
lib/tst_safe_macros.c is being used nowadays for everything. But there is also
include/tst_safe_file_ops.h, which does not have C file
(lib/tst_safe_file_ops.c) because it internally use lib/tst_safe_macros.c.
I guess creating lib/tst_safe_macros.c was postponed until we rewrite all tests,
maybe it's a time to create it.

@Li @Cyril: Also include/tst_safe_file_ops.h has SAFE_READ_MEMINFO() and
SAFE_READ_PROC_STATUS(), IMHO these should be in include/tst_memutils.h.
Or, we shouldn't have 2 headers for similar thing, it would be good to merge
these two.

> @@ -1352,3 +1352,19 @@ int safe_sysinfo(const char *file, const int lineno, struct sysinfo *info)

>  	return ret;
>  }
> +
> +int safe_print_file(const char *file, const int lineno, char *path)
> +{
> +	int ret;
> +	FILE *pfile;
> +	char line[PATH_MAX];
> +
> +	pfile = safe_fopen(file, lineno, NULL, path, "r");
> +
> +	while (fgets(line, sizeof(line), pfile))
> +		tst_resm_(file, lineno, TINFO, "%s", line);
> +
> +	ret = safe_fclose(file, lineno, NULL, pfile);
> +
> +	return ret;
> +}
> diff --git a/lib/tst_memutils.c b/lib/tst_memutils.c
> index c5382ff10..6c1e7c29e 100644
> --- a/lib/tst_memutils.c
> +++ b/lib/tst_memutils.c
> @@ -182,3 +182,8 @@ void tst_disable_oom_protection(pid_t pid)
>  {
>  	set_oom_score_adj(pid, 0);
>  }
> +
> +void tst_print_meminfo_(const char *file, const int lineno)
> +{
> +	safe_print_file(file, lineno, "/proc/meminfo");
As I mentioned above, we try to avoid function wrappers.
> +}

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2023-12-15 18:58 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-10  9:43 [LTP] [PATCH v1] swapping01.c: Reporting /proc/meminfo before test and at the moment of the failure Wei Gao via ltp
2023-12-12 17:29 ` Petr Vorel
2023-12-14  6:33 ` [LTP] [PATCH v2 0/2] Add tst_print_meminfo function in swapping01 Wei Gao via ltp
2023-12-14  6:33   ` [LTP] [PATCH v2 1/2] tst_memutils.c: Add tst_print_meminfo function Wei Gao via ltp
2023-12-14  6:33   ` [LTP] [PATCH v2 2/2] swapping01.c: Reporting /proc/meminfo during test Wei Gao via ltp
2023-12-14  7:13   ` [LTP] [PATCH v3 0/2] Add tst_print_meminfo function into swapping01 Wei Gao via ltp
2023-12-14  7:13     ` [LTP] [PATCH v3 1/2] tst_memutils.c: Add tst_print_meminfo function Wei Gao via ltp
2023-12-15 18:57       ` Petr Vorel [this message]
2023-12-18  3:41         ` Li Wang
2023-12-18  3:51           ` Li Wang
2023-12-18  4:39             ` Petr Vorel
2023-12-18  4:30           ` Petr Vorel
2023-12-18  7:20             ` Li Wang
2023-12-14  7:13     ` [LTP] [PATCH v3 2/2] swapping01.c: Reporting /proc/meminfo during test Wei Gao via ltp
2023-12-18  7:37       ` Li Wang
2023-12-18 12:22     ` [LTP] [PATCH v4 0/2] Add tst_print_meminfo function into swapping01 Wei Gao via ltp
2023-12-18 12:22       ` [LTP] [PATCH v4 1/2] tst_memutils.c: Add tst_print_meminfo function Wei Gao via ltp
2023-12-18 13:24         ` Petr Vorel
2023-12-18 12:22       ` [LTP] [PATCH v4 2/2] swapping01.c: Reporting /proc/meminfo during test Wei Gao via ltp
2023-12-18 13:34         ` Petr Vorel
2023-12-18 13:47           ` Petr Vorel

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=20231215185749.GA58273@pevik \
    --to=pvorel@suse.cz \
    --cc=ltp@lists.linux.it \
    --cc=wegao@suse.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