[PATCH v2 1/2] tests: add semop.test

Dmitry V. Levin ldv at altlinux.org
Wed Apr 20 01:32:50 UTC 2016


On Mon, Apr 18, 2016 at 03:10:53PM +0800, Fei Jie wrote:
> * tests/semop.c: New file.
> * tests/semop.test: New test.
> * tests/.gitignore: Add semop.
> * tests/Makefile.am (check_PROGRAMS): Likewise.
> (DECODER_TESTS): Add semop.test.
> ---
>  tests/.gitignore  |  1 +
>  tests/Makefile.am |  2 ++
>  tests/semop.c     | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  tests/semop.test  |  6 ++++++
>  4 files changed, 64 insertions(+)
>  create mode 100644 tests/semop.c
>  create mode 100755 tests/semop.test
> 
> diff --git a/tests/.gitignore b/tests/.gitignore
> index f3ee629..3d1dbef 100644
> --- a/tests/.gitignore
> +++ b/tests/.gitignore
> @@ -138,6 +138,7 @@ seccomp-filter
>  seccomp-filter-v
>  seccomp-strict
>  select
> +semop
>  sendfile
>  sendfile64
>  set_ptracer_any
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index e9cd625..f31b600 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -188,6 +188,7 @@ check_PROGRAMS = \
>  	seccomp-filter-v \
>  	seccomp-strict \
>  	select \
> +	semop \
>  	sendfile \
>  	sendfile64 \
>  	set_ptracer_any \
> @@ -394,6 +395,7 @@ DECODER_TESTS = \
>  	seccomp-filter.test \
>  	seccomp-strict.test \
>  	select.test \
> +	semop.test \
>  	sendfile.test \
>  	sendfile64.test \
>  	sethostname.test \
> diff --git a/tests/semop.c b/tests/semop.c
> new file mode 100644
> index 0000000..3d3cb93
> --- /dev/null
> +++ b/tests/semop.c
> @@ -0,0 +1,55 @@
> +#include "tests.h"
> +#include <sys/types.h>
> +#include <sys/ipc.h>
> +#include <sys/sem.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <unistd.h>
> +
> +union semun
> +{
> +	int val;
> +	struct semid_ds *buf;
> +	unsigned short *array;
> +	struct seminfo *__buf;
> +};
> +
> +static int id = -1;
> +
> +static void
> +cleanup(void)
> +{
> +	semctl(id, 0, IPC_RMID, 0);
> +	id = -1;
> +}
> +
> +int
> +main(void)
> +{
> +	id = semget (IPC_PRIVATE, 1, 0600);
> +	if (id <0)

Something went wrong with spaces here, otherwise OK.

> +		perror_msg_and_skip("semget");
> +	atexit(cleanup);
> +
> +	union semun sem_union;
> +	sem_union.val = 0;
> +	if (semctl(id, 0, SETVAL, sem_union) == -1)
> +		perror_msg_and_skip("semctl");
> +
> +	struct sembuf sem_b;
> +	sem_b.sem_num = 0;
> +	sem_b.sem_op = 1;
> +	sem_b.sem_flg = SEM_UNDO;
> +
> +	if (semop(id, &sem_b, 1))
> +		perror_msg_and_skip("semop, 1");
> +	printf("semop(%d, [{0, 1, SEM_UNDO}], 1) = 0\n", id);
> +
> +	sem_b.sem_op = -1;
> +	if (semop(id, &sem_b, 1))
> +		perror_msg_and_skip("semop, -1");
> +	printf("semop(%d, [{0, -1, SEM_UNDO}], 1) = 0\n", id);
> +
> +	puts("+++ exited with 0 +++");
> +	return 0;
> +}

I've changed sem_b to a pointer to a tail_alloc'ed memory.

Applied with these changes, thanks.


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20160420/30f6aba7/attachment.bin>


More information about the Strace-devel mailing list