[LTP] [PATCH] lib: add tst_read_meminfo / tst_get_avail_mem

Cyril Hrubis
2016-07-13T14:23:33Z

Hi!
> > > It's similar to SAFE_FILE_SCANF, but it scanfs each line and first
> > > matching all scanf directives wins and terminates search, otherwise
> > > you get non-zero ret code. For example:
> > >
> > > if (SAFE_FILE_LINES_SCANF("/proc/meminfo", "MemFree: %ld", &free))
> > > tst_brk(TBROK, "Could not parse MemFree");
> >
> > The API looks good to me. Nice work.
> >
> > We should call this version FILE_LINES_SCANF() since the SAFE_ variants
> > call tst_brkm() on failure.
>
> I was hesitant about SAFE_ part, but since it still calls brk on some
> occasions I left it there.
>
> There is also option to remove brkm calls, turn it into tst_file_lines_scanf(),
> and let user deal with possible errors.

Thinking about this, there are only two errors that we care about.
Either the file we are trying to open does not exist, which may be
reason to fail the test with TCONF instead or use different code path.
And the second one is when we couldn't match the line(s) which has the
same implications.

We can safely call tst_brkm(TBROK,) for the rest of the cases. And even
the 'file does not exist' could be easily handled in test setup with
single access() call.

So I would say that we can keep the code as it is and just drop the
SAFE_ prefix and possibly add SAFE_FILE_LINES_SCANF() as well for cases
where the user is not interested in handling the returned error himself.

--
Cyril Hrubis
chrubis@suse.cz