From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v3 5/8] doc: Document TEST macro and state TST_RET/ERR rule LTP-002
Date: Thu, 29 Jul 2021 17:27:09 +0200 [thread overview]
Message-ID: <YQLIzZJiDUKznZ/d@yuki> (raw)
In-Reply-To: <20210728123412.31858-6-rpalethorpe@suse.com>
Hi!
I've pushed all but this patch, see below.
> -------------------------------------------------------------------------------
>
> -The 'TST_EXP_FAIL2()' is the same as 'TST_EXP_FAIL()' except the return value
> -is expected to be non-negative integer if call passes.
> +The 'TST_EXP_FAIL2()' is the same as 'TST_EXP_FAIL()' except the
> +return value is expected to be non-negative integer if call
> +passes. These macros build upon the +TEST()+ macro and associated
> +variables.
> +
> +[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.
> +
> +As seen above, this and similar macros take optional variadic
> +arguments. These begin with a format string and then appropriate
> +values to be formatted. So
> +
> +[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 to those shown here, please see 'tst_test_macros.h'.
There is already TST_EXP_PASS description before the TST_EXP_FAIL so
this duplicates it. Other than that the rest looks good.
--
Cyril Hrubis
chrubis@suse.cz
next prev parent reply other threads:[~2021-07-29 15:27 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-28 12:34 [LTP] [PATCH v3 0/8] Sparse based checker and rule proposal Richard Palethorpe
2021-07-28 12:34 ` [LTP] [PATCH v3 1/8] Add Sparse based checker and TST_RET/ERR check Richard Palethorpe
2021-07-28 12:34 ` [LTP] [PATCH v3 2/8] Add 'make check' to the build system Richard Palethorpe
2021-08-27 12:06 ` Petr Vorel
2021-08-30 14:33 ` Cyril Hrubis
2021-08-30 18:13 ` Petr Vorel
2021-07-28 12:34 ` [LTP] [PATCH v3 3/8] doc: Add rules and recommendations list Richard Palethorpe
2021-07-28 12:34 ` [LTP] [PATCH v3 4/8] doc: Remind authors and maintainers to run make check Richard Palethorpe
2021-07-28 12:34 ` [LTP] [PATCH v3 5/8] doc: Document TEST macro and state TST_RET/ERR rule LTP-002 Richard Palethorpe
2021-07-29 15:27 ` Cyril Hrubis [this message]
2021-07-28 12:34 ` [LTP] [PATCH v3 6/8] Reference LTP-002 rule in Cocci scripts Richard Palethorpe
2021-07-28 12:34 ` [LTP] [PATCH v3 7/8] API: Move libtsc.h from realtime tests include to tst_tsc.h Richard Palethorpe
2021-07-28 12:34 ` [LTP] [PATCH v3 8/8] API/tst_tsc: Add guards and remove some boilerplate Richard Palethorpe
2021-08-09 20:12 ` [LTP] Review of C static analyses tools Richard Palethorpe
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=YQLIzZJiDUKznZ/d@yuki \
--to=chrubis@suse.cz \
--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