public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Richard Palethorpe <rpalethorpe@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 6/7] doc: Document TEST macro and state TST_RET/ERR rule LTP-002
Date: Thu, 01 Jul 2021 08:17:53 +0100	[thread overview]
Message-ID: <87fswy33ku.fsf@suse.de> (raw)
In-Reply-To: <20210629072710.23800-7-rpalethorpe@suse.com>


Richard Palethorpe via ltp <ltp@lists.linux.it> writes:

>  
> +[source,c]
> +-------------------------------------------------------------------------------
> +TEST(socket(AF_INET, SOCK_RAW, 1));
> +if (TST_RET > -1) {
> +	tst_res(TFAIL, "Created raw socket");
> +	SAFE_CLOSE(TST_RET);
> +} else if (TST_ERR != EPERM) {
> +	tst_res(TFAIL | TTERRNO,
> +		"Failed to create socket for wrong reason");
> +} else {
> +	tst_res(TPASS | TTERRNO, "Didn't create raw socket");
> +}
> +-------------------------------------------------------------------------------
> +
> +The +TEST+ macro sets +TST_RET+ to its argument's return value and
> ++TST_ERR+ to +errno+. The +TTERNO+ flag can be used to print the error
> +number's symbolic value.
> +
> +No LTP library function or macro, except those in 'tst_test_macros.h',
> +will write to these variables (rule 'LTP-002'). So their values will
> +not be changed unexpectedly.
> +
> +[source,c]
> +-------------------------------------------------------------------------------
> +TST_EXP_POSITIVE(wait(&status));
> +
> +if (!TST_PASS)
> +	return;
> +-------------------------------------------------------------------------------
> +
> +If the return value of 'wait' is positive. This macro will print a
> +pass result and set +TST_PASS+ appropriately. If the return value is
> +zero or negative, then it will print fail.
> +
> +This and similar macros take optional variadic arguments. These begin
> +with a format string and then appropriate values to be formatted.
> +
> +[source,c]
> +-------------------------------------------------------------------------------
> +TST_EXP_PASS(chown("a/file", uid, gid), "chown(%s,%d,%d)",
> +	     "a/file", uid, gid);
> +-------------------------------------------------------------------------------
> +
> +Expects +chown+ to return 0 and emits a pass or a fail. The arguments
> +to +chown+ will be printed in either case. There are many similar
> +macros, please see 'tst_test_macros.h'.

It appears that TST_EXP* macros (but not TEST) are documented
elsewhere. So I should probably combine these comments with the existing
docs.

-- 
Thank you,
Richard.

  reply	other threads:[~2021-07-01  7:17 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-29  7:27 [LTP] [PATCH 0/7] Sparse based checker and rule proposal Richard Palethorpe
2021-06-29  7:27 ` [LTP] [PATCH 1/7] Add Sparse based checker and TST_RET/ERR check Richard Palethorpe
2021-07-08 13:19   ` Cyril Hrubis
2021-07-09  7:47     ` Richard Palethorpe
2021-06-29  7:27 ` [LTP] [PATCH 2/7] Add 'make check' to the build system Richard Palethorpe
2021-06-29  7:27 ` [LTP] [PATCH 3/7] meltdown: Set CFLAGS for check targets Richard Palethorpe
2021-07-08 13:11   ` Cyril Hrubis
2021-07-09  7:49     ` Richard Palethorpe
2021-06-29  7:27 ` [LTP] [PATCH 4/7] doc: Add rules and recommendations list Richard Palethorpe
2021-07-08 13:34   ` Cyril Hrubis
2021-06-29  7:27 ` [LTP] [PATCH 5/7] doc: Remind authors and maintainers to run make check Richard Palethorpe
2021-07-08 13:35   ` Cyril Hrubis
2021-06-29  7:27 ` [LTP] [PATCH 6/7] doc: Document TEST macro and state TST_RET/ERR rule LTP-002 Richard Palethorpe
2021-07-01  7:17   ` Richard Palethorpe [this message]
2021-06-29  7:27 ` [LTP] [PATCH 7/7] Reference LTP-002 rule in Cocci scripts Richard Palethorpe
2021-07-08 13:38 ` [LTP] [PATCH 0/7] Sparse based checker and rule proposal 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=87fswy33ku.fsf@suse.de \
    --to=rpalethorpe@suse.de \
    --cc=ltp@lists.linux.it \
    /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