#!/bin/bash


#-------------------------------------------------
#---------------- NEW LOG FILE -------------------
#-------------------------------------------------
log_file=log.csv
touch $log_file

sleep 5

uri=http://testgrid.allmydata.org:3567/uri/URI:DIR2:plnblw6xezafhqzovmc7aa3kau:dj4wdnuuafcppvd5vbq7qt5zqjgoxqnfcl2cbatv32zqsnfzg4cq

#-------------------------------------------------
#-------------- Initialisation -------------------
#-------------------------------------------------

# The size of files to be used in tests 
block_size=1024
file_size=(1 10 100 512 1024 2048 4096 8192 16384 32768 65536 131072 262144)
# file_size[i]*block_size => 1kO 10KB 100KB 512KB 1MB 2MB 4MB 8MB 16MB 32MB 64MB 128MB 256MB

# The number of tests to do for each file
count_tests=3 #100 

# start from this index at file_size array
start=0
# stop at this index
stop=${#file_size[@]} 

# dd if=/dev/zero of=bigfile bs=1024 count=104   ---> random file

NO_ARGS=0
E_OPTERROR=85

#-------------------------------------------------
#---------------- Test Tahoe ---------------------
#-------------------------------------------------

for (( i=$start; i<$stop; i++ ));
do
	# Random file generation
	dd if=/dev/zero of=testfile bs=$block_size count=${file_size[$i]}

	for (( j=0; j<$count_tests; j++ ));
	do	
		#commande d'envoi
		begin=$(date +%s.%N)
		out=($(curl -T testfile $uri/${file_size[$i]}_$j))
		end=$(date +%s.%N)
		echo ${file_size[$i]} tahoe IP@ $(echo "$end - $begin" | bc) $out >> ${log_file}
	done	
done


echo "---------------------------------------------"
cat ${log_file}