From 7230d0a38862a286776aedd2e8b6fe86f5891e59 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Wed, 14 Jan 2015 16:52:28 +0000 Subject: [PATCH] tests: add IPC_STAT to ipc tests, workaround limitiations of old kernels * tests/ipc_msg.c: Include . (main): Add a test call with IPC_STAT, handle old kernels MSG_STAT behaviour. * tests/ipc_sem.c: Include . (main): Add a test call with IPC_STAT, handle old kernels SEM_STAT behaviour. * tests/ipc_shm.c: Include . (main): Add a test call with IPC_STAT, handle old kernels SHM_STAT behaviour. --- tests/ipc_msg.c | 33 +++++++++++++++++++++++++-------- tests/ipc_sem.c | 36 ++++++++++++++++++++++++++---------- tests/ipc_shm.c | 33 +++++++++++++++++++++++++-------- 3 files changed, 76 insertions(+), 26 deletions(-) diff --git a/tests/ipc_msg.c b/tests/ipc_msg.c index 4888d3a0..1917086e 100644 --- a/tests/ipc_msg.c +++ b/tests/ipc_msg.c @@ -1,31 +1,48 @@ #include +#include #include int main(void) { - int id = msgget(IPC_PRIVATE, 0600); + int rc, id; + struct msqid_ds ds; + + id = msgget(IPC_PRIVATE, 0600); if (id < 0) return 77; printf("msgget\\(IPC_PRIVATE, 0600\\) += %d\n", id); - int rc = 1; + if (msgctl(id, IPC_STAT, &ds)) + goto fail; + printf("msgctl\\(%d, IPC_STAT, %p\\) += 0\n", id, &ds); - struct msqid_ds ds; int max = msgctl(0, MSG_INFO, &ds); if (max < 0) goto fail; printf("msgctl\\(0, MSG_INFO, %p\\) += %d\n", &ds, max); - if (msgctl(id, MSG_STAT, &ds) != id) - goto fail; - printf("msgctl\\(%d, MSG_STAT, %p\\) += %d\n", id, &ds, id); + rc = msgctl(id, MSG_STAT, &ds); + if (rc != id) { + /* + * In linux < v2.6.24-rc1 the first argument must be + * an index in the kernel's internal array. + */ + if (-1 != rc || EINVAL != errno) + goto fail; + printf("msgctl\\(%d, MSG_STAT, %p\\) += -1 EINVAL \\(Invalid argument\\)\n", id, &ds); + } else { + printf("msgctl\\(%d, MSG_STAT, %p\\) += %d\n", id, &ds, id); + } rc = 0; - -fail: +done: if (msgctl(id, IPC_RMID, 0) < 0) return 1; printf("msgctl\\(%d, IPC_RMID, 0\\) += 0\n", id); return rc; + +fail: + rc = 1; + goto done; } diff --git a/tests/ipc_sem.c b/tests/ipc_sem.c index 78d9682c..115221b9 100644 --- a/tests/ipc_sem.c +++ b/tests/ipc_sem.c @@ -1,33 +1,49 @@ #include +#include #include int main(void) { - int id = semget(IPC_PRIVATE, 1, 0600); + int rc, id; + struct semid_ds ds; + struct seminfo info; + + id = semget(IPC_PRIVATE, 1, 0600); if (id < 0) return 77; printf("semget\\(IPC_PRIVATE, 1, 0600\\) += %d\n", id); - int rc = 1; + if (semctl(id, 0, IPC_STAT, &ds)) + goto fail; + printf("semctl\\(%d, 0, IPC_STAT, %p\\) += 0\n", id, &ds); - struct seminfo info; int max = semctl(0, 0, SEM_INFO, &info); if (max < 0) goto fail; printf("semctl\\(0, 0, SEM_INFO, %p\\) += %d\n", &info, max); - struct semid_ds ds; - if (semctl(id, 0, SEM_STAT, &ds) != id) - goto fail; - printf("semctl\\(%d, 0, SEM_STAT, %p\\) += %d\n", id, &ds, id); + rc = semctl(id, 0, SEM_STAT, &ds); + if (rc != id) { + /* + * In linux < v2.6.24-rc1 the first argument must be + * an index in the kernel's internal array. + */ + if (-1 != rc || EINVAL != errno) + goto fail; + printf("semctl\\(%d, 0, SEM_STAT, %p\\) += -1 EINVAL \\(Invalid argument\\)\n", id, &ds); + } else { + printf("semctl\\(%d, 0, SEM_STAT, %p\\) += %d\n", id, &ds, id); + } rc = 0; - -fail: +done: if (semctl(id, 0, IPC_RMID, 0) < 0) return 1; printf("semctl\\(%d, 0, IPC_RMID, 0\\) += 0\n", id); - return rc; + +fail: + rc = 1; + goto done; } diff --git a/tests/ipc_shm.c b/tests/ipc_shm.c index 5b3c9fac..f1995d30 100644 --- a/tests/ipc_shm.c +++ b/tests/ipc_shm.c @@ -1,31 +1,48 @@ #include +#include #include int main(void) { - int id = shmget(IPC_PRIVATE, 1, 0600); + int rc, id; + struct shmid_ds ds; + + id = shmget(IPC_PRIVATE, 1, 0600); if (id < 0) return 77; printf("shmget\\(IPC_PRIVATE, 1, 0600\\) += %d\n", id); - int rc = 1; + if (shmctl(id, IPC_STAT, &ds)) + goto fail; + printf("shmctl\\(%d, IPC_STAT, %p\\) += 0\n", id, &ds); - struct shmid_ds ds; int max = shmctl(0, SHM_INFO, &ds); if (max < 0) goto fail; printf("shmctl\\(0, SHM_INFO, %p\\) += %d\n", &ds, max); - if (shmctl(id, SHM_STAT, &ds) != id) - goto fail; - printf("shmctl\\(%d, SHM_STAT, %p\\) += %d\n", id, &ds, id); + rc = shmctl(id, SHM_STAT, &ds); + if (rc != id) { + /* + * In linux < v2.6.24-rc1 the first argument must be + * an index in the kernel's internal array. + */ + if (-1 != rc || EINVAL != errno) + goto fail; + printf("shmctl\\(%d, SHM_STAT, %p\\) += -1 EINVAL \\(Invalid argument\\)\n", id, &ds); + } else { + printf("shmctl\\(%d, SHM_STAT, %p\\) += %d\n", id, &ds, id); + } rc = 0; - -fail: +done: if (shmctl(id, IPC_RMID, 0) < 0) return 1; printf("shmctl\\(%d, IPC_RMID, 0\\) += 0\n", id); return rc; + +fail: + rc = 1; + goto done; } -- 2.40.0