]> granicus.if.org Git - strace/commitdiff
tests: add getcwd.test
authorJayRJoshi <jay.r.joshi100@gmail.com>
Wed, 23 Mar 2016 13:38:35 +0000 (19:08 +0530)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 23 Mar 2016 13:38:35 +0000 (13:38 +0000)
* 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
tests/Makefile.am
tests/getcwd.c [new file with mode: 0644]
tests/getcwd.test [new file with mode: 0755]

index 449af18250e991a988b869d471ee5dc7965c226d..d1fb6d496e4c59e188ac11bdef4135c303db28d9 100644 (file)
@@ -42,6 +42,7 @@ fstat64
 fstatat64
 ftruncate
 ftruncate64
+getcwd
 getdents
 getdents64
 getrandom
index add44efe7f7582c0d6972dcf23f0966e4f198dbe..60b1087e949e2dbedf727389d5a93b7af9d91d85 100644 (file)
@@ -93,6 +93,7 @@ check_PROGRAMS = \
        fstatat64 \
        ftruncate \
        ftruncate64 \
+       getcwd \
        getdents \
        getdents64 \
        getrandom \
@@ -269,6 +270,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 (file)
index 0000000..3135df2
--- /dev/null
@@ -0,0 +1,39 @@
+#include "tests.h"
+
+#include <sys/syscall.h>
+
+#ifdef __NR_getcwd
+
+# include <stdio.h>
+# include <unistd.h>
+# include <sys/param.h>
+
+int
+main(void)
+{
+       long res;
+       char cur_dir[PATH_MAX + 1];
+
+       res = syscall(__NR_getcwd, cur_dir, sizeof(cur_dir));
+
+       if (res <= 0)
+               perror_msg_and_fail("getcwd");
+
+       printf("getcwd(\"");
+       print_quoted_string(cur_dir);
+       printf("\", %zu) = %ld\n", sizeof(cur_dir), res);
+
+       syscall(__NR_getcwd, cur_dir, 0);
+
+       printf("getcwd(%p, 0) = -1 ERANGE (%m)\n", cur_dir);
+
+       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 (executable)
index 0000000..12f77ed
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+# Check getcwd syscall decoding.
+
+. "${srcdir=.}/init.sh"
+
+run_prog > /dev/null
+OUT="$LOG.out"
+run_strace -egetcwd -a18 $args > "$OUT"
+match_diff "$LOG" "$OUT"
+rm -f "$OUT"