On Tue, Mar 22, 2016 at 5:15 AM, Dmitry V. Levin <l...@altlinux.org> wrote:
> On Mon, Mar 21, 2016 at 03:17:19PM +0530, Jay Joshi wrote:
>> Subject: [PATCH] tests: add getcwd.test, 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.
>
> Looks like it's better to split this patch. The first one would just add
> print_quoted_string, ...
>
>> * tests/getcwd.c: New file.
>> * tests/getcwd.test: New test.
>> * tests/.gitignore: Add getcwd.
>> * tests/Makefile.am (check_PROGRAMS): Likewise.
>> (TESTS): Add getcwd.test.
>
> ... and the second would add this test.
>
> Besides the split and several minor comments below, the patch seems ready.
>
>> --- /dev/null
>> +++ b/tests/getcwd.test
>> @@ -0,0 +1,13 @@
>> +#!/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"
>
> Let's keep everything quoted the same way.
>
>> +
>> +exit 0
>
> You don't really need this. I know I've added a lot of them myself,
> but they are not needed in new files anyway.
>
>> --- /dev/null
>> +++ b/tests/print_quoted_string.c
>> @@ -0,0 +1,67 @@
>> +#include "tests.h"
>> +
>> +#include <stdio.h>
>> +#include <stdlib.h>
>> +
>> +/* Modified from string_quote() from util.c.
>
> It's "Based on" rather than "Modified from".
>
> Also, our preferred boxed comment style is
> /*
> * Lines of
> * Text.
> */
>
>> + /* Print \[[o]o]o */
>> + if ((c >> 3) != 0) {
>> + if ((c >> 6) != 0)
>> + putchar(c3);
>> + putchar(c2);
>> + }
>
> Isn't this more readable:
>
> if (c3 != '0' || c2 != '0') {
> if (c3 != '0')
> putchar(c3);
> putchar(c2);
> }
>
>> +/* Print string in escaped format. */
>> +void print_quoted_string(const char *str);
>> +
>
> escaped vs quoted
>
Patch is attached.
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.
---
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..d5dc157
--- /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 f3f23a1c8baf7c89bfbd5ad53dcc1dea2ab362c6 Mon Sep 17 00:00:00 2001
From: JayRJoshi <jay.r.joshi...@gmail.com>
Date: Tue, 22 Mar 2016 21:12:40 +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 | 40 ++++++++++++++++++++++++++++++++++++++++
tests/getcwd.test | 11 +++++++++++
4 files changed, 54 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..7cbc189
--- /dev/null
+++ b/tests/getcwd.c
@@ -0,0 +1,40 @@
+#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