public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: xuyang2018.jy@fujitsu.com <xuyang2018.jy@fujitsu.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 2/2] syscalls/shmget06: Add test when shm_next_id is already in use
Date: Tue, 27 Jul 2021 02:13:30 +0000	[thread overview]
Message-ID: <60FF6BE9.5040101@fujitsu.com> (raw)
In-Reply-To: <1627033320-1584-2-git-send-email-xuyang2018.jy@fujitsu.com>

Hi Cyril

I have merged this patchset, thanks for your review.

Best Regards
Yang Xu
> When the identifier of the System V shared memory segment that shm_next_id stored
> is already in use, shmget() with different key will return the another shm id. But
> kernel doesn't guarantee desired id, I just compare with the existed id, if not
> equal, the test succeeds.
> 
> This case is similar to msgget05.c.
> 
> Reviewed-by: Cyril Hrubis<chrubis@suse.cz>
> Signed-off-by: Yang Xu<xuyang2018.jy@fujitsu.com>
> ---
>   runtest/syscalls                              |  1 +
>   runtest/syscalls-ipc                          |  1 +
>   .../kernel/syscalls/ipc/shmget/.gitignore     |  1 +
>   .../kernel/syscalls/ipc/shmget/shmget06.c     | 75 +++++++++++++++++++
>   4 files changed, 78 insertions(+)
>   create mode 100644 testcases/kernel/syscalls/ipc/shmget/shmget06.c
> 
> diff --git a/runtest/syscalls b/runtest/syscalls
> index b65b18c32..b379b2d90 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -1413,6 +1413,7 @@ shmget02 shmget02
>   shmget03 shmget03
>   shmget04 shmget04
>   shmget05 shmget05
> +shmget06 shmget06
> 
>   sigaction01 sigaction01
>   sigaction02 sigaction02
> diff --git a/runtest/syscalls-ipc b/runtest/syscalls-ipc
> index ff0364704..b758158c3 100644
> --- a/runtest/syscalls-ipc
> +++ b/runtest/syscalls-ipc
> @@ -68,3 +68,4 @@ shmget02 shmget02
>   shmget03 shmget03
>   shmget04 shmget04
>   shmget05 shmget05
> +shmget06 shmget06
> diff --git a/testcases/kernel/syscalls/ipc/shmget/.gitignore b/testcases/kernel/syscalls/ipc/shmget/.gitignore
> index 6f08529f8..768d1c69d 100644
> --- a/testcases/kernel/syscalls/ipc/shmget/.gitignore
> +++ b/testcases/kernel/syscalls/ipc/shmget/.gitignore
> @@ -2,3 +2,4 @@
>   /shmget03
>   /shmget04
>   /shmget05
> +/shmget06
> diff --git a/testcases/kernel/syscalls/ipc/shmget/shmget06.c b/testcases/kernel/syscalls/ipc/shmget/shmget06.c
> new file mode 100644
> index 000000000..d91b7b635
> --- /dev/null
> +++ b/testcases/kernel/syscalls/ipc/shmget/shmget06.c
> @@ -0,0 +1,75 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
> + * Author: Yang Xu<xuyang2018.jy@fujitsu.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * It is a basic test for shm_next_id.
> + *
> + * When the shared memory segment identifier that shm_next_id stored is already
> + * in use, call shmget with different key just use another unused value in range
> + * [0,INT_MAX]. Kernel doesn't guarantee the desired id.
> + */
> +
> +#include<errno.h>
> +#include<string.h>
> +#include<sys/types.h>
> +#include<sys/ipc.h>
> +#include<sys/shm.h>
> +#include "tst_test.h"
> +#include "tst_safe_sysv_ipc.h"
> +#include "libnewipc.h"
> +
> +#define NEXT_ID_PATH "/proc/sys/kernel/shm_next_id"
> +
> +static int shm_id[2], pid;
> +static key_t shmkey[2];
> +
> +static void verify_shmget(void)
> +{
> +	SAFE_FILE_PRINTF(NEXT_ID_PATH, "%d", shm_id[0]);
> +
> +	shm_id[1] = SAFE_SHMGET(shmkey[1], SHM_SIZE, IPC_CREAT | SHM_RW);
> +	if (shm_id[1] == shm_id[0])
> +		tst_res(TFAIL, "shm id %d has existed, shmget() returns the"
> +			" same shm id unexpectedly", shm_id[0]);
> +	else
> +		tst_res(TPASS, "shm id %d has existed, shmget() returns the"
> +			" new shm id %d", shm_id[0], shm_id[1]);
> +
> +	SAFE_SHMCTL(shm_id[1], IPC_RMID, NULL);
> +}
> +
> +static void setup(void)
> +{
> +	shmkey[0] = GETIPCKEY();
> +	shmkey[1] = GETIPCKEY();
> +	pid = getpid();
> +	SAFE_FILE_PRINTF(NEXT_ID_PATH, "%d", pid);
> +	shm_id[0] = SAFE_SHMGET(shmkey[0], SHM_SIZE, IPC_CREAT | SHM_RW);
> +}
> +
> +static void cleanup(void)
> +{
> +	int i;
> +
> +	for (i = 0; i<  2; i++) {
> +		if (shm_id[i] != -1)
> +			SAFE_SHMCTL(shm_id[i], IPC_RMID, NULL);
> +	}
> +}
> +
> +static struct tst_test test = {
> +	.needs_tmpdir = 1,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.test_all = verify_shmget,
> +	.needs_kconfigs = (const char *[]) {
> +		"CONFIG_CHECKPOINT_RESTORE=y",
> +		NULL
> +	},
> +	.needs_root = 1,
> +};

  reply	other threads:[~2021-07-27  2:13 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-12  8:52 [LTP] [PATCH v1 1/4] syscalls/shmget01: Remove it Yang Xu
2021-05-12  8:52 ` [LTP] [PATCH v1 2/4] syscalls/shmget*: Convert into new api Yang Xu
2021-05-12 10:44   ` xuyang2018.jy
2021-06-03  9:49     ` xuyang2018.jy
2021-06-18 14:28   ` Cyril Hrubis
2021-06-21  9:48     ` xuyang2018.jy
2021-06-22  8:31     ` [LTP] [PATCH v2] " Yang Xu
2021-06-23 13:35       ` Cyril Hrubis
2021-06-24  3:46         ` xuyang2018.jy
2021-05-12  8:52 ` [LTP] [PATCH v1 3/4] syscalls/shmget05: Add test for /proc/sys/kernel/shm_next_id Yang Xu
2021-06-29  3:25   ` xuyang2018.jy
2021-07-12  2:37     ` xuyang2018.jy
2021-07-22 11:52   ` Cyril Hrubis
2021-07-23  9:10     ` xuyang2018.jy
2021-05-12  8:52 ` [LTP] [PATCH v1 4/4] syscalls/shmget06: Add test when the id of shm_next_id has existed Yang Xu
2021-07-22 12:08   ` Cyril Hrubis
2021-07-23  9:15     ` xuyang2018.jy
2021-07-23  9:41     ` [LTP] [PATCH v2 1/2] syscalls/shmget05: Add test for /proc/sys/kernel/shm_next_id Yang Xu
2021-07-23  9:42       ` [LTP] [PATCH v2 2/2] syscalls/shmget06: Add test when shm_next_id is already in use Yang Xu
2021-07-27  2:13         ` xuyang2018.jy [this message]
2021-06-18 12:54 ` [LTP] [PATCH v1 1/4] syscalls/shmget01: Remove it 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=60FF6BE9.5040101@fujitsu.com \
    --to=xuyang2018.jy@fujitsu.com \
    --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