* [LTP] [PATCH 1/4] lapi/sem.h: Add SEMMSL macro
@ 2023-03-20 6:30 Yang Xu
2023-03-20 6:30 ` [LTP] [PATCH 2/4] ipc/semget02,03,06: Convert into new api Yang Xu
` (3 more replies)
0 siblings, 4 replies; 13+ messages in thread
From: Yang Xu @ 2023-03-20 6:30 UTC (permalink / raw)
To: ltp
This macro is used to trigger semget EINVAL error.
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
include/lapi/sem.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/include/lapi/sem.h b/include/lapi/sem.h
index 495afe937..ba559d2f1 100644
--- a/include/lapi/sem.h
+++ b/include/lapi/sem.h
@@ -24,4 +24,8 @@ union semun {
# define SEM_STAT_ANY 20
#endif
+#ifndef SEMMSL
+# define SEMMSL 32000
+#endif
+
#endif /* LAPI_SEM_H__ */
--
2.39.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [LTP] [PATCH 2/4] ipc/semget02,03,06: Convert into new api
2023-03-20 6:30 [LTP] [PATCH 1/4] lapi/sem.h: Add SEMMSL macro Yang Xu
@ 2023-03-20 6:30 ` Yang Xu
2023-04-13 9:38 ` Li Wang
2023-03-20 6:30 ` [LTP] [PATCH 3/4] libs/libnewipc: Add GET_USED_ARRAYS api Yang Xu
` (2 subsequent siblings)
3 siblings, 1 reply; 13+ messages in thread
From: Yang Xu @ 2023-03-20 6:30 UTC (permalink / raw)
To: ltp
Merged semget03.c and semget06.c into semget02.c.
Also use SEMMSL macro instead of 32000 and add EINVAL
error test when key exists but nsems is larger than old.
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
runtest/syscalls | 2 -
runtest/syscalls-ipc | 2 -
.../kernel/syscalls/ipc/semget/.gitignore | 2 -
testcases/kernel/syscalls/ipc/semget/Makefile | 4 +-
.../kernel/syscalls/ipc/semget/semget02.c | 221 +++++++-----------
.../kernel/syscalls/ipc/semget/semget03.c | 133 -----------
.../kernel/syscalls/ipc/semget/semget06.c | 143 ------------
7 files changed, 81 insertions(+), 426 deletions(-)
delete mode 100644 testcases/kernel/syscalls/ipc/semget/semget03.c
delete mode 100644 testcases/kernel/syscalls/ipc/semget/semget06.c
diff --git a/runtest/syscalls b/runtest/syscalls
index b9d4a43c8..9c96f57f7 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1237,9 +1237,7 @@ semctl09 semctl09
semget01 semget01
semget02 semget02
-semget03 semget03
semget05 semget05
-semget06 semget06
semop01 semop01
semop02 semop02
diff --git a/runtest/syscalls-ipc b/runtest/syscalls-ipc
index b758158c3..df41140a7 100644
--- a/runtest/syscalls-ipc
+++ b/runtest/syscalls-ipc
@@ -41,9 +41,7 @@ semctl09 semctl09
semget01 semget01
semget02 semget02
-semget03 semget03
semget05 semget05
-semget06 semget06
semop01 semop01
semop02 semop02
diff --git a/testcases/kernel/syscalls/ipc/semget/.gitignore b/testcases/kernel/syscalls/ipc/semget/.gitignore
index ce26c93b0..4519b30d2 100644
--- a/testcases/kernel/syscalls/ipc/semget/.gitignore
+++ b/testcases/kernel/syscalls/ipc/semget/.gitignore
@@ -1,5 +1,3 @@
/semget01
/semget02
-/semget03
/semget05
-/semget06
diff --git a/testcases/kernel/syscalls/ipc/semget/Makefile b/testcases/kernel/syscalls/ipc/semget/Makefile
index c41744764..2f98c36ca 100644
--- a/testcases/kernel/syscalls/ipc/semget/Makefile
+++ b/testcases/kernel/syscalls/ipc/semget/Makefile
@@ -7,7 +7,7 @@ LTPLIBS = ltpipc ltpnewipc
include $(top_srcdir)/include/mk/testcases.mk
-semget01: LTPLDLIBS = -lltpnewipc
-semget02 semget03 semget04 semget05 semget06: LTPLDLIBS = -lltpipc
+semget01 semget02: LTPLDLIBS = -lltpnewipc
+semget05: LTPLDLIBS = -lltpipc
include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/ipc/semget/semget02.c b/testcases/kernel/syscalls/ipc/semget/semget02.c
index 4124514c2..4273c84c7 100644
--- a/testcases/kernel/syscalls/ipc/semget/semget02.c
+++ b/testcases/kernel/syscalls/ipc/semget/semget02.c
@@ -1,165 +1,102 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
- *
- * Copyright (c) International Business Machines Corp., 2001
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines Corp., 2001
*/
-/*
- * NAME
- * semget02.c
+/*\
+ * [Description]
*
- * DESCRIPTION
- * semget02 - test for EACCES and EEXIST errors
+ * This basic error handing of the semget syscall.
*
- * ALGORITHM
- * create a semaphore set without read or alter permissions
- * loop if that option was specified
- * call semget() using two different invalid cases
- * check the errno value
- * issue a PASS message if we get EACCES or EEXIST
- * otherwise, the tests fails
- * issue a FAIL message
- * call cleanup
- *
- * USAGE: <for command-line>
- * semget02 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- * where, -c n : Run n copies concurrently.
- * -e : Turn on errno logging.
- * -i n : Execute test n times.
- * -I x : Execute test for x seconds.
- * -P x : Pause for x seconds between iterations.
- * -t : Turn on syscall timing.
- *
- * HISTORY
- * 03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- * none
+ * - EACCES - a semaphore set exists for key, but the calling process does not
+ * have permission to access the set
+ * - EEXIST - a semaphore set already exists for key and IPC_CREAT | IPC_EXCL
+ * is given
+ * - ENOENT - No semaphore set exists for key and semflg did not specify
+ * IPC_CREAT
+ * - EINVAL - nsems is less than 0 or greater than the limit on the number of
+ * semaphores per semaphore set(SEMMSL)
+ * - EINVAL - a semaphore set corresponding to key already exists, but nsems is
+ * larger than the number of semaphores in that set
*/
-#include <pwd.h>
-
-#include "ipcsem.h"
-char *TCID = "semget02";
-int TST_TOTAL = 2;
-
-char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
-
-int sem_id_1 = -1;
-
-struct test_case_t {
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/types.h>
+#include <pwd.h>
+#include "tst_test.h"
+#include "tst_safe_sysv_ipc.h"
+#include "libnewipc.h"
+#include "lapi/sem.h"
+
+static int sem_id = -1;
+static key_t semkey, semkey1;
+static struct passwd *pw;
+static struct tcase {
+ int *key;
+ int nsems;
int flags;
- int error;
-} TC[] = {
- /* EACCES - the semaphore has no read or alter permissions */
- {
- SEM_RA, EACCES},
- /* EEXIST - the semaphore id exists and semget() was called with */
- /* IPC_CREAT and IPC_EXCL */
- {
- IPC_CREAT | IPC_EXCL, EEXIST}
+ int exp_err;
+ /*1: nobody expected, 0: root expected */
+ int exp_user;
+} tcases[] = {
+ {&semkey, PSEMS, SEM_RA, EACCES, 1},
+ {&semkey, PSEMS, IPC_CREAT | IPC_EXCL, EEXIST, 0},
+ {&semkey1, PSEMS, SEM_RA, ENOENT, 0},
+ {&semkey1, -1, IPC_CREAT | IPC_EXCL, EINVAL, 0},
+ {&semkey1, SEMMSL + 1, IPC_CREAT | IPC_EXCL, EINVAL, 0},
+ {&semkey, PSEMS + 1, SEM_RA, EINVAL, 0},
};
-int main(int ac, char **av)
+static void verify_semget(struct tcase *tc)
{
- int lc;
- int i;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
- setup(); /* global setup */
-
- /* The following loop checks looping state if -i option given */
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- /* reset tst_count in case we are looping */
- tst_count = 0;
-
- for (i = 0; i < TST_TOTAL; i++) {
- /* use the TEST macro to make the call */
-
- TEST(semget(semkey, PSEMS, TC[i].flags));
-
- if (TEST_RETURN != -1) {
- sem_id_1 = TEST_RETURN;
- tst_resm(TFAIL, "call succeeded");
- continue;
- }
+ TST_EXP_FAIL2(semget(*tc->key, tc->nsems, tc->flags), tc->exp_err,
+ "semget(%i, %i, %i)", *tc->key, tc->nsems, tc->flags);
+}
- if (TEST_ERRNO == TC[i].error) {
- tst_resm(TPASS, "expected failure - errno "
- "= %d : %s", TEST_ERRNO,
- strerror(TEST_ERRNO));
- } else {
- tst_resm(TFAIL, "unexpected error - %d : %s",
- TEST_ERRNO, strerror(TEST_ERRNO));
- }
+static void do_test(unsigned int n)
+{
+ pid_t pid;
+ struct tcase *tc = &tcases[n];
+
+ if (tc->exp_user == 0) {
+ verify_semget(tc);
+ } else {
+ pid = SAFE_FORK();
+ if (pid) {
+ tst_reap_children();
+ } else {
+ SAFE_SETUID(pw->pw_uid);
+ verify_semget(tc);
+ exit(0);
}
}
-
- cleanup();
-
- tst_exit();
}
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
+static void setup(void)
{
- tst_require_root();
-
- /* Switch to nobody user for correct error code collection */
- ltpuser = getpwnam(nobody_uid);
- if (seteuid(ltpuser->pw_uid) == -1) {
- tst_resm(TINFO, "setreuid failed to "
- "to set the effective uid to %d", ltpuser->pw_uid);
- perror("setreuid");
- }
-
- tst_sig(NOFORK, DEF_HANDLER, cleanup);
+ semkey = GETIPCKEY();
+ semkey1 = GETIPCKEY();
- TEST_PAUSE;
+ sem_id = SAFE_SEMGET(semkey, PSEMS, IPC_CREAT | IPC_EXCL);
- /*
- * Create a temporary directory and cd into it.
- * This helps to ensure that a unique msgkey is created.
- * See libs/libltpipc/libipc.c for more information.
- */
- tst_tmpdir();
-
- /* get an IPC resource key */
- semkey = getipckey();
-
- /* create a semaphore set without read or alter permissions */
- if ((sem_id_1 = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL)) == -1) {
- tst_brkm(TBROK, cleanup, "couldn't create semaphore in setup");
- }
+ pw = SAFE_GETPWNAM("nobody");
}
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * or premature exit.
- */
-void cleanup(void)
+static void cleanup(void)
{
- /* if it exists, remove the semaphore resource */
- rm_sema(sem_id_1);
-
- tst_rmdir();
-
+ if (sem_id != -1)
+ SAFE_SEMCTL(sem_id, PSEMS, IPC_RMID);
}
+
+static struct tst_test test = {
+ .needs_tmpdir = 1,
+ .needs_root = 1,
+ .forks_child = 1,
+ .tcnt = ARRAY_SIZE(tcases),
+ .setup = setup,
+ .cleanup = cleanup,
+ .test = do_test,
+};
diff --git a/testcases/kernel/syscalls/ipc/semget/semget03.c b/testcases/kernel/syscalls/ipc/semget/semget03.c
deleted file mode 100644
index 995b4bd3a..000000000
--- a/testcases/kernel/syscalls/ipc/semget/semget03.c
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- *
- * Copyright (c) International Business Machines Corp., 2001
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * NAME
- * semget03.c
- *
- * DESCRIPTION
- * semget03 - test for ENOENT error
- *
- * ALGORITHM
- * loop if that option was specified
- * call semget() with a valid key but with no associated semaphore set
- * and IPC_CREAT is not asserted
- * check the errno value
- * issue a PASS message if we get ENOENT
- * otherwise, the tests fails
- * issue a FAIL message
- * call cleanup
- *
- * USAGE: <for command-line>
- * semget03 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- * where, -c n : Run n copies concurrently.
- * -e : Turn on errno logging.
- * -i n : Execute test n times.
- * -I x : Execute test for x seconds.
- * -P x : Pause for x seconds between iterations.
- * -t : Turn on syscall timing.
- *
- * HISTORY
- * 03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- * none
- */
-
-#include "ipcsem.h"
-
-char *TCID = "semget03";
-int TST_TOTAL = 1;
-
-int sem_id_1 = -1;
-
-int main(int ac, char **av)
-{
- int lc;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
- setup(); /* global setup */
-
- /* The following loop checks looping state if -i option given */
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- /* reset tst_count in case we are looping */
- tst_count = 0;
-
- /* use the TEST macro to make the call */
-
- TEST(semget(semkey, PSEMS, SEM_RA));
-
- if (TEST_RETURN != -1) {
- sem_id_1 = TEST_RETURN;
- tst_resm(TFAIL, "call succeeded when error expected");
- continue;
- }
-
- switch (TEST_ERRNO) {
- case ENOENT:
- tst_resm(TPASS, "expected failure - errno "
- "= %d : %s", TEST_ERRNO, strerror(TEST_ERRNO));
- break;
- default:
- tst_resm(TFAIL, "unexpected error - %d : %s",
- TEST_ERRNO, strerror(TEST_ERRNO));
- break;
- }
- }
-
- cleanup();
-
- tst_exit();
-}
-
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
-{
-
- tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
- TEST_PAUSE;
-
- /*
- * Create a temporary directory and cd into it.
- * This helps to ensure that a unique msgkey is created.
- * See libs/libltpipc/libipc.c for more information.
- */
- tst_tmpdir();
-
- /* get an IPC resource key */
- semkey = getipckey();
-}
-
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * or premature exit.
- */
-void cleanup(void)
-{
- /* if it exists, remove the semaphore resource */
- rm_sema(sem_id_1);
-
- tst_rmdir();
-
-}
diff --git a/testcases/kernel/syscalls/ipc/semget/semget06.c b/testcases/kernel/syscalls/ipc/semget/semget06.c
deleted file mode 100644
index 52297c010..000000000
--- a/testcases/kernel/syscalls/ipc/semget/semget06.c
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- *
- * Copyright (c) International Business Machines Corp., 2001
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * NAME
- * semget06.c
- *
- * DESCRIPTION
- * semget06 - test for EINVAL error
- *
- * ALGORITHM
- * loop if that option was specified
- * call semget() using two different invalid cases - too many and too
- * few primitive semaphores
- * check the errno value
- * issue a PASS message if we get EINVAL
- * otherwise, the tests fails
- * issue a FAIL message
- * call cleanup
- *
- * USAGE: <for command-line>
- * semget06 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- * where, -c n : Run n copies concurrently.
- * -e : Turn on errno logging.
- * -i n : Execute test n times.
- * -I x : Execute test for x seconds.
- * -P x : Pause for x seconds between iterations.
- * -t : Turn on syscall timing.
- *
- * HISTORY
- * 03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- * none
- */
-
-#include "ipcsem.h"
-
-char *TCID = "semget06";
-int TST_TOTAL = 2;
-
-#define LARGENUM 1024 * 32
-#define SMALLNUM -1
-
-int sem_id_1 = -1;
-
-int num_sems[] = { LARGENUM, SMALLNUM };
-
-int main(int ac, char **av)
-{
- int lc;
- int i;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
- setup(); /* global setup */
-
- /* The following loop checks looping state if -i option given */
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- /* reset tst_count in case we are looping */
- tst_count = 0;
-
- /* loop through the test cases */
-
- for (i = 0; i < TST_TOTAL; i++) {
- TEST(semget(semkey, num_sems[i],
- IPC_CREAT | IPC_EXCL | SEM_RA));
-
- if (TEST_RETURN != -1) {
- sem_id_1 = TEST_RETURN;
- tst_resm(TFAIL, "call succeeded");
- continue;
- }
-
- switch (TEST_ERRNO) {
- case EINVAL:
- tst_resm(TPASS, "expected failure - errno "
- "= %d : %s", TEST_ERRNO,
- strerror(TEST_ERRNO));
- break;
- default:
- tst_resm(TFAIL, "unexpected error - %d : %s",
- TEST_ERRNO, strerror(TEST_ERRNO));
- break;
- }
- }
- }
-
- cleanup();
-
- tst_exit();
-}
-
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
-{
-
- tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
- TEST_PAUSE;
-
- /*
- * Create a temporary directory and cd into it.
- * This helps to ensure that a unique msgkey is created.
- * See libs/libltpipc/libipc.c for more information.
- */
- tst_tmpdir();
-
- /* get an IPC resource key */
- semkey = getipckey();
-}
-
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * or premature exit.
- */
-void cleanup(void)
-{
- /* if it exists, remove the semaphore resource */
- rm_sema(sem_id_1);
-
- tst_rmdir();
-
-}
--
2.39.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [LTP] [PATCH 3/4] libs/libnewipc: Add GET_USED_ARRAYS api
2023-03-20 6:30 [LTP] [PATCH 1/4] lapi/sem.h: Add SEMMSL macro Yang Xu
2023-03-20 6:30 ` [LTP] [PATCH 2/4] ipc/semget02,03,06: Convert into new api Yang Xu
@ 2023-03-20 6:30 ` Yang Xu
2023-03-20 6:30 ` [LTP] [PATCH 4/4] ipc/semget05: Convert into new api Yang Xu
2023-03-29 7:52 ` [LTP] [PATCH 1/4] lapi/sem.h: Add SEMMSL macro xuyang2018.jy
3 siblings, 0 replies; 13+ messages in thread
From: Yang Xu @ 2023-03-20 6:30 UTC (permalink / raw)
To: ltp
This api is used to get the semaphore arrays resource total.
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
include/libnewipc.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/include/libnewipc.h b/include/libnewipc.h
index 1e126ca1c..969c93292 100644
--- a/include/libnewipc.h
+++ b/include/libnewipc.h
@@ -53,6 +53,8 @@ int get_used_sysvipc(const char *file, const int lineno, const char *sysvipc_fil
get_used_sysvipc(__FILE__, __LINE__, "/proc/sysvipc/msg")
#define GET_USED_SEGMENTS() \
get_used_sysvipc(__FILE__, __LINE__, "/proc/sysvipc/shm")
+#define GET_USED_ARRAYS() \
+ get_used_sysvipc(__FILE__, __LINE__, "/proc/sysvipc/sem")
void *probe_free_addr(const char *file, const int lineno);
#define PROBE_FREE_ADDR() \
--
2.39.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [LTP] [PATCH 4/4] ipc/semget05: Convert into new api
2023-03-20 6:30 [LTP] [PATCH 1/4] lapi/sem.h: Add SEMMSL macro Yang Xu
2023-03-20 6:30 ` [LTP] [PATCH 2/4] ipc/semget02,03,06: Convert into new api Yang Xu
2023-03-20 6:30 ` [LTP] [PATCH 3/4] libs/libnewipc: Add GET_USED_ARRAYS api Yang Xu
@ 2023-03-20 6:30 ` Yang Xu
2023-04-13 9:46 ` Li Wang
2023-03-29 7:52 ` [LTP] [PATCH 1/4] lapi/sem.h: Add SEMMSL macro xuyang2018.jy
3 siblings, 1 reply; 13+ messages in thread
From: Yang Xu @ 2023-03-20 6:30 UTC (permalink / raw)
To: ltp
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="y", Size: 6830 bytes --]
Use the same logic as shmget03 and msget02 to trigger ENOSPC error.
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
testcases/kernel/syscalls/ipc/semget/Makefile | 5 +-
.../kernel/syscalls/ipc/semget/semget05.c | 187 ++++++------------
2 files changed, 59 insertions(+), 133 deletions(-)
diff --git a/testcases/kernel/syscalls/ipc/semget/Makefile b/testcases/kernel/syscalls/ipc/semget/Makefile
index 2f98c36ca..b1201281d 100644
--- a/testcases/kernel/syscalls/ipc/semget/Makefile
+++ b/testcases/kernel/syscalls/ipc/semget/Makefile
@@ -3,11 +3,10 @@
top_srcdir ?= ../../../../..
-LTPLIBS = ltpipc ltpnewipc
+LTPLIBS = ltpnewipc
include $(top_srcdir)/include/mk/testcases.mk
-semget01 semget02: LTPLDLIBS = -lltpnewipc
-semget05: LTPLDLIBS = -lltpipc
+LTPLDLIBS = -lltpnewipc
include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/ipc/semget/semget05.c b/testcases/kernel/syscalls/ipc/semget/semget05.c
index f801cb8ed..38b0fad3c 100644
--- a/testcases/kernel/syscalls/ipc/semget/semget05.c
+++ b/testcases/kernel/syscalls/ipc/semget/semget05.c
@@ -1,152 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
- *
- * Copyright (c) International Business Machines Corp., 2001
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines Corp., 2001
*/
-/*
- * NAME
- * semget05.c
+/*\
+ * [Description]
*
- * DESCRIPTION
- * semget05 - test for ENOSPC error
+ * Test for ENOSPC error.
*
- * ALGORITHM
- * create semaphore sets in a loop until the system limit is reached
- * loop if that option was specified
- * attempt to create yet another semaphore set
- * check the errno value
- * issue a PASS message if we get ENOSPC
- * otherwise, the tests fails
- * issue a FAIL message
- * call cleanup
- *
- * USAGE: <for command-line>
- * HISTORY
- * 03/2001 - Written by Wayne Boyer
- * 07/2006 - Changes By Michael Reed
- * - Changed the value of MAXIDS for the specific machine by reading
- * the system limit for SEMMNI - The maximum number of sempahore sets
- * 03/2008 - Matthieu Fertré (mfertre@irisa.fr)
- * - Fix concurrency issue. Create private semaphores to
- * avoid conflict with concurrent processes.
- *
- * RESTRICTIONS
- * none
+ * ENOSPC - a semaphore set exceed the maximum number of semaphore sets(SEMMNI)
*/
-#include "ipcsem.h"
-
-char *TCID = "semget05";
-int TST_TOTAL = 1;
-
-/*
- * The MAXIDS value is somewhat arbitrary and may need to be increased
- * depending on the system being tested.
- */
-
-int MAXIDS = 2048;
-
-int *sem_id_arr = NULL;
-int num_sems = 0; /* count the semaphores created */
-
-int main(int ac, char **av)
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include "lapi/sem.h"
+#include "tst_test.h"
+#include "libnewipc.h"
+#include "tst_safe_sysv_ipc.h"
+
+static int *sem_id_arr;
+static int maxsems, array_cnt, used_cnt;
+static key_t semkey;
+
+static void verify_semget(void)
{
- int lc;
- FILE *fp;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
- /* Set the MAXIDS for the specific machine by reading the system limit
- * for SEMMNI - The maximum number of sempahore sets
- */
- fp = fopen("/proc/sys/kernel/sem", "r");
- if (fp != NULL) {
- int getmaxid;
- if (fscanf(fp, "%*d %*d %*d %d", &getmaxid) == 1)
- MAXIDS = getmaxid + 1;
- fclose(fp);
- }
-
- sem_id_arr = malloc(sizeof(int) * MAXIDS);
- if (sem_id_arr == NULL)
- tst_brkm(TBROK, cleanup, "malloc failed");
-
- setup();
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- tst_count = 0;
-
-
- TEST(semget(IPC_PRIVATE, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA));
- if (TEST_RETURN != -1) {
- tst_resm(TFAIL, "call succeeded when error expected");
- continue;
- }
-
- switch (TEST_ERRNO) {
- case ENOSPC:
- tst_resm(TPASS, "expected failure - errno "
- "= %d : %s", TEST_ERRNO, strerror(TEST_ERRNO));
- break;
- default:
- tst_resm(TFAIL, "unexpected error - %d : %s",
- TEST_ERRNO, strerror(TEST_ERRNO));
- break;
- }
- }
-
- cleanup();
-
- tst_exit();
+ TST_EXP_FAIL2(semget(semkey + maxsems, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA),
+ ENOSPC, "semget(%i, %i, %i)", semkey + maxsems, PSEMS,
+ IPC_CREAT | IPC_EXCL | SEM_RA);
}
-void setup(void)
+static void setup(void)
{
- int sem_q;
-
- tst_sig(NOFORK, DEF_HANDLER, cleanup);
+ int res, num;
- TEST_PAUSE;
+ semkey = GETIPCKEY();
+ used_cnt = GET_USED_ARRAYS();
+ tst_res(TINFO, "Current environment %d semaphore arrays are already in use",
+ used_cnt);
+ SAFE_FILE_SCANF("/proc/sys/kernel/sem", "%*d %*d %*d %d", &maxsems);
- tst_tmpdir();
-
- while ((sem_q = semget(IPC_PRIVATE, PSEMS, IPC_CREAT | IPC_EXCL)) != -1) {
- sem_id_arr[num_sems++] = sem_q;
- if (num_sems == MAXIDS) {
- tst_brkm(TBROK, cleanup, "The maximum number of "
- "semaphore ID's has been\n\t reached. Please "
- "increase the MAXIDS value in the test.");
- }
- }
+ sem_id_arr = SAFE_MALLOC((maxsems - used_cnt) * sizeof(int));
+ for (num = 0; num < maxsems - used_cnt; num++) {
+ res = semget(semkey + num, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA);
+ if (res == -1)
+ tst_brk(TBROK | TERRNO, "semget failed unexpectedly");
- if (errno != ENOSPC) {
- tst_brkm(TBROK, cleanup, "Didn't get ENOSPC in test setup"
- " - errno = %d : %s", errno, strerror(errno));
+ sem_id_arr[array_cnt++] = res;
}
+ tst_res(TINFO, "The maximum number of semaphore arrays (%d) has been reached",
+ maxsems);
}
-void cleanup(void)
+static void cleanup(void)
{
- int i;
+ int num;
- for (i = 0; i < num_sems; i++) {
- rm_sema(sem_id_arr[i]);
- }
+ if (!sem_id_arr)
+ return;
+
+ for (num = 0; num < array_cnt; num++)
+ SAFE_SEMCTL(sem_id_arr[num], PSEMS, IPC_RMID);
free(sem_id_arr);
- tst_rmdir();
}
+
+static struct tst_test test = {
+ .needs_tmpdir = 1,
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = verify_semget,
+ .save_restore = (const struct tst_path_val[]){
+ {"/proc/sys/kernel/sem", NULL, TST_SR_TCONF},
+ {}
+ }
+};
--
2.39.1
[-- Attachment #2: Type: text/plain, Size: 60 bytes --]
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH 1/4] lapi/sem.h: Add SEMMSL macro
2023-03-20 6:30 [LTP] [PATCH 1/4] lapi/sem.h: Add SEMMSL macro Yang Xu
` (2 preceding siblings ...)
2023-03-20 6:30 ` [LTP] [PATCH 4/4] ipc/semget05: Convert into new api Yang Xu
@ 2023-03-29 7:52 ` xuyang2018.jy
3 siblings, 0 replies; 13+ messages in thread
From: xuyang2018.jy @ 2023-03-29 7:52 UTC (permalink / raw)
To: ltp
HI
Ping.
Best Regards
Yang Xu
> This macro is used to trigger semget EINVAL error.
>
> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
> ---
> include/lapi/sem.h | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/include/lapi/sem.h b/include/lapi/sem.h
> index 495afe937..ba559d2f1 100644
> --- a/include/lapi/sem.h
> +++ b/include/lapi/sem.h
> @@ -24,4 +24,8 @@ union semun {
> # define SEM_STAT_ANY 20
> #endif
>
> +#ifndef SEMMSL
> +# define SEMMSL 32000
> +#endif
> +
> #endif /* LAPI_SEM_H__ */
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH 2/4] ipc/semget02,03,06: Convert into new api
2023-03-20 6:30 ` [LTP] [PATCH 2/4] ipc/semget02,03,06: Convert into new api Yang Xu
@ 2023-04-13 9:38 ` Li Wang
0 siblings, 0 replies; 13+ messages in thread
From: Li Wang @ 2023-04-13 9:38 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Hi Xu,
I help tested and merged patch1/4 and 2/4.
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH 4/4] ipc/semget05: Convert into new api
2023-03-20 6:30 ` [LTP] [PATCH 4/4] ipc/semget05: Convert into new api Yang Xu
@ 2023-04-13 9:46 ` Li Wang
2023-04-14 4:02 ` [LTP] [RESEND] " Yang Xu
2023-04-14 5:25 ` [LTP] [PATCH 4/4] " Yang Xu (Fujitsu)
0 siblings, 2 replies; 13+ messages in thread
From: Li Wang @ 2023-04-13 9:46 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Hi Xu,
Patch generally looks good, but I can't apply it to
main tree because of some code conflicting.
Can you help check the patch and resend another version?
On Mon, Mar 20, 2023 at 2:31 PM Yang Xu <xuyang2018.jy@fujitsu.com> wrote:
> Use the same logic as shmget03 and msget02 to trigger ENOSPC error.
>
> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
> ---
> testcases/kernel/syscalls/ipc/semget/Makefile | 5 +-
> .../kernel/syscalls/ipc/semget/semget05.c | 187 ++++++------------
> 2 files changed, 59 insertions(+), 133 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/ipc/semget/Makefile
> b/testcases/kernel/syscalls/ipc/semget/Makefile
> index 2f98c36ca..b1201281d 100644
> --- a/testcases/kernel/syscalls/ipc/semget/Makefile
> +++ b/testcases/kernel/syscalls/ipc/semget/Makefile
> @@ -3,11 +3,10 @@
>
> top_srcdir ?= ../../../../..
>
> -LTPLIBS = ltpipc ltpnewipc
> +LTPLIBS = ltpnewipc
>
> include $(top_srcdir)/include/mk/testcases.mk
>
> -semget01 semget02: LTPLDLIBS = -lltpnewipc
> -semget05: LTPLDLIBS = -lltpipc
> +LTPLDLIBS = -lltpnewipc
>
> include $(top_srcdir)/include/mk/generic_leaf_target.mk
> diff --git a/testcases/kernel/syscalls/ipc/semget/semget05.c
> b/testcases/kernel/syscalls/ipc/semget/semget05.c
> index f801cb8ed..38b0fad3c 100644
> --- a/testcases/kernel/syscalls/ipc/semget/semget05.c
> +++ b/testcases/kernel/syscalls/ipc/semget/semget05.c
> @@ -1,152 +1,79 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> /*
> - *
> - * Copyright (c) International Business Machines Corp., 2001
> - *
> - * This program is free software; you can redistribute it and/or modify
> - * it under the terms of the GNU General Public License as published by
> - * the Free Software Foundation; either version 2 of the License, or
> - * (at your option) any later version.
> - *
> - * This program is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
> - * the GNU General Public License for more details.
> - *
> - * You should have received a copy of the GNU General Public License
> - * along with this program; if not, write to the Free Software
> - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> 02110-1301 USA
> + * Copyright (c) International Business Machines Corp., 2001
> */
>
> -/*
> - * NAME
> - * semget05.c
> +/*\
> + * [Description]
> *
> - * DESCRIPTION
> - * semget05 - test for ENOSPC error
> + * Test for ENOSPC error.
> *
> - * ALGORITHM
> - * create semaphore sets in a loop until the system limit is reached
> - * loop if that option was specified
> - * attempt to create yet another semaphore set
> - * check the errno value
> - * issue a PASS message if we get ENOSPC
> - * otherwise, the tests fails
> - * issue a FAIL message
> - * call cleanup
> - *
> - * USAGE: <for command-line>
> - * HISTORY
> - * 03/2001 - Written by Wayne Boyer
> - * 07/2006 - Changes By Michael Reed
> - * - Changed the value of MAXIDS for the specific machine
> by reading
> - * the system limit for SEMMNI - The maximum number of
> sempahore sets
> - * 03/2008 - Matthieu Fertré (mfertre@irisa.fr)
> - * - Fix concurrency issue. Create private semaphores to
> - * avoid conflict with concurrent processes.
> - *
> - * RESTRICTIONS
> - * none
> + * ENOSPC - a semaphore set exceed the maximum number of semaphore
> sets(SEMMNI)
> */
>
> -#include "ipcsem.h"
> -
> -char *TCID = "semget05";
> -int TST_TOTAL = 1;
> -
> -/*
> - * The MAXIDS value is somewhat arbitrary and may need to be increased
> - * depending on the system being tested.
> - */
> -
> -int MAXIDS = 2048;
> -
> -int *sem_id_arr = NULL;
> -int num_sems = 0; /* count the semaphores created */
> -
> -int main(int ac, char **av)
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <unistd.h>
> +#include <sys/types.h>
> +#include <sys/ipc.h>
> +#include "lapi/sem.h"
> +#include "tst_test.h"
> +#include "libnewipc.h"
> +#include "tst_safe_sysv_ipc.h"
> +
> +static int *sem_id_arr;
> +static int maxsems, array_cnt, used_cnt;
> +static key_t semkey;
> +
> +static void verify_semget(void)
> {
> - int lc;
> - FILE *fp;
> -
> - tst_parse_opts(ac, av, NULL, NULL);
> -
> - /* Set the MAXIDS for the specific machine by reading the system
> limit
> - * for SEMMNI - The maximum number of sempahore sets
> - */
> - fp = fopen("/proc/sys/kernel/sem", "r");
> - if (fp != NULL) {
> - int getmaxid;
> - if (fscanf(fp, "%*d %*d %*d %d", &getmaxid) == 1)
> - MAXIDS = getmaxid + 1;
> - fclose(fp);
> - }
> -
> - sem_id_arr = malloc(sizeof(int) * MAXIDS);
> - if (sem_id_arr == NULL)
> - tst_brkm(TBROK, cleanup, "malloc failed");
> -
> - setup();
> -
> - for (lc = 0; TEST_LOOPING(lc); lc++) {
> - tst_count = 0;
> -
> -
> - TEST(semget(IPC_PRIVATE, PSEMS, IPC_CREAT | IPC_EXCL |
> SEM_RA));
> - if (TEST_RETURN != -1) {
> - tst_resm(TFAIL, "call succeeded when error
> expected");
> - continue;
> - }
> -
> - switch (TEST_ERRNO) {
> - case ENOSPC:
> - tst_resm(TPASS, "expected failure - errno "
> - "= %d : %s", TEST_ERRNO,
> strerror(TEST_ERRNO));
> - break;
> - default:
> - tst_resm(TFAIL, "unexpected error - %d : %s",
> - TEST_ERRNO, strerror(TEST_ERRNO));
> - break;
> - }
> - }
> -
> - cleanup();
> -
> - tst_exit();
> + TST_EXP_FAIL2(semget(semkey + maxsems, PSEMS, IPC_CREAT | IPC_EXCL
> | SEM_RA),
> + ENOSPC, "semget(%i, %i, %i)", semkey + maxsems, PSEMS,
> + IPC_CREAT | IPC_EXCL | SEM_RA);
> }
>
> -void setup(void)
> +static void setup(void)
> {
> - int sem_q;
> -
> - tst_sig(NOFORK, DEF_HANDLER, cleanup);
> + int res, num;
>
> - TEST_PAUSE;
> + semkey = GETIPCKEY();
> + used_cnt = GET_USED_ARRAYS();
> + tst_res(TINFO, "Current environment %d semaphore arrays are
> already in use",
> + used_cnt);
> + SAFE_FILE_SCANF("/proc/sys/kernel/sem", "%*d %*d %*d %d",
> &maxsems);
>
> - tst_tmpdir();
> -
> - while ((sem_q = semget(IPC_PRIVATE, PSEMS, IPC_CREAT | IPC_EXCL))
> != -1) {
> - sem_id_arr[num_sems++] = sem_q;
> - if (num_sems == MAXIDS) {
> - tst_brkm(TBROK, cleanup, "The maximum number of "
> - "semaphore ID's has been\n\t reached.
> Please "
> - "increase the MAXIDS value in the test.");
> - }
> - }
> + sem_id_arr = SAFE_MALLOC((maxsems - used_cnt) * sizeof(int));
> + for (num = 0; num < maxsems - used_cnt; num++) {
> + res = semget(semkey + num, PSEMS, IPC_CREAT | IPC_EXCL |
> SEM_RA);
> + if (res == -1)
> + tst_brk(TBROK | TERRNO, "semget failed
> unexpectedly");
>
> - if (errno != ENOSPC) {
> - tst_brkm(TBROK, cleanup, "Didn't get ENOSPC in test setup"
> - " - errno = %d : %s", errno, strerror(errno));
> + sem_id_arr[array_cnt++] = res;
> }
> + tst_res(TINFO, "The maximum number of semaphore arrays (%d) has
> been reached",
> + maxsems);
> }
>
> -void cleanup(void)
> +static void cleanup(void)
> {
> - int i;
> + int num;
>
> - for (i = 0; i < num_sems; i++) {
> - rm_sema(sem_id_arr[i]);
> - }
> + if (!sem_id_arr)
> + return;
> +
> + for (num = 0; num < array_cnt; num++)
> + SAFE_SEMCTL(sem_id_arr[num], PSEMS, IPC_RMID);
>
> free(sem_id_arr);
> - tst_rmdir();
> }
> +
> +static struct tst_test test = {
> + .needs_tmpdir = 1,
> + .setup = setup,
> + .cleanup = cleanup,
> + .test_all = verify_semget,
> + .save_restore = (const struct tst_path_val[]){
> + {"/proc/sys/kernel/sem", NULL, TST_SR_TCONF},
> + {}
> + }
> +};
> --
> 2.39.1
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
* [LTP] [RESEND] ipc/semget05: Convert into new api
2023-04-13 9:46 ` Li Wang
@ 2023-04-14 4:02 ` Yang Xu
2023-04-14 6:47 ` Yang Xu (Fujitsu)
2023-04-14 5:25 ` [LTP] [PATCH 4/4] " Yang Xu (Fujitsu)
1 sibling, 1 reply; 13+ messages in thread
From: Yang Xu @ 2023-04-14 4:02 UTC (permalink / raw)
To: ltp
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="UTF-8", Size: 6830 bytes --]
Use the same logic as shmget03 and msget03 to trigger ENOSPC error.
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
testcases/kernel/syscalls/ipc/semget/Makefile | 5 +-
.../kernel/syscalls/ipc/semget/semget05.c | 187 ++++++------------
2 files changed, 59 insertions(+), 133 deletions(-)
diff --git a/testcases/kernel/syscalls/ipc/semget/Makefile b/testcases/kernel/syscalls/ipc/semget/Makefile
index 2f98c36ca..b1201281d 100644
--- a/testcases/kernel/syscalls/ipc/semget/Makefile
+++ b/testcases/kernel/syscalls/ipc/semget/Makefile
@@ -3,11 +3,10 @@
top_srcdir ?= ../../../../..
-LTPLIBS = ltpipc ltpnewipc
+LTPLIBS = ltpnewipc
include $(top_srcdir)/include/mk/testcases.mk
-semget01 semget02: LTPLDLIBS = -lltpnewipc
-semget05: LTPLDLIBS = -lltpipc
+LTPLDLIBS = -lltpnewipc
include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/ipc/semget/semget05.c b/testcases/kernel/syscalls/ipc/semget/semget05.c
index f801cb8ed..38b0fad3c 100644
--- a/testcases/kernel/syscalls/ipc/semget/semget05.c
+++ b/testcases/kernel/syscalls/ipc/semget/semget05.c
@@ -1,152 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
- *
- * Copyright (c) International Business Machines Corp., 2001
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines Corp., 2001
*/
-/*
- * NAME
- * semget05.c
+/*\
+ * [Description]
*
- * DESCRIPTION
- * semget05 - test for ENOSPC error
+ * Test for ENOSPC error.
*
- * ALGORITHM
- * create semaphore sets in a loop until the system limit is reached
- * loop if that option was specified
- * attempt to create yet another semaphore set
- * check the errno value
- * issue a PASS message if we get ENOSPC
- * otherwise, the tests fails
- * issue a FAIL message
- * call cleanup
- *
- * USAGE: <for command-line>
- * HISTORY
- * 03/2001 - Written by Wayne Boyer
- * 07/2006 - Changes By Michael Reed
- * - Changed the value of MAXIDS for the specific machine by reading
- * the system limit for SEMMNI - The maximum number of sempahore sets
- * 03/2008 - Matthieu Fertré (mfertre@irisa.fr)
- * - Fix concurrency issue. Create private semaphores to
- * avoid conflict with concurrent processes.
- *
- * RESTRICTIONS
- * none
+ * ENOSPC - a semaphore set exceed the maximum number of semaphore sets(SEMMNI)
*/
-#include "ipcsem.h"
-
-char *TCID = "semget05";
-int TST_TOTAL = 1;
-
-/*
- * The MAXIDS value is somewhat arbitrary and may need to be increased
- * depending on the system being tested.
- */
-
-int MAXIDS = 2048;
-
-int *sem_id_arr = NULL;
-int num_sems = 0; /* count the semaphores created */
-
-int main(int ac, char **av)
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include "lapi/sem.h"
+#include "tst_test.h"
+#include "libnewipc.h"
+#include "tst_safe_sysv_ipc.h"
+
+static int *sem_id_arr;
+static int maxsems, array_cnt, used_cnt;
+static key_t semkey;
+
+static void verify_semget(void)
{
- int lc;
- FILE *fp;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
- /* Set the MAXIDS for the specific machine by reading the system limit
- * for SEMMNI - The maximum number of sempahore sets
- */
- fp = fopen("/proc/sys/kernel/sem", "r");
- if (fp != NULL) {
- int getmaxid;
- if (fscanf(fp, "%*d %*d %*d %d", &getmaxid) == 1)
- MAXIDS = getmaxid + 1;
- fclose(fp);
- }
-
- sem_id_arr = malloc(sizeof(int) * MAXIDS);
- if (sem_id_arr == NULL)
- tst_brkm(TBROK, cleanup, "malloc failed");
-
- setup();
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- tst_count = 0;
-
-
- TEST(semget(IPC_PRIVATE, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA));
- if (TEST_RETURN != -1) {
- tst_resm(TFAIL, "call succeeded when error expected");
- continue;
- }
-
- switch (TEST_ERRNO) {
- case ENOSPC:
- tst_resm(TPASS, "expected failure - errno "
- "= %d : %s", TEST_ERRNO, strerror(TEST_ERRNO));
- break;
- default:
- tst_resm(TFAIL, "unexpected error - %d : %s",
- TEST_ERRNO, strerror(TEST_ERRNO));
- break;
- }
- }
-
- cleanup();
-
- tst_exit();
+ TST_EXP_FAIL2(semget(semkey + maxsems, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA),
+ ENOSPC, "semget(%i, %i, %i)", semkey + maxsems, PSEMS,
+ IPC_CREAT | IPC_EXCL | SEM_RA);
}
-void setup(void)
+static void setup(void)
{
- int sem_q;
-
- tst_sig(NOFORK, DEF_HANDLER, cleanup);
+ int res, num;
- TEST_PAUSE;
+ semkey = GETIPCKEY();
+ used_cnt = GET_USED_ARRAYS();
+ tst_res(TINFO, "Current environment %d semaphore arrays are already in use",
+ used_cnt);
+ SAFE_FILE_SCANF("/proc/sys/kernel/sem", "%*d %*d %*d %d", &maxsems);
- tst_tmpdir();
-
- while ((sem_q = semget(IPC_PRIVATE, PSEMS, IPC_CREAT | IPC_EXCL)) != -1) {
- sem_id_arr[num_sems++] = sem_q;
- if (num_sems == MAXIDS) {
- tst_brkm(TBROK, cleanup, "The maximum number of "
- "semaphore ID's has been\n\t reached. Please "
- "increase the MAXIDS value in the test.");
- }
- }
+ sem_id_arr = SAFE_MALLOC((maxsems - used_cnt) * sizeof(int));
+ for (num = 0; num < maxsems - used_cnt; num++) {
+ res = semget(semkey + num, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA);
+ if (res == -1)
+ tst_brk(TBROK | TERRNO, "semget failed unexpectedly");
- if (errno != ENOSPC) {
- tst_brkm(TBROK, cleanup, "Didn't get ENOSPC in test setup"
- " - errno = %d : %s", errno, strerror(errno));
+ sem_id_arr[array_cnt++] = res;
}
+ tst_res(TINFO, "The maximum number of semaphore arrays (%d) has been reached",
+ maxsems);
}
-void cleanup(void)
+static void cleanup(void)
{
- int i;
+ int num;
- for (i = 0; i < num_sems; i++) {
- rm_sema(sem_id_arr[i]);
- }
+ if (!sem_id_arr)
+ return;
+
+ for (num = 0; num < array_cnt; num++)
+ SAFE_SEMCTL(sem_id_arr[num], PSEMS, IPC_RMID);
free(sem_id_arr);
- tst_rmdir();
}
+
+static struct tst_test test = {
+ .needs_tmpdir = 1,
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = verify_semget,
+ .save_restore = (const struct tst_path_val[]){
+ {"/proc/sys/kernel/sem", NULL, TST_SR_TCONF},
+ {}
+ }
+};
--
2.39.1
[-- Attachment #2: Type: text/plain, Size: 60 bytes --]
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH 4/4] ipc/semget05: Convert into new api
2023-04-13 9:46 ` Li Wang
2023-04-14 4:02 ` [LTP] [RESEND] " Yang Xu
@ 2023-04-14 5:25 ` Yang Xu (Fujitsu)
2023-04-17 2:39 ` Yang Xu (Fujitsu)
1 sibling, 1 reply; 13+ messages in thread
From: Yang Xu (Fujitsu) @ 2023-04-14 5:25 UTC (permalink / raw)
To: Li Wang; +Cc: ltp
Hi Li
> Hi Xu,
>
> Patch generally looks good, but I can't apply it to
> main tree because of some code conflicting.
>
In fact, I don't know the reason.
I use my local patch, it can be merged.
> Can you help check the patch and resend another version?
I see garbled code for Matthieu Fertré "é" character when I download
this patch from patchwork by using mbox format.
Also for this patch, the Content-Transfer-Encoding: 8bit, the previous
patch is Content-Transfer-Encoding: 7bit.
Also when I send patch, I can see a mention that
The following files are 8bit, but do not declare a
Content-Transfer-Encoding.
0001-ipc-semget05-Convert-into-new-api.patch
Which 8bit encoding should I declare [UTF-8]?
I have resend this patch, but I don't see it on patchwork.
Best Regards
Yang Xu
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [LTP] [RESEND] ipc/semget05: Convert into new api
2023-04-14 4:02 ` [LTP] [RESEND] " Yang Xu
@ 2023-04-14 6:47 ` Yang Xu (Fujitsu)
0 siblings, 0 replies; 13+ messages in thread
From: Yang Xu (Fujitsu) @ 2023-04-14 6:47 UTC (permalink / raw)
To: Li Wang; +Cc: ltp
Hi LI
In fact, this patch still can not be merged after resend.
I search Content-Transfer-Encoding in the following url:
https://www.w3.org/Protocols/rfc1341/5_Content-Transfer-Encoding.html
Content-Transfer-Encoding: 7 bit means that the data is all represented
as short lines of US-ASCII data
Content-Transfer-Encoding: 8 bit means that the lines are short, but
there may be non-ASCII characters (octets with the high-order bit set).
I seen these from the above url
"
As of the publication of this document, there are no standardized
Internet transports for which it is legitimate to include unencoded
8-bit or binary data in mail bodies. Thus there are no circumstances in
which the "8bit" or "binary" Content-Transfer-Encoding is actually legal
on the Internet. However, in the event that 8-bit or binary mail
transport becomes a reality in Internet mail, or when this document is
used in conjunction with any other 8-bit or binary-capable transport
mechanism, 8-bit or binary bodies should be labeled as such using this
mechanism."
I guess maybe I merged these 3/4 4/4 patch with your reviewed-by by
myself? So we can avoid this problem. What do you think about it?
Best Regards
Yang Xu
> Use the same logic as shmget03 and msget03 to trigger ENOSPC error.
>
> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
> ---
> testcases/kernel/syscalls/ipc/semget/Makefile | 5 +-
> .../kernel/syscalls/ipc/semget/semget05.c | 187 ++++++------------
> 2 files changed, 59 insertions(+), 133 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/ipc/semget/Makefile b/testcases/kernel/syscalls/ipc/semget/Makefile
> index 2f98c36ca..b1201281d 100644
> --- a/testcases/kernel/syscalls/ipc/semget/Makefile
> +++ b/testcases/kernel/syscalls/ipc/semget/Makefile
> @@ -3,11 +3,10 @@
>
> top_srcdir ?= ../../../../..
>
> -LTPLIBS = ltpipc ltpnewipc
> +LTPLIBS = ltpnewipc
>
> include $(top_srcdir)/include/mk/testcases.mk
>
> -semget01 semget02: LTPLDLIBS = -lltpnewipc
> -semget05: LTPLDLIBS = -lltpipc
> +LTPLDLIBS = -lltpnewipc
>
> include $(top_srcdir)/include/mk/generic_leaf_target.mk
> diff --git a/testcases/kernel/syscalls/ipc/semget/semget05.c b/testcases/kernel/syscalls/ipc/semget/semget05.c
> index f801cb8ed..38b0fad3c 100644
> --- a/testcases/kernel/syscalls/ipc/semget/semget05.c
> +++ b/testcases/kernel/syscalls/ipc/semget/semget05.c
> @@ -1,152 +1,79 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> /*
> - *
> - * Copyright (c) International Business Machines Corp., 2001
> - *
> - * This program is free software; you can redistribute it and/or modify
> - * it under the terms of the GNU General Public License as published by
> - * the Free Software Foundation; either version 2 of the License, or
> - * (at your option) any later version.
> - *
> - * This program is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
> - * the GNU General Public License for more details.
> - *
> - * You should have received a copy of the GNU General Public License
> - * along with this program; if not, write to the Free Software
> - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + * Copyright (c) International Business Machines Corp., 2001
> */
>
> -/*
> - * NAME
> - * semget05.c
> +/*\
> + * [Description]
> *
> - * DESCRIPTION
> - * semget05 - test for ENOSPC error
> + * Test for ENOSPC error.
> *
> - * ALGORITHM
> - * create semaphore sets in a loop until the system limit is reached
> - * loop if that option was specified
> - * attempt to create yet another semaphore set
> - * check the errno value
> - * issue a PASS message if we get ENOSPC
> - * otherwise, the tests fails
> - * issue a FAIL message
> - * call cleanup
> - *
> - * USAGE: <for command-line>
> - * HISTORY
> - * 03/2001 - Written by Wayne Boyer
> - * 07/2006 - Changes By Michael Reed
> - * - Changed the value of MAXIDS for the specific machine by reading
> - * the system limit for SEMMNI - The maximum number of sempahore sets
> - * 03/2008 - Matthieu Fertr� (mfertre@irisa.fr)
> - * - Fix concurrency issue. Create private semaphores to
> - * avoid conflict with concurrent processes.
> - *
> - * RESTRICTIONS
> - * none
> + * ENOSPC - a semaphore set exceed the maximum number of semaphore sets(SEMMNI)
> */
>
> -#include "ipcsem.h"
> -
> -char *TCID = "semget05";
> -int TST_TOTAL = 1;
> -
> -/*
> - * The MAXIDS value is somewhat arbitrary and may need to be increased
> - * depending on the system being tested.
> - */
> -
> -int MAXIDS = 2048;
> -
> -int *sem_id_arr = NULL;
> -int num_sems = 0; /* count the semaphores created */
> -
> -int main(int ac, char **av)
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <unistd.h>
> +#include <sys/types.h>
> +#include <sys/ipc.h>
> +#include "lapi/sem.h"
> +#include "tst_test.h"
> +#include "libnewipc.h"
> +#include "tst_safe_sysv_ipc.h"
> +
> +static int *sem_id_arr;
> +static int maxsems, array_cnt, used_cnt;
> +static key_t semkey;
> +
> +static void verify_semget(void)
> {
> - int lc;
> - FILE *fp;
> -
> - tst_parse_opts(ac, av, NULL, NULL);
> -
> - /* Set the MAXIDS for the specific machine by reading the system limit
> - * for SEMMNI - The maximum number of sempahore sets
> - */
> - fp = fopen("/proc/sys/kernel/sem", "r");
> - if (fp != NULL) {
> - int getmaxid;
> - if (fscanf(fp, "%*d %*d %*d %d", &getmaxid) == 1)
> - MAXIDS = getmaxid + 1;
> - fclose(fp);
> - }
> -
> - sem_id_arr = malloc(sizeof(int) * MAXIDS);
> - if (sem_id_arr == NULL)
> - tst_brkm(TBROK, cleanup, "malloc failed");
> -
> - setup();
> -
> - for (lc = 0; TEST_LOOPING(lc); lc++) {
> - tst_count = 0;
> -
> -
> - TEST(semget(IPC_PRIVATE, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA));
> - if (TEST_RETURN != -1) {
> - tst_resm(TFAIL, "call succeeded when error expected");
> - continue;
> - }
> -
> - switch (TEST_ERRNO) {
> - case ENOSPC:
> - tst_resm(TPASS, "expected failure - errno "
> - "= %d : %s", TEST_ERRNO, strerror(TEST_ERRNO));
> - break;
> - default:
> - tst_resm(TFAIL, "unexpected error - %d : %s",
> - TEST_ERRNO, strerror(TEST_ERRNO));
> - break;
> - }
> - }
> -
> - cleanup();
> -
> - tst_exit();
> + TST_EXP_FAIL2(semget(semkey + maxsems, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA),
> + ENOSPC, "semget(%i, %i, %i)", semkey + maxsems, PSEMS,
> + IPC_CREAT | IPC_EXCL | SEM_RA);
> }
>
> -void setup(void)
> +static void setup(void)
> {
> - int sem_q;
> -
> - tst_sig(NOFORK, DEF_HANDLER, cleanup);
> + int res, num;
>
> - TEST_PAUSE;
> + semkey = GETIPCKEY();
> + used_cnt = GET_USED_ARRAYS();
> + tst_res(TINFO, "Current environment %d semaphore arrays are already in use",
> + used_cnt);
> + SAFE_FILE_SCANF("/proc/sys/kernel/sem", "%*d %*d %*d %d", &maxsems);
>
> - tst_tmpdir();
> -
> - while ((sem_q = semget(IPC_PRIVATE, PSEMS, IPC_CREAT | IPC_EXCL)) != -1) {
> - sem_id_arr[num_sems++] = sem_q;
> - if (num_sems == MAXIDS) {
> - tst_brkm(TBROK, cleanup, "The maximum number of "
> - "semaphore ID's has been\n\t reached. Please "
> - "increase the MAXIDS value in the test.");
> - }
> - }
> + sem_id_arr = SAFE_MALLOC((maxsems - used_cnt) * sizeof(int));
> + for (num = 0; num < maxsems - used_cnt; num++) {
> + res = semget(semkey + num, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA);
> + if (res == -1)
> + tst_brk(TBROK | TERRNO, "semget failed unexpectedly");
>
> - if (errno != ENOSPC) {
> - tst_brkm(TBROK, cleanup, "Didn't get ENOSPC in test setup"
> - " - errno = %d : %s", errno, strerror(errno));
> + sem_id_arr[array_cnt++] = res;
> }
> + tst_res(TINFO, "The maximum number of semaphore arrays (%d) has been reached",
> + maxsems);
> }
>
> -void cleanup(void)
> +static void cleanup(void)
> {
> - int i;
> + int num;
>
> - for (i = 0; i < num_sems; i++) {
> - rm_sema(sem_id_arr[i]);
> - }
> + if (!sem_id_arr)
> + return;
> +
> + for (num = 0; num < array_cnt; num++)
> + SAFE_SEMCTL(sem_id_arr[num], PSEMS, IPC_RMID);
>
> free(sem_id_arr);
> - tst_rmdir();
> }
> +
> +static struct tst_test test = {
> + .needs_tmpdir = 1,
> + .setup = setup,
> + .cleanup = cleanup,
> + .test_all = verify_semget,
> + .save_restore = (const struct tst_path_val[]){
> + {"/proc/sys/kernel/sem", NULL, TST_SR_TCONF},
> + {}
> + }
> +};
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH 4/4] ipc/semget05: Convert into new api
2023-04-14 5:25 ` [LTP] [PATCH 4/4] " Yang Xu (Fujitsu)
@ 2023-04-17 2:39 ` Yang Xu (Fujitsu)
2023-04-17 7:59 ` Li Wang
0 siblings, 1 reply; 13+ messages in thread
From: Yang Xu (Fujitsu) @ 2023-04-17 2:39 UTC (permalink / raw)
To: Li Wang; +Cc: ltp
HI Li
I merged this patch into my own ltp fork, so you can review this patch
on my ltp fork.
https://github.com/xuyang0410/ltp/commits/master
Best Regards
Yang Xu
> Hi Li
>
>> Hi Xu,
>>
>> Patch generally looks good, but I can't apply it to
>> main tree because of some code conflicting.
>>
>
> In fact, I don't know the reason.
> I use my local patch, it can be merged.
>
>> Can you help check the patch and resend another version?
>
> I see garbled code for Matthieu Fertré "é" character when I download
> this patch from patchwork by using mbox format.
>
> Also for this patch, the Content-Transfer-Encoding: 8bit, the previous
> patch is Content-Transfer-Encoding: 7bit.
>
> Also when I send patch, I can see a mention that
> The following files are 8bit, but do not declare a
> Content-Transfer-Encoding.
> 0001-ipc-semget05-Convert-into-new-api.patch
> Which 8bit encoding should I declare [UTF-8]?
>
> I have resend this patch, but I don't see it on patchwork.
>
> Best Regards
> Yang Xu
>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH 4/4] ipc/semget05: Convert into new api
2023-04-17 2:39 ` Yang Xu (Fujitsu)
@ 2023-04-17 7:59 ` Li Wang
2023-04-17 8:16 ` Yang Xu (Fujitsu)
0 siblings, 1 reply; 13+ messages in thread
From: Li Wang @ 2023-04-17 7:59 UTC (permalink / raw)
To: Yang Xu (Fujitsu); +Cc: ltp
On Mon, Apr 17, 2023 at 10:40 AM Yang Xu (Fujitsu) <
xuyang2018.jy@fujitsu.com> wrote:
> HI Li
>
> I merged this patch into my own ltp fork, so you can review this patch
> on my ltp fork.
>
Yes, the patch looks good, feel free add my reviewd-by and push.
Reviewed-by: Li Wang <liwang@redhat.com>
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH 4/4] ipc/semget05: Convert into new api
2023-04-17 7:59 ` Li Wang
@ 2023-04-17 8:16 ` Yang Xu (Fujitsu)
0 siblings, 0 replies; 13+ messages in thread
From: Yang Xu (Fujitsu) @ 2023-04-17 8:16 UTC (permalink / raw)
To: Li Wang; +Cc: ltp
HI Li
>
>
> On Mon, Apr 17, 2023 at 10:40 AM Yang Xu (Fujitsu)
> <xuyang2018.jy@fujitsu.com <mailto:xuyang2018.jy@fujitsu.com>> wrote:
>
> HI Li
>
> I merged this patch into my own ltp fork, so you can review this patch
> on my ltp fork.
>
>
> Yes, the patch looks good, feel free add my reviewd-by and push.
>
> Reviewed-by: Li Wang <liwang@redhat.com <mailto:liwang@redhat.com>>
Thanks, merged!
Best Regards
Yang Xu
>
>
> --
> Regards,
> Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2023-04-17 8:16 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-20 6:30 [LTP] [PATCH 1/4] lapi/sem.h: Add SEMMSL macro Yang Xu
2023-03-20 6:30 ` [LTP] [PATCH 2/4] ipc/semget02,03,06: Convert into new api Yang Xu
2023-04-13 9:38 ` Li Wang
2023-03-20 6:30 ` [LTP] [PATCH 3/4] libs/libnewipc: Add GET_USED_ARRAYS api Yang Xu
2023-03-20 6:30 ` [LTP] [PATCH 4/4] ipc/semget05: Convert into new api Yang Xu
2023-04-13 9:46 ` Li Wang
2023-04-14 4:02 ` [LTP] [RESEND] " Yang Xu
2023-04-14 6:47 ` Yang Xu (Fujitsu)
2023-04-14 5:25 ` [LTP] [PATCH 4/4] " Yang Xu (Fujitsu)
2023-04-17 2:39 ` Yang Xu (Fujitsu)
2023-04-17 7:59 ` Li Wang
2023-04-17 8:16 ` Yang Xu (Fujitsu)
2023-03-29 7:52 ` [LTP] [PATCH 1/4] lapi/sem.h: Add SEMMSL macro xuyang2018.jy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).