#!/bin/sh
#
# Run a simple backup using the Sparse option then restore it.
#
TestName="bandwidth-limit-per-client-test"
JobName=BackupClient1
. scripts/functions

scripts/cleanup
scripts/copy-test-confs

rm -f bin/bareos-dir.conf
/bin/cp -f ${rconfigs}/${TestName}/bareos-dir.conf ${configs}/bareos-dir.conf
/bin/cp -f ${rconfigs}/${TestName}/bareos-sd.conf ${configs}/bareos-sd.conf
/bin/cp -f ${rconfigs}/${TestName}/bareos-fd.conf ${configs}/bareos-fd.conf
/bin/cp -f ${rconfigs}/${TestName}/bconsole.conf ${configs}/bconsole.conf

#
# create test data
#
dd if=/dev/zero of=${cwd}/tmp/testdata bs=500k count=8

echo "${cwd}/tmp/testdata" >${cwd}/tmp/file-list
start_test

#@$out /dev/null
cat >${cwd}/tmp/bconcmds <<END_OF_DATA
messages
label storage=File volume=TestVolume001
@$out ${cwd}/tmp/log1.out
run job=$JobName Level=Full yes
wait
messages

END_OF_DATA

run_bareos
check_for_zombie_jobs storage=File
stop_bareos

#
# Check if job1 is successful
#
grep "^  Termination: *Backup OK" ${tmp}/log1.out 2>&1 >/dev/null
if test $? -eq 0; then
   print_debug "First Backup is OK."
else
   estat=1
fi

#
# Check if job1 is throuput is between 850 and 1150 KB/S
#
rate=`grep "Rate:.*KB/s"  ${tmp}/log1.out | cut -d: -f2 | sed -e 's/  *//' -e 's/\..*//'`
if test $rate -gt 810 -a $rate -lt 1150 ; then
   print_debug "Backup Rate more than 850 and less than 1150 KB/s, ${rate} OK."
else
   estat=1
fi

end_test
