[PATCH v2 2/3] tests: add dup.test, dup2.test and dup3.test

Dmitry V. Levin ldv at altlinux.org
Mon Mar 7 22:56:41 UTC 2016


On Mon, Mar 07, 2016 at 11:32:02AM +0800, Fei Jie wrote:
[...]
> --- /dev/null
> +++ b/tests/dup.c
> @@ -0,0 +1,27 @@
> +#include "tests.h"
> +#include <sys/syscall.h>
> +
> +#ifdef __NR_dup

I think you can safely assume that dup syscall is available
and use dup() wrapper from libc.

> --- /dev/null
> +++ b/tests/dup2.c
> @@ -0,0 +1,28 @@
> +#include "tests.h"
> +#include <sys/syscall.h>
> +
> +#ifdef __NR_dup2
> +
> +# include <errno.h>
> +# include <stdio.h>
> +# include <unistd.h>
> +
> +int
> +main(void)
> +{
> +	const long int fd_old = (long int) 0xdeadbeefffffffff;
> +	const long int fd_new = (long int) 0xdeadbeeffffffffe;
> +	int rc = syscall(__NR_dup2, fd_old, fd_new);
> +	printf("dup2(%d, %d) = %d %s (%m)\n",
> +	       (int)fd_old, (int)fd_new, rc,

The test for dup2 is fine, but please add space symbols after casts
consistently.

> --- /dev/null
> +++ b/tests/dup3.c
> @@ -0,0 +1,29 @@
> +#include "tests.h"
> +#include <sys/syscall.h>
> +
> +#ifdef __NR_dup3
> +
> +# include <errno.h>
> +# include <fcntl.h>
> +# include <stdio.h>
> +# include <unistd.h>
> +
> +int
> +main(void)
> +{
> +	const long int fd_old = (long int) 0xdeadbeefffffffff;
> +	const long int fd_new = (long int) 0xdeadbeeffffffffe;
> +	int rc = syscall(__NR_dup3, fd_old, fd_new, O_CLOEXEC);
> +	printf("dup3(%d, %d, O_CLOEXEC) = %d %s (%m)\n",

Since O_CLOEXEC is a relatively new flag, we have to test it before use,
see tests/userfaultfd.c as an example.
Note that <fcntl.h> has to be included before the test.


-- 
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/20160308/f417be49/attachment.bin>


More information about the Strace-devel mailing list