Skip to content

Commit 1fb6c0a

Browse files
vireshkmetan-ucw
authored andcommitted
syscalls/semop: Migrate to new test framework
This basically rewrites most of the code, merges a few tests and cleans up the code a lot. Signed-off-by: Viresh Kumar <[email protected]> Signed-off-by: Cyril Hrubis <[email protected]>
1 parent 42477ed commit 1fb6c0a

File tree

9 files changed

+267
-855
lines changed

9 files changed

+267
-855
lines changed

runtest/syscalls

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,8 +1172,6 @@ semget06 semget06
11721172
semop01 semop01
11731173
semop02 semop02
11741174
semop03 semop03
1175-
semop04 semop04
1176-
semop05 semop05
11771175

11781176
send01 send01
11791177

runtest/syscalls-ipc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ semget06 semget06
4545
semop01 semop01
4646
semop02 semop02
4747
semop03 semop03
48-
semop04 semop04
49-
semop05 semop05
5048

5149
shmat01 shmat01
5250
shmat02 shmat02
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
/semop01
22
/semop02
33
/semop03
4-
/semop04
5-
/semop05

testcases/kernel/syscalls/ipc/semop/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
top_srcdir ?= ../../../../..
55

6-
LTPLIBS = ltpipc
6+
LTPLIBS = ltpnewipc
77

88
include $(top_srcdir)/include/mk/testcases.mk
99

10-
LTPLDLIBS = -lltpipc
10+
LTPLDLIBS = -lltpnewipc
1111

1212
include $(top_srcdir)/include/mk/generic_leaf_target.mk
Lines changed: 55 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,143 +1,68 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
12
/*
3+
* Test that semop() basic functionality is correct
24
*
3-
* Copyright (c) International Business Machines Corp., 2001
4-
*
5-
* This program is free software; you can redistribute it and/or modify
6-
* it under the terms of the GNU General Public License as published by
7-
* the Free Software Foundation; either version 2 of the License, or
8-
* (at your option) any later version.
9-
*
10-
* This program is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13-
* the GNU General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU General Public License
16-
* along with this program; if not, write to the Free Software
17-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18-
*/
19-
20-
/*
21-
* NAME
22-
* semop01.c
23-
*
24-
* DESCRIPTION
25-
* semop01 - test that semop() basic functionality is correct
26-
*
27-
* ALGORITHM
28-
* create a semaphore set and initialize some values
29-
* loop if that option was specified
30-
* call semop() to set values for the primitive semaphores
31-
* check the return code
32-
* if failure, issue a FAIL message.
33-
* otherwise,
34-
* if doing functionality testing
35-
* get the semaphore values and compare with expected values
36-
* if correct,
37-
* issue a PASS message
38-
* otherwise
39-
* issue a FAIL message
40-
* else issue a PASS message
41-
* call cleanup
42-
*
43-
* HISTORY
44-
* 03/2001 - Written by Wayne Boyer
5+
* Copyright (c) International Business Machines Corp., 2001
6+
* 03/2001 - Written by Wayne Boyer
457
* 17/01/02 - Modified. Manoj Iyer, IBM Austin. TX. [email protected]
46-
* 4th argument to semctl() system call was modified according
47-
* to man pages.
48-
* In my opinion The test should not even have compiled but
49-
* it was working due to some mysterious reason.
50-
*
51-
* RESTRICTIONS
52-
* none
538
*/
549

55-
#include "ipcsem.h"
56-
57-
#define NSEMS 4 /* the number of primitive semaphores to test */
10+
#include <stdlib.h>
11+
#include <sys/sem.h>
12+
#include "tst_test.h"
13+
#include "libnewipc.h"
14+
#include "lapi/semun.h"
5815

59-
char *TCID = "semop01";
60-
int TST_TOTAL = 1;
16+
#define NSEMS 4
6117

62-
int sem_id_1 = -1; /* a semaphore set with read & alter permissions */
18+
static int sem_id = -1;
19+
static key_t semkey;
6320

64-
union semun get_arr;
65-
struct sembuf sops[PSEMS];
21+
static unsigned short int sarr[PSEMS];
22+
static union semun get_arr = {.array = sarr};
23+
static struct sembuf sops[PSEMS];
6624

