[PATCH v1] tests: getcwd.test

Jay Joshi jay.r.joshi100 at gmail.com
Tue Mar 15 11:36:48 UTC 2016


>From 5e543e3a0ae730b1833c8a4d5d9a5bf28273256d Mon Sep 17 00:00:00 2001
From: JayRJoshi <jay.r.joshi100 at gmail.com>
Date: Tue, 15 Mar 2016 16:41:39 +0530
Subject: [PATCH] Test for getcwd (getcwd.c, getcwd.expected, getcwd.test)
 added

---
 tests/.gitignore      |  1 +
 tests/Makefile.am     |  2 ++
 tests/getcwd.c        | 36 ++++++++++++++++++++++++++++++++++++
 tests/getcwd.expected |  2 ++
 tests/getcwd.test     |  9 +++++++++
 5 files changed, 50 insertions(+)
 create mode 100644 tests/getcwd.c
 create mode 100644 tests/getcwd.expected
 create mode 100755 tests/getcwd.test

diff --git a/tests/.gitignore b/tests/.gitignore
index b89796a..52eb76d 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -41,6 +41,7 @@ fstat64
 fstatat64
 ftruncate
 ftruncate64
+getcwd
 getdents
 getdents64
 getrandom
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 59e7e78..81ad778 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -91,6 +91,7 @@ check_PROGRAMS = \
  fstatat64 \
  ftruncate \
  ftruncate64 \
+ getcwd \
  getdents \
  getdents64 \
  getrandom \
@@ -264,6 +265,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..f2b4651
--- /dev/null
+++ b/tests/getcwd.c
@@ -0,0 +1,36 @@
+#include "tests.h"
+
+#include <sys/stat.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+
+
+int
+main(void)
+{
+  char cur_dir[32];
+
+  if (mkdir("/tmp/sample_dir", S_IRWXU) == -1)
+    perror_msg_and_skip("mkdir");
+
+  if (chdir("/tmp/sample_dir") == -1)
+    perror_msg_and_skip("chdir");
+
+  if (getcwd(cur_dir, sizeof(cur_dir)) != NULL) {
+    printf("getcwd(\"/tmp/sample_dir\", 32) = 16\n");
+  } else {
+    perror_msg_and_fail("getcwd");
+  }
+
+  if (rmdir(cur_dir) == -1)
+    perror_msg_and_skip("rmdir");
+
+  if (getcwd(cur_dir, sizeof(cur_dir)) != NULL) {
+    printf("getcwd(\"/tmp/sample_dir\", 32) = 16\n");
+  } else {
+    printf("getcwd(\"0x0123456789ab, 32) = -1 ENOENT (%m)\n");
+  }
+
+  return 0;
+}
diff --git a/tests/getcwd.expected b/tests/getcwd.expected
new file mode 100644
index 0000000..23bc26b
--- /dev/null
+++ b/tests/getcwd.expected
@@ -0,0 +1,2 @@
+getcwd\(\"/tmp/sample_dir\", 32\) += 16
+getcwd\(0x[0-9a-f]+, 32\) += -1 ENOENT \(No such file or directory\)
diff --git a/tests/getcwd.test b/tests/getcwd.test
new file mode 100755
index 0000000..03fabb1
--- /dev/null
+++ b/tests/getcwd.test
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+. "${srcdir=.}/init.sh"
+
+run_prog > /dev/null
+run_strace -egetcwd $args
+match_grep
+
+exit 0
-- 
1.9.1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20160315/b25dfe88/attachment.html>


More information about the Strace-devel mailing list