All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 1/4] syscalls/sync01: Remove it
Date: Mon, 9 Nov 2020 13:42:33 +0100	[thread overview]
Message-ID: <20201109124233.GA9991@yuki.lan> (raw)
In-Reply-To: <5FA8BE07.4040201@cn.fujitsu.com>

Hi!
> 1) open(2) will return -1 if an error occur.
>      Is it necessary to check invalid return value(except -1) if an 
> error occur?

Well if there are values that are never supposed to be returned it makes
sense to catch these and return a TBROK or TFAIL.

If we are expecially testing a syscall() I would say that we should
check for all kinds of errors including the values that shall not be
returned e.g.:

	TEST(open(...));

	if (TST_RET == -1) {
		tst_ret(TFAIL | TTERRNO, "open() failed");
		return;
	}

	if (TST_RET < 0) {
		tst_ret(TFAIL | TTERRNO, "Invalid open() retval %ld", TST_RET);
		return;
	}

	...


If the syscall is part of the test preparation and there is no safe
macro I would say that it's enough to cover all invalid values in one
condition e.g.:

	fd = open(...);
	if (fd < 0)
		tst_brk(TBROK | TERRNO, "open() failed");


> 2) mmap(2) will return MAP_FAILED if an error occurs.
>      Is it necessary to check invalid value(except MAP_FAILED) if an 
> error occur?

Actually return value from mmap() is pointer, right? And the only value
that is not supposed to be returned is MAP_FAILED or do I miss
something?

> Martin's patches have added a check for invalid return value in many 
> safe macros but a lot of syscall tests(e.g. after doingTEST()) don't add 
> the check for now.
> I am not sure if we need to add the check for all syscall tests. :-)

I would say that at least for newly added test we should make sure that
there is no unexpected value returned.

> BTW: In my opinion, it is hardly to get invalid return value so the 
> check seems unnecessary and redundance.

Well it's not a common case but I've seen this to happen a few times,
once it was because a backported patch applied cleanly but the code was
incorrect and as a result syscall started to return really unexpected
values.

-- 
Cyril Hrubis
chrubis@suse.cz

  parent reply	other threads:[~2020-11-09 12:42 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-26  5:48 [LTP] [PATCH 1/4] syscalls/sync01: Remove it Yang Xu
2020-10-26  5:48 ` [LTP] [PATCH 2/4] syscalls/sync02: " Yang Xu
2020-10-26  5:48 ` [LTP] [PATCH 3/4] syscalls/sync03: Remove useless judgement Yang Xu
2020-10-26  5:48 ` [LTP] [PATCH 4/4] syscalls/sync: Rename sync03.c to sync01.c Yang Xu
2020-11-04  3:06 ` [LTP] [PATCH 1/4] syscalls/sync01: Remove it Yang Xu
2020-11-06 12:36   ` Cyril Hrubis
2020-11-06 16:14     ` Xiao Yang
2020-11-06 16:47       ` Cyril Hrubis
2020-11-06 23:46         ` Xiao Yang
2020-11-07  0:53           ` Yang Xu
2020-11-07 16:55           ` Petr Vorel
2020-11-09  3:56             ` Xiao Yang
2020-11-09  6:37               ` Petr Vorel
2020-11-09 12:42               ` Cyril Hrubis [this message]
2020-11-09 18:15                 ` Radoslav Kolev
2020-11-11 18:25                   ` Petr Vorel
2020-11-12 10:43                     ` 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=20201109124233.GA9991@yuki.lan \
    --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 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.