tests: start.sh: fix logs/current symlink creation

Message ID 20190109123411.27125-1-arnout@mind.be
State Accepted
Headers show
Series
  • tests: start.sh: fix logs/current symlink creation
Related show

Commit Message

Arnout Vandecappelle Jan. 9, 2019, 12:34 p.m.
Since 3bdc651a624, start.sh creates the logs/current symlink even if
LOGDIR was set in the environment, as is the case when using run-all.sh.
However, run-all.sh and start.sh use a separate 'date' invocation so the
resulting string may be different. Usually it is the same because the
two invocations immediately follow each other, *except* if run-all.sh
also does a build. In addition, if the user sets LOGDIR to something
else, the symlink is completely bogus.

Fix this by not relying on the 'date' invocation for creating the
symlink. Instead, use the basename of LOGDIR. To keep things consistent
with current behavior, only create the symlink if LOGDIR points to a
subdirectory of DIR/logs.

The following use cases now work reliably:
* run-all.sh with or without the -B option;
* manually calling start.sh followed by run-tests.py without setting
  LOGDIR.
* manually calling start.sh with LOGDIR set to a subdirectory of logs
  and calling run-tests.py without --logdir option (which makes it
  default to logs/current).
* run-all.sh with LOGDIR set to a subdirectory of logs.

Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
---
 tests/hwsim/start.sh | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Jouni Malinen Jan. 12, 2019, 5:47 p.m. | #1
On Wed, Jan 09, 2019 at 01:34:11PM +0100, Arnout Vandecappelle (Essensium/Mind) wrote:
> Since 3bdc651a624, start.sh creates the logs/current symlink even if
> LOGDIR was set in the environment, as is the case when using run-all.sh.
> However, run-all.sh and start.sh use a separate 'date' invocation so the
> resulting string may be different. Usually it is the same because the
> two invocations immediately follow each other, *except* if run-all.sh
> also does a build. In addition, if the user sets LOGDIR to something
> else, the symlink is completely bogus.
> 
> Fix this by not relying on the 'date' invocation for creating the
> symlink. Instead, use the basename of LOGDIR. To keep things consistent
> with current behavior, only create the symlink if LOGDIR points to a
> subdirectory of DIR/logs.
> 
> The following use cases now work reliably:
> * run-all.sh with or without the -B option;
> * manually calling start.sh followed by run-tests.py without setting
>   LOGDIR.
> * manually calling start.sh with LOGDIR set to a subdirectory of logs
>   and calling run-tests.py without --logdir option (which makes it
>   default to logs/current).
> * run-all.sh with LOGDIR set to a subdirectory of logs.

Thanks, applied.

Patch

diff --git a/tests/hwsim/start.sh b/tests/hwsim/start.sh
index 77e9791ab..648a54d84 100755
--- a/tests/hwsim/start.sh
+++ b/tests/hwsim/start.sh
@@ -8,9 +8,9 @@  HAPD_AS=$DIR/../../hostapd/hostapd
 HAPDCLI=$DIR/../../hostapd/hostapd_cli
 WLANTEST=$DIR/../../wlantest/wlantest
 HLR_AUC_GW=$DIR/../../hostapd/hlr_auc_gw
-DATE="$(date +%s)"
 
 if [ -z "$LOGDIR" ] ; then
+    DATE="$(date +%s)"
     LOGDIR="$DIR/logs/$DATE"
     mkdir -p $LOGDIR
 else
@@ -51,9 +51,10 @@  else
     fi
 fi
 
-if test -w "$DIR/logs" ; then
-    rm -rf $DIR/logs/current
-    ln -sf $DATE $DIR/logs/current
+LOGBASEDIR="$( cd "$(dirname "$LOGDIR")" && pwd )"
+if test "$LOGBASEDIR" = "$DIR/logs" -a -w "$LOGBASEDIR" ; then
+    rm -rf "$LOGBASEDIR/current"
+    ln -sf "$(basename "$LOGDIR")" "$LOGBASEDIR/current"
 fi
 
 if groups | tr ' ' "\n" | grep -q ^admin$; then