Skip to content

Commit e7f167b

Browse files
xuyang0410metan-ucw
authored andcommitted
syscalls/msgget04: Add test for /proc/sys/kernel/msg_next_id
Signed-off-by: Yang Xu <[email protected]> Reviewed-by: Cyril Hrubis <[email protected]>
1 parent 3e29ecc commit e7f167b

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

runtest/syscalls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ msgctl12 msgctl12
810810
msgget01 msgget01
811811
msgget02 msgget02
812812
msgget03 msgget03
813+
msgget04 msgget04
813814

814815
msgrcv01 msgrcv01
815816
msgrcv02 msgrcv02

runtest/syscalls-ipc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ msgctl12 msgctl12
1212
msgget01 msgget01
1313
msgget02 msgget02
1414
msgget03 msgget03
15+
msgget04 msgget04
1516

1617
msgrcv01 msgrcv01
1718
msgrcv02 msgrcv02
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/msgget01
22
/msgget02
33
/msgget03
4+
/msgget04
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
4+
* Author: Yang Xu <[email protected]>
5+
*
6+
* It is a basic test about msg_next_id.
7+
* msg_next_id specifies desired id for next allocated IPC message. By default
8+
* they are equal to -1, which means generic allocation logic. Possible values
9+
* to set are in range {0..INT_MAX}.
10+
* Toggle with non-default value will be set back to -1 by kernel after
11+
* successful IPC object allocation.
12+
*/
13+
14+
#include <errno.h>
15+
#include <string.h>
16+
#include <sys/types.h>
17+
#include <sys/ipc.h>
18+
#include <sys/msg.h>
19+
#include "tst_test.h"
20+
#include "tst_safe_sysv_ipc.h"
21+
#include "libnewipc.h"
22+
23+
#define NEXT_ID_PATH "/proc/sys/kernel/msg_next_id"
24+
static int queue_id, pid;
25+
static key_t msgkey;
26+
27+
static void verify_msgget(void)
28+
{
29+
SAFE_FILE_PRINTF(NEXT_ID_PATH, "%d", pid);
30+
31+
queue_id = SAFE_MSGGET(msgkey, IPC_CREAT | MSG_RW);
32+
if (queue_id == pid)
33+
tst_res(TPASS, "msg_next_id succeeded, queue id %d", pid);
34+
else
35+
tst_res(TFAIL, "msg_next_id failed, expected id %d, but got %d", pid, queue_id);
36+
37+
TST_ASSERT_INT(NEXT_ID_PATH, -1);
38+
SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
39+
pid++;
40+
}
41+
42+
static void setup(void)
43+
{
44+
msgkey = GETIPCKEY();
45+
pid = getpid();
46+
}
47+
48+
static void cleanup(void)
49+
{
50+
if (queue_id != -1)
51+
SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
52+
}
53+
54+
static struct tst_test test = {
55+
.setup = setup,
56+
.cleanup = cleanup,
57+
.test_all = verify_msgget,
58+
.needs_kconfigs = (const char *[]) {
59+
"CONFIG_CHECKPOINT_RESTORE=y",
60+
NULL
61+
},
62+
.needs_root = 1,
63+
};

0 commit comments

Comments
 (0)