On Sat, Mar 26, 2016 at 8:59 AM, Dmitry V. Levin <[email protected]> wrote:
> On Fri, Mar 25, 2016 at 04:46:53PM +0530, Jay Joshi wrote:
>> On Fri, Mar 25, 2016 at 1:56 AM, Dmitry V. Levin wrote:
>> > On Thu, Mar 24, 2016 at 03:17:48PM +0530, Jay Joshi wrote:
> [...]
>> >> Also, is a test for abbreviated output required?
>> >
>> > It surely won't harm. :)
>> >
>>
>> I've seen in some tests like mmap.test, $ME_ is used in run_prog. I
>> think test scripts should not directly access them. What do you say?
>
> Why do you think so?  Does the name look cryptic?
>

I mean, something like run_prog -a $mmap looks simpler.

> [...]
>> >> --- a/tests/uname.c
>> >> +++ b/tests/uname.c
>> >> @@ -11,21 +11,23 @@ int main()
>> >>  {
>> >>       struct utsname *const uname = tail_alloc(sizeof(struct utsname));
>> >>       int rc = syscall(__NR_uname, uname);
>> >> -     printf("uname({sysname=\"%s\", nodename=\"%s\", release=\"%s\""
>> >> -            ", version=\"%s\", machine=\"%s\""
>> >> +     printf("uname({sysname=\"");
>> >> +             print_quoted_string(uname->sysname);
>> >> +     printf("\", nodename=\"");
>> >> +             print_quoted_string(uname->nodename);
>> >> +     printf("\", release=\"");
>> >> +             print_quoted_string(uname->release);
>> >> +     printf("\", version=\"");
>> >> +             print_quoted_string(uname->version);
>> >> +     printf("\", machine=\"");
>> >> +             print_quoted_string(uname->machine);
>> >
>> > Why these print_quoted_string calls are indented this way?
>>
>> I think it looks more readable this way, it's like the're nested inside 
>> quotes.
>
> I don't share your PoV on this.
>
>
Okay, print statements will be indented same way.
Patch is attached.
I've used getopts for flag abbrev, even if there is this only flag. Is
it fine? Any other changes required?
From 134ce78f3b32b4d41d75a1ddfcd0a9447a35d990 Mon Sep 17 00:00:00 2001
From: JayRJoshi <[email protected]>
Date: Thu, 24 Mar 2016 12:39:32 +0530
Subject: [PATCH 2/2] tests/uname.c: use print_quoted_string

* tests/uname.c: Use print_quoted_string to print members of utsname,
Add abbrev check.
* tests/uname.c: Add abbrev check.
---
 tests/uname.c    | 48 ++++++++++++++++++++++++++++++++++--------------
 tests/uname.test |  8 +++++++-
 2 files changed, 41 insertions(+), 15 deletions(-)

diff --git a/tests/uname.c b/tests/uname.c
index 0f1b5f3..147eae6 100644
--- a/tests/uname.c
+++ b/tests/uname.c
@@ -6,27 +6,47 @@
 # include <stdio.h>
 # include <sys/utsname.h>
 # include <unistd.h>
+# include <assert.h>
 
-int main()
+int main(int ac, char **av)
 {
+	assert(ac <= 2);
+
+	int abbrev = 0, c;
+	while ((c = getopt (ac, av, "a")) != -1) {
+		switch (c) {
+			case 'a':
+				abbrev = 1;
+				break;
+		}
+	}
+
 	struct utsname *const uname = tail_alloc(sizeof(struct utsname));
 	int rc = syscall(__NR_uname, uname);
-	printf("uname({sysname=\"%s\", nodename=\"%s\", release=\"%s\""
-	       ", version=\"%s\", machine=\"%s\""
-# ifdef HAVE_STRUCT_UTSNAME_DOMAINNAME
-	       ", domainname=\"%s\""
-# endif
-	       "}) = %d\n",
-	       uname->sysname,
-	       uname->nodename,
-	       uname->release,
-	       uname->version,
-	       uname->machine,
+	printf("uname({sysname=\"");
+	print_quoted_string(uname->sysname);
+	printf("\", nodename=\"");
+	print_quoted_string(uname->nodename);
+	printf("\"");
+	if (abbrev) {
+		printf(", ...");
+		goto print_and_exit;
+	}
+	printf(", release=\"");
+	print_quoted_string(uname->release);
+	printf("\", version=\"");
+	print_quoted_string(uname->version);
+	printf("\", machine=\"");
+	print_quoted_string(uname->machine);
+	printf("\"");
 # ifdef HAVE_STRUCT_UTSNAME_DOMAINNAME
-	       uname->domainname,
+	printf(", domainname=\"");
+	print_quoted_string(uname->domainname);
+	printf("\"");
 # endif
-	       rc);
 
+print_and_exit:
+	printf("}) = %d\n", rc);
 	puts("+++ exited with 0 +++");
 	return 0;
 }
diff --git a/tests/uname.test b/tests/uname.test
index e699f1c..4277efb 100755
--- a/tests/uname.test
+++ b/tests/uname.test
@@ -6,10 +6,16 @@
 
 check_prog uniq
 
-run_prog > /dev/null
 OUT="$LOG.out"
 EXP="$LOG.exp"
+
+run_prog > /dev/null
 run_strace -v -euname $args > "$EXP"
 uniq < "$LOG" > "$OUT"
+
+run_prog "./${ME_%.test}" -a > /dev/null
+run_strace -euname $args >> "$EXP"
+uniq < "$LOG" >> "$OUT"
+
 match_diff "$OUT" "$EXP"
 rm -f "$OUT" "$EXP"
-- 
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/strace-devel

Reply via email to