[PATCH 1/3] tests: add lchown.test

Dmitry V. Levin ldv at altlinux.org
Mon Apr 18 02:07:47 UTC 2016


On Tue, Apr 12, 2016 at 02:57:45PM +0800, Fei Jie wrote:
> * tests/lchown.c: New file.
> * tests/lchown.test: New test.
> * tests/.gitignore: Add lchown.
> * tests/Makefile.am (check_PROGRAMS): Likewise.
> (DECODER_TESTS): Add lchown.test.
> ---
>  tests/.gitignore  |  1 +
>  tests/Makefile.am |  2 ++
>  tests/lchown.c    | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
>  tests/lchown.test |  6 ++++++
>  4 files changed, 58 insertions(+)
>  create mode 100644 tests/lchown.c
>  create mode 100755 tests/lchown.test
> 
> diff --git a/tests/.gitignore b/tests/.gitignore
> index 6aae5de..35db0da 100644
> --- a/tests/.gitignore
> +++ b/tests/.gitignore
> @@ -67,6 +67,7 @@ ipc_sem
>  ipc_shm
>  ksysent
>  ksysent.h
> +lchown
>  libtests.a
>  linkat
>  llseek
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index 2a4feb0..c3138eb 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -117,6 +117,7 @@ check_PROGRAMS = \
>  	ipc_sem \
>  	ipc_shm \
>  	ksysent \
> +	lchown \
>  	linkat \
>  	llseek \
>  	lseek \
> @@ -321,6 +322,7 @@ DECODER_TESTS = \
>  	ipc_msgbuf.test \
>  	ipc_sem.test \
>  	ipc_shm.test \
> +	lchown.test \
>  	linkat.test \
>  	llseek.test \
>  	lseek.test \
> diff --git a/tests/lchown.c b/tests/lchown.c
> new file mode 100644
> index 0000000..f39797c
> --- /dev/null
> +++ b/tests/lchown.c
> @@ -0,0 +1,49 @@
> +#include "tests.h"
> +#include <sys/syscall.h>
> +#include <fcntl.h>
> +
> +#ifdef __NR_lchown
> +
> +# include <errno.h>
> +# include <stdio.h>
> +# include <unistd.h>
> +
> +int
> +main(void)
> +{
> +	static const char sample[] = "lchown_sample";
> +	uid_t uid = geteuid();
> +	uid_t gid = getegid();
> +
> +	if (open(sample, O_RDONLY | O_CREAT, 0400) == -1)
> +		perror_msg_and_fail("open");
> +
> +	if (syscall(__NR_lchown, sample, uid, gid) == 0) {
> +		printf("lchown(\"%s\", %d, %d) = 0\n",
> +		       sample, uid, gid);

On 9 architectures supported by strace (including arm and x86),
__NR_lchown operates with 16-bit uids/gids, while geteuid/getegid
functions return 32-bit uids/gids.  This leads to test failure.

I've committed a different test for lchown and related syscalls.  It also
does some corner case testing that helped to find and fix a bug in 16-bit
uids/gids decoder.


-- 
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/20160418/5c65696d/attachment.bin>


More information about the Strace-devel mailing list