67-
int main(int ac, char **av)
25+
static void run(void)
6826
{
69-
int lc;
70-
int i;
27+
union semun arr = { .val = 0 };
7128
int fail = 0;
29+
int i;
7230

73-
tst_parse_opts(ac, av, NULL, NULL);
74-
75-
setup();
76-
77-
for (lc = 0; TEST_LOOPING(lc); lc++) {
78-
tst_count = 0;
79-
80-
TEST(semop(sem_id_1, sops, NSEMS));
81-
82-
if (TEST_RETURN == -1) {
83-
tst_resm(TFAIL, "%s call failed - errno = %d : %s",
84-
TCID, TEST_ERRNO, strerror(TEST_ERRNO));
85-
} else {
86-
/* get the values and make sure they */
87-
/* are the same as what was set */
88-
if (semctl(sem_id_1, 0, GETALL, get_arr) == -1) {
89-
tst_brkm(TBROK, cleanup,
90-
"semctl() failed in functional test");
91-
}
92-
93-
for (i = 0; i < NSEMS; i++) {
94-
if (get_arr.array[i] != i * i) {
95-
fail = 1;
96-
}
97-
}
98-
if (fail)
99-
tst_resm(TFAIL,
100-
"semaphore values are wrong");
101-
else
102-
tst_resm(TPASS,
103-
"semaphore values are correct");
104-
}
31+
TEST(semop(sem_id, sops, NSEMS));
32+
if (TST_RET == -1) {
33+
tst_res(TFAIL | TTERRNO, "semop() failed");
34+
return;
35+
}
36+
37+
if (semctl(sem_id, 0, GETALL, get_arr) == -1)
38+
tst_brk(TBROK | TERRNO, "semctl(%i, 0, GETALL, ...)", sem_id);
10539

106-
/*
107-
* clean up things in case we are looping
108-
*/
109-
union semun set_arr;
110-
set_arr.val = 0;
111-
for (i = 0; i < NSEMS; i++) {
112-
if (semctl(sem_id_1, i, SETVAL, set_arr) == -1) {
113-
tst_brkm(TBROK, cleanup, "semctl failed");
114-
}
40+
for (i = 0; i < NSEMS; i++) {
41+
if (get_arr.array[i] != i * i) {
42+
fail = 1;
11543
}
11644
}
11745

118-
cleanup();
119-
tst_exit();
46+
if (fail)
47+
tst_res(TFAIL, "semaphore values are wrong");
48+
else
49+
tst_res(TPASS, "semaphore values are correct");
50+
51+
for (i = 0; i < NSEMS; i++) {
52+
if (semctl(sem_id, i, SETVAL, arr) == -1)
53+
tst_brk(TBROK | TERRNO, "semctl(%i, %i, SETVAL, ...)", sem_id, i);
54+
}
12055
}
12156

122-
void setup(void)
57+
static void setup(void)
12358
{
12459
int i;
12560

126-
tst_sig(NOFORK, DEF_HANDLER, cleanup);
127-
128-
TEST_PAUSE;
61+
semkey = GETIPCKEY();
12962

130-
tst_tmpdir();
131-
132-
get_arr.array = malloc(sizeof(unsigned short int) * PSEMS);
133-
if (get_arr.array == NULL)
134-
tst_brkm(TBROK, cleanup, "malloc failed");
135-
136-
semkey = getipckey();
137-
138-
sem_id_1 = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA);
139-
if (sem_id_1 == -1)
140-
tst_brkm(TBROK, cleanup, "couldn't create semaphore in setup");
63+
sem_id = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA);
64+
if (sem_id == -1)
65+
tst_brk(TBROK | TERRNO, "couldn't create semaphore in setup");
14166

14267
for (i = 0; i < NSEMS; i++) {
14368
sops[i].sem_num = i;
@@ -146,11 +71,17 @@ void setup(void)
14671
}
14772
}
14873

149-
void cleanup(void)
74+
static void cleanup(void)
15075
{
151-
rm_sema(sem_id_1);
152-
153-
free(get_arr.array);
154-
155-
tst_rmdir();
76+
if (sem_id != -1) {
77+
if (semctl(sem_id, 0, IPC_RMID) == -1)
78+
tst_res(TWARN, "semaphore deletion failed.");
79+
}
15680
}
81+
82+
static struct tst_test test = {
83+
.test_all = run,
84+
.setup = setup,
85+
.cleanup = cleanup,
86+
.needs_tmpdir = 1,
87+
};

0 commit comments

Comments
 (0)