1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Copyright (c) International Business Machines Corp., 2001 4 */ 5/* 6 * HISTORY 7 * 03/2001 - Written by Wayne Boyer 8 */ 9/*\ 10 * [Description] 11 * 12 * Test for semctl() ERANGE error 13 */ 14 15#include "tst_safe_sysv_ipc.h" 16#include "tst_test.h" 17#include "lapi/sem.h" 18#include "libnewipc.h" 19 20static int sem_id = -1; 21 22#define BIGV 65535 /* a number ((2^16)-1) that should be larger */ 23 /* than the maximum for a semaphore value */ 24 25unsigned short big_arr[] = { BIGV, BIGV, BIGV, BIGV, BIGV, BIGV, BIGV, BIGV, 26 BIGV, BIGV 27}; 28 29static struct tcases { 30 int count; 31 int cmd; 32 union semun t_arg; 33 char *message; 34} tests[] = { 35 {5, SETVAL, {.val = -1}, "the value to set is less than zero"}, 36 {0, SETALL, {.array = big_arr}, "the value to set are too large"}, 37 {5, SETVAL, {.val = BIGV}, "the value to set is too large"} 38}; 39 40static void verify_semctl(unsigned int n) 41{ 42 struct tcases *tc = &tests[n]; 43 44 TST_EXP_FAIL(semctl(sem_id, tc->count, tc->cmd, tc->t_arg), ERANGE, 45 "semctl() with %s", tc->message); 46} 47 48static void setup(void) 49{ 50 static key_t semkey; 51 52 semkey = GETIPCKEY(); 53 54 sem_id = SAFE_SEMGET(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA); 55} 56 57static void cleanup(void) 58{ 59 if (sem_id != -1) 60 SAFE_SEMCTL(sem_id, 0, IPC_RMID); 61} 62 63static struct tst_test test = { 64 .setup = setup, 65 .cleanup = cleanup, 66 .test = verify_semctl, 67 .tcnt = ARRAY_SIZE(tests), 68}; 69