From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v4 1/2] syscalls/setrlimit05.c: Add a test for EFAULT
Date: Thu, 12 Oct 2017 16:15:34 +0200 [thread overview]
Message-ID: <20171012141534.GA25576@rei> (raw)
In-Reply-To: <1507724801-4974-1-git-send-email-yangx.jy@cn.fujitsu.com>
Hi!
> +/*
> + * Test for EFAULT when rlim points outside the accessible address space.
> + */
> +
> +#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) {
> + tst_res(TFAIL, "setrlimit() succeeded unexpectedly");
> + goto end;
^
Why not just exit(0) here?
> + }
> +
> + /* Usually, setrlimit() should return EFAULT */
> + if (TEST_ERRNO == EFAULT) {
> + tst_res(TPASS | TTERRNO,
> + "setrlimit() failed as expected");
> + } else {
> + tst_res(TFAIL | TTERRNO,
> + "setrlimit() should fail with EFAULT, got");
> + }
> +end:
> + exit(0);
> + }
> +
> + SAFE_WAITPID(pid, &status, 0);
> +
> + /* If glibc has to convert between 32bit and 64bit struct rlimit
> + * in some cases, it is possible to get SegFault.
> + */
> + if (!WIFEXITED(status)) {
> + if (WIFSIGNALED(status) == SIGSEGV) {
^
This is wrong, we have to use
WTERMSIG(status) == SIGSEGV
> + tst_res(TPASS,
> + "setrlimit() returned SIGSEGV as expected");
> + } else {
> + tst_res(TFAIL, "setrlimit() did not return SIGSEGV");
> + }
> + }
We should generally do something as:
if (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) {
tst_res(TPASS, "setrlimit() caused SIGSEGV");
return;
}
tst_brk(TBROK, "Child ended with status %i", status);
But that prints the status as a number, which is hard to decipher. And
this is not the first time pattern like this emerges in test code. Maybe
we just need a library function to dissect the status as returned by
wait and print it content, then we can print the status in
human-readable format here and exit. I will try to sketch such function
and send a patch to ML as RFC.
> +}
> +
> +static struct tst_test test = {
> + .test_all = verify_setrlimit,
> + .forks_child = 1,
> +};
> --
> 1.8.3.1
>
>
>
--
Cyril Hrubis
chrubis@suse.cz
next prev parent reply other threads:[~2017-10-12 14:15 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
2017-10-11 12:26 ` [LTP] [PATCH v4 " Xiao Yang
2017-10-12 14:15 ` Cyril Hrubis [this message]
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=20171012141534.GA25576@rei \
--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