All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] Convert dup02 to new API and clean up
Date: Wed, 4 Nov 2020 19:12:52 +0100	[thread overview]
Message-ID: <20201104181252.GA10153@pevik> (raw)
In-Reply-To: <20201104132116.20712-1-radoslav.kolev@suse.com>

Hi Radoslav,

>  testcases/kernel/syscalls/dup/dup02.c | 212 ++++++--------------------
...

> +	struct tcase *testcase = &testcases[n];
Maybe shorter names (tc)?

> +
> +	TEST(dup(testcase->fd));
> +
> +	if (TST_RET < -1) {
> +		tst_res(TFAIL, "Invalid dup() return value %ld", TST_RET);
I'd use here also TERRNO (on this unexpected error.

> +	} else if (TST_RET == -1) {
> +		if (TST_ERR == testcase->expected_errno) {
		if (testcase->expected_errno ==  TST_ERR) {
(checkpatch.pl script from kernel warning; checkpatch.pl warnings aren't hard
requirements but it's good try to remove them if possible).

> +			tst_res(TPASS | TERRNO, "dup(%d) failed as expected",
> +				testcase->fd);
> +		} else {
> +			tst_res(TFAIL | TERRNO, "dup(%d) Failed unexpectedly",
> +				testcase->fd);
>  		}
> +	} else {
> +		tst_res(TFAIL, "dup(%d) Succeeded unexpectedly", testcase->fd);
> +		SAFE_CLOSE(TST_RET);
>  	}

Nested if/else blocks are hard to read. We're trying to reduce them with return:
(not hard requirement, but really more readable)

	if (TST_RET < -1) {
		tst_res(TFAIL | TTERRNO, "Invalid dup() return value %ld", TST_RET);
		return;
	}

	if (TST_RET == -1) {
		if (testcase->expected_errno ==  TST_ERR) {
			tst_res(TPASS | TERRNO, "dup(%d) failed as expected",
				testcase->fd);
		} else {
			tst_res(TFAIL | TERRNO, "dup(%d) Failed unexpectedly",
				testcase->fd);
		}

		return;
	}

	tst_res(TFAIL, "dup(%d) Succeeded unexpectedly", testcase->fd);
	SAFE_CLOSE(TST_RET);

Otherwise LGTM :).

Kind regards,
Petr

      reply	other threads:[~2020-11-04 18:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-04 13:21 [LTP] [PATCH] Convert dup02 to new API and clean up Radoslav Kolev
2020-11-04 18:12 ` Petr Vorel [this message]

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=20201104181252.GA10153@pevik \
    --to=pvorel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.