From 04da9478887e705ea38e4f097492da20e651686c Mon Sep 17 00:00:00 2001
From: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
Date: Wed, 13 Sep 2017 15:48:42 +0800
Subject: [PATCH] commands/ar01: Fix for test in deterministic mode

If binutils was configured with --enable-deterministic-archives,
ar will run in deterministic mode by default, and use zero for
timestamps and uids/gids, which makes the test case abnormal.

Fix this by add the "U" modifier when deterministic mode is default.

Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
Signed-off-by: Fei Jie <feij.fnst@cn.fujitsu.com>

Upstream-Status: Backport
[http://lists.linux.it/pipermail/ltp/2017-September/005668.html]

Signed-off-by: Yi Zhao <yi.zhao@windriver.com>
---
 testcases/commands/ar/ar01 | 92 ++++++++++++++++++++++++++--------------------
 1 file changed, 52 insertions(+), 40 deletions(-)

diff --git a/testcases/commands/ar/ar01 b/testcases/commands/ar/ar01
index be105f6da..813a51d9c 100644
--- a/testcases/commands/ar/ar01
+++ b/testcases/commands/ar/ar01
@@ -24,16 +24,28 @@
 #
 AR="${AR:=ar}"
 TST_CNT=17
+TST_SETUP=setup
 TST_TESTFUNC=test
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_CMDS="$AR"
 
 . tst_test.sh
 
+setup()
+{
+	ar --help | grep "use zero for timestamps and uids/gids (default)" \
+		>/dev/null
+	if [ $? -eq 0 ]; then
+		MOD="U"
+	else
+		MOD=""
+	fi
+}
+
 test1()
 {
-	ROD ar -cr lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in
-	ROD ar -ra file1.in lib.a $TST_DATAROOT/file2.in
+	ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in
+	ROD ar -ra"$MOD" file1.in lib.a $TST_DATAROOT/file2.in
 	ROD ar -t lib.a \> ar.out
 
 	printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp
@@ -50,9 +62,9 @@ test1()
 
 test2()
 {
-	ROD ar -cr lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \
-		         $TST_DATAROOT/file3.in $TST_DATAROOT/file4.in
-	ROD ar -ma file1.in lib.a file4.in
+	ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \
+			       $TST_DATAROOT/file3.in $TST_DATAROOT/file4.in
+	ROD ar -ma"$MOD" file1.in lib.a file4.in
 	ROD ar -t lib.a \> ar.out
 
 	printf "file1.in\nfile4.in\nfile2.in\nfile3.in\n" > ar.exp
@@ -69,8 +81,8 @@ test2()
 
 test3()
 {
-	ROD ar -cr lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in
-	ROD ar -rb file3.in lib.a $TST_DATAROOT/file2.in
+	ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in
+	ROD ar -rb"$MOD" file3.in lib.a $TST_DATAROOT/file2.in
 	ROD ar -t lib.a \> ar.out
 
 	printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp
@@ -87,9 +99,9 @@ test3()
 
 test4()
 {
-	ROD ar -cr lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in \
-	                 $TST_DATAROOT/file2.in
-	ROD ar -mb file3.in lib.a file2.in
+	ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in \
+			       $TST_DATAROOT/file2.in
+	ROD ar -mb"$MOD" file3.in lib.a file2.in
 	ROD ar -t lib.a \> ar.out
 
 	printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp
@@ -106,7 +118,7 @@ test4()
 
 test5()
 {
-	ROD ar -cr lib.a $TST_DATAROOT/file1.in \> ar.out
+	ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in \> ar.out
 
 	if [ -s ar.out ]; then
 		tst_res TFAIL "ar produced output unexpectedly (-c)"
@@ -120,7 +132,7 @@ test5()
 
 test6()
 {
-	ROD ar -qc lib.a $TST_DATAROOT/file1.in \> ar.out
+	ROD ar -qc"$MOD" lib.a $TST_DATAROOT/file1.in \> ar.out
 
 	if [ -s ar.out ]; then
 		tst_res TFAIL "ar produced output unexpectedly (-qc)"
@@ -134,9 +146,9 @@ test6()
 
 test7()
 {
-	ROD ar -cr lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \
-	                 $TST_DATAROOT/file3.in
-	ROD ar -d lib.a file1.in file2.in
+	ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \
+			       $TST_DATAROOT/file3.in
+	ROD ar -d"$MOD" lib.a file1.in file2.in
 	ROD ar -t lib.a \> ar.out
 
 	printf "file3.in\n" > ar.exp
@@ -153,9 +165,9 @@ test7()
 
 test8()
 {
-	ROD ar -cr lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \
-	                 $TST_DATAROOT/file3.in
-	ROD ar -d lib.a
+	ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \
+			       $TST_DATAROOT/file3.in
+	ROD ar -d"$MOD" lib.a
 	ROD ar -t lib.a \> ar.out
 
 	printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp
@@ -172,8 +184,8 @@ test8()
 
 test9()
 {
-	ROD ar -cr lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in
-	ROD ar -ri file3.in lib.a $TST_DATAROOT/file2.in
+	ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in
+	ROD ar -ri"$MOD" file3.in lib.a $TST_DATAROOT/file2.in
 	ROD ar -t lib.a \> ar.out
 
 	printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp
@@ -190,9 +202,9 @@ test9()
 
 test10()
 {
-	ROD ar -cr lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in \
-	                 $TST_DATAROOT/file2.in
-	ROD ar -mi file3.in lib.a file2.in
+	ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in \
+			       $TST_DATAROOT/file2.in
+	ROD ar -mi"$MOD" file3.in lib.a file2.in
 	ROD ar -t lib.a \> ar.out
 
 	printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp
@@ -209,9 +221,9 @@ test10()
 
 test11()
 {
-	ROD ar -cr lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in \
-	                 $TST_DATAROOT/file2.in
-	ROD ar -m lib.a file3.in
+	ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in \
+			       $TST_DATAROOT/file2.in
+	ROD ar -m"$MOD" lib.a file3.in
 	ROD ar -t lib.a \> ar.out
 
 	printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp
@@ -228,9 +240,9 @@ test11()
 
 test12()
 {
-	ROD ar -cr lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \
-	                 $TST_DATAROOT/file3.in
-	ROD ar -p lib.a \> ar.out
+	ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \
+			       $TST_DATAROOT/file3.in
+	ROD ar -p"$MOD" lib.a \> ar.out
 
 	printf "This is file one\nThis is file two\nThis is file three\n" > ar.exp
 
@@ -247,9 +259,9 @@ test12()
 test13()
 {
 
-	ROD ar -cr lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \
-	                 $TST_DATAROOT/file3.in
-	ROD ar -q lib.a $TST_DATAROOT/file4.in
+	ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \
+			       $TST_DATAROOT/file3.in
+	ROD ar -q"$MOD" lib.a $TST_DATAROOT/file4.in
 	ROD ar -t lib.a \> ar.out
 
 	printf "file1.in\nfile2.in\nfile3.in\nfile4.in\n" > ar.exp
@@ -267,14 +279,14 @@ test13()
 test14()
 {
 	ROD touch file0.in
-	ROD ar -cr lib.a file0.in $TST_DATAROOT/file1.in
+	ROD ar -cr"$MOD" lib.a file0.in $TST_DATAROOT/file1.in
 
 	file0_mtime1=$(ar -tv lib.a | grep file0.in)
 	file1_mtime1=$(ar -tv lib.a | grep file1.in)
 
 	touch -c -t $(date --date='next day' +"%Y%m%d%H%M") file0.in
 
-	ROD ar -ru lib.a file0.in $TST_DATAROOT/file1.in
+	ROD ar -ru"$MOD" lib.a file0.in $TST_DATAROOT/file1.in
 
 	file0_mtime2=$(ar -tv lib.a | grep file0.in)
 	file1_mtime2=$(ar -tv lib.a | grep file1.in)
@@ -296,7 +308,7 @@ test14()
 
 test15()
 {
-	ROD ar -cr lib.a $TST_DATAROOT/file1.in
+	ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in
 	ROD ar -tv lib.a \> ar.out
 
 	if grep -q '[rwx-]\{9\} [0-9].*/[0-9].*\s*[0-9].*.*file1.in' ar.out; then
@@ -311,9 +323,9 @@ test15()
 
 test16()
 {
-	ROD ar -cr lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \
-	                 $TST_DATAROOT/file3.in
-	ROD ar -xv lib.a \> ar.out
+	ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \
+			       $TST_DATAROOT/file3.in
+	ROD ar -xv"$MOD" lib.a \> ar.out
 
 	printf "x - file1.in\nx - file2.in\nx - file3.in\n" > ar.exp
 
@@ -335,8 +347,8 @@ test16()
 
 test17()
 {
-	ROD ar -cr lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in
-	ROD ar -xv lib.a file2.in \> ar.out
+	ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in
+	ROD ar -xv"$MOD" lib.a file2.in \> ar.out
 
 	printf "x - file2.in\n" > ar.exp
 
-- 
2.19.0.rc2

