Skip to content

Commit

Permalink
shmctl01: don't use hardcoded index == 0 for SHM_STAT test
Browse files Browse the repository at this point in the history
Test fails on SHM_STAT testcase:
   shmctl01    5  TFAIL  :  shmctl01.c:173: shmctl01 call failed
                            errno = 22 : Invalid argument
   shmctl(0, SHM_STAT, 0x601060)           = -EINVAL

since following commit:
   commit 99db46ea292780cd978d56932d9445b1e8bdafe8
   Author: Manfred Spraul <manfred@colorfullife.com>
   Date:   Tue May 14 15:46:36 2019 -0700
     ipc: do cyclic id allocation for the ipc object.

Don't rely on index 0 being always available, but instead
use (maximum) index returned by SHM_INFO.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Acked-by: Cyril Hrubis <chrubis@suse.cz>
  • Loading branch information
jstancek committed May 21, 2019
1 parent d656a44 commit db0a43d
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions testcases/kernel/syscalls/ipc/shmctl/shmctl01.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ static void func_info(int ret);

/* Check routine for SHM_STAT */
static void func_sstat(int ret);
static void func_sstat_setup(void);

/* Check routine for SHM_LOCK */
static void func_lock(int ret);
Expand Down Expand Up @@ -110,7 +111,7 @@ static struct test_case_t {
#endif
{&shm_id_1, IPC_SET, &buf, func_set, set_setup},
{&shm_id_1, IPC_INFO, (struct shmid_ds *) &info, func_info, NULL},
{&shm_index, SHM_STAT, &buf, func_sstat, NULL},
{&shm_index, SHM_STAT, &buf, func_sstat, func_sstat_setup},
{&shm_id_1, SHM_LOCK, NULL, func_lock, NULL},
{&shm_id_1, SHM_UNLOCK, NULL, func_unlock, NULL},
{&shm_id_1, IPC_RMID, NULL, func_rmid, NULL},
Expand Down Expand Up @@ -407,9 +408,23 @@ static void func_info(int ret)
static void func_sstat(int ret)
{
if (ret >= 0)
tst_resm(TPASS, "get correct shared memory id");
tst_resm(TPASS, "get correct shared memory id for index: %d",
shm_index);
else
tst_resm(TFAIL, "shared memory id is incorrect");
tst_resm(TFAIL, "shared memory id is incorrect, index: %d",
shm_index);
}

static void func_sstat_setup(void)
{
struct shm_info tmp;
int ret;

ret = shmctl(shm_id_1, SHM_INFO, (void *)&tmp);
if (ret < 0)
tst_resm(TFAIL|TERRNO, "shmctl(SHM_INFO)");
else
shm_index = ret;
}

static void func_lock(int ret)
Expand Down

0 comments on commit db0a43d

Please sign in to comment.