public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: zhaogongyi via ltp <ltp@lists.linux.it>
To: Cyril Hrubis <chrubis@suse.cz>
Cc: "ltp@lists.linux.it" <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH v2 3/3] syscalls/madvise11: new test for madvise(MADV_DONTNEED)
Date: Wed, 12 Oct 2022 08:56:57 +0000	[thread overview]
Message-ID: <50d81a53dcc5410287c35f99618ccb70@huawei.com> (raw)

Hi,

> 
> Hi!
> > +static void run(void)
> > +{
> > +	char cmd[BUF_SIZE];
> > +	char line[BUF_SIZE];
> > +	char vm_area_addr[128];
> > +
> > +	TEST(madvise(addr, MAP_SIZE, MADV_DONTNEED));
> > +	if (TST_RET == -1) {
> > +		tst_brk(TBROK | TTERRNO, "madvise(%p, %d, 0x%x)",
> > +			addr, MAP_SIZE, MADV_DONTNEED);
> > +	}
> > +
> > +	sprintf(vm_area_addr, "%p", addr);
> > +	sprintf(cmd,
> > +		"cat /proc/%d/smaps | grep %s -A 4 | grep Rss: | grep '0 kB'",
> > +		getpid(), &(vm_area_addr[2]));
> 
> This is way too ugly and may break easily too.
> 
> If we are going to parse the file we should do it properly in C instead.
> Why can't we just read the file line by line until we find the right address
> at the start of the line and once we do look for the Rss?


I have do it with C at first, but it seems not intuitive. I will change back on next version of the patch.

Regards,
Gongyi 


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

             reply	other threads:[~2022-10-12  8:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-12  8:56 zhaogongyi via ltp [this message]
  -- strict thread matches above, loose matches on Subject: below --
2022-10-11 12:16 [LTP] [PATCH v2 0/3] new test for madvise(MADV_DONTNEED) Zhao Gongyi via ltp
2022-10-11 12:16 ` [LTP] [PATCH v2 3/3] syscalls/madvise11: " Zhao Gongyi via ltp
2022-10-12  8:52   ` 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=50d81a53dcc5410287c35f99618ccb70@huawei.com \
    --to=ltp@lists.linux.it \
    --cc=chrubis@suse.cz \
    --cc=zhaogongyi@huawei.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