summaryrefslogtreecommitdiffstats
path: root/test/testswmr.sh
diff options
context:
space:
mode:
Diffstat (limited to 'test/testswmr.sh')
-rwxr-xr-xtest/testswmr.sh139
1 files changed, 131 insertions, 8 deletions
diff --git a/test/testswmr.sh b/test/testswmr.sh
index 794910c..42e76ce 100755
--- a/test/testswmr.sh
+++ b/test/testswmr.sh
@@ -34,6 +34,14 @@ Nsecs_addrem=8 # number of seconds per read interval
nerrors=0
###############################################################################
+## definitions for message file to coordinate test runs
+###############################################################################
+WRITER_MESSAGE=SWMR_WRITER_MESSAGE # The message file created by writer that the open is complete
+ # This should be the same as the define in "./swmr_common.h"
+MESSAGE_TIMEOUT=300 # Message timeout length in secs
+ # This should be the same as the define in "./h5test.h"
+
+###############################################################################
## short hands and function definitions
###############################################################################
DPRINT=: # Set to "echo Debug:" for debugging printing,
@@ -48,8 +56,42 @@ TESTING() {
echo "Testing $* $SPACES" | cut -c1-70 | tr -d '\012'
}
+# To wait for the writer message file or till the maximum # of seconds is reached
+# $1 is the message file to wait for
+# This performs similar function as the routine h5_wait_message() in test/h5test.c
+WAIT_MESSAGE() {
+ message=$1 # Get the name of the message file to wait for
+ t0=`date +%s` # Get current time in seconds
+ difft=0 # Initialize the time difference
+ mexist=0 # Indicate whether the message file is found
+ while [ $difft -lt $MESSAGE_TIMEOUT ] ; # Loop till message times out
+ do
+ t1=`date +%s` # Get current time in seconds
+ difft=`expr $t1 - $t0` # Calculate the time difference
+ if [ -e $message ]; then # If message file is found:
+ mexist=1 # indicate the message file is found
+ rm $message # remove the message file
+ break # get out of the while loop
+ fi
+ done;
+ if test $mexist -eq 0; then
+ # Issue warning that the writer message file is not found, continue with launching the reader(s)
+ echo warning: $WRITER_MESSAGE is not found after waiting $MESSAGE_TIMEOUT seconds
+ else
+ echo $WRITER_MESSAGE is found
+ fi
+}
+
###############################################################################
## Main
+##
+## Modifications:
+## Vailin Choi; July 2013
+## Add waiting of message file before launching the reader(s).
+## Due to the implementation of file locking, coordination
+## is needed in file opening for the writer/reader tests
+## to proceed as expected.
+##
###############################################################################
# The build (current) directory might be different than the source directory.
if test -z "$srcdir"; then
@@ -103,6 +145,66 @@ do
echo
echo "###############################################################################"
+ echo "## Use H5Fstart_swmr_write() to enable SWMR writing mode"
+ echo "###############################################################################"
+
+ # Remove any possible writer message file before launching writer
+ rm -f $WRITER_MESSAGE
+ #
+ # Launch the Writer
+ echo launch the swmr_start_writer
+ seed="" # Put -r <random seed> command here
+ ./swmr_start_write $compress $index_type $Nrecords $seed &
+ pid_writer=$!
+ $DPRINT pid_writer=$pid_writer
+ #
+ # Wait for message from writer process before starting reader(s)
+ WAIT_MESSAGE $WRITER_MESSAGE
+
+ #
+ # Launch the Readers
+ #declare -a seeds=(<seed1> <seed2> <seed3> ... )
+ echo launch $Nreaders swmr_readers
+ pid_readers=""
+ n=0
+ while [ $n -lt $Nreaders ]; do
+ #seed="-r ${seeds[$n]}"
+ seed=""
+ ./swmr_reader $Nsecs_add $seed &
+ pid_readers="$pid_readers $!"
+ n=`expr $n + 1`
+ done
+ $DPRINT pid_readers=$pid_readers
+ $IFDEBUG ps
+
+ # Collect exit code of the readers first because they usually finish
+ # before the writer.
+ for xpid in $pid_readers; do
+ $DPRINT checked reader $xpid
+ wait $xpid
+ if test $? -ne 0; then
+ echo reader had error
+ nerrors=`expr $nerrors + 1`
+ fi
+ done
+
+ # Collect exit code of the writer
+ $DPRINT checked writer $pid_writer
+ wait $pid_writer
+ if test $? -ne 0; then
+ echo writer had error
+ nerrors=`expr $nerrors + 1`
+ fi
+
+ # Check for error and exit if one occured
+ $DPRINT nerrors=$nerrors
+ if test $nerrors -ne 0 ; then
+ echo "SWMR tests failed with $nerrors errors."
+ exit 1
+ fi
+
+ echo
+ echo "###############################################################################"
echo "## Writer test - test expanding the dataset"
echo "###############################################################################"
@@ -113,14 +215,19 @@ do
echo generator had error
nerrors=`expr $nerrors + 1`
fi
-
+ # Remove any possible writer message file before launching writer
+ rm -f $WRITER_MESSAGE
+ #
# Launch the Writer
echo launch the swmr_writer
seed="" # Put -r <random seed> command here
./swmr_writer $Nrecords $seed &
pid_writer=$!
$DPRINT pid_writer=$pid_writer
-
+ #
+ # Wait for message from writer process before starting reader(s)
+ WAIT_MESSAGE $WRITER_MESSAGE
+ #
# Launch the Readers
#declare -a seeds=(<seed1> <seed2> <seed3> ... )
echo launch $Nreaders swmr_readers
@@ -166,14 +273,19 @@ do
echo "###############################################################################"
echo "## Remove test - test shrinking the dataset"
echo "###############################################################################"
-
+ #
+ # Remove any possible writer message file before launching writer
+ rm -f $WRITER_MESSAGE
# Launch the Remove Writer
echo launch the swmr_remove_writer
seed="" # Put -r <random seed> command here
./swmr_remove_writer $Nrecs_rem $seed &
pid_writer=$!
$DPRINT pid_writer=$pid_writer
-
+ #
+ # Wait for message from writer process before starting reader(s)
+ WAIT_MESSAGE $WRITER_MESSAGE
+ #
# Launch the Remove Readers
#declare -a seeds=(<seed1> <seed2> <seed3> ... )
n=0
@@ -236,14 +348,20 @@ do
echo writer had error
nerrors=`expr $nerrors + 1`
fi
-
+ #
+ # Remove any possible writer message file before launching writer
+ rm -f $WRITER_MESSAGE
+ #
# Launch the Add/Remove Writer
echo launch the swmr_addrem_writer
seed="" # Put -r <random seed> command here
./swmr_addrem_writer $Nrecords $seed &
pid_writer=$!
$DPRINT pid_writer=$pid_writer
-
+ #
+ # Wait for message from writer process before starting reader(s)
+ WAIT_MESSAGE $WRITER_MESSAGE
+ #
# Launch the Add/Remove Readers
#declare -a seeds=(<seed1> <seed2> <seed3> ... )
n=0
@@ -300,13 +418,18 @@ do
echo generator had error
nerrors=`expr $nerrors + 1`
fi
-
+ #
+ # Remove any possible writer message file before launching writer
+ rm -f $WRITER_MESSAGE
# Launch the Sparse writer
echo launch the swmr_sparse_writer
nice -n 20 ./swmr_sparse_writer $Nrecs_spa &
pid_writer=$!
$DPRINT pid_writer=$pid_writer
-
+ #
+ # Wait for message from writer process before starting reader(s)
+ WAIT_MESSAGE $WRITER_MESSAGE
+ #
# Launch the Sparse readers
n=0
pid_readers=""