tests: add IPC_STAT to ipc tests, workaround limitiations of old kernels

* tests/ipc_msg.c: Include <errno.h>.
(main): Add a test call with IPC_STAT, handle old kernels MSG_STAT behaviour.
* tests/ipc_sem.c: Include <errno.h>.
(main): Add a test call with IPC_STAT, handle old kernels SEM_STAT behaviour.
* tests/ipc_shm.c: Include <errno.h>.
(main): Add a test call with IPC_STAT, handle old kernels SHM_STAT behaviour.
This commit is contained in:
Дмитрий Левин 2015-01-14 16:52:28 +00:00
parent 97e5996105
commit 7230d0a388
3 changed files with 76 additions and 26 deletions

View File

@ -1,31 +1,48 @@
#include <stdio.h>
#include <errno.h>
#include <sys/msg.h>
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;
}

View File

@ -1,33 +1,49 @@
#include <stdio.h>
#include <errno.h>
#include <sys/sem.h>
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;
}

View File

@ -1,31 +1,48 @@
#include <stdio.h>
#include <errno.h>
#include <sys/shm.h>
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;
}