* [LTP] [PATCH v2] posix/conformance/interfaces/sem_timedwait/2-1: Remove MAP_ANONYMOUS
@ 2024-09-19 3:27 Ma Xinjian via ltp
2024-09-23 12:54 ` Cyril Hrubis
0 siblings, 1 reply; 2+ messages in thread
From: Ma Xinjian via ltp @ 2024-09-19 3:27 UTC (permalink / raw)
To: ltp, chrubis
MAP_ANONYMOUS is not part of POSIX, so remove it from open posix testsuit.
And use open_shm to get the file descriptor.
Signed-off-by: Ma Xinjian <maxj.fnst@fujitsu.com>
---
.../interfaces/sem_timedwait/2-1.c | 24 +++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sem_timedwait/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/sem_timedwait/2-1.c
index 2eca8dff6..b1747f01d 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sem_timedwait/2-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sem_timedwait/2-1.c
@@ -24,6 +24,7 @@
#include "posixtest.h"
#define TEST "2-1"
+#define SHM_NAME "posixtest_2-1"
#define FUNCTION "sem_timedwait"
#define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
@@ -31,8 +32,25 @@ int main(void)
{
sem_t *mysemp;
struct timespec ts;
- int pid;
- mysemp = mmap(NULL, sizeof(*mysemp), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+ int fd, pid;
+
+ fd = shm_open(SHM_NAME, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
+ if (fd == -1) {
+ perror("An error occurs when calling shm_open()");
+ return PTS_UNRESOLVED;
+ }
+
+ if (ftruncate(fd, sizeof(*mysemp)) == -1) {
+ perror("An error occurs when calling ftruncate()");
+ return PTS_UNRESOLVED;
+ }
+
+ if (shm_unlink(SHM_NAME) != 0) {
+ perror("An error occurs when calling shm_unlink()");
+ return PTS_UNRESOLVED;
+ }
+
+ mysemp = mmap(NULL, sizeof(*mysemp), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (mysemp == MAP_FAILED) {
perror(ERROR_PREFIX "mmap");
return PTS_UNRESOLVED;
@@ -82,5 +100,7 @@ int main(void)
}
return PTS_PASS;
}
+
+ close(fd);
return PTS_UNRESOLVED;
}
--
2.42.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [LTP] [PATCH v2] posix/conformance/interfaces/sem_timedwait/2-1: Remove MAP_ANONYMOUS
2024-09-19 3:27 [LTP] [PATCH v2] posix/conformance/interfaces/sem_timedwait/2-1: Remove MAP_ANONYMOUS Ma Xinjian via ltp
@ 2024-09-23 12:54 ` Cyril Hrubis
0 siblings, 0 replies; 2+ messages in thread
From: Cyril Hrubis @ 2024-09-23 12:54 UTC (permalink / raw)
To: Ma Xinjian; +Cc: ltp
Hi!
Pushed with two minor changes, thanks.
- POSIX requires that the SHM_NAME starts with /
- Made use of ERROR_PREFIX
Full diff:
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sem_timedwait/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/sem_timedwait/2-1.c
index b1747f01d..d9012cc5e 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sem_timedwait/2-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sem_timedwait/2-1.c
@@ -24,7 +24,7 @@
#include "posixtest.h"
#define TEST "2-1"
-#define SHM_NAME "posixtest_2-1"
+#define SHM_NAME "/posixtest_2-1"
#define FUNCTION "sem_timedwait"
#define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
@@ -36,17 +36,17 @@ int main(void)
fd = shm_open(SHM_NAME, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
if (fd == -1) {
- perror("An error occurs when calling shm_open()");
+ perror(ERROR_PREFIX "shm_open()");
return PTS_UNRESOLVED;
}
if (ftruncate(fd, sizeof(*mysemp)) == -1) {
- perror("An error occurs when calling ftruncate()");
+ perror(ERROR_PREFIX "ftruncate()");
return PTS_UNRESOLVED;
}
if (shm_unlink(SHM_NAME) != 0) {
- perror("An error occurs when calling shm_unlink()");
+ perror(ERROR_PREFIX "shm_unlink()");
return PTS_UNRESOLVED;
}
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-09-23 12:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-19 3:27 [LTP] [PATCH v2] posix/conformance/interfaces/sem_timedwait/2-1: Remove MAP_ANONYMOUS Ma Xinjian via ltp
2024-09-23 12:54 ` Cyril Hrubis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox