public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v3 1/2] syscalls/setrlimit05.c: Add a test for EFAULT
Date: Wed, 11 Oct 2017 13:46:15 +0200	[thread overview]
Message-ID: <20171011114615.GC19812@rei.lan> (raw)
In-Reply-To: <1507697036-30535-1-git-send-email-yangx.jy@cn.fujitsu.com>

Hi!
> +#define _GNU_SOURCE
> +#include <errno.h>
> +#include <sys/resource.h>
> +#include <sys/time.h>
> +#include <sys/wait.h>
> +#include <stdlib.h>
> +
> +#include "tst_test.h"
> +
> +static void verify_setrlimit(void)
> +{
> +	int status;
> +	pid_t pid;
> +
> +	pid = SAFE_FORK();
> +	if (!pid) {
> +		TEST(setrlimit(RLIMIT_NOFILE, (void *) -1));
> +		if (TEST_RETURN == -1 && TEST_ERRNO == EFAULT)
> +			exit(0);
> +
> +		exit(1);

Can we do the PASS/FAIL for the expected errno here?

Then we need to handle just the TPASS in the parent in case of SegFault.

> +	}
> +
> +	SAFE_WAITPID(pid, &status, 0);
> +
> +	/* Usually, setrlimit() should return EFAULT */
> +	if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
> +		tst_res(TPASS, "setrlimit() returned EFAULT as expected");
> +		return;
> +	}
> +
> +	/* If glibc has to convert between 32bit and 64bit struct rlimit
> +	 * in some cases, it is possible to get SegFault.
> +	 */
> +	if (!WIFEXITED(status) && WIFSIGNALED(status) == SIGSEGV) {
> +		tst_res(TPASS, "setrlimit() returned SIGSEGV as expected");
> +		return;
> +	}
> +
> +	tst_res(TFAIL, "setrlimit() did not return EFAULT or SIGSEGV");
> +}
> +
> +static struct tst_test test = {
> +	.test_all = verify_setrlimit,
> +	.forks_child = 1,
> +	.needs_root = 1,

Do we really need root?

> +};
> -- 
> 1.8.3.1
> 
> 
> 

-- 
Cyril Hrubis
chrubis@suse.cz

  reply	other threads:[~2017-10-11 11:46 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-04  5:51 [LTP] [PATCH 1/2] syscalls/setrlimit02.c: Add a test for EFAULT Xiao Yang
2017-10-04  5:52 ` [LTP] [PATCH 2/2] syscalls/setrlimit03.c: Cleanup && Convert to new API Xiao Yang
2017-10-09 14:23 ` [LTP] [PATCH 1/2] syscalls/setrlimit02.c: Add a test for EFAULT Cyril Hrubis
2017-10-10  1:52   ` [LTP] [PATCH v2 " Xiao Yang
2017-10-10  1:52     ` [LTP] [PATCH v2 2/2] syscalls/setrlimit03.c: Cleanup && Convert to new API Xiao Yang
2017-10-19  5:12       ` Xiao Yang
2017-10-26  8:31       ` Cyril Hrubis
2017-10-10 12:55     ` [LTP] [PATCH v2 1/2] syscalls/setrlimit02.c: Add a test for EFAULT Cyril Hrubis
2017-10-11  4:43       ` [LTP] [PATCH v3 1/2] syscalls/setrlimit05.c: " Xiao Yang
2017-10-11 11:46         ` Cyril Hrubis [this message]
2017-10-11 12:26           ` [LTP] [PATCH v4 " Xiao Yang
2017-10-12 14:15             ` Cyril Hrubis
2017-10-16 10:30               ` [LTP] [PATCH v5 " Xiao Yang
2017-10-18 15:07                 ` 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=20171011114615.GC19812@rei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox