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] syscalls/msgget04: Add test for /proc/sys/kernel/msg_next_id
Date: Wed, 12 Aug 2020 16:40:07 +0200	[thread overview]
Message-ID: <20200812144007.GA23472@yuki.lan> (raw)
In-Reply-To: <1595245614-24814-1-git-send-email-xuyang2018.jy@cn.fujitsu.com>

Hi!
> diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget04.c b/testcases/kernel/syscalls/ipc/msgget/msgget04.c
> new file mode 100644
> index 000000000..3791f331a
> --- /dev/null
> +++ b/testcases/kernel/syscalls/ipc/msgget/msgget04.c
> @@ -0,0 +1,66 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
> + * Author: Yang Xu <xuyang2018.jy@cn.jujitsu.com>
> + *
> + * It is a basic test about msg_next_id.
> + * msg_next_id specifies desired id for next allocated IPC message. By default
> + * they are equal to -1, which means generic allocation logic. Possible values
> + * to set are in range {0..INT_MAX}.
> + * Toggle with non-default value will be set back to -1 by kernel after
> + * successful IPC object allocation.
> + */
> +
> +#include <errno.h>
> +#include <string.h>
> +#include <sys/types.h>
> +#include <sys/ipc.h>
> +#include <sys/msg.h>
> +#include "tst_test.h"
> +#include "tst_safe_sysv_ipc.h"
> +#include "libnewipc.h"
> +
> +#define NEXT_ID_PATH "/proc/sys/kernel/msg_next_id"
> +static int queue_id = 1, pid;
> +static key_t msgkey;
> +
> +static void verify_msgget(void)
> +{
> +	SAFE_FILE_PRINTF(NEXT_ID_PATH, "%d", pid);
> +
> +	TEST(msgget(msgkey, IPC_CREAT | MSG_RW));
> +	if (TST_RET == -1) {
> +		tst_res(TFAIL | TTERRNO, "msgget() failed");
> +		return;
> +	}
> +
> +	queue_id = TST_RET;
> +	if (queue_id == pid)
> +		tst_res(TPASS, "msg_next_id succeeded, queue id %d", pid);
> +	else
> +		tst_res(TFAIL, "msg_next_id failed, expected id %d, but got %d", pid, queue_id);
> +
> +	TST_ASSERT_INT(NEXT_ID_PATH, -1);
> +	SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
> +	pid++;
> +}
> +
> +static void setup(void)
> +{
> +	msgkey = GETIPCKEY();
> +	pid = getpid();
> +}
> +
> +static void cleanup(void)
> +{
> +	if (queue_id != -1)
> +		SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
> +	SAFE_FILE_SCANF(NEXT_ID_PATH, "-1");

Shouldn't this be SAFE_FILE_PRINTF() ?

Otherwise it looks fine, also I can fix this one before pushing.



Also what happens when we write id of existing id to that file? I guess
that we can write another test that tries that...

> +}
> +
> +static struct tst_test test = {
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.test_all = verify_msgget,
> +	.needs_root = 1,
> +};
> -- 
> 2.23.0
> 
> 
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

  reply	other threads:[~2020-08-12 14:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-20 11:46 [LTP] [PATCH] syscalls/msgget04: Add test for /proc/sys/kernel/msg_next_id Yang Xu
2020-08-12 14:40 ` Cyril Hrubis [this message]
2020-08-13  2:55   ` Yang Xu
2020-08-13  3:29   ` [LTP] [PATCH v2] " Yang Xu
2020-08-13  3:47     ` Yang Xu

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=20200812144007.GA23472@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox