[LTP] [PATCH v2 3/3] syscalls/madvise11: new test for madvise(MADV_DONTNEED)
zhaogongyi
zhaogongyi@huawei.com
Wed Oct 12 10:56:57 CEST 2022
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
More information about the ltp
mailing list