public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Tarun Sahu <tsahu@linux.ibm.com>
To: Cyril Hrubis <chrubis@suse.cz>
Cc: sbhat@linux.ibm.com, aneesh.kumar@linux.ibm.com,
	geetika@linux.ibm.com, vaibhav@linux.ibm.com, ltp@lists.linux.it,
	mike.kravetz@oracle.com
Subject: Re: [LTP] [PATCH v4 2/7] Hugetlb: Migrating libhugetlbfs counters
Date: Fri, 18 Nov 2022 21:21:59 +0530	[thread overview]
Message-ID: <690a07c2b82db5356c81ecd36c6d6d91d62b2cd5.camel@linux.ibm.com> (raw)
In-Reply-To: <Y3ebLYv5EzkOV/cZ@yuki>

Hi,
Thanks Cyril, for the such a good insights. I will rework on this test.

~Tarun

On Fri, 2022-11-18 at 15:48 +0100, Cyril Hrubis wrote:
> Hi!
> > > > +static long hpage_size;
> > > > +
> > > > +	if (t != et) {
> > > > +		tst_res(TFAIL, "At Line %i:While %s: Bad
> > > > "MEMINFO_HPAGE_TOTAL
> > > > +				" expected %li, actual %li",
> > > > line, desc, et, t);
> > > 
> > > We do have tst_res_() that can be called as:
> > > 
> > > 	tst_res_(__FILE__, line,
> > >                  "%s bad " MEMINFO_HPAGE_TOTAL " = %li expected
> > > %li",
> > > 		 desc, et, t);
> > Ok. Will update it.
> > > > +out:
> > > > +	return verify_counters(line, desc, et, ef, er, es);
> > > > +}
> > > > +#define set_nr_hugepages(c, d) CHECK_(set_nr_hugepages_(c, d,
> > > > __LINE__))
> > > 
> > > The macro name should be uppercase so that it's clear that it's a
> > > macro
> > > and not a simple function. With that we can also drop the
> > > underscore
> > > from the actual function name too.
> > > 
> > I avoided it deliberately knowing that these macros are being
> > called too
> > often, keeping them in uppercase would have made the code look too
> > messy.
> > Then, I looked that there was tst_res and similiar macros too which
> > were
> > kept in smallcase too (which is wrapper to tst_res_ function), That
> > is why
> > I kept them smallcase.
> 
> The whole point why we are going in circles around how to structure
> this
> piece of code is code readibility. Source code is more often read
> than
> written, which means that it's more important to invest into writing
> code that is easily understandable since that will save effort in the
> long term. That is true especially for kernel tests, where there is
> enough complexity in the kernel itself and writing tests that are not
> easy to understand does actually harm.
> 
> There is a key difference between tst_res() defined to tst_res_()
> that
> adds a few parameters and macros that change the codeflow. If there
> are
> macros that change code flow, and perhaps checkpatch is right here
> that
> it's wiser to avoid them at all, they should at least scream in upper
> case letters that this is not a regular function.
> 
> This all boils down to a principle of a least surprise.
> 
> Perhaps the best solution would be to get back to a drawing board and
> figure out how to better structure the test so that the code flow is
> easier to follow.
> 


> > > Maybe it would be a bit nicer to have actually two different
> > > macros so
> > > that we don't have to resort to this do {} while (0) trickery
> > > e.g.
> > > 
> > > #define CHECK_BREAK(cond) if (cond) break;
> > > #define CHECK_RETURN(cond) if (cond) return -1;
> > > 
> > > #define MAP_BREAK(s, h, f, d) CHECK_BREAK(map(s, h, f, d,
> > > __LINE__))
> > > #define MAP_RETURN(s, h, f, d) CHECK_RETURN(map(s, h, f, d,
> > > __LINE__))
> > > 
> > > Then the check counters would look much better.
> > > 
> > > Or we can just stick to the RETURN variants and put the body of
> > > the loop
> > > in the runtest() function into do_interation() function.
> > > 
> > I like the second idea, as it will only have one macro. which will
> > keep the
> > code less messy. But anyway, I had tried this already, if (cond)
> > return; is
> > not allowed. "make check" throws warning saying, "Macros with flow
> > control
> > statements should be avoided". Only way I could see is to use
> > break.
> 
> Again, let's not work around the tooling we have, the tooling is
> supposed to help, once you start bending the code so that the tooling
> is
> happy you are on a wrong path.
> 


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

  reply	other threads:[~2022-11-18 15:52 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-16 11:25 [LTP] [PATCH v4 0/7] Hugetlb:Migrating the libhugetlbfs tests Tarun Sahu
2022-11-16 11:25 ` [LTP] [PATCH v4 1/7] Hugetlb: Add new argument flags in tst_creat_unlinked Tarun Sahu
2022-11-16 15:17   ` Cyril Hrubis
2022-11-17  7:02     ` Tarun Sahu
2022-11-18  8:27       ` Tarun Sahu
2022-11-16 11:25 ` [LTP] [PATCH v4 2/7] Hugetlb: Migrating libhugetlbfs counters Tarun Sahu
2022-11-16 15:37   ` Cyril Hrubis
2022-11-16 16:26     ` Tarun Sahu
2022-11-18 14:48       ` Cyril Hrubis
2022-11-18 15:51         ` Tarun Sahu [this message]
2022-11-16 11:25 ` [LTP] [PATCH v4 3/7] Hugetlb: Migrating libhugetlbfs directio Tarun Sahu
2022-11-16 11:25 ` [LTP] [PATCH v4 4/7] Hugetlb: Safe macro for posix_fadvise call Tarun Sahu
2022-11-16 11:25 ` [LTP] [PATCH v4 5/7] Hugetlb: Migrating libhugetlbfs fadvise_reserve Tarun Sahu
2022-11-16 11:25 ` [LTP] [PATCH v4 6/7] Hugetlb: Migrating libhugetlbfs fallocate_align Tarun Sahu
2022-11-16 11:25 ` [LTP] [PATCH v4 7/7] Hugetlb: Migrating libhugetlbfs fallocate_basic Tarun Sahu

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=690a07c2b82db5356c81ecd36c6d6d91d62b2cd5.camel@linux.ibm.com \
    --to=tsahu@linux.ibm.com \
    --cc=aneesh.kumar@linux.ibm.com \
    --cc=chrubis@suse.cz \
    --cc=geetika@linux.ibm.com \
    --cc=ltp@lists.linux.it \
    --cc=mike.kravetz@oracle.com \
    --cc=sbhat@linux.ibm.com \
    --cc=vaibhav@linux.ibm.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