[PATCH 3/3] tests: add umask.test
Dmitry V. Levin
ldv at altlinux.org
Mon Feb 29 23:50:47 UTC 2016
On Fri, Feb 26, 2016 at 05:41:39PM +0800, Fei Jie wrote:
> * tests/umask.c: New file.
> * tests/umask.test: New test.
> * tests/.gitignore: Add umask.
> * tests/Makefile.am (check_PROGRAMS): Likewise.
> (TESTS): Add umask.test.
> ---
> tests/.gitignore | 1 +
> tests/Makefile.am | 2 ++
> tests/umask.c | 25 +++++++++++++++++++++++++
> tests/umask.test | 11 +++++++++++
> 4 files changed, 39 insertions(+)
> create mode 100644 tests/umask.c
> create mode 100755 tests/umask.test
>
> diff --git a/tests/.gitignore b/tests/.gitignore
> index a5d586d..31b643c 100644
> --- a/tests/.gitignore
> +++ b/tests/.gitignore
> @@ -121,6 +121,7 @@ uid
> uid16
> uid32
> uio
> +umask
> umount
> umount2
> umovestr
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index 4603c92..6ce2def 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -169,6 +169,7 @@ check_PROGRAMS = \
> uid16 \
> uid32 \
> uio \
> + umask \
> umount \
> umount2 \
> umovestr \
> @@ -325,6 +326,7 @@ TESTS = \
> uid16.test \
> uid32.test \
> uio.test \
> + umask.test \
> umount.test \
> umount2.test \
> umovestr.test \
> diff --git a/tests/umask.c b/tests/umask.c
> new file mode 100644
> index 0000000..badc6f5
> --- /dev/null
> +++ b/tests/umask.c
> @@ -0,0 +1,25 @@
> +#include "tests.h"
> +#include <sys/syscall.h>
> +
> +#ifdef __NR_umask
> +
> +# include <stdio.h>
> +# include <sys/types.h>
> +# include <sys/stat.h>
> +# include <unistd.h>
> +
> +int
> +main(void)
> +{
> + mode_t rc = syscall(__NR_umask, 044);
You can assume that umask function provided by libc works
and use it safely instead of syscall().
> + printf("umask(0%o) = 0%o\n", 044, rc);
This would print zero umask as 00, which is probably not what you want.
Let's use %#o format like strace parser does.
--
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/20160301/1ff67d16/attachment.bin>
More information about the Strace-devel
mailing list