From: Jan Stancek <jstancek@redhat.com>
To: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
Cc: ltp-list <ltp-list@lists.sourceforge.net>
Subject: Re: [LTP] [PATCH v2 2/2] mlock/mlock02.c: add EPERM and ENOMEM errno tests
Date: Wed, 19 Feb 2014 06:29:41 -0500 (EST) [thread overview]
Message-ID: <1795224124.5672526.1392809381205.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <1392802803.2083.5.camel@G08JYZSD130126>
----- Original Message -----
> From: "Zeng Linggang" <zenglg.jy@cn.fujitsu.com>
> To: "Jan Stancek" <jstancek@redhat.com>
> Cc: "ltp-list" <ltp-list@lists.sourceforge.net>
> Sent: Wednesday, 19 February, 2014 10:40:03 AM
> Subject: [PATCH v2 2/2] mlock/mlock02.c: add EPERM and ENOMEM errno tests
>
> Add EPERM and ENOMEM errno tests for mlock(2).
>
> Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
> ---
> testcases/kernel/syscalls/mlock/mlock02.c | 88
> ++++++++++++++++++++++++++++---
> 1 file changed, 81 insertions(+), 7 deletions(-)
Hi,
as mentioned in part1, there are some compilation issues:
Let's pretend we are on ia64 (extra -D__ia64__ passed to gcc):
$ gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -D_FORTIFY_SOURCE=2 -I/usr/src/ltp/testcases/kernel/include -I../../../../include -I../../../../include -L../../../../lib mlock02.c -lltp -o mlock02 -D__ia64__
mlock02.c: In function ‘setup1’:
mlock02.c:133: error: assignment of read-only location ‘*test’
>
> diff --git a/testcases/kernel/syscalls/mlock/mlock02.c
> b/testcases/kernel/syscalls/mlock/mlock02.c
> index 1d1c853..6ccd281 100644
> --- a/testcases/kernel/syscalls/mlock/mlock02.c
> +++ b/testcases/kernel/syscalls/mlock/mlock02.c
> @@ -20,13 +20,22 @@
> * ALGORITHM
> * test 1:
> * Call mlock with a NULL address. ENOMEM should be returned
> + * test 2:
> + * The caller was not privileged and its RLIMIT_MEMLOCK soft
> + * resource limit was 0. EPERM should be returned
> + * test 3:
> + * The caller was not privileged and its RLIMIT_MEMLOCK soft
> + * resource limit was nonzero, but tried to lock more memory than
> + * the limit permitted. ENOMEM should be returned
> */
>
> #include <errno.h>
> #include <unistd.h>
> #include <sys/mman.h>
> +#include <pwd.h>
> #include "test.h"
> #include "usctest.h"
> +#include "safe_macros.h"
>
> char *TCID = "mlock02";
>
> @@ -36,25 +45,32 @@ struct test_case_t {
> void **addr;
> int len;
> int error;
> - void (*setupfunc) ();
> + int (*setupfunc) ();
> + void (*cleanupfunc) ();
should list parameters or void
> };
>
> static void *addr1;
> +static struct passwd *ltpuser;
> static void setup(void);
> #ifdef __ia64__
> -static void setup1(const struct test_case_t *);
> +static int setup1(const struct test_case_t *);
> #else
> -static void setup1(void);
> +static int setup1(void);
> #endif
> +static int setup2(void);
> +static int setup3(void);
> +static void cleanup2(void);
> static void cleanup(void);
> static void mlock_verify(const struct test_case_t *);
>
> static struct test_case_t TC[] = {
> - {&addr1, 1024, ENOMEM, setup1},
> + {&addr1, 1024, ENOMEM, setup1, NULL},
> + {&addr1, 1024, EPERM, setup2, cleanup2},
> + {&addr1+1024, 1024, ENOMEM, setup3, cleanup2},
What is at this memory location? It appears to be from heap:
(gdb) b setup3
Breakpoint 1 at 0x401b30: file mlock02.c, line 168.
(gdb) r
Starting program: /usr/src/ltp/testcases/kernel/syscalls/mlock/mlock02
...
Breakpoint 1, setup3 () at mlock02.c:168
168 {
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.132.el6.x86_64
(gdb) p/x &addr1
$3 = 0x608728
(gdb) p/x &addr1+1024
$4 = 0x60a728
(gdb) info proc map
process 524
cmdline = '/usr/src/ltp/testcases/kernel/syscalls/mlock/mlock02'
cwd = '/usr/src/ltp/testcases/kernel/syscalls/mlock'
exe = '/usr/src/ltp/testcases/kernel/syscalls/mlock/mlock02'
Mapped address spaces:
Start Addr End Addr Size Offset objfile
0x400000 0x409000 0x9000 0 /usr/src/ltp/testcases/kernel/syscalls/mlock/mlock02
0x608000 0x609000 0x1000 0x8000 /usr/src/ltp/testcases/kernel/syscalls/mlock/mlock02
0x609000 0x62e000 0x25000 0 [heap]
> };
>
> int TST_TOTAL = ARRAY_SIZE(TC);
> -static int exp_enos[] = { ENOMEM, 0 };
> +static int exp_enos[] = { ENOMEM, EPERM, 0 };
>
> int main(int ac, char **av)
> {
> @@ -83,6 +99,8 @@ static void setup(void)
> tst_sig(NOFORK, DEF_HANDLER, cleanup);
>
> TEST_PAUSE;
> +
> + ltpuser = SAFE_GETPWNAM(cleanup, "nobody");
> }
>
> static void mlock_verify(const struct test_case_t *test)
> @@ -92,6 +110,9 @@ static void mlock_verify(const struct test_case_t *test)
>
> TEST(mlock(*(test->addr), test->len));
>
> + if (test->cleanupfunc != NULL)
> + test->cleanupfunc();
> +
> if (TEST_RETURN != -1) {
> tst_resm(TFAIL, "mlock succeeded unexpectedly");
> return;
> @@ -107,17 +128,70 @@ static void mlock_verify(const struct test_case_t
> *test)
> }
>
> #ifdef __ia64__
> -static void setup1(const struct test_case_t *test)
> +static int setup1(const struct test_case_t *test)
> {
> test->len = getpagesize() + 1;
> + return 0;
> }
> #else
> -static void setup1(void)
> +static int setup1(void)
> {
> addr1 = NULL;
> + return 0;
> }
> #endif
>
> +static int setup2(void)
> +{
> + struct rlimit rl;
> +
> + if (geteuid() != 0) {
> + tst_resm(TWARN, "Test needs to be run as root");
> + return -1;
> + }
If you add tst_require_root(NULL); to setup() that will break with TCONF and you can remove this.
> +
> + rl.rlim_max = 0;
> + rl.rlim_cur = 0;
> + if (setrlimit(RLIMIT_MEMLOCK, &rl) != 0) {
> + tst_resm(TWARN,
> + "setrlimit failed to set the resource for "
> + "RLIMIT_MEMLOCK to check for mlock()");
I'd expect TBROK here.
> + return -1;
> + }
> +
> + SAFE_SETEUID(cleanup, ltpuser->pw_uid);
> +
> + return 0;
> +}
> +
> +static int setup3(void)
> +{
> + struct rlimit rl;
> +
> + if (geteuid() != 0) {
> + tst_resm(TWARN, "Test needs to be run as root");
> + return -1;
> + }
same as in setup2, can be removed if you add tst_require_root(NULL); to setup()
> +
> + rl.rlim_max = 1;
> + rl.rlim_cur = 1;
> + if (setrlimit(RLIMIT_MEMLOCK, &rl) != 0) {
> + tst_resm(TWARN,
> + "setrlimit failed to set the resource for "
> + "RLIMIT_MEMLOCK to check for mlock()");
I'd expect TBROK here as well.
> + return -1;
> + }
> +
> + SAFE_SETEUID(cleanup, ltpuser->pw_uid);
> +
> + return 0;
> +}
For setup2 and setup3 I'd suggest to set *addr to some reasonable value,
so that when mlock returns ENOMEM we know it wasn't because *addr was NULL.
Regards,
Jan
> +
> +static void cleanup2(void)
> +{
> + SAFE_SETEUID(cleanup, 0);
> +}
> +
> static void cleanup(void)
> {
> TEST_CLEANUP;
> --
> 1.8.4.2
>
>
>
>
------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
next prev parent reply other threads:[~2014-02-19 11:29 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-14 10:10 [LTP] [PATCH] mlock/mlock02.c: cleanup Zeng Linggang
2014-02-14 10:12 ` [LTP] [PATCH 2/2] mlock/mlock02.c: add EPERM errno test Zeng Linggang
2014-02-14 10:54 ` Jan Stancek
2014-02-19 9:38 ` [LTP] [PATCH v2 1/2] mlock/mlock02.c: cleanup Zeng Linggang
2014-02-19 9:40 ` [LTP] [PATCH v2 2/2] mlock/mlock02.c: add EPERM and ENOMEM errno tests Zeng Linggang
2014-02-19 11:29 ` Jan Stancek [this message]
2014-02-20 9:40 ` [LTP] [PATCH v3 1/2] mlock/mlock02.c: cleanup Zeng Linggang
2014-02-20 9:50 ` [LTP] [PATCH v3 2/2] mlock/mlock02.c: add EPERM and ENOMEM errno tests Zeng Linggang
2014-02-20 11:05 ` Jan Stancek
2014-02-20 13:03 ` Jan Stancek
2014-02-21 9:03 ` Zeng Linggang
2014-03-03 7:47 ` [LTP] [PATCH v4 1/3] safe_macros: Add SAFE_GETRLIMIT and SAFE_SETRLIMIT Zeng Linggang
2014-03-03 7:50 ` [LTP] [PATCH v4 2/3] mlock/mlock02.c: cleanup Zeng Linggang
2014-03-03 7:51 ` [LTP] [PATCH v4 3/3] mlock/mlock02.c: add EPERM and ENOMEM errno tests Zeng Linggang
2014-03-03 9:07 ` Jan Stancek
2014-03-03 11:22 ` [LTP] [PATCH v5 1/3] safe_macros: Add SAFE_GETRLIMIT and SAFE_SETRLIMIT Zeng Linggang
2014-03-03 11:23 ` [LTP] [PATCH v5 2/3] mlock/mlock02.c: cleanup Zeng Linggang
2014-03-03 11:25 ` [LTP] [PATCH v5 3/3] mlock/mlock02.c: add EPERM and ENOMEM errno tests Zeng Linggang
2014-03-03 20:28 ` Jan Stancek
2014-03-04 5:02 ` Zeng Linggang
2014-03-04 5:33 ` [LTP] [PATCH v5 1/3] safe_macros: Add SAFE_GETRLIMIT and SAFE_SETRLIMIT Wanlong Gao
2014-03-04 6:17 ` Zeng Linggang
2014-02-21 1:04 ` [LTP] [PATCH v3 2/2] mlock/mlock02.c: add EPERM and ENOMEM errno tests Zeng Linggang
2014-02-19 11:02 ` [LTP] [PATCH v2 1/2] mlock/mlock02.c: cleanup Jan Stancek
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=1795224124.5672526.1392809381205.JavaMail.zimbra@redhat.com \
--to=jstancek@redhat.com \
--cc=ltp-list@lists.sourceforge.net \
--cc=zenglg.jy@cn.fujitsu.com \
/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