X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=example%2Fdiameter%2Flauncher%2Fresources%2Fscripts%2Fclone.sh;h=bb4c468368fa8f2dccbb477686e968373af74209;hb=b8a974c5eaba39f0891dfd17b64f7dd6411688dc;hp=f24f7850f94a93d1831e019e1d3d1df261c523c8;hpb=c7f7ea45e06f24df384069535ae12f5f2fc3c004;p=anna.git diff --git a/example/diameter/launcher/resources/scripts/clone.sh b/example/diameter/launcher/resources/scripts/clone.sh index f24f785..bb4c468 100755 --- a/example/diameter/launcher/resources/scripts/clone.sh +++ b/example/diameter/launcher/resources/scripts/clone.sh @@ -1,4 +1,11 @@ #!/bin/bash +##################################################### +#### #### +## ## +# THIS SCRIPT IS NORMALLY INTENDED FOR INTERNAL USE # +## ## +#### #### +##################################################### ############# # VARIABLES # @@ -7,6 +14,7 @@ CLONE_WKDIR=$(mktemp -d) #MAX_NUMBER_GROUPS=400 MAX_NUMBER_GROUPS=200 # (depends on the machine) +CLONE_EXTRA_VARS_SCR_BN=clone-extra-vars.sh ############# # FUNCTIONS # @@ -17,7 +25,6 @@ _exit (){ echo # Background jobs: - #remaining_jobs=$(jobs -p) (kill -9 $(jobs -p) 2>&1) >/dev/null # Cleanup: @@ -39,19 +46,19 @@ usage() { echo " testcase variable file: path to the testcase file with parseable variables, for example '/testcase.txt.msk'." echo " xml files within this test case, must exist with aditional .msk extension in the same directory." echo - echo " Currently, 9 variables are supported to be replaced:" + echo " Currently, 4 variables are supported to be replaced:" echo echo " * __TESTID__ : sequence number. For example if you provide 1 to 20 for this script, it will be 1 .. 20" + echo " * __SEQ7__ : 7-digit number corresponding to the sequence number (0000001 for 1, and so on)" echo " * __SEQ8__ : 8-digit number corresponding to the sequence number (00000001 for 1, and so on)" echo " * __IPV4HEX__ : hexadecimal IPv4 address, for example: 00000001" echo " * __IPV4__ : IPv4 address, for example: 0.0.0.1" echo - #echo " One variant (former ones plus 1):" - #echo " __SEQ8P1__ : 8-digit number corresponding to the sequence number (00000002 for 1, and so on)" - #echo " __IPV4HEXP1__: hexadecimal IPv4 address, for example: 00000002" - #echo " __IPV4P1__ : IPv4 address, for example: 0.0.0.2" - #echo - echo " Edit the variables section to add more special values if you need them." + echo " Optionally (when exists), a user defined file '$CLONE_EXTRA_VARS_SCR_BN' is sourced to extend the parseable" + echo " variables used within the test case stuff (this script must be placed on that directory). The script" + echo " will be called with the sequence number as argument during clone procedure, and shall define the needed" + echo " variable values referenced in the parsed files. The variables must be named as '____' which ensures" + echo " that main clone script environment is not contaminated." echo echo " initial sequence: initial sequence number to parse over variables." echo " final sequence: final sequence number to parse over variables." @@ -70,12 +77,6 @@ usage() { _exit } -children () { - bash_pid=$$ - children=`ps -eo ppid | grep -w $bash_pid` - echo $children | wc -w -} - # $1: sequence number; $2: file to parse(will be updated); $3: result file parse_file() { local vars=$(egrep -o '__((_*[A-Z]*[0-9]*)*)__' $2 | cut -d: -f2 | sort -u) @@ -95,35 +96,27 @@ clone() { local wkdir=$2 mkdir -p $wkdir - ############################################# SPECIAL VARIABLES SECTION ############################################# - ################################ EDIT THIS SECTION IF YOU NEED NEW SPECIAL VARIABLES ################################ - testid=$sequence - seq8=$(printf "%08d" $testid) - seq8_p1=$((seq8+1)) - ipv4hex=$seq8 - ipv4hex_p1=$seq8_p1 - #ipv4=$(for i in $(echo $seq8 | sed 's/\(..\)/0x\1 /g'); do printf "%d." $i; done | sed 's/\.$/\n/') + ############################################# VARIABLES SECTION ############################################# + local testid=$sequence + local seq7=$(printf "%07d" $testid) + local seq8=$(printf "%08d" $testid) + local ipv4hex=$seq8 # Numbers beginning with "0" are treated as octal (i.e. base-8): we would have 'invalid octal number with 08 and 09' # Solution: convert to base-10 in this way: $((10#$i)) - ipv4=$(for i in $(echo $seq8 | sed 's/\(..\)/ \1 /g'); do printf "%d." $((10#$i)); done | sed 's/\.$/\n/') - ipv4_p1=$(for i in $(echo $seq8_p1 | sed 's/\(..\)/ \1 /g'); do printf "%d." $((10#$i)); done | sed 's/\.$/\n/') - - local target=$wkdir/values.${1} - echo "__TESTID__=$testid" > $target - echo "__SEQ8__=$seq8" >> $target - echo "__IPV4HEX__=$ipv4hex" >> $target - echo "__IPV4__=$ipv4" >> $target - ## First variant: - #echo "__SEQ8P1__=$seq8_p1" >> $target - #echo "__IPV4HEXP1__=$ipv4hex_p1" >> $target - #echo "__IPV4P1__=$ipv4_p1" >> $target - source $target - #rm $target - ######################################### END SPECIAL VARIABLES SECTION ######################################### + local ipv4=$(for i in $(echo $seq8 | sed 's/\(..\)/ \1 /g'); do printf "%d." $((10#$i)); done | sed 's/\.$/\n/') + local __TESTID__=$testid + local __SEQ7__=$seq7 + local __SEQ8__=$seq8 + local __IPV4HEX__=$ipv4hex + local __IPV4__=$ipv4 + [ -n "$extra_vars" ] && source $CLONE_EXTRA_VARS_SCR_FILE $sequence + ######################################### END VARIABLES SECTION ######################################### # Parse template files: parse_file $sequence $TESTCASE_TEMPLATE $wkdir/testcase.txt.$sequence + local xml= + local new_file= for file in $(grep sendxml $TESTCASE_TEMPLATE | cut -d\| -f4 | sed 's/\.xml$/.xml.msk/') do xml=`basename $file .msk` @@ -147,8 +140,8 @@ clone_group() { for i in `seq $2 $3` do clone $i $CLONE_WKDIR/$1 - sleep 0.01 done + echo " - Completed range [$2,$3] for $(basename $ADML_DIR)" } ############# @@ -166,6 +159,9 @@ N_GROUPS=$5 POPULATION=$6 POPULATION_FILE=$TESTCASE_TEMPLATE_DIR/$POPULATION POPULATION_ALL=$TESTCASE_TEMPLATE_DIR/${POPULATION}.all +CLONE_EXTRA_VARS_SCR_FILE=$TESTCASE_TEMPLATE_DIR/$CLONE_EXTRA_VARS_SCR_BN +extra_vars= +[ -f $CLONE_EXTRA_VARS_SCR_FILE ] && extra_vars=yes [ "$4" = "" ] && usage @@ -183,6 +179,9 @@ then fi N_ITEMS=$((CLONE_SEQ_END - CLONE_SEQ_BEGIN + 1)) +[ "$N_ITEMS" -lt 1 ] && _exit "Initial sequence ($CLONE_SEQ_BEGIN) provided must be under final sequence value ($CLONE_SEQ_END) !!" +[ "$CLONE_SEQ_END" -gt "99999999" ] && echo "Warning: some sequence value in range provided overflows __SEQ8__ and derived variables (__IPV4__ and __IPV4HEX__). Be care about using them ..." + if [ -z "$N_GROUPS" ] then N_GROUPS=$((N_ITEMS/25)) @@ -199,10 +198,10 @@ fi # Start cloning: timestamp_begin=$(echo "scale=3 ; $(date '+%s') + $(date '+%N') / 1000000000" | bc) -children_before=$(children) offset=0 -$OPERATION "test|clear" -echo "Please be patient, this may take a while ..." +$OPERATION "test|clear" >/dev/null +[ $? -ne 0 ] && _exit "Clone aborted: failed to clean tests !" +#echo "Please be patient, this may take a while ..." #echo "Temporary directory: $CLONE_WKDIR" for group in `seq 1 $((N_GROUPS+1))` do @@ -211,15 +210,11 @@ do [ $n_end -gt $CLONE_SEQ_END ] && n_end=$CLONE_SEQ_END [ $n_end -lt $n_begin ] && break clone_group $group $n_begin $n_end & + sleep 0.05 offset=$((group * GROUPS_SIZE)) done -# Wait background jobs to finish: -while true -do - sleep 1 - [ $(children) -eq $children_before ] && break -done +wait $(jobs -p) # Programming: echo -n "Programming .."