All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] rdist01: fix mistakes
@ 2013-11-04  9:45 Simon Xu
  2013-11-07 16:02 ` chrubis
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Xu @ 2013-11-04  9:45 UTC (permalink / raw)
  To: ltp-list

Fix the following mistakes in the script:
1) the way it gets dirname and basename of files is broken
2) ${FILES} and ${HOSTS} get substituted when generating distfile
3) the way it calculates sum of files on RHOST is broken
4) there is no $DIRECTORIES variable

Signed-off-by: Simon Xu <xu.simon@oracle.com>
---
 testcases/network/tcp_cmds/rdist/rdist01 | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/testcases/network/tcp_cmds/rdist/rdist01 b/testcases/network/tcp_cmds/rdist/rdist01
index 9e30492..27d6270 100755
--- a/testcases/network/tcp_cmds/rdist/rdist01
+++ b/testcases/network/tcp_cmds/rdist/rdist01
@@ -63,8 +63,8 @@ do_setup()
     done
 
     for i in $FILES; do
-        BASE=${i##*/}
-        DIR=${%%/*}
+        BASE=$(basename "$i")
+        DIR=$(dirname "$i")
         test -d "$DIR" || mkdir -p "$DIR"
         if [ $? -ne 0 ] ; then
             end_testcase "failed to create $DIR"
@@ -94,7 +94,7 @@ create_distfile()
 {
     T_FILES="FILES = ( "
     for i in $FILES; do
-        if [ "${i%%*/}" = "." ]; then
+        if [ $(dirname "$i") == "." ]; then
             T_FILES="$T_FILES $i"
         else
             T_FILES="$T_FILES $DIR"
@@ -105,7 +105,7 @@ create_distfile()
     T_HOST="HOSTS = ("
     for c_ruser in $RUSERS; do
         for c_rhost in $HOSTS; do
-         T_HOST=$T_HOST"$c_ruser@$c_rhost "
+         T_HOST=$T_HOST" $c_ruser@$c_rhost"
         done
     done
 
@@ -113,7 +113,7 @@ create_distfile()
     cat <<EOF > "$TCtmp/distfile"
 $T_HOST
 $T_FILES
-${FILES} -> ${HOSTS}
+\${FILES} -> \${HOSTS}
 EOF
 }
 
@@ -130,17 +130,15 @@ check_result()
     cd $TCtmp
     for c_rhost in $HOSTS; do
         for c_ruser in $RUSERS; do
-            TOTAL_SUM=`rsh -n -l $c_ruser $c_rhost \
-            x=0; SUM=\$(sum -s $FILES|awk '{ print \$1 }')
-            for i in \$SUM; do
-                x=\$(( \$x + \$i ))
+            TOTAL_SUM=0
+            for i in $(rsh -n -l $c_ruser $c_rhost sum -s $FILES | awk '{ print $1 }'); do
+                TOTAL_SUM=$(( $TOTAL_SUM + $i ))
             done
-            echo \$x`
-            if [ $TOTAL_SUM = $LSUM ]; then
+            if [ $TOTAL_SUM == $LSUM ]; then
                 tst_resm TINFO "Success rdist in $c_ruser@$c_rhost "
-                rsh -n -l $c_ruser $c_rhost "rm -rf $FILES $DIRECTORIES"
+                rsh -n -l $c_ruser $c_rhost "rm -rf $FILES"
             else
-                end_testcase "Wrong sum doing  rdist in $curr_ruser@$curr_rhost"
+                end_testcase "Wrong sum doing rdist in $curr_ruser@$curr_rhost"
             fi
        done
    done
-- 
1.8.4.2


------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH] rdist01: fix mistakes
  2013-11-04  9:45 [LTP] [PATCH] rdist01: fix mistakes Simon Xu
@ 2013-11-07 16:02 ` chrubis
  2013-11-08  3:39   ` [LTP] [PATCH V2] " Simon Xu
  0 siblings, 1 reply; 4+ messages in thread
From: chrubis @ 2013-11-07 16:02 UTC (permalink / raw)
  To: Simon Xu; +Cc: ltp-list

Hi!
> @@ -130,17 +130,15 @@ check_result()
>      cd $TCtmp
>      for c_rhost in $HOSTS; do
>          for c_ruser in $RUSERS; do
> -            TOTAL_SUM=`rsh -n -l $c_ruser $c_rhost \
> -            x=0; SUM=\$(sum -s $FILES|awk '{ print \$1 }')
> -            for i in \$SUM; do
> -                x=\$(( \$x + \$i ))
> +            TOTAL_SUM=0
> +            for i in $(rsh -n -l $c_ruser $c_rhost sum -s $FILES | awk '{ print $1 }'); do
> +                TOTAL_SUM=$(( $TOTAL_SUM + $i ))
>              done
> -            echo \$x`
> -            if [ $TOTAL_SUM = $LSUM ]; then
> +            if [ $TOTAL_SUM == $LSUM ]; then

Unlike C the correct comparsion operator here is the single '='. The
'==' is bash extension that does not work with other shells. And in case
you are comparing two numbers -eq is even better (as ' 0' -eq '0' is
still true unlike ' 0' = '0').

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explore
techniques for threading, error checking, porting, and tuning. Get the most 
from the latest Intel processors and coprocessors. See abstracts and register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [LTP] [PATCH V2] rdist01: fix mistakes
  2013-11-07 16:02 ` chrubis
