On Wed, Mar 23, 2016 at 1:00 AM, Dmitry V. Levin <l...@altlinux.org> wrote:
> On Tue, Mar 22, 2016 at 09:37:09PM +0530, Jay Joshi wrote:
>> From b7ac9e7a693b8199b1942570847a82fecc8abcef Mon Sep 17 00:00:00 2001
>> From: JayRJoshi <jay.r.joshi...@gmail.com>
>> Date: Tue, 22 Mar 2016 21:07:27 +0530
>> Subject: [PATCH 1/2] Add print_quoted_string function to libtests
>>
>> * tests/tests.h (print_quoted_string): New prototype.
>> * tests/print_quoted_string.c: New file.
>> * tests/Makefile.am (libtests_a_SOURCES): Add it.
>
> $ git am --whitespace=error-all a.patch
> Applying: Add print_quoted_string function to libtests
> .git/rebase-apply/patch:31: trailing whitespace.
> /*
> .git/rebase-apply/patch:83: space before tab in indent.
>                                                 if (c3 != '0' || c2 != '0')
> .git/rebase-apply/patch:84: space before tab in indent.
>                                                         putchar(c2);
> fatal: 3 lines add whitespace errors.
>
> If you had .git/hooks/pre-commit enabled, it wouldn't let
> these whitespace errors slip into commits.
>

Interesting :)
From 551df83fa025e256bf7a142720ba45f2ce2c8697 Mon Sep 17 00:00:00 2001
From: JayRJoshi <jay.r.joshi...@gmail.com>
Date: Wed, 23 Mar 2016 19:04:15 +0530
Subject: [PATCH 1/2] Add print_quoted_string function to libtests

* tests/tests.h (print_quoted_string): New prototype.
* tests/print_quoted_string.c: New file.
* tests/Makefile.am (libtests_a_SOURCES): Add it.
---
 tests/Makefile.am           |  1 +
 tests/print_quoted_string.c | 67 +++++++++++++++++++++++++++++++++++++++++++++
 tests/tests.h               |  3 ++
 3 files changed, 71 insertions(+)
 create mode 100644 tests/print_quoted_string.c

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3005382..add44ef 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -46,6 +46,7 @@ libtests_a_SOURCES = \
 	hexdump_strdup.c \
 	hexquote_strndup.c \
 	inode_of_sockfd.c \
+	print_quoted_string.c \
 	tail_alloc.c \
 	tests.h \
 	tprintf.c \
diff --git a/tests/print_quoted_string.c b/tests/print_quoted_string.c
new file mode 100644
index 0000000..18a9ccf
--- /dev/null
+++ b/tests/print_quoted_string.c
@@ -0,0 +1,67 @@
+#include "tests.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+/*
+ * Based on string_quote() from util.c.
+ * Assumes instr is NUL-terminated.
+ */
+
+void
+print_quoted_string(const char *instr)
+{
+	const unsigned char *str = (const unsigned char*) instr;
+	int c;
+
+	while ((c = *(str++))) {
+		switch (c) {
+			case '\"':
+				printf("\\\"");
+				break;
+			case '\\':
+				printf("\\\\");
+				break;
+			case '\f':
+				printf("\\f");
+				break;
+			case '\n':
+				printf("\\n");
+				break;
+			case '\r':
+				printf("\\r");
+				break;
+			case '\t':
+				printf("\\t");
+				break;
+			case '\v':
+				printf("\\v");
+				break;
+			default:
+				if (c >= ' ' && c <= 0x7e)
+					putchar(c);
+				else {
+					putchar('\\');
+
+					char c1 = '0' + (c & 0x7);
+					char c2 = '0' + ((c >> 3) & 0x7);
+					char c3 = '0' + (c >> 6);
+
+					if (*str >= '0' && *str <= '9') {
+						/* Print \octal */
+						putchar(c3);
+						putchar(c2);
+					} else {
+						/* Print \[[o]o]o */
+						if (c3 != '0')
+							putchar(c3);
+						if (c3 != '0' || c2 != '0')
+							putchar(c2);
+					}
+					putchar(c1);
+				}
+				break;
+		}
+	}
+
+}
diff --git a/tests/tests.h b/tests/tests.h
index 826f8b2..d8632ba 100644
--- a/tests/tests.h
+++ b/tests/tests.h
@@ -75,6 +75,9 @@ const char *hexquote_strndup(const char *, size_t);
 /* Return inode number of socket descriptor. */
 unsigned long inode_of_sockfd(int);
 
+/* Print string in quoted form. */
+void print_quoted_string(const char *str);
+
 # define ARRAY_SIZE(arg) ((unsigned int) (sizeof(arg) / sizeof((arg)[0])))
 # define LENGTH_OF(arg) ((unsigned int) sizeof(arg) - 1)
 
-- 
1.9.1


From 6a73d26bae9a3cc85c33b1ae0634a04751077df6 Mon Sep 17 00:00:00 2001
From: JayRJoshi <jay.r.joshi...@gmail.com>
Date: Wed, 23 Mar 2016 19:08:35 +0530
Subject: [PATCH 2/2] tests: add getcwd.test

* 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    | 39 +++++++++++++++++++++++++++++++++++++++
 tests/getcwd.test | 11 +++++++++++
 4 files changed, 53 insertions(+)
 create mode 100644 tests/getcwd.c
 create mode 100644 tests/getcwd.test

diff --git a/tests/.gitignore b/tests/.gitignore
index 449af18..d1fb6d4 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 add44ef..60b1087 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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
index 0000000..3135df2
--- /dev/null
+++ b/tests/getcwd.c
@@ -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 100644
index 0000000..12f77ed
--- /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 -a18 $args > "$OUT"
+match_diff "$LOG" "$OUT"
+rm -f "$OUT"
-- 
1.9.1

------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140
_______________________________________________
Strace-devel mailing list
Strace-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/strace-devel

Reply via email to