#!/bin/bash

rm out.txt
echo "Start test" >> out.txt
aptitude -y install mc atop screen pbzip2 sysbench

CPU=$(cat /proc/cpuinfo  | grep -c processor)
((CPU--))

for i in `seq 0 $CPU`;
 do
  echo "performance" > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor
 done


rm ports.tar
wget http://test.artplanet.su/ports.tar

rm myfile.tar.bz2
START=$(($(date +%s%N)/1000000))
tar jcf myfile.tar.bz2 ports.tar 
END=$(($(date +%s%N)/1000000))
DIFF=$(( $END - $START ))
echo "Create bzip2 arhive in $DIFF miliseconds (one core)" >> out.txt

rm myfile.tar.bz2
START=$(($(date +%s%N)/1000000))
tar cf myfile.tar.bz2 --use-compress-prog=pbzip2 ports.tar 
END=$(($(date +%s%N)/1000000))
DIFF=$(( $END - $START ))
echo "Create bzip2 arhive in $DIFF miliseconds (multi core)" >> out.txt
rm myfile.tar.bz2


echo "Single Core test by sysbench" >> out.txt
sysbench --test=cpu --cpu-max-prime=100000 run >> out.txt

echo "Multi Thread test by sysbench" >> out.txt
CPU=$(cat /proc/cpuinfo  | grep -c processor)
sysbench --test=cpu --cpu-max-prime=100000 --num-threads=$CPU run >> out.txt

echo "HDD TEST DD line write" >> out.txt
echo 3 > /proc/sys/vm/drop_caches
dd if=/dev/zero of=/root/zerofile.tst bs=1M count=51200 2>> out.txt

echo "HDD TEST DD line read" >> out.txt
echo 3 > /proc/sys/vm/drop_caches
dd if=/root/zerofile.tst of=/dev/null bs=1M count=51200 2>> out.txt

rm /root/zerofile.tst

sysbench --num-threads=16 --test=fileio --file-total-size=50G --file-test-mode=rndrw prepare
echo "HDD TEST sysbench random read" >> out.txt
echo 3 > /proc/sys/vm/drop_caches
sysbench --num-threads=16 --test=fileio --file-total-size=50G --file-test-mode=rndrd --init-rng=on --max-time=300 --max-requests=0 run >> out.txt
echo "HDD TEST sysbench random write" >> out.txt
echo 3 > /proc/sys/vm/drop_caches
sysbench --num-threads=16 --test=fileio --file-total-size=50G --file-test-mode=rndwr --init-rng=on --max-time=300 --max-requests=0 run >> out.txt
echo "HDD TEST sysbench random read/write" >> out.txt
echo 3 > /proc/sys/vm/drop_caches
sysbench --num-threads=16 --test=fileio --file-total-size=50G --file-test-mode=rndrw --init-rng=on --max-time=300 --max-requests=0 run >> out.txt
echo 3 > /proc/sys/vm/drop_caches
sysbench --num-threads=16 --test=fileio --file-total-size=50G --file-test-mode=rndrw cleanup