@ 2013-11-08  3:39   ` Simon Xu
  2013-11-11 16:48     ` chrubis
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Xu @ 2013-11-08  3:39 UTC (permalink / raw)
  To: ltp-list

Fix the following mistakes in the script:
1) the way it gets dirname and basename of files is broken
2) ${FILES} and ${HOSTS} get substituted when generating distfile
3) the way it calculates sum of files on RHOST is broken
4) there is no $DIRECTORIES variable

Signed-off-by: Simon Xu <xu.simon@oracle.com>
---
 testcases/network/tcp_cmds/rdist/rdist01 | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/testcases/network/tcp_cmds/rdist/rdist01 b/testcases/network/tcp_cmds/rdist/rdist01
index 9e30492..4bc239f 100755
--- a/testcases/network/tcp_cmds/rdist/rdist01
+++ b/testcases/network/tcp_cmds/rdist/rdist01
@@ -63,8 +63,8 @@ do_setup()
     done
 
     for i in $FILES; do
-        BASE=${i##*/}
-        DIR=${%%/*}
+        BASE=$(basename "$i")
+        DIR=$(dirname "$i")
         test -d "$DIR" || mkdir -p "$DIR"
         if [ $? -ne 0 ] ; then
             end_testcase "failed to create $DIR"
@@ -94,7 +94,7 @@ create_distfile()
 {
     T_FILES="FILES = ( "
     for i in $FILES; do
-        if [ "${i%%*/}" = "." ]; then
+        if [ $(dirname "$i") == "." ]; then
             T_FILES="$T_FILES $i"
         else
             T_FILES="$T_FILES $DIR"
@@ -105,7 +105,7 @@ create_distfile()
     T_HOST="HOSTS = ("
     for c_ruser in $RUSERS; do
         for c_rhost in $HOSTS; do
-         T_HOST=$T_HOST"$c_ruser@$c_rhost "
+         T_HOST=$T_HOST" $c_ruser@$c_rhost"
         done
     done
 
@@ -113,7 +113,7 @@ create_distfile()
     cat <<EOF > "$TCtmp/distfile"
 $T_HOST
 $T_FILES
-${FILES} -> ${HOSTS}
+\${FILES} -> \${HOSTS}
 EOF
 }
 
@@ -130,17 +130,15 @@ check_result()
     cd $TCtmp
     for c_rhost in $HOSTS; do
         for c_ruser in $RUSERS; do
-            TOTAL_SUM=`rsh -n -l $c_ruser $c_rhost \
-            x=0; SUM=\$(sum -s $FILES|awk '{ print \$1 }')
-            for i in \$SUM; do
-                x=\$(( \$x + \$i ))
+            TOTAL_SUM=0
+            for i in $(rsh -n -l $c_ruser $c_rhost sum -s $FILES | awk '{ print $1 }'); do
+                TOTAL_SUM=$(( $TOTAL_SUM + $i ))
             done
-            echo \$x`
-            if [ $TOTAL_SUM = $LSUM ]; then
+            if [ $TOTAL_SUM -eq $LSUM ]; then
                 tst_resm TINFO "Success rdist in $c_ruser@$c_rhost "
-                rsh -n -l $c_ruser $c_rhost "rm -rf $FILES $DIRECTORIES"
+                rsh -n -l $c_ruser $c_rhost "rm -rf $FILES"
             else
-                end_testcase "Wrong sum doing  rdist in $curr_ruser@$curr_rhost"
+                end_testcase "Wrong sum doing rdist in $curr_ruser@$curr_rhost"
             fi
        done
    done
-- 
1.8.4.2


------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explore
techniques for threading, error checking, porting, and tuning. Get the most 
from the latest Intel processors and coprocessors. See abstracts and register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH V2] rdist01: fix mistakes
  2013-11-08  3:39   ` [LTP] [PATCH V2] " Simon Xu
@ 2013-11-11 16:48     ` chrubis
  0 siblings, 0 replies; 4+ messages in thread
From: chrubis @ 2013-11-11 16:48 UTC (permalink / raw)
  To: Simon Xu; +Cc: ltp-list

Hi!
> Fix the following mistakes in the script:
> 1) the way it gets dirname and basename of files is broken
> 2) ${FILES} and ${HOSTS} get substituted when generating distfile
> 3) the way it calculates sum of files on RHOST is broken
> 4) there is no $DIRECTORIES variable

Pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explore
techniques for threading, error checking, porting, and tuning. Get the most 
from the latest Intel processors and coprocessors. See abstracts and register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-11-11 17:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-04  9:45 [LTP] [PATCH] rdist01: fix mistakes Simon Xu
2013-11-07 16:02 ` chrubis
2013-11-08  3:39   ` [LTP] [PATCH V2] " Simon Xu
2013-11-11 16:48     ` chrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.