Skip to content

Commit

Permalink
syscalls/ipc: Add shmctl07 test
Browse files Browse the repository at this point in the history
A new test for SHM_LOCK and SHM_UNLOCK.

Signed-off-by: Cyril Hrubis <[email protected]>
Reviewed-by: Li Wang <[email protected]>
  • Loading branch information
metan-ucw committed Sep 10, 2020
1 parent 3ff3dc7 commit d54c87f
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions runtest/syscalls
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,7 @@ shmctl03 shmctl03
shmctl04 shmctl04
shmctl05 shmctl05
shmctl06 shmctl06
shmctl07 shmctl07

shmdt01 shmdt01
shmdt02 shmdt02
Expand Down
1 change: 1 addition & 0 deletions runtest/syscalls-ipc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ shmctl03 shmctl03
shmctl04 shmctl04
shmctl05 shmctl05
shmctl06 shmctl06
shmctl07 shmctl07

shmdt01 shmdt01
shmdt02 shmdt02
Expand Down
1 change: 1 addition & 0 deletions testcases/kernel/syscalls/ipc/shmctl/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/shmctl04
/shmctl05
/shmctl06
/shmctl07
68 changes: 68 additions & 0 deletions testcases/kernel/syscalls/ipc/shmctl/shmctl07.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2020 Cyril Hrubis <[email protected]>
*/
/*
* Test for a SHM_LOCK and SHM_UNLOCK.
*/

#define _GNU_SOURCE
#include <stdio.h>
#include "tst_test.h"
#include "tst_safe_sysv_ipc.h"
#include "libnewipc.h"

#define SHM_SIZE 2048

static int shm_id = -1;

static void verify_shmlock(void)
{
struct shmid_ds ds;

TEST(shmctl(shm_id, SHM_LOCK, NULL));

if (TST_RET != 0)
tst_res(TFAIL | TTERRNO, "shmctl(%i, SHM_LOCK, NULL)", shm_id);
else
tst_res(TPASS, "shmctl(%i, SHM_LOCK, NULL)", shm_id);


SAFE_SHMCTL(shm_id, IPC_STAT, &ds);

if (ds.shm_perm.mode & SHM_LOCKED)
tst_res(TPASS, "SMH_LOCKED bit is on in shm_perm.mode");
else
tst_res(TFAIL, "SHM_LOCKED bit is off in shm_perm.mode");

TEST(shmctl(shm_id, SHM_UNLOCK, NULL));

if (TST_RET != 0)
tst_res(TFAIL | TTERRNO, "shmctl(%i, SHM_UNLOCK, NULL)", shm_id);
else
tst_res(TPASS, "shmctl(%i, SHM_UNLOCK, NULL)", shm_id);

SAFE_SHMCTL(shm_id, IPC_STAT, &ds);

if (ds.shm_perm.mode & SHM_LOCKED)
tst_res(TFAIL, "SMH_LOCKED bit is on in shm_perm.mode");
else
tst_res(TPASS, "SHM_LOCKED bit is off in shm_perm.mode");
}

static void setup(void)
{
shm_id = SAFE_SHMGET(IPC_PRIVATE, SHM_SIZE, IPC_CREAT | SHM_RW);
}

static void cleanup(void)
{
if (shm_id >= 0)
SAFE_SHMCTL(shm_id, IPC_RMID, NULL);
}

static struct tst_test test = {
.setup = setup,
.cleanup = cleanup,
.test_all = verify_shmlock,
};

0 comments on commit d54c87f

Please sign in to comment.