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