[PATCH 2/3] tests: add getcwd.test

Dmitry V. Levin ldv at altlinux.org
Thu Mar 17 02:03:16 UTC 2016


On Tue, Mar 15, 2016 at 04:38:35PM +0800, Fei Jie wrote:
> * tests/getcwd.c: New file.
> * tests/getcwd.test: New test.
> * tests/.gitignore: Add getcwd.
> * tests/Makefile.am (check_PROGRAMS): Likewise.
> (TESTS): Add getcwd.test.
> ---
>  tests/.gitignore  |  1 +
>  tests/Makefile.am |  2 ++
>  tests/getcwd.c    | 26 ++++++++++++++++++++++++++
>  tests/getcwd.test | 11 +++++++++++
>  4 files changed, 40 insertions(+)
>  create mode 100644 tests/getcwd.c
>  create mode 100755 tests/getcwd.test
> 
> diff --git a/tests/.gitignore b/tests/.gitignore
> index 6059af9..8312930 100644
> --- a/tests/.gitignore
> +++ b/tests/.gitignore
> @@ -42,6 +42,7 @@ fstat64
>  fstatat64
>  ftruncate
>  ftruncate64
> +getcwd
>  getdents
>  getdents64
>  getrandom
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index 6d1c771..2a2f3a3 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -92,6 +92,7 @@ check_PROGRAMS = \
>  	fstatat64 \
>  	ftruncate \
>  	ftruncate64 \
> +	getcwd \
>  	getdents \
>  	getdents64 \
>  	getrandom \
> @@ -266,6 +267,7 @@ TESTS = \
>  	fstatat64.test \
>  	ftruncate.test \
>  	ftruncate64.test \
> +	getcwd.test \
>  	getdents.test \
>  	getdents64.test \
>  	getrandom.test \
> diff --git a/tests/getcwd.c b/tests/getcwd.c
> new file mode 100644
> index 0000000..7683d27
> --- /dev/null
> +++ b/tests/getcwd.c
> @@ -0,0 +1,26 @@
> +#include "tests.h"
> +#include <sys/syscall.h>
> +
> +#ifdef __NR_getcwd
> +
> +# include <stdio.h>
> +# include <unistd.h>
> +
> +static char buf[8192];
> +
> +int
> +main(void)
> +{
> +	int rc = syscall(__NR_getcwd, buf, 8192);

Note that getcwd might fail, but you still can assume that it will
succeed because a lot of other things are likely to go wrong otherwise.

> +	printf("getcwd(\"%s\", 8192) = %d\n",
> +	       buf, rc);

Using 8192 instead of sizeof(buf) is not an example of good style.

> +
> +	puts("+++ exited with 0 +++");
> +	return 0;
> +}
> +
> +#else
> +
> +SKIP_MAIN_UNDEFINED("__NR_getcwd")
> +
> +#endif	
> diff --git a/tests/getcwd.test b/tests/getcwd.test
> new file mode 100755
> index 0000000..48e7a91
> --- /dev/null
> +++ b/tests/getcwd.test
> @@ -0,0 +1,11 @@
> +#!/bin/sh
> +
> +# Check getcwd syscall decoding.
> +
> +. "${srcdir=.}/init.sh"
> +
> +run_prog > /dev/null
> +OUT="$LOG.out"
> +run_strace -egetcwd -a23 $args > "$OUT"
> +match_diff "$LOG" "$OUT"
> +rm -f "$OUT"

23 might be too big.


-- 
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/20160317/1c5c1871/attachment.bin>


More information about the Strace-devel mailing